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.

641 lines
21 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Schema.c
  5. Abstract:
  6. Command line test tool for dumping the NDS schema attribute and class
  7. names and/or definitions.
  8. Author:
  9. Glenn Curtis [glennc] 22-Apr-96
  10. ***/
  11. #include <utils.c>
  12. int
  13. _cdecl main( int argc, char **argv )
  14. {
  15. DWORD status = NO_ERROR;
  16. HANDLE hTree = NULL;
  17. HANDLE hOperationData = NULL;
  18. OEM_STRING OemArg;
  19. UNICODE_STRING TreeName;
  20. WCHAR szTreeName[256];
  21. WCHAR szTempAttrName[256];
  22. WCHAR szTempClassName[256];
  23. ASN1_ID asn1Id;
  24. DWORD dwNumberOfEntries;
  25. DWORD dwInfoType;
  26. DWORD dwSyntaxID;
  27. DWORD iter;
  28. TreeName.Length = 0;
  29. TreeName.MaximumLength = sizeof( szTreeName );
  30. TreeName.Buffer = szTreeName;
  31. //
  32. // Check the arguments.
  33. //
  34. if ( argc < 3 )
  35. {
  36. Usage:
  37. printf( "\nUsage: ditdump <tree name> -n|d|x C|A [P] [C]\n" );
  38. printf( "\n where: n = Names only\n" );
  39. printf( " where: d = Names & definitions\n" );
  40. printf( " where: x = Extended names & definitions (Includes inherited properties)\n" );
  41. printf( " where: C = Classes\n" );
  42. printf( " where: A = Attributes\n" );
  43. printf( "\n where: P = Prompts user for list of specific\n" );
  44. printf( " classes, attributes, or syntaxes to read.\n" );
  45. printf( "\n where: C = Prompts user for a specific set of credentials.\n" );
  46. return -1;
  47. }
  48. OemArg.Length = strlen( argv[1] );
  49. OemArg.MaximumLength = OemArg.Length;
  50. OemArg.Buffer = argv[1];
  51. RtlOemStringToUnicodeString( &TreeName, &OemArg, FALSE );
  52. if ( ( argc > 4 && argv[4][0] == 'C' ) ||
  53. ( argc > 5 && argv[5][0] == 'C' ) )
  54. {
  55. WCHAR UserName[256];
  56. WCHAR Password[256];
  57. printf( "\nEnter a user name : " );
  58. GetStringOrDefault( UserName, L"" );
  59. printf( "\nEnter a password : " );
  60. GetStringOrDefault( Password, L"" );
  61. status = NwNdsOpenObject( TreeName.Buffer,
  62. UserName,
  63. Password,
  64. &hTree,
  65. NULL,
  66. NULL,
  67. NULL,
  68. NULL,
  69. NULL );
  70. }
  71. else
  72. {
  73. status = NwNdsOpenObject( TreeName.Buffer,
  74. NULL,
  75. NULL,
  76. &hTree,
  77. NULL,
  78. NULL,
  79. NULL,
  80. NULL,
  81. NULL );
  82. }
  83. if ( status )
  84. {
  85. printf( "\nError: NwNdsOpenObject returned status 0x%.8X\n", status );
  86. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  87. GetLastError() );
  88. return -1;
  89. }
  90. if ( argv[2][1] == 'n' && argv[3][0] == 'A' )
  91. {
  92. LPNDS_NAME_ONLY lpAttrNames = NULL;
  93. if ( argc > 4 && argv[4][0] == 'P' )
  94. {
  95. status = NwNdsCreateBuffer( NDS_SCHEMA_READ_ATTR_DEF,
  96. &hOperationData );
  97. if ( status )
  98. {
  99. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  100. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  101. GetLastError() );
  102. return -1;
  103. }
  104. do
  105. {
  106. printf( "\nEnter attribute name or <Enter> to end : " );
  107. GetStringOrDefault( szTempAttrName, L"" );
  108. if ( wcslen(szTempAttrName) > 0 )
  109. {
  110. status = NwNdsPutInBuffer( szTempAttrName,
  111. 0,
  112. NULL,
  113. 0,
  114. 0,
  115. hOperationData );
  116. if ( status )
  117. {
  118. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  119. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  120. GetLastError() );
  121. return -1;
  122. }
  123. }
  124. } while ( wcslen(szTempAttrName) > 0 );
  125. }
  126. printf( "\nGoing to dump the schema attribute names.\n" );
  127. status = NwNdsReadAttrDef( hTree,
  128. NDS_INFO_NAMES,
  129. &hOperationData );
  130. if ( status )
  131. {
  132. printf( "\nError: NwNdsReadAttrDef returned status 0x%.8X\n", status );
  133. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  134. GetLastError() );
  135. return -1;
  136. }
  137. status = NwNdsGetAttrDefListFromBuffer( hOperationData,
  138. &dwNumberOfEntries,
  139. &dwInfoType,
  140. (LPVOID *) &lpAttrNames );
  141. if ( status )
  142. {
  143. printf( "\nError: NwNdsGetAttrDefListFromBuffer returned status 0x%.8X\n", status );
  144. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  145. GetLastError() );
  146. return -1;
  147. }
  148. printf( "\nThe list of attribute definitions in the schema for\n" );
  149. printf( "NDS tree %S is :\n\n", TreeName.Buffer );
  150. for ( iter = 0; iter < dwNumberOfEntries; iter++ )
  151. {
  152. (void) NwNdsGetSyntaxID( hTree,
  153. lpAttrNames[iter].szName,
  154. &dwSyntaxID );
  155. printf( " %S (Syntax ID: %ld)\n",
  156. lpAttrNames[iter].szName,
  157. dwSyntaxID );
  158. }
  159. (void) NwNdsFreeBuffer( hOperationData );
  160. (void) NwNdsCloseObject( hTree );
  161. return 0;
  162. }
  163. if ( argv[2][1] == 'd' && argv[3][0] == 'A' )
  164. {
  165. LPNDS_ATTR_DEF lpAttrDefs = NULL;
  166. if ( argc > 4 && argv[4][0] == 'P' )
  167. {
  168. status = NwNdsCreateBuffer( NDS_SCHEMA_READ_ATTR_DEF,
  169. &hOperationData );
  170. if ( status )
  171. {
  172. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  173. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  174. GetLastError() );
  175. return -1;
  176. }
  177. do
  178. {
  179. printf( "\nEnter attribute name or <Enter> to end : " );
  180. GetStringOrDefault( szTempAttrName, L"" );
  181. if ( wcslen(szTempAttrName) > 0 )
  182. {
  183. status = NwNdsPutInBuffer( szTempAttrName,
  184. 0,
  185. NULL,
  186. 0,
  187. 0,
  188. hOperationData );
  189. if ( status )
  190. {
  191. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  192. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  193. GetLastError() );
  194. return -1;
  195. }
  196. }
  197. } while ( wcslen(szTempAttrName) > 0 );
  198. }
  199. printf( "\nGoing to dump the schema attribute names and definitions.\n" );
  200. status = NwNdsReadAttrDef( hTree,
  201. NDS_INFO_NAMES_DEFS,
  202. &hOperationData );
  203. if ( status )
  204. {
  205. printf( "\nError: NwNdsReadAttrDef returned status 0x%.8X\n", status );
  206. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  207. GetLastError() );
  208. return -1;
  209. }
  210. status = NwNdsGetAttrDefListFromBuffer( hOperationData,
  211. &dwNumberOfEntries,
  212. &dwInfoType,
  213. (LPVOID *) &lpAttrDefs );
  214. if ( status )
  215. {
  216. printf( "\nError: NwNdsGetAttrDefListFromBuffer returned status 0x%.8X\n", status );
  217. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  218. GetLastError() );
  219. return -1;
  220. }
  221. printf( "\nThe list of attribute definitions in the schema for\n" );
  222. printf( "NDS tree %S is :\n\n", TreeName.Buffer );
  223. for ( iter = 0; iter < dwNumberOfEntries; iter++ )
  224. {
  225. printf( " %S\n", lpAttrDefs[iter].szAttributeName );
  226. printf( " _____________________________________________\n" );
  227. printf( " Flags : 0x%.8X\n",
  228. lpAttrDefs[iter].dwFlags );
  229. printf( " Syntax ID : %ld\n",
  230. lpAttrDefs[iter].dwSyntaxID );
  231. printf( " Lower Limit : 0x%.8X\n",
  232. lpAttrDefs[iter].dwLowerLimit );
  233. printf( " Upper Limit : 0x%.8X\n",
  234. lpAttrDefs[iter].dwUpperLimit );
  235. printf( " ASN.1 ID length : %ld\n",
  236. lpAttrDefs[iter].asn1ID.length );
  237. printf( " ASN.1 ID Data : %s\n\n",
  238. lpAttrDefs[iter].asn1ID.data );
  239. }
  240. (void) NwNdsFreeBuffer( hOperationData );
  241. (void) NwNdsCloseObject( hTree );
  242. return 0;
  243. }
  244. if ( argv[2][1] == 'n' && argv[3][0] == 'C' )
  245. {
  246. LPNDS_NAME_ONLY lpClassNames = NULL;
  247. if ( argc > 4 && argv[4][0] == 'P' )
  248. {
  249. status = NwNdsCreateBuffer( NDS_SCHEMA_READ_CLASS_DEF,
  250. &hOperationData );
  251. if ( status )
  252. {
  253. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  254. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  255. GetLastError() );
  256. return -1;
  257. }
  258. do
  259. {
  260. printf( "\nEnter class name or <Enter> to end : " );
  261. GetStringOrDefault( szTempClassName, L"" );
  262. if ( wcslen(szTempClassName) > 0 )
  263. {
  264. status = NwNdsPutInBuffer( szTempClassName,
  265. 0,
  266. NULL,
  267. 0,
  268. 0,
  269. hOperationData );
  270. if ( status )
  271. {
  272. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  273. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  274. GetLastError() );
  275. return -1;
  276. }
  277. }
  278. } while ( wcslen(szTempClassName) > 0 );
  279. }
  280. printf( "\nGoing to dump the schema class names.\n" );
  281. status = NwNdsReadClassDef( hTree,
  282. NDS_INFO_NAMES,
  283. &hOperationData );
  284. if ( status )
  285. {
  286. printf( "\nError: NwNdsReadClassDef returned status 0x%.8X\n", status );
  287. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  288. GetLastError() );
  289. return -1;
  290. }
  291. status = NwNdsGetClassDefListFromBuffer( hOperationData,
  292. &dwNumberOfEntries,
  293. &dwInfoType,
  294. (LPVOID *) &lpClassNames );
  295. if ( status )
  296. {
  297. printf( "\nError: NwNdsGetClassDefListFromBuffer returned status 0x%.8X\n", status );
  298. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  299. GetLastError() );
  300. return -1;
  301. }
  302. printf( "\nThe list of class definitions in the schema for\n" );
  303. printf( "NDS tree %S is :\n\n", TreeName.Buffer );
  304. for ( iter = 0; iter < dwNumberOfEntries; iter++ )
  305. {
  306. printf( " %S\n", lpClassNames[iter].szName );
  307. }
  308. (void) NwNdsFreeBuffer( hOperationData );
  309. (void) NwNdsCloseObject( hTree );
  310. return 0;
  311. }
  312. if ( argv[2][1] == 'd' && argv[3][0] == 'C' )
  313. {
  314. LPNDS_CLASS_DEF lpClassDefs = NULL;
  315. if ( argc > 4 && argv[4][0] == 'P' )
  316. {
  317. status = NwNdsCreateBuffer( NDS_SCHEMA_READ_CLASS_DEF,
  318. &hOperationData );
  319. if ( status )
  320. {
  321. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  322. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  323. GetLastError() );
  324. return -1;
  325. }
  326. do
  327. {
  328. printf( "\nEnter class name or <Enter> to end : " );
  329. GetStringOrDefault( szTempClassName, L"" );
  330. if ( wcslen(szTempClassName) > 0 )
  331. {
  332. status = NwNdsPutInBuffer( szTempClassName,
  333. 0,
  334. NULL,
  335. 0,
  336. 0,
  337. hOperationData );
  338. if ( status )
  339. {
  340. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  341. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  342. GetLastError() );
  343. return -1;
  344. }
  345. }
  346. } while ( wcslen(szTempClassName) > 0 );
  347. }
  348. printf( "\nGoing to dump the schema class names and definitions.\n" );
  349. status = NwNdsReadClassDef( hTree,
  350. NDS_INFO_NAMES_DEFS,
  351. &hOperationData );
  352. if ( status )
  353. {
  354. printf( "\nError: NwNdsReadClassDef returned status 0x%.8X\n", status );
  355. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  356. GetLastError() );
  357. return -1;
  358. }
  359. status = NwNdsGetClassDefListFromBuffer( hOperationData,
  360. &dwNumberOfEntries,
  361. &dwInfoType,
  362. (LPVOID *) &lpClassDefs );
  363. if ( status )
  364. {
  365. printf( "\nError: NwNdsGetClassDefListFromBuffer returned status 0x%.8X\n", status );
  366. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  367. GetLastError() );
  368. return -1;
  369. }
  370. printf( "\nThe list of class definitions in the schema for\n" );
  371. printf( "NDS tree %S is :\n\n", TreeName.Buffer );
  372. for ( iter = 0; iter < dwNumberOfEntries; iter++ )
  373. {
  374. printf( " %S\n", lpClassDefs[iter].szClassName );
  375. printf( " _____________________________________________\n" );
  376. printf( " Flags : 0x%.8X\n",
  377. lpClassDefs[iter].dwFlags );
  378. printf( " ASN.1 ID length : %ld\n",
  379. lpClassDefs[iter].asn1ID.length );
  380. printf( " ASN.1 ID Data : %s\n\n",
  381. lpClassDefs[iter].asn1ID.data );
  382. printf( " Super Classes (%ld) : \n",
  383. lpClassDefs[iter].dwNumberOfSuperClasses );
  384. DumpListOfStrings( lpClassDefs[iter].lpSuperClasses );
  385. printf( " Containment Classes (%ld) : \n",
  386. lpClassDefs[iter].dwNumberOfContainmentClasses );
  387. DumpListOfStrings( lpClassDefs[iter].lpContainmentClasses );
  388. printf( " Naming Attributes (%ld) : \n",
  389. lpClassDefs[iter].dwNumberOfNamingAttributes );
  390. DumpListOfStrings( lpClassDefs[iter].lpNamingAttributes );
  391. printf( " Mandatory Attributes (%ld) : \n",
  392. lpClassDefs[iter].dwNumberOfMandatoryAttributes );
  393. DumpListOfStrings( lpClassDefs[iter].lpMandatoryAttributes );
  394. printf( " Optional Attributes (%ld) : \n",
  395. lpClassDefs[iter].dwNumberOfOptionalAttributes );
  396. DumpListOfStrings( lpClassDefs[iter].lpOptionalAttributes );
  397. printf( "\n" );
  398. }
  399. (void) NwNdsFreeBuffer( hOperationData );
  400. (void) NwNdsCloseObject( hTree );
  401. return 0;
  402. }
  403. if ( argv[2][1] == 'x' && argv[3][0] == 'C' )
  404. {
  405. LPNDS_CLASS_DEF lpClassDefs = NULL;
  406. if ( argc > 4 && argv[4][0] == 'P' )
  407. {
  408. status = NwNdsCreateBuffer( NDS_SCHEMA_READ_CLASS_DEF,
  409. &hOperationData );
  410. if ( status )
  411. {
  412. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  413. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  414. GetLastError() );
  415. return -1;
  416. }
  417. do
  418. {
  419. printf( "\nEnter class name or <Enter> to end : " );
  420. GetStringOrDefault( szTempClassName, L"" );
  421. if ( wcslen(szTempClassName) > 0 )
  422. {
  423. status = NwNdsPutInBuffer( szTempClassName,
  424. 0,
  425. NULL,
  426. 0,
  427. 0,
  428. hOperationData );
  429. if ( status )
  430. {
  431. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  432. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  433. GetLastError() );
  434. return -1;
  435. }
  436. }
  437. } while ( wcslen(szTempClassName) > 0 );
  438. }
  439. printf( "\nGoing to dump the extended schema class names and definitions.\n" );
  440. status = NwNdsReadClassDef( hTree,
  441. NDS_CLASS_INFO_EXPANDED_DEFS,
  442. &hOperationData );
  443. if ( status )
  444. {
  445. printf( "\nError: NwNdsReadClassDef returned status 0x%.8X\n", status );
  446. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  447. GetLastError() );
  448. return -1;
  449. }
  450. status = NwNdsGetClassDefListFromBuffer( hOperationData,
  451. &dwNumberOfEntries,
  452. &dwInfoType,
  453. (LPVOID *) &lpClassDefs );
  454. if ( status )
  455. {
  456. printf( "\nError: NwNdsGetClassDefListFromBuffer returned status 0x%.8X\n", status );
  457. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  458. GetLastError() );
  459. return -1;
  460. }
  461. printf( "\nThe list of class definitions in the schema for\n" );
  462. printf( "NDS tree %S is :\n\n", TreeName.Buffer );
  463. for ( iter = 0; iter < dwNumberOfEntries; iter++ )
  464. {
  465. printf( " %S\n", lpClassDefs[iter].szClassName );
  466. printf( " _____________________________________________\n" );
  467. printf( " Flags : 0x%.8X\n",
  468. lpClassDefs[iter].dwFlags );
  469. printf( " ASN.1 ID length : %ld\n",
  470. lpClassDefs[iter].asn1ID.length );
  471. printf( " ASN.1 ID Data : %s\n\n",
  472. lpClassDefs[iter].asn1ID.data );
  473. printf( " Super Classes (%ld) : \n",
  474. lpClassDefs[iter].dwNumberOfSuperClasses );
  475. DumpListOfStrings( lpClassDefs[iter].lpSuperClasses );
  476. printf( " Containment Classes (%ld) : \n",
  477. lpClassDefs[iter].dwNumberOfContainmentClasses );
  478. DumpListOfStrings( lpClassDefs[iter].lpContainmentClasses );
  479. printf( " Naming Attributes (%ld) : \n",
  480. lpClassDefs[iter].dwNumberOfNamingAttributes );
  481. DumpListOfStrings( lpClassDefs[iter].lpNamingAttributes );
  482. printf( " Mandatory Attributes (%ld) : \n",
  483. lpClassDefs[iter].dwNumberOfMandatoryAttributes );
  484. DumpListOfStrings( lpClassDefs[iter].lpMandatoryAttributes );
  485. printf( " Optional Attributes (%ld) : \n",
  486. lpClassDefs[iter].dwNumberOfOptionalAttributes );
  487. DumpListOfStrings( lpClassDefs[iter].lpOptionalAttributes );
  488. printf( "\n" );
  489. }
  490. (void) NwNdsFreeBuffer( hOperationData );
  491. (void) NwNdsCloseObject( hTree );
  492. return 0;
  493. }
  494. goto Usage;
  495. }