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.

82 lines
2.3 KiB

  1. // setvid.c
  2. #include "oidtst.h"
  3. VOID
  4. _cdecl
  5. main(
  6. int argc,
  7. char *argv[]
  8. )
  9. {
  10. HANDLE Volume;
  11. IO_STATUS_BLOCK IoStatusBlock;
  12. NTSTATUS Status;
  13. OBJECT_ATTRIBUTES ObjAttr;
  14. ANSI_STRING AnsiName;
  15. UNICODE_STRING UnicodeName;
  16. char DriveNameBuffer[32];
  17. FILE_OBJECTID_BUFFER ObjectIdBuffer;
  18. //
  19. // Get parameters
  20. //
  21. if (argc < 4) {
  22. printf("This program sets the object id for a volume (ntfs only).\n\n");
  23. printf("usage: %s <drive letter>: ObjectId ExtendedInfo\n", argv[0]);
  24. return;
  25. }
  26. strcpy( DriveNameBuffer, "\\DosDevices\\" );
  27. strcat( DriveNameBuffer, argv[1] );
  28. RtlInitAnsiString( &AnsiName, DriveNameBuffer );
  29. Status = RtlAnsiStringToUnicodeString( &UnicodeName, &AnsiName, TRUE );
  30. if (!NT_SUCCESS(Status)) {
  31. printf( "Error initalizing strings" );
  32. return;
  33. }
  34. RtlZeroMemory( &ObjAttr, sizeof(OBJECT_ATTRIBUTES) );
  35. ObjAttr.Length = sizeof(OBJECT_ATTRIBUTES);
  36. ObjAttr.ObjectName = &UnicodeName;
  37. ObjAttr.Attributes = OBJ_CASE_INSENSITIVE;
  38. Status = NtOpenFile( &Volume,
  39. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  40. &ObjAttr,
  41. &IoStatusBlock,
  42. FILE_SHARE_READ | FILE_SHARE_WRITE,
  43. FILE_SYNCHRONOUS_IO_ALERT );
  44. if (Volume == INVALID_HANDLE_VALUE) {
  45. printf( "Error opening file %s %x\n", argv[1], GetLastError() );
  46. return;
  47. }
  48. // RtlZeroBytes( &ObjectIdBuffer, sizeof( ObjectIdBuffer ) );
  49. sscanf( argv[2], "%s", &ObjectIdBuffer.ObjectId );
  50. sscanf( argv[3], "%s", &ObjectIdBuffer.ExtendedInfo );
  51. printf( "\nUsing ObjectId:%s, ExtendedInfo:%s\n",
  52. ObjectIdBuffer.ObjectId,
  53. ObjectIdBuffer.ExtendedInfo );
  54. Status = NtSetVolumeInformationFile( Volume,
  55. &IoStatusBlock,
  56. &ObjectIdBuffer,
  57. sizeof( ObjectIdBuffer ),
  58. FileFsObjectIdInformation );
  59. FsTestDecipherStatus( Status );
  60. CloseHandle( Volume );
  61. return;
  62. }