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.

546 lines
15 KiB

  1. //*************************************************************
  2. //
  3. // Group Policy Performance test program
  4. //
  5. // Copyright (c) Microsoft Corporation 1997-1998
  6. //
  7. // History: 10-Dec-98 SitaramR Created from DKays version
  8. //
  9. //*************************************************************
  10. #define UNICODE
  11. #include <windows.h>
  12. #define SECURITY_WIN32
  13. #include <security.h>
  14. #include <stdio.h>
  15. #include <ole2.h>
  16. #include <prsht.h>
  17. #include <initguid.h>
  18. #include <gpedit.h>
  19. #include <iads.h>
  20. #include <adshlp.h>
  21. const MAX_BUF_LEN = 2056; // Static buffer size
  22. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  23. void PrintHelp();
  24. BOOL CreateTest2GPOs( WCHAR *pwszDomain );
  25. BOOL CreateTest3GPOs( WCHAR *pwszDomain );
  26. BOOL CreateTest4GPOs( WCHAR *pwszDomain );
  27. BOOL CreateTest5GPOs( WCHAR *pwszDomain );
  28. GUID guidExtensions[] = { // List of GP client side extension guids
  29. { 0x25537BA6, 0x77A8, 0x11D2, {0x9B, 0x6C, 0x00, 0x00, 0xF8, 0x08, 0x08, 0x61}},
  30. { 0x35378EAC, 0x683F, 0x11D2, {0xA8, 0x9A, 0x00, 0xC0, 0x4F, 0xBB, 0xCF, 0xA2}},
  31. { 0x3610eda5, 0x77ef, 0x11d2, {0x8d, 0xc5, 0x00, 0xc0, 0x4f, 0xa3, 0x1a, 0x66}},
  32. { 0x42B5FAAE, 0x6536, 0x11d2, {0xAE, 0x5A, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3}},
  33. { 0x827d319e, 0x6eac, 0x11d2, {0xa4, 0xea, 0x00, 0xc0, 0x4f, 0x79, 0xf8, 0x3a}},
  34. { 0xb1be8d72, 0x6eac, 0x11d2, {0xa4, 0xea, 0x00, 0xc0, 0x4f, 0x79, 0xf8, 0x3a}},
  35. { 0xc6dc5466, 0x785a, 0x11d2, {0x84, 0xd0, 0x00, 0xc0, 0x4f, 0xb1, 0x69, 0xf7}},
  36. };
  37. GUID guidSnapin = { 0xdd7f2e0f, 0x9089, 0x11d2, {0xb2, 0x81, 0x00, 0xc0, 0x4f, 0xbb, 0xcf, 0xa2 }};
  38. int __cdecl main( int argc, char **argv )
  39. {
  40. for ( int n = 1; n < argc; n++ )
  41. {
  42. if ( lstrcmpA(argv[n], "-help") == 0
  43. || lstrcmpA(argv[n], "/help") == 0
  44. || lstrcmpA(argv[n], "-?") == 0
  45. || lstrcmpA(argv[n], "/?") == 0 )
  46. {
  47. PrintHelp();
  48. return 0;
  49. }
  50. printf( "Usage: polcreat or polcreat /? to see help info" );
  51. return 0;
  52. }
  53. WCHAR wszUser[MAX_BUF_LEN];
  54. ULONG ulSize = ARRAYSIZE(wszUser);
  55. BOOL bOk = GetUserNameEx( NameFullyQualifiedDN, wszUser, &ulSize );
  56. if ( !bOk )
  57. {
  58. printf( "GetUserNameEx failed with 0x%x\n", GetLastError() );
  59. return 0;
  60. }
  61. //
  62. // Get domain path
  63. //
  64. WCHAR wszDomain[MAX_BUF_LEN];
  65. lstrcpy( wszDomain, L"LDAP://" );
  66. BOOL bFound = FALSE;
  67. WCHAR *pchCur = wszUser;
  68. while ( pchCur && *pchCur != 0 && lstrlen(pchCur) > 3 )
  69. {
  70. if ( CompareString (LOCALE_USER_DEFAULT, NORM_IGNORECASE,
  71. pchCur, 3, TEXT("DC="), 3) == CSTR_EQUAL)
  72. {
  73. bFound = TRUE;
  74. lstrcat( wszDomain, pchCur );
  75. break;
  76. }
  77. pchCur++;
  78. }
  79. if ( !bFound )
  80. {
  81. printf( "Unable to create domain path from user path %ws\n", wszUser );
  82. return 0;
  83. }
  84. printf( "Using Domain path, %ws\n", wszDomain );
  85. CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
  86. printf( "Creating Test2 GPOs\n" );
  87. bOk = CreateTest2GPOs( wszDomain );
  88. if ( !bOk )
  89. {
  90. printf( "Failed to create test2 GPOs\n" );
  91. return 0;
  92. }
  93. printf( "Creating Test3 GPOs\n" );
  94. bOk = CreateTest3GPOs( wszDomain );
  95. if ( !bOk )
  96. {
  97. printf( "Failed to create test3 GPOs\n" );
  98. return 0;
  99. }
  100. printf( "Creating Test4 GPOs\n" );
  101. bOk = CreateTest4GPOs( wszDomain );
  102. if ( !bOk )
  103. {
  104. printf( "Failed to create test4 GPOs\n" );
  105. return 0;
  106. }
  107. printf( "Creating Test5 GPOs\n" );
  108. bOk = CreateTest5GPOs( wszDomain );
  109. if ( !bOk )
  110. {
  111. printf( "Failed to create test5 GPOs\n" );
  112. return 0;
  113. }
  114. printf( "Successfully created all OUs and GPOs" );
  115. return 0;
  116. }
  117. BOOL CreateOU( WCHAR *pwszParent, WCHAR *pwszOU )
  118. {
  119. //
  120. // Bind to the parent container and create OU
  121. //
  122. IADsContainer *pContainer;
  123. IDispatch *pIDispatch;
  124. IADs *pADs;
  125. HRESULT hr = ADsGetObject( pwszParent,
  126. IID_IADsContainer,
  127. (void**)&pContainer);
  128. if ( hr != S_OK )
  129. {
  130. printf( "Failed to bind to parent container %ws with 0x%x\n", pwszParent, hr );
  131. return FALSE;
  132. }
  133. hr = pContainer->Create(L"organizationalUnit",
  134. pwszOU, // L"OU=OU1",
  135. &pIDispatch );
  136. if ( hr != S_OK )
  137. {
  138. printf( "Failed to bind to create %ws with 0x%x\n", pwszOU, hr );
  139. return FALSE;
  140. }
  141. hr = pIDispatch->QueryInterface( IID_IADs, (void **)&pADs);
  142. if ( hr != S_OK )
  143. {
  144. printf( "Failed to QI %ws with 0x%x\n", pwszOU, hr );
  145. return FALSE;
  146. }
  147. hr = pADs->SetInfo();
  148. if ( hr != S_OK )
  149. {
  150. printf( "Failed to SetInfo %ws with 0x%x\n", pwszOU, hr );
  151. return FALSE;
  152. }
  153. return TRUE;
  154. }
  155. BOOL CreatePolicies( WCHAR *pwszDomain, WCHAR *pwszOUPath, WCHAR *pwszOUName, ULONG cPolicies )
  156. {
  157. //
  158. // cPolicies must be a multiple of 7 because there are 7 client side
  159. // extensions.
  160. //
  161. ULONG cPols = cPolicies / 7;
  162. WCHAR wszGPOName[MAX_BUF_LEN];
  163. WCHAR wszGPOPath[MAX_BUF_LEN];
  164. WCHAR wszNum[20];
  165. LPGROUPPOLICYOBJECT pGPO;
  166. for ( ULONG i=0; i<cPols; i++ )
  167. {
  168. for ( ULONG j=0; j<7; j++ )
  169. {
  170. HRESULT hr = CoCreateInstance( CLSID_GroupPolicyObject,
  171. NULL,
  172. CLSCTX_SERVER,
  173. IID_IGroupPolicyObject,
  174. (void**)&pGPO );
  175. if ( hr != S_OK )
  176. {
  177. printf( "CoCreateInstance of pGPO failed 0x%x\n", hr );
  178. return FALSE;
  179. }
  180. wcscpy( wszGPOName, pwszOUName );
  181. wsprintf( wszNum, L"%d%d", i, j );
  182. wcscat( wszGPOName, wszNum );
  183. hr = pGPO->New( pwszDomain, wszGPOName, FALSE );
  184. if ( hr != S_OK )
  185. {
  186. printf( "Creating new GPO %ws failed 0x%x\n", wszGPOName, hr );
  187. return FALSE;
  188. }
  189. hr = pGPO->GetPath( wszGPOPath, ARRAYSIZE(wszGPOPath) );
  190. if ( hr != S_OK )
  191. {
  192. printf( "Getting GPO path of %ws failed 0x%x\n", wszGPOName, hr );
  193. return FALSE;
  194. }
  195. hr = pGPO->Save( TRUE, TRUE, &guidExtensions[j], &guidSnapin ); // machine policy
  196. if ( hr != S_OK )
  197. {
  198. printf( "Saving GPO %ws failed 0x%x\n", wszGPOName, hr );
  199. return FALSE;
  200. }
  201. hr = pGPO->Save( FALSE, TRUE, &guidExtensions[j], &guidSnapin ); // user policy
  202. if ( hr != S_OK )
  203. {
  204. printf( "Saving GPO %ws failed 0x%x\n", wszGPOName, hr );
  205. return FALSE;
  206. }
  207. hr = CreateGPOLink( wszGPOPath, pwszOUPath, FALSE );
  208. if ( hr != S_OK )
  209. {
  210. printf( "Linking GPO %ws failed 0x%x\n", wszGPOName, hr );
  211. return FALSE;
  212. }
  213. pGPO->Release();
  214. } // for j
  215. } // for i
  216. return TRUE;
  217. }
  218. BOOL MakeLdapPath( WCHAR *pwszParent, WCHAR *pwszOU, WCHAR *pwszChild )
  219. {
  220. //
  221. // Make ldap path to child by prepending OU to parent path
  222. //
  223. wcscpy( pwszChild, L"LDAP://" );
  224. wcscat( pwszChild, pwszOU );
  225. wcscat( pwszChild, L"," );
  226. wcscat( pwszChild, &pwszParent[7] );
  227. return TRUE;
  228. }
  229. BOOL CreateTest2GPOs( WCHAR *pwszDomain )
  230. {
  231. WCHAR wszParent[MAX_BUF_LEN];
  232. WCHAR wszChild[MAX_BUF_LEN];
  233. wcscpy( wszParent, pwszDomain );
  234. // OU_L1_P7_T2
  235. BOOL bOk = CreateOU( wszParent, L"OU=OU_L1_P7_T2");
  236. if ( !bOk )
  237. return FALSE;
  238. MakeLdapPath( wszParent, L"OU=OU_L1_P7_T2", wszChild );
  239. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L1_P7_T2_GP", 7);
  240. if ( !bOk )
  241. return FALSE;
  242. // OU_L1_P0_T2
  243. bOk = CreateOU( wszParent, L"OU=OU_L1_P0_T2");
  244. if ( !bOk )
  245. return FALSE;
  246. // OU_L2_P7_T2
  247. MakeLdapPath( wszParent, L"OU=OU_L1_P0_T2", wszChild );
  248. wcscpy( wszParent, wszChild );
  249. bOk = CreateOU( wszParent, L"OU=OU_L2_P7_T2");
  250. if ( !bOk )
  251. return FALSE;
  252. MakeLdapPath( wszParent, L"OU=OU_L2_P7_T2", wszChild );
  253. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P7_T2_GP", 7);
  254. if ( !bOk )
  255. return FALSE;
  256. // OU_L2_P0_T2
  257. bOk = CreateOU( wszParent, L"OU=OU_L2_P0_T2");
  258. if ( !bOk )
  259. return FALSE;
  260. // OU_L3_P7_T2
  261. MakeLdapPath( wszParent, L"OU=OU_L2_P0_T2", wszChild );
  262. wcscpy( wszParent, wszChild );
  263. bOk = CreateOU( wszParent, L"OU=OU_L3_P7_T2");
  264. if ( !bOk )
  265. return FALSE;
  266. MakeLdapPath( wszParent, L"OU=OU_L3_P7_T2", wszChild );
  267. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L3_P7_T2_GP", 7);
  268. if ( !bOk )
  269. return FALSE;
  270. // OU_L3_P0_T2
  271. bOk = CreateOU( wszParent, L"OU=OU_L3_P0_T2");
  272. if ( !bOk )
  273. return FALSE;
  274. // OU_L4_P7_T2
  275. MakeLdapPath( wszParent, L"OU=OU_L3_P0_T2", wszChild );
  276. wcscpy( wszParent, wszChild );
  277. bOk = CreateOU( wszParent, L"OU=OU_L4_P7_T2");
  278. if ( !bOk )
  279. return FALSE;
  280. MakeLdapPath( wszParent, L"OU=OU_L4_P7_T2", wszChild );
  281. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L4_P7_T2_GP", 7);
  282. if ( !bOk )
  283. return FALSE;
  284. // OU_L4_P0_T2
  285. bOk = CreateOU( wszParent, L"OU=OU_L4_P0_T2");
  286. if ( !bOk )
  287. return FALSE;
  288. // OU_L5_P7_T2
  289. MakeLdapPath( wszParent, L"OU=OU_L4_P0_T2", wszChild );
  290. wcscpy( wszParent, wszChild );
  291. bOk = CreateOU( wszParent, L"OU=OU_L5_P7_T2");
  292. if ( !bOk )
  293. return FALSE;
  294. MakeLdapPath( wszParent, L"OU=OU_L5_P7_T2", wszChild );
  295. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L5_P7_T2_GP", 7);
  296. if ( !bOk )
  297. return FALSE;
  298. // OU_L5_P0_T2
  299. bOk = CreateOU( wszParent, L"OU=OU_L5_P0_T2");
  300. if ( !bOk )
  301. return FALSE;
  302. return TRUE;
  303. }
  304. BOOL CreateTest3GPOs( WCHAR *pwszDomain )
  305. {
  306. WCHAR wszParent[MAX_BUF_LEN];
  307. WCHAR wszChild[MAX_BUF_LEN];
  308. wcscpy( wszParent, pwszDomain );
  309. // OU_L1_P0_T3
  310. BOOL bOk = CreateOU( wszParent, L"OU=OU_L1_P0_T3");
  311. if ( !bOk )
  312. return FALSE;
  313. // OU_L2_P14_T3
  314. MakeLdapPath( wszParent, L"OU=OU_L1_P0_T3", wszChild );
  315. wcscpy( wszParent, wszChild );
  316. bOk = CreateOU( wszParent, L"OU=OU_L2_P14_T3");
  317. if ( !bOk )
  318. return FALSE;
  319. MakeLdapPath( wszParent, L"OU=OU_L2_P14_T3", wszChild );
  320. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P14_T3_GP", 14 );
  321. if ( !bOk )
  322. return FALSE;
  323. // OU_L2_P28_T3
  324. bOk = CreateOU( wszParent, L"OU=OU_L2_P28_T3");
  325. if ( !bOk )
  326. return FALSE;
  327. MakeLdapPath( wszParent, L"OU=OU_L2_P28_T3", wszChild );
  328. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P28_T3_GP", 28 );
  329. if ( !bOk )
  330. return FALSE;
  331. // OU_L2_P56_T3
  332. bOk = CreateOU( wszParent, L"OU=OU_L2_P56_T3");
  333. if ( !bOk )
  334. return FALSE;
  335. MakeLdapPath( wszParent, L"OU=OU_L2_P56_T3", wszChild );
  336. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P56_T3_GP", 56 );
  337. if ( !bOk )
  338. return FALSE;
  339. // OU_L2_P70_T3
  340. bOk = CreateOU( wszParent, L"OU=OU_L2_P70_T3");
  341. if ( !bOk )
  342. return FALSE;
  343. MakeLdapPath( wszParent, L"OU=OU_L2_P70_T3", wszChild );
  344. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P70_T3_GP", 70 );
  345. if ( !bOk )
  346. return FALSE;
  347. // OU_L2_P98_T3
  348. bOk = CreateOU( wszParent, L"OU=OU_L2_P98_T3");
  349. if ( !bOk )
  350. return FALSE;
  351. MakeLdapPath( wszParent, L"OU=OU_L2_P98_T3", wszChild );
  352. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P98_T3_GP", 98 );
  353. if ( !bOk )
  354. return FALSE;
  355. return TRUE;
  356. }
  357. BOOL CreateTest4GPOs( WCHAR *pwszDomain )
  358. {
  359. WCHAR wszParent[MAX_BUF_LEN];
  360. WCHAR wszChild[MAX_BUF_LEN];
  361. wcscpy( wszParent, pwszDomain );
  362. // OU_L1_P7_T4
  363. BOOL bOk = CreateOU( wszParent, L"OU=OU_L1_P7_T4");
  364. if ( !bOk )
  365. return FALSE;
  366. MakeLdapPath( wszParent, L"OU=OU_L1_P7_T4", wszChild );
  367. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L1_P7_T4_GP", 7 );
  368. if ( !bOk )
  369. return FALSE;
  370. // OU_L2_P7_T4
  371. MakeLdapPath( wszParent, L"OU=OU_L1_P7_T4", wszChild );
  372. wcscpy( wszParent, wszChild );
  373. bOk = CreateOU( wszParent, L"OU=OU_L2_P7_T4");
  374. if ( !bOk )
  375. return FALSE;
  376. MakeLdapPath( wszParent, L"OU=OU_L2_P7_T4", wszChild );
  377. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P7_T4_GP", 7 );
  378. if ( !bOk )
  379. return FALSE;
  380. // OU_L1_P14_T4
  381. wcscpy( wszParent, pwszDomain );
  382. bOk = CreateOU( wszParent, L"OU=OU_L1_P14_T4");
  383. if ( !bOk )
  384. return FALSE;
  385. MakeLdapPath( wszParent, L"OU=OU_L1_P14_T4", wszChild );
  386. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L1_P14_T4_GP", 14 );
  387. if ( !bOk )
  388. return FALSE;
  389. // OU_L2_P14_T4
  390. MakeLdapPath( wszParent, L"OU=OU_L1_P14_T4", wszChild );
  391. wcscpy( wszParent, wszChild );
  392. bOk = CreateOU( wszParent, L"OU=OU_L2_P14_T4");
  393. if ( !bOk )
  394. return FALSE;
  395. MakeLdapPath( wszParent, L"OU=OU_L2_P14_T4", wszChild );
  396. bOk = CreatePolicies( pwszDomain, wszChild, L"OU_L2_P14_T4_GP", 14 );
  397. if ( !bOk )
  398. return FALSE;
  399. return TRUE;
  400. }
  401. BOOL CreateTest5GPOs( WCHAR *pwszDomain )
  402. {
  403. WCHAR wszParent[MAX_BUF_LEN*10];
  404. WCHAR wszChild[MAX_BUF_LEN*10];
  405. WCHAR wszOUString[MAX_BUF_LEN];
  406. wcscpy( wszParent, pwszDomain );
  407. for ( unsigned i=1; i<60; i++ )
  408. {
  409. wsprintf( wszOUString, L"OU=OU_L%d_P0_T5", i );
  410. BOOL bOk = CreateOU( wszParent, wszOUString );
  411. if ( !bOk )
  412. return FALSE;
  413. MakeLdapPath( wszParent, wszOUString, wszChild );
  414. wcscpy( wszParent, wszChild );
  415. }
  416. return TRUE;
  417. }
  418. void PrintHelp()
  419. {
  420. printf( "Usage: polcreat to create OUs and GPOs or,\n polcreat /? to get performance test cases\n\n" );\
  421. printf(" TEST SCENARIOS (Naming covention is: OU_Level#_P#GPOs_T#test)\n");
  422. printf("\nTest 1:\n");
  423. printf(" 1. User at Domain level\n\n\n");
  424. printf("Test 2:\n");
  425. printf(" 1. User at OU_L1_P7_T2\n");
  426. printf(" 2. User at OU_L1_P0_T2, OU_L2_P7_T2\n");
  427. printf(" 3. User at OU_L1_P0_T2, OU_L2_P0_T2, OU_L3_P7_T2\n");
  428. printf(" 4. User at OU_L1_P0_T2, OU_L2_P0_T2, OU_L3_P0_T2, OU_L4_P7_T2\n");
  429. printf(" 5. User at OU_L1_P0_T2, OU_L2_P0_T2, OU_L3_P0_T2, OU_L4_P0_T2, OU_L5_P7_T2\n");
  430. printf(" 5. User at OU_L1_P0_T2, OU_L2_P0_T2, OU_L3_P0_T2, OU_L4_P0_T2, OU_L5_P0_T2\n\n\n");
  431. printf("Test 3:\n");
  432. printf(" 1. User at OU_L1_P0_T3, OU_L2_P14_T3\n");
  433. printf(" 2. User at OU_L1_P0_T3, OU_L2_P28_T3\n");
  434. printf(" 3. User at OU_L1_P0_T3, OU_L2_P70_T3\n\n\n");
  435. printf("Test 4:\n");
  436. printf(" 1. User at OU_L1_P7_T4, OU_L2_P7_T4\n");
  437. printf(" 2. User at OU_L1_P14_T4, OU_L2_P14_T4\n\n");
  438. }