Source code of Windows XP (NT5)
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.

888 lines
26 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1996.
  5. //
  6. // File: NTMARTAT.C
  7. //
  8. // Contents: NT Marta provider unit test
  9. //
  10. // History: 29-Aug-96 MacM Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <windows.h>
  14. #include <accprov.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. //
  18. // These come from access.hxx
  19. //
  20. #define SLEN(x) ((sizeof(x) / sizeof(CHAR)) - 1)
  21. void *AccAlloc(ULONG cSize);
  22. #if DBG == 1
  23. void AccFree(PVOID pv);
  24. #else
  25. #define AccFree LocalFree
  26. #endif
  27. //
  28. // Object types
  29. //
  30. #define OT_FILEA "FILE"
  31. #define OT_SERVICEA "SERVICE"
  32. #define OT_PRINTERA "PRINTER"
  33. #define OT_REGISTRYA "REGISTRY"
  34. #define OT_SHAREA "SHARE"
  35. #define OT_KERNELA "KERNEL"
  36. #define OT_DSA "DS"
  37. #define OT_DSALLA "DS_ALL"
  38. #define OT_CAPLEVELA "capclass"
  39. #define OT_CAPLEVELA_LEN SLEN(OT_CAPLEVELA)
  40. #define OT_TRUSTEEA "set"
  41. #define OT_TRUSTEEA_LEN SLEN(OT_TRUSTEEA)
  42. #define OT_ACCESSA "setaccess"
  43. #define OT_ACCESSA_LEN SLEN(OT_ACCESSA)
  44. #define OT_SEINFOA "seinfo"
  45. #define OT_SEINFOA_LEN SLEN(OT_SEINFOA)
  46. #define OT_GTRUSTEEA "grant"
  47. #define OT_GTRUSTEEA_LEN SLEN(OT_GTRUSTEEA)
  48. #define OT_GACCESSA "grantaccess"
  49. #define OT_GACCESSA_LEN SLEN(OT_GACCESSA)
  50. #define OT_RTRUSTEEA "revoke"
  51. #define OT_RTRUSTEEA_LEN SLEN(OT_RTRUSTEEA)
  52. //
  53. // Macro to determine if a command line parameter matches
  54. //
  55. #define CMDLINE_MATCH(index, str, len) \
  56. (_strnicmp(argv[index],str,len) == 0 && argv[index][len] == ':')
  57. //+---------------------------------------------------------------------------
  58. //
  59. // Function: Usage
  60. //
  61. // Synopsis: Displays the expected usage
  62. //
  63. // Arguments: None
  64. //
  65. // Returns: VOID
  66. //
  67. // Notes:
  68. //
  69. //----------------------------------------------------------------------------
  70. void Usage()
  71. {
  72. printf("USAGE: NTMARTA objectname objecttype <%s:x> <%s:x> [<%s:x> <%s:x>] "
  73. "[<%s:x> <%s:x>] <%s:x>\n",
  74. OT_CAPLEVELA,
  75. OT_SEINFOA,
  76. OT_TRUSTEEA,
  77. OT_ACCESSA,
  78. OT_GTRUSTEEA,
  79. OT_GACCESSA,
  80. OT_RTRUSTEEA);
  81. printf(" tests NT MARTA provider\n");
  82. printf(" objectname = path to the object\n");
  83. printf(" objecttype = %s\n",OT_FILEA);
  84. printf(" %s\n",OT_SERVICEA);
  85. printf(" %s\n",OT_PRINTERA);
  86. printf(" %s\n",OT_REGISTRYA);
  87. printf(" %s\n",OT_SHAREA);
  88. printf(" %s\n",OT_KERNELA);
  89. printf(" %s\n",OT_DSA);
  90. printf(" %s\n",OT_DSALLA);
  91. printf(" <%s:x> where x is the capabilities class to query for\n",
  92. OT_CAPLEVELA);
  93. printf(" <%s:x> where x is the SeInfo to get/set\n",
  94. OT_SEINFOA);
  95. printf(" <%s:x> where x is the trustee to set\n",
  96. OT_TRUSTEEA);
  97. printf(" <%s:x> where x is the access to set\n",
  98. OT_ACCESSA);
  99. printf(" <%s:x> where x is the trustee to grant\n",
  100. OT_GTRUSTEEA);
  101. printf(" <%s:x> where x is the access to grant\n",
  102. OT_GACCESSA);
  103. printf(" <%s:x> where x is the trustee to revoke\n",
  104. OT_RTRUSTEEA);
  105. }
  106. //+---------------------------------------------------------------------------
  107. //
  108. // Function: DumpAccessEntry
  109. //
  110. // Synopsis: Displays the access entry to the screen
  111. //
  112. // Arguments: [IN pAE] -- Access entry to display
  113. //
  114. // Returns: VOID
  115. //
  116. // Notes:
  117. //
  118. //----------------------------------------------------------------------------
  119. void DumpAccessEntry(PACTRL_ACCESS_ENTRY pAE)
  120. {
  121. printf("\tPACTRL_ACCESS_ENTRY@%lu\n",pAE);
  122. printf("\t\tTrustee: %ws\n", pAE->Trustee.ptstrName);
  123. printf("\t\tfAccessFlags: 0x%lx\n", pAE->fAccessFlags);
  124. printf("\t\tAccess: 0x%lx\n", pAE->Access);
  125. printf("\t\tProvSpecificAccess: 0x%lx\n", pAE->ProvSpecificAccess);
  126. printf("\t\tInheritance: 0x%lx\n", pAE->Inheritance);
  127. printf("\t\tlpInheritProperty: 0x%lx\n", pAE->lpInheritProperty);
  128. }
  129. //+---------------------------------------------------------------------------
  130. //
  131. // Function: DumpAList
  132. //
  133. // Synopsis: Displays an access or audit list
  134. //
  135. // Arguments: [IN pAList] -- AList to display
  136. //
  137. // Returns: VOID
  138. //
  139. // Notes:
  140. //
  141. //----------------------------------------------------------------------------
  142. void DumpAList(PACTRL_ALIST pAList)
  143. {
  144. ULONG iIndex, iAE;
  145. for(iIndex = 0; iIndex < pAList->cEntries; iIndex++)
  146. {
  147. printf("\tProperty: %ws\n",
  148. pAList->pPropertyAccessList[iIndex].lpProperty);
  149. for(iAE = 0;
  150. iAE < pAList->pPropertyAccessList[iIndex].pAccessEntryList->
  151. cEntries;
  152. iAE++)
  153. {
  154. DumpAccessEntry(&(pAList->pPropertyAccessList[iIndex].
  155. pAccessEntryList->pAccessList[iAE]));
  156. }
  157. }
  158. }
  159. //+---------------------------------------------------------------------------
  160. //
  161. // Function: GetAndDumpInfo
  162. //
  163. // Synopsis: Gets and displays the access info for the specified object
  164. //
  165. // Arguments: [IN pwszObject] -- Object path
  166. // [IN ObjType] -- Object type
  167. // [IN SeInfo] -- Security info to get
  168. // [OUT ppAccess] -- Where to return access list
  169. // [OUT ppAudit] -- Where to return audit list
  170. // [OUT ppOwner] -- Where to return owner
  171. // [OUT ppGroup] -- Where to return group
  172. //
  173. // Returns: ERRORS_SUCCESS -- Success
  174. //
  175. // Notes:
  176. //
  177. //----------------------------------------------------------------------------
  178. DWORD GetAndDumpInfo(PCWSTR pwszObject,
  179. SE_OBJECT_TYPE ObjType,
  180. SECURITY_INFORMATION SeInfo,
  181. PACTRL_ACCESS *ppAccess,
  182. PACTRL_AUDIT *ppAudit,
  183. PTRUSTEE *ppOwner,
  184. PTRUSTEE *ppGroup)
  185. {
  186. DWORD dwErr;
  187. ULONG iIndex;
  188. *ppAccess = NULL;
  189. *ppAudit = NULL;
  190. *ppOwner = NULL;
  191. *ppGroup = NULL;
  192. dwErr = AccProvGetAllRights((LPCWSTR)pwszObject,
  193. ObjType,
  194. NULL,
  195. (SeInfo & DACL_SECURITY_INFORMATION) != 0 ?
  196. ppAccess :
  197. NULL,
  198. (SeInfo & SACL_SECURITY_INFORMATION) != 0 ?
  199. ppAudit :
  200. NULL,
  201. (SeInfo & OWNER_SECURITY_INFORMATION) != 0 ?
  202. ppOwner :
  203. NULL,
  204. (SeInfo & GROUP_SECURITY_INFORMATION) != 0 ?
  205. ppGroup :
  206. NULL);
  207. if(dwErr == ERROR_SUCCESS)
  208. {
  209. if(*ppOwner != NULL)
  210. {
  211. printf("\tOwner: %ws\n",
  212. (*ppOwner)->ptstrName);
  213. }
  214. if(*ppGroup != NULL)
  215. {
  216. printf("\tGroup: %ws\n",
  217. (*ppGroup)->ptstrName);
  218. }
  219. if(*ppAccess != NULL)
  220. {
  221. DumpAList(*ppAccess);
  222. }
  223. if(*ppAudit != NULL)
  224. {
  225. DumpAList(*ppAudit);
  226. }
  227. }
  228. return(dwErr);
  229. }
  230. //+---------------------------------------------------------------------------
  231. //
  232. // Function: main
  233. //
  234. // Synopsis: The main
  235. //
  236. // Arguments: [IN argc] -- Count of arguments
  237. // [IN argv] -- List of arguments
  238. //
  239. // Returns: 0 -- Success
  240. // 1 -- Failure
  241. //
  242. // Notes:
  243. //
  244. //----------------------------------------------------------------------------
  245. __cdecl main(INT argc,
  246. CHAR *argv[])
  247. {
  248. WCHAR wszPath[MAX_PATH + 1];
  249. SE_OBJECT_TYPE ObjType= SE_UNKNOWN_OBJECT_TYPE;
  250. ULONG dwCapsClass = 0;
  251. ULONG dwAccess = 0;
  252. ULONG dwGrantAcc = 0;
  253. WCHAR wszTrustee[MAX_PATH + 1];
  254. WCHAR wszGrant[MAX_PATH + 1];
  255. WCHAR wszRevoke[MAX_PATH + 1];
  256. ULONG cAccess = 0; // Used to do argument validation
  257. ULONG cGrant = 0;
  258. ULONG cRevoke = 0;
  259. DWORD dwCaps;
  260. ULONG iIndex;
  261. DWORD dwErr;
  262. SECURITY_INFORMATION SeInfo = DACL_SECURITY_INFORMATION |
  263. OWNER_SECURITY_INFORMATION;
  264. PACTRL_ACCESS_INFO pAccInfo;
  265. ULONG cAccInfo;
  266. ULONG fAccFlags;
  267. PACTRL_ACCESS pAccess = NULL;
  268. PACTRL_AUDIT pAudit = NULL;
  269. PTRUSTEE pOwner = NULL;
  270. PTRUSTEE pGroup = NULL;
  271. if(argc < 3)
  272. {
  273. Usage();
  274. exit(1);
  275. }
  276. if(strcmp(argv[1], "-?") == 0 ||
  277. strcmp(argv[1], "/?") == 0)
  278. {
  279. Usage();
  280. exit(1);
  281. }
  282. mbstowcs(wszPath,
  283. argv[1],
  284. strlen(argv[1]) + 1);
  285. //
  286. // Figure out what the object type is
  287. //
  288. if(_stricmp(argv[2], OT_FILEA) == 0)
  289. {
  290. ObjType = SE_FILE_OBJECT;
  291. }
  292. else if (_stricmp(argv[2],OT_SERVICEA) == 0)
  293. {
  294. ObjType = SE_SERVICE;
  295. }
  296. else if (_stricmp(argv[2],OT_PRINTERA) == 0)
  297. {
  298. ObjType = SE_PRINTER;
  299. }
  300. else if (_stricmp(argv[2],OT_REGISTRYA) == 0)
  301. {
  302. ObjType = SE_REGISTRY_KEY;
  303. }
  304. else if (_stricmp(argv[2],OT_SHAREA) == 0)
  305. {
  306. ObjType = SE_LMSHARE;
  307. }
  308. else if (_stricmp(argv[2],OT_KERNELA) == 0)
  309. {
  310. ObjType = SE_KERNEL_OBJECT;
  311. }
  312. else if (_stricmp(argv[2],OT_DSA) == 0)
  313. {
  314. ObjType = SE_DS_OBJECT;
  315. }
  316. else if (_stricmp(argv[2],OT_DSALLA) == 0)
  317. {
  318. ObjType = SE_DS_OBJECT_ALL;
  319. }
  320. for(iIndex = 3; iIndex < (ULONG)argc; iIndex++)
  321. {
  322. printf("processing cmdline entry: %s\n", argv[iIndex]);
  323. if(CMDLINE_MATCH(iIndex, OT_CAPLEVELA, OT_CAPLEVELA_LEN))
  324. {
  325. dwCapsClass = atol(argv[iIndex] + OT_CAPLEVELA_LEN + 1);
  326. }
  327. else if(CMDLINE_MATCH(iIndex,OT_ACCESSA,OT_ACCESSA_LEN))
  328. {
  329. dwAccess = atol(argv[iIndex] + OT_ACCESSA_LEN + 1);
  330. cAccess++;
  331. }
  332. else if(CMDLINE_MATCH(iIndex,OT_TRUSTEEA,OT_TRUSTEEA_LEN))
  333. {
  334. mbstowcs(wszTrustee,
  335. argv[iIndex] + OT_TRUSTEEA_LEN + 1,
  336. strlen(argv[iIndex] + OT_TRUSTEEA_LEN + 1) + 1);
  337. cAccess++;
  338. }
  339. else if(CMDLINE_MATCH(iIndex, OT_SEINFOA, OT_SEINFOA_LEN))
  340. {
  341. SeInfo = (SECURITY_INFORMATION)
  342. atol(argv[iIndex] + OT_SEINFOA_LEN + 1);
  343. }
  344. else if (CMDLINE_MATCH(iIndex, OT_GTRUSTEEA, OT_GTRUSTEEA_LEN))
  345. {
  346. mbstowcs(wszGrant,
  347. argv[iIndex] + OT_GTRUSTEEA_LEN + 1,
  348. strlen(argv[iIndex] + OT_GTRUSTEEA_LEN + 1) + 1);
  349. cGrant++;
  350. }
  351. else if (CMDLINE_MATCH(iIndex, OT_RTRUSTEEA, OT_RTRUSTEEA_LEN))
  352. {
  353. mbstowcs(wszRevoke,
  354. argv[iIndex] + OT_RTRUSTEEA_LEN + 1,
  355. strlen(argv[iIndex] + OT_RTRUSTEEA_LEN + 1) + 1);
  356. cRevoke++;
  357. }
  358. else if(CMDLINE_MATCH(iIndex,OT_GACCESSA,OT_GACCESSA_LEN))
  359. {
  360. dwGrantAcc = atol(argv[iIndex] + OT_GACCESSA_LEN + 1);
  361. cGrant++;
  362. }
  363. else
  364. {
  365. printf("Unknown argument \"%s\" being ignorned\n", argv[iIndex]);
  366. }
  367. }
  368. //
  369. // Ok, first, we'll try the capabilities
  370. //
  371. printf("\nCAPABILITIES: dwCapsClass: %ld\n", dwCapsClass);
  372. AccProvGetCapabilities(dwCapsClass,
  373. &dwCaps);
  374. printf("AccProvGetCapabilities returned capabilities %ld\n",
  375. dwCaps);
  376. //
  377. // Then, get the list of supported rights
  378. //
  379. dwErr = AccProvGetAccessInfoPerObjectType((LPCWSTR)wszPath,
  380. ObjType,
  381. &cAccInfo,
  382. &pAccInfo,
  383. &fAccFlags);
  384. if(dwErr == ERROR_SUCCESS)
  385. {
  386. printf("AccessInfo: %lu objects\n",
  387. cAccInfo);
  388. printf("AccessFlags: %lu\n",
  389. fAccFlags);
  390. for(iIndex = 0; iIndex < cAccInfo; iIndex++)
  391. {
  392. printf("\t%ws\t\t0x%08lx\n",
  393. pAccInfo[iIndex].lpAccessPermissionName,
  394. pAccInfo[iIndex].fAccessPermission);
  395. }
  396. AccFree(pAccInfo);
  397. }
  398. printf("\nACCESSIBILITY\n");
  399. //
  400. // Then, the accessibility stuff
  401. //
  402. dwErr = AccProvIsObjectAccessible((LPCWSTR)wszPath,
  403. ObjType);
  404. if(dwErr == ERROR_SUCCESS)
  405. {
  406. printf("Object %ws is accessible\n",
  407. wszPath);
  408. //
  409. // Do it again, for caching purposes
  410. //
  411. dwErr = AccProvIsObjectAccessible((LPCWSTR)wszPath,
  412. ObjType);
  413. if(dwErr == ERROR_SUCCESS)
  414. {
  415. printf("Object %ws is still accessible\n",
  416. wszPath);
  417. }
  418. else
  419. {
  420. printf("Second access attempt on %ws failed with %lu\n",
  421. wszPath,
  422. dwErr);
  423. }
  424. }
  425. else
  426. {
  427. printf("First access attempt on %ws failed with %lu\n",
  428. wszPath,
  429. dwErr);
  430. }
  431. if(dwErr == ERROR_SUCCESS)
  432. {
  433. //
  434. // First, get the rights for the object
  435. //
  436. printf("\nACCESS - GetAllRights\n");
  437. dwErr = GetAndDumpInfo((LPCWSTR)wszPath,
  438. ObjType,
  439. SeInfo,
  440. &pAccess,
  441. &pAudit,
  442. &pOwner,
  443. &pGroup);
  444. if(dwErr != ERROR_SUCCESS)
  445. {
  446. printf("GetAllRights failed with %lu\n",
  447. dwErr);
  448. }
  449. }
  450. //
  451. // If that worked, try setting it...
  452. //
  453. if(dwErr == ERROR_SUCCESS && cAccess == 2)
  454. {
  455. DWORD dwErr2;
  456. ACTRL_ALIST NewAccess;
  457. ACTRL_PROPERTY_ENTRY APE;
  458. ACTRL_ACCESS_ENTRY_LIST AAEL;
  459. PACTRL_ACCESS_ENTRY pNewList;
  460. NewAccess.cEntries = 1;
  461. NewAccess.pPropertyAccessList = &APE;
  462. APE.lpProperty = NULL;
  463. APE.fListFlags = 0;
  464. APE.pAccessEntryList = &AAEL;
  465. AAEL.cEntries = 1;
  466. if(pAccess != NULL)
  467. {
  468. AAEL.cEntries += pAccess->pPropertyAccessList[0].pAccessEntryList->cEntries;
  469. }
  470. pNewList = (PACTRL_ACCESS_ENTRY)
  471. AccAlloc(AAEL.cEntries * sizeof(ACTRL_ACCESS_ENTRY));
  472. if(pNewList == NULL)
  473. {
  474. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  475. printf("Failed to allocate for %lu nodes\n",
  476. AAEL.cEntries);
  477. }
  478. else
  479. {
  480. if(pAccess != NULL)
  481. {
  482. memcpy(pNewList,
  483. pAccess->pPropertyAccessList[0].pAccessEntryList->pAccessList,
  484. (AAEL.cEntries - 1) * sizeof(ACTRL_ACCESS_ENTRY));
  485. }
  486. printf("Adding %lu for trustee %ws to %ws\n",
  487. dwAccess,
  488. wszTrustee,
  489. wszPath);
  490. pNewList[AAEL.cEntries - 1].Trustee.ptstrName =
  491. wszTrustee;
  492. pNewList[AAEL.cEntries - 1].Trustee.TrusteeForm =
  493. TRUSTEE_IS_NAME;
  494. pNewList[AAEL.cEntries - 1].Trustee.TrusteeType =
  495. TRUSTEE_IS_USER;
  496. pNewList[AAEL.cEntries - 1].Access = dwAccess;
  497. pNewList[AAEL.cEntries - 1].fAccessFlags =
  498. ACTRL_ACCESS_ALLOWED;
  499. pNewList[AAEL.cEntries - 1].ProvSpecificAccess = 0;
  500. pNewList[AAEL.cEntries - 1].Inheritance = 0;
  501. pNewList[AAEL.cEntries - 1].lpInheritProperty = NULL;
  502. }
  503. AAEL.pAccessList = pNewList;
  504. if(dwErr == ERROR_SUCCESS)
  505. {
  506. //
  507. // Get a valid event to wait on...
  508. //
  509. ACTRL_OVERLAPPED Overlapped;
  510. Overlapped.hEvent = CreateEvent(NULL,
  511. TRUE,
  512. FALSE,
  513. NULL);
  514. printf("\nACCESS - SetAccessRights\n");
  515. dwErr = AccProvSetAccessRights((LPCWSTR)wszPath,
  516. ObjType,
  517. SeInfo,
  518. &NewAccess,
  519. NULL,
  520. pOwner,
  521. pGroup,
  522. &Overlapped);
  523. if(dwErr == ERROR_SUCCESS)
  524. {
  525. printf("SetAccessRights on %ws succeeded!\n",
  526. wszPath);
  527. WaitForSingleObject(Overlapped.hEvent,
  528. INFINITE);
  529. Sleep(1000);
  530. //
  531. // Get the results
  532. //
  533. dwErr = AccProvGetOperationResults(&Overlapped,
  534. &dwErr2);
  535. if(dwErr2 == ERROR_SUCCESS)
  536. {
  537. printf("AccProvGetOperationResults succeeded!\n");
  538. printf("Operation results: %lu\n",
  539. dwErr2);
  540. }
  541. else
  542. {
  543. printf("AccProvGetOperationResults failed with %lu\n",
  544. dwErr2);
  545. dwErr = dwErr2;
  546. }
  547. }
  548. else
  549. {
  550. printf("SetAccessRights on %ws failed with %lu\n",
  551. wszPath,
  552. dwErr);
  553. }
  554. AccFree(pNewList);
  555. }
  556. //
  557. // If it worked, get the results again and display them
  558. //
  559. if(dwErr == ERROR_SUCCESS)
  560. {
  561. AccFree(pAccess);
  562. AccFree(pAudit);
  563. AccFree(pOwner);
  564. AccFree(pGroup);
  565. pAccess = NULL;
  566. pAudit = NULL;
  567. pOwner = NULL;
  568. pGroup = NULL;
  569. dwErr = GetAndDumpInfo((LPCWSTR)wszPath,
  570. ObjType,
  571. SeInfo,
  572. &pAccess,
  573. &pAudit,
  574. &pOwner,
  575. &pGroup);
  576. if(dwErr != ERROR_SUCCESS)
  577. {
  578. printf("GetAllRights failed with %lu\n",
  579. dwErr);
  580. }
  581. }
  582. }
  583. #if 0
  584. //
  585. // Now, see if we can do a grant...
  586. //
  587. if(dwErr == ERROR_SUCCESS && cGrant == 2)
  588. {
  589. ACTRL_ACCESS NewAccess;
  590. ACTRL_ACCESS_ENTRY NewAccessList[1];
  591. NewAccess.cEntries = 1;
  592. NewAccess.pAccessList = NewAccessList;
  593. memset(NewAccessList, 0, sizeof(NewAccessList));
  594. printf("Granting %lu for trustee %ws to %ws\n",
  595. dwGrantAcc,
  596. wszGrant,
  597. wszPath);
  598. NewAccessList[0].Trustee.ptstrName = wszGrant;
  599. NewAccessList[0].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
  600. NewAccessList[0].Trustee.TrusteeType = TRUSTEE_IS_USER;
  601. NewAccessList[0].Access = dwGrantAcc;
  602. NewAccessList[0].fAEFlags = ACTRL_ACCESS_ALLOWED;
  603. //
  604. // Get a valid event to wait on...
  605. //
  606. ACTRL_OVERLAPPED Overlapped;
  607. Overlapped.hEvent = CreateEvent(NULL,
  608. TRUE,
  609. FALSE,
  610. NULL);
  611. printf("\nACCESS - GrantAccessRights\n");
  612. dwErr = AccProvGrantAccessRights((LPCWSTR)wszPath,
  613. ObjType,
  614. &NewAccess,
  615. NULL,
  616. &Overlapped);
  617. if(dwErr == ERROR_SUCCESS)
  618. {
  619. printf("GrantAccessRights on %ws succeeded!\n",
  620. wszPath);
  621. WaitForSingleObject(Overlapped.hEvent,
  622. INFINITE);
  623. Sleep(1000);
  624. //
  625. // Get the results
  626. //
  627. DWORD dwErr2;
  628. dwErr = AccProvGetOperationResults(&Overlapped,
  629. &dwErr2);
  630. if(dwErr2 == ERROR_SUCCESS)
  631. {
  632. printf("AccProvGetOperationResults succeeded!\n");
  633. printf("Operation results: %lu\n",
  634. dwErr2);
  635. }
  636. else
  637. {
  638. printf("AccProvGetOperationResults failed with %lu\n",
  639. dwErr2);
  640. dwErr = dwErr2;
  641. }
  642. }
  643. else
  644. {
  645. printf("GrantAccessRights on %ws failed with %lu\n",
  646. wszPath,
  647. dwErr);
  648. }
  649. //
  650. // If it worked, get the results again and display them
  651. //
  652. if(dwErr == ERROR_SUCCESS)
  653. {
  654. AccFree(pAccess);
  655. AccFree(pAudit);
  656. AccFree(pOwner);
  657. AccFree(pGroup);
  658. pAccess = NULL;
  659. pAudit = NULL;
  660. pOwner = NULL;
  661. pGroup = NULL;
  662. dwErr = GetAndDumpInfo((LPCWSTR)wszPath,
  663. ObjType,
  664. SeInfo,
  665. &pAccess,
  666. &pAudit,
  667. &pOwner,
  668. &pGroup);
  669. if(dwErr != ERROR_SUCCESS)
  670. {
  671. printf("GetAllRights failed with %lu\n",
  672. dwErr);
  673. }
  674. }
  675. }
  676. //
  677. // Finally, a revoke...
  678. //
  679. if(dwErr == ERROR_SUCCESS)
  680. {
  681. TRUSTEE rgTrustees[2];
  682. memset(rgTrustees, 0, sizeof(TRUSTEE) * 2);
  683. printf("Revoking accessfor trustee %ws to %ws\n",
  684. wszRevoke,
  685. wszPath);
  686. ULONG iRevoke = 0;
  687. if(cAccess == 2)
  688. {
  689. rgTrustees[iRevoke].ptstrName = wszRevoke;
  690. rgTrustees[iRevoke].TrusteeForm = TRUSTEE_IS_NAME;
  691. rgTrustees[iRevoke].TrusteeType = TRUSTEE_IS_USER;
  692. iRevoke++;
  693. }
  694. if(cGrant == 2)
  695. {
  696. rgTrustees[iRevoke].ptstrName = wszGrant;
  697. rgTrustees[iRevoke].TrusteeForm = TRUSTEE_IS_NAME;
  698. rgTrustees[iRevoke].TrusteeType = TRUSTEE_IS_USER;
  699. iRevoke++;
  700. }
  701. if(iRevoke != 0)
  702. {
  703. //
  704. // Get a valid event to wait on...
  705. //
  706. ACTRL_OVERLAPPED Overlapped;
  707. Overlapped.hEvent = CreateEvent(NULL,
  708. TRUE,
  709. FALSE,
  710. NULL);
  711. printf("\nACCESS - RevokeAccessRights\n");
  712. dwErr = AccProvRevokeAccessRights((LPCWSTR)wszPath,
  713. ObjType,
  714. NULL,
  715. iRevoke,
  716. rgTrustees,
  717. &Overlapped);
  718. if(dwErr == ERROR_SUCCESS)
  719. {
  720. printf("RevokeAccessRights on %ws succeeded!\n",
  721. wszPath);
  722. WaitForSingleObject(Overlapped.hEvent,
  723. INFINITE);
  724. Sleep(1000);
  725. //
  726. // Get the results
  727. //
  728. DWORD dwErr2;
  729. dwErr = AccProvGetOperationResults(&Overlapped,
  730. &dwErr2);
  731. if(dwErr2 == ERROR_SUCCESS)
  732. {
  733. printf("AccProvGetOperationResults succeeded!\n");
  734. printf("Operation results: %lu\n",
  735. dwErr2);
  736. }
  737. else
  738. {
  739. printf("AccProvGetOperationResults failed with %lu\n",
  740. dwErr2);
  741. dwErr = dwErr2;
  742. }
  743. }
  744. else
  745. {
  746. printf("RevokeAccessRights on %ws failed with %lu\n",
  747. wszPath,
  748. dwErr);
  749. }
  750. //
  751. // If it worked, get the results again and display them
  752. //
  753. if(dwErr == ERROR_SUCCESS)
  754. {
  755. AccFree(pAccess);
  756. AccFree(pAudit);
  757. AccFree(pOwner);
  758. AccFree(pGroup);
  759. pAccess = NULL;
  760. pAudit = NULL;
  761. pOwner = NULL;
  762. pGroup = NULL;
  763. dwErr = GetAndDumpInfo((LPCWSTR)wszPath,
  764. ObjType,
  765. SeInfo,
  766. &pAccess,
  767. &pAudit,
  768. &pOwner,
  769. &pGroup);
  770. if(dwErr != ERROR_SUCCESS)
  771. {
  772. printf("GetAllRights failed with %lu\n",
  773. dwErr);
  774. }
  775. }
  776. }
  777. }
  778. #endif
  779. AccFree(pAccess);
  780. AccFree(pAudit);
  781. AccFree(pOwner);
  782. AccFree(pGroup);
  783. return(0);
  784. }