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.

253 lines
6.1 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*************************************************************************
  3. *
  4. * MSLAN.C
  5. *
  6. * Name Enumerator for Microsoft networks
  7. *
  8. *
  9. *************************************************************************/
  10. /*
  11. * Includes
  12. */
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <lm.h>
  18. #include "qappsrv.h"
  19. /*=============================================================================
  20. == External Functions Defined
  21. =============================================================================*/
  22. int MsEnumerate( void );
  23. /*=============================================================================
  24. == Private Functions Defined
  25. =============================================================================*/
  26. int _ServerEnum( PSERVER_INFO_101 *, LPDWORD );
  27. int _LookUpAddress( LPTSTR );
  28. /*=============================================================================
  29. == Functions used
  30. =============================================================================*/
  31. int TreeAdd( LPTSTR, LPTSTR );
  32. /*=============================================================================
  33. == Global Data
  34. =============================================================================*/
  35. extern WCHAR Domain[];
  36. extern USHORT fAddress;
  37. extern WCHAR AppServer[];
  38. /*******************************************************************************
  39. *
  40. * MsEnumerate
  41. *
  42. * MsEnumerate adds all the hydra application servers on a ms network
  43. * to a binary tree
  44. *
  45. * ENTRY:
  46. * nothing
  47. *
  48. * EXIT:
  49. * ERROR_SUCCESS - no error
  50. *
  51. ******************************************************************************/
  52. int
  53. MsEnumerate()
  54. {
  55. PSERVER_TRANSPORT_INFO_0 pTransport;
  56. PSERVER_INFO_101 pInfo = NULL;
  57. PSERVER_INFO_101 psv101= NULL;
  58. DWORD AvailCount;
  59. ULONG ActualCount;
  60. ULONG TotalCount;
  61. WCHAR Address[MAXADDRESS];
  62. LPTSTR pName;
  63. int i, j;
  64. int rc;
  65. /*
  66. * Get the names and the count
  67. */
  68. if( AppServer[0] )
  69. {
  70. rc = ( int )NetServerGetInfo( AppServer , 101 , ( LPBYTE * )&psv101 );
  71. if( rc )
  72. {
  73. return rc;
  74. }
  75. if( ( psv101->sv101_type & SV_TYPE_TERMINALSERVER ) )
  76. {
  77. if( fAddress )
  78. {
  79. rc = _LookUpAddress( AppServer );
  80. }
  81. else
  82. {
  83. rc = TreeAdd( AppServer, L"" );
  84. }
  85. }
  86. if( psv101 != NULL )
  87. {
  88. NetApiBufferFree( psv101 );
  89. }
  90. return rc;
  91. }
  92. else if( rc = _ServerEnum( &pInfo, &AvailCount ) )
  93. {
  94. return( rc );
  95. }
  96. /*
  97. * Add name to binary tree
  98. */
  99. while( AvailCount-- )
  100. {
  101. pName = pInfo[AvailCount].sv101_name;
  102. if( fAddress )
  103. {
  104. rc = _LookUpAddress( pName );
  105. }
  106. else
  107. {
  108. if( rc = TreeAdd( pName, L"" ) )
  109. {
  110. break; //return( rc );
  111. }
  112. }
  113. }
  114. if( pInfo != NULL )
  115. {
  116. NetApiBufferFree( pInfo );
  117. }
  118. return( rc );
  119. }
  120. /*******************************************************************************
  121. *
  122. * _ServerEnum
  123. *
  124. * enumerate ms network servers
  125. *
  126. * ENTRY:
  127. * ppInfo (output)
  128. * adderss of pointer to data buffer
  129. * pAvail (output)
  130. * address to return number of entries available
  131. *
  132. * EXIT:
  133. * ERROR_SUCCESS - no error
  134. *
  135. ******************************************************************************/
  136. int
  137. _ServerEnum( PSERVER_INFO_101 * ppInfo, LPDWORD pAvail )
  138. {
  139. INT rc;
  140. DWORD TotalEntries;
  141. rc = NetServerEnum (
  142. NULL, //IN LPTSTR servername OPTIONAL,
  143. 101, //IN DWORD level,
  144. (LPBYTE *)ppInfo, //OUT LPBYTE *bufptr,
  145. (DWORD) -1, //IN DWORD prefmaxlen,
  146. pAvail, //OUT LPDWORD entriesread,
  147. &TotalEntries, //OUT LPDWORD totalentries,
  148. SV_TYPE_TERMINALSERVER, //IN DWORD servertype,
  149. Domain[0] ? Domain:NULL, //IN LPTSTR domain OPTIONAL,
  150. NULL ); //IN OUT LPDWORD resume_handle OPTIONAL
  151. return( rc );
  152. }
  153. /*******************************************************************************
  154. *
  155. * _LookUpAddress
  156. *
  157. * enumerate ms network nodes
  158. *
  159. * ENTRY:
  160. * Name of server
  161. * EXIT:
  162. * ERROR_SUCCESS - no error
  163. *
  164. ******************************************************************************/
  165. int _LookUpAddress( LPTSTR pName )
  166. {
  167. PSERVER_TRANSPORT_INFO_0 pTransport;
  168. ULONG ActualCount;
  169. ULONG TotalCount;
  170. WCHAR Address[MAXADDRESS] = {0};
  171. int i, j;
  172. int rc;
  173. rc = NetServerTransportEnum( pName,
  174. 0,
  175. (LPBYTE *) &pTransport,
  176. (DWORD) -1,
  177. &ActualCount,
  178. &TotalCount,
  179. NULL );
  180. if( rc == ERROR_SUCCESS )
  181. {
  182. for ( i=0; i < (int)ActualCount; i++ )
  183. {
  184. if ( wcscmp(pTransport->svti0_networkaddress,L"000000000000") )
  185. {
  186. int nSize;
  187. wcscpy( Address, L" [" );
  188. wcscat( Address, pTransport->svti0_networkaddress );
  189. wcscat( Address, L"]" );
  190. nSize = wcslen(Address);
  191. for ( j=11; j < nSize; j++ )
  192. {
  193. if ( Address[j] == '0' )
  194. {
  195. Address[j] = ' ';
  196. }
  197. else
  198. {
  199. break;
  200. }
  201. }
  202. }
  203. pTransport++;
  204. if( rc = TreeAdd( pName, _wcsupr(Address) ) )
  205. {
  206. break; //return( rc );
  207. }
  208. }
  209. }
  210. return rc;
  211. }