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.

1016 lines
23 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: MARTATST.C
  7. //
  8. // Contents: Unit test for file propagation, issues
  9. //
  10. // History: 14-Jan-97 MacM Created
  11. //
  12. // Notes:
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <aclapi.h>
  22. #include <ntrtl.h>
  23. #define FLAG_ON(flags,bit) ((flags) & (bit))
  24. //
  25. // Flags for tests
  26. //
  27. #define MTEST_CONVERT 0x00000001
  28. #define MTEST_GETOWNER 0x00000002
  29. #define MTEST_GETSACL 0x00000004
  30. #define MTEST_BUILDSD 0x00000008
  31. #define MTEST_GETEXPL 0x00000010
  32. #define MTEST_GETEFF 0x00000020
  33. #define MTEST_GETEFF2 0x00000040
  34. #define MTEST_GETEFF3 0x00000080
  35. #define MTEST_GETAUD 0x00000100
  36. #define MTEST_BUILDSD2 0x00000200
  37. void
  38. DumpAccessEntry (
  39. PACTRL_ACCESS_ENTRY pAE
  40. )
  41. {
  42. printf("\tPACTRL_ACCESS_ENTRY@%lu\n",pAE);
  43. printf("\t\tTrustee: %ws\n", pAE->Trustee.ptstrName);
  44. printf("\t\tfAccessFlags: 0x%lx\n", pAE->fAccessFlags);
  45. printf("\t\tAccess: 0x%lx\n", pAE->Access);
  46. printf("\t\tProvSpecificAccess: 0x%lx\n", pAE->ProvSpecificAccess);
  47. printf("\t\tInheritance: 0x%lx\n", pAE->Inheritance);
  48. printf("\t\tlpInheritProperty: 0x%lx\n", pAE->lpInheritProperty);
  49. }
  50. void
  51. DumpAList (
  52. PACTRL_ACCESSW pAList
  53. )
  54. {
  55. ULONG iIndex, iAE;
  56. for ( iIndex = 0; iIndex < pAList->cEntries; iIndex++ ) {
  57. printf("\tProperty: %ws\n",
  58. pAList->pPropertyAccessList[iIndex].lpProperty);
  59. for( iAE = 0;
  60. iAE < pAList->pPropertyAccessList[iIndex].pAccessEntryList->
  61. cEntries;
  62. iAE++) {
  63. DumpAccessEntry(&(pAList->pPropertyAccessList[iIndex].
  64. pAccessEntryList->pAccessList[iAE]));
  65. }
  66. }
  67. }
  68. VOID
  69. Usage (
  70. IN PSTR pszExe
  71. )
  72. /*++
  73. Routine Description:
  74. Displays the usage
  75. Arguments:
  76. pszExe - Name of the exe
  77. Return Value:
  78. VOID
  79. --*/
  80. {
  81. printf("%s path user seinfo [/test] \n", pszExe);
  82. printf(" where path is the root path to use\n");
  83. printf(" user is the name of the trustee to use\n");
  84. printf(" seinfo is the seinfo to use for reads/writes:\n");
  85. printf(" OWNER_SECURITY_INFORMATION (0x00000001L)\n");
  86. printf(" GROUP_SECURITY_INFORMATION (0x00000002L)\n");
  87. printf(" DACL_SECURITY_INFORMATION (0x00000004L)\n");
  88. printf(" SACL_SECURITY_INFORMATION (0x00000008L)\n");
  89. printf(" /test indicates which test to run:\n");
  90. printf(" /CONVERT (ConvertSecurityDescriptorToAccessNamed)\n");
  91. printf(" /GETOWNER (Get owner for the file)\n");
  92. printf(" /GETSACL (Get sacl for the file)\n");
  93. printf(" /BUILDSD (BuildSecurityDescriptor with deny)\n");
  94. printf(" /BUILDSD2 (BuildSDA with NULL parameters)\n");
  95. printf(" /GETEXPL (GetExplicitEntriesFromAcl)\n");
  96. printf(" /GETEFF (GetEffectiveRightsFromAcl)\n");
  97. printf(" /GETEFF2 (GetEffectiveRightsFromAcl2)\n");
  98. printf(" /GETEFF3 (GetEffectiveRightsFromAcl3 [Administrators])\n");
  99. printf(" /GETAUD (GetAuditedPermissionsFromAcl on NULL SACL)\n");
  100. return;
  101. }
  102. DWORD
  103. DoConvertSecurityDescriptorToAccessNamedTest (
  104. IN PWSTR pwszPath,
  105. IN DWORD SeInfo
  106. )
  107. /*++
  108. Routine Description:
  109. Reads the SD off of the object, and converts it to a Access structure
  110. Arguments:
  111. pwszPath -- Root path
  112. Return Value:
  113. ERROR_SUCCESS -- Success
  114. --*/
  115. {
  116. DWORD dwErr = ERROR_SUCCESS;
  117. PSECURITY_DESCRIPTOR pSD;
  118. printf("ConvertSecurityDescriptorToAccessNamed\n");
  119. dwErr = GetNamedSecurityInfo( pwszPath, SE_FILE_OBJECT, SeInfo,
  120. NULL, NULL, NULL, NULL, &pSD);
  121. if (dwErr != ERROR_SUCCESS) {
  122. fprintf(stderr, "GetNamedSecurityInfo on %ws failed with %lu\n", pwszPath, dwErr);
  123. } else {
  124. PACTRL_ACCESS pAccess = NULL;
  125. PACTRL_AUDIT pAudit = NULL;
  126. LPTSTR pOwner = NULL;
  127. LPTSTR pGroup = NULL;
  128. dwErr = ConvertSecurityDescriptorToAccessNamed(
  129. pwszPath, SE_FILE_OBJECT, pSD,
  130. FLAG_ON(SeInfo, DACL_SECURITY_INFORMATION) ?
  131. &pAccess :
  132. NULL,
  133. FLAG_ON(SeInfo, SACL_SECURITY_INFORMATION) ?
  134. &pAudit :
  135. NULL,
  136. FLAG_ON(SeInfo, OWNER_SECURITY_INFORMATION) ?
  137. &pOwner :
  138. NULL,
  139. FLAG_ON(SeInfo, GROUP_SECURITY_INFORMATION) ?
  140. &pGroup :
  141. NULL );
  142. if (dwErr != ERROR_SUCCESS) {
  143. fprintf( stderr,"ConvertSecurityDescriptor failed with %lu\n", dwErr );
  144. } else {
  145. if (pAccess != NULL ) {
  146. fprintf(stdout, "Access list\n");
  147. DumpAList( pAccess );
  148. LocalFree( pAccess );
  149. }
  150. if (pAudit != NULL ) {
  151. fprintf(stdout, "Audit list\n");
  152. DumpAList( pAudit );
  153. LocalFree( pAudit );
  154. }
  155. if (pOwner != NULL ) {
  156. fprintf(stdout, "Owner: %ws\n", pOwner);
  157. LocalFree( pOwner );
  158. }
  159. if (pGroup != NULL ) {
  160. fprintf(stdout, "Group: %ws\n", pGroup);
  161. LocalFree( pGroup );
  162. }
  163. }
  164. LocalFree( pSD );
  165. }
  166. return(dwErr);
  167. }
  168. DWORD
  169. DoGetOwnerTest (
  170. IN PWSTR pwszPath,
  171. IN DWORD SeInfo
  172. )
  173. /*++
  174. Routine Description:
  175. Reads the SD off of the object, and gets the owner for from it
  176. Arguments:
  177. pwszPath -- Root path
  178. SeInfo -- Ignored
  179. Return Value:
  180. ERROR_SUCCESS -- Success
  181. --*/
  182. {
  183. DWORD dwErr = ERROR_SUCCESS;
  184. PSECURITY_DESCRIPTOR pSD;
  185. LPWSTR pwszOwner;
  186. printf("GetOwner\n");
  187. dwErr = GetNamedSecurityInfoEx( pwszPath, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION,
  188. NULL, NULL, NULL, NULL, &pwszOwner, NULL );
  189. if ( dwErr == ERROR_SUCCESS ) {
  190. fprintf(stdout, "GetNamedSecurityInfoExW returned %ws\n", pwszOwner);
  191. LocalFree( pwszOwner );
  192. } else {
  193. fprintf(stderr, "GetNamedSecurityInfoEx on %ws failed with %lu\n", pwszPath, dwErr );
  194. }
  195. return( dwErr );
  196. }
  197. DWORD
  198. DoGetSaclTest (
  199. IN PWSTR pwszPath,
  200. IN DWORD SeInfo
  201. )
  202. /*++
  203. Routine Description:
  204. Reads the SACL off of the object
  205. Arguments:
  206. pwszPath -- Root path
  207. SeInfo -- Ignored
  208. Return Value:
  209. ERROR_SUCCESS -- Success
  210. --*/
  211. {
  212. DWORD dwErr = ERROR_SUCCESS;
  213. PACTRL_AUDIT pAudit = NULL;
  214. HANDLE hProcessToken;
  215. printf("GetSacl\n");
  216. //
  217. // Enable the read sacl privs
  218. //
  219. if ( OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &hProcessToken ) == FALSE) {
  220. dwErr = GetLastError();
  221. } else {
  222. TOKEN_PRIVILEGES EnableSeSecurity;
  223. TOKEN_PRIVILEGES Previous;
  224. DWORD PreviousSize;
  225. EnableSeSecurity.PrivilegeCount = 1;
  226. EnableSeSecurity.Privileges[0].Luid.LowPart = SE_SECURITY_PRIVILEGE;
  227. EnableSeSecurity.Privileges[0].Luid.HighPart = 0;
  228. EnableSeSecurity.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  229. PreviousSize = sizeof(Previous);
  230. if (AdjustTokenPrivileges( hProcessToken, FALSE, &EnableSeSecurity,
  231. sizeof(EnableSeSecurity), &Previous,
  232. &PreviousSize ) == FALSE) {
  233. dwErr = GetLastError();
  234. }
  235. }
  236. if ( dwErr != ERROR_SUCCESS ) {
  237. fprintf( stderr, "AdjustTokenPrivileges failed with %lu\n", dwErr );
  238. } else {
  239. dwErr = GetNamedSecurityInfoEx( pwszPath, SE_FILE_OBJECT, SACL_SECURITY_INFORMATION,
  240. NULL, NULL, NULL, &pAudit, NULL, NULL);
  241. if (dwErr != ERROR_SUCCESS) {
  242. fprintf(stderr, "GetNamedSecurityInfoEx on %ws failed with %lu\n", pwszPath, dwErr);
  243. } else {
  244. fprintf(stdout, "Audit list\n");
  245. DumpAList( pAudit );
  246. LocalFree( pAudit );
  247. }
  248. }
  249. return(dwErr);
  250. }
  251. DWORD
  252. DoBuildSDTest (
  253. IN PWSTR pwszPath,
  254. IN PWSTR pwszUser
  255. )
  256. /*++
  257. Routine Description:
  258. Builds a security descriptor
  259. Arguments:
  260. pwszPath -- Root path
  261. pwszUser -- User to add
  262. Return Value:
  263. ERROR_SUCCESS -- Success
  264. --*/
  265. {
  266. DWORD dwErr = ERROR_SUCCESS;
  267. EXPLICIT_ACCESS EA[2];
  268. PSECURITY_DESCRIPTOR pNewSD = NULL;
  269. ULONG cSDSize;
  270. printf("BuildSecurityDescriptor with DENY\n");
  271. BuildExplicitAccessWithName( &(EA[0]),
  272. pwszUser,
  273. STANDARD_RIGHTS_ALL,
  274. GRANT_ACCESS,
  275. 0 );
  276. BuildExplicitAccessWithName( &(EA[1]),
  277. pwszUser,
  278. FILE_WRITE_EA,
  279. DENY_ACCESS,
  280. 0 );
  281. dwErr = BuildSecurityDescriptorW( NULL, NULL, 2, EA, 0, NULL, NULL, &cSDSize, &pNewSD );
  282. if ( dwErr != ERROR_SUCCESS ) {
  283. fprintf( stderr, "BuildSecurityDescriptorW failed with %lu\n", dwErr );
  284. } else {
  285. LocalFree( pNewSD );
  286. }
  287. return(dwErr);
  288. }
  289. DWORD
  290. DoBuildSD2Test (
  291. IN PWSTR pwszPath,
  292. IN PWSTR pwszUser
  293. )
  294. /*++
  295. Routine Description:
  296. Builds a security descriptor
  297. Arguments:
  298. pwszPath -- Root path
  299. pwszUser -- User to add
  300. Return Value:
  301. ERROR_SUCCESS -- Success
  302. --*/
  303. {
  304. DWORD dwErr = ERROR_SUCCESS;
  305. EXPLICIT_ACCESS EA[2];
  306. PSECURITY_DESCRIPTOR pNewSD = NULL;
  307. ULONG cSDSize;
  308. printf("BuildSecurityDescriptor with NULL parameters\n");
  309. dwErr = BuildSecurityDescriptorW( NULL, NULL, 0, NULL, 0, NULL, NULL, &cSDSize, &pNewSD );
  310. if ( dwErr != ERROR_SUCCESS ) {
  311. fprintf( stderr, "BuildSecurityDescriptorW failed with %lu\n", dwErr );
  312. } else {
  313. LocalFree( pNewSD );
  314. }
  315. return(dwErr);
  316. }
  317. DWORD
  318. DoGetExplicitTest (
  319. IN PWSTR pwszPath,
  320. IN ULONG SeInfo
  321. )
  322. /*++
  323. Routine Description:
  324. Builds a security descriptor
  325. Arguments:
  326. pwszPath -- Root path
  327. SeInfo -- ignored
  328. Return Value:
  329. ERROR_SUCCESS -- Success
  330. --*/
  331. {
  332. DWORD dwErr = ERROR_SUCCESS;
  333. PSECURITY_DESCRIPTOR pSD = NULL;
  334. PACL pDAcl;
  335. printf("GetExplicitEntriesFromAcl\n");
  336. //
  337. // First, get the existing security descriptor
  338. //
  339. dwErr = GetNamedSecurityInfo( pwszPath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
  340. NULL, NULL, &pDAcl, NULL, &pSD);
  341. if ( dwErr != ERROR_SUCCESS ) {
  342. fprintf( stderr, "Failed to get the access for %ws: %lu\n", pwszPath, dwErr );
  343. } else {
  344. PEXPLICIT_ACCESS pExplicit;
  345. DWORD cItems;
  346. //
  347. // Get the explicit accesses
  348. //
  349. dwErr = GetExplicitEntriesFromAcl(pDAcl, &cItems, &pExplicit);
  350. if ( dwErr != ERROR_SUCCESS ) {
  351. fprintf( stderr, "GetExplicitEntries failed with %lu\n", dwErr );
  352. } else {
  353. LocalFree( pExplicit );
  354. }
  355. LocalFree( pSD );
  356. }
  357. return(dwErr);
  358. }
  359. DWORD
  360. DoGetEffectiveTest (
  361. IN PWSTR pwszPath,
  362. IN PWSTR pwszUser
  363. )
  364. /*++
  365. Routine Description:
  366. Builds a security descriptor
  367. Arguments:
  368. pwszPath -- Root path
  369. pwszUser -- User to add
  370. Return Value:
  371. ERROR_SUCCESS -- Success
  372. --*/
  373. {
  374. DWORD dwErr = ERROR_SUCCESS;
  375. EXPLICIT_ACCESS EA[2];
  376. PSECURITY_DESCRIPTOR pNewSD = NULL;
  377. ULONG cSDSize;
  378. printf("GetEffectiveRightsFromAcl test\n");
  379. BuildExplicitAccessWithName( &(EA[0]),
  380. pwszUser,
  381. GENERIC_ALL,
  382. GRANT_ACCESS,
  383. 0x9 );
  384. BuildExplicitAccessWithName( &(EA[1]),
  385. pwszUser,
  386. 0x1f01ff,
  387. GRANT_ACCESS,
  388. 0x2 );
  389. dwErr = BuildSecurityDescriptorW( NULL, NULL, 2, EA, 0, NULL, NULL, &cSDSize, &pNewSD );
  390. if ( dwErr != ERROR_SUCCESS ) {
  391. fprintf( stderr, "BuildSecurityDescriptorW failed with %lu\n", dwErr );
  392. } else {
  393. PACL pDAcl;
  394. BOOL f1, f2;
  395. //
  396. // Get the ACL
  397. //
  398. if ( GetSecurityDescriptorDacl( pNewSD, &f1, &pDAcl, &f2) == FALSE ) {
  399. dwErr = GetLastError();
  400. } else {
  401. ACCESS_RIGHTS Rights;
  402. TRUSTEE Trustee;
  403. BuildTrusteeWithName( &Trustee, pwszUser );
  404. //
  405. // Go ahead and get the effect access, and make sure it isn't NULL
  406. //
  407. dwErr = GetEffectiveRightsFromAcl( pDAcl, &Trustee, &Rights );
  408. if ( dwErr != ERROR_SUCCESS ) {
  409. printf( "GetEffectiveRightsFromAcl failed with %lu\n", dwErr );
  410. } else {
  411. ACCESS_RIGHTS Expected = 0x1f01ff;
  412. if ( Rights != Expected) {
  413. printf( "Expected 0x%lx, got 0x%lx\n",
  414. Expected, Rights );
  415. dwErr = ERROR_INVALID_ACL;
  416. }
  417. }
  418. }
  419. LocalFree( pNewSD );
  420. }
  421. return(dwErr);
  422. }
  423. DWORD
  424. DoGetEffectiveTest2 (
  425. IN PWSTR pwszPath,
  426. IN PWSTR pwszUser
  427. )
  428. /*++
  429. Routine Description:
  430. Builds a security descriptor
  431. Arguments:
  432. pwszPath -- Root path
  433. pwszUser -- User to add
  434. Return Value:
  435. ERROR_SUCCESS -- Success
  436. --*/
  437. {
  438. DWORD dwErr = ERROR_SUCCESS;
  439. BYTE Buffer[100];
  440. PACL pAcl = (PACL)Buffer;
  441. SID EveryoneSid = {SID_REVISION,1 ,SECURITY_WORLD_SID_AUTHORITY, SECURITY_WORLD_RID};
  442. printf("GetEffectiveRightsFromAcl test 2\n");
  443. if(InitializeAcl(pAcl, 100, ACL_REVISION) == FALSE)
  444. {
  445. printf("InitializeAcl failed: 0x%lx\n", GetLastError());
  446. return(GetLastError());
  447. }
  448. if(AddAccessAllowedAce(pAcl, ACL_REVISION, 0x10000000, &EveryoneSid) != TRUE)
  449. {
  450. dwErr = GetLastError();
  451. }
  452. else
  453. {
  454. if(AddAccessAllowedAce(pAcl, ACL_REVISION, 0x1f01ff, &EveryoneSid) != TRUE)
  455. {
  456. dwErr = GetLastError();
  457. }
  458. }
  459. if(dwErr != ERROR_SUCCESS)
  460. {
  461. printf("Failed to add acls: %lu\n", dwErr);
  462. }
  463. else
  464. {
  465. ACCESS_RIGHTS Rights;
  466. TRUSTEE Trustee;
  467. BuildTrusteeWithName( &Trustee, L"S-1-1-0" );
  468. //
  469. // Go ahead and get the effect access, and make sure it isn't NULL
  470. //
  471. dwErr = GetEffectiveRightsFromAcl( pAcl, &Trustee, &Rights );
  472. if ( dwErr != ERROR_SUCCESS ) {
  473. printf( "GetEffectiveRightsFromAcl failed with %lu\n", dwErr );
  474. } else {
  475. printf( "got 0x%lx\n", Rights );
  476. }
  477. }
  478. return(dwErr);
  479. }
  480. DWORD
  481. DoGetEffectiveTest3 (
  482. IN PWSTR pwszPath,
  483. IN PWSTR pwszUser
  484. )
  485. /*++
  486. Routine Description:
  487. Builds a security descriptor
  488. Arguments:
  489. pwszPath -- Root path
  490. pwszUser -- User to add
  491. Return Value:
  492. ERROR_SUCCESS -- Success
  493. --*/
  494. {
  495. DWORD dwErr = ERROR_SUCCESS;
  496. BYTE Buffer[100];
  497. PACL pAcl = (PACL)Buffer;
  498. static SID_IDENTIFIER_AUTHORITY UaspBuiltinAuthority = SECURITY_NT_AUTHORITY;
  499. DWORD BuiltSid[sizeof(SID)/sizeof(DWORD) + 2 ];
  500. PSID pSid = (PSID)BuiltSid;
  501. printf("GetEffectiveRightsFromAcl test 3\n");
  502. RtlInitializeSid( pSid, &UaspBuiltinAuthority, 2 );
  503. *(RtlSubAuthoritySid(pSid, 0)) = SECURITY_BUILTIN_DOMAIN_RID;
  504. *(RtlSubAuthoritySid(pSid, 1)) = DOMAIN_ALIAS_RID_ADMINS;
  505. if(InitializeAcl(pAcl, 100, ACL_REVISION) == FALSE)
  506. {
  507. printf("InitializeAcl failed: 0x%lx\n", GetLastError());
  508. return(GetLastError());
  509. }
  510. if(AddAccessAllowedAce(pAcl, ACL_REVISION, 0x1f01ff, pSid) != TRUE)
  511. {
  512. dwErr = GetLastError();
  513. }
  514. if(dwErr != ERROR_SUCCESS)
  515. {
  516. printf("Failed to add acls: %lu\n", dwErr);
  517. }
  518. else
  519. {
  520. ACCESS_RIGHTS Rights;
  521. TRUSTEE Trustee;
  522. BuildTrusteeWithName( &Trustee, L"S-1-1-0" );
  523. //
  524. // Go ahead and get the effect access, and make sure it isn't NULL
  525. //
  526. dwErr = GetEffectiveRightsFromAcl( pAcl, &Trustee, &Rights );
  527. if ( dwErr != ERROR_SUCCESS ) {
  528. printf( "GetEffectiveRightsFromAcl failed with %lu\n", dwErr );
  529. } else {
  530. printf( "got 0x%lx\n", Rights );
  531. }
  532. }
  533. return(dwErr);
  534. }
  535. DWORD
  536. DoGetAudTest (
  537. IN PWSTR pwszPath,
  538. IN PWSTR pwszUser
  539. )
  540. /*++
  541. Routine Description:
  542. Arguments:
  543. pwszPath -- Root path
  544. pwszUser -- User to add
  545. Return Value:
  546. ERROR_SUCCESS -- Success
  547. --*/
  548. {
  549. DWORD dwErr = ERROR_SUCCESS;
  550. ACCESS_MASK Success, Failure;
  551. TRUSTEE Trustee;
  552. BuildTrusteeWithName(&Trustee, pwszUser);
  553. printf("GetAuditedPermissionsFromAcl on NULL SACL\n");
  554. dwErr = GetAuditedPermissionsFromAcl(NULL, &Trustee, &Success, &Failure);
  555. if ( dwErr != ERROR_SUCCESS ) {
  556. printf( "GetAuditedPermissionsFromAcl failed with %lu\n", dwErr );
  557. } else {
  558. if (Success == 0 && Failure == 0 ) {
  559. printf("Success\n");
  560. } else {
  561. printf( "Got Success: %lu, Failure: %lu\n", Success, Failure );
  562. }
  563. }
  564. return(dwErr);
  565. }
  566. __cdecl main (
  567. IN INT argc,
  568. IN CHAR *argv[])
  569. /*++
  570. Routine Description:
  571. The main
  572. Arguments:
  573. argc -- Count of arguments
  574. argv -- List of arguments
  575. Return Value:
  576. 0 -- Success
  577. non-0 -- Failure
  578. --*/
  579. {
  580. DWORD dwErr = ERROR_SUCCESS, dwErr2;
  581. WCHAR wszPath[MAX_PATH + 1];
  582. WCHAR wszUser[MAX_PATH + 1];
  583. ULONG Tests = 0;
  584. DWORD SeInfo = 0xFFFFFFFF;
  585. INT i;
  586. srand((ULONG)(GetTickCount() * GetCurrentThreadId()));
  587. if(argc < 4) {
  588. Usage( argv[0] );
  589. exit( 1 );
  590. }
  591. mbstowcs(wszPath, argv[1], strlen(argv[1]) + 1);
  592. mbstowcs(wszUser, argv[2], strlen(argv[2]) + 1);
  593. SeInfo = atol(argv[3]);
  594. if ( SeInfo == 0xFFFFFFFF ) {
  595. Usage( argv[0] );
  596. exit( 1 );
  597. }
  598. //
  599. // process the command line
  600. //
  601. for( i = 4; i < argc; i++ ) {
  602. if ( _stricmp( argv[i],"/CONVERT") == 0 ) {
  603. Tests |= MTEST_CONVERT;
  604. } else if ( _stricmp( argv[i],"/GETOWNER") == 0 ) {
  605. Tests |= MTEST_GETOWNER;
  606. } else if ( _stricmp( argv[i],"/GETSACL") == 0 ) {
  607. Tests |= MTEST_GETSACL;
  608. } else if ( _stricmp( argv[i],"/BUILDSD") == 0 ) {
  609. Tests |= MTEST_BUILDSD;
  610. } else if ( _stricmp( argv[i],"/BUILDSD2") == 0 ) {
  611. Tests |= MTEST_BUILDSD2;
  612. } else if ( _stricmp( argv[i],"/GETEXPL") == 0 ) {
  613. Tests |= MTEST_GETEXPL;
  614. } else if ( _stricmp( argv[i],"/GETEFF") == 0 ) {
  615. Tests |= MTEST_GETEFF;
  616. } else if ( _stricmp( argv[i],"/GETEFF2") == 0 ) {
  617. Tests |= MTEST_GETEFF2;
  618. } else if ( _stricmp( argv[i],"/GETEFF3") == 0 ) {
  619. Tests |= MTEST_GETEFF3;
  620. } else if ( _stricmp( argv[i],"/GETAUD") == 0 ) {
  621. Tests |= MTEST_GETAUD;
  622. } else {
  623. Usage( argv[0] );
  624. exit( 1 );
  625. break;
  626. }
  627. }
  628. if(Tests == 0) {
  629. Tests = MTEST_CONVERT |
  630. MTEST_GETOWNER |
  631. MTEST_GETSACL |
  632. MTEST_BUILDSD |
  633. MTEST_BUILDSD2 |
  634. MTEST_GETEXPL |
  635. MTEST_GETEFF |
  636. MTEST_GETEFF2 |
  637. MTEST_GETEFF3 |
  638. MTEST_GETAUD;
  639. }
  640. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_CONVERT)) {
  641. dwErr = DoConvertSecurityDescriptorToAccessNamedTest(wszPath, SeInfo);
  642. }
  643. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_GETOWNER)) {
  644. dwErr = DoGetOwnerTest(wszPath, SeInfo);
  645. }
  646. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_GETSACL)) {
  647. dwErr = DoGetSaclTest(wszPath, SeInfo);
  648. }
  649. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_BUILDSD)) {
  650. dwErr = DoBuildSDTest(wszPath, wszUser);
  651. }
  652. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_BUILDSD2)) {
  653. dwErr = DoBuildSD2Test(wszPath, wszUser);
  654. }
  655. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_GETEXPL)) {
  656. dwErr = DoGetExplicitTest(wszPath, SeInfo);
  657. }
  658. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_GETEFF)) {
  659. dwErr = DoGetEffectiveTest(wszPath, wszUser);
  660. }
  661. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_GETEFF2)) {
  662. dwErr = DoGetEffectiveTest2(wszPath, wszUser);
  663. }
  664. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_GETEFF3)) {
  665. dwErr = DoGetEffectiveTest3(wszPath, wszUser);
  666. }
  667. if(dwErr == ERROR_SUCCESS && FLAG_ON(Tests, MTEST_GETAUD)) {
  668. dwErr = DoGetAudTest(wszPath, wszUser);
  669. }
  670. printf( "%s\n", dwErr == ERROR_SUCCESS ?
  671. "success" :
  672. "failed" );
  673. return( dwErr );
  674. }