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.

382 lines
10 KiB

  1. #include "pch.h"
  2. #include <authzi.h>
  3. PSID pSid = NULL;
  4. void _cdecl wmain(int argc, WCHAR * argv[])
  5. {
  6. LONG i = 0;
  7. LONG ii = 0;
  8. LONG j = 0;
  9. LONG Iterations = 0;
  10. BOOL b = TRUE;
  11. AUTHZ_AUDIT_EVENT_HANDLE hAAI1 = NULL;
  12. AUTHZ_AUDIT_EVENT_HANDLE hAAI2 = NULL;
  13. AUTHZ_AUDIT_EVENT_HANDLE hOA = NULL;
  14. AUTHZ_RESOURCE_MANAGER_HANDLE hRM = NULL;
  15. AUTHZ_AUDIT_QUEUE_HANDLE hAAQ = NULL;
  16. AUTHZ_CLIENT_CONTEXT_HANDLE hCC = NULL;
  17. PSECURITY_DESCRIPTOR pSD = NULL;
  18. PSECURITY_DESCRIPTOR pSD2 = NULL;
  19. PSECURITY_DESCRIPTOR pASD[2];
  20. PWCHAR StringSD = L"O:BAG:BUD:(A;;0x40;;;s-1-2-2)(A;;0x1;;;BA)(OA;;0x2;6da8a4ff-0e52-11d0-a286-00aa00304900;;BA)(OA;;0x4;6da8a4ff-0e52-11d0-a286-00aa00304901;;BA)(OA;;0x8;6da8a4ff-0e52-11d0-a286-00aa00304903;;AU)(OA;;0x10;6da8a4ff-0e52-11d0-a286-00aa00304904;;BU)(OA;;0x20;6da8a4ff-0e52-11d0-a286-00aa00304905;;AU)(A;;0x40;;;PS)S:(AU;IDSAFA;0xFFFFFF;;;WD)";
  21. HANDLE hToken = NULL;
  22. UCHAR Buffer[256];
  23. AUTHZ_ACCESS_REQUEST Request = {0};
  24. PAUTHZ_ACCESS_REPLY pReply = (PAUTHZ_ACCESS_REPLY) Buffer;
  25. LUID Luid = {0xdead,0xbeef};
  26. PAUDIT_PARAMS pParams = NULL;
  27. AUTHZ_AUDIT_EVENT_TYPE_HANDLE pAEI = NULL;
  28. AUTHZ_ACCESS_CHECK_RESULTS_HANDLE hCache = NULL;
  29. if (argc != 2)
  30. {
  31. wprintf(L"usage: %s iterations\n", argv[0]);
  32. exit(0);
  33. }
  34. Iterations = wcstol(argv[1], NULL, 10);
  35. wprintf(L"Log Stress with queues. Default and specific queue each with %d audits. Press a key to start.\n", Iterations);
  36. getchar();
  37. if (!b)
  38. {
  39. wprintf(L"SDDL failed with %d\n", GetLastError());
  40. return;
  41. }
  42. b = AuthzInitializeResourceManager(
  43. 0,
  44. NULL,
  45. NULL,
  46. NULL,
  47. L"Jeff's RM",
  48. &hRM
  49. );
  50. if (!b)
  51. {
  52. wprintf(L"AuthzInitializeResourceManager failed with %d\n", GetLastError());
  53. return;
  54. }
  55. //
  56. // Create a client context from the current token.
  57. //
  58. OpenProcessToken(
  59. GetCurrentProcess(),
  60. TOKEN_QUERY,
  61. &hToken
  62. );
  63. b = AuthzInitializeContextFromToken(
  64. 0,
  65. hToken,
  66. hRM,
  67. NULL,
  68. Luid,
  69. NULL,
  70. &hCC
  71. );
  72. if (!b)
  73. {
  74. wprintf(L"AuthzInitializeContextFromToken failed with 0x%x\n", GetLastError());
  75. return;
  76. }
  77. for (i = 0; i < Iterations; i++)
  78. {
  79. //
  80. // Create the SD for the access checks
  81. //
  82. b = ConvertStringSecurityDescriptorToSecurityDescriptorW(
  83. StringSD,
  84. SDDL_REVISION_1,
  85. &pSD,
  86. NULL
  87. );
  88. pASD[0] = pSD;
  89. pASD[1] = pSD;
  90. AuthzInitializeObjectAccessAuditEvent(
  91. 0,
  92. NULL,
  93. L"op",
  94. L"object type",
  95. L"object name",
  96. L"info",
  97. &hOA,
  98. 0
  99. );
  100. if (!b)
  101. {
  102. wprintf(L"AuthzInitializeObjectAccessAuditEvent failed with %d\n", GetLastError());
  103. return;
  104. }
  105. b = AuthziInitializeAuditEvent(
  106. AUTHZ_NO_ALLOC_STRINGS | AUTHZ_DS_CATEGORY_FLAG,
  107. hRM,
  108. NULL,
  109. NULL,
  110. NULL,
  111. INFINITE,
  112. L"This is with the default RM queue.",
  113. L"This is with the default RM queue.",
  114. L"This is with the default RM queue.",
  115. L"This is with the default RM queue.",
  116. &hAAI1
  117. );
  118. if (!b)
  119. {
  120. wprintf(L"AuthzInitializeAuditInfo (no queue) failed with %d\n", GetLastError());
  121. return;
  122. }
  123. b = AuthziInitializeAuditQueue(
  124. AUTHZ_MONITOR_AUDIT_QUEUE_SIZE,
  125. 1000,
  126. 100,
  127. NULL,
  128. &hAAQ
  129. );
  130. if (!b)
  131. {
  132. wprintf(L"AuthziInitializeAuditQueue failed with %d\n", GetLastError());
  133. return;
  134. }
  135. b = AuthziAllocateAuditParams(
  136. &pParams,
  137. 1
  138. );
  139. if (!b)
  140. {
  141. wprintf(L"AuthzAllocateAuditParams failed with %d\n", GetLastError());
  142. }
  143. b = AuthziInitializeAuditParams(
  144. 0,
  145. pParams,
  146. &pSid,
  147. L"foo",
  148. 1,
  149. APT_String, L"This audit was with a custom AUDIT_EVENT_INFO, AUDIT_PARAMS, and queue."
  150. );
  151. // b = AuthziInitializeAuditParamsWithRM(
  152. // 0,
  153. // hRM,
  154. // 1,
  155. // pParams,
  156. // APT_String, L"This audit was with a custom AUDIT_EVENT_INFO, AUDIT_PARAMS, and queue."
  157. // );
  158. if (!b)
  159. {
  160. wprintf(L"AuthzInitializeAuditParamsWithRM failed with %d\n", GetLastError());
  161. }
  162. b = AuthziInitializeAuditEventType(
  163. 0,
  164. SE_CATEGID_OBJECT_ACCESS,
  165. 567,
  166. 1,
  167. &pAEI
  168. );
  169. if (!b)
  170. {
  171. wprintf(L"AuthzInitializeAuditEvent failed with %d\n", GetLastError());
  172. }
  173. b = AuthziInitializeAuditEvent(
  174. AUTHZ_NO_RM_AUDIT,
  175. NULL, //hRM,
  176. pAEI,
  177. pParams,
  178. NULL,
  179. INFINITE,
  180. L"This is with a specific queue and params.",
  181. L"This is with a specific queue and params.",
  182. L"This is with a specific queue and params.",
  183. L"This is with a specific queue and params.",
  184. &hAAI2
  185. );
  186. if (!b)
  187. {
  188. wprintf(L"AuthziInitializeAuditEvent (with queue) failed with %d\n", GetLastError());
  189. return;
  190. }
  191. for (ii = 0; ii < 100; ii++)
  192. {
  193. b = AuthziLogAuditEvent(
  194. 0,
  195. hAAI2,
  196. NULL
  197. );
  198. if (!b)
  199. {
  200. wprintf(L"log failed with %d \n", GetLastError());
  201. return;
  202. }
  203. }
  204. Request.ObjectTypeList = NULL;
  205. Request.PrincipalSelfSid = NULL;
  206. Request.DesiredAccess = MAXIMUM_ALLOWED;
  207. pReply->ResultListLength = 1;
  208. pReply->Error = (PDWORD) (((PCHAR) pReply) + sizeof(AUTHZ_ACCESS_REPLY));
  209. pReply->GrantedAccessMask = (PACCESS_MASK) (pReply->Error + pReply->ResultListLength);
  210. pReply->SaclEvaluationResults = (PDWORD) pReply->GrantedAccessMask + (sizeof(ACCESS_MASK) * pReply->ResultListLength);
  211. b = AuthzAccessCheck(
  212. 0,
  213. hCC,
  214. &Request,
  215. hOA,
  216. pSD,
  217. pASD,
  218. 2,
  219. pReply,
  220. &hCache
  221. );
  222. if (!b)
  223. {
  224. wprintf(L"AuthzAccessCheck (with queue) failed with %d\n", GetLastError());
  225. return;
  226. }
  227. pSD2 = pSD;
  228. pSD = NULL;
  229. for (j = 0; j < 100; j++)
  230. {
  231. b = AuthzCachedAccessCheck(
  232. 0,
  233. hCache,
  234. &Request,
  235. hOA,
  236. pReply
  237. );
  238. b = AuthzCachedAccessCheck(
  239. 0,
  240. hCache,
  241. &Request,
  242. hAAI1,
  243. pReply
  244. );
  245. b = AuthzCachedAccessCheck(
  246. 0,
  247. hCache,
  248. &Request,
  249. hAAI1,
  250. pReply
  251. );
  252. if (!b)
  253. {
  254. wprintf(L"CachedAuthzAccessCheck (no queue) failed with %d\n", GetLastError());
  255. return;
  256. }
  257. }
  258. b = AuthzFreeAuditEvent(
  259. hAAI2
  260. );
  261. b = AuthzFreeAuditEvent(
  262. hAAI1
  263. );
  264. b = AuthzFreeAuditEvent(
  265. hOA
  266. );
  267. if (!b)
  268. {
  269. wprintf(L"AuthzFreeAuditInfo (no queue) failed with %d\n", GetLastError());
  270. return;
  271. }
  272. b = AuthziFreeAuditEventType(
  273. pAEI
  274. );
  275. if (!b)
  276. {
  277. wprintf(L"AuthzFreeAuditEventType failed with %d\n", GetLastError());
  278. return;
  279. }
  280. b = AuthziFreeAuditParams(
  281. pParams
  282. );
  283. if (!b)
  284. {
  285. wprintf(L"AuthzFreeAuditParams failed with %d\n", GetLastError());
  286. return;
  287. }
  288. b = AuthziFreeAuditQueue(
  289. hAAQ
  290. );
  291. if (!b)
  292. {
  293. wprintf(L"AuthzFreeAuditQueue failed with %d\n", GetLastError());
  294. return;
  295. }
  296. b = AuthzFreeHandle(
  297. hCache
  298. );
  299. if (!b)
  300. {
  301. wprintf(L"AuthzFreeHandle failed with %d\n", GetLastError());
  302. return;
  303. }
  304. }
  305. b = AuthzFreeContext(
  306. hCC
  307. );
  308. if (!b)
  309. {
  310. wprintf(L"AuthzFreeContext failed with %d\n", GetLastError());
  311. return;
  312. }
  313. b = AuthzFreeResourceManager(
  314. hRM
  315. );
  316. if (!b)
  317. {
  318. wprintf(L"AuthzFreeResourceManager failed with %d\n", GetLastError());
  319. return;
  320. }
  321. wprintf(L"Done. Press a key.\n");
  322. getchar();
  323. }