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.

449 lines
14 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Schema.c
  5. Abstract:
  6. Command line test tool for testing the NDS schema APIs.
  7. Author:
  8. Glenn Curtis [glennc] 22-Apr-96
  9. ***/
  10. #include <utils.c>
  11. int
  12. _cdecl main( int argc, char **argv )
  13. {
  14. DWORD status = NO_ERROR;
  15. HANDLE hObject;
  16. HANDLE hOperationData = NULL;
  17. OEM_STRING OemArg;
  18. UNICODE_STRING TreeName;
  19. WCHAR lpTreeName[256];
  20. UNICODE_STRING ObjectName;
  21. WCHAR lpObjectName[256];
  22. WCHAR TempName[256];
  23. HANDLE hTree;
  24. ASN1_ID asn1Id;
  25. TreeName.Length = 0;
  26. TreeName.MaximumLength = sizeof( lpTreeName );
  27. TreeName.Buffer = lpTreeName;
  28. ObjectName.Length = 0;
  29. ObjectName.MaximumLength = sizeof( lpObjectName );
  30. ObjectName.Buffer = lpObjectName;
  31. //
  32. // Check the arguments.
  33. //
  34. if ( argc != 5 )
  35. {
  36. Usage:
  37. printf( "\nUsage: schema <tree name> -a|m|r A|C <attribute or class name>\n" );
  38. printf( "\n where: a = add\n" );
  39. printf( " where: m = modify (classes only)\n" );
  40. printf( " where: r = remove\n" );
  41. printf( " where: A = Attribute\n" );
  42. printf( " where: C = Class\n" );
  43. return -1;
  44. }
  45. OemArg.Length = strlen( argv[1] );
  46. OemArg.MaximumLength = OemArg.Length;
  47. OemArg.Buffer = argv[1];
  48. RtlOemStringToUnicodeString( &TreeName, &OemArg, FALSE );
  49. OemArg.Length = strlen( argv[4] );
  50. OemArg.MaximumLength = OemArg.Length;
  51. OemArg.Buffer = argv[4];
  52. RtlOemStringToUnicodeString( &ObjectName, &OemArg, FALSE );
  53. status = NwNdsOpenObject( TreeName.Buffer,
  54. NULL,
  55. NULL,
  56. &hTree,
  57. NULL,
  58. NULL,
  59. NULL,
  60. NULL,
  61. NULL );
  62. if ( status )
  63. {
  64. printf( "\nError: NwNdsOpenObject returned status 0x%.8X\n", status );
  65. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  66. GetLastError() );
  67. return -1;
  68. }
  69. if ( argv[2][1] == 'a' && argv[3][0] == 'A' )
  70. {
  71. DWORD dwSyntaxId;
  72. DWORD dwMinValue;
  73. DWORD dwMaxValue;
  74. printf( "\nGoing to try to add an attribute to schema.\n" );
  75. printf( "\nEnter a syntax id (0-27) for new attribute %S\n", ObjectName.Buffer );
  76. scanf( "%d", &dwSyntaxId );
  77. printf( "\nEnter a minimum range value for new attribute %S\n", ObjectName.Buffer );
  78. scanf( "%d", &dwMinValue );
  79. printf( "\nEnter a maximum range value for new attribute %S\n", ObjectName.Buffer );
  80. scanf( "%d", &dwMaxValue );
  81. status = NwNdsDefineAttribute( hTree,
  82. ObjectName.Buffer,
  83. NDS_SINGLE_VALUED_ATTR,
  84. dwSyntaxId,
  85. dwMinValue,
  86. dwMaxValue,
  87. asn1Id );
  88. if ( status )
  89. {
  90. printf( "\nError: NwNdsDefineAttribute returned status 0x%.8X\n", status );
  91. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  92. GetLastError() );
  93. return -1;
  94. }
  95. printf( "\n Success!\n" );
  96. return 0;
  97. }
  98. if ( argv[2][1] == 'r' && argv[3][0] == 'A' )
  99. {
  100. printf( "\nGoing to try to remove an attribute from schema.\n" );
  101. status = NwNdsDeleteAttrDef( hTree,
  102. ObjectName.Buffer );
  103. if ( status )
  104. {
  105. printf( "\nError: NwNdsDeleteAttrDef returned status 0x%.8X\n", status );
  106. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  107. GetLastError() );
  108. return -1;
  109. }
  110. printf( "\n Success!\n" );
  111. return 0;
  112. }
  113. if ( argv[2][1] == 'a' && argv[3][0] == 'C' )
  114. {
  115. HANDLE hSuperClasses = NULL;
  116. HANDLE hContainmentClasses = NULL;
  117. HANDLE hNamingAttributes = NULL;
  118. HANDLE hMandatoryAttributes = NULL;
  119. HANDLE hOptionalAttributes = NULL;
  120. DWORD dwFlags;
  121. printf( "\nGoing to try to add a class to schema.\n" );
  122. do
  123. {
  124. printf( "\nEnter super class name or <Enter> to end : " );
  125. GetStringOrDefault( TempName, L"" );
  126. if ( wcslen(TempName) > 0 )
  127. {
  128. if ( hSuperClasses == NULL )
  129. {
  130. status = NwNdsCreateBuffer( NDS_SCHEMA_DEFINE_CLASS,
  131. &hSuperClasses );
  132. if ( status )
  133. {
  134. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  135. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  136. GetLastError() );
  137. return -1;
  138. }
  139. }
  140. status = NwNdsPutInBuffer( TempName,
  141. 0,
  142. NULL,
  143. 0,
  144. 0,
  145. hSuperClasses );
  146. if ( status )
  147. {
  148. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  149. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  150. GetLastError() );
  151. return -1;
  152. }
  153. }
  154. } while ( wcslen(TempName) > 0 );
  155. do
  156. {
  157. printf( "\nEnter containment class name or <Enter> to end : " );
  158. GetStringOrDefault( TempName, L"" );
  159. if ( wcslen(TempName) > 0 )
  160. {
  161. if ( hContainmentClasses == NULL )
  162. {
  163. status = NwNdsCreateBuffer( NDS_SCHEMA_DEFINE_CLASS,
  164. &hContainmentClasses );
  165. if ( status )
  166. {
  167. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  168. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  169. GetLastError() );
  170. return -1;
  171. }
  172. }
  173. status = NwNdsPutInBuffer( TempName,
  174. 0,
  175. NULL,
  176. 0,
  177. 0,
  178. hContainmentClasses );
  179. if ( status )
  180. {
  181. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  182. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  183. GetLastError() );
  184. return -1;
  185. }
  186. }
  187. } while ( wcslen(TempName) > 0 );
  188. do
  189. {
  190. printf( "\nEnter naming attribute name or <Enter> to end : " );
  191. GetStringOrDefault( TempName, L"" );
  192. if ( wcslen(TempName) > 0 )
  193. {
  194. if ( hNamingAttributes == NULL )
  195. {
  196. status = NwNdsCreateBuffer( NDS_SCHEMA_DEFINE_CLASS,
  197. &hNamingAttributes );
  198. if ( status )
  199. {
  200. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  201. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  202. GetLastError() );
  203. return -1;
  204. }
  205. }
  206. status = NwNdsPutInBuffer( TempName,
  207. 0,
  208. NULL,
  209. 0,
  210. 0,
  211. hNamingAttributes );
  212. if ( status )
  213. {
  214. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  215. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  216. GetLastError() );
  217. return -1;
  218. }
  219. }
  220. } while ( wcslen(TempName) > 0 );
  221. do
  222. {
  223. printf( "\nEnter mandatory attribute name or <Enter> to end : " );
  224. GetStringOrDefault( TempName, L"" );
  225. if ( wcslen(TempName) > 0 )
  226. {
  227. if ( hMandatoryAttributes == NULL )
  228. {
  229. status = NwNdsCreateBuffer( NDS_SCHEMA_DEFINE_CLASS,
  230. &hMandatoryAttributes );
  231. if ( status )
  232. {
  233. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  234. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  235. GetLastError() );
  236. return -1;
  237. }
  238. }
  239. status = NwNdsPutInBuffer( TempName,
  240. 0,
  241. NULL,
  242. 0,
  243. 0,
  244. hMandatoryAttributes );
  245. if ( status )
  246. {
  247. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  248. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  249. GetLastError() );
  250. return -1;
  251. }
  252. }
  253. } while ( wcslen(TempName) > 0 );
  254. do
  255. {
  256. printf( "\nEnter optional attribute name or <Enter> to end : " );
  257. GetStringOrDefault( TempName, L"" );
  258. if ( wcslen(TempName) > 0 )
  259. {
  260. if ( hOptionalAttributes == NULL )
  261. {
  262. status = NwNdsCreateBuffer( NDS_SCHEMA_DEFINE_CLASS,
  263. &hOptionalAttributes );
  264. if ( status )
  265. {
  266. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  267. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  268. GetLastError() );
  269. return -1;
  270. }
  271. }
  272. status = NwNdsPutInBuffer( TempName,
  273. 0,
  274. NULL,
  275. 0,
  276. 0,
  277. hOptionalAttributes );
  278. if ( status )
  279. {
  280. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n", status );
  281. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  282. GetLastError() );
  283. return -1;
  284. }
  285. }
  286. } while ( wcslen(TempName) > 0 );
  287. printf( "\nEnter a value for the class flags : " );
  288. scanf( "%d", &dwFlags );
  289. status = NwNdsDefineClass( hTree,
  290. ObjectName.Buffer,
  291. dwFlags,
  292. asn1Id,
  293. hSuperClasses,
  294. hContainmentClasses,
  295. hNamingAttributes,
  296. hMandatoryAttributes,
  297. hOptionalAttributes );
  298. if ( status )
  299. {
  300. printf( "\nError: NwNdsDefineAttribute returned status 0x%.8X\n", status );
  301. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  302. GetLastError() );
  303. return -1;
  304. }
  305. printf( "\n Success!\n" );
  306. return 0;
  307. }
  308. if ( argv[2][1] == 'r' && argv[3][0] == 'C' )
  309. {
  310. printf( "\nGoing to try to remove a class from schema.\n" );
  311. status = NwNdsDeleteClassDef( hTree,
  312. ObjectName.Buffer );
  313. if ( status )
  314. {
  315. printf( "\nError: NwNdsDeleteClassDef returned status 0x%.8X\n", status );
  316. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  317. GetLastError() );
  318. return -1;
  319. }
  320. printf( "\n Success!\n" );
  321. return 0;
  322. }
  323. if ( argv[2][1] == 'm' && argv[3][0] == 'C' )
  324. {
  325. WCHAR AddAttributeName[256];
  326. printf( "\nGoing to try to add an attribute to a class in the schema.\n" );
  327. printf( "\nEnter an attribute name to add to class %S\n", ObjectName.Buffer );
  328. GetStringOrDefault( AddAttributeName, L"" );
  329. status = NwNdsAddAttributeToClass( hTree,
  330. ObjectName.Buffer,
  331. AddAttributeName );
  332. if ( status )
  333. {
  334. printf( "\nError: NwNdsAddAttributeToClass returned status 0x%.8X\n", status );
  335. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  336. GetLastError() );
  337. return -1;
  338. }
  339. printf( "\n Success!\n" );
  340. return 0;
  341. }
  342. goto Usage;
  343. }