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.

526 lines
16 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Utils.c
  5. Abstract:
  6. Collection of functions used by ndsutils applications.
  7. Author:
  8. Glenn Curtis [glennc] 25-Jan-96
  9. ***/
  10. #include <ndsapi32.h>
  11. #include <nds32.h>
  12. #include <ndsattr.h>
  13. #include <ndssntx.h>
  14. #define ROUNDUP4(x) ( ( (x) + 3 ) & ( ~3 ) )
  15. VOID
  16. PrintObjectAttributeNamesAndValues(
  17. char * TreeName,
  18. char * ObjectName,
  19. DWORD NumberOfEntries,
  20. LPNDS_ATTR_INFO lpEntries );
  21. VOID
  22. PrintValues(
  23. DWORD Count,
  24. DWORD SyntaxId,
  25. LPBYTE lpValues );
  26. LPBYTE
  27. PrintValue(
  28. DWORD SyntaxId,
  29. LPBYTE lpValue );
  30. VOID
  31. DumpListOfStrings(
  32. LPWSTR_LIST lpStrings );
  33. VOID
  34. GetStringOrDefault(
  35. LPWSTR string,
  36. LPWSTR defaultString );
  37. void
  38. DumpObjectsToConsole(
  39. DWORD NumberOfObjects,
  40. DWORD InformationType,
  41. LPNDS_OBJECT_INFO lpObjects );
  42. VOID
  43. PrintObjectAttributeNamesAndValues(
  44. char * TreeName,
  45. char * ObjectName,
  46. DWORD NumberOfEntries,
  47. LPNDS_ATTR_INFO lpEntries )
  48. {
  49. DWORD status = NO_ERROR;
  50. DWORD iter;
  51. DWORD iter2;
  52. DWORD PaddingLength;
  53. printf( "\n Reading all attributes from object \\\\%s\\%s\n returned the following:\n\n", TreeName, ObjectName );
  54. printf( "\n Attribute Name | Attribute Value \n" );
  55. printf( "____________________________________|_______________________________________\n" );
  56. for ( iter = 0; iter < NumberOfEntries; iter++ )
  57. {
  58. printf( " %S", lpEntries[iter].szAttributeName );
  59. PaddingLength = 33 - wcslen( lpEntries[iter].szAttributeName );
  60. for ( iter2 = 0; iter2 < PaddingLength; iter2++ )
  61. printf( " " );
  62. printf( "|" );
  63. PrintValues( lpEntries[iter].dwNumberOfValues,
  64. lpEntries[iter].dwSyntaxId,
  65. lpEntries[iter].lpValue );
  66. printf( "\n" );
  67. }
  68. }
  69. VOID
  70. PrintAttributeNamesAndValues(
  71. DWORD NumberOfEntries,
  72. LPNDS_ATTR_INFO lpEntries )
  73. {
  74. DWORD status = NO_ERROR;
  75. DWORD iter;
  76. DWORD iter2;
  77. DWORD PaddingLength;
  78. printf( "\n Attribute Name | Attribute Value \n" );
  79. printf( "____________________________________|_______________________________________\n" );
  80. for ( iter = 0; iter < NumberOfEntries; iter++ )
  81. {
  82. printf( " %S", lpEntries[iter].szAttributeName );
  83. PaddingLength = 33 - wcslen( lpEntries[iter].szAttributeName );
  84. for ( iter2 = 0; iter2 < PaddingLength; iter2++ )
  85. printf( " " );
  86. printf( "|" );
  87. PrintValues( lpEntries[iter].dwNumberOfValues,
  88. lpEntries[iter].dwSyntaxId,
  89. lpEntries[iter].lpValue );
  90. printf( "\n" );
  91. }
  92. }
  93. VOID
  94. PrintValues(
  95. DWORD Count,
  96. DWORD SyntaxId,
  97. LPBYTE lpValues )
  98. {
  99. DWORD iter;
  100. LPBYTE lpByte = lpValues;
  101. printf( " Syntax Id: %d\tNumber of values: %d\n", SyntaxId, Count );
  102. printf( " |\n" );
  103. printf( " | Value(s):\n" );
  104. for ( iter = 0; iter < Count; iter++ )
  105. {
  106. printf( " | Value %d:\n",
  107. iter + 1 );
  108. lpByte = PrintValue( SyntaxId, lpByte );
  109. }
  110. printf( "____________________________________|_______________________________________" );
  111. }
  112. LPBYTE
  113. PrintValue(
  114. DWORD SyntaxId,
  115. LPBYTE lpByte )
  116. {
  117. DWORD len = 0;
  118. DWORD iter;
  119. DWORD nFields;
  120. switch( SyntaxId )
  121. {
  122. case NDS_SYNTAX_ID_1 :
  123. case NDS_SYNTAX_ID_2 :
  124. case NDS_SYNTAX_ID_3 :
  125. case NDS_SYNTAX_ID_4 :
  126. case NDS_SYNTAX_ID_5 :
  127. case NDS_SYNTAX_ID_10 :
  128. case NDS_SYNTAX_ID_20 :
  129. {
  130. LPASN1_TYPE_1 lpASN1_1 = (LPASN1_TYPE_1) lpByte;
  131. printf( " | %S\n",
  132. lpASN1_1->DNString );
  133. lpByte = (LPBYTE ) lpASN1_1 + sizeof(ASN1_TYPE_1);
  134. }
  135. break;
  136. case NDS_SYNTAX_ID_6 :
  137. {
  138. LPASN1_TYPE_6 lpASN1_6 = (LPASN1_TYPE_6) lpByte;
  139. printf( " | %S\n",
  140. lpASN1_6->String );
  141. while ( lpASN1_6->Next != NULL )
  142. {
  143. lpASN1_6 = lpASN1_6->Next;
  144. printf( " | %S\n",
  145. lpASN1_6->String );
  146. }
  147. lpByte = (LPBYTE ) lpASN1_6 + sizeof(ASN1_TYPE_6);
  148. }
  149. break;
  150. case NDS_SYNTAX_ID_7 :
  151. {
  152. LPASN1_TYPE_7 lpASN1_7 = (LPASN1_TYPE_7) lpByte;
  153. printf( " | %S\n",
  154. lpASN1_7->Boolean ? L"TRUE" : L"FALSE" );
  155. lpByte = (LPBYTE ) lpASN1_7 + sizeof(ASN1_TYPE_7);
  156. }
  157. break;
  158. case NDS_SYNTAX_ID_8 :
  159. case NDS_SYNTAX_ID_22 :
  160. case NDS_SYNTAX_ID_24 :
  161. case NDS_SYNTAX_ID_27 :
  162. {
  163. LPASN1_TYPE_8 lpASN1_8 = (LPASN1_TYPE_8) lpByte;
  164. printf( " | %ld\n",
  165. lpASN1_8->Integer );
  166. lpByte = (LPBYTE ) lpASN1_8 + sizeof(ASN1_TYPE_8);
  167. }
  168. break;
  169. case NDS_SYNTAX_ID_9 :
  170. {
  171. LPASN1_TYPE_9 lpASN1_9 = (LPASN1_TYPE_9) lpByte;
  172. printf( " ( Octet String Length ) | %ld\n",
  173. lpASN1_9->Length );
  174. lpByte = (LPBYTE ) lpASN1_9 + sizeof(ASN1_TYPE_9);
  175. }
  176. break;
  177. case NDS_SYNTAX_ID_11 :
  178. {
  179. LPASN1_TYPE_11 lpASN1_11 = (LPASN1_TYPE_11) lpByte;
  180. printf( " | %S\n",
  181. lpASN1_11->TelephoneNumber );
  182. lpByte = (LPBYTE ) lpASN1_11 + sizeof(ASN1_TYPE_11);
  183. }
  184. break;
  185. case NDS_SYNTAX_ID_12 :
  186. {
  187. LPASN1_TYPE_12 lpASN1_12 = (LPASN1_TYPE_12) lpByte;
  188. printf( " ( Address Type ) | %ld\n",
  189. lpASN1_12->AddressType );
  190. printf( " ( Address Length ) | %ld\n",
  191. lpASN1_12->AddressLength );
  192. lpByte = (LPBYTE ) lpASN1_12 + sizeof(ASN1_TYPE_12);
  193. }
  194. break;
  195. case NDS_SYNTAX_ID_13 :
  196. {
  197. LPASN1_TYPE_13 lpASN1_13 = (LPASN1_TYPE_13) lpByte;
  198. printf( " | " );
  199. for ( iter = 0; iter < lpASN1_13->Length; iter++ )
  200. {
  201. printf( "%x", lpASN1_13->Data[iter] );
  202. }
  203. printf( "\n" );
  204. while ( lpASN1_13->Next != NULL )
  205. {
  206. lpASN1_13 = lpASN1_13->Next;
  207. printf( " | " );
  208. for ( iter = 0; iter < lpASN1_13->Length; iter++ )
  209. {
  210. printf( "%x", lpASN1_13->Data[iter] );
  211. }
  212. printf( "\n" );
  213. }
  214. lpByte = (LPBYTE ) lpASN1_13 + sizeof(ASN1_TYPE_13);
  215. }
  216. break;
  217. case NDS_SYNTAX_ID_14 :
  218. {
  219. LPASN1_TYPE_14 lpASN1_14 = (LPASN1_TYPE_14) lpByte;
  220. printf( " ( Type ) | %ld\n",
  221. lpASN1_14->Type );
  222. printf( " ( Address ) | %S\n",
  223. lpASN1_14->Address );
  224. lpByte = (LPBYTE ) lpASN1_14 + sizeof(ASN1_TYPE_14);
  225. }
  226. break;
  227. case NDS_SYNTAX_ID_15 :
  228. {
  229. LPASN1_TYPE_15 lpASN1_15 = (LPASN1_TYPE_15) lpByte;
  230. printf( " ( Type ) | %ld\n",
  231. lpASN1_15->Type );
  232. printf( " ( Volume Name ) | %S\n",
  233. lpASN1_15->VolumeName );
  234. printf( " ( Path ) | %S\n",
  235. lpASN1_15->Path );
  236. lpByte = (LPBYTE ) lpASN1_15 + sizeof(ASN1_TYPE_15);
  237. }
  238. break;
  239. case NDS_SYNTAX_ID_16 :
  240. {
  241. LPASN1_TYPE_16 lpASN1_16 = (LPASN1_TYPE_16) lpByte;
  242. printf( " ( Server Name ) | %S\n",
  243. lpASN1_16->ServerName );
  244. printf( " ( Replica Type ) | %ld\n",
  245. lpASN1_16->ReplicaType );
  246. printf( " ( Replica Number ) | %ld\n",
  247. lpASN1_16->ReplicaNumber );
  248. printf( " ( Count ) | %ld\n",
  249. lpASN1_16->Count );
  250. for ( iter = 0; iter < lpASN1_16->Count; iter++ )
  251. {
  252. printf( " ( Address Type ) | %ld\n",
  253. lpASN1_16->ReplicaAddressHint[iter].AddressType );
  254. printf( " ( Address Length ) | %ld\n",
  255. lpASN1_16->ReplicaAddressHint[iter].AddressLength );
  256. }
  257. lpByte += sizeof(ASN1_TYPE_16) - sizeof(ASN1_TYPE_12) +
  258. ( lpASN1_16->Count * sizeof(ASN1_TYPE_12) );
  259. }
  260. break;
  261. case NDS_SYNTAX_ID_17 :
  262. {
  263. LPASN1_TYPE_17 lpASN1_17 = (LPASN1_TYPE_17) lpByte;
  264. printf( " ( Protected Attribute Name )| %S\n",
  265. lpASN1_17->ProtectedAttrName );
  266. printf( " ( Subject Name ) | %S\n",
  267. lpASN1_17->SubjectName );
  268. printf( " ( NWDS_PRIVILEGES ) | %ld\n",
  269. lpASN1_17->Privileges );
  270. lpByte = (LPBYTE ) lpASN1_17 + sizeof(ASN1_TYPE_17);
  271. }
  272. break;
  273. case NDS_SYNTAX_ID_18 :
  274. {
  275. LPASN1_TYPE_18 lpASN1_18 = (LPASN1_TYPE_18) lpByte;
  276. printf( " ( Postal Address - line 1 ) | %S\n",
  277. lpASN1_18->PostalAddress[0] );
  278. printf( " ( Postal Address - line 2 ) | %S\n",
  279. lpASN1_18->PostalAddress[1] );
  280. printf( " ( Postal Address - line 3 ) | %S\n",
  281. lpASN1_18->PostalAddress[2] );
  282. printf( " ( Postal Address - line 4 ) | %S\n",
  283. lpASN1_18->PostalAddress[3] );
  284. printf( " ( Postal Address - line 5 ) | %S\n",
  285. lpASN1_18->PostalAddress[4] );
  286. printf( " ( Postal Address - line 6 ) | %S\n",
  287. lpASN1_18->PostalAddress[5] );
  288. lpByte = (LPBYTE ) lpASN1_18 + sizeof(ASN1_TYPE_18);
  289. }
  290. break;
  291. case NDS_SYNTAX_ID_19 :
  292. {
  293. LPASN1_TYPE_19 lpASN1_19 = (LPASN1_TYPE_19) lpByte;
  294. printf( " ( Whole seconds )| %ld\n",
  295. lpASN1_19->WholeSeconds );
  296. printf( " ( Event ID ) | %ld\n",
  297. lpASN1_19->EventID );
  298. lpByte = (LPBYTE ) lpASN1_19 + sizeof(ASN1_TYPE_19);
  299. }
  300. break;
  301. case NDS_SYNTAX_ID_21 :
  302. {
  303. LPASN1_TYPE_21 lpASN1_21 = (LPASN1_TYPE_21) lpByte;
  304. printf( " ( Length )| %ld\n",
  305. lpASN1_21->Length );
  306. lpByte = (LPBYTE ) lpASN1_21 + sizeof(ASN1_TYPE_21);
  307. }
  308. break;
  309. case NDS_SYNTAX_ID_23 :
  310. {
  311. LPASN1_TYPE_23 lpASN1_23 = (LPASN1_TYPE_23) lpByte;
  312. printf( " ( Remote ID ) | %ld\n",
  313. lpASN1_23->RemoteID );
  314. printf( " ( Object Name ) | %S\n",
  315. lpASN1_23->ObjectName );
  316. lpByte = (LPBYTE ) lpASN1_23 + sizeof(ASN1_TYPE_23);
  317. }
  318. break;
  319. case NDS_SYNTAX_ID_25 :
  320. {
  321. LPASN1_TYPE_25 lpASN1_25 = (LPASN1_TYPE_25) lpByte;
  322. printf( " ( Object Name ) | %S\n",
  323. lpASN1_25->ObjectName );
  324. printf( " ( Level ) | %ld\n",
  325. lpASN1_25->Level );
  326. printf( " ( Interval ) | %ld\n",
  327. lpASN1_25->Interval );
  328. lpByte = (LPBYTE ) lpASN1_25 + sizeof(ASN1_TYPE_25);
  329. }
  330. break;
  331. case NDS_SYNTAX_ID_26 :
  332. {
  333. LPASN1_TYPE_26 lpASN1_26 = (LPASN1_TYPE_26) lpByte;
  334. printf( " ( Object Name ) | %S\n",
  335. lpASN1_26->ObjectName );
  336. printf( " ( Amount ) | %ld\n",
  337. lpASN1_26->Amount );
  338. lpByte = (LPBYTE ) lpASN1_26 + sizeof(ASN1_TYPE_26);
  339. }
  340. break;
  341. default :
  342. printf( " | <UNKNOWN SYNTAX ID>\n" );
  343. }
  344. return lpByte;
  345. }
  346. VOID
  347. PrintAttributeNames(
  348. DWORD NumberOfEntries,
  349. LPNDS_NAME_ONLY lpEntries )
  350. {
  351. DWORD status = NO_ERROR;
  352. DWORD iter;
  353. DWORD iter2;
  354. DWORD PaddingLength;
  355. printf( "\n Attribute Name\n" );
  356. printf( "____________________________________\n" );
  357. for ( iter = 0; iter < NumberOfEntries; iter++ )
  358. {
  359. printf( " %S", lpEntries[iter].szName );
  360. printf( "\n" );
  361. }
  362. }
  363. VOID
  364. DumpListOfStrings(
  365. LPWSTR_LIST lpStrings )
  366. {
  367. LPWSTR_LIST lpTempStrings = lpStrings;
  368. while ( lpTempStrings != NULL )
  369. {
  370. printf( " %S\n", lpTempStrings->szString );
  371. lpTempStrings = lpTempStrings->Next;
  372. }
  373. printf( "\n" );
  374. }
  375. VOID
  376. GetStringOrDefault(
  377. LPWSTR szString,
  378. LPWSTR szDefaultString )
  379. {
  380. int i = 0;
  381. WCHAR ch;
  382. ch = getwchar();
  383. while ( ch != '\r' && ch != '\n' )
  384. {
  385. szString[i] = ch;
  386. i++;
  387. szString[i] = 0;
  388. ch = getwchar();
  389. }
  390. if ( i == 0 && szDefaultString != NULL )
  391. {
  392. wcscpy( szString, szDefaultString );
  393. }
  394. if ( i == 0 && szDefaultString == NULL )
  395. {
  396. wcscpy( szString, L"" );
  397. }
  398. }
  399. void
  400. DumpObjectsToConsole(
  401. DWORD NumberOfObjects,
  402. DWORD InformationType,
  403. LPNDS_OBJECT_INFO lpObjects )
  404. {
  405. DWORD i;
  406. LPNDS_OBJECT_INFO lpTempObject = lpObjects;
  407. for ( i = 0; i < NumberOfObjects; i++ )
  408. {
  409. printf( "\n______________________________________________\n" );
  410. printf( " Object Full Name : %S\n",
  411. lpTempObject->szObjectFullName );
  412. printf( " Object Name : %S\n",
  413. lpTempObject->szObjectName );
  414. printf( " Object Class Name : %S\n",
  415. lpTempObject->szObjectClass );
  416. printf( " Object Entry Id : 0x%.8X\n",
  417. lpTempObject->dwEntryId );
  418. printf( " Object Modification Time : 0x%.8X\n",
  419. lpTempObject->dwModificationTime );
  420. printf( " Object Subordinate Count : %ld\n\n",
  421. lpTempObject->dwSubordinateCount );
  422. printf( " Number of attributes : %ld\n\n",
  423. lpTempObject->dwNumberOfAttributes );
  424. if ( lpTempObject->dwNumberOfAttributes )
  425. {
  426. if ( InformationType == NDS_INFO_ATTR_NAMES_VALUES )
  427. {
  428. PrintAttributeNamesAndValues( lpTempObject->dwNumberOfAttributes,
  429. (LPNDS_ATTR_INFO) lpTempObject->lpAttribute );
  430. }
  431. if ( InformationType == NDS_INFO_NAMES )
  432. {
  433. PrintAttributeNames( lpTempObject->dwNumberOfAttributes,
  434. (LPNDS_NAME_ONLY) lpTempObject->lpAttribute );
  435. }
  436. }
  437. lpTempObject += 1;
  438. }
  439. }