Leaked source code of windows server 2003
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.

230 lines
6.2 KiB

  1. //****************************************************************************
  2. //
  3. // Microsoft NT Remote Access Service
  4. //
  5. // Copyright 1992-93
  6. //
  7. //
  8. // Revision History
  9. //
  10. //
  11. // 05/29/97 Rao Salapaka Created
  12. //
  13. //
  14. // Description: All Initialization code for rasman component lives here.
  15. //
  16. //****************************************************************************
  17. #ifndef UNICODE
  18. #define UNICODE
  19. #endif
  20. #ifdef _UNICODE
  21. #define _UNICODE
  22. #endif
  23. extern "C"
  24. {
  25. #include <nt.h>
  26. }
  27. #include <ntrtl.h>
  28. #include <nturtl.h>
  29. #include <tchar.h>
  30. //#include <comdef.h>
  31. #include <ncnetcfg.h>
  32. #include <rtutils.h>
  33. #include <initguid.h>
  34. #include <devguid.h>
  35. #include <netcfg_i.c>
  36. /* Bits returned by GetInstalledProtocols.
  37. */
  38. #define NP_Nbf 0x1
  39. #define NP_Ipx 0x2
  40. #define NP_Ip 0x4
  41. extern "C"
  42. {
  43. DWORD dwGetInstalledProtocols(DWORD *pdwInstalledProtocols,
  44. BOOL fRouter,
  45. BOOL fRasCli,
  46. BOOL fRasSrv);
  47. }
  48. DWORD
  49. dwGetInstalledProtocols(DWORD *pdwInstalledProtocols,
  50. BOOL fRouter,
  51. BOOL fRasCli,
  52. BOOL fRasSrv )
  53. {
  54. HRESULT hr = S_OK;
  55. INetCfg *pINetCfg = NULL;
  56. INetCfgComponent *pINetCfgComp = NULL;
  57. INetCfgComponent *pINetCfgRasCli = NULL;
  58. INetCfgComponent *pINetCfgRasSrv = NULL;
  59. INetCfgComponent *pINetCfgRasRtr = NULL;
  60. DWORD dwCountTries = 0;
  61. *pdwInstalledProtocols = 0;
  62. do
  63. {
  64. hr = HrCreateAndInitializeINetCfg( TRUE, &pINetCfg );
  65. if ( S_OK == hr )
  66. break;
  67. if ( NETCFG_E_IN_USE != hr )
  68. goto done;
  69. Sleep ( 5000 );
  70. dwCountTries ++;
  71. } while ( NETCFG_E_IN_USE == hr
  72. && dwCountTries < 6);
  73. if ( hr )
  74. goto done;
  75. //
  76. // Get RasClient component
  77. //
  78. if ( FAILED( hr = HrFindComponent(pINetCfg,
  79. GUID_DEVCLASS_NETSERVICE,
  80. c_szInfId_MS_RasCli,
  81. &pINetCfgRasCli) ) )
  82. goto done;
  83. //
  84. // Get RasSrv component
  85. //
  86. if ( FAILED( hr = HrFindComponent(pINetCfg,
  87. GUID_DEVCLASS_NETSERVICE,
  88. c_szInfId_MS_RasSrv,
  89. &pINetCfgRasSrv ) ) )
  90. goto done;
  91. //
  92. // Get RasRtr component
  93. //
  94. if ( FAILED ( hr = HrFindComponent ( pINetCfg,
  95. GUID_DEVCLASS_NETSERVICE,
  96. c_szInfId_MS_RasRtr,
  97. &pINetCfgRasRtr ) ) )
  98. goto done;
  99. //
  100. // Bail if neither DUN Client nor Dial Up Server is installed
  101. //
  102. if ( !pINetCfgRasCli
  103. && !pINetCfgRasSrv
  104. && !pINetCfgRasRtr)
  105. {
  106. hr = E_FAIL;
  107. goto done;
  108. }
  109. //
  110. // Get Nbf component
  111. //
  112. if (FAILED (hr = HrFindComponent(pINetCfg,
  113. GUID_DEVCLASS_NETTRANS,
  114. c_szInfId_MS_NetBEUI,
  115. &pINetCfgComp)))
  116. goto done;
  117. if (pINetCfgComp)
  118. {
  119. if ( ( fRasCli
  120. && pINetCfgRasCli
  121. && ( hr = pINetCfgRasCli->IsBoundTo( pINetCfgComp ) ) == S_OK )
  122. || ( fRasSrv
  123. && pINetCfgRasSrv
  124. && ( hr = pINetCfgRasSrv->IsBoundTo( pINetCfgComp ) ) == S_OK )
  125. || ( fRouter
  126. && pINetCfgRasRtr
  127. && ( hr = pINetCfgRasRtr->IsBoundTo( pINetCfgComp ) ) == S_OK ) )
  128. *pdwInstalledProtocols |= NP_Nbf;
  129. ReleaseObj(pINetCfgComp);
  130. pINetCfgComp = NULL;
  131. }
  132. //
  133. // Get TcpIp component
  134. //
  135. if (FAILED (hr = HrFindComponent(pINetCfg,
  136. GUID_DEVCLASS_NETTRANS,
  137. c_szInfId_MS_TCPIP,
  138. &pINetCfgComp)))
  139. goto done;
  140. if (pINetCfgComp)
  141. {
  142. if ( ( fRasCli
  143. && pINetCfgRasCli
  144. && ( hr = pINetCfgRasCli->IsBoundTo( pINetCfgComp ) ) == S_OK )
  145. || ( fRasSrv
  146. && pINetCfgRasSrv
  147. && ( hr = pINetCfgRasSrv->IsBoundTo( pINetCfgComp ) ) == S_OK )
  148. || ( fRouter
  149. && pINetCfgRasRtr
  150. && ( hr = pINetCfgRasRtr->IsBoundTo( pINetCfgComp ) ) == S_OK ) )
  151. *pdwInstalledProtocols |= NP_Ip;
  152. ReleaseObj (pINetCfgComp);
  153. pINetCfgComp = NULL;
  154. }
  155. //
  156. // Get NWIpx component
  157. //
  158. if (FAILED( hr = HrFindComponent(pINetCfg,
  159. GUID_DEVCLASS_NETTRANS,
  160. c_szInfId_MS_NWIPX,
  161. &pINetCfgComp)))
  162. goto done;
  163. if (pINetCfgComp)
  164. {
  165. if ( ( fRasCli
  166. && pINetCfgRasCli
  167. && ( hr = pINetCfgRasCli->IsBoundTo( pINetCfgComp ) ) == S_OK )
  168. || ( fRasSrv
  169. && pINetCfgRasSrv
  170. && ( hr = pINetCfgRasSrv->IsBoundTo( pINetCfgComp ) ) == S_OK )
  171. || ( fRouter
  172. && pINetCfgRasRtr
  173. && ( hr = pINetCfgRasSrv->IsBoundTo( pINetCfgComp ) ) == S_OK ) )
  174. *pdwInstalledProtocols |= NP_Ipx;
  175. ReleaseObj (pINetCfgComp);
  176. pINetCfgComp = NULL;
  177. }
  178. done:
  179. ReleaseObj (pINetCfgRasSrv);
  180. ReleaseObj (pINetCfgRasCli);
  181. ReleaseObj (pINetCfgRasRtr);
  182. if (pINetCfg)
  183. {
  184. HrUninitializeAndReleaseINetCfg( TRUE, pINetCfg);
  185. }
  186. if (SUCCEEDED (hr))
  187. hr = S_OK;
  188. return HRESULT_CODE( hr );
  189. }