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.

305 lines
7.4 KiB

  1. //
  2. // NDS Browser Test App for Supplemental Credentials
  3. //
  4. // Cory West
  5. // July 22, 1996
  6. //
  7. #include "ndsapi32.h"
  8. #include "nds.h"
  9. VOID
  10. ConsoleDumpSubordinates(
  11. PNDS_RESPONSE_SUBORDINATE_LIST pSubList
  12. );
  13. int
  14. _cdecl main(
  15. int argc,
  16. char **argv
  17. ) {
  18. NTSTATUS Status;
  19. //
  20. // For NwNdsOpenTreeHandle
  21. //
  22. HANDLE hRdr;
  23. OEM_STRING oemStr;
  24. UNICODE_STRING ObjectName;
  25. UNICODE_STRING UserName;
  26. UNICODE_STRING Password;
  27. WCHAR NdsStr[256];
  28. WCHAR UserStr[256];
  29. WCHAR PassStr[256];
  30. //
  31. // For NwNdsResolveName
  32. //
  33. PNDS_RESPONSE_RESOLVE_NAME psResolveName;
  34. DWORD dwOid;
  35. UNICODE_STRING ReferredServer;
  36. WCHAR ServerName[48];
  37. HANDLE hReferredServer;
  38. DWORD dwHandleType;
  39. //
  40. // For NwNdsReadObjectInfo
  41. //
  42. BYTE RawResponse[1024];
  43. PNDS_RESPONSE_GET_OBJECT_INFO psGetInfo;
  44. PBYTE pbRawGetInfo;
  45. DWORD dwStrLen;
  46. //
  47. // For NwNdsList
  48. //
  49. DWORD dwIterHandle;
  50. /**************************************************/
  51. //
  52. // Examine the argument count and hope for the best.
  53. //
  54. if ( argc != 5 ) {
  55. printf( "Usage: browser <tree name> <ds object path> <username> <password>\n" );
  56. printf( "For example, browser marsdev dev.mars corywest corywest.dev.mars\n");
  57. return -1;
  58. }
  59. //
  60. // Convert the tree name string to unicode.
  61. //
  62. oemStr.Length = strlen( argv[1] );
  63. oemStr.MaximumLength = oemStr.Length;
  64. oemStr.Buffer = argv[1];
  65. ObjectName.Length = 0;
  66. ObjectName.MaximumLength = sizeof( NdsStr );
  67. ObjectName.Buffer = NdsStr;
  68. RtlOemStringToUnicodeString( &ObjectName, &oemStr, FALSE );
  69. //
  70. // Convert the username and password.
  71. //
  72. oemStr.Length = strlen( argv[3] );
  73. oemStr.MaximumLength = oemStr.Length;
  74. oemStr.Buffer = argv[3];
  75. UserName.Length = 0;
  76. UserName.MaximumLength = sizeof( UserStr );
  77. UserName.Buffer = UserStr;
  78. RtlOemStringToUnicodeString( &UserName, &oemStr, FALSE );
  79. oemStr.Length = strlen( argv[4] );
  80. oemStr.MaximumLength = oemStr.Length;
  81. oemStr.Buffer = argv[4];
  82. Password.Length = 0;
  83. Password.MaximumLength = sizeof( PassStr );
  84. Password.Buffer = PassStr;
  85. RtlOemStringToUnicodeString( &Password, &oemStr, FALSE );
  86. //
  87. // Get a handle to the redirector.
  88. //
  89. Status = NwOpenHandleWithSupplementalCredentials( &ObjectName,
  90. &UserName,
  91. &Password,
  92. &dwHandleType,
  93. &hRdr );
  94. if ( !NT_SUCCESS( Status ) ) {
  95. printf( "*** Open Handle to Nds Tree: Status = %08lx\n", Status );
  96. return -1;
  97. }
  98. //
  99. // Resolve the name that we have to an object id.
  100. //
  101. oemStr.Length = strlen(argv[2]);
  102. oemStr.MaximumLength = oemStr.Length;
  103. oemStr.Buffer = argv[2];
  104. ObjectName.Length = 0;
  105. ObjectName.MaximumLength = sizeof(NdsStr);
  106. ObjectName.Buffer = NdsStr;
  107. RtlOemStringToUnicodeString( &ObjectName, &oemStr, FALSE );
  108. ReferredServer.Buffer = ServerName;
  109. ReferredServer.MaximumLength = sizeof( ServerName );
  110. ReferredServer.Length = 0;
  111. Status = NwNdsResolveName ( hRdr,
  112. &ObjectName,
  113. &dwOid,
  114. &ReferredServer,
  115. NULL,
  116. 0 );
  117. if ( !NT_SUCCESS( Status ) ) {
  118. printf( "*** Resolve Name: Status = %08lx\n", Status );
  119. goto Exit;
  120. }
  121. if ( ReferredServer.Length != 0 ) {
  122. //
  123. // We have to jump servers.
  124. //
  125. Status = NwNdsOpenGenericHandle( &ReferredServer,
  126. &dwHandleType,
  127. &hReferredServer );
  128. if ( !NT_SUCCESS( Status ) ) {
  129. printf( "*** Couldn't open referred server: Status = %08lx\n", Status );
  130. goto Exit;
  131. }
  132. CloseHandle( hRdr );
  133. hRdr = hReferredServer;
  134. }
  135. printf( "=========================== NDS Object Info ===========================\n" );
  136. printf( "Object ID = 0x%08lx\n", dwOid );
  137. //
  138. // Go for the object information.
  139. //
  140. Status = NwNdsReadObjectInfo( hRdr,
  141. dwOid,
  142. RawResponse,
  143. sizeof( RawResponse ) );
  144. if ( !NT_SUCCESS( Status ) ) {
  145. printf( "*** Get Object Info: Status = %08lx\n", Status );
  146. goto Exit;
  147. }
  148. psGetInfo = ( PNDS_RESPONSE_GET_OBJECT_INFO ) RawResponse;
  149. printf( "Flags = 0x%08lx\n", psGetInfo->EntryFlags );
  150. printf( "Subordinate Count = 0x%08lx\n", psGetInfo->SubordinateCount );
  151. printf( "Last Modified Time = 0x%08lx\n", psGetInfo->ModificationTime );
  152. //
  153. // Dig out the two unicode strings for class name and object name.
  154. //
  155. pbRawGetInfo = RawResponse;
  156. pbRawGetInfo += sizeof ( NDS_RESPONSE_GET_OBJECT_INFO );
  157. dwStrLen = * ( DWORD * ) pbRawGetInfo;
  158. pbRawGetInfo += sizeof( DWORD );
  159. printf( "Class Name: %S\n", pbRawGetInfo );
  160. pbRawGetInfo += ROUNDUP4( dwStrLen );
  161. dwStrLen = * ( DWORD * ) pbRawGetInfo;
  162. pbRawGetInfo += sizeof( DWORD );
  163. printf( "Object Name: %S\n", pbRawGetInfo );
  164. //
  165. // Get the subordinate list.
  166. //
  167. if ( psGetInfo->SubordinateCount ) {
  168. dwIterHandle = INITIAL_ITERATION;
  169. do {
  170. Status = NwNdsList( hRdr,
  171. dwOid,
  172. &dwIterHandle,
  173. RawResponse,
  174. sizeof( RawResponse ) );
  175. if ( !NT_SUCCESS( Status ) ) {
  176. printf( "*** List Subordinates: Status = %08lx\n", Status );
  177. goto Exit;
  178. }
  179. ConsoleDumpSubordinates( (PNDS_RESPONSE_SUBORDINATE_LIST) RawResponse );
  180. } while ( dwIterHandle != INITIAL_ITERATION );
  181. }
  182. Exit:
  183. CloseHandle( hRdr );
  184. if ( NT_SUCCESS( Status ) ) {
  185. return 0;
  186. } else {
  187. return -1;
  188. }
  189. }
  190. VOID
  191. ConsoleDumpSubordinates(
  192. PNDS_RESPONSE_SUBORDINATE_LIST pSubList
  193. ) {
  194. NTSTATUS Status;
  195. PNDS_RESPONSE_SUBORDINATE_ENTRY pSubEntry;
  196. PBYTE pbRaw;
  197. DWORD dwStrLen, dwEntries;
  198. dwEntries = pSubList->SubordinateEntries;
  199. printf( "======================== Subordinate List (%d) ========================\n", dwEntries );
  200. pSubEntry = ( PNDS_RESPONSE_SUBORDINATE_ENTRY )
  201. ( ( (BYTE *)pSubList ) + sizeof( NDS_RESPONSE_SUBORDINATE_LIST ) );
  202. while ( dwEntries ) {
  203. printf( "EntryID (0x%08lx),\tFlags (0x%08lx)\n",
  204. pSubEntry->EntryId, pSubEntry->Flags );
  205. printf( "Subordinate Count (%d),\tMod Time (0x%08lx)\n",
  206. pSubEntry->SubordinateCount, pSubEntry->ModificationTime );
  207. pbRaw = (BYTE *) pSubEntry;
  208. pbRaw += sizeof( NDS_RESPONSE_SUBORDINATE_ENTRY );
  209. dwStrLen = * ( DWORD * ) pbRaw;
  210. pbRaw += sizeof( DWORD );
  211. printf( "Class Name: %S\t", pbRaw );
  212. pbRaw += ROUNDUP4( dwStrLen );
  213. dwStrLen = * ( DWORD * ) pbRaw;
  214. pbRaw += sizeof( DWORD );
  215. printf( "Object Name: %S\n", pbRaw );
  216. pSubEntry = ( PNDS_RESPONSE_SUBORDINATE_ENTRY ) ( pbRaw + ROUNDUP4( dwStrLen ) );
  217. dwEntries--;
  218. printf( "-----------------------------------------------------------------------\n" );
  219. }
  220. return;
  221. }