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.

321 lines
7.0 KiB

  1. //****************************************************************************
  2. //
  3. // Microsoft NT Remote Access Service
  4. //
  5. // Copyright 1992-93
  6. //
  7. //
  8. // Revision History
  9. //
  10. //
  11. // 05/29/97s 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. #ifndef _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 <comdef.h>
  30. #include <tchar.h>
  31. #include <rtutils.h>
  32. #include <rasman.h>
  33. extern "C"
  34. {
  35. #include <reghelp.h>
  36. }
  37. #define REGISTRY_NUMBEROFRINGS TEXT("NumberOfRings")
  38. #define RNETCFG_RASCLI 1
  39. #define RNETCFG_RASSRV 2
  40. #define RNETCFG_ROUTER 4
  41. DWORD g_dwRasComponent = 0;
  42. #define TRACESETTINGS (0x00010000 | TRACE_USE_MASK | TRACE_USE_MSEC)
  43. extern "C"
  44. {
  45. DWORD dwTraceId;
  46. DWORD dwGetNumberOfRings ( PDWORD pdwRings );
  47. DWORD dwGetPortUsage(DWORD *pdwPortUsage);
  48. LONG lrIsModemRasEnabled(HKEY hkey, BOOL *pfRasEnabled);
  49. DeviceInfo * GetDeviceInfo (PBYTE pbGuid );
  50. }
  51. LONG
  52. lrCheckValue(
  53. HKEY hkeyRas,
  54. LPCTSTR lpcszValue,
  55. BOOL *pfEnabled)
  56. {
  57. DWORD dwdata;
  58. DWORD dwtype;
  59. DWORD dwsize = sizeof(DWORD);
  60. LONG lr;
  61. *pfEnabled = FALSE;
  62. if(ERROR_FILE_NOT_FOUND == (lr = RegQueryValueEx(
  63. hkeyRas,
  64. lpcszValue,
  65. 0, &dwtype,
  66. (PBYTE) &dwdata,
  67. &dwsize)))
  68. {
  69. TracePrintfExA(
  70. dwTraceId,
  71. TRACESETTINGS,
  72. "lrCheckValue: value %ws not found",
  73. lpcszValue);
  74. dwdata = 1;
  75. if(lr = lrRasEnableDevice(hkeyRas,
  76. lpcszValue))
  77. {
  78. TracePrintfExA(
  79. dwTraceId,
  80. TRACESETTINGS,
  81. "lrCheckValue: Couldn't set value %ws. 0x%x",
  82. lpcszValue,
  83. lr);
  84. goto done;
  85. }
  86. *pfEnabled = TRUE;
  87. goto done;
  88. }
  89. *pfEnabled = dwdata;
  90. done:
  91. return lr;
  92. }
  93. LONG
  94. lrIsModemRasEnabled(HKEY hkey,
  95. BOOL *pfRasEnabled,
  96. BOOL *pfRouterEnabled)
  97. {
  98. DWORD dwdata;
  99. DWORD dwsize = sizeof ( DWORD );
  100. DWORD dwtype;
  101. LONG lr;
  102. HKEY hkeyRas = NULL;
  103. DWORD dwDisposition;
  104. *pfRasEnabled = FALSE;
  105. *pfRouterEnabled = FALSE;
  106. //
  107. // Open the RAS key and if the key is not present
  108. // create the key.
  109. //
  110. if (lr = RegCreateKeyEx(
  111. hkey,
  112. TEXT("Clients\\Ras"),
  113. 0, NULL, 0,
  114. KEY_ALL_ACCESS,
  115. NULL,
  116. &hkeyRas,
  117. &dwDisposition))
  118. {
  119. TracePrintfExA(
  120. dwTraceId,
  121. TRACESETTINGS,
  122. "dwFindModemPortUsage: Failed to"
  123. "create/open RAS key under modem class. 0x%x",
  124. lr);
  125. goto done;
  126. }
  127. //
  128. // Check to see if the modem is enabled for Ras dialin
  129. //
  130. if(lr = lrCheckValue(
  131. hkeyRas,
  132. TEXT("EnableForRas"),
  133. pfRasEnabled))
  134. {
  135. TracePrintfExA(
  136. dwTraceId,
  137. TRACESETTINGS,
  138. "dwFindModemPortUsage: lrCheckValue"
  139. "failed for RasEnabled. %d",
  140. lr );
  141. lr = ERROR_SUCCESS;
  142. }
  143. if (!*pfRasEnabled)
  144. {
  145. TracePrintfExA(
  146. dwTraceId,
  147. TRACESETTINGS,
  148. "dwFindModemPortUsage: Modem"
  149. "is not enabled for RAS");
  150. }
  151. //
  152. // Check to see if the modem is enabled for routing
  153. //
  154. if(lr = lrCheckValue(
  155. hkeyRas,
  156. TEXT("EnableForRouting"),
  157. pfRouterEnabled))
  158. {
  159. TracePrintfExA(
  160. dwTraceId,
  161. TRACESETTINGS,
  162. "dwFindModemPortUsage: lrCheckValue "
  163. "failed for RouterEnabled. %d",
  164. lr );
  165. lr = ERROR_SUCCESS;
  166. }
  167. if(!*pfRouterEnabled)
  168. {
  169. TracePrintfExA(
  170. dwTraceId,
  171. TRACESETTINGS,
  172. "dwFindModemPortUsage: Modem "
  173. "is not enabled for Routing");
  174. }
  175. done:
  176. if(hkeyRas)
  177. {
  178. RegCloseKey(hkeyRas);
  179. }
  180. return (DWORD) lr;
  181. }
  182. DWORD
  183. dwGetPortUsage(DWORD *pdwUsage)
  184. {
  185. HKEY hkey = NULL;
  186. DWORD dwRetCode = ERROR_SUCCESS;
  187. static const TCHAR c_szRemoteAccess[] =
  188. TEXT("System\\CurrentControlSet\\Services\\RemoteAccess");
  189. TracePrintfExA(dwTraceId, TRACESETTINGS,
  190. "dwGetPorTUsage:...");
  191. if(0 == g_dwRasComponent)
  192. {
  193. // Check to see if Ras Server is installed
  194. //
  195. g_dwRasComponent = RNETCFG_RASCLI;
  196. if (RegOpenKeyEx(
  197. HKEY_LOCAL_MACHINE,
  198. c_szRemoteAccess,
  199. 0, KEY_QUERY_VALUE,
  200. &hkey))
  201. {
  202. TracePrintfExA(
  203. dwTraceId, TRACESETTINGS,
  204. "dwAssignDefaultPortUsage: RemoteAccess not installed");
  205. }
  206. else
  207. {
  208. g_dwRasComponent = RNETCFG_RASSRV;
  209. }
  210. }
  211. *pdwUsage = CALL_OUT;
  212. *pdwUsage |= ((g_dwRasComponent & RNETCFG_RASSRV) ?
  213. (CALL_IN | CALL_ROUTER) : 0);
  214. return dwRetCode;
  215. }
  216. DWORD
  217. dwGetNumberOfRings (PDWORD pdwRings)
  218. {
  219. LONG lr = ERROR_SUCCESS;
  220. HKEY hkey = NULL;
  221. DWORD dwsize = sizeof(DWORD);
  222. DWORD dwtype;
  223. TCHAR c_szRasmanParam[] =
  224. TEXT("SYSTEM\\CurrentControlSet\\Services\\Rasman\\Parameters");
  225. if(lr = RegOpenKeyEx(
  226. HKEY_LOCAL_MACHINE,
  227. c_szRasmanParam,
  228. 0, KEY_READ,
  229. &hkey))
  230. {
  231. TracePrintfExA(
  232. dwTraceId, TRACESETTINGS,
  233. "dwGetNumberOfRings: failed to open rasman key in registry. 0x%x",
  234. lr);
  235. goto done;
  236. }
  237. if(lr = RegQueryValueEx(
  238. hkey,
  239. TEXT("NumberOfRings"),
  240. 0, &dwtype,
  241. (PBYTE) pdwRings,
  242. &dwsize))
  243. {
  244. *pdwRings = 1;
  245. }
  246. if ( *pdwRings < 1
  247. || *pdwRings > 20)
  248. {
  249. *pdwRings = 1;
  250. }
  251. done:
  252. if(hkey)
  253. {
  254. RegCloseKey(hkey);
  255. }
  256. TracePrintfExA(
  257. dwTraceId, TRACESETTINGS,
  258. "dwGetNumberOfRings: dwRings=%d. lr=0x%x",
  259. *pdwRings, lr);
  260. return (DWORD) lr;
  261. }