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.

237 lines
6.6 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ReadObj.c
  5. Abstract:
  6. Command line test tool for reading attributes of an object in a NDS tree.
  7. Author:
  8. Glenn Curtis [glennc] 05-Jan-96
  9. ***/
  10. #include <utils.c>
  11. int
  12. _cdecl main( int argc, char **argv )
  13. {
  14. DWORD status = NO_ERROR;
  15. LPBYTE lpTemp = NULL;
  16. DWORD dwValue;
  17. HANDLE hObject = NULL;
  18. HANDLE hOperationData = NULL;
  19. OEM_STRING OemArg;
  20. UNICODE_STRING ObjectName;
  21. WCHAR lpObjectName[256];
  22. //
  23. // For GetFromBuffer function calls
  24. //
  25. LPNDS_ATTR_INFO lpEntries = NULL;
  26. LPBYTE lpValue = NULL;
  27. WCHAR * lpAttributeName = NULL;
  28. DWORD SyntaxId = 0;
  29. DWORD NumberOfValues = 0;
  30. DWORD NumberOfEntries = 0;
  31. DWORD NumberOfEntriesRemaining = 0;
  32. ObjectName.Length = 0;
  33. ObjectName.MaximumLength = sizeof( lpObjectName );
  34. ObjectName.Buffer = lpObjectName;
  35. //
  36. // Check the arguments.
  37. //
  38. if ( argc != 2 )
  39. {
  40. printf( "\nUsage: readobj <object DN>\n" );
  41. printf( "\n where:\n" );
  42. printf( " object DN = \\\\tree\\xxx.yyy.zzz\n" );
  43. printf( "\nFor Example: readobj \\\\MARSDEV\\CN=TEST.OU=DEV.O=MARS\n\n" );
  44. return -1;
  45. }
  46. OemArg.Length = strlen( argv[1] );
  47. OemArg.MaximumLength = OemArg.Length;
  48. OemArg.Buffer = argv[1];
  49. RtlOemStringToUnicodeString( &ObjectName, &OemArg, FALSE );
  50. if ( status = NwNdsOpenObject( ObjectName.Buffer,
  51. NULL,
  52. NULL,
  53. &hObject,
  54. NULL,
  55. NULL,
  56. NULL,
  57. NULL,
  58. NULL ) != NO_ERROR )
  59. {
  60. printf( "\nError: NwNdsOpenObject returned status %ld\n\n", status );
  61. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  62. GetLastError() );
  63. return -1;
  64. }
  65. //
  66. // Prepare buffer with list of attributes to read
  67. //
  68. if ( status = NwNdsCreateBuffer( NDS_OBJECT_READ,
  69. &hOperationData )
  70. != NO_ERROR )
  71. {
  72. printf( "\nError: NwNdsCreateBuffer returned status %ld\n\n",
  73. status );
  74. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  75. GetLastError() );
  76. return -1;
  77. }
  78. printf( "Put value NDS_COMMON_NAME into attributes buffer\n" );
  79. if ( status = NwNdsPutInBuffer( NDS_COMMON_NAME,
  80. NULL,
  81. 0,
  82. 0,
  83. hOperationData )
  84. != NO_ERROR )
  85. {
  86. printf( "\nError: NwNdsPutInBuffer returned status %ld\n\n",
  87. status );
  88. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  89. GetLastError() );
  90. return -1;
  91. }
  92. printf( "Put value NDS_ORGANIZATIONAL_UNIT_NAME into attributes buffer\n" );
  93. if ( status = NwNdsPutInBuffer( NDS_ORGANIZATIONAL_UNIT_NAME,
  94. NULL,
  95. 0,
  96. 0,
  97. hOperationData )
  98. != NO_ERROR )
  99. {
  100. printf( "\nError: NwNdsPutInBuffer returned status %ld\n\n",
  101. status );
  102. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  103. GetLastError() );
  104. return -1;
  105. }
  106. printf( "Put value NDS_ORGANIZATION_NAME into attributes buffer\n" );
  107. if ( status = NwNdsPutInBuffer( NDS_ORGANIZATION_NAME,
  108. NULL,
  109. 0,
  110. 0,
  111. hOperationData )
  112. != NO_ERROR )
  113. {
  114. printf( "\nError: NwNdsPutInBuffer returned status %ld\n\n",
  115. status );
  116. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  117. GetLastError() );
  118. return -1;
  119. }
  120. printf( "Reading object attributes from the tree\n" );
  121. if ( status = NwNdsReadObject( hObject, NDS_INFO_NAMES_DEFS, &hOperationData ) != NO_ERROR )
  122. {
  123. printf( "\nError: NwNdsReadObject returned status %ld\n\n", status );
  124. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  125. GetLastError() );
  126. return -1;
  127. }
  128. if ( status = NwNdsGetAttrListFromBuffer( hOperationData,
  129. &NumberOfEntries,
  130. &lpEntries )
  131. != NO_ERROR )
  132. {
  133. printf( "\nError: NwNdsGetAttrListFromBuffer returned status %ld\n\n",
  134. status );
  135. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  136. GetLastError() );
  137. return -1;
  138. }
  139. if ( status = NwNdsFreeBuffer( hOperationData ) != NO_ERROR )
  140. {
  141. printf( "\nError: NwNdsFreeBuffer returned status %ld\n\n", status );
  142. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  143. GetLastError() );
  144. return -1;
  145. }
  146. hOperationData = NULL;
  147. printf( "Now reading ALL object attributes from the tree\n" );
  148. if ( status = NwNdsReadObject( hObject,
  149. NDS_INFO_NAMES_DEFS,
  150. &hOperationData )
  151. != NO_ERROR )
  152. {
  153. printf( "\nError: NwNdsReadObject returned status %ld\n\n", status );
  154. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  155. GetLastError() );
  156. return -1;
  157. }
  158. if ( status = NwNdsCloseObject( hObject ) != NO_ERROR )
  159. {
  160. printf( "\nError: NwNdsCloseObject returned status %ld\n\n", status );
  161. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  162. GetLastError() );
  163. return -1;
  164. }
  165. if ( status = NwNdsGetAttrListFromBuffer( hOperationData,
  166. &NumberOfEntries,
  167. &lpEntries )
  168. != NO_ERROR )
  169. {
  170. printf( "\nError: NwNdsGetAttrListFromBuffer returned status %ld\n\n",
  171. status );
  172. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  173. GetLastError() );
  174. return -1;
  175. }
  176. if ( status = NwNdsFreeBuffer( hOperationData ) != NO_ERROR )
  177. {
  178. printf( "\nError: NwNdsFreeBuffer returned status %ld\n\n", status );
  179. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  180. GetLastError() );
  181. return -1;
  182. }
  183. return status;
  184. }