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.

671 lines
19 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <aclapi.h>
  7. #include <dsgetdc.h>
  8. #include <objbase.h>
  9. #include <iads.h>
  10. #include <lm.h>
  11. #include <winldap.h>
  12. #include <dsgetdc.h>
  13. #include <shlobj.h>
  14. #include <dsclient.h>
  15. #include <ntdsapi.h>
  16. #include <winbase.h>
  17. #include <ntsam.h>
  18. #include <ntlsa.h>
  19. #include <sddl.h>
  20. #include <seopaque.h>
  21. #include <sertlp.h>
  22. #include "authz.h"
  23. #define FirstAce(Acl) ((PVOID)((PUCHAR)(Acl) + sizeof(ACL)))
  24. #define NextAce(Ace) ((PVOID)((PUCHAR)(Ace) + ((PACE_HEADER)(Ace))->AceSize))
  25. #define MY_MAX 1024
  26. CHAR Buffer[MY_MAX];
  27. CHAR TypeListBuffer[MY_MAX];
  28. GUID Guid0 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x00}};
  29. GUID Guid1 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x01}};
  30. GUID Guid2 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x02}};
  31. GUID Guid3 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x03}};
  32. GUID Guid4 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x04}};
  33. GUID Guid5 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x05}};
  34. GUID Guid6 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x06}};
  35. GUID Guid7 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x07}};
  36. GUID Guid8 = {0x6da8a4ff, 0xe52, 0x11d0, {0xa2, 0x86, 0x00, 0xaa, 0x00, 0x30, 0x49, 0x08}};
  37. ULONG WORLD_SID[] = {0x101, 0x1000000, 0};
  38. // S-1-5-21-397955417-626881126-188441444-2791022
  39. ULONG KEDAR_SID[] = {0x00000501, 0x05000000, 0x00000015, 0x17b85159, 0x255d7266, 0x0b3b6364, 0x002a966e};
  40. // S-1-5-21-397955417-626881126-188441444-2204519
  41. ULONG RAHUL_SID[] = {0x00000501, 0x05000000, 0x00000015, 0x17b85159, 0x255d7266, 0x0b3b6364, 0x0021a367};
  42. // S-1-5-21-397955417-626881126-188441444-2101332
  43. ULONG ROBER_SID[] = {0x00000501, 0x05000000, 0x00000015, 0x17b85159, 0x255d7266, 0x0b3b6364, 0x00201054};
  44. ULONG LOCAL_RAJ_SID[] = {0x00000501, 0x05000000, 21, 1085031214, 57989841, 725345543, 1002};
  45. BOOL GlobalTruthValue = FALSE;
  46. BOOL
  47. MyAccessCheck(
  48. IN AUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext,
  49. IN PACE_HEADER pAce,
  50. IN PVOID pArgs OPTIONAL,
  51. IN OUT PBOOL pbAceApplicable
  52. )
  53. {
  54. *pbAceApplicable = GlobalTruthValue;
  55. return TRUE;
  56. }
  57. BOOL
  58. MyComputeDynamicGroups(
  59. IN AUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext,
  60. IN PVOID Args,
  61. OUT PSID_AND_ATTRIBUTES *pSidAttrArray,
  62. OUT PDWORD pSidCount,
  63. OUT PSID_AND_ATTRIBUTES *pRestrictedSidAttrArray,
  64. OUT PDWORD pRestrictedSidCount
  65. )
  66. {
  67. ULONG Length = 0;
  68. *pSidCount = 2;
  69. *pRestrictedSidCount = 0;
  70. *pRestrictedSidAttrArray = 0;
  71. Length = RtlLengthSid((PSID) KEDAR_SID);
  72. Length += RtlLengthSid((PSID) RAHUL_SID);
  73. if (!(*pSidAttrArray = malloc(sizeof(SID_AND_ATTRIBUTES) * 2 + Length)))
  74. {
  75. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  76. return FALSE;
  77. }
  78. (*pSidAttrArray)[0].Attributes = SE_GROUP_ENABLED;
  79. (*pSidAttrArray)[0].Sid = ((PUCHAR) (*pSidAttrArray)) + 2 * sizeof(SID_AND_ATTRIBUTES);
  80. RtlCopySid(Length/2, (*pSidAttrArray)[0].Sid, (PSID) KEDAR_SID);
  81. (*pSidAttrArray)[1].Attributes = SE_GROUP_USE_FOR_DENY_ONLY;
  82. (*pSidAttrArray)[1].Sid = ((PUCHAR) (*pSidAttrArray)) + 2 * sizeof(SID_AND_ATTRIBUTES) + Length/2;
  83. RtlCopySid(Length/2, (*pSidAttrArray)[1].Sid, (PSID) RAHUL_SID);
  84. // wprintf(L"Returning two groups in COMPUTE_DYNAMIC\n");
  85. return TRUE;
  86. }
  87. VOID
  88. MyFreeDynamicGroups (
  89. IN PSID_AND_ATTRIBUTES pSidAttrArray
  90. )
  91. {
  92. if (pSidAttrArray) free(pSidAttrArray);
  93. }
  94. ULONG Special[] = {0x101, 0x2000000, 2};
  95. #if 1
  96. void _cdecl wmain( int argc, WCHAR * argv[] )
  97. {
  98. NTSTATUS Status = STATUS_SUCCESS;
  99. BOOL b = TRUE;
  100. AUTHZ_RESOURCE_MANAGER_HANDLE RM = NULL;
  101. HANDLE hToken = NULL;
  102. LUID luid = {0xdead,0xbeef};
  103. AUTHZ_CLIENT_CONTEXT_HANDLE CC = NULL;
  104. AUTHZ_ACCESS_REQUEST Request;
  105. PAUTHZ_ACCESS_REPLY pReply = (PAUTHZ_ACCESS_REPLY) Buffer;
  106. PSECURITY_DESCRIPTOR pSD = NULL;
  107. DWORD dwErr;
  108. ULONG i = 0;
  109. PACE_HEADER Ace = NULL;
  110. DWORD AceCount = 0;
  111. LUID MySeLuid = {0, SE_SECURITY_PRIVILEGE};
  112. LUID MyOwLuid = {0, SE_TAKE_OWNERSHIP_PRIVILEGE};
  113. DWORD Len = 0;
  114. SID_AND_ATTRIBUTES SidAttr[10];
  115. AUTHZ_AUDIT_INFO_HANDLE AuditInfo;
  116. PAUTHZ_AUDIT_INFO_HANDLE pAuditInfo = NULL;
  117. CHAR TokenBuff[100];
  118. PTOKEN_PRIVILEGES TokenPriv = (PTOKEN_PRIVILEGES) TokenBuff;
  119. AUTHZ_HANDLE AuthHandle = 0;
  120. AUTHZ_HANDLE AuthHandlePS = 0;
  121. PACL pAcl = NULL;
  122. /*
  123. PWCHAR StringSD = L"O:BAG:DUD:(D;;0xFFFFFF;;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-20) (A;;0xFFFFFF;;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-21) (D;;0x60000;;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-201) (OA;;0x1;00000000-0000-0000-00000000;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-201) S:(AU;IDSA;SD;;;DU)";
  124. PWCHAR StringSD = L"O:BAG:DUD:(D;;0xFFFFFF;;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-20)
  125. (A;;0xFFFFFF;;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-25)
  126. (D;;0x60000;;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-201)
  127. (A;;0x1;;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-201)
  128. (OA;;0x2;00000000-0000-0000-00000001;;s-0x1-000000000005-15-65d637a8-5274c742-3f32a78a-201)
  129. (OD;;0x2;00000000-0000-0000-00000004;;s-0x1-000000000001-0)
  130. (OA;;0x4;00000000-0000-0000-00000002;;s-0x1-000000000005-20-220)
  131. (OA;;0x4;00000000-0000-0000-00000006;;s-0x1-000000000005-20-220)
  132. (OD;;0xC;00000000-0000-0000-00000000;;s-0x1-000000000005-20-221)
  133. (OA;;0x18;00000000-0000-0000-00000004;;s-0x1-000000000005-5-0-ae35)
  134. (OA;;0x38;00000000-0000-0000-00000001;;s-0x1-000000000002-0)
  135. (OA;;0xF90000;00000000-0000-0000-00000000;;s-0x1-000000000005-4)
  136. (OA;;0x1000000;00000000-0000-0000-00000004;;s-0x1-000000000005-b)
  137. S:(AU;IDSA;SD;;;DU)";
  138. */
  139. PWCHAR StringSD = L"O:BAG:DUD:(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)";
  140. // PWCHAR StringSD = L"O:BAG:DUD:(A;;0x40;;;SY)(A;;0x1;;;BA)S:(AU;IDSA;SD;;;DU)";
  141. // PWCHAR StringSD = L"O:BAG:DUD:(A;;0x40;;;SY)(A;;0x1;;;PS)S:(AU;IDSA;SD;;;DU)";
  142. TokenPriv->PrivilegeCount = 2;
  143. TokenPriv->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  144. TokenPriv->Privileges[0].Luid = MySeLuid;
  145. TokenPriv->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;
  146. TokenPriv->Privileges[1].Luid = MyOwLuid;
  147. b = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSD, SDDL_REVISION_1, &pSD, NULL);
  148. if (!b)
  149. {
  150. wprintf(L"SDDL failed with %d\n", GetLastError());
  151. return;
  152. }
  153. if (argc == 2)
  154. {
  155. wprintf(L"\n\n CALLBACK ACES!!!!\n\n");
  156. pAcl = RtlpDaclAddrSecurityDescriptor((PISECURITY_DESCRIPTOR) pSD);
  157. // pAcl = (PACL) (((SECURITY_DESCRIPTOR_RELATIVE *) pSD)->Dacl + (PUCHAR) pSD);
  158. AceCount = pAcl->AceCount;
  159. for (i = 0, Ace = FirstAce(pAcl); i < AceCount; i++, Ace = NextAce(Ace))
  160. {
  161. switch(Ace->AceType)
  162. {
  163. case ACCESS_ALLOWED_ACE_TYPE:
  164. Ace->AceType = ACCESS_ALLOWED_CALLBACK_ACE_TYPE;
  165. break;
  166. case ACCESS_ALLOWED_OBJECT_ACE_TYPE:
  167. Ace->AceType = ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE;
  168. break;
  169. }
  170. }
  171. }
  172. b = AuthzInitializeResourceManager(
  173. MyAccessCheck,
  174. MyComputeDynamicGroups,
  175. MyFreeDynamicGroups,
  176. NULL,
  177. 0, // Flags
  178. &RM
  179. );
  180. if (!b)
  181. {
  182. wprintf(L"AuthzRMInitialize failed with %d\n", GetLastError());
  183. return;
  184. }
  185. else
  186. {
  187. wprintf(L"AuthzRMInitialize succeeded\n");
  188. }
  189. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
  190. {
  191. wprintf(L"OpenProcessToken failed with %d\n", GetLastError());
  192. return;
  193. }
  194. else
  195. {
  196. wprintf(L"OpenProcessToken succeeded\n");
  197. }
  198. wprintf(L"Calling initialize token\n");
  199. b = AdjustTokenPrivileges(
  200. hToken,
  201. FALSE,
  202. TokenPriv,
  203. 100,
  204. NULL,
  205. NULL
  206. );
  207. if (!b)
  208. {
  209. wprintf(L"Can not adjust privilege, %x\n", GetLastError());
  210. // return;
  211. }
  212. if (!wcscmp(argv[2], L"User"))
  213. {
  214. b = AuthzInitializeContextFromSid(
  215. // (PSID) LOCAL_RAJ_SID,
  216. (PSID) KEDAR_SID,
  217. NULL,
  218. RM,
  219. NULL,
  220. luid,
  221. 0,
  222. NULL,
  223. &CC
  224. );
  225. }
  226. else
  227. {
  228. b = AuthzInitializeContextFromToken(
  229. hToken,
  230. RM,
  231. NULL,
  232. luid,
  233. 0,
  234. NULL,
  235. &CC
  236. );
  237. }
  238. if (!wcscmp(argv[3], L"Audit"))
  239. {
  240. pAuditInfo = &AuditInfo;
  241. }
  242. pAuditInfo = &AuditInfo;
  243. if (!b)
  244. {
  245. wprintf(L"AuthzInitializeContextFromToken failed with %d\n", GetLastError());
  246. return;
  247. }
  248. else
  249. {
  250. wprintf(L"AuthzInitializeContextFromToken succeeded\n");
  251. }
  252. Request.DesiredAccess = MAXIMUM_ALLOWED;
  253. Request.DesiredAccess = wcstol(argv[1], NULL, 16);
  254. wprintf(L"Desired = %x\n", Request.DesiredAccess);
  255. Request.ObjectTypeList = (POBJECT_TYPE_LIST) TypeListBuffer;
  256. Request.ObjectTypeList[0].Level = 0;
  257. Request.ObjectTypeList[0].ObjectType = &Guid0;
  258. Request.ObjectTypeList[0].Sbz = 0;
  259. Request.ObjectTypeList[1].Level = 1;
  260. Request.ObjectTypeList[1].ObjectType = &Guid1;
  261. Request.ObjectTypeList[1].Sbz = 0;
  262. Request.ObjectTypeList[2].Level = 2;
  263. Request.ObjectTypeList[2].ObjectType = &Guid2;
  264. Request.ObjectTypeList[2].Sbz = 0;
  265. Request.ObjectTypeList[3].Level = 2;
  266. Request.ObjectTypeList[3].ObjectType = &Guid3;
  267. Request.ObjectTypeList[3].Sbz = 0;
  268. Request.ObjectTypeList[4].Level = 1;
  269. Request.ObjectTypeList[4].ObjectType = &Guid4;
  270. Request.ObjectTypeList[4].Sbz = 0;
  271. Request.ObjectTypeList[5].Level = 2;
  272. Request.ObjectTypeList[5].ObjectType = &Guid5;
  273. Request.ObjectTypeList[5].Sbz = 0;
  274. Request.ObjectTypeList[6].Level = 3;
  275. Request.ObjectTypeList[6].ObjectType = &Guid6;
  276. Request.ObjectTypeList[6].Sbz = 0;
  277. Request.ObjectTypeList[7].Level = 2;
  278. Request.ObjectTypeList[7].ObjectType = &Guid7;
  279. Request.ObjectTypeList[7].Sbz = 0;
  280. Request.ObjectTypeListLength = 8;
  281. Request.OptionalArguments = NULL;
  282. Request.PrincipalSelfSid = NULL;
  283. pReply->ResultListLength = 8;
  284. pReply->Error = (PDWORD) (((PCHAR) pReply) + sizeof(AUTHZ_ACCESS_REPLY));
  285. pReply->GrantedAccessMask = (PACCESS_MASK) (pReply->Error + pReply->ResultListLength);
  286. b = AuthzAccessCheck(
  287. CC,
  288. &Request,
  289. pAuditInfo,
  290. pSD,
  291. NULL,
  292. 0,
  293. pReply,
  294. &AuthHandle
  295. );
  296. if (!b)
  297. {
  298. wprintf(L"AccessCheck no SELF failed\n");
  299. return;
  300. }
  301. else
  302. {
  303. wprintf(L"\nAccessCheck no SELF succeeded\n\n");
  304. for (i = 0; i < pReply->ResultListLength; i++)
  305. {
  306. wprintf(L"i = %d, AccessMask = %x, Error = %d\n",
  307. i, pReply->GrantedAccessMask[i], pReply->Error[i]);
  308. }
  309. }
  310. Request.PrincipalSelfSid = (PSID) RAHUL_SID;
  311. GlobalTruthValue = TRUE;
  312. SidAttr[0].Attributes = SE_GROUP_ENABLED;
  313. SidAttr[0].Sid = (PSID) Special;
  314. //
  315. // b = AuthzAddSidsToContext(
  316. // CC,
  317. // SidAttr,
  318. // 1,
  319. // NULL,
  320. // 0
  321. // );
  322. //
  323. // if (!b)
  324. // {
  325. // wprintf(L"AuthzNormalGroups failed with %d\n", GetLastError());
  326. // return;
  327. // }
  328. //
  329. b = AuthzAccessCheck(
  330. CC,
  331. &Request,
  332. pAuditInfo,
  333. pSD,
  334. NULL,
  335. 0,
  336. pReply,
  337. &AuthHandlePS
  338. );
  339. if (!b)
  340. {
  341. wprintf(L"AccessCheck SELF = ROBER failed\n");
  342. return;
  343. }
  344. else
  345. {
  346. wprintf(L"\nAccessCheck SELF + ROBER succeeded\n\n");
  347. for (i = 0; i < pReply->ResultListLength; i++)
  348. {
  349. wprintf(L"i = %d, AccessMask = %x, Error = %d\n",
  350. i, pReply->GrantedAccessMask[i], pReply->Error[i]);
  351. }
  352. }
  353. Request.PrincipalSelfSid = NULL;
  354. GlobalTruthValue = FALSE;
  355. if (AuthHandlePS)
  356. {
  357. b = AuthzCachedAccessCheck(
  358. AuthHandlePS,
  359. &Request,
  360. pAuditInfo,
  361. pReply
  362. );
  363. if (!b)
  364. {
  365. wprintf(L"CachedAccessCheck failed\n");
  366. return;
  367. }
  368. else
  369. {
  370. wprintf(L"\nCachedAccessCheck succeeded\n\n");
  371. for (i = 0; i < pReply->ResultListLength; i++)
  372. {
  373. wprintf(L"i = %d, AccessMask = %x, Error = %d\n",
  374. i, pReply->GrantedAccessMask[i], pReply->Error[i]);
  375. }
  376. }
  377. AuthzFreeHandle(AuthHandlePS);
  378. }
  379. else
  380. {
  381. wprintf(L"No CachedAccessCheck done since NULL = AuthHandlePS\n");
  382. }
  383. if (AuthHandle)
  384. {
  385. Request.PrincipalSelfSid = (PSID) RAHUL_SID;
  386. GlobalTruthValue = TRUE;
  387. b = AuthzCachedAccessCheck(
  388. AuthHandle,
  389. &Request,
  390. pAuditInfo,
  391. pReply
  392. );
  393. if (!b)
  394. {
  395. wprintf(L"CachedAccessCheck failed\n");
  396. return;
  397. }
  398. else
  399. {
  400. wprintf(L"\nCachedAccessCheck succeeded\n\n");
  401. for (i = 0; i < pReply->ResultListLength; i++)
  402. {
  403. wprintf(L"i = %d, AccessMask = %x, Error = %d\n",
  404. i, pReply->GrantedAccessMask[i], pReply->Error[i]);
  405. }
  406. }
  407. AuthzFreeHandle(AuthHandle);
  408. }
  409. else
  410. {
  411. wprintf(L"No CachedAccessCheck done since NULL = AuthHandle\n");
  412. }
  413. AuthzFreeContext(CC);
  414. return;
  415. }
  416. #else
  417. void _cdecl wmain( int argc, WCHAR * argv[] )
  418. {
  419. NTSTATUS Status = STATUS_SUCCESS;
  420. ULONG i = 0, j = 0;
  421. BOOL b = TRUE;
  422. AUTHZ_RESOURCE_MANAGER RM = NULL;
  423. HANDLE hToken = NULL;
  424. LUID luid = {0xdead,0xbeef};
  425. AUTHZ_CLIENT_CONTEXT_HANDLE CC = NULL;
  426. AUTHZ_ACCESS_REQUEST Request;
  427. PAUTHZ_ACCESS_REPLY pReply = (PAUTHZ_ACCESS_REPLY) Buffer;
  428. PSECURITY_DESCRIPTOR pSD = NULL;
  429. DWORD dwErr;
  430. PACE_HEADER Ace = NULL;
  431. DWORD AceCount = 0;
  432. LUID MySeLuid = {0, SE_SECURITY_PRIVILEGE};
  433. LUID MyOwLuid = {0, SE_TAKE_OWNERSHIP_PRIVILEGE};
  434. DWORD Len = 0;
  435. SID_AND_ATTRIBUTES SidAttr[10];
  436. AUTHZ_AUDIT_INFO AuditInfo;
  437. PAUTHZ_AUDIT_INFO pAuditInfo = NULL;
  438. CHAR TokenBuff[100];
  439. PTOKEN_PRIVILEGES TokenPriv = (PTOKEN_PRIVILEGES) TokenBuff;
  440. AUTHZ_HANDLE AuthHandle = 0;
  441. AUTHZ_HANDLE AuthHandlePS = 0;
  442. PACL pAcl = NULL;
  443. PWCHAR StringSD = L"O:BAG:DUD:(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)";
  444. b = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSD, SDDL_REVISION_1, &pSD, NULL);
  445. if (!b)
  446. {
  447. wprintf(L"SDDL failed with %d\n", GetLastError());
  448. return;
  449. }
  450. b = AuthzRMInitialize(
  451. MyAccessCheck,
  452. MyComputeDynamicGroups,
  453. MyFreeDynamicGroups,
  454. NULL,
  455. 0,
  456. &RM
  457. );
  458. if (!b)
  459. {
  460. wprintf(L"AuthzRMInitialize failed with %d\n", GetLastError());
  461. return;
  462. }
  463. else
  464. {
  465. wprintf(L"AuthzRMInitialize succeeded\n");
  466. }
  467. Request.DesiredAccess = 0x101;
  468. wprintf(L"Desired = %x\n", Request.DesiredAccess);
  469. Request.ObjectTypeList = (POBJECT_TYPE_LIST) TypeListBuffer;
  470. Request.ObjectTypeList[0].Level = 0;
  471. Request.ObjectTypeList[0].ObjectType = &Guid0;
  472. Request.ObjectTypeList[0].Sbz = 0;
  473. Request.ObjectTypeList[1].Level = 1;
  474. Request.ObjectTypeList[1].ObjectType = &Guid1;
  475. Request.ObjectTypeList[1].Sbz = 0;
  476. Request.ObjectTypeList[2].Level = 2;
  477. Request.ObjectTypeList[2].ObjectType = &Guid2;
  478. Request.ObjectTypeList[2].Sbz = 0;
  479. Request.ObjectTypeList[3].Level = 2;
  480. Request.ObjectTypeList[3].ObjectType = &Guid3;
  481. Request.ObjectTypeList[3].Sbz = 0;
  482. Request.ObjectTypeList[4].Level = 1;
  483. Request.ObjectTypeList[4].ObjectType = &Guid4;
  484. Request.ObjectTypeList[4].Sbz = 0;
  485. Request.ObjectTypeList[5].Level = 2;
  486. Request.ObjectTypeList[5].ObjectType = &Guid5;
  487. Request.ObjectTypeList[5].Sbz = 0;
  488. Request.ObjectTypeList[6].Level = 2;
  489. Request.ObjectTypeList[6].ObjectType = &Guid6;
  490. Request.ObjectTypeList[6].Sbz = 0;
  491. Request.ObjectTypeListLength = 7;
  492. Request.OptionalArguments = NULL;
  493. Request.PrincipalSelfSid = NULL;
  494. pReply->ResultListLength = 7;
  495. pReply->Error = (PDWORD) (((PCHAR) pReply) + sizeof(AUTHZ_ACCESS_REPLY));
  496. pReply->GrantedAccessMask = (PACCESS_MASK) (pReply->Error + pReply->ResultListLength);
  497. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
  498. {
  499. // wprintf(L"OpenProcessToken failed with %d\n", GetLastError());
  500. return;
  501. }
  502. else
  503. {
  504. // wprintf(L"OpenProcessToken succeeded\n");
  505. }
  506. // wprintf(L"Calling initialize token\n");
  507. b = AuthzInitializeContextFromToken(
  508. hToken,
  509. RM,
  510. NULL,
  511. luid,
  512. 0,
  513. NULL,
  514. &CC
  515. );
  516. if (!b)
  517. {
  518. // wprintf(L"AuthzInitializeContextFromToken failed\n");
  519. return;
  520. }
  521. for (i = 0; i < 100000; i++)
  522. {
  523. DWORD StartTime, EndTime;
  524. StartTime = GetCurrentTime();
  525. for (j = 0; j < 50000; j++)
  526. {
  527. b = AuthzAccessCheck(
  528. CC,
  529. &Request,
  530. pAuditInfo,
  531. pSD,
  532. NULL,
  533. 0,
  534. pReply,
  535. 0
  536. );
  537. if (!b)
  538. {
  539. // wprintf(L"AccessCheck no SELF failed\n");
  540. return;
  541. }
  542. }
  543. EndTime = GetCurrentTime();
  544. wprintf(L"Time taken %d\n", EndTime - StartTime);
  545. }
  546. AuthzFreeContext(CC);
  547. CloseHandle(hToken);
  548. }
  549. #endif