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.

1025 lines
39 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: T C P A F . C P P
  7. //
  8. // Contents: TCP/IP answer file processing
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "tcpipobj.h"
  18. #include "ncsetup.h"
  19. #include "tcpconst.h"
  20. #include "tcperror.h"
  21. #include "tcputil.h"
  22. #include "ncreg.h"
  23. #include "ncperms.h"
  24. #include "afilestr.h"
  25. #include "ipafval.h"
  26. extern const WCHAR c_szAdapterSections[];
  27. BOOL FValidateIpFieldsFromAnswerFile(VSTR & vstrIpAddr, PCWSTR pszValueName,
  28. PCWSTR szAdapterName, BOOL fIsIpAddr = TRUE);
  29. BOOL FValidateAdapterParametersFromAnswerFile(ADAPTER_INFO* pAdapter,
  30. PCWSTR pszAdapterName);
  31. BOOL FValidateGlobalParametersFromAnswerFile(GLOBAL_INFO* pGlobalInfo);
  32. HRESULT HrLoadUnConfigurableParamFromAnswerFile(HINF hinf,
  33. PCWSTR pszSection,
  34. const ValueTypePair * prgVtpParams,
  35. UINT cParams,
  36. HKEY hkeyParam);
  37. HRESULT CTcpipcfg::HrProcessAnswerFile(PCWSTR pszAnswerFile,
  38. PCWSTR pszAnswerSection)
  39. {
  40. HRESULT hr = S_OK;
  41. HRESULT hrTmp = S_OK;
  42. CSetupInfFile caf; // Class to process answer file
  43. AssertSz(pszAnswerFile, "Answer file string is NULL!");
  44. AssertSz(pszAnswerSection, "Answer file sections string is NULL!");
  45. // Open the answer file.
  46. hr = caf.HrOpen(pszAnswerFile, NULL, INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL);
  47. if (SUCCEEDED(hr))
  48. {
  49. hrTmp = HrLoadGlobalParamFromAnswerFile(caf.Hinf(), pszAnswerSection);
  50. if (SUCCEEDED(hr))
  51. hr = hrTmp;
  52. // Get the adapter specific Tcpip and NetBT parameters
  53. WCHAR * mszAdapterList;
  54. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(caf.Hinf(),
  55. pszAnswerSection,
  56. c_szAdapterSections,
  57. &mszAdapterList);
  58. if (SUCCEEDED(hrTmp) && NULL != mszAdapterList)
  59. {
  60. hrTmp = HrLoadAdapterParameterFromAnswerFile(caf.Hinf(),
  61. mszAdapterList);
  62. delete [] mszAdapterList;
  63. }
  64. if (SUCCEEDED(hr))
  65. hr = hrTmp;
  66. caf.Close();
  67. }
  68. TraceErrorOptional("CTcpipcfg::HrProcessAnswerFile", hr,
  69. SPAPI_E_LINE_NOT_FOUND == hr);
  70. // Mask the errors since we will be using the defaults
  71. if FAILED(hr)
  72. hr = S_OK;
  73. return hr;
  74. }
  75. // Load Global parameters from answerfile to memory structure
  76. HRESULT CTcpipcfg::HrLoadGlobalParamFromAnswerFile(HINF hinf,
  77. PCWSTR pszTcpipMainSection)
  78. {
  79. HRESULT hr = S_OK;
  80. HRESULT hrTmp;
  81. BOOL fTmp;
  82. DWORD dwTmp;
  83. hr = m_glbGlobalInfo.HrSetDefaults();
  84. if SUCCEEDED(hr)
  85. {
  86. // $REVIEW(tongl 3/22/98): per Stuart Kwan, I'm reading global
  87. // DNS server list just for the upgrade case
  88. // DNSDomain -> m_strDnsDomain
  89. tstring strDnsDomain;
  90. hrTmp = HrSetupGetFirstString( hinf,
  91. pszTcpipMainSection,
  92. c_szAfDnsDomain,
  93. &strDnsDomain);
  94. if SUCCEEDED(hrTmp)
  95. {
  96. m_fUpgradeGlobalDnsDomain = TRUE;
  97. if (!strDnsDomain.empty())
  98. {
  99. DNS_STATUS status;
  100. status = DnsValidateName(strDnsDomain.c_str(), DnsNameDomain);
  101. //validate the global dns domain name
  102. if (ERROR_INVALID_NAME == status ||
  103. DNS_ERROR_INVALID_NAME_CHAR == status)
  104. {
  105. WriteTcpSetupErrorLog(IDS_TCP_AF_INVALID_GLOBAL_DNS_DOMAIN, strDnsDomain.c_str());
  106. m_fUpgradeGlobalDnsDomain = FALSE;
  107. }
  108. }
  109. if (m_fUpgradeGlobalDnsDomain)
  110. m_strUpgradeGlobalDnsDomain = strDnsDomain;
  111. }
  112. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  113. hrTmp = S_OK;
  114. else
  115. TraceError("HrLoadGlobalParameterFromAnswerFile: DNSDomain", hrTmp);
  116. if (SUCCEEDED(hr))
  117. hr = hrTmp;
  118. // DNSHostName -> m_strHostNameFromAnswerFile
  119. hrTmp = HrSetupGetFirstString(hinf,
  120. pszTcpipMainSection,
  121. c_szAfDnsHostname,
  122. &m_glbGlobalInfo.m_strHostNameFromAnswerFile);
  123. if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  124. hrTmp = S_OK;
  125. else
  126. TraceError("HrLoadGlobalParamFromAnswerFile: DNSHostName", hrTmp);
  127. if (SUCCEEDED(hr))
  128. hr = hrTmp;
  129. // DNSSuffixSearchOrder -> m_strSearchList
  130. WCHAR * mszSearchList;
  131. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc( hinf,
  132. pszTcpipMainSection,
  133. c_szAfDnsSuffixSearchOrder,
  134. &mszSearchList);
  135. if SUCCEEDED(hrTmp)
  136. {
  137. MultiSzToColString( mszSearchList,
  138. &m_glbGlobalInfo.m_vstrDnsSuffixList);
  139. delete [] mszSearchList;
  140. }
  141. if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  142. hrTmp = S_OK;
  143. else
  144. TraceError("HrLoadGlobalParamFromAnswerFile: DNSSuffixSearchOrder", hrTmp);
  145. if (SUCCEEDED(hr))
  146. hr = hrTmp;
  147. // EnableLMHosts -> m_fEnableLmHosts
  148. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszTcpipMainSection,
  149. c_szAfEnableLmhosts,
  150. &fTmp);
  151. if SUCCEEDED(hrTmp)
  152. m_glbGlobalInfo.m_fEnableLmHosts = fTmp;
  153. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  154. hrTmp = S_OK;
  155. else
  156. TraceError("HrLoadGlobalParamFromAnswerFile: EnableLMHosts", hrTmp);
  157. if (SUCCEEDED(hr))
  158. hr = hrTmp;
  159. // Per AmritanR, drop the upgrade support of IpEnableRouter to fix bug 345700
  160. // EnableIPForwarding -> m_fEnableRouter (BOOL)
  161. //(nsun 11/03/98) parameters for RRAS during unattended install
  162. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszTcpipMainSection,
  163. c_szAfEnableICMPRedirect,
  164. &fTmp);
  165. if SUCCEEDED(hrTmp)
  166. m_glbGlobalInfo.m_fEnableIcmpRedirect = fTmp;
  167. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  168. hrTmp = S_OK;
  169. else
  170. TraceError("HrLoadGlobalParamFromAnswerFile: EnableICMPRedirect", hrTmp);
  171. if (SUCCEEDED(hr))
  172. hr = hrTmp;
  173. //(nsun 09/20/99) PerformRouterDiscoveryDefault was removed to fix bug 405636
  174. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszTcpipMainSection,
  175. c_szAfDeadGWDetectDefault,
  176. &fTmp);
  177. if SUCCEEDED(hrTmp)
  178. m_glbGlobalInfo.m_fDeadGWDetectDefault = fTmp;
  179. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  180. hrTmp = S_OK;
  181. else
  182. TraceError("HrLoadGlobalParamFromAnswerFile: DeadGWDetectDefault", hrTmp);
  183. if (SUCCEEDED(hr))
  184. hr = hrTmp;
  185. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszTcpipMainSection,
  186. c_szAfDontAddDefaultGatewayDefault,
  187. &fTmp);
  188. if SUCCEEDED(hrTmp)
  189. m_glbGlobalInfo.m_fDontAddDefaultGatewayDefault = fTmp;
  190. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  191. hrTmp = S_OK;
  192. else
  193. TraceError("HrLoadGlobalParamFromAnswerFile: DontAddDefaultGatewayDefault", hrTmp);
  194. if (SUCCEEDED(hr))
  195. hr = hrTmp;
  196. // EnableSecurity -> m_fEnableFiltering
  197. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszTcpipMainSection,
  198. c_szAfEnableSecurity,
  199. &fTmp);
  200. if SUCCEEDED(hrTmp)
  201. m_glbGlobalInfo.m_fEnableFiltering = fTmp;
  202. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  203. hrTmp = S_OK;
  204. else
  205. TraceError("HrLoadGlobalParamFromAnswerFile: EnableSecurity", hrTmp);
  206. if (SUCCEEDED(hr))
  207. hr = hrTmp;
  208. // 8/10/98 nsun: added to support UseDomainNameDevolution value in unattended install
  209. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszTcpipMainSection,
  210. c_szAfUseDomainNameDevolution,
  211. &fTmp);
  212. if SUCCEEDED(hrTmp)
  213. m_glbGlobalInfo.m_fUseDomainNameDevolution = fTmp;
  214. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  215. hrTmp = S_OK;
  216. else
  217. TraceError("HrLoadGlobalParamFromAnswerFile: UseDomainNameDevolution", hrTmp);
  218. if (SUCCEEDED(hr))
  219. hr = hrTmp;
  220. //$REVIEW (nsun 12/11/98) directly save the unconfigurable parameters
  221. // right after reading it from the answer file.
  222. HKEY hkeyTcpipParam = NULL;
  223. Assert(m_pnccTcpip);
  224. if(m_pnccTcpip)
  225. {
  226. hrTmp = m_pnccTcpip->OpenParamKey(&hkeyTcpipParam);
  227. if (SUCCEEDED(hrTmp))
  228. {
  229. Assert(hkeyTcpipParam);
  230. hrTmp = HrLoadUnConfigurableParamFromAnswerFile(hinf,
  231. pszTcpipMainSection,
  232. rgVtpIp,
  233. sizeof(rgVtpIp)/sizeof(rgVtpIp[0]),
  234. hkeyTcpipParam);
  235. RegSafeCloseKey(hkeyTcpipParam);
  236. }
  237. if (SUCCEEDED(hr))
  238. hr = hrTmp;
  239. }
  240. HKEY hkeyWinsParam = NULL;
  241. Assert(m_pnccWins);
  242. if(m_pnccWins)
  243. {
  244. hrTmp = m_pnccWins->OpenParamKey(&hkeyWinsParam);
  245. if (SUCCEEDED(hrTmp))
  246. {
  247. Assert(hkeyWinsParam);
  248. hrTmp = HrLoadUnConfigurableParamFromAnswerFile(hinf,
  249. pszTcpipMainSection,
  250. rgVtpNetBt,
  251. sizeof(rgVtpNetBt)/sizeof(rgVtpNetBt[0]),
  252. hkeyWinsParam);
  253. RegSafeCloseKey(hkeyWinsParam);
  254. }
  255. if (SUCCEEDED(hr))
  256. hr = hrTmp;
  257. }
  258. if (!FValidateGlobalParametersFromAnswerFile(&m_glbGlobalInfo))
  259. {
  260. TraceError("FValidateGlobalParametersFromAnswerFile() got invalid tcp settings", E_FAIL);
  261. }
  262. }
  263. TraceError("CTcpipcfg::HrLoadGlobalParamFromAnswerFile", hr);
  264. return hr;
  265. }
  266. // Load adapter specific parameters from answerfile to memory structure
  267. HRESULT CTcpipcfg::HrLoadAdapterParameterFromAnswerFile(HINF hinf,
  268. PCWSTR mszTcpipAdapterSections)
  269. {
  270. HRESULT hr = S_OK;
  271. HRESULT hrTmp = S_OK;
  272. HRESULT hrReg = S_OK;
  273. PCWSTR pszAdapterSection = mszTcpipAdapterSections;
  274. tstring strAdapterName;
  275. tstring strInterfaceRegPath;
  276. //$REVIEW (nsun 12/11/98) bug #204145
  277. //directly save the unconfigurable parameters right after reading
  278. //it from the answer file.
  279. HKEY hkeyTcpipParam = NULL;
  280. hrReg = m_pnccTcpip->OpenParamKey(&hkeyTcpipParam);
  281. hr = hrReg;
  282. while (*pszAdapterSection)
  283. {
  284. // Get the card name "SpecificTo = ..."
  285. hrTmp = HrSetupGetFirstString(hinf, pszAdapterSection,
  286. c_szAfSpecificTo, &strAdapterName);
  287. if (SUCCEEDED(hrTmp))
  288. {
  289. GUID guidNetCard;
  290. if (!FGetInstanceGuidOfComponentInAnswerFile(
  291. strAdapterName.c_str(),
  292. m_pnc,
  293. &guidNetCard))
  294. {
  295. TraceTag(ttidError, "FGetInstanceGuidOfComponentInAnswerFile failed to match GUID for adapter %S", strAdapterName.c_str());
  296. // Move to the next card
  297. pszAdapterSection += lstrlenW(pszAdapterSection) + 1;
  298. continue;
  299. }
  300. // Do we already have this adapter in our list ?
  301. ADAPTER_INFO * pAdapterInfo = PAdapterFromInstanceGuid(&guidNetCard);
  302. if (!pAdapterInfo)
  303. {
  304. pAdapterInfo = new ADAPTER_INFO;
  305. if (NULL == pAdapterInfo)
  306. {
  307. hr = E_OUTOFMEMORY;
  308. continue;
  309. }
  310. hrTmp = pAdapterInfo->HrSetDefaults(&guidNetCard, c_szEmpty,
  311. c_szEmpty, c_szEmpty);
  312. if (SUCCEEDED(hrTmp))
  313. {
  314. m_vcardAdapterInfo.push_back(pAdapterInfo);
  315. // Set the flag that we only got this card from answer file,
  316. // not from binding path, i.e. it's not on the binding path yet.
  317. pAdapterInfo->m_fIsFromAnswerFile = TRUE;
  318. }
  319. else
  320. {
  321. delete pAdapterInfo;
  322. pAdapterInfo = NULL;
  323. }
  324. }
  325. if (SUCCEEDED(hrTmp))
  326. {
  327. BOOL fWins;
  328. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszAdapterSection,
  329. c_szAfWins,
  330. &fWins);
  331. if (FAILED(hrTmp))
  332. {
  333. if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  334. hrTmp = S_OK;
  335. else
  336. TraceError("HrLoadAdapterParamFormAnswerFile: fWins", hrTmp);
  337. }
  338. else if (fWins)
  339. {
  340. // WinsServerList -> m_vstrWinsServerList
  341. WCHAR * mszWinsServerList;
  342. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  343. pszAdapterSection,
  344. c_szAfWinsServerList,
  345. &mszWinsServerList);
  346. if SUCCEEDED(hrTmp)
  347. {
  348. MultiSzToColString(mszWinsServerList,
  349. &pAdapterInfo->m_vstrWinsServerList);
  350. delete [] mszWinsServerList;
  351. }
  352. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  353. hrTmp = S_OK;
  354. else
  355. TraceError("HrLoadAdapterParamFromAnswerFile: WinsServerList", hrTmp);
  356. if (SUCCEEDED(hr))
  357. hr = hrTmp;
  358. }
  359. if (SUCCEEDED(hr))
  360. hr = hrTmp;
  361. // DHCP -> m_fEnableDhcp
  362. BOOL fEnableDhcp;
  363. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszAdapterSection,
  364. c_szAfDhcp,
  365. &fEnableDhcp);
  366. if SUCCEEDED(hrTmp)
  367. pAdapterInfo->m_fEnableDhcp = fEnableDhcp;
  368. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  369. hrTmp = S_OK;
  370. else
  371. TraceError("HrLoadAdapterParamFromAnswerFile: DHCP", hrTmp);
  372. if (SUCCEEDED(hr))
  373. hr = hrTmp;
  374. // IPAddress -> m_vstrIpAddresses
  375. WCHAR * mszIPAddresses;
  376. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  377. pszAdapterSection,
  378. c_szAfIpaddress,
  379. &mszIPAddresses);
  380. if SUCCEEDED(hrTmp)
  381. {
  382. MultiSzToColString(mszIPAddresses,
  383. &pAdapterInfo->m_vstrIpAddresses);
  384. delete [] mszIPAddresses;
  385. }
  386. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  387. hrTmp = S_OK;
  388. else
  389. TraceError("HrLoadAdapterParamFromAnswerFile: IPAddress", hrTmp);
  390. if (SUCCEEDED(hr))
  391. hr = hrTmp;
  392. // SubnetMask -> m_vstrSubnetMask
  393. WCHAR * mszSubnetMasks;
  394. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  395. pszAdapterSection,
  396. c_szAfSubnetmask,
  397. &mszSubnetMasks);
  398. if SUCCEEDED(hrTmp)
  399. {
  400. MultiSzToColString(mszSubnetMasks,
  401. &pAdapterInfo->m_vstrSubnetMask);
  402. delete [] mszSubnetMasks;
  403. }
  404. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  405. hrTmp = S_OK;
  406. else
  407. TraceError("HrLoadAdapterParamFromAnswerFile: SubnetMask", hrTmp);
  408. if (SUCCEEDED(hr))
  409. hr = hrTmp;
  410. // Gateway -> m_vstrDefaultGateway
  411. WCHAR * mszDefaultGateways;
  412. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  413. pszAdapterSection,
  414. c_szAfDefaultGateway,
  415. &mszDefaultGateways);
  416. if (SUCCEEDED(hrTmp))
  417. {
  418. MultiSzToColString(mszDefaultGateways,
  419. &pAdapterInfo->m_vstrDefaultGateway);
  420. delete [] mszDefaultGateways;
  421. }
  422. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  423. hrTmp = S_OK;
  424. else
  425. TraceError("HrLoadAdapterParamFromAnswerFile: Gateway", hrTmp);
  426. if (SUCCEEDED(hr))
  427. hr = hrTmp;
  428. // DNSDomain -> m_strDnsDomain
  429. tstring strDnsDomain;
  430. hrTmp = HrSetupGetFirstString( hinf,
  431. pszAdapterSection,
  432. c_szAfDnsDomain,
  433. &strDnsDomain);
  434. if SUCCEEDED(hrTmp)
  435. pAdapterInfo->m_strDnsDomain = strDnsDomain;
  436. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  437. hrTmp = S_OK;
  438. else
  439. TraceError("HrLoadAdapterParameterFromAnswerFile: DNSDomain", hrTmp);
  440. if (SUCCEEDED(hr))
  441. hr = hrTmp;
  442. // DNSServerSearchOrder -> m_vstrDnsServerList
  443. WCHAR * mszDnsServerList;
  444. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  445. pszAdapterSection,
  446. c_szAfDnsServerSearchOrder,
  447. &mszDnsServerList);
  448. if SUCCEEDED(hrTmp)
  449. {
  450. MultiSzToColString(mszDnsServerList,
  451. &pAdapterInfo->m_vstrDnsServerList);
  452. delete [] mszDnsServerList;
  453. }
  454. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  455. hrTmp = S_OK;
  456. else
  457. TraceError("HrLoadAdapterParameterFromAnswerFile: DNSServerSearchOrder", hrTmp);
  458. if (SUCCEEDED(hr))
  459. hr = hrTmp;
  460. BOOL fTmp = FALSE;
  461. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszAdapterSection,
  462. c_szAfDisableDynamicUpdate,
  463. &fTmp);
  464. if (SUCCEEDED(hrTmp))
  465. {
  466. pAdapterInfo->m_fDisableDynamicUpdate = fTmp;
  467. }
  468. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  469. hrTmp = S_OK;
  470. else
  471. TraceError(
  472. "HrLoadAdapterParameterFromAnswerFile: DisableDynamicUpdate",
  473. hrTmp);
  474. if (SUCCEEDED(hr))
  475. hr = hrTmp;
  476. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszAdapterSection,
  477. c_szAfEnableAdapterDomainNameRegistration,
  478. &fTmp);
  479. if (SUCCEEDED(hrTmp))
  480. {
  481. pAdapterInfo->m_fEnableNameRegistration = fTmp;
  482. }
  483. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  484. hrTmp = S_OK;
  485. else
  486. TraceError(
  487. "HrLoadAdapterParameterFromAnswerFile: EnableAdapterDomainNameRegistration",
  488. hrTmp);
  489. if (SUCCEEDED(hr))
  490. hr = hrTmp;
  491. // NetBIOSOptions ->m_dwNetbiosOptions
  492. DWORD dwNetbiosOptions;
  493. hrTmp = HrSetupGetFirstDword(hinf,
  494. pszAdapterSection,
  495. c_szAfNetBIOSOptions,
  496. &dwNetbiosOptions);
  497. if SUCCEEDED(hrTmp)
  498. {
  499. if ((dwNetbiosOptions == c_dwUnsetNetbios) ||
  500. (dwNetbiosOptions == c_dwEnableNetbios) ||
  501. (dwNetbiosOptions == c_dwDisableNetbios))
  502. {
  503. pAdapterInfo->m_dwNetbiosOptions = dwNetbiosOptions;
  504. }
  505. }
  506. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  507. hrTmp = S_OK;
  508. else
  509. TraceError("HrLoadAdapterParameterFromAnswerFile: NetBIOSOptions", hrTmp);
  510. if (SUCCEEDED(hr))
  511. hr = hrTmp;
  512. // TcpAllowedPorts -> m_vstrTcpFilterList
  513. WCHAR * mszTcpFilterList;
  514. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  515. pszAdapterSection,
  516. c_szAfTcpAllowedPorts,
  517. &mszTcpFilterList);
  518. if (SUCCEEDED(hrTmp))
  519. {
  520. MultiSzToColString(mszTcpFilterList,
  521. &pAdapterInfo->m_vstrTcpFilterList);
  522. delete [] mszTcpFilterList;
  523. }
  524. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  525. hrTmp = S_OK;
  526. else
  527. TraceError("HrLoadAdapterParamFromAnswerFile: TcpAllowedPorts", hrTmp);
  528. if (SUCCEEDED(hr))
  529. hr = hrTmp;
  530. // UdpAllowedPorts -> m_vstrUdpFilterList
  531. WCHAR * mszUdpFilterList;
  532. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  533. pszAdapterSection,
  534. c_szAfUdpAllowedPorts,
  535. &mszUdpFilterList);
  536. if (SUCCEEDED(hrTmp))
  537. {
  538. MultiSzToColString(mszUdpFilterList,
  539. &pAdapterInfo->m_vstrUdpFilterList);
  540. delete [] mszUdpFilterList;
  541. }
  542. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  543. hrTmp = S_OK;
  544. else
  545. TraceError("HrLoadAdapterParamFromAnswerFile: UdpAllowedPorts", hrTmp);
  546. if (SUCCEEDED(hr))
  547. hr = hrTmp;
  548. // IpAllowedProtocols -> m_vstrIpFilterList
  549. WCHAR * mszIpFilterList;
  550. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc(hinf,
  551. pszAdapterSection,
  552. c_szAfIpAllowedProtocols,
  553. &mszIpFilterList);
  554. if (SUCCEEDED(hrTmp))
  555. {
  556. MultiSzToColString(mszIpFilterList,
  557. &pAdapterInfo->m_vstrIpFilterList);
  558. delete [] mszIpFilterList;
  559. }
  560. else if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  561. hrTmp = S_OK;
  562. else
  563. TraceError("HrLoadAdapterParamFromAnswerFile: IpAllowedProtocols", hrTmp);
  564. if (SUCCEEDED(hr))
  565. hr = hrTmp;
  566. //$REVIEW (nsun 12/11/98) bug #204145
  567. //directly save the unconfigurable parameters right after reading
  568. //it from the answer file.
  569. if (SUCCEEDED(hrReg))
  570. {
  571. Assert(hkeyTcpipParam);
  572. HKEY hkeyInterfaceParam = NULL;
  573. strInterfaceRegPath = c_szInterfacesRegKey;
  574. strInterfaceRegPath += L"\\";
  575. WCHAR szGuid [c_cchGuidWithTerm];
  576. StringFromGUID2(guidNetCard, szGuid, c_cchGuidWithTerm);
  577. strInterfaceRegPath += szGuid;
  578. DWORD dwDisposition;
  579. hrTmp = HrRegCreateKeyEx(hkeyTcpipParam, strInterfaceRegPath.c_str(),
  580. REG_OPTION_NON_VOLATILE, KEY_READ_WRITE_DELETE, NULL,
  581. &hkeyInterfaceParam, &dwDisposition);
  582. if( SUCCEEDED(hrTmp))
  583. {
  584. Assert(hkeyInterfaceParam);
  585. hrTmp = HrLoadUnConfigurableParamFromAnswerFile(
  586. hinf,
  587. pszAdapterSection,
  588. rgVtpIpAdapter,
  589. sizeof(rgVtpIpAdapter)/sizeof(rgVtpIpAdapter[0]),
  590. hkeyInterfaceParam
  591. );
  592. RegSafeCloseKey(hkeyInterfaceParam);
  593. }
  594. else
  595. TraceError("HrLoadAdapterParamFromAnswerFile: CreateTcpipParm Reg key", hrTmp);
  596. }
  597. if (SUCCEEDED(hr))
  598. hr = hrTmp;
  599. if (!FValidateAdapterParametersFromAnswerFile(pAdapterInfo, strAdapterName.c_str()))
  600. {
  601. TraceError("FValidateAdapterParameterFromAnswerFile() got invalid tcp settings", E_FAIL);
  602. }
  603. }
  604. }
  605. if (SUCCEEDED(hr))
  606. hr = hrTmp;
  607. // Move to the next card
  608. pszAdapterSection += lstrlenW(pszAdapterSection)+1;
  609. } // end of while loop
  610. if (SUCCEEDED(hrReg))
  611. RegSafeCloseKey(hkeyTcpipParam);
  612. TraceError("CTcpipcfg::HrLoadAdapterParamFromAnswerFile", hr);
  613. return hr;
  614. }
  615. HRESULT HrLoadUnConfigurableParamFromAnswerFile(HINF hinf,
  616. PCWSTR pszSection,
  617. const ValueTypePair * prgVtpParams,
  618. UINT cParams,
  619. HKEY hkeyParam)
  620. {
  621. Assert(prgVtpParams);
  622. HRESULT hr = S_OK;
  623. HRESULT hrTmp = S_OK;
  624. HRESULT hrReg = S_OK;
  625. BOOL fTmp;
  626. DWORD dwTmp;
  627. tstring strTmp;
  628. WCHAR * mszTmp;
  629. for(UINT i = 0; i < cParams; i++)
  630. {
  631. TraceTag(ttidTcpip, "HrLoadUnConfigurableParamFromAnswerFile: configuring '%S'...", prgVtpParams[i].pszValueName);
  632. switch(prgVtpParams[i].dwType)
  633. {
  634. case REG_BOOL:
  635. hrTmp = HrSetupGetFirstStringAsBool(hinf, pszSection,
  636. prgVtpParams[i].pszValueName,
  637. &fTmp);
  638. if (SUCCEEDED(hrTmp))
  639. hrReg = HrRegSetDword(hkeyParam,
  640. prgVtpParams[i].pszValueName,
  641. fTmp);
  642. break;
  643. case REG_DWORD:
  644. hrTmp = HrSetupGetFirstDword(hinf, pszSection,
  645. prgVtpParams[i].pszValueName,
  646. &dwTmp);
  647. if (SUCCEEDED(hrTmp))
  648. hrReg = HrRegSetDword(hkeyParam,
  649. prgVtpParams[i].pszValueName,
  650. dwTmp);
  651. break;
  652. case REG_SZ:
  653. hrTmp = HrSetupGetFirstString(hinf, pszSection,
  654. prgVtpParams[i].pszValueName,
  655. &strTmp);
  656. if (SUCCEEDED(hrTmp))
  657. hrReg = HrRegSetString(hkeyParam,
  658. prgVtpParams[i].pszValueName,
  659. strTmp);
  660. break;
  661. case REG_MULTI_SZ:
  662. hrTmp = HrSetupGetFirstMultiSzFieldWithAlloc( hinf,
  663. pszSection,
  664. prgVtpParams[i].pszValueName,
  665. &mszTmp);
  666. if (SUCCEEDED(hrTmp))
  667. {
  668. hrReg = HrRegSetMultiSz(hkeyParam,
  669. prgVtpParams[i].pszValueName,
  670. mszTmp);
  671. delete [] mszTmp;
  672. }
  673. break;
  674. case REG_FILE:
  675. hrTmp = HrSetupGetFirstString(hinf, pszSection,
  676. prgVtpParams[i].pszValueName,
  677. &strTmp);
  678. if (SUCCEEDED(hrTmp) && (strTmp.length() > 0))
  679. {
  680. DWORD dwDisposition=0;
  681. TOKEN_PRIVILEGES * ptpRestore = NULL;
  682. HKEY hkeyRestore=NULL;
  683. hrReg = HrRegCreateKeyEx(hkeyParam,
  684. prgVtpParams[i].pszValueName,
  685. REG_OPTION_NON_VOLATILE,
  686. KEY_ALL_ACCESS, NULL,
  687. &hkeyRestore, &dwDisposition);
  688. if (S_OK == hr)
  689. {
  690. hrReg = HrEnableAllPrivileges(&ptpRestore);
  691. if (SUCCEEDED(hrReg))
  692. {
  693. TraceTag(ttidTcpip, "HrLoadUnConfigurableParamFromAnswerFile: trying to restore regkey from file '%S'..", strTmp.c_str());
  694. hrReg = HrRegRestoreKey(hkeyRestore, strTmp.c_str(), 0);
  695. (void) HrRestorePrivileges(ptpRestore);
  696. delete [] reinterpret_cast<BYTE *>(ptpRestore);
  697. }
  698. RegCloseKey(hkeyRestore);
  699. }
  700. }
  701. break;
  702. }
  703. if(FAILED(hrTmp))
  704. {
  705. if(hrTmp == SPAPI_E_LINE_NOT_FOUND)
  706. hrTmp = S_OK;
  707. else
  708. {
  709. TraceTag(ttidError,
  710. "HrLoadUnConfigurableParamFromAnswerFile: failed to load %S. hr = %x.",
  711. prgVtpParams[i].pszValueName, hrTmp);
  712. }
  713. }
  714. #ifdef ENABLETRACE
  715. if(FAILED(hrReg))
  716. {
  717. TraceTag(ttidError,
  718. "HrLoadUnConfigurableParamFromAnswerFile: failed to set %S to the registry. hr = %x.",
  719. prgVtpParams[i].pszValueName, hrReg);
  720. }
  721. #endif
  722. if (SUCCEEDED(hr))
  723. hr = hrTmp;
  724. if (SUCCEEDED(hr))
  725. hr = hrReg;
  726. }
  727. TraceError("CTcpipcfg::HrLoadUnConfigurableParamFromAnswerFile", hr);
  728. return hr;
  729. }
  730. BOOL FValidateIpFieldsFromAnswerFile(VSTR & vstrIpAddr, PCTSTR pszValueName,
  731. PCWSTR pszAdapterName, BOOL fIsIpAddr)
  732. {
  733. BOOL fRet = TRUE;
  734. for (VSTR::iterator iter = vstrIpAddr.begin(); iter != vstrIpAddr.end(); iter++)
  735. {
  736. tstring* pstrIpAddr = *iter;
  737. if (!FIsValidIpFields(pstrIpAddr->c_str(), fIsIpAddr))
  738. {
  739. WriteTcpSetupErrorLog(fIsIpAddr ? IDS_TCP_AF_INVALID_IP_FIELDS : IDS_TCP_AF_INVALID_FIELDS,
  740. pszValueName,
  741. pszAdapterName,
  742. pstrIpAddr->c_str());
  743. fRet = FALSE;
  744. }
  745. }
  746. return fRet;
  747. }
  748. BOOL FValidateGlobalParametersFromAnswerFile(GLOBAL_INFO* pGlobalInfo)
  749. {
  750. BOOL fRet = TRUE;
  751. DNS_STATUS status;
  752. if (!pGlobalInfo->m_vstrDnsSuffixList.empty())
  753. {
  754. for (VSTR::iterator iter = pGlobalInfo->m_vstrDnsSuffixList.begin();
  755. iter != pGlobalInfo->m_vstrDnsSuffixList.end(); iter++)
  756. {
  757. status = DnsValidateName((*iter)->c_str(), DnsNameDomain);
  758. if (ERROR_INVALID_NAME == status ||
  759. DNS_ERROR_INVALID_NAME_CHAR == status)
  760. {
  761. WriteTcpSetupErrorLog(IDS_TCP_AF_INVALID_DNS_SUFFIX,
  762. c_szAfDnsSuffixSearchOrder,
  763. (*iter)->c_str());
  764. fRet = FALSE;
  765. }
  766. }
  767. }
  768. if (!fRet)
  769. {
  770. FreeCollectionAndItem(pGlobalInfo->m_vstrDnsSuffixList);
  771. }
  772. return fRet;
  773. }
  774. BOOL FValidateAdapterParametersFromAnswerFile(ADAPTER_INFO* pAdapter, PCWSTR pszAdapterName)
  775. {
  776. BOOL fRet = TRUE;
  777. if (!pAdapter->m_fEnableDhcp)
  778. {
  779. if (!pAdapter->m_vstrIpAddresses.empty())
  780. {
  781. if (!FValidateIpFieldsFromAnswerFile(pAdapter->m_vstrIpAddresses,
  782. c_szAfIpaddress,
  783. pszAdapterName))
  784. {
  785. fRet = FALSE;
  786. }
  787. }
  788. if (!pAdapter->m_vstrSubnetMask.empty())
  789. {
  790. if (!FValidateIpFieldsFromAnswerFile(pAdapter->m_vstrSubnetMask,
  791. c_szAfSubnetmask,
  792. pszAdapterName,
  793. FALSE))
  794. {
  795. fRet = FALSE;
  796. }
  797. }
  798. if (fRet)
  799. {
  800. IP_VALIDATION_ERR err = ValidateIp(pAdapter);
  801. if (err != ERR_NONE)
  802. {
  803. fRet = FALSE;
  804. switch (err)
  805. {
  806. case ERR_INCORRECT_IP:
  807. WriteTcpSetupErrorLog(IDS_TCP_AF_INVALID_SUBNET, pszAdapterName);
  808. break;
  809. case ERR_NO_IP:
  810. WriteTcpSetupErrorLog(IDS_TCP_AF_NO_IP, pszAdapterName);
  811. break;
  812. case ERR_NO_SUBNET:
  813. WriteTcpSetupErrorLog(IDS_TCP_AF_NO_SUBNET, pszAdapterName);
  814. break;
  815. default:
  816. //$REVIEW: we don't want to check other invalid settings at this time
  817. // because the setting maybe is valid in NT4, for example: uncontiguous
  818. // subnet mask
  819. fRet = TRUE;
  820. break;
  821. }
  822. }
  823. }
  824. if (!fRet)
  825. {
  826. //Invalid IP settings in the answer file. Set IP settings back to default
  827. pAdapter->m_fEnableDhcp = TRUE;
  828. FreeCollectionAndItem(pAdapter->m_vstrIpAddresses);
  829. FreeCollectionAndItem(pAdapter->m_vstrSubnetMask);
  830. }
  831. }
  832. if (!pAdapter->m_strDnsDomain.empty())
  833. {
  834. DNS_STATUS status;
  835. status = DnsValidateName(pAdapter->m_strDnsDomain.c_str(), DnsNameDomain);
  836. if (ERROR_INVALID_NAME == status ||
  837. DNS_ERROR_INVALID_NAME_CHAR == status)
  838. {
  839. WriteTcpSetupErrorLog(IDS_TCP_AF_INVALID_DNS_DOMAIN, pszAdapterName);
  840. pAdapter->m_strDnsDomain = c_szEmpty;
  841. fRet = FALSE;
  842. }
  843. }
  844. if (!pAdapter->m_vstrDnsServerList.empty())
  845. {
  846. if (!FValidateIpFieldsFromAnswerFile(pAdapter->m_vstrDnsServerList,
  847. c_szAfDnsServerSearchOrder,
  848. pszAdapterName))
  849. {
  850. FreeCollectionAndItem(pAdapter->m_vstrDnsServerList);
  851. fRet = FALSE;
  852. }
  853. }
  854. if (!pAdapter->m_vstrDefaultGateway.empty())
  855. {
  856. if (!FValidateIpFieldsFromAnswerFile(pAdapter->m_vstrDefaultGateway,
  857. c_szAfDefaultGateway,
  858. pszAdapterName))
  859. {
  860. FreeCollectionAndItem(pAdapter->m_vstrDefaultGateway);
  861. fRet = FALSE;
  862. }
  863. }
  864. if (!pAdapter->m_vstrWinsServerList.empty())
  865. {
  866. if (!FValidateIpFieldsFromAnswerFile(pAdapter->m_vstrWinsServerList,
  867. c_szAfWinsServerList,
  868. pszAdapterName))
  869. {
  870. FreeCollectionAndItem(pAdapter->m_vstrWinsServerList);
  871. fRet = FALSE;
  872. }
  873. }
  874. return fRet;
  875. }