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.

634 lines
18 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: R A S A F . C P P
  7. //
  8. // Contents: RAS Answer File objects.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 19 Apr 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "ncipaddr.h"
  18. #include "ncmisc.h"
  19. #include "ncreg.h"
  20. #include "ncsetup.h"
  21. #include "rasaf.h"
  22. #include "rasobj.h"
  23. extern const WCHAR c_szAfAppleTalk[];
  24. extern const WCHAR c_szAfAutoNetworkNumbers[];
  25. extern const WCHAR c_szAfClientCanReqIpaddr[];
  26. extern const WCHAR c_szAfClientReqNodeNumber[];
  27. extern const WCHAR c_szAfDialinProtocols[];
  28. extern const WCHAR c_szAfForceEncryptedData[];
  29. extern const WCHAR c_szAfForceStrongEncryption[];
  30. extern const WCHAR c_szAfForceEncryptedPassword[];
  31. extern const WCHAR c_szAfWanNetPoolSize[];
  32. extern const WCHAR c_szAfIpAddressStart[];
  33. extern const WCHAR c_szAfIpAddressEnd[];
  34. extern const WCHAR c_szAfIpxClientAccess[];
  35. extern const WCHAR c_szAfIpx[];
  36. extern const WCHAR c_szAfL2tpMaxVcs[];
  37. extern const WCHAR c_szAfL2tpEndpoints[];
  38. extern const WCHAR c_szAfMultilink[];
  39. extern const WCHAR c_szAfNetNumberFrom[];
  40. extern const WCHAR c_szAfNetbeuiClientAccess[];
  41. extern const WCHAR c_szAfNetbeui[];
  42. extern const WCHAR c_szAfNetwork[];
  43. extern const WCHAR c_szAfParamsSection[];
  44. extern const WCHAR c_szAfPptpEndpoints[];
  45. extern const WCHAR c_szAfRouterType[];
  46. extern const WCHAR c_szAfSecureVPN[];
  47. extern const WCHAR c_szAfSetDialinUsage[];
  48. extern const WCHAR c_szAfSameNetworkNumber[];
  49. extern const WCHAR c_szAfTcpipClientAccess[];
  50. extern const WCHAR c_szAfTcpip[];
  51. extern const WCHAR c_szAfThisComputer[];
  52. extern const WCHAR c_szAfUseDhcp[];
  53. extern const WCHAR c_szInfId_MS_L2tpMiniport[];
  54. extern const WCHAR c_szInfId_MS_PptpMiniport[];
  55. extern const WCHAR c_szInfId_MS_PppoeMiniport[];
  56. //+---------------------------------------------------------------------------
  57. // CRasSrvAnswerFileData
  58. //
  59. HRESULT
  60. CRasSrvAnswerFileData::HrOpenAndRead (
  61. PCWSTR pszAnswerFile,
  62. PCWSTR pszAnswerSection)
  63. {
  64. // Open the answer file. It will close itself in it's destructor.
  65. CSetupInfFile inf;
  66. UINT unErrorLine;
  67. HRESULT hr = inf.HrOpen (
  68. pszAnswerFile, NULL,
  69. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  70. &unErrorLine);
  71. if (SUCCEEDED(hr))
  72. {
  73. m_fRouterTypeSpecified = FALSE;
  74. m_fSetUsageToDialin = FALSE;
  75. // Prepare the default values for use when we fail to read.
  76. // Initializing with defaults also helps to gaurantee that bogus
  77. // values aren't used when we add items to the structure but fail
  78. // to provide answer file support for them.
  79. //
  80. m_dataSrvCfg.GetDefault ();
  81. m_dataSrvIp .GetDefault ();
  82. m_dataSrvIpx.GetDefault ();
  83. m_dataSrvNbf.GetDefault ();
  84. DATA_SRV_CFG defSrvCfg = m_dataSrvCfg;
  85. DATA_SRV_IP defSrvIp = m_dataSrvIp;
  86. DATA_SRV_IPX defSrvIpx = m_dataSrvIpx;
  87. DATA_SRV_NBF defSrvNbf = m_dataSrvNbf;
  88. // Get the real parameter section.
  89. //
  90. tstring strSection;
  91. hr = inf.HrGetString (pszAnswerSection,
  92. c_szAfParamsSection, &strSection);
  93. if (FAILED(hr))
  94. {
  95. // If we failed to find the parameter section, just try
  96. // this one.
  97. //
  98. strSection = pszAnswerSection;
  99. }
  100. static const MAP_SZ_DWORD c_mapProtocols [] =
  101. {
  102. { c_szAfTcpip, RPI_IP },
  103. { c_szAfIpx, RPI_IPX },
  104. { c_szAfNetbeui, RPI_NBF },
  105. { c_szAfAppleTalk, RPI_ATALK },
  106. };
  107. // Read the list of dial-in protocols.
  108. //
  109. hr = inf.HrGetMultiSzMapToDword (strSection.c_str(),
  110. c_szAfDialinProtocols,
  111. c_mapProtocols,
  112. celems (c_mapProtocols),
  113. &m_dwDialInProtocolIds);
  114. if (FAILED(hr) || !m_dwDialInProtocolIds)
  115. {
  116. // If its not there, use all possible.
  117. m_dwDialInProtocolIds = RPI_ALL;
  118. }
  119. hr = inf.HrGetStringAsBool (strSection.c_str(),
  120. c_szAfMultilink,
  121. &m_dataSrvCfg.fMultilink);
  122. if (FAILED(hr))
  123. {
  124. m_dataSrvCfg.fMultilink = defSrvCfg.fMultilink;
  125. }
  126. hr = inf.HrGetDword(strSection.c_str(),
  127. c_szAfRouterType,
  128. (DWORD*)&m_dataSrvCfg.dwRouterType);
  129. if (FAILED(hr))
  130. {
  131. m_dataSrvCfg.dwRouterType = defSrvCfg.dwRouterType;
  132. }
  133. else
  134. {
  135. m_fRouterTypeSpecified = TRUE;
  136. }
  137. hr = inf.HrGetDword (strSection.c_str(),
  138. c_szAfForceEncryptedPassword,
  139. &m_dataSrvCfg.dwAuthLevel);
  140. if (FAILED(hr))
  141. {
  142. m_dataSrvCfg.dwAuthLevel = defSrvCfg.dwAuthLevel;
  143. }
  144. hr = inf.HrGetStringAsBool (strSection.c_str(),
  145. c_szAfForceEncryptedData,
  146. &m_dataSrvCfg.fDataEnc);
  147. if (FAILED(hr))
  148. {
  149. m_dataSrvCfg.fDataEnc = defSrvCfg.fDataEnc;
  150. }
  151. hr = inf.HrGetStringAsBool (strSection.c_str(),
  152. c_szAfForceStrongEncryption,
  153. &m_dataSrvCfg.fStrongDataEnc);
  154. if (FAILED(hr))
  155. {
  156. m_dataSrvCfg.fStrongDataEnc = defSrvCfg.fStrongDataEnc;
  157. }
  158. hr = inf.HrGetDword (strSection.c_str(),
  159. c_szAfSecureVPN,
  160. &m_dataSrvCfg.dwSecureVPN);
  161. if (FAILED(hr))
  162. {
  163. m_dataSrvCfg.dwSecureVPN = defSrvCfg.dwSecureVPN;
  164. }
  165. // pmay: 251736
  166. // Discover whether we are to set all port usage to 'dialin'
  167. //
  168. DWORD dwSetUsageToDialin;
  169. hr = inf.HrGetDword(strSection.c_str(),
  170. c_szAfSetDialinUsage,
  171. &dwSetUsageToDialin);
  172. if (SUCCEEDED(hr))
  173. {
  174. m_fSetUsageToDialin = !!dwSetUsageToDialin;
  175. }
  176. static const MAP_SZ_DWORD c_mapNetworkAccess [] =
  177. {
  178. { c_szAfNetwork, TRUE },
  179. { c_szAfThisComputer, FALSE },
  180. };
  181. // Read the IP values.
  182. //
  183. m_dataSrvIp.fEnableIn =
  184. (m_dwDialInProtocolIds & RPI_IP) ? TRUE : FALSE;
  185. hr = inf.HrGetStringMapToDword (strSection.c_str(),
  186. c_szAfTcpipClientAccess,
  187. c_mapNetworkAccess,
  188. celems (c_mapNetworkAccess),
  189. (DWORD*)&m_dataSrvIp.fAllowNetworkAccess);
  190. if (FAILED(hr))
  191. {
  192. m_dataSrvIp.fAllowNetworkAccess = defSrvIp.fAllowNetworkAccess;
  193. }
  194. hr = inf.HrGetStringAsBool (strSection.c_str(),
  195. c_szAfUseDhcp,
  196. &m_dataSrvIp.fUseDhcp);
  197. if (FAILED(hr))
  198. {
  199. m_dataSrvIp.fUseDhcp = defSrvIp.fUseDhcp;
  200. }
  201. hr = inf.HrGetStringAsBool (strSection.c_str(),
  202. c_szAfClientCanReqIpaddr,
  203. &m_dataSrvIp.fAllowClientAddr);
  204. if (FAILED(hr))
  205. {
  206. m_dataSrvIp.fAllowClientAddr = defSrvIp.fAllowClientAddr;
  207. }
  208. tstring strIpAddress;
  209. hr = inf.HrGetString (strSection.c_str(),
  210. c_szAfIpAddressStart,
  211. &strIpAddress);
  212. if (SUCCEEDED(hr))
  213. {
  214. m_dataSrvIp.dwIpStart = IpPszToHostAddr(strIpAddress.c_str());
  215. }
  216. else
  217. {
  218. m_dataSrvIp.dwIpStart = defSrvIp.dwIpStart;
  219. }
  220. hr = inf.HrGetString (strSection.c_str(),
  221. c_szAfIpAddressEnd,
  222. &strIpAddress);
  223. if (SUCCEEDED(hr))
  224. {
  225. m_dataSrvIp.dwIpEnd = IpPszToHostAddr(strIpAddress.c_str());
  226. }
  227. else
  228. {
  229. m_dataSrvIp.dwIpEnd = defSrvIp.dwIpEnd;
  230. }
  231. // Read the IPX values.
  232. //
  233. m_dataSrvIpx.fEnableIn =
  234. (m_dwDialInProtocolIds & RPI_IPX) ? TRUE : FALSE;
  235. hr = inf.HrGetStringMapToDword (strSection.c_str(),
  236. c_szAfIpxClientAccess,
  237. c_mapNetworkAccess,
  238. celems (c_mapNetworkAccess),
  239. (DWORD*)&m_dataSrvIpx.fAllowNetworkAccess);
  240. if (FAILED(hr))
  241. {
  242. m_dataSrvIpx.fAllowNetworkAccess = defSrvIpx.fAllowNetworkAccess;
  243. }
  244. hr = inf.HrGetStringAsBool (strSection.c_str(),
  245. c_szAfAutoNetworkNumbers,
  246. &m_dataSrvIpx.fUseAutoAddr);
  247. if (FAILED(hr))
  248. {
  249. m_dataSrvIpx.fUseAutoAddr = defSrvIpx.fUseAutoAddr;
  250. }
  251. hr = inf.HrGetStringAsBool (strSection.c_str(),
  252. c_szAfSameNetworkNumber,
  253. &m_dataSrvIpx.fUseSameNetNum);
  254. if (FAILED(hr))
  255. {
  256. m_dataSrvIpx.fUseSameNetNum = defSrvIpx.fUseSameNetNum;
  257. }
  258. hr = inf.HrGetStringAsBool (strSection.c_str(),
  259. c_szAfClientReqNodeNumber,
  260. &m_dataSrvIpx.fAllowClientNetNum);
  261. if (FAILED(hr))
  262. {
  263. m_dataSrvIpx.fAllowClientNetNum = defSrvIpx.fAllowClientNetNum;
  264. }
  265. hr = inf.HrGetDword (strSection.c_str(),
  266. c_szAfNetNumberFrom,
  267. &m_dataSrvIpx.dwIpxNetFirst);
  268. if (FAILED(hr))
  269. {
  270. m_dataSrvIpx.dwIpxNetFirst = defSrvIpx.dwIpxNetFirst;
  271. }
  272. hr = inf.HrGetDword (strSection.c_str(),
  273. c_szAfWanNetPoolSize,
  274. &m_dataSrvIpx.dwIpxWanPoolSize);
  275. if (FAILED(hr))
  276. {
  277. m_dataSrvIpx.dwIpxWanPoolSize = defSrvIpx.dwIpxWanPoolSize;
  278. }
  279. // Read the NBF values.
  280. //
  281. m_dataSrvNbf.fEnableIn =
  282. (m_dwDialInProtocolIds & RPI_NBF) ? TRUE : FALSE;
  283. hr = inf.HrGetStringMapToDword (strSection.c_str(),
  284. c_szAfNetbeuiClientAccess,
  285. c_mapNetworkAccess,
  286. celems (c_mapNetworkAccess),
  287. (DWORD*)&m_dataSrvNbf.fAllowNetworkAccess);
  288. if (FAILED(hr))
  289. {
  290. m_dataSrvNbf.fAllowNetworkAccess = defSrvNbf.fAllowNetworkAccess;
  291. }
  292. // Default anything bogus.
  293. //
  294. m_dataSrvCfg.CheckAndDefault ();
  295. m_dataSrvIp .CheckAndDefault ();
  296. m_dataSrvIpx.CheckAndDefault ();
  297. m_dataSrvNbf.CheckAndDefault ();
  298. hr = S_OK;
  299. }
  300. TraceError ("CRasSrvAnswerFileData::HrOpenAndRead", hr);
  301. return hr;
  302. }
  303. VOID
  304. CRasSrvAnswerFileData::SaveToRegistry (
  305. VOID) const
  306. {
  307. m_dataSrvCfg.SaveToReg();
  308. m_dataSrvIp .SaveToReg();
  309. m_dataSrvIpx.SaveToReg();
  310. m_dataSrvNbf.SaveToReg();
  311. }
  312. //+---------------------------------------------------------------------------
  313. // CL2tpAnswerFileData
  314. //
  315. const DWORD c_MaxMaxVcs = 1000;
  316. const DWORD c_DefMaxVcs = 1000;
  317. const DWORD c_MaxEndpoints = 1000;
  318. const DWORD c_DefEndpoints = 5;
  319. VOID
  320. CL2tpAnswerFileData::CheckAndDefault ()
  321. {
  322. if (m_cMaxVcs > c_MaxMaxVcs)
  323. {
  324. m_cMaxVcs = c_DefMaxVcs;
  325. }
  326. if (m_cEndpoints > c_MaxEndpoints)
  327. {
  328. m_cEndpoints = c_DefEndpoints;
  329. }
  330. }
  331. HRESULT
  332. CL2tpAnswerFileData::HrOpenAndRead (
  333. PCWSTR pszAnswerFile,
  334. PCWSTR pszAnswerSection)
  335. {
  336. ZeroMemory (this, sizeof(*this));
  337. // Open the answer file. It will close itself in it's destructor.
  338. CSetupInfFile inf;
  339. UINT unErrorLine;
  340. HRESULT hr = inf.HrOpen (
  341. pszAnswerFile, NULL,
  342. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  343. &unErrorLine);
  344. if (SUCCEEDED(hr))
  345. {
  346. // Read the number of VPNs.
  347. //
  348. hr = inf.HrGetDword (pszAnswerSection,
  349. c_szAfL2tpMaxVcs,
  350. &m_cMaxVcs);
  351. if (FAILED(hr))
  352. {
  353. m_cMaxVcs = c_DefMaxVcs;
  354. }
  355. hr = inf.HrGetDword (pszAnswerSection,
  356. c_szAfL2tpEndpoints,
  357. &m_cEndpoints);
  358. if (FAILED(hr))
  359. {
  360. m_cEndpoints = c_DefEndpoints;
  361. m_fWriteEndpoints = FALSE;
  362. }
  363. else
  364. {
  365. m_fWriteEndpoints = TRUE;
  366. }
  367. // Default anything bogus.
  368. //
  369. CheckAndDefault ();
  370. hr = S_OK;
  371. }
  372. TraceError ("CL2tpAnswerFileData::HrOpenAndRead", hr);
  373. return hr;
  374. }
  375. VOID
  376. CL2tpAnswerFileData::SaveToRegistry (
  377. INetCfg* pnc) const
  378. {
  379. Assert (pnc);
  380. HKEY hkey;
  381. HRESULT hr;
  382. // Update the L2TP miniport's parameter key.
  383. //
  384. hr = HrOpenComponentParamKey (
  385. pnc,
  386. GUID_DEVCLASS_NET,
  387. c_szInfId_MS_L2tpMiniport,
  388. &hkey);
  389. if (S_OK == hr)
  390. {
  391. (VOID) HrRegSetDword (hkey, L"MaxVcs", m_cMaxVcs);
  392. if (m_fWriteEndpoints)
  393. {
  394. (VOID) HrRegSetDword (hkey, L"WanEndpoints", m_cEndpoints);
  395. }
  396. RegCloseKey (hkey);
  397. }
  398. }
  399. //+---------------------------------------------------------------------------
  400. // CPptpAnswerFileData
  401. //
  402. // Minimum and maximum number of Virtual Private Networks
  403. // allowed by PPTP.
  404. const DWORD c_cPptpVpnsMin = 0;
  405. const DWORD c_cPptpVpnsMax = 1000;
  406. static const DWORD c_cDefPptpVpnsWorkstation = 2;
  407. static const DWORD c_cDefPptpVpnsServer = 5;
  408. DWORD
  409. CPptpAnswerFileData::GetDefaultNumberOfVpns ()
  410. {
  411. PRODUCT_FLAVOR pf;
  412. GetProductFlavor(NULL, &pf);
  413. DWORD cVpns;
  414. // On the server product, default to 5 VPNs, otherwise, default to 2 VPNs.
  415. //
  416. if (PF_SERVER == pf)
  417. {
  418. cVpns = c_cDefPptpVpnsServer;
  419. }
  420. else
  421. {
  422. cVpns = c_cDefPptpVpnsWorkstation;
  423. }
  424. return cVpns;
  425. }
  426. #pragma warning(push)
  427. #pragma warning(disable:4296)
  428. VOID
  429. CPptpAnswerFileData::CheckAndDefault ()
  430. {
  431. if ((m_cVpns < c_cPptpVpnsMin) || (m_cVpns > c_cPptpVpnsMax))
  432. {
  433. m_cVpns = GetDefaultNumberOfVpns ();
  434. }
  435. }
  436. #pragma warning(pop)
  437. HRESULT
  438. CPptpAnswerFileData::HrOpenAndRead (
  439. PCWSTR pszAnswerFile,
  440. PCWSTR pszAnswerSection)
  441. {
  442. ZeroMemory (this, sizeof(*this));
  443. // Open the answer file. It will close itself in it's destructor.
  444. CSetupInfFile inf;
  445. UINT unErrorLine;
  446. HRESULT hr = inf.HrOpen (
  447. pszAnswerFile, NULL,
  448. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  449. &unErrorLine);
  450. if (SUCCEEDED(hr))
  451. {
  452. // Read the number of VPNs.
  453. //
  454. hr = inf.HrGetDword (pszAnswerSection,
  455. c_szAfPptpEndpoints,
  456. &m_cVpns);
  457. if (FAILED(hr))
  458. {
  459. m_cVpns = GetDefaultNumberOfVpns ();
  460. }
  461. // Default anything bogus.
  462. //
  463. CheckAndDefault ();
  464. hr = S_OK;
  465. }
  466. TraceError ("CPptpAnswerFileData::HrOpenAndRead", hr);
  467. return hr;
  468. }
  469. VOID
  470. CPptpAnswerFileData::SaveToRegistry (
  471. INetCfg* pnc) const
  472. {
  473. Assert (pnc);
  474. HKEY hkey;
  475. HRESULT hr;
  476. // Update the PPTP miniport's parameter key.
  477. //
  478. hr = HrOpenComponentParamKey (
  479. pnc,
  480. GUID_DEVCLASS_NET,
  481. c_szInfId_MS_PptpMiniport,
  482. &hkey);
  483. if (S_OK == hr)
  484. {
  485. (VOID) HrRegSetDword (hkey, L"WanEndpoints", m_cVpns);
  486. RegCloseKey (hkey);
  487. }
  488. }
  489. VOID
  490. CPppoeAnswerFileData::CheckAndDefault ()
  491. {
  492. m_cVpns = 1;
  493. }
  494. HRESULT
  495. CPppoeAnswerFileData::HrOpenAndRead (
  496. PCWSTR pszAnswerFile,
  497. PCWSTR pszAnswerSection)
  498. {
  499. ZeroMemory (this, sizeof(*this));
  500. // Open the answer file. It will close itself in it's destructor.
  501. CSetupInfFile inf;
  502. UINT unErrorLine;
  503. HRESULT hr = inf.HrOpen (
  504. pszAnswerFile, NULL,
  505. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  506. &unErrorLine);
  507. if (SUCCEEDED(hr))
  508. {
  509. // Read the number of VPNs.
  510. //
  511. hr = inf.HrGetDword (pszAnswerSection,
  512. c_szAfL2tpEndpoints,
  513. &m_cVpns);
  514. if (FAILED(hr))
  515. {
  516. m_cVpns = 1;
  517. }
  518. // Default anything bogus.
  519. //
  520. CheckAndDefault ();
  521. hr = S_OK;
  522. }
  523. TraceError ("CPppoeAnswerFileData::HrOpenAndRead", hr);
  524. return hr;
  525. }
  526. VOID
  527. CPppoeAnswerFileData::SaveToRegistry (
  528. INetCfg* pnc) const
  529. {
  530. Assert (pnc);
  531. HKEY hkey;
  532. HRESULT hr;
  533. // Update the PPTP miniport's parameter key.
  534. //
  535. hr = HrOpenComponentParamKey (
  536. pnc,
  537. GUID_DEVCLASS_NET,
  538. c_szInfId_MS_PppoeMiniport,
  539. &hkey);
  540. if (S_OK == hr)
  541. {
  542. (VOID) HrRegSetDword (hkey, L"WanEndpoints", m_cVpns);
  543. RegCloseKey (hkey);
  544. }
  545. }