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.

269 lines
7.1 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "ntaccess.h"
  4. #include "azaccess.h"
  5. #include "bmcommon.h"
  6. #include "benchmrk.h"
  7. EXTERN_C AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager;
  8. EXTERN_C AUTHZ_RM_AUDIT_INFO_HANDLE hRmAuditInfo;
  9. double az_time, nt_time;
  10. EXTERN_C PAUTHZ_ACCESS_REPLY pReply, pReplyOT;
  11. EXTERN_C AUTHZ_AUDIT_INFO_HANDLE hAuditInfo;
  12. void DoBenchMarks( IN ULONG NumIter, IN DWORD Flags )
  13. {
  14. DWORD dwError=NO_ERROR;
  15. //
  16. // do NT access checks
  17. //
  18. dwError = InitNtAccessChecks();
  19. if ( dwError != NO_ERROR )
  20. {
  21. goto Cleanup;
  22. }
  23. wprintf(L"NtAccessChecks : ");
  24. fflush(stdout);
  25. timer_start();
  26. dwError = DoNtAccessChecks( NumIter, Flags );
  27. if ( dwError != NO_ERROR )
  28. {
  29. goto Cleanup;
  30. }
  31. timer_stop();
  32. nt_time = timer_time();
  33. wprintf(L"%.2f sec\n", nt_time);
  34. //
  35. // do authz access checks
  36. //
  37. dwError = InitAuthzAccessChecks();
  38. if ( dwError != NO_ERROR )
  39. {
  40. goto Cleanup;
  41. }
  42. wprintf(L"AzAccessChecks : ");
  43. fflush(stdout);
  44. timer_start();
  45. dwError = AuthzDoAccessCheck( NumIter, Flags );
  46. if ( dwError != NO_ERROR )
  47. {
  48. goto Cleanup;
  49. }
  50. timer_stop();
  51. az_time = timer_time();
  52. wprintf(L"%.2f sec\n", az_time);
  53. wprintf(L"perf ratio : %2.2f \n", nt_time/az_time);
  54. //
  55. // make sure that both az and nt returned the same results
  56. //
  57. UINT len;
  58. if ( Flags & BMF_UseObjTypeList )
  59. {
  60. len = ObjectTypeListLength;
  61. for (UINT i=0; i < len; i++)
  62. {
  63. if ((pReplyOT->Error[i] != fNtAccessCheckResult[i]) ||
  64. ((pReplyOT->Error[i] == ERROR_SUCCESS) && (pReplyOT->GrantedAccessMask[i] != dwNtGrantedAccess[i])))
  65. {
  66. wprintf(L"AccessCheck mismatch @ %d\n", i);
  67. wprintf(L"AGA: %08lx\tAE: %08lx\nNGA: %08lx\tNE: %08lx\n",
  68. pReplyOT->GrantedAccessMask[i],
  69. pReplyOT->Error[i],
  70. dwNtGrantedAccess[i],
  71. fNtAccessCheckResult[i]);
  72. }
  73. }
  74. }
  75. else
  76. {
  77. if (
  78. ((pReply->Error[0] == ERROR_SUCCESS) && (0 == fNtAccessCheckResult[0])) ||
  79. ((pReply->Error[0] != ERROR_SUCCESS) && (1 == fNtAccessCheckResult[0])) ||
  80. ((pReply->Error[0] == ERROR_SUCCESS) && (pReply->GrantedAccessMask[0] != dwNtGrantedAccess[0]))
  81. )
  82. {
  83. wprintf(L"AccessCheck mismatch\n");
  84. wprintf(L"AGA: %08lx\tAE: %08lx\nNGA: %08lx\tNE: %08lx\n",
  85. pReply->GrantedAccessMask[0],
  86. pReply->Error[0],
  87. dwNtGrantedAccess[0],
  88. fNtAccessCheckResult[0]);
  89. }
  90. }
  91. //
  92. // make sure that both az and nt returned the same results
  93. //
  94. if ( Flags & BMF_UseObjTypeList )
  95. {
  96. len = ObjectTypeListLength;
  97. for (UINT i=0; i < len; i++)
  98. {
  99. if ((pReplyOT->Error[i] != fNtAccessCheckResult[i]) ||
  100. ((pReplyOT->Error[i] == ERROR_SUCCESS) && (pReplyOT->GrantedAccessMask[i] != dwNtGrantedAccess[i])))
  101. {
  102. wprintf(L"AccessCheck mismatch @ %d\n", i);
  103. wprintf(L"AGA: %08lx\tAE: %08lx\nNGA: %08lx\tNE: %08lx\n",
  104. pReplyOT->GrantedAccessMask[i],
  105. pReplyOT->Error[i],
  106. dwNtGrantedAccess[i],
  107. fNtAccessCheckResult[i]);
  108. }
  109. }
  110. }
  111. else
  112. {
  113. if (
  114. ((pReply->Error[0] == ERROR_SUCCESS) && (0 == fNtAccessCheckResult[0])) ||
  115. ((pReply->Error[0] != ERROR_SUCCESS) && (1 == fNtAccessCheckResult[0])) ||
  116. ((pReply->Error[0] == ERROR_SUCCESS) && (pReply->GrantedAccessMask[0] != dwNtGrantedAccess[0]))
  117. )
  118. {
  119. wprintf(L"AccessCheck mismatch\n");
  120. wprintf(L"AGA: %08lx\tAE: %08lx\nNGA: %08lx\tNE: %08lx\n",
  121. pReply->GrantedAccessMask[0],
  122. pReply->Error[0],
  123. dwNtGrantedAccess[0],
  124. fNtAccessCheckResult[0]);
  125. }
  126. }
  127. return;
  128. Cleanup:
  129. wprintf(L"DoBenchMarks failed: %lx\n", dwError);
  130. }
  131. #define OTO_OT 1
  132. #define OTO_SO 2
  133. #define OTO_OTSO 3
  134. PWCHAR szUsage = L"Usage: azbm iter-count ot-option access-mask sd-index audit-flag";
  135. extern "C" int __cdecl wmain(int argc, PWSTR argv[])
  136. {
  137. NTSTATUS Status;
  138. ULONG NumChecks = 10000;
  139. BOOLEAN WasEnabled;
  140. ULONG OtOptions;
  141. ACCESS_MASK DesiredAccess;
  142. ULONG SdIndex;
  143. DWORD fGenAudit;
  144. if ( argc != 6 )
  145. {
  146. wprintf(szUsage);
  147. exit(-1);
  148. }
  149. if (1 != swscanf(argv[1], L"%d", &NumChecks))
  150. {
  151. wprintf(L"Bad iteration-count");
  152. exit(-1);
  153. }
  154. if (1 != swscanf(argv[2], L"%d", &OtOptions))
  155. {
  156. wprintf(L"Bad ot-option");
  157. exit(-1);
  158. }
  159. if (1 != swscanf(argv[3], L"%x", &DesiredAccess))
  160. {
  161. wprintf(L"Bad access-mask");
  162. exit(-1);
  163. }
  164. g_DesiredAccess = DesiredAccess;
  165. if (1 != swscanf(argv[4], L"%d", &SdIndex))
  166. {
  167. wprintf(L"Bad sd-index");
  168. exit(-1);
  169. }
  170. g_szSd = g_aszSd[SdIndex];
  171. if (1 != swscanf(argv[5], L"%d", &fGenAudit))
  172. {
  173. wprintf(L"Bad audit-flag");
  174. exit(-1);
  175. }
  176. Status = RtlAdjustPrivilege(
  177. SE_AUDIT_PRIVILEGE,
  178. TRUE, // enable
  179. FALSE, // do it on the thread token
  180. &WasEnabled
  181. );
  182. if (!NT_SUCCESS(Status))
  183. {
  184. wprintf(L"RtlAdjustPrivilege: %lx\n", Status);
  185. }
  186. if ( fGenAudit )
  187. {
  188. if ( OtOptions & OTO_SO )
  189. {
  190. wprintf(L"regular access checks with audit\n");
  191. wprintf(L"---------------------\n");
  192. DoBenchMarks( NumChecks, BMF_GenerateAudit );
  193. }
  194. if ( OtOptions & OTO_OT )
  195. {
  196. wprintf(L"\n\naccess checks with obj-type list with audit\n");
  197. wprintf(L"--------------------------------\n");
  198. DoBenchMarks( NumChecks, BMF_UseObjTypeList | BMF_GenerateAudit );
  199. }
  200. }
  201. else
  202. {
  203. if ( OtOptions & OTO_SO )
  204. {
  205. wprintf(L"regular access checks\n");
  206. wprintf(L"---------------------\n");
  207. DoBenchMarks( NumChecks, 0 );
  208. }
  209. if ( OtOptions & OTO_OT )
  210. {
  211. wprintf(L"\n\naccess checks with obj-type list\n");
  212. wprintf(L"--------------------------------\n");
  213. DoBenchMarks( NumChecks, BMF_UseObjTypeList );
  214. }
  215. }
  216. AuthzFreeAuditInfo(hAuditInfo);
  217. AuthzFreeAuditQueue(NULL);
  218. AuthzFreeResourceManager(hAuthzResourceManager);
  219. UNREFERENCED_PARAMETER(argc);
  220. UNREFERENCED_PARAMETER(argv);
  221. return 0;
  222. }