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.

158 lines
4.3 KiB

  1. // enumq.c
  2. #include "oidtst.h"
  3. void
  4. FsTestDumpQuotaIndexEntries (
  5. IN PFILE_QUOTA_INFORMATION QuotaInfo,
  6. IN ULONG_PTR LengthInBytes
  7. )
  8. {
  9. ULONG RemainingBytesToDump = (ULONG) LengthInBytes;
  10. ULONG Idx;
  11. ULONG CurrentEntrySize;
  12. PFILE_QUOTA_INFORMATION Ptr;
  13. printf( "\n\nFound %x quota index bytes", LengthInBytes );
  14. Ptr = QuotaInfo;
  15. Idx = 0;
  16. while (RemainingBytesToDump > 0) {
  17. printf( "\n\nEntry %x", Idx );
  18. printf( "\nQuotaUsed %i64", Ptr->QuotaUsed.QuadPart );
  19. printf( "\nQuotaLimit %i64", Ptr->QuotaLimit.QuadPart );
  20. printf( "\nSidLength %x", Ptr->SidLength );
  21. printf( "\nSid bytes are: " );
  22. FsTestHexDumpLongs( (PVOID) &Ptr->Sid, Ptr->SidLength );
  23. // why 0x38? it's SIZEOF_QUOTA_USER_DATA (which isn't exported to this test) + 8 for quad alignment
  24. CurrentEntrySize = Ptr->SidLength + 0x38;
  25. Ptr = (PFILE_QUOTA_INFORMATION) ((PUCHAR)Ptr + CurrentEntrySize);
  26. RemainingBytesToDump -= CurrentEntrySize;
  27. Idx += 1;
  28. }
  29. }
  30. int
  31. FsTestEnumerateQuota (
  32. IN HANDLE hFile
  33. )
  34. {
  35. IO_STATUS_BLOCK IoStatusBlock;
  36. NTSTATUS Status;
  37. FILE_QUOTA_INFORMATION QuotaInfo[4];
  38. BOOLEAN ReturnSingleEntry = FALSE;
  39. FILE_INFORMATION_CLASS InfoClass = FileQuotaInformation;
  40. //
  41. // Init with garbage so we can make sure Ntfs is doing its job.
  42. //
  43. RtlFillMemory( QuotaInfo, sizeof(QuotaInfo), 0x51 );
  44. Status = NtQueryDirectoryFile( hFile,
  45. NULL, // Event
  46. NULL, // ApcRoutine
  47. NULL, // ApcContext
  48. &IoStatusBlock,
  49. &QuotaInfo[0],
  50. sizeof(QuotaInfo),
  51. InfoClass,
  52. ReturnSingleEntry,
  53. NULL, // FileName
  54. TRUE ); // RestartScan
  55. if (Status == STATUS_SUCCESS) {
  56. FsTestDumpQuotaIndexEntries( &QuotaInfo[0], IoStatusBlock.Information );
  57. }
  58. while (Status == STATUS_SUCCESS) {
  59. //
  60. // Init with garbage so we can make sure Ntfs is doing its job.
  61. //
  62. RtlFillMemory( QuotaInfo, sizeof(QuotaInfo), 0x51 );
  63. Status = NtQueryDirectoryFile( hFile,
  64. NULL, // Event
  65. NULL, // ApcRoutine
  66. NULL, // ApcContext
  67. &IoStatusBlock,
  68. &QuotaInfo[0],
  69. sizeof(QuotaInfo),
  70. InfoClass,
  71. ReturnSingleEntry,
  72. NULL, // FileName
  73. FALSE ); // RestartScan
  74. if (Status == STATUS_SUCCESS) {
  75. FsTestDumpQuotaIndexEntries( &QuotaInfo[0], IoStatusBlock.Information );
  76. }
  77. }
  78. printf( "\n" );
  79. return FsTestDecipherStatus( Status );
  80. }
  81. VOID
  82. _cdecl
  83. main (
  84. int argc,
  85. char *argv[]
  86. )
  87. {
  88. HANDLE hFile;
  89. char Buffer[80];
  90. char Buff2[4];
  91. //
  92. // Get parameters
  93. //
  94. if (argc < 2) {
  95. printf("This program enumerates the quota (if any) for a volume (ntfs only).\n\n");
  96. printf("usage: %s driveletter\n", argv[0]);
  97. return;
  98. }
  99. strcpy( Buffer, argv[1] );
  100. strcat( Buffer, "\\$Extend\\$Quota:$Q:$INDEX_ALLOCATION" );
  101. hFile = CreateFile( Buffer,
  102. GENERIC_READ,
  103. FILE_SHARE_READ,
  104. NULL,
  105. OPEN_EXISTING,
  106. FILE_FLAG_BACKUP_SEMANTICS | SECURITY_IMPERSONATION,
  107. NULL );
  108. if ( hFile == INVALID_HANDLE_VALUE ) {
  109. printf( "Error opening directory %s (dec) %d\n", Buffer, GetLastError() );
  110. return;
  111. }
  112. printf( "\nUsing directory:%s\n", Buffer );
  113. FsTestEnumerateQuota( hFile );
  114. CloseHandle( hFile );
  115. return;
  116. }