Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.4 KiB

  1. // rootattr.c
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <nt.h>
  5. #include <ntrtl.h>
  6. #include <nturtl.h>
  7. #include <windows.h>
  8. #include <ntioapi.h>
  9. VOID
  10. _cdecl
  11. main (
  12. int argc,
  13. char *argv[]
  14. )
  15. {
  16. IO_STATUS_BLOCK ioStatusBlock;
  17. FILE_BASIC_INFORMATION basicInfo;
  18. HANDLE hFile;
  19. NTSTATUS status;
  20. char buffer[260];
  21. //
  22. // Get parameters
  23. //
  24. if (argc < 2) {
  25. printf("This program returns or sets the attributes for the root directory.\n\n");
  26. printf("usage: %s driveletter [new value]\n", argv[0]);
  27. return;
  28. }
  29. strcpy( buffer, argv[1] );
  30. strcat( buffer, "\\" );
  31. hFile = CreateFile( buffer,
  32. MAXIMUM_ALLOWED,
  33. FILE_SHARE_READ,
  34. NULL,
  35. OPEN_EXISTING,
  36. FILE_FLAG_BACKUP_SEMANTICS | SECURITY_IMPERSONATION,
  37. NULL );
  38. if ( hFile == INVALID_HANDLE_VALUE ) {
  39. printf( "Error opening directory %s, error %d (decimal)\n", buffer, GetLastError() );
  40. return;
  41. }
  42. status = NtQueryInformationFile( hFile,
  43. &ioStatusBlock,
  44. &basicInfo,
  45. sizeof( basicInfo ),
  46. FileBasicInformation );
  47. if (!NT_SUCCESS( status )) {
  48. printf( "Couldn't get attributes, error status %x\n", status );
  49. CloseHandle( hFile );
  50. return;
  51. }
  52. printf( "Attributes for %s are currently: %0x\n", buffer, basicInfo.FileAttributes );
  53. if (argc >= 3) {
  54. //
  55. // Third argument present, must be setting attributes.
  56. //
  57. sscanf( argv[2], "%02x", &basicInfo.FileAttributes );
  58. printf( "Setting attributes for %s to: %0x\n", buffer, basicInfo.FileAttributes );
  59. status = NtSetInformationFile( hFile,
  60. &ioStatusBlock,
  61. &basicInfo,
  62. sizeof( basicInfo ),
  63. FileBasicInformation );
  64. if (NT_SUCCESS( status )) {
  65. printf( "Set attributes succesfully\n" );
  66. } else {
  67. printf( "Couldn't set attributes, error status %x\n", status );
  68. }
  69. }
  70. CloseHandle( hFile );
  71. return;
  72. }