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.

2161 lines
60 KiB

  1. /****************************************************************************
  2. File: actestc.cxx
  3. Description: Client side of the DCOM IAccessControl test program.
  4. ****************************************************************************/
  5. #include <windows.h>
  6. #include <ole2.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <ctype.h>
  10. #include <string.h>
  11. #include <accctrl.h>
  12. #include "oactest.h"
  13. #include <oleext.h>
  14. #include <rpcdce.h>
  15. /* Internal program parameters */
  16. #define BIG_BUFFER 2048
  17. #define LINE_BUFF_SIZE 200
  18. #define MAX_TOKENS_NUM 20
  19. #define STR_LEN 100
  20. // Define some bogus access masks so that we can verify the
  21. // the validation mechanism of DCOM IAccessControl
  22. #define BOGUS_ACCESS_RIGHT1 (COM_RIGHTS_EXECUTE*2)
  23. #define BOGUS_ACCESS_RIGHT2 (COM_RIGHTS_EXECUTE*4)
  24. #define BOGUS_ACCESS_RIGHT3 (COM_RIGHTS_EXECUTE*8)
  25. #define BOGUS_ACCESS_RIGHT4 (COM_RIGHTS_EXECUTE*16)
  26. // The following structure encapsulates all kinds of information that
  27. // can be associated with a trustee.
  28. typedef struct tagTRUSTEE_RECORD
  29. {
  30. DWORD grfAccessPermissions;
  31. ACCESS_MODE grfAccessMode;
  32. DWORD grfInheritance;
  33. PTRUSTEE_W pMultipleTrustee;
  34. MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation;
  35. TRUSTEE_FORM TrusteeForm;
  36. TRUSTEE_TYPE TrusteeType;
  37. LPWSTR pwszTrusteeName;
  38. PISID pSID;
  39. } TRUSTEE_RECORD;
  40. /* Global variables */
  41. char pszUserName[STR_LEN]; // User Name
  42. char pszBasePath[STR_LEN];
  43. char pszResource[STR_LEN]; // Resource location
  44. EXPLICIT_ACCESS_W g_pLocalExplicitAccessList[100];
  45. ULONG g_ulNumOfLocalExplicitAccesses = 0;
  46. ACCESS_REQUEST_W g_pLocalAccessRequestList[100];
  47. ULONG g_ulNumOfLocalAccessRequests = 0;
  48. PEXPLICIT_ACCESS_W g_pReturnedExplicitAccessList = NULL;
  49. ULONG g_ulNumOfExplicitAccessesReturned = 0;
  50. TRUSTEE_W g_pLocalTrusteeList[100];
  51. ULONG g_ulNumOfLocalTrustees = 0;
  52. TRUSTEE_RECORD g_LocalTrusteeRecord;
  53. IAccessControlTest *g_pIAccessControlTest;
  54. IUnknown *g_pIUnknown;
  55. const CLSID CLSID_COAccessControlTest
  56. = {0x20692b00,0xe710,0x11cf,{0xaf,0x0b,0x00,0xaa,0x00,0x44,0xfb,0x89}};
  57. /* Internal function prototyoes */
  58. void Tokenize(char *, char *[], short *);
  59. void stringtolower(char *);
  60. PISID GetSIDForTrustee(LPWSTR);
  61. void AddTrusteeToExplicitAccessList(TRUSTEE_RECORD *, PEXPLICIT_ACCESS_W, ULONG *);
  62. void DeleteTrusteeFromExplicitAccessList(ULONG, PEXPLICIT_ACCESS_W, ULONG *);
  63. void AddTrusteeToAccessRequestList(TRUSTEE_RECORD *, PACCESS_REQUEST_W, ULONG *);
  64. void DeleteTrusteeFromAccessRequestList(ULONG, PACCESS_REQUEST_W, ULONG *);
  65. void MapTrusteeRecordToTrustee(TRUSTEE_RECORD *, TRUSTEE_W *);
  66. void AddTrusteeToTrusteeList(TRUSTEE_RECORD *, TRUSTEE_W *, ULONG *);
  67. void DeleteTrusteeFromTrusteeList(ULONG, TRUSTEE_W *, ULONG *);
  68. void DestroyAccessRequestList(PACCESS_REQUEST_W, ULONG *);
  69. void DestroyTrusteeList(TRUSTEE_W *, ULONG *);
  70. void DestroyExplicitAccessList(PEXPLICIT_ACCESS_W, ULONG *);
  71. void PrintEnvironment(void);
  72. void DumpTrusteeRecord(TRUSTEE_RECORD *);
  73. void DumpAccessRequestList(ULONG, ACCESS_REQUEST_W []);
  74. void DumpExplicitAccessList(ULONG, EXPLICIT_ACCESS_W []);
  75. void DumpAccessPermissions(DWORD);
  76. DWORD StringToAccessPermission(CHAR *);
  77. void DumpAccessMode(ACCESS_MODE);
  78. void DumpTrusteeList(ULONG, TRUSTEE_W []);
  79. void DumpTrustee(TRUSTEE_W *);
  80. void DumpMultipleTrusteeOperation(MULTIPLE_TRUSTEE_OPERATION);
  81. MULTIPLE_TRUSTEE_OPERATION StringToMultipleTrusteeOperation(CHAR *);
  82. void DumpTrusteeType(TRUSTEE_TYPE);
  83. TRUSTEE_TYPE StringToTrusteeType(CHAR *);
  84. void DumpTrusteeForm(TRUSTEE_FORM);
  85. TRUSTEE_FORM StringToTrusteeForm(CHAR *);
  86. void DumpSID(PISID);
  87. ACCESS_MODE StringToAccessMode(CHAR *);
  88. void DumpInheritance(DWORD);
  89. DWORD StringToInheritance(CHAR *);
  90. void ReleaseExplicitAccessList(ULONG, PEXPLICIT_ACCESS_W);
  91. void CopyExplicitAccessList(PEXPLICIT_ACCESS_W, PEXPLICIT_ACCESS_W, ULONG *, ULONG);
  92. void ExecTestServer(CHAR *);
  93. void ExecRevertAccessRights(void);
  94. void ExecCommitAccessRights(void);
  95. void ExecGetClassID(void);
  96. void ExecInitNewACL(void);
  97. void ExecLoadACL(CHAR *);
  98. void ExecSaveACL(CHAR *);
  99. void ExecGetSizeMax(void);
  100. void ExecIsDirty(void);
  101. void ExecGrantAccessRights(void);
  102. void ExecSetAccessRights(void);
  103. void ExecDenyAccessRights(void);
  104. void ExecReplaceAllAccessRights(void);
  105. void ExecRevokeExplicitAccessRights(void);
  106. void ExecIsAccessPermitted(void);
  107. void ExecGetEffectiveAccessRights(void);
  108. void ExecGetExplicitAccessRights(void);
  109. void ExecCleanupProc();
  110. void Usage(char * pszProgramName)
  111. {
  112. printf("Usage: %s\n", pszProgramName);
  113. printf(" -m remote_server_name\n");
  114. exit(1);
  115. }
  116. void stringtolower
  117. (
  118. char *pszString
  119. )
  120. {
  121. char c;
  122. while(c = *pszString)
  123. {
  124. if(c <= 'Z' && c >= 'A')
  125. {
  126. *pszString = c - 'A' + 'a';
  127. }
  128. pszString++;
  129. }
  130. } // stringtolower
  131. void __cdecl main(int argc, char **argv)
  132. {
  133. RPC_STATUS status;
  134. unsigned long ulCode;
  135. WCHAR DummyChar;
  136. int i;
  137. char aLineBuff[LINE_BUFF_SIZE];
  138. char *aTokens[MAX_TOKENS_NUM];
  139. short iNumOfTokens;
  140. SEC_WINNT_AUTH_IDENTITY_A auth_id;
  141. UCHAR uname[STR_LEN];
  142. UCHAR domain[STR_LEN];
  143. UCHAR password[STR_LEN];
  144. TRUSTEE_W DummyMultipleTrustee;
  145. ULONG ulStrLen;
  146. DWORD dwAccessPermission;
  147. BOOL biBatchMode = FALSE;
  148. HRESULT hr;
  149. OLECHAR pwszRemoteServer[1024];
  150. DWORD dwStrLen;
  151. /* allow the user to override settings with command line switches */
  152. for (i = 1; i < argc; i++) {
  153. if ((*argv[i] == '-') || (*argv[i] == '/')) {
  154. switch (tolower(*(argv[i]+1))) {
  155. case 'm': // remote server name
  156. dwStrLen = MultiByteToWideChar( CP_ACP
  157. , NULL
  158. , argv[++i]
  159. , -1
  160. , pwszRemoteServer
  161. , 1024);
  162. break;
  163. case 'b':
  164. biBatchMode = TRUE;
  165. break;
  166. case 'h':
  167. case '?':
  168. default:
  169. Usage(argv[0]);
  170. }
  171. }
  172. else
  173. Usage(argv[0]);
  174. }
  175. // Initialize the testing environment
  176. aTokens[0] = aLineBuff;
  177. g_LocalTrusteeRecord.grfAccessPermissions = 0;
  178. g_LocalTrusteeRecord.grfAccessMode = GRANT_ACCESS;
  179. g_LocalTrusteeRecord.grfInheritance = NO_INHERITANCE;
  180. g_LocalTrusteeRecord.pMultipleTrustee = NULL;
  181. g_LocalTrusteeRecord.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
  182. g_LocalTrusteeRecord.TrusteeForm = TRUSTEE_IS_NAME;
  183. g_LocalTrusteeRecord.TrusteeType = TRUSTEE_IS_USER;
  184. g_LocalTrusteeRecord.pwszTrusteeName = NULL;
  185. g_LocalTrusteeRecord.pSID = NULL;
  186. auth_id.User = uname;
  187. auth_id.Domain = domain;
  188. auth_id.Password = password;
  189. auth_id.Flags = 0x01; // ANSI
  190. // Call CoInitialize to initialize the com library
  191. hr = CoInitialize(NULL);
  192. if(FAILED(hr))
  193. {
  194. printf("Failed to initialize the COM library.");
  195. exit(hr);
  196. } // if
  197. // Call CoInitializeSecurity
  198. hr = CoInitializeSecurity( NULL
  199. , -1
  200. , NULL
  201. , NULL
  202. , RPC_C_AUTHN_LEVEL_CONNECT
  203. , RPC_C_IMP_LEVEL_IMPERSONATE
  204. , NULL
  205. , EOAC_NONE
  206. , NULL );
  207. if(FAILED(hr))
  208. {
  209. printf("Failed to initialize the COM call security layer.\n");
  210. exit(hr);
  211. }
  212. MULTI_QI MultiQI;
  213. MultiQI.pIID = &IID_IUnknown;
  214. MultiQI.pItf = NULL;
  215. COSERVERINFO ServerInfo;
  216. ServerInfo.pwszName = pwszRemoteServer;
  217. ServerInfo.pAuthInfo = NULL;
  218. ServerInfo.dwReserved1 = 0;
  219. ServerInfo.dwReserved2 = 0;
  220. // Call CoCreateInstance to create an access control test
  221. // object
  222. hr = CoCreateInstanceEx( CLSID_COAccessControlTest
  223. , NULL
  224. , CLSCTX_REMOTE_SERVER
  225. , &ServerInfo
  226. , 1
  227. , &MultiQI);
  228. if(FAILED(hr))
  229. {
  230. printf("CoCreateInstance failed with exit code %x.\n", hr);
  231. exit(hr);
  232. }
  233. hr = MultiQI.hr;
  234. g_pIUnknown = (IUnknown *)MultiQI.pItf;
  235. if(FAILED(hr))
  236. {
  237. printf("Failed to create an instance of the access control test object.\n");
  238. exit(hr);
  239. }
  240. hr = g_pIUnknown->QueryInterface(IID_IAccessControlTest, (void **)&g_pIAccessControlTest);
  241. if(FAILED(hr))
  242. {
  243. printf("Failed to query for the IAccessControlTest interface.\n");
  244. exit(hr);
  245. }
  246. printf("\n");
  247. PrintEnvironment();
  248. printf("\n");
  249. /* Entering the interactive command loop */
  250. for(;;)
  251. {
  252. // Print out prompt
  253. if (!biBatchMode)
  254. {
  255. printf("Command>");
  256. }
  257. memset(aLineBuff, 0, LINE_BUFF_SIZE);
  258. // Read input form user
  259. gets(aLineBuff);
  260. if (biBatchMode)
  261. {
  262. printf("%s\n",aLineBuff);
  263. }
  264. Tokenize(aLineBuff,aTokens,&iNumOfTokens);
  265. // Process the tokens
  266. stringtolower(aTokens[0]);
  267. // Decode and execute command
  268. // Ignore comments
  269. if (iNumOfTokens == 0)
  270. {
  271. continue;
  272. }
  273. if (*aTokens[0] == '#')
  274. {
  275. continue;
  276. }
  277. printf("\n");
  278. if (strcmp(aTokens[0],"quit") == 0)
  279. {
  280. printf("Exit.\n");
  281. ExecCleanupProc();
  282. break;
  283. }
  284. else if (strcmp(aTokens[0],"exit") == 0)
  285. {
  286. printf("Exit.\n");
  287. ExecCleanupProc();
  288. break;
  289. }
  290. else if (strcmp(aTokens[0],"sleep") == 0)
  291. {
  292. printf("Sleep for %s milliseconds", aTokens[1]);
  293. Sleep(atoi(aTokens[1]));
  294. }
  295. else if (strcmp(aTokens[0], "testserver") == 0)
  296. {
  297. g_pIAccessControlTest->TestServer(aTokens[1]);
  298. printf("Done.\n");
  299. }
  300. else if (strcmp(aTokens[0],"switchclientctx") == 0)
  301. {
  302. printf("User:");
  303. gets((CHAR *)uname);
  304. printf("Domain:");
  305. gets((CHAR *)domain);
  306. printf("Password:");
  307. gets((CHAR *)password);
  308. auth_id.UserLength = strlen((CHAR *)uname);
  309. auth_id.DomainLength = strlen((CHAR *)domain);
  310. auth_id.PasswordLength = strlen((CHAR *)password);
  311. auth_id.Flags = 0x1;
  312. /* Set authentication info so that the server is triggered */
  313. /* to cache group info for the client from the domain server */
  314. hr = CoSetProxyBlanket( g_pIAccessControlTest
  315. , RPC_C_AUTHN_WINNT
  316. , RPC_C_AUTHZ_NONE
  317. , NULL
  318. , RPC_C_AUTHN_LEVEL_CONNECT
  319. , RPC_C_IMP_LEVEL_IMPERSONATE
  320. , &auth_id
  321. , EOAC_NONE );
  322. printf("CoSetProxyBlanket returned %x\n", hr);
  323. if (FAILED(hr))
  324. {
  325. exit(hr);
  326. }
  327. }
  328. else if (strcmp(aTokens[0],"toggleaccessperm") == 0)
  329. {
  330. stringtolower(aTokens[1]);
  331. dwAccessPermission = StringToAccessPermission(aTokens[1]);
  332. if (g_LocalTrusteeRecord.grfAccessPermissions & dwAccessPermission)
  333. {
  334. g_LocalTrusteeRecord.grfAccessPermissions &= ~dwAccessPermission;
  335. }
  336. else
  337. {
  338. g_LocalTrusteeRecord.grfAccessPermissions |= dwAccessPermission;
  339. }
  340. printf("Done.\n");
  341. }
  342. else if (strcmp(aTokens[0],"set") == 0)
  343. {
  344. stringtolower(aTokens[1]);
  345. if (strcmp(aTokens[1],"trusteename") == 0)
  346. {
  347. // The old SID in the global trustee record will no longer valid so we
  348. // may as well release it to avoid confusion
  349. if (g_LocalTrusteeRecord.pSID != NULL)
  350. {
  351. midl_user_free(g_LocalTrusteeRecord.pSID);
  352. g_LocalTrusteeRecord.pSID = NULL;
  353. }
  354. if (g_LocalTrusteeRecord.pwszTrusteeName != NULL)
  355. {
  356. midl_user_free(g_LocalTrusteeRecord.pwszTrusteeName);
  357. }
  358. ulStrLen = MultiByteToWideChar( CP_ACP
  359. , 0
  360. , aTokens[2]
  361. , -1
  362. , &DummyChar
  363. , 0 );
  364. g_LocalTrusteeRecord.pwszTrusteeName = (LPWSTR)midl_user_allocate(sizeof(WCHAR) * (ulStrLen+1));
  365. MultiByteToWideChar( CP_ACP
  366. , 0
  367. , aTokens[2]
  368. , ulStrLen + 1
  369. , g_LocalTrusteeRecord.pwszTrusteeName
  370. , ulStrLen + 1);
  371. printf("Done.\n");
  372. }
  373. else if (strcmp(aTokens[1], "accessmode") == 0)
  374. {
  375. stringtolower(aTokens[2]);
  376. g_LocalTrusteeRecord.grfAccessMode = StringToAccessMode(aTokens[2]);
  377. printf("Done.\n");
  378. }
  379. else if (strcmp(aTokens[1], "inheritance") == 0)
  380. {
  381. stringtolower(aTokens[2]);
  382. g_LocalTrusteeRecord.grfInheritance = StringToInheritance(aTokens[2]);
  383. printf("Done.\n");
  384. }
  385. else if (strcmp(aTokens[1], "multipletrustee") == 0)
  386. {
  387. stringtolower(aTokens[2]);
  388. if (strcmp(aTokens[2], "null") == 0)
  389. {
  390. g_LocalTrusteeRecord.pMultipleTrustee = NULL;
  391. }
  392. else
  393. {
  394. g_LocalTrusteeRecord.pMultipleTrustee = &DummyMultipleTrustee;
  395. }
  396. printf("Done.\n");
  397. }
  398. else if (strcmp(aTokens[1], "multipletrusteeoperation") == 0)
  399. {
  400. stringtolower(aTokens[2]);
  401. g_LocalTrusteeRecord.MultipleTrusteeOperation = StringToMultipleTrusteeOperation(aTokens[2]);
  402. printf("Done.\n");
  403. }
  404. else if (strcmp(aTokens[1], "trusteeform") == 0)
  405. {
  406. stringtolower(aTokens[2]);
  407. g_LocalTrusteeRecord.TrusteeForm = StringToTrusteeForm(aTokens[2]);
  408. printf("Done.\n");
  409. }
  410. else if (strcmp(aTokens[1], "trusteetype") == 0)
  411. {
  412. stringtolower(aTokens[2]);
  413. g_LocalTrusteeRecord.TrusteeType = StringToTrusteeType(aTokens[2]);
  414. printf("Done.\n");
  415. }
  416. else
  417. {
  418. printf("Invalid environment variable.\n");
  419. } // if
  420. }
  421. else if (strcmp(aTokens[0], "getsidforcurrenttrustee") == 0)
  422. {
  423. g_LocalTrusteeRecord.pSID = GetSIDForTrustee(g_LocalTrusteeRecord.pwszTrusteeName);
  424. printf("Done.\n");
  425. }
  426. else if (strcmp(aTokens[0], "addtrustee") == 0)
  427. {
  428. stringtolower(aTokens[1]);
  429. if (strcmp(aTokens[1], "explicitaccesslist") == 0)
  430. {
  431. AddTrusteeToExplicitAccessList(&g_LocalTrusteeRecord, g_pLocalExplicitAccessList, &g_ulNumOfLocalExplicitAccesses);
  432. printf("Done.\n");
  433. }
  434. else if (strcmp(aTokens[1], "accessrequestlist") == 0)
  435. {
  436. AddTrusteeToAccessRequestList(&g_LocalTrusteeRecord, g_pLocalAccessRequestList, &g_ulNumOfLocalAccessRequests);
  437. printf("Done.\n");
  438. }
  439. else if (strcmp(aTokens[1], "trusteelist") == 0)
  440. {
  441. AddTrusteeToTrusteeList(&g_LocalTrusteeRecord, g_pLocalTrusteeList, &g_ulNumOfLocalTrustees);
  442. printf("Done.\n");
  443. }
  444. else
  445. {
  446. printf("Unknown list type.\n");
  447. }
  448. }
  449. else if (strcmp(aTokens[0], "deletetrustee") == 0)
  450. {
  451. stringtolower(aTokens[2]);
  452. if (strcmp(aTokens[2], "localexplicitaccesslist") == 0)
  453. {
  454. DeleteTrusteeFromExplicitAccessList(atoi(aTokens[1]), g_pLocalExplicitAccessList, &g_ulNumOfLocalExplicitAccesses);
  455. printf("Done.\n");
  456. }
  457. else if (strcmp(aTokens[2], "accessrequestlist") == 0)
  458. {
  459. DeleteTrusteeFromAccessRequestList(atoi(aTokens[1]), g_pLocalAccessRequestList, &g_ulNumOfLocalAccessRequests);
  460. printf("Done.\n");
  461. }
  462. else if (strcmp(aTokens[2], "trusteelist") == 0)
  463. {
  464. DeleteTrusteeFromTrusteeList(atoi(aTokens[1]), g_pLocalTrusteeList, &g_ulNumOfLocalTrustees);
  465. printf("Done.\n");
  466. }
  467. else
  468. {
  469. printf("Unknown list type.\n");
  470. }
  471. }
  472. else if (strcmp(aTokens[0], "destroy") == 0)
  473. {
  474. stringtolower(aTokens[1]);
  475. if (strcmp(aTokens[1], "localexplicitaccesslist") == 0)
  476. {
  477. DestroyExplicitAccessList(g_pLocalExplicitAccessList, &g_ulNumOfLocalExplicitAccesses);
  478. printf("Done.\n");
  479. }
  480. else if (strcmp(aTokens[1], "returnedexplicitaccessslist") == 0)
  481. {
  482. DestroyExplicitAccessList(g_pReturnedExplicitAccessList, &g_ulNumOfExplicitAccessesReturned);
  483. printf("Done.\n");
  484. }
  485. else if (strcmp(aTokens[1], "accessrequestlist") == 0)
  486. {
  487. DestroyAccessRequestList(g_pLocalAccessRequestList, &g_ulNumOfLocalAccessRequests);
  488. printf("Done.\n");
  489. }
  490. else if (strcmp(aTokens[1], "trusteelist") == 0)
  491. {
  492. DestroyTrusteeList(g_pLocalTrusteeList, &g_ulNumOfLocalTrustees);
  493. }
  494. else
  495. {
  496. printf("Unknown list type.");
  497. }
  498. }
  499. else if (strcmp(aTokens[0], "view") == 0)
  500. {
  501. stringtolower(aTokens[1]);
  502. if (strcmp(aTokens[1], "localexplicitaccesslist") == 0)
  503. {
  504. DumpExplicitAccessList(g_ulNumOfLocalExplicitAccesses, g_pLocalExplicitAccessList);
  505. printf("Done.\n");
  506. }
  507. else if (strcmp(aTokens[1], "returnedexplicitaccessslist") == 0)
  508. {
  509. DumpExplicitAccessList(g_ulNumOfExplicitAccessesReturned, g_pReturnedExplicitAccessList);
  510. printf("Done.\n");
  511. }
  512. else if (strcmp(aTokens[1], "accessrequestlist") == 0)
  513. {
  514. DumpAccessRequestList(g_ulNumOfLocalAccessRequests, g_pLocalAccessRequestList);
  515. printf("Done.\n");
  516. }
  517. else if (strcmp(aTokens[1], "trusteelist") == 0)
  518. {
  519. DumpTrusteeList(g_ulNumOfLocalTrustees, g_pLocalTrusteeList);
  520. printf("Done.\n");
  521. }
  522. else if (strcmp(aTokens[1], "trusteerecord") == 0)
  523. {
  524. DumpTrusteeRecord(&g_LocalTrusteeRecord);
  525. printf("Done.\n");
  526. }
  527. else if (strcmp(aTokens[1], "localenvironment") == 0)
  528. {
  529. PrintEnvironment();
  530. }
  531. else
  532. {
  533. printf("Invalid argument.");
  534. }
  535. }
  536. else if (strcmp(aTokens[0], "copyreturnedlist") == 0)
  537. {
  538. // release the old local explicit access list
  539. ReleaseExplicitAccessList(g_ulNumOfLocalExplicitAccesses, g_pLocalExplicitAccessList);
  540. // replace the local explicit acccess list with the explicit access list returned
  541. // from the last call to GetExplicitAccess
  542. CopyExplicitAccessList(g_pLocalExplicitAccessList, g_pReturnedExplicitAccessList, &g_ulNumOfLocalExplicitAccesses, g_ulNumOfExplicitAccessesReturned);
  543. printf("Done.\n");
  544. }
  545. else if (strcmp(aTokens[0], "exec") == 0)
  546. {
  547. stringtolower(aTokens[1]);
  548. if (strcmp(aTokens[1], "testserver") == 0)
  549. {
  550. ExecTestServer(aTokens[2]);
  551. }
  552. else if (strcmp(aTokens[1], "revertaccessrights") == 0)
  553. {
  554. ExecRevertAccessRights();
  555. }
  556. else if (strcmp(aTokens[1], "commitaccessrights") == 0)
  557. {
  558. ExecCommitAccessRights();
  559. }
  560. else if (strcmp(aTokens[1], "getclassid") == 0)
  561. {
  562. ExecGetClassID();
  563. }
  564. else if (strcmp(aTokens[1], "initnewacl") == 0)
  565. {
  566. ExecInitNewACL();
  567. }
  568. else if (strcmp(aTokens[1], "loadacl") == 0)
  569. {
  570. ExecLoadACL(aTokens[2]);
  571. }
  572. else if (strcmp(aTokens[1], "saveacl") == 0)
  573. {
  574. ExecSaveACL(aTokens[2]);
  575. }
  576. else if (strcmp(aTokens[1], "isdirty") == 0)
  577. {
  578. ExecIsDirty();
  579. }
  580. else if (strcmp(aTokens[1], "getsizemax") == 0)
  581. {
  582. ExecGetSizeMax();
  583. }
  584. else if (strcmp(aTokens[1], "grantaccessrights") == 0)
  585. {
  586. ExecGrantAccessRights();
  587. }
  588. else if (strcmp(aTokens[1], "setaccessrights") == 0)
  589. {
  590. ExecSetAccessRights();
  591. }
  592. else if (strcmp(aTokens[1], "denyaccessrights") == 0)
  593. {
  594. ExecDenyAccessRights();
  595. }
  596. else if (strcmp(aTokens[1], "replaceallaccessrights") == 0)
  597. {
  598. ExecReplaceAllAccessRights();
  599. }
  600. else if (strcmp(aTokens[1], "revokeexplicitaccessrights") == 0)
  601. {
  602. ExecRevokeExplicitAccessRights();
  603. }
  604. else if (strcmp(aTokens[1], "isaccesspermitted") == 0)
  605. {
  606. ExecIsAccessPermitted();
  607. }
  608. else if (strcmp(aTokens[1], "geteffectiveaccessrights") == 0)
  609. {
  610. ExecGetEffectiveAccessRights();
  611. }
  612. else if (strcmp(aTokens[1], "getexplicitaccessrights") == 0)
  613. {
  614. ExecGetExplicitAccessRights();
  615. }
  616. else
  617. {
  618. printf("Unknown command.\n");
  619. }
  620. }
  621. else
  622. {
  623. printf("Unrecognized command.\n");
  624. } // if
  625. printf("\n");
  626. } // for
  627. exit(0);
  628. } // end main()
  629. PISID GetSIDForTrustee
  630. (
  631. LPWSTR pwszTrusteeName
  632. )
  633. {
  634. PISID pSID;
  635. DWORD dwSize = 0;
  636. WCHAR pwszDomain[100];
  637. DWORD dwDomainSize = 100;
  638. SID_NAME_USE SIDUse;
  639. LookupAccountNameW( NULL
  640. , pwszTrusteeName
  641. , pSID
  642. , &dwSize
  643. , pwszDomain
  644. , &dwDomainSize
  645. , &SIDUse );
  646. pSID = (PISID)midl_user_allocate(dwSize);
  647. LookupAccountNameW( NULL
  648. , pwszTrusteeName
  649. , pSID
  650. , &dwSize
  651. , pwszDomain
  652. , &dwDomainSize
  653. , &SIDUse );
  654. return pSID;
  655. }
  656. void AddTrusteeToExplicitAccessList
  657. (
  658. TRUSTEE_RECORD *pTrusteeRecord,
  659. PEXPLICIT_ACCESS_W pExplicitAccessList,
  660. ULONG *pulNumOfExplicitAccesses
  661. )
  662. {
  663. PEXPLICIT_ACCESS_W pInsertionPoint;
  664. pInsertionPoint = pExplicitAccessList + *pulNumOfExplicitAccesses;
  665. pInsertionPoint->grfAccessPermissions = pTrusteeRecord->grfAccessPermissions;
  666. pInsertionPoint->grfAccessMode = pTrusteeRecord->grfAccessMode;
  667. pInsertionPoint->grfInheritance = pTrusteeRecord->grfInheritance;
  668. MapTrusteeRecordToTrustee(pTrusteeRecord, &(pInsertionPoint->Trustee));
  669. (*pulNumOfExplicitAccesses)++;
  670. }
  671. void DeleteTrusteeFromExplicitAccessList
  672. (
  673. ULONG ulIndex,
  674. PEXPLICIT_ACCESS_W pExplicitAccessList,
  675. ULONG *pulNumOfExplicitAccesses
  676. )
  677. {
  678. PEXPLICIT_ACCESS_W pDeletionPoint;
  679. if(ulIndex >= *pulNumOfExplicitAccesses)
  680. {
  681. return;
  682. }
  683. pDeletionPoint = pExplicitAccessList + ulIndex;
  684. midl_user_free(pDeletionPoint->Trustee.ptstrName);
  685. (*pulNumOfExplicitAccesses)--;
  686. memmove(pDeletionPoint, pDeletionPoint + 1, sizeof(EXPLICIT_ACCESS_W) * (*pulNumOfExplicitAccesses - ulIndex));
  687. }
  688. void AddTrusteeToAccessRequestList
  689. (
  690. TRUSTEE_RECORD *pTrusteeRecord,
  691. PACCESS_REQUEST_W pAccessRequestList,
  692. ULONG *pulNumOfAccessRequests
  693. )
  694. {
  695. PACCESS_REQUEST_W pInsertionPoint;
  696. pInsertionPoint = pAccessRequestList + *pulNumOfAccessRequests;
  697. pInsertionPoint->grfAccessPermissions = pTrusteeRecord->grfAccessPermissions;
  698. MapTrusteeRecordToTrustee(pTrusteeRecord, &(pInsertionPoint->Trustee));
  699. (*pulNumOfAccessRequests)++;
  700. }
  701. void DeleteTrusteeFromAccessRequestList
  702. (
  703. ULONG ulIndex,
  704. PACCESS_REQUEST_W pAccessRequestList,
  705. ULONG *pulNumOfAccessRequests
  706. )
  707. {
  708. PACCESS_REQUEST_W pDeletionPoint;
  709. pDeletionPoint = pAccessRequestList + ulIndex;
  710. if (ulIndex >= *pulNumOfAccessRequests)
  711. {
  712. return;
  713. }
  714. midl_user_free(pDeletionPoint->Trustee.ptstrName);
  715. (*pulNumOfAccessRequests)--;
  716. memmove(pDeletionPoint, pDeletionPoint + 1, sizeof(ACCESS_REQUEST_W) * (*pulNumOfAccessRequests - ulIndex));
  717. }
  718. void MapTrusteeRecordToTrustee
  719. (
  720. TRUSTEE_RECORD *pTrusteeRecord,
  721. TRUSTEE_W *pTrustee
  722. )
  723. {
  724. ULONG ulTrusteeNameLength;
  725. pTrustee->pMultipleTrustee = pTrusteeRecord->pMultipleTrustee;
  726. pTrustee->MultipleTrusteeOperation = pTrusteeRecord->MultipleTrusteeOperation;
  727. pTrustee->TrusteeForm = pTrusteeRecord->TrusteeForm;
  728. pTrustee->TrusteeType = pTrusteeRecord->TrusteeType;
  729. switch(pTrusteeRecord->TrusteeForm)
  730. {
  731. case TRUSTEE_IS_SID:
  732. if(pTrusteeRecord->pSID== NULL)
  733. {
  734. pTrustee->ptstrName = NULL;
  735. }
  736. else
  737. {
  738. ulTrusteeNameLength = GetSidLengthRequired(pTrusteeRecord->pSID->SubAuthorityCount);
  739. pTrustee->ptstrName = (LPWSTR)midl_user_allocate(ulTrusteeNameLength);
  740. CopySid(ulTrusteeNameLength, (PSID)(pTrustee->ptstrName), pTrusteeRecord->pSID);
  741. }
  742. break;
  743. case TRUSTEE_IS_NAME:
  744. if (pTrusteeRecord->pwszTrusteeName == NULL)
  745. {
  746. pTrustee->ptstrName = NULL;
  747. }
  748. else
  749. {
  750. ulTrusteeNameLength = lstrlenW(pTrusteeRecord->pwszTrusteeName);
  751. pTrustee->ptstrName = (LPWSTR)midl_user_allocate((ulTrusteeNameLength + 1) * sizeof(WCHAR));
  752. lstrcpyW(pTrustee->ptstrName, pTrusteeRecord->pwszTrusteeName);
  753. }
  754. break;
  755. }
  756. }
  757. void AddTrusteeToTrusteeList
  758. (
  759. TRUSTEE_RECORD *pTrusteeRecord,
  760. TRUSTEE_W *pTrusteeList,
  761. ULONG *pulNumOfTrustees
  762. )
  763. {
  764. TRUSTEE_W *pInsertionPoint;
  765. pInsertionPoint = pTrusteeList + *pulNumOfTrustees;
  766. MapTrusteeRecordToTrustee(pTrusteeRecord, pInsertionPoint);
  767. (*pulNumOfTrustees)++;
  768. }
  769. void DeleteTrusteeFromTrusteeList
  770. (
  771. ULONG ulIndex,
  772. TRUSTEE_W *pTrusteeList,
  773. ULONG *pulNumOfTrustees
  774. )
  775. {
  776. TRUSTEE_W *pDeletionPoint;
  777. pDeletionPoint = pTrusteeList + ulIndex;
  778. if (ulIndex >= *pulNumOfTrustees)
  779. {
  780. return;
  781. }
  782. midl_user_free(pDeletionPoint->ptstrName);
  783. (*pulNumOfTrustees)--;
  784. memmove(pDeletionPoint, pDeletionPoint + 1, sizeof(TRUSTEE_W) * (*pulNumOfTrustees - ulIndex));
  785. }
  786. void DestroyAccessRequestList
  787. (
  788. PACCESS_REQUEST_W pAccessRequestList,
  789. ULONG *pulNumOfAccessRequests
  790. )
  791. {
  792. ULONG i;
  793. PACCESS_REQUEST_W pAccessRequestListPtr;
  794. for ( i = 0, pAccessRequestListPtr = pAccessRequestList
  795. ; i < *pulNumOfAccessRequests
  796. ; i++, pAccessRequestListPtr++)
  797. {
  798. midl_user_free(pAccessRequestListPtr->Trustee.ptstrName);
  799. }
  800. *pulNumOfAccessRequests = 0;
  801. }
  802. void DestroyTrusteeList
  803. (
  804. TRUSTEE_W *pTrusteeList,
  805. ULONG *pulNumOfTrustees
  806. )
  807. {
  808. ULONG i;
  809. TRUSTEE_W *pTrusteeListPtr;
  810. for ( i = 0, pTrusteeListPtr = pTrusteeList
  811. ; i < *pulNumOfTrustees
  812. ; i++, pTrusteeListPtr++)
  813. {
  814. midl_user_free(pTrusteeListPtr->ptstrName);
  815. }
  816. *pulNumOfTrustees = 0;
  817. }
  818. void DestroyExplicitAccessList
  819. (
  820. PEXPLICIT_ACCESS_W pExplicitAccessList,
  821. ULONG *pulNumOfExplicitAccesses
  822. )
  823. {
  824. ReleaseExplicitAccessList(*pulNumOfExplicitAccesses, pExplicitAccessList);
  825. *pulNumOfExplicitAccesses = 0;
  826. }
  827. /*
  828. Function: PrintEnvironment
  829. Parameter: none
  830. Return: void
  831. Purpose: This function prints out the current setting of the
  832. client side global varibles.
  833. */
  834. void PrintEnvironment
  835. (
  836. void
  837. )
  838. {
  839. printf("Local access request list:\n");
  840. DumpAccessRequestList(g_ulNumOfLocalAccessRequests, g_pLocalAccessRequestList);
  841. printf("Local explicit access list:\n");
  842. DumpExplicitAccessList(g_ulNumOfLocalExplicitAccesses, g_pLocalExplicitAccessList);
  843. printf("Local trustee list:\n");
  844. DumpTrusteeList(g_ulNumOfLocalTrustees, g_pLocalTrusteeList);
  845. printf("The explicit access list returned form the last call to GetExplicitAccessRights:\n");
  846. DumpExplicitAccessList(g_ulNumOfExplicitAccessesReturned, g_pReturnedExplicitAccessList);
  847. printf("Current trustee record:\n");
  848. DumpTrusteeRecord(&g_LocalTrusteeRecord);
  849. } // PrintEnvironment
  850. void DumpTrusteeRecord
  851. (
  852. TRUSTEE_RECORD *pTrusteeRecord
  853. )
  854. {
  855. CHAR pszTrusteeName[200];
  856. ULONG ulStrLen;
  857. printf("Access permissions:\n");
  858. DumpAccessPermissions(pTrusteeRecord->grfAccessPermissions);
  859. printf("Access mode: ");
  860. DumpAccessMode(pTrusteeRecord->grfAccessMode);
  861. printf("Inheritance: ");
  862. DumpInheritance(pTrusteeRecord->grfInheritance);
  863. printf("pMultipleTrustree is ");
  864. if(pTrusteeRecord->pMultipleTrustee == NULL)
  865. {
  866. printf("NULL.\n");
  867. }
  868. else
  869. {
  870. printf("non-NULL.\n");
  871. }
  872. printf("MultipleTrusteeOperation: ");
  873. DumpMultipleTrusteeOperation(pTrusteeRecord->MultipleTrusteeOperation);
  874. printf("TrusteeForm: ");
  875. DumpTrusteeForm(pTrusteeRecord->TrusteeForm);
  876. printf("TrusteeType: ");
  877. DumpTrusteeType(pTrusteeRecord->TrusteeType);
  878. if (pTrusteeRecord->pwszTrusteeName == NULL)
  879. {
  880. strcpy(pszTrusteeName, "<NULL>");
  881. }
  882. else
  883. {
  884. ulStrLen = WideCharToMultiByte( CP_ACP
  885. , 0
  886. , pTrusteeRecord->pwszTrusteeName
  887. , -1
  888. , pszTrusteeName
  889. , 200
  890. , NULL
  891. , NULL );
  892. }
  893. printf("Trustee's name: %s\n", pszTrusteeName);
  894. printf("Trustee's SID: \n");
  895. DumpSID(pTrusteeRecord->pSID);
  896. printf("\n");
  897. }
  898. void DumpAccessRequestList
  899. (
  900. ULONG ulNumOfEntries,
  901. ACCESS_REQUEST_W pAccessRequestList[]
  902. )
  903. {
  904. ULONG i;
  905. PACCESS_REQUEST_W pLocalAccessRequestListPtr;
  906. for (i = 0, pLocalAccessRequestListPtr = pAccessRequestList; i < ulNumOfEntries; i++, pLocalAccessRequestListPtr++)
  907. {
  908. printf("Access request #%d:\n\n", i);
  909. printf("Access permissions: ");
  910. DumpAccessPermissions(pLocalAccessRequestListPtr->grfAccessPermissions);
  911. printf("Trustee: \n");
  912. DumpTrustee(&(pLocalAccessRequestListPtr->Trustee));
  913. printf("\n");
  914. }
  915. }
  916. /*
  917. Function: DumpLocalExplicitAccessList
  918. Parameters: ULONG ulNumOfEntries - Number of EXPLICIT_ACCESS structures in the array
  919. EXPLICIT_ACCESS_W pExplicitAccessList - Pointer to an array of EXPLICIT_ACCESS structures to be printed
  920. to be printed to the console.
  921. Purpose: This function prints an array of explicit access structures to the console
  922. */
  923. void DumpExplicitAccessList
  924. (
  925. ULONG ulNumOfEntries,
  926. EXPLICIT_ACCESS_W pExplicitAccessList[]
  927. )
  928. {
  929. ULONG i; // Loop counter
  930. EXPLICIT_ACCESS_W *pLocalExplicitAccessListPtr; // Local pointer for stepping through the explicit access list
  931. for (pLocalExplicitAccessListPtr = pExplicitAccessList, i = 0; i < ulNumOfEntries; i++, pLocalExplicitAccessListPtr++)
  932. {
  933. printf("Entry #%d.\n\n", i);
  934. printf("Access permissions:\n");
  935. DumpAccessPermissions(pLocalExplicitAccessListPtr->grfAccessPermissions);
  936. printf("Access mode: ");
  937. DumpAccessMode(pLocalExplicitAccessListPtr->grfAccessMode);
  938. printf("Inheritance: ");
  939. DumpInheritance(pLocalExplicitAccessListPtr->grfInheritance);
  940. printf("Trustee:\n");
  941. DumpTrustee(&(pLocalExplicitAccessListPtr->Trustee));
  942. printf("End Of entry #%d.\n\n", i);
  943. } // for
  944. } // DumpLocalExplicitAccessList
  945. void DumpAccessPermissions
  946. (
  947. DWORD grfAccessPermissions
  948. )
  949. {
  950. if(grfAccessPermissions & COM_RIGHTS_EXECUTE)
  951. {
  952. printf("COM_RIGHTS_EXECUTE\n");
  953. }
  954. if(grfAccessPermissions & BOGUS_ACCESS_RIGHT1)
  955. {
  956. printf("BOGUS_ACCESS_RIGHT1\n");
  957. }
  958. if(grfAccessPermissions & BOGUS_ACCESS_RIGHT2)
  959. {
  960. printf("BOGUS_ACCESS_RIGHT2\n");
  961. }
  962. if(grfAccessPermissions & BOGUS_ACCESS_RIGHT3)
  963. {
  964. printf("BOGUS_ACCESS_RIGHT3\n");
  965. }
  966. if(grfAccessPermissions & BOGUS_ACCESS_RIGHT4)
  967. {
  968. printf("BOGUS_ACCESS_RIGHT4\n");
  969. }
  970. }
  971. DWORD StringToAccessPermission
  972. (
  973. CHAR *pszString
  974. )
  975. {
  976. if (strcmp(pszString, "com_rights_execute") == 0)
  977. {
  978. return COM_RIGHTS_EXECUTE;
  979. }
  980. if (strcmp(pszString, "bogus_access_right1") == 0)
  981. {
  982. return BOGUS_ACCESS_RIGHT1;
  983. }
  984. if (strcmp(pszString, "bogus_access_right2") == 0)
  985. {
  986. return BOGUS_ACCESS_RIGHT2;
  987. }
  988. if (strcmp(pszString, "bogus_access_right3") == 0)
  989. {
  990. return BOGUS_ACCESS_RIGHT3;
  991. }
  992. if (strcmp(pszString, "bogus_access_right4") == 0)
  993. {
  994. return BOGUS_ACCESS_RIGHT4;
  995. }
  996. return 0;
  997. }
  998. void DumpAccessMode
  999. (
  1000. ACCESS_MODE grfAccessMode
  1001. )
  1002. {
  1003. switch(grfAccessMode)
  1004. {
  1005. case NOT_USED_ACCESS:
  1006. printf("NOT_USED_ACCESS\n");
  1007. break;
  1008. case GRANT_ACCESS:
  1009. printf("GRANT_ACCESS\n");
  1010. break;
  1011. case DENY_ACCESS:
  1012. printf("DENY_ACCESS\n");
  1013. break;
  1014. case SET_ACCESS:
  1015. printf("SET_ACCESS\n");
  1016. break;
  1017. case REVOKE_ACCESS:
  1018. printf("REVOKE_ACCESS\n");
  1019. break;
  1020. case SET_AUDIT_SUCCESS:
  1021. printf("SET_AUDIT_SUCCESS\n");
  1022. break;
  1023. case SET_AUDIT_FAILURE:
  1024. printf("SET_AUDIT_FAILURE\n");
  1025. break;
  1026. } // switch
  1027. } // DumpAccessMode
  1028. void DumpTrusteeList
  1029. (
  1030. ULONG ulNumOfTrustees,
  1031. TRUSTEE_W pTrusteeList[]
  1032. )
  1033. {
  1034. ULONG i;
  1035. PTRUSTEE_W pTrusteeListPtr;
  1036. for( i = 0, pTrusteeListPtr = pTrusteeList
  1037. ; i < ulNumOfTrustees
  1038. ; i++, pTrusteeListPtr++)
  1039. {
  1040. printf("Trustee #%d:\n", i);
  1041. DumpTrustee(pTrusteeListPtr);
  1042. printf("\n");
  1043. }
  1044. }
  1045. void DumpTrustee
  1046. (
  1047. TRUSTEE_W *pTrustee
  1048. )
  1049. {
  1050. char pszTrusteeName[256];
  1051. ULONG ulStrLen;
  1052. printf("pMultipleTrustee is ");
  1053. if(pTrustee->pMultipleTrustee == NULL)
  1054. {
  1055. printf("NULL.\n");
  1056. }
  1057. else
  1058. {
  1059. printf("non-NULL.\n");
  1060. }
  1061. printf("MultipleTrusteeOperation: ");
  1062. DumpMultipleTrusteeOperation(pTrustee->MultipleTrusteeOperation);
  1063. printf("TrusteeForm: ");
  1064. DumpTrusteeForm(pTrustee->TrusteeForm);
  1065. printf("TrusteeType: ");
  1066. DumpTrusteeType(pTrustee->TrusteeType);
  1067. switch(pTrustee->TrusteeForm)
  1068. {
  1069. case TRUSTEE_IS_NAME:
  1070. if (pTrustee->ptstrName == NULL)
  1071. {
  1072. strcpy(pszTrusteeName, "<NULL>");
  1073. }
  1074. else
  1075. {
  1076. ulStrLen = WideCharToMultiByte( CP_ACP
  1077. , 0
  1078. , pTrustee->ptstrName
  1079. , -1
  1080. , pszTrusteeName
  1081. , 256
  1082. , NULL
  1083. , NULL );
  1084. pszTrusteeName[ulStrLen] = '\0';
  1085. }
  1086. printf("Trustee's name is: %s\n", pszTrusteeName);
  1087. break;
  1088. case TRUSTEE_IS_SID:
  1089. printf("Trustee's SID is:\n");
  1090. DumpSID((PISID)(pTrustee->ptstrName));
  1091. break;
  1092. } // switch
  1093. }
  1094. void DumpMultipleTrusteeOperation
  1095. (
  1096. MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation
  1097. )
  1098. {
  1099. switch(MultipleTrusteeOperation)
  1100. {
  1101. case NO_MULTIPLE_TRUSTEE:
  1102. printf("NO_MULTIPLE_TRUSTEE\n");
  1103. break;
  1104. case TRUSTEE_IS_IMPERSONATE:
  1105. printf("TRUSTEE_IS_IMPERSONATE\n");
  1106. break;
  1107. }
  1108. }
  1109. MULTIPLE_TRUSTEE_OPERATION StringToMultipleTrusteeOperation
  1110. (
  1111. CHAR *pszString
  1112. )
  1113. {
  1114. if(strcmp(pszString, "no_multiple_trustee") == 0)
  1115. {
  1116. return NO_MULTIPLE_TRUSTEE;
  1117. }
  1118. if(strcmp(pszString, "trustee_is_impersonate") == 0)
  1119. {
  1120. return TRUSTEE_IS_IMPERSONATE;
  1121. }
  1122. return NO_MULTIPLE_TRUSTEE;
  1123. }
  1124. void DumpTrusteeType
  1125. (
  1126. TRUSTEE_TYPE TrusteeType
  1127. )
  1128. {
  1129. switch (TrusteeType)
  1130. {
  1131. case TRUSTEE_IS_UNKNOWN:
  1132. printf("TRUSTEE_IS_UNKNOWN\n");
  1133. break;
  1134. case TRUSTEE_IS_USER:
  1135. printf("TRUSTEE_IS_USER\n");
  1136. break;
  1137. case TRUSTEE_IS_GROUP:
  1138. printf("TRSUTEE_IS_GROUP\n");
  1139. break;
  1140. }
  1141. }
  1142. TRUSTEE_TYPE StringToTrusteeType
  1143. (
  1144. CHAR *pszString
  1145. )
  1146. {
  1147. if(strcmp(pszString, "trustee_is_unknown") == 0)
  1148. {
  1149. return TRUSTEE_IS_UNKNOWN;
  1150. }
  1151. if(strcmp(pszString, "trustee_is_user") == 0)
  1152. {
  1153. return TRUSTEE_IS_USER;
  1154. }
  1155. if(strcmp(pszString, "trustee_is_group") == 0)
  1156. {
  1157. return TRUSTEE_IS_GROUP;
  1158. }
  1159. return TRUSTEE_IS_UNKNOWN;
  1160. }
  1161. void DumpTrusteeForm
  1162. (
  1163. TRUSTEE_FORM TrusteeForm
  1164. )
  1165. {
  1166. switch (TrusteeForm)
  1167. {
  1168. case TRUSTEE_IS_NAME:
  1169. printf("TRUSTEE_IS_NAME\n");
  1170. break;
  1171. case TRUSTEE_IS_SID:
  1172. printf("TRUSTEE_IS_SID\n");
  1173. break;
  1174. }
  1175. }
  1176. TRUSTEE_FORM StringToTrusteeForm
  1177. (
  1178. CHAR *pszString
  1179. )
  1180. {
  1181. if (strcmp(pszString, "trustee_is_name") == 0)
  1182. {
  1183. return TRUSTEE_IS_NAME;
  1184. }
  1185. if (strcmp(pszString, "trustee_is_sid") == 0)
  1186. {
  1187. return TRUSTEE_IS_SID;
  1188. }
  1189. return TRUSTEE_IS_NAME;
  1190. }
  1191. void DumpSID
  1192. (
  1193. PISID pSID
  1194. )
  1195. {
  1196. ULONG i;
  1197. if( pSID == NULL)
  1198. {
  1199. printf("<NULL>\n");
  1200. }
  1201. else
  1202. {
  1203. printf("Revision: %d\n", pSID->Revision);
  1204. printf("SubAuthorityCount: %d\n", pSID->SubAuthorityCount);
  1205. printf("IdentifierAuthority: {%d,%d,%d,%d,%d,%d}\n", (pSID->IdentifierAuthority.Value)[0]
  1206. , (pSID->IdentifierAuthority.Value)[1]
  1207. , (pSID->IdentifierAuthority.Value)[2]
  1208. , (pSID->IdentifierAuthority.Value)[3]
  1209. , (pSID->IdentifierAuthority.Value)[4]
  1210. , (pSID->IdentifierAuthority.Value)[5] );
  1211. printf("SubAuthorities:\n");
  1212. for (i = 0; i < pSID->SubAuthorityCount; i++)
  1213. {
  1214. printf("%d\n", pSID->SubAuthority[i]);
  1215. }
  1216. }
  1217. }
  1218. ACCESS_MODE StringToAccessMode
  1219. (
  1220. CHAR *pszString
  1221. )
  1222. {
  1223. if(strcmp(pszString, "not_use_access") == 0)
  1224. {
  1225. return NOT_USED_ACCESS;
  1226. }
  1227. if(strcmp(pszString, "grant_access") == 0)
  1228. {
  1229. return GRANT_ACCESS;
  1230. }
  1231. if(strcmp(pszString, "set_access") == 0)
  1232. {
  1233. return SET_ACCESS;
  1234. }
  1235. if(strcmp(pszString, "deny_access") == 0)
  1236. {
  1237. return DENY_ACCESS;
  1238. }
  1239. if(strcmp(pszString, "revoke_access") == 0)
  1240. {
  1241. return REVOKE_ACCESS;
  1242. }
  1243. if(strcmp(pszString, "set_audit_success") == 0)
  1244. {
  1245. return SET_AUDIT_SUCCESS;
  1246. }
  1247. if(strcmp(pszString, "set_audit_failure") == 0)
  1248. {
  1249. return SET_AUDIT_FAILURE;
  1250. }
  1251. return NOT_USED_ACCESS;
  1252. }
  1253. void DumpInheritance
  1254. (
  1255. DWORD grfInheritance
  1256. )
  1257. {
  1258. switch(grfInheritance)
  1259. {
  1260. case NO_INHERITANCE:
  1261. printf("NO_INHERITANCE\n");
  1262. break;
  1263. case SUB_CONTAINERS_ONLY_INHERIT:
  1264. printf("SUB_CONTAINERS_ONLY_INHERIT\n");
  1265. break;
  1266. case SUB_OBJECTS_ONLY_INHERIT:
  1267. printf("SUB_OBJECTS_ONLY_INHERIT\n");
  1268. break;
  1269. case SUB_CONTAINERS_AND_OBJECTS_INHERIT:
  1270. printf("SUB_CONTAINERS_AND_OBJECTS_INHERIT\n");
  1271. break;
  1272. }
  1273. }
  1274. DWORD StringToInheritance
  1275. (
  1276. CHAR *pszString
  1277. )
  1278. {
  1279. if (strcmp(pszString, "no_inheritance") == 0)
  1280. {
  1281. return NO_INHERITANCE;
  1282. }
  1283. if (strcmp(pszString, "sub_containers_only_inherit") == 0)
  1284. {
  1285. return SUB_CONTAINERS_ONLY_INHERIT;
  1286. }
  1287. if (strcmp(pszString, "sub_objects_only_inherit") == 0)
  1288. {
  1289. return SUB_OBJECTS_ONLY_INHERIT;
  1290. }
  1291. if (strcmp(pszString, "sub_containers_and_objects_inherit") == 0)
  1292. {
  1293. return SUB_CONTAINERS_AND_OBJECTS_INHERIT;
  1294. }
  1295. return 0;
  1296. }
  1297. void ReleaseExplicitAccessList
  1298. (
  1299. ULONG cCount,
  1300. PEXPLICIT_ACCESS_W pExplicitAccessList
  1301. )
  1302. {
  1303. ULONG i;
  1304. for (i = 0; i < cCount; i++)
  1305. {
  1306. midl_user_free(pExplicitAccessList[i].Trustee.ptstrName);
  1307. }
  1308. if(pExplicitAccessList != g_pLocalExplicitAccessList)
  1309. {
  1310. midl_user_free(pExplicitAccessList);
  1311. }
  1312. }
  1313. void CopyExplicitAccessList
  1314. (
  1315. PEXPLICIT_ACCESS_W pTarget,
  1316. PEXPLICIT_ACCESS_W pSource,
  1317. ULONG *pcCount,
  1318. ULONG cCount
  1319. )
  1320. {
  1321. ULONG i;
  1322. PEXPLICIT_ACCESS_W pTargetPtr;
  1323. PEXPLICIT_ACCESS_W pSourcePtr;
  1324. ULONG ulTrusteeNameSize;
  1325. for ( i = 0, pTargetPtr = pTarget, pSourcePtr = pSource
  1326. ; i < cCount
  1327. ; i++, pTargetPtr++, pSourcePtr++)
  1328. {
  1329. memcpy(pTargetPtr, pSourcePtr, sizeof(EXPLICIT_ACCESS));
  1330. switch(pTargetPtr->Trustee.TrusteeForm)
  1331. {
  1332. case TRUSTEE_IS_SID:
  1333. ulTrusteeNameSize = GetSidLengthRequired(((PISID)(pTargetPtr->Trustee.ptstrName))->SubAuthorityCount);
  1334. pTargetPtr->Trustee.ptstrName = (LPWSTR)midl_user_allocate(ulTrusteeNameSize);
  1335. CopySid(ulTrusteeNameSize, (PISID)(pTargetPtr->Trustee.ptstrName), (PISID)(pSourcePtr->Trustee.ptstrName));
  1336. break;
  1337. case TRUSTEE_IS_NAME:
  1338. ulTrusteeNameSize = lstrlenW(pSourcePtr->Trustee.ptstrName);
  1339. pTargetPtr->Trustee.ptstrName = (LPWSTR)midl_user_allocate((ulTrusteeNameSize + 1) * sizeof(WCHAR));
  1340. lstrcpyW(pTargetPtr->Trustee.ptstrName, pSourcePtr->Trustee.ptstrName);
  1341. break;
  1342. }
  1343. }
  1344. *pcCount = cCount;
  1345. }
  1346. void ExecTestServer
  1347. (
  1348. CHAR *pszTestString
  1349. )
  1350. {
  1351. ULONG ulCode;
  1352. HRESULT hr;
  1353. printf("Calling TestServer.\n");
  1354. g_pIAccessControlTest->TestServer(pszTestString);
  1355. } // ExecTestServer
  1356. void ExecRevertAccessRights
  1357. (
  1358. void
  1359. )
  1360. {
  1361. ULONG ulCode;
  1362. HRESULT hr;
  1363. printf("Calling RevertAccessRights.\n");
  1364. hr = g_pIAccessControlTest->RevertAccessRights();
  1365. if(hr == E_NOTIMPL)
  1366. {
  1367. printf("hr is E_NOTIMPL.\n");
  1368. }
  1369. } // ExecRevertAccessRights
  1370. void ExecCommitAccessRights
  1371. (
  1372. void
  1373. )
  1374. {
  1375. ULONG ulCode;
  1376. HRESULT hr;
  1377. printf("Calling CommitAccessRights.\n");
  1378. hr = g_pIAccessControlTest->CommitAccessRights(0);
  1379. if(hr == E_NOTIMPL)
  1380. {
  1381. printf("hr is E_NOTIMPL.\n");
  1382. }
  1383. } // ExecCommitAccessRights
  1384. void ExecGetClassID
  1385. (
  1386. void
  1387. )
  1388. {
  1389. ULONG ulCode;
  1390. DOUBLE dMillisec;
  1391. DWORD dwTotalTickCount;
  1392. CLSID clsid;
  1393. HRESULT hr;
  1394. printf("Calling GetClassID.\n");
  1395. dwTotalTickCount = GetTickCount();
  1396. hr = g_pIAccessControlTest->GetClassID(&clsid, &dMillisec);
  1397. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1398. if(SUCCEEDED(hr))
  1399. {
  1400. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1401. printf("The clsid returned is {%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}.\n"
  1402. , clsid.Data1, clsid.Data2, clsid.Data3
  1403. , clsid.Data4[0], clsid.Data4[1], clsid.Data4[2]
  1404. , clsid.Data4[3], clsid.Data4[4], clsid.Data4[5]
  1405. , clsid.Data4[6], clsid.Data4[7]);
  1406. }
  1407. else
  1408. {
  1409. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1410. } // if
  1411. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1412. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1413. } // ExecGetSizeMax
  1414. void ExecInitNewACL
  1415. (
  1416. void
  1417. )
  1418. {
  1419. ULONG ulCode;
  1420. DOUBLE dMillisec;
  1421. DWORD dwTotalTickCount;
  1422. HRESULT hr;
  1423. printf("Calling InitNewACL.\n");
  1424. dwTotalTickCount = GetTickCount();
  1425. hr = g_pIAccessControlTest->InitNewACL(&dMillisec);
  1426. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1427. if(SUCCEEDED(hr))
  1428. {
  1429. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1430. }
  1431. else
  1432. {
  1433. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1434. } // if
  1435. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1436. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1437. } // ExecInitNewACL
  1438. void ExecLoadACL
  1439. (
  1440. CHAR *pszFilename
  1441. )
  1442. {
  1443. ULONG ulCode;
  1444. DOUBLE dMillisec;
  1445. DWORD dwTotalTickCount;
  1446. HRESULT hr;
  1447. printf("Calling LoadACL.\n");
  1448. dwTotalTickCount = GetTickCount();
  1449. hr = g_pIAccessControlTest->LoadACL(pszFilename, &dMillisec);
  1450. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1451. if(SUCCEEDED(hr))
  1452. {
  1453. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1454. }
  1455. else
  1456. {
  1457. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1458. } // if
  1459. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1460. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1461. } // ExecLoadACL
  1462. void ExecSaveACL
  1463. (
  1464. CHAR *pszFilename
  1465. )
  1466. {
  1467. ULONG ulCode;
  1468. DOUBLE dMillisec;
  1469. DWORD dwTotalTickCount;
  1470. ULONG ulNumOfBytesWritten;
  1471. HRESULT hr;
  1472. printf("Calling SaveACL.\n");
  1473. dwTotalTickCount = GetTickCount();
  1474. hr = g_pIAccessControlTest->SaveACL(pszFilename, TRUE, &ulNumOfBytesWritten, &dMillisec);
  1475. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1476. if(SUCCEEDED(hr))
  1477. {
  1478. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1479. }
  1480. else
  1481. {
  1482. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1483. } // if
  1484. printf("The number of bytes written to the file was %d\n", ulNumOfBytesWritten);
  1485. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1486. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1487. } // ExecSaveACL
  1488. void ExecGetSizeMax
  1489. (
  1490. void
  1491. )
  1492. {
  1493. ULONG ulCode;
  1494. DWORD dwTotalTickCount;
  1495. DOUBLE dMillisec;
  1496. ULONG ulNumOfBytesRequired;
  1497. HRESULT hr;
  1498. printf("Calling GetSizeMax.\n");
  1499. dwTotalTickCount = GetTickCount();
  1500. hr = g_pIAccessControlTest->GetSizeMax(&ulNumOfBytesRequired, &dMillisec);
  1501. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1502. if(SUCCEEDED(hr))
  1503. {
  1504. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1505. }
  1506. else
  1507. {
  1508. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1509. } // if
  1510. printf("The number of bytes required to save the ACL was %d\n", ulNumOfBytesRequired);
  1511. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1512. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1513. } // ExecGetSizeMax
  1514. void ExecIsDirty
  1515. (
  1516. void
  1517. )
  1518. {
  1519. ULONG ulCode;
  1520. DOUBLE dMillisec;
  1521. DWORD dwTotalTickCount;
  1522. HRESULT hr;
  1523. printf("Calling IsDirty.\n");
  1524. dwTotalTickCount = GetTickCount();
  1525. hr = g_pIAccessControlTest->IsDirty(&dMillisec);
  1526. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1527. if(SUCCEEDED(hr))
  1528. {
  1529. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1530. if(hr == S_OK)
  1531. {
  1532. printf("The access control object was dirty.\n");
  1533. }
  1534. else
  1535. {
  1536. printf("The access control object was clean.\n");
  1537. }
  1538. }
  1539. else
  1540. {
  1541. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1542. } // if
  1543. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1544. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1545. } // ExecIsDirty
  1546. void ExecGrantAccessRights
  1547. (
  1548. void
  1549. )
  1550. {
  1551. ULONG ulCode;
  1552. DOUBLE dMillisec;
  1553. DWORD dwTotalTickCount;
  1554. HRESULT hr;
  1555. printf("Calling GrantAccessRights.\n");
  1556. dwTotalTickCount = GetTickCount();
  1557. hr = g_pIAccessControlTest->GrantAccessRights(g_ulNumOfLocalAccessRequests, (PE_ACCESS_REQUEST)(g_pLocalAccessRequestList), &dMillisec);
  1558. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1559. if(SUCCEEDED(hr))
  1560. {
  1561. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1562. }
  1563. else
  1564. {
  1565. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1566. } // if
  1567. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1568. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1569. } // ExecGrantAccessRights
  1570. void ExecSetAccessRights
  1571. (
  1572. void
  1573. )
  1574. {
  1575. ULONG ulCode;
  1576. DOUBLE dMillisec;
  1577. DWORD dwTotalTickCount;
  1578. HRESULT hr;
  1579. printf("Calling SetAccessRights.\n");
  1580. dwTotalTickCount = GetTickCount();
  1581. hr = g_pIAccessControlTest->SetAccessRights(g_ulNumOfLocalAccessRequests, (PE_ACCESS_REQUEST)g_pLocalAccessRequestList, &dMillisec);
  1582. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1583. if(SUCCEEDED(hr))
  1584. {
  1585. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1586. }
  1587. else
  1588. {
  1589. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1590. } // if
  1591. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1592. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1593. } // ExecSetAccessRights
  1594. void ExecDenyAccessRights
  1595. (
  1596. void
  1597. )
  1598. {
  1599. ULONG ulCode;
  1600. DOUBLE dMillisec;
  1601. DWORD dwTotalTickCount;
  1602. HRESULT hr;
  1603. printf("Calling DenyAccessRights.\n");
  1604. dwTotalTickCount = GetTickCount();
  1605. hr = g_pIAccessControlTest->DenyAccessRights(g_ulNumOfLocalAccessRequests, (PE_ACCESS_REQUEST)g_pLocalAccessRequestList, &dMillisec);
  1606. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1607. if(SUCCEEDED(hr))
  1608. {
  1609. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1610. }
  1611. else
  1612. {
  1613. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1614. } // if
  1615. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1616. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1617. } // ExecDenyAccessRights
  1618. void ExecReplaceAllAccessRights
  1619. (
  1620. void
  1621. )
  1622. {
  1623. ULONG ulCode;
  1624. DOUBLE dMillisec;
  1625. DWORD dwTotalTickCount;
  1626. HRESULT hr;
  1627. printf("Calling ReplaceAllAccessRights.\n");
  1628. dwTotalTickCount = GetTickCount();
  1629. hr = g_pIAccessControlTest->ReplaceAllAccessRights(g_ulNumOfLocalExplicitAccesses, (PE_EXPLICIT_ACCESS)g_pLocalExplicitAccessList, &dMillisec);
  1630. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1631. if(SUCCEEDED(hr))
  1632. {
  1633. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1634. }
  1635. else
  1636. {
  1637. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1638. } // if
  1639. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1640. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1641. } // ExecReplaceAllAccessRights
  1642. void ExecRevokeExplicitAccessRights
  1643. (
  1644. void
  1645. )
  1646. {
  1647. ULONG ulCode;
  1648. DOUBLE dMillisec;
  1649. DWORD dwTotalTickCount;
  1650. HRESULT hr;
  1651. printf("Calling RevokeExplicitAccessRights.\n");
  1652. dwTotalTickCount = GetTickCount();
  1653. hr = g_pIAccessControlTest->RevokeExplicitAccessRights(g_ulNumOfLocalTrustees, (PE_TRUSTEE)g_pLocalTrusteeList, &dMillisec);
  1654. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1655. if(SUCCEEDED(hr))
  1656. {
  1657. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1658. }
  1659. else
  1660. {
  1661. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1662. } // if
  1663. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1664. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1665. } // ExecRevokeExplicitAccessRights
  1666. void ExecIsAccessPermitted
  1667. (
  1668. void
  1669. )
  1670. {
  1671. ULONG ulCode;
  1672. DOUBLE dMillisec;
  1673. DWORD dwTotalTickCount;
  1674. HRESULT hr;
  1675. TRUSTEE_W Trustee;
  1676. MapTrusteeRecordToTrustee(&g_LocalTrusteeRecord, &Trustee);
  1677. printf("Calling IsAccessPermitted.\n");
  1678. dwTotalTickCount = GetTickCount();
  1679. hr = g_pIAccessControlTest->IsAccessPermitted((PE_TRUSTEE)&Trustee, g_LocalTrusteeRecord.grfAccessPermissions, &dMillisec);
  1680. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1681. if (hr == S_OK)
  1682. {
  1683. printf("The current trustee is granted the current set of access rights.\n");
  1684. }
  1685. else if (hr == E_ACCESSDENIED)
  1686. {
  1687. printf("The current trustee is denied the current set of access rights.\n");
  1688. }
  1689. else
  1690. {
  1691. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1692. } // if
  1693. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1694. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1695. } // ExecIsAccessPermitted
  1696. void ExecGetEffectiveAccessRights
  1697. (
  1698. void
  1699. )
  1700. {
  1701. ULONG ulCode;
  1702. DOUBLE dMillisec;
  1703. DWORD dwTotalTickCount;
  1704. HRESULT hr;
  1705. TRUSTEE_W Trustee;
  1706. DWORD dwRights;
  1707. MapTrusteeRecordToTrustee(&g_LocalTrusteeRecord, &Trustee);
  1708. printf("Calling GetEffectiveAccessRights.\n");
  1709. dwTotalTickCount = GetTickCount();
  1710. hr = g_pIAccessControlTest->GetEffectiveAccessRights((PE_TRUSTEE)&Trustee, &dwRights, &dMillisec);
  1711. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1712. if(SUCCEEDED(hr))
  1713. {
  1714. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1715. printf("The set of effective access rights available to the current trustee includes:\n");
  1716. DumpAccessPermissions(dwRights);
  1717. }
  1718. else
  1719. {
  1720. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1721. } // if
  1722. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1723. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1724. } // ExecGetEffectiveAccessRights
  1725. void ExecGetExplicitAccessRights
  1726. (
  1727. void
  1728. )
  1729. {
  1730. ULONG ulCode;
  1731. DOUBLE dMillisec;
  1732. DWORD dwTotalTickCount;
  1733. HRESULT hr;
  1734. // If the global retruned explicit access list pointer is not NULL,
  1735. // release the old returned explicit access list
  1736. if (g_pReturnedExplicitAccessList != NULL)
  1737. {
  1738. ReleaseExplicitAccessList(g_ulNumOfExplicitAccessesReturned, g_pReturnedExplicitAccessList);
  1739. } // if
  1740. g_pReturnedExplicitAccessList = NULL;
  1741. printf("Calling GetExplicitAccessRights.\n");
  1742. dwTotalTickCount = GetTickCount();
  1743. hr = g_pIAccessControlTest->GetExplicitAccessRights(&g_ulNumOfExplicitAccessesReturned, (PE_EXPLICIT_ACCESS *)&g_pReturnedExplicitAccessList, &dMillisec);
  1744. dwTotalTickCount = GetTickCount() - dwTotalTickCount;
  1745. if(SUCCEEDED(hr))
  1746. {
  1747. printf("The command was executed successfully on the server side with a return code of %x.\n", hr);
  1748. printf("The number of explicit access structures returned is %d.\n", g_ulNumOfExplicitAccessesReturned);
  1749. printf("The returned explicit access list is as follows:\n");
  1750. DumpExplicitAccessList(g_ulNumOfExplicitAccessesReturned, g_pReturnedExplicitAccessList);
  1751. }
  1752. else
  1753. {
  1754. printf("Execution of the command failed on the server side with a return code of %x.\n", hr);
  1755. } // if
  1756. printf("The time spent on the server side to execute the command was %fms.\n", dMillisec);
  1757. printf("The total number of clock ticks spent on the DCOM call was %d.\n", dwTotalTickCount);
  1758. } // ExecGetExplicitAccessRights
  1759. void ExecCleanupProc
  1760. (
  1761. void
  1762. )
  1763. {
  1764. ULONG ulCode;
  1765. // Release the IAccessControlTest pointer
  1766. g_pIAccessControlTest->Release();
  1767. g_pIUnknown->Release();
  1768. // Cleanup all the memory allocated for the Local list
  1769. DestroyAccessRequestList(g_pLocalAccessRequestList, &g_ulNumOfLocalAccessRequests);
  1770. DestroyTrusteeList(g_pLocalTrusteeList, &g_ulNumOfLocalTrustees);
  1771. DestroyExplicitAccessList(g_pLocalExplicitAccessList, &g_ulNumOfLocalExplicitAccesses);
  1772. DestroyExplicitAccessList(g_pReturnedExplicitAccessList, &g_ulNumOfExplicitAccessesReturned);
  1773. } // ExecCleanupProc
  1774. /*
  1775. Function: Tokenize
  1776. Parameters: [in] char *pLineBuffer
  1777. [out] char *pTokens[]
  1778. [out] short *piNumOfTokens
  1779. Return: void
  1780. Purpose: This function partition a string of space delimited tokens
  1781. to null delimited tokens and return pointers to each individual
  1782. token in pTokens and the number of tokens ion the string in
  1783. piNumOfTokens.
  1784. Comment: Memory for the array of char * Tokens should be allocated by
  1785. the caller.
  1786. This function is implemented as a simple finite state machine.
  1787. State 0 - Outside a token
  1788. State 1 - Inside a token
  1789. */
  1790. void Tokenize
  1791. (
  1792. char * pLineBuffer,
  1793. char * pTokens[],
  1794. short * piNumOfTokens
  1795. )
  1796. {
  1797. short iTokens = 0; // Token index
  1798. char *pLBuffPtr = pLineBuffer; // Pointer in the line buffer
  1799. char c; // current character
  1800. short state = 0; // State of the tokenizing machine
  1801. for(;;)
  1802. {
  1803. c = *pLBuffPtr;
  1804. switch(state)
  1805. {
  1806. case 0:
  1807. switch(c)
  1808. {
  1809. case '\t': // Ignore blanks
  1810. case ' ':
  1811. case '\n':
  1812. break;
  1813. case '\0':
  1814. goto end;
  1815. default:
  1816. state=1;
  1817. pTokens[iTokens]=pLBuffPtr;
  1818. break;
  1819. } // switch
  1820. break;
  1821. case 1:
  1822. switch(c)
  1823. {
  1824. case '\t':
  1825. case ' ':
  1826. case '\n':
  1827. *pLBuffPtr='\0';
  1828. iTokens++;
  1829. state=0;
  1830. break;
  1831. case '\0':
  1832. *pLBuffPtr='\0';
  1833. iTokens++;
  1834. pTokens[iTokens]=pLBuffPtr;
  1835. goto end;
  1836. default:
  1837. break;
  1838. }
  1839. break;
  1840. }
  1841. pLBuffPtr++;
  1842. }// switch
  1843. end:
  1844. *piNumOfTokens = iTokens;
  1845. return;
  1846. } // Tokenize
  1847. /*********************************************************************/
  1848. /* MIDL allocate and free */
  1849. /*********************************************************************/
  1850. void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
  1851. {
  1852. return(CoTaskMemAlloc(len));
  1853. }
  1854. void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
  1855. {
  1856. CoTaskMemFree(ptr);
  1857. }
  1858. /* end file actestc.c */