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.

255 lines
7.2 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Enum.c
  5. Abstract:
  6. Command line test tool for listing all subordinate objects of an object
  7. in a NDS tree.
  8. Author:
  9. Glenn Curtis [glennc] 25-Jan-96
  10. ***/
  11. #include <ndsapi32.h>
  12. #include <nds32.h>
  13. #include <utils.c>
  14. typedef struct
  15. {
  16. DWORD Signature;
  17. HANDLE NdsTree;
  18. DWORD ObjectId;
  19. DWORD ResumeId;
  20. DWORD NdsRawDataBuffer;
  21. DWORD NdsRawDataSize;
  22. DWORD NdsRawDataId;
  23. DWORD NdsRawDataCount;
  24. WCHAR Name[1];
  25. } NDS_OBJECT, * LPNDS_OBJECT;
  26. int
  27. _cdecl main( int argc, char **argv )
  28. {
  29. DWORD status = NO_ERROR;
  30. LPBYTE lpTemp = NULL;
  31. DWORD dwValue;
  32. DWORD i;
  33. HANDLE hObject;
  34. HANDLE hOperationData = NULL;
  35. LPNDS_ATTR_INFO lpEntries = NULL;
  36. DWORD NumberOfEntries = 0;
  37. OEM_STRING OemArg;
  38. UNICODE_STRING ObjectName;
  39. DWORD EntriesReturned;
  40. DWORD InformationType;
  41. DWORD ModificationTime;
  42. WCHAR szObjectName[256];
  43. WCHAR szObjectRelativeName[NDS_MAX_NAME_CHARS];
  44. WCHAR szObjectFullName[NDS_MAX_NAME_CHARS];
  45. WCHAR szObjectClassName[NDS_MAX_NAME_CHARS];
  46. LPNDS_FILTER_LIST lpFilters = NULL;
  47. //
  48. // All this nonsense is for converting ASCII to UNICODE
  49. //
  50. UNICODE_STRING Filters[5];
  51. WCHAR lpFilter1Buf[256];
  52. WCHAR lpFilter2Buf[256];
  53. WCHAR lpFilter3Buf[256];
  54. WCHAR lpFilter4Buf[256];
  55. WCHAR lpFilter5Buf[256];
  56. Filters[0].Length = 0;
  57. Filters[0].MaximumLength = sizeof( lpFilter1Buf );
  58. Filters[0].Buffer = lpFilter1Buf;
  59. Filters[1].Length = 0;
  60. Filters[1].MaximumLength = sizeof( lpFilter2Buf );
  61. Filters[1].Buffer = lpFilter2Buf;
  62. Filters[2].Length = 0;
  63. Filters[2].MaximumLength = sizeof( lpFilter3Buf );
  64. Filters[2].Buffer = lpFilter3Buf;
  65. Filters[3].Length = 0;
  66. Filters[3].MaximumLength = sizeof( lpFilter4Buf );
  67. Filters[3].Buffer = lpFilter4Buf;
  68. Filters[4].Length = 0;
  69. Filters[4].MaximumLength = sizeof( lpFilter5Buf );
  70. Filters[4].Buffer = lpFilter5Buf;
  71. //
  72. // End
  73. //
  74. ObjectName.Length = 0;
  75. ObjectName.MaximumLength = sizeof( szObjectName );
  76. ObjectName.Buffer = szObjectName;
  77. //
  78. // Check the arguments.
  79. //
  80. if ( argc < 2 || argc > 7 )
  81. {
  82. printf( "\nUsage: enum <object DN> [ClassName1] [Class Name2] ... [ClassName5]\n" );
  83. printf( "\n where:\n" );
  84. printf( " object DN = \\\\tree\\xxx.yyy.zzz\n" );
  85. printf( " ClassName = User Group Alias etc.\n" );
  86. printf( "\nFor Example: enum \\\\MARSDEV\\O=MARS User Group\n\n" );
  87. return -1;
  88. }
  89. if ( argc > 2 )
  90. {
  91. lpFilters = (LPNDS_FILTER_LIST) LocalAlloc( LMEM_ZEROINIT,
  92. sizeof( NDS_FILTER_LIST ) -
  93. sizeof( NDS_FILTER ) +
  94. ( sizeof( NDS_FILTER ) *
  95. argc - 2 ) );
  96. if ( lpFilters == NULL )
  97. {
  98. printf( "\nError: LocalAlloc failed\n\n" );
  99. return -1;
  100. }
  101. lpFilters->dwNumberOfFilters = argc - 2;
  102. for ( i = 0; i < lpFilters->dwNumberOfFilters; i++ )
  103. {
  104. OemArg.Length = strlen( argv[i + 2] );
  105. OemArg.MaximumLength = OemArg.Length;
  106. OemArg.Buffer = argv[i + 2];
  107. RtlOemStringToUnicodeString( &Filters[i], &OemArg, FALSE );
  108. lpFilters->Filters[i].szObjectClass = Filters[i].Buffer;
  109. }
  110. }
  111. OemArg.Length = strlen( argv[1] );
  112. OemArg.MaximumLength = OemArg.Length;
  113. OemArg.Buffer = argv[1];
  114. RtlOemStringToUnicodeString( &ObjectName, &OemArg, FALSE );
  115. status = NwNdsOpenObject( ObjectName.Buffer,
  116. NULL,
  117. NULL,
  118. &hObject,
  119. (LPWSTR) szObjectRelativeName,
  120. (LPWSTR) szObjectFullName,
  121. (LPWSTR) szObjectClassName,
  122. &ModificationTime,
  123. &NumberOfEntries );
  124. if ( status )
  125. {
  126. printf( "\nError: NwNdsOpenObject returned status 0x%.8X\n\n", status );
  127. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  128. GetLastError() );
  129. return -1;
  130. }
  131. printf( "NwNdsOpenObject returned the following data:\n\n" );
  132. printf( " Object Relative Name : %S\n" , szObjectRelativeName );
  133. printf( " Object Full Name : %S\n" , szObjectFullName );
  134. printf( " Object Class Name : %S\n" , szObjectClassName );
  135. printf( " Object Modification Time : %ld\n\n" , ModificationTime );
  136. printf( " Object Subordinate Count : %ld\n\n" , NumberOfEntries );
  137. printf( " Object Handle Info : \n" );
  138. printf( " Signature : 0x%.8X\n" ,
  139. ((LPNDS_OBJECT) hObject)->Signature );
  140. printf( " Resume Id : 0x%.8X\n" ,
  141. ((LPNDS_OBJECT) hObject)->ResumeId );
  142. printf( " Object Id : 0x%.8X\n" ,
  143. ((LPNDS_OBJECT) hObject)->ObjectId );
  144. printf( " Name : %S\n\n" ,
  145. ((LPNDS_OBJECT) hObject)->Name );
  146. status = NwNdsListSubObjects( hObject,
  147. 5,
  148. &EntriesReturned,
  149. lpFilters,
  150. &hOperationData );
  151. while( status == NO_ERROR )
  152. {
  153. DWORD NumberOfObjects;
  154. LPNDS_OBJECT_INFO lpObjects;
  155. printf( "Calling NwNdsListSubObjects return %ld objects.\n",
  156. EntriesReturned );
  157. NwNdsGetObjectListFromBuffer( hOperationData,
  158. &NumberOfObjects,
  159. &InformationType,
  160. &lpObjects );
  161. printf( "-- Calling NwNdsGetObjectListFromBuffer return %ld objects.\n",
  162. NumberOfObjects );
  163. DumpObjectsToConsole( NumberOfObjects, InformationType, lpObjects );
  164. (void) NwNdsFreeBuffer( hOperationData );
  165. hOperationData = NULL;
  166. status = NwNdsListSubObjects( hObject,
  167. 5,
  168. &EntriesReturned,
  169. lpFilters,
  170. &hOperationData );
  171. }
  172. if ( status != NO_ERROR &&
  173. status != WN_NO_MORE_ENTRIES )
  174. {
  175. printf( "\nError: NwNdsListSubObjects returned status 0x%.8X\n\n", status );
  176. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  177. GetLastError() );
  178. }
  179. CleanupAndExit:
  180. status = NwNdsCloseObject( hObject );
  181. if ( status )
  182. {
  183. printf( "\nError: NwNdsCloseObject returned status 0x%.8X\n\n", status );
  184. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  185. GetLastError() );
  186. }
  187. if ( hOperationData )
  188. {
  189. status = NwNdsFreeBuffer( hOperationData );
  190. if ( status )
  191. {
  192. printf( "\nError: NwNdsFreeBuffer returned status 0x%.8X\n\n", status );
  193. printf( "\nError: GetLastError returned: 0x%.8X\n\n",
  194. GetLastError() );
  195. }
  196. }
  197. return status;
  198. }