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.

7262 lines
215 KiB

  1. // ----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N E T R E G . C P P
  7. //
  8. // Contents: Windows NT4.0 & 3.51 Network Registry Info Dumper
  9. //
  10. // Notes:
  11. //
  12. // Author: kumarp 22-December-97
  13. //
  14. // ----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include <ntsecapi.h>
  18. #include "afilestr.h"
  19. #include "conflict.h"
  20. #include "infmap.h"
  21. #include "kkcwinf.h"
  22. #include "kkenet.h"
  23. #include "kkreg.h"
  24. #include "kkstl.h"
  25. #include "kkutils.h"
  26. #include "ncipaddr.h"
  27. #include "ncmisc.h"
  28. #include "ncreg.h"
  29. #include "ncsetup.h"
  30. #include "netreg.h"
  31. #include "netupgrd.h"
  32. #include "nustrs.h"
  33. #include "nuutils.h"
  34. #include "oemupg.h"
  35. #include "resource.h"
  36. #include "ipafval.h"
  37. #include "winsock2.h"
  38. #include "ws2spi.h"
  39. #include "dhcpupg.h"
  40. // for WLBS stuff
  41. #include "wlbsparm.h"
  42. // ----------------------------------------------------------------------
  43. // external string constants
  44. extern const WCHAR c_szAfWins[];
  45. extern const WCHAR c_szAfForceStrongEncryption[];
  46. extern const WCHAR c_szDrives[];
  47. extern const WCHAR c_szInfId_MS_AppleTalk[];
  48. extern const WCHAR c_szInfId_MS_Isotpsys[];
  49. extern const WCHAR c_szInfId_MS_MSClient[];
  50. extern const WCHAR c_szInfId_MS_NWIPX[];
  51. extern const WCHAR c_szInfId_MS_NWNB[];
  52. extern const WCHAR c_szInfId_MS_NWSPX[];
  53. extern const WCHAR c_szInfId_MS_NetBIOS[];
  54. extern const WCHAR c_szInfId_MS_NetBT[];
  55. extern const WCHAR c_szInfId_MS_NwSapAgent[];
  56. extern const WCHAR c_szInfId_MS_RasCli[];
  57. extern const WCHAR c_szInfId_MS_RasSrv[];
  58. extern const WCHAR c_szInfId_MS_Streams[];
  59. extern const WCHAR c_szInfId_MS_TCPIP[];
  60. extern const WCHAR c_szInfId_MS_WLBS[];
  61. extern const WCHAR c_szNdisWan[];
  62. extern const WCHAR c_szNo[];
  63. extern const WCHAR c_szParameters[];
  64. extern const WCHAR c_szRegKeyComponentClasses[];
  65. extern const WCHAR c_szRegKeyServices[];
  66. extern const WCHAR c_szRegValDependOnGroup[];
  67. extern const WCHAR c_szRegValDependOnService[];
  68. extern const WCHAR c_szRegValServiceName[];
  69. extern const WCHAR c_szRegValStart[];
  70. extern const WCHAR c_szShares[];
  71. extern const WCHAR c_szSvcBrowser[];
  72. extern const WCHAR c_szSvcDhcpRelayAgent[];
  73. extern const WCHAR c_szSvcDhcpServer[];
  74. extern const WCHAR c_szSvcLmServer[];
  75. extern const WCHAR c_szSvcNWCWorkstation[];
  76. extern const WCHAR c_szSvcNetBIOS[];
  77. extern const WCHAR c_szSvcNetLogon[];
  78. extern const WCHAR c_szSvcRasAuto[];
  79. extern const WCHAR c_szSvcRipForIp[];
  80. extern const WCHAR c_szSvcRipForIpx[];
  81. extern const WCHAR c_szSvcRouter[];
  82. extern const WCHAR c_szSvcSapAgent[];
  83. extern const WCHAR c_szSvcWorkstation[];
  84. extern const WCHAR c_szYes[];
  85. // ----------------------------------------------------------------------
  86. // string constants
  87. const WCHAR c_szRAS[] = L"RAS";
  88. const WCHAR c_szRasMan[] = L"RasMan";
  89. const WCHAR c_szRouter[] = L"Router";
  90. const WCHAR c_szServer[] = L"Server";
  91. const WCHAR sz_DLC[] = L"DLC";
  92. const WCHAR sz_MS_DLC[] = L"MS_DLC";
  93. // WLBS:
  94. const WCHAR c_szWLBS[] = L"WLBS";
  95. const WCHAR c_szConvoy[] = L"Convoy";
  96. const WCHAR c_szMSWLBS[] = L"MS_WLBS";
  97. const WCHAR c_szMSTCPIP[] = L"MS_TCPIP";
  98. // end WLBS:
  99. // ----------------------------------------------------------------------
  100. // variables
  101. //Global
  102. // Novell Client32 upgrades
  103. BOOL g_fForceNovellDirCopy = FALSE;
  104. //File scope
  105. static TStringList *g_pslNetCard, *g_pslNetCardInstance, *g_pslNetCardAFileName;
  106. static PCWInfSection g_pwisBindings;
  107. // WLBS:
  108. static WCHAR pszWlbsClusterAdapterName[16], pszWlbsVirtualAdapterName[16];
  109. // end WLBS:
  110. // static PCWInfSection g_pwisMSNetClient;
  111. // static PCWInfSection g_pwisNetClients;
  112. // used by WriteRASParams
  113. static BOOL g_fAtLeastOneDialIn=FALSE;
  114. static BOOL g_fAtLeastOneDialOut=FALSE;
  115. static BOOL g_fAtLeastOneDialInUsingNdisWan=FALSE;
  116. static BOOL g_fAtLeastOneDialOutUsingNdisWan=FALSE;
  117. static PCWSTR g_pszServerOptimization[] =
  118. {
  119. c_szAfUnknown,
  120. c_szAfMinmemoryused,
  121. c_szAfBalance,
  122. c_szAfMaxthroughputforfilesharing,
  123. c_szAfMaxthrouputfornetworkapps
  124. };
  125. static PCWSTR g_szNetComponentSectionName[] =
  126. {
  127. c_szAfUnknown,
  128. c_szAfSectionNetAdapters,
  129. c_szAfSectionNetProtocols,
  130. c_szAfSectionNetServices,
  131. c_szAfSectionNetClients
  132. };
  133. // ----------------------------------------------------------------------
  134. // Forward Declarations
  135. BOOL WriteIdentificationInfo(IN CWInfFile *pwifAnswerFile);
  136. BOOL WriteNetAdaptersInfo(IN CWInfFile *pwifAnswerFile);
  137. HRESULT HrWriteNetComponentsInfo(IN CWInfFile* pwifAnswerFile);
  138. //Protocols
  139. BOOL WriteTCPIPParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisTCPIPGlobalParams,
  140. OUT TStringList& slAdditionalParamsSections);
  141. BOOL WriteTCPIPAdapterParams(PCWInfFile pwifAnswerFile, PCWSTR pszAdapterDriver,
  142. OUT TStringList& slAdditionalParamsSections,
  143. BOOL fDisabledToDhcpServer,
  144. BOOL fDisableNetbios);
  145. BOOL WriteIPXParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisIPXGlobalParams,
  146. OUT TStringList& slAdditionalParamsSections);
  147. BOOL WriteAppleTalkParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisGlobalParams,
  148. OUT TStringList& slAdditionalParamsSections);
  149. BOOL WritePPTPParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  150. //Services
  151. BOOL WriteRASParams(PCWInfFile pwifAnswerFile,
  152. PCWInfSection pwisNetServices,
  153. PCWInfSection pwisRASParams);
  154. HRESULT HrWritePreSP3ComponentsToSteelHeadUpgradeParams(
  155. IN CWInfFile* pwifAnswerFile);
  156. BOOL WriteNWCWorkstationParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  157. BOOL WriteDhcpServerParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  158. BOOL WriteTp4Params(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  159. BOOL WriteWLBSParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  160. BOOL WriteConvoyParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  161. // the following four actually write into [params.MS_NetClient] section
  162. BOOL WriteNetBIOSParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  163. BOOL WriteBrowserParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  164. BOOL WriteLanmanServerParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  165. BOOL WriteLanmanWorkstationParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  166. BOOL WriteRPCLocatorParams(PCWInfFile pwifAnswerFile, PCWInfSection pwisParams);
  167. //Bindings
  168. BOOL WriteBindings(IN PCWSTR pszComponentName);
  169. //Helper Functions
  170. inline WORD SwapHiLoBytes(WORD w)
  171. {
  172. return ((w & 0xff) << 8) | (w >> 8);
  173. }
  174. BOOL
  175. FIsDontExposeLowerComponent (
  176. IN PCWSTR pszInfId)
  177. {
  178. return ((0 == lstrcmpiW(pszInfId, c_szInfId_MS_NWIPX) ||
  179. (0 == lstrcmpiW(pszInfId, c_szInfId_MS_NWNB) ||
  180. (0 == lstrcmpiW(pszInfId, c_szInfId_MS_NWSPX)))));
  181. }
  182. BOOL
  183. WriteRegValueToAFile(
  184. IN PCWInfSection pwisSection,
  185. IN HKEY hKey,
  186. IN PCWSTR pszSubKey,
  187. IN PCWSTR pszValueName,
  188. IN WORD wValueType = REG_SZ,
  189. IN PCWSTR pszValueNewName = NULL,
  190. IN BOOL fDefaultProvided = FALSE,
  191. IN ...);
  192. BOOL
  193. WriteRegValueToAFile(
  194. IN PCWInfSection pwisSection,
  195. IN HKEY hKey,
  196. IN PCWSTR pszSubKey,
  197. IN PCWSTR pszValueName,
  198. IN WORD wValueType,
  199. IN PCWSTR pszValueNewName,
  200. IN BOOL fDefaultProvided,
  201. IN va_list arglist);
  202. BOOL
  203. WriteRegValueToAFile(
  204. IN PCWInfSection pwisSection,
  205. IN CORegKey& rk,
  206. IN PCWSTR pszValueName,
  207. IN WORD wValueType = REG_SZ,
  208. IN PCWSTR pszValueNewName = NULL,
  209. IN BOOL fDefaultProvided = FALSE,
  210. ...);
  211. BOOL
  212. WriteRegValueToAFile(
  213. IN PCWInfSection pwisSection,
  214. IN CORegKey& rk,
  215. IN PCWSTR pszValueName,
  216. IN WORD wValueType,
  217. IN PCWSTR pszValueNewName,
  218. IN BOOL fDefaultProvided,
  219. IN va_list arglist);
  220. BOOL
  221. WriteServiceRegValueToAFile(
  222. IN PCWInfSection pwisSection,
  223. IN PCWSTR pszServiceKey,
  224. IN PCWSTR pszValueName,
  225. IN WORD wValueType = REG_SZ,
  226. IN PCWSTR pszValueNewName = NULL,
  227. IN BOOL fDefaultProvided = FALSE,
  228. ...);
  229. //PCWSTR GetBusTypeName(DWORD dwBusType);
  230. PCWSTR GetBusTypeName(INTERFACE_TYPE eBusType);
  231. void AddToNetCardDB(IN PCWSTR pszAdapterName,
  232. IN PCWSTR pszProductName,
  233. IN PCWSTR pszAdapterDriver);
  234. BOOL IsNetCardProductName(IN PCWSTR pszName);
  235. BOOL IsNetCardInstance(IN PCWSTR pszName);
  236. PCWSTR MapNetCardInstanceToAFileName(IN PCWSTR pszNetCardInstance);
  237. void MapNetCardInstanceToAFileName(IN PCWSTR pszNetCardInstance,
  238. OUT tstring& strMappedName);
  239. OUT BOOL IsNetworkComponent(IN CORegKey *prkSoftwareMicrosoft,
  240. IN const tstring strComponentName);
  241. BOOL GetServiceKey(IN PCWSTR pszServiceName, OUT PCORegKey &prkService);
  242. BOOL GetServiceParamsKey(IN PCWSTR pszServiceName, OUT PCORegKey &prkServiceParams);
  243. BOOL GetServiceSubkey(IN PCWSTR pszServiceName,
  244. IN PCWSTR pszSubKeyName,
  245. OUT PCORegKey &prkServiceSubkey);
  246. BOOL GetServiceSubkey(IN const PCORegKey prkService,
  247. IN PCWSTR pszSubKeyName,
  248. OUT PCORegKey &prkServiceSubkey);
  249. void ConvertRouteToStringList (PCWSTR pszRoute,
  250. TStringList &slRoute );
  251. BOOL StringListsIntersect(const TStringList& sl1, const TStringList& sl2);
  252. QWORD ConvertToQWord(TByteArray ab);
  253. VOID ConvertToByteList(TByteArray ab, tstring& str);
  254. void ReplaceCharsInString(IN OUT PWSTR szString,
  255. IN PCWSTR szFindChars, IN WCHAR chReplaceWith);
  256. HRESULT HrNetRegSaveKey(IN HKEY hkeyBase, IN PCWSTR szSubKey,
  257. IN PCWSTR szComponent,
  258. OUT tstring* pstrFileName);
  259. HRESULT HrNetRegSaveKeyAndAddToSection(IN HKEY hkeyBase, IN PCWSTR szSubKey,
  260. IN PCWSTR szComponent,
  261. IN PCWSTR szKeyName,
  262. IN CWInfSection* pwisSection);
  263. HRESULT HrNetRegSaveServiceSubKeyAndAddToSection(IN PCWSTR szServiceName,
  264. IN PCWSTR szServiceSubKeyName,
  265. IN PCWSTR szKeyName,
  266. IN CWInfSection* pwisSection);
  267. HRESULT HrProcessOemComponentAndUpdateAfSection(
  268. IN CNetMapInfo* pnmi,
  269. IN HWND hParentWindow,
  270. IN HKEY hkeyParams,
  271. IN PCWSTR szPreNT5InfId,
  272. IN PCWSTR szPreNT5Instance,
  273. IN PCWSTR szNT5InfId,
  274. IN PCWSTR szDescription,
  275. IN CWInfSection* pwisParams);
  276. HRESULT HrGetNumPhysicalNetAdapters(OUT UINT* puNumAdapters);
  277. HRESULT HrHandleMiscSpecialCases(IN CWInfFile* pwifAnswerFile);
  278. VOID WriteWinsockOrder(IN CWInfFile* pwifAnswerFile);
  279. // ----------------------------------------------------------------------
  280. static const WCHAR c_szCleanMainSection[] = L"Clean";
  281. static const WCHAR c_szCleanAddRegSection[] = L"Clean.AddReg";
  282. static const WCHAR c_szCleanDelRegSection[] = L"Clean.DelReg";
  283. static const WCHAR c_szCleanServicesSection[] = L"Clean.Services";
  284. static const WCHAR c_szAddReg[] = L"AddReg";
  285. static const WCHAR c_szDelReg[] = L"DelReg";
  286. static const WCHAR c_szDelService[] = L"DelService";
  287. static const WCHAR c_szDelRegFromSoftwareKey[] = L"HKLM, \"Software\\Microsoft\\";
  288. static const WCHAR c_szDelRegFromServicesKey[] = L"HKLM, \"SYSTEM\\CurrentControlSet\\Services\\";
  289. static const WCHAR c_szTextModeFlags[] = L"TextModeFlags";
  290. static const WCHAR c_szDelRegNCPA[] = L"HKLM, \"Software\\Microsoft\\NCPA\"";
  291. //
  292. // List of software key names that are optional components. These are either
  293. // new names OR old names of optional components.
  294. //
  295. static const PCWSTR c_aszOptComp[] =
  296. {
  297. L"SNMP",
  298. L"WINS",
  299. L"SFM",
  300. L"DNS",
  301. L"SimpTcp",
  302. L"LPDSVC",
  303. L"DHCPServer",
  304. L"ILS",
  305. L"TCPUTIL",
  306. L"NETMONTOOLS",
  307. L"DSMIGRAT",
  308. L"MacPrint",
  309. L"MacSrv"
  310. };
  311. static const WCHAR c_szBloodHound[] = L"Bh";
  312. static const WCHAR c_szInfOption[] = L"InfOption";
  313. static const WCHAR c_szNetMonTools[] = L"NETMONTOOLS";
  314. static const WCHAR c_szIas[] = L"IAS";
  315. static const WCHAR c_szIasVersion[] = L"Version";
  316. // ----------------------------------------------------------------------
  317. //
  318. // Function: HrInitNetUpgrade
  319. //
  320. // Purpose: Initialize netupgrd data structures.
  321. //
  322. // Arguments: None
  323. //
  324. // Returns: S_OK on success, otherwise an error code
  325. //
  326. // Author: kumarp 02-December-97
  327. //
  328. HRESULT HrInitNetUpgrade()
  329. {
  330. DefineFunctionName("HrInitNetUpgrade");
  331. HRESULT hr;
  332. DWORD dwErrorMessageCode = IDS_E_SetupCannotContinue;
  333. hr = HrInitNetMapInfo();
  334. if (S_OK != hr)
  335. {
  336. dwErrorMessageCode = IDS_E_NetMapInfError;
  337. }
  338. //
  339. // Detect presence of Novell client to trigger special-case upgrade actions
  340. //
  341. if (S_OK == hr)
  342. {
  343. if (g_NetUpgradeInfo.From.dwBuildNumber > wWinNT4BuildNumber)
  344. {
  345. // now see if client32 is installed.
  346. static const WCHAR c_szNovell[] = L"NetWareWorkstation";
  347. HKEY hkeyServices, hkeyNovell;
  348. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyServices, KEY_READ, &hkeyServices);
  349. if (S_OK == hr)
  350. {
  351. // CONSIDER: is it better to check to see if some service is running?
  352. // see if Services\NetwareWorkstation key exists
  353. if (S_OK == HrRegOpenKeyEx(hkeyServices, c_szNovell, KEY_READ, &hkeyNovell))
  354. {
  355. RegCloseKey(hkeyNovell);
  356. g_fForceNovellDirCopy = TRUE;
  357. }
  358. RegCloseKey(hkeyServices);
  359. }
  360. else
  361. {
  362. hr = S_OK; // no NetWare.
  363. }
  364. }
  365. }
  366. if (S_OK == hr)
  367. {
  368. UINT cNumConflicts;
  369. hr = HrGenerateConflictList(&cNumConflicts);
  370. if (S_OK == hr)
  371. {
  372. if ((cNumConflicts > 0) || g_fForceNovellDirCopy)
  373. {
  374. hr = HrInitAndProcessOemDirs();
  375. if (FAILED(hr))
  376. {
  377. dwErrorMessageCode = IDS_E_InitAndProcessOemDirs;
  378. }
  379. }
  380. }
  381. else
  382. {
  383. dwErrorMessageCode = IDS_E_GenUpgradeConflictList;
  384. }
  385. }
  386. if( S_OK == hr )
  387. {
  388. //
  389. // Handle special-cased DHCP upgrade code to convert from
  390. // old format databases to current ESE format.
  391. //
  392. dwErrorMessageCode = DhcpUpgConvertDhcpDbToTemp();
  393. hr = HRESULT_FROM_WIN32(dwErrorMessageCode);
  394. TraceError( "DhcpUpgConvertDhcpDbToTemp", hr );
  395. if( FAILED(hr) )
  396. {
  397. dwErrorMessageCode = IDS_E_DhcpServerUpgradeError;
  398. }
  399. }
  400. if (FAILED(hr))
  401. {
  402. AbortUpgradeId(DwWin32ErrorFromHr(hr), dwErrorMessageCode);
  403. }
  404. TraceError(__FUNCNAME__, hr);
  405. return hr;
  406. }
  407. // ----------------------------------------------------------------------
  408. //
  409. // Function: MapNetComponentNameForBinding
  410. //
  411. // Purpose: Map component name to proper answerfile token so that it can
  412. // be used in a binding path
  413. // (e.g. IEEPRO3 --> Adapter02)
  414. //
  415. // Arguments:
  416. // pszComponentName [in] constTString object name of name of
  417. // strMappedName [out] name of name of
  418. //
  419. // Returns: None
  420. //
  421. // Author: kumarp 17-December-97
  422. //
  423. VOID
  424. MapNetComponentNameForBinding (
  425. IN PCWSTR pszComponentName,
  426. OUT tstring &strMappedName)
  427. {
  428. if (IsNetCardInstance(pszComponentName))
  429. {
  430. MapNetCardInstanceToAFileName(pszComponentName, strMappedName);
  431. }
  432. else
  433. {
  434. HRESULT hr;
  435. hr = HrMapPreNT5NetComponentServiceNameToNT5InfId(
  436. pszComponentName,
  437. &strMappedName);
  438. if (S_OK != hr)
  439. {
  440. strMappedName = c_szAfUnknown;
  441. }
  442. }
  443. }
  444. // ----------------------------------------------------------------------
  445. //
  446. // Function: FIsOptionalComponent
  447. //
  448. // Purpose: Determine if a component is an optional component
  449. //
  450. // Arguments:
  451. // pszName [in] name of component
  452. //
  453. // Returns: TRUE on success, FALSE otherwise
  454. //
  455. // Author: kumarp 02-December-97
  456. //
  457. BOOL FIsOptionalComponent(
  458. PCWSTR pszName)
  459. {
  460. BOOL fIsOc;
  461. fIsOc = FIsInStringArray(c_aszOptComp, celems(c_aszOptComp), pszName);
  462. if (!fIsOc)
  463. {
  464. // BUG #148890 (danielwe) 13 Mar 1998: Special case check for NetMon
  465. // (bloodhound). If component name is "Bh", open its NetRules key (if
  466. // it exists) and see if it was installed as NETMONTOOLS which means
  467. // it was the NetMon tools optional component
  468. if (!lstrcmpiW (pszName, c_szBloodHound))
  469. {
  470. tstring strNetRules;
  471. HKEY hkeyBh;
  472. strNetRules = L"Software\\Microsoft\\";
  473. strNetRules += pszName;
  474. strNetRules += L"\\CurrentVersion\\NetRules";
  475. if (SUCCEEDED(HrRegOpenKeyEx(HKEY_LOCAL_MACHINE,
  476. strNetRules.c_str(), KEY_READ,
  477. &hkeyBh)))
  478. {
  479. tstring strOption;
  480. if (SUCCEEDED(HrRegQueryString(hkeyBh, c_szInfOption,
  481. &strOption)))
  482. {
  483. if (!lstrcmpiW(strOption.c_str(), c_szNetMonTools))
  484. {
  485. fIsOc = TRUE;
  486. }
  487. }
  488. RegCloseKey(hkeyBh);
  489. }
  490. }
  491. }
  492. return fIsOc;
  493. }
  494. static const WCHAR c_szRegKeyOc[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Setup\\OptionalComponents";
  495. static const WCHAR c_szInstalled[] = L"Installed";
  496. static const WCHAR c_szOcIsInstalled[] = L"1";
  497. extern const WCHAR c_szOcMainSection[];
  498. static const WCHAR c_szSfm[] = L"SFM";
  499. static const WCHAR c_szMacSrv[] = L"MacSrv";
  500. static const WCHAR c_szMacPrint[] = L"MacPrint";
  501. static const WCHAR c_szRegKeyOcmSubComp[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Setup\\OC Manager\\Subcomponents";
  502. static const WCHAR c_szRegKeyCmak[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\CMAK.EXE";
  503. static const WCHAR c_szRegValueCpsSrv[] = L"CPSSRV";
  504. static const WCHAR c_szRegValueCpsAd[] = L"CPSAD";
  505. static const WCHAR c_szNetCm[] = L"NETCM";
  506. static const TCHAR c_szRegKeyIAS[] = TEXT("SYSTEM\\CurrentControlSet\\Services\\AuthSrv\\Parameters");
  507. //+---------------------------------------------------------------------------
  508. //
  509. // Function: WriteNt5OptionalComponentList
  510. //
  511. // Purpose: Writes the list of optional components that were installed
  512. // prior to upgrading from an NT5 build.
  513. //
  514. // Arguments:
  515. // pwifAnswerFile [in] Answer file object
  516. //
  517. // Returns: TRUE if success, FALSE if not.
  518. //
  519. // Author: danielwe 8 Jan 1998
  520. //
  521. // Notes:
  522. //
  523. BOOL WriteNt5OptionalComponentList(IN CWInfFile *pwifAnswerFile)
  524. {
  525. HRESULT hr = S_OK;
  526. PCWInfSection pwisMain;
  527. // Add section "[OldOptionalComponents]"
  528. pwisMain = pwifAnswerFile->AddSectionIfNotPresent(c_szOcMainSection);
  529. if (!pwisMain)
  530. {
  531. hr = E_FAIL;
  532. }
  533. if (SUCCEEDED(hr))
  534. {
  535. CORegKey rkOc(HKEY_LOCAL_MACHINE, c_szRegKeyOc, KEY_READ);
  536. CORegKeyIter rkOcIter(rkOc);
  537. tstring strOcName;
  538. // loop over each subkey in the OptionalComponents tree
  539. while (!rkOcIter.Next(&strOcName))
  540. {
  541. if (!FIsOptionalComponent(strOcName.c_str()))
  542. {
  543. continue;
  544. }
  545. HKEY hkeyOc;
  546. hr = HrRegOpenKeyEx(rkOc.HKey(), strOcName.c_str(),
  547. KEY_READ, &hkeyOc);
  548. if (SUCCEEDED(hr))
  549. {
  550. ULONG fInstalled;
  551. hr = HrRegQueryStringAsUlong(hkeyOc, c_szInstalled, 10,
  552. &fInstalled);
  553. if (SUCCEEDED(hr) ||
  554. HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
  555. {
  556. hr = S_OK;
  557. if (fInstalled)
  558. {
  559. if (!lstrcmpiW(strOcName.c_str(), c_szSfm))
  560. {
  561. // Special case the SFM component because
  562. // it got split into 2
  563. pwisMain->AddKey(c_szMacSrv,
  564. c_szOcIsInstalled);
  565. pwisMain->AddKey(c_szMacPrint,
  566. c_szOcIsInstalled);
  567. }
  568. else
  569. {
  570. pwisMain->AddKey(strOcName.c_str(),
  571. c_szOcIsInstalled);
  572. }
  573. }
  574. }
  575. RegCloseKey(hkeyOc);
  576. }
  577. }
  578. }
  579. TraceError("WriteNt5OptionalComponentList", hr);
  580. return SUCCEEDED(hr);
  581. }
  582. //+---------------------------------------------------------------------------
  583. //
  584. // Function: HandlePostConnectionsSfmOcUpgrade
  585. //
  586. // Purpose: Handles the upgrade of the SFM optional component which was
  587. // split into 2 different components. This only applies to
  588. // post connections builds (1740+).
  589. //
  590. // Arguments:
  591. // pwifAnswerFile [in] Answer file object
  592. //
  593. // Returns: TRUE
  594. //
  595. // Author: danielwe 3 Feb 1998
  596. //
  597. // Notes: If SFM was previously installed, write out MacSrv and MacPrint
  598. // to the answer file in its place.
  599. //
  600. BOOL HandlePostConnectionsSfmOcUpgrade(IN CWInfFile *pwifAnswerFile)
  601. {
  602. HKEY hkeyOc;
  603. if (SUCCEEDED(HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyOcmSubComp,
  604. KEY_READ, &hkeyOc)))
  605. {
  606. DWORD dwSfm;
  607. if (SUCCEEDED(HrRegQueryDword(hkeyOc, c_szSfm, &dwSfm)))
  608. {
  609. if (dwSfm == 1)
  610. {
  611. PCWInfSection pwisMain;
  612. pwisMain = pwifAnswerFile->AddSectionIfNotPresent(c_szOcMainSection);
  613. if (pwisMain)
  614. {
  615. pwisMain->AddKey(c_szMacSrv, c_szOcIsInstalled);
  616. pwisMain->AddKey(c_szMacPrint, c_szOcIsInstalled);
  617. }
  618. }
  619. }
  620. RegCloseKey(hkeyOc);
  621. }
  622. return TRUE;
  623. }
  624. //+---------------------------------------------------------------------------
  625. //
  626. // Function: HrWriteConfigManagerOptionalComponents
  627. //
  628. // Purpose: Special case for writing config manager components to the
  629. // answer file.
  630. //
  631. // Arguments:
  632. // pwifAnswerFile [in] Answer file object
  633. //
  634. // Returns: S_OK if success, otherwise an error code
  635. //
  636. // Author: danielwe 1 May 1998
  637. //
  638. // Notes:
  639. //
  640. HRESULT HrWriteConfigManagerOptionalComponents(CWInfFile *pwifAnswerFile)
  641. {
  642. HRESULT hr = S_OK;
  643. HKEY hkeyCmak;
  644. HKEY hkeyOcm;
  645. PCWInfSection pwisMain;
  646. BOOL fFoundCmComponent = FALSE;
  647. pwisMain = pwifAnswerFile->FindSection(c_szOcMainSection);
  648. if (SUCCEEDED(HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyCmak, KEY_READ,
  649. &hkeyCmak)))
  650. {
  651. fFoundCmComponent = TRUE;
  652. RegCloseKey(hkeyCmak);
  653. }
  654. if (SUCCEEDED(HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyOcmSubComp,
  655. KEY_READ, &hkeyOcm)))
  656. {
  657. DWORD dwValue;
  658. if (SUCCEEDED(HrRegQueryDword(hkeyOcm, c_szRegValueCpsSrv, &dwValue)))
  659. {
  660. if (dwValue)
  661. {
  662. fFoundCmComponent = TRUE;
  663. }
  664. }
  665. if (SUCCEEDED(HrRegQueryDword(hkeyOcm, c_szRegValueCpsAd, &dwValue)))
  666. {
  667. if (dwValue)
  668. {
  669. fFoundCmComponent = TRUE;
  670. }
  671. }
  672. RegCloseKey(hkeyOcm);
  673. }
  674. // If we found any one of the three CM components, then we want to install the suite of
  675. // all three components.
  676. //
  677. if (fFoundCmComponent)
  678. {
  679. pwisMain->AddKey(c_szNetCm, c_szOcIsInstalled);
  680. }
  681. TraceError("HrWriteConfigManagerOptionalComponents", hr);
  682. return hr;
  683. }
  684. //+---------------------------------------------------------------------------
  685. //
  686. // Function: HrWriteIASOptionalComponents
  687. //
  688. // Purpose: Special case for writing IAS component to the
  689. // answer file.
  690. //
  691. // Arguments:
  692. // pwifAnswerFile [in] Answer file object
  693. //
  694. // Returns: S_OK if success, otherwise an error code
  695. //
  696. // Author: tperraut (T.P. comments) Feb 22 1999
  697. //
  698. // Notes: 03/31/2000 tperraut: do not check the content of the Version
  699. // string anymore: all NT4 IAS should get upgraded
  700. //
  701. HRESULT HrWriteIASOptionalComponents(CWInfFile *pwifAnswerFile)
  702. {
  703. HRESULT hr;
  704. HKEY hkeyIAS;
  705. PCWInfSection pwisMain = pwifAnswerFile->FindSection(c_szOcMainSection);
  706. if (SUCCEEDED(HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyIAS, KEY_READ,
  707. &hkeyIAS)))
  708. {
  709. tstring strVersion;
  710. hr = HrRegQueryString(hkeyIAS, c_szIasVersion, &strVersion);
  711. if (S_OK == hr)
  712. {
  713. pwisMain->AddKey(c_szIas, c_szOcIsInstalled);
  714. }
  715. RegCloseKey(hkeyIAS);
  716. }
  717. else
  718. {
  719. hr = E_FAIL;
  720. }
  721. TraceError("HrWriteIASOptionalComponents", hr);
  722. return hr;
  723. }
  724. // ----------------------------------------------------------------------
  725. //
  726. // Function: HrWriteNt4OptionalComponentList
  727. //
  728. // Purpose: Writes the list of optional components that were installed
  729. // if upgrading from NT4.
  730. //
  731. // Arguments:
  732. // pwifAnswerFile [in] pointer to CWInfFile object
  733. // slNetOcList [in] list of optional components
  734. //
  735. // Returns: S_OK on success, otherwise an error code
  736. //
  737. // Author: kumarp 02-December-97
  738. //
  739. HRESULT
  740. HrWriteNt4OptionalComponentList (
  741. IN CWInfFile *pwifAnswerFile,
  742. IN const TStringList &slNetOcList)
  743. {
  744. HRESULT hr = S_OK;
  745. PCWInfSection pwisMain;
  746. pwisMain = pwifAnswerFile->AddSectionIfNotPresent(c_szOcMainSection);
  747. if (!pwisMain)
  748. {
  749. hr = E_FAIL;
  750. }
  751. if (SUCCEEDED(hr))
  752. {
  753. TStringListIter iter;
  754. tstring strTemp;
  755. for (iter = slNetOcList.begin(); iter != slNetOcList.end(); iter++)
  756. {
  757. strTemp = **iter;
  758. if (!lstrcmpiW(strTemp.c_str(), c_szSfm))
  759. {
  760. // Special case the SFM component because it got split into 2
  761. pwisMain->AddKey(c_szMacSrv, c_szOcIsInstalled);
  762. }
  763. else if (!lstrcmpiW(strTemp.c_str(), c_szBloodHound))
  764. {
  765. // Special case NetMon. If tools were installed via the "Bh"
  766. // component of NT4, write this out as NETMONTOOLS=1 in the
  767. // answer file.
  768. pwisMain->AddKey(c_szNetMonTools, c_szOcIsInstalled);
  769. }
  770. else
  771. {
  772. pwisMain->AddKey(strTemp.c_str(), c_szOcIsInstalled);
  773. }
  774. }
  775. // tperraut
  776. hr = HrWriteIASOptionalComponents(pwifAnswerFile);
  777. hr = HrWriteConfigManagerOptionalComponents(pwifAnswerFile);
  778. }
  779. TraceError("HrWriteNt4OptionalComponentList", hr);
  780. return hr;
  781. }
  782. // ----------------------------------------------------------------------
  783. //
  784. // Function: HrWriteMainCleanSection
  785. //
  786. // Purpose: Write [Clean] section in the answerfile
  787. //
  788. // Arguments:
  789. // pwifAnswerFile [in] pointer to CWInfFile object
  790. //
  791. // Returns: S_OK on success, otherwise an error code
  792. //
  793. // Author: kumarp 02-December-97
  794. //
  795. // Notes: The [Clean] section holds data that controls what is deleted
  796. // at the start of GUI mode setup
  797. //
  798. HRESULT
  799. HrWriteMainCleanSection (
  800. IN CWInfFile *pwifAnswerFile)
  801. {
  802. HRESULT hr = S_OK;
  803. PCWInfSection pwisMain;
  804. // Add section "[Clean]"
  805. pwisMain = pwifAnswerFile->AddSection(c_szCleanMainSection);
  806. if (!pwisMain)
  807. {
  808. hr = E_FAIL;
  809. }
  810. if (SUCCEEDED(hr))
  811. {
  812. pwisMain->AddKey(c_szDelReg, c_szCleanDelRegSection);
  813. }
  814. TraceError("HrWriteMainCleanSection", hr);
  815. return hr;
  816. }
  817. // ----------------------------------------------------------------------
  818. //
  819. // Function: HrGetListOfServicesNotToBeDeleted
  820. //
  821. // Purpose: Generate list of services that should not be deleted
  822. // during upgrade.
  823. //
  824. // Arguments:
  825. // pmszServices [out] pointer to multisz list of services
  826. //
  827. // Returns: S_OK on success, otherwise an error code
  828. //
  829. // Author: kumarp 02-December-97
  830. //
  831. // Notes: This info is read from netupg.inf file
  832. //
  833. HRESULT
  834. HrGetListOfServicesNotToBeDeleted (
  835. OUT PWSTR* pmszServices)
  836. {
  837. AssertValidWritePtr(pmszServices);
  838. HRESULT hr;
  839. HINF hinf;
  840. *pmszServices = NULL;
  841. hr = HrOpenNetUpgInfFile(&hinf);
  842. if (S_OK == hr)
  843. {
  844. INFCONTEXT ic;
  845. hr = HrSetupFindFirstLine(
  846. hinf,
  847. L"UpgradeData",
  848. L"ServicesNotToBeDeletedDuringUpgrade",
  849. &ic);
  850. if (S_OK == hr)
  851. {
  852. hr = HrSetupGetMultiSzFieldWithAlloc(ic, 1, pmszServices);
  853. }
  854. SetupCloseInfFile(hinf);
  855. }
  856. return hr;
  857. }
  858. // ----------------------------------------------------------------------
  859. //
  860. // Function: GetNetworkServicesList
  861. //
  862. // Purpose: Generate list of net services
  863. //
  864. // Arguments:
  865. // slNetServices [out] list of net services
  866. // slNetOptionalComponents [out] list of optional components found
  867. //
  868. // Returns: None
  869. //
  870. // Author: kumarp 02-December-97
  871. //
  872. void
  873. GetNetworkServicesList (
  874. OUT TStringList& slNetServices,
  875. OUT TStringList& slNetOptionalComponents)
  876. {
  877. DefineFunctionName("GetNetworkServicesList");
  878. HRESULT hr=S_OK;
  879. tstring strNetComponentName;
  880. tstring strServiceName;
  881. Assert (g_NetUpgradeInfo.From.dwBuildNumber);
  882. if (g_NetUpgradeInfo.From.dwBuildNumber <= wWinNT4BuildNumber)
  883. {
  884. // found Pre-NT5 networking, collect list by enumerating over
  885. // the registry
  886. CORegKey rkSoftwareMicrosoft(HKEY_LOCAL_MACHINE, c_szRegKeySoftwareMicrosoft,
  887. KEY_READ);
  888. if (!rkSoftwareMicrosoft.HKey())
  889. {
  890. TraceTag(ttidError, "%s: Error reading HKLM\\%S", __FUNCNAME__,
  891. c_szRegKeySoftwareMicrosoft);
  892. hr = E_FAIL;
  893. goto return_from_function;
  894. }
  895. CORegKeyIter* prkiNetComponents = new CORegKeyIter(rkSoftwareMicrosoft);
  896. if(prkiNetComponents) {
  897. // mbend - this is not great, but it should get Prefix to shutup
  898. while (!prkiNetComponents->Next(&strNetComponentName))
  899. {
  900. if (FIsOptionalComponent(strNetComponentName.c_str()))
  901. {
  902. AddAtEndOfStringList(slNetOptionalComponents, strNetComponentName);
  903. }
  904. // any software that has a NetRules key under the CurrentVersion
  905. // key is a network component
  906. if (!IsNetworkComponent(&rkSoftwareMicrosoft, strNetComponentName))
  907. {
  908. continue;
  909. }
  910. CORegKey rkNetComponent(rkSoftwareMicrosoft,
  911. (strNetComponentName +
  912. L"\\CurrentVersion").c_str());
  913. if (!((HKEY) rkNetComponent))
  914. {
  915. continue;
  916. }
  917. strServiceName.erase();
  918. rkNetComponent.QueryValue(c_szRegValServiceName, strServiceName);
  919. if (!strServiceName.empty())
  920. {
  921. AddAtEndOfStringList(slNetServices, strServiceName);
  922. }
  923. }
  924. }
  925. hr = S_OK;
  926. }
  927. // with the above algorithm we do not catch all networking components
  928. // because there are certain networking servies such as NetBIOSInformation
  929. // that have entry under service but not under software\microsoft
  930. // for such components, we use the following rule
  931. // if a serice under CurrentControlSet\Sevices has a Linkage sub key
  932. // then it is considered as a networking service
  933. //
  934. HKEY hkeyServices;
  935. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyServices,
  936. KEY_READ, &hkeyServices);
  937. if (S_OK == hr)
  938. {
  939. WCHAR szBuf[MAX_PATH];
  940. FILETIME time;
  941. DWORD dwSize;
  942. DWORD dwRegIndex;
  943. HKEY hkeyService;
  944. HKEY hkeyLinkage;
  945. BOOL fHasLinkageKey;
  946. for (dwRegIndex = 0, dwSize = celems(szBuf);
  947. S_OK == HrRegEnumKeyEx(hkeyServices, dwRegIndex, szBuf,
  948. &dwSize, NULL, NULL, &time);
  949. dwRegIndex++, dwSize = celems(szBuf))
  950. {
  951. Assert(*szBuf);
  952. hr = HrRegOpenKeyEx(hkeyServices, szBuf, KEY_READ, &hkeyService);
  953. if (hr == S_OK)
  954. {
  955. //
  956. // 399641: instead of using Linkage, we use Linkage\Disabled.
  957. //
  958. hr = HrRegOpenKeyEx(hkeyService, c_szLinkageDisabled, KEY_READ, &hkeyLinkage);
  959. fHasLinkageKey = (S_OK == hr);
  960. RegSafeCloseKey(hkeyLinkage);
  961. if (fHasLinkageKey && !FIsInStringList(slNetServices, szBuf))
  962. {
  963. slNetServices.push_back(new tstring(szBuf));
  964. }
  965. RegCloseKey (hkeyService);
  966. }
  967. }
  968. RegCloseKey(hkeyServices);
  969. }
  970. return_from_function:
  971. TraceError(__FUNCNAME__, hr);
  972. }
  973. // REVIEW$ (shaunco)
  974. // This is a list of drivers/services that were disabled (via TextModeFlags)
  975. // but not deleted. Thus, the purpose was just to prevent these from
  976. // starting during GUI mode. That is now handled automatically by the
  977. // service controller, so the only things from this list which we might have
  978. // an issue with are those that are system-start.
  979. //
  980. static const PCWSTR c_aszServicesToDisable[] =
  981. {
  982. L"Afd",
  983. L"CiFilter",
  984. L"ClipSrv",
  985. L"DHCP",
  986. L"DigiFEP5",
  987. L"IpFilterDriver"
  988. L"LicenseService",
  989. L"NdisTapi",
  990. L"NetDDE",
  991. L"NetDDEdsdm",
  992. L"Pcimac",
  993. L"RasAcd",
  994. L"RasArp",
  995. L"Telnet",
  996. L"ftpsvc",
  997. L"gophersvc",
  998. L"msftpsvc",
  999. L"ntcx",
  1000. L"ntepc",
  1001. L"ntxall",
  1002. L"ntxem",
  1003. L"raspptpf",
  1004. L"w3svc",
  1005. L"wuser32",
  1006. };
  1007. HRESULT
  1008. HrPrepareServiceForUpgrade (
  1009. IN PCWSTR pszServiceName,
  1010. IN PCWSTR pmszServicesNotToBeDeleted,
  1011. IN CWInfSection* pwisDelReg,
  1012. IN CWInfSection* pwisDelService,
  1013. IN CWInfSection* pwisStartTypes)
  1014. {
  1015. Assert (pszServiceName);
  1016. Assert (pmszServicesNotToBeDeleted);
  1017. Assert (pwisDelReg);
  1018. Assert (pwisDelService);
  1019. Assert (pwisStartTypes);
  1020. HRESULT hr;
  1021. HKEY hkey;
  1022. DWORD dwValue;
  1023. WCHAR szBuf [_MAX_PATH];
  1024. BOOL fDelete;
  1025. fDelete = !FIsSzInMultiSzSafe (pszServiceName, pmszServicesNotToBeDeleted) &&
  1026. FCanDeleteOemService (pszServiceName);
  1027. if (fDelete)
  1028. {
  1029. // Remove from the software hive if present.
  1030. //
  1031. wcscpy (szBuf, c_szDelRegFromSoftwareKey);
  1032. wcscat (szBuf, pszServiceName);
  1033. wcscat (szBuf, L"\"");
  1034. pwisDelReg->AddRawLine (szBuf);
  1035. }
  1036. hr = HrRegOpenServiceKey (pszServiceName, KEY_READ_WRITE, &hkey);
  1037. if (S_OK == hr)
  1038. {
  1039. // Save the start type so that we can restore it after we reinstall
  1040. // the service for Windows 2000.
  1041. //
  1042. hr = HrRegQueryDword (hkey, c_szRegValStart, &dwValue);
  1043. if (S_OK == hr)
  1044. {
  1045. pwisStartTypes->AddKey (pszServiceName, dwValue);
  1046. }
  1047. if (fDelete)
  1048. {
  1049. hr = HrRegQueryDword (hkey, c_szType, &dwValue);
  1050. if (S_OK == hr)
  1051. {
  1052. if (dwValue & SERVICE_ADAPTER)
  1053. {
  1054. // Pseudo service on NT4. We have to delete this with
  1055. // a DelReg, not a DelService.
  1056. //
  1057. wcscpy (szBuf, c_szDelRegFromServicesKey);
  1058. wcscat (szBuf, pszServiceName);
  1059. wcscat (szBuf, L"\"");
  1060. pwisDelReg->AddRawLine (szBuf);
  1061. }
  1062. else
  1063. {
  1064. pwisDelService->AddKey(c_szDelService, pszServiceName);
  1065. }
  1066. // Since we will be deleting it during GUI mode, we need to
  1067. // ensure that it gets set to disabled during text mode so
  1068. // that (in the event it is a SYSTEM_START driver) it does
  1069. // not get started during GUI mode before we can delete it.
  1070. //
  1071. (VOID) HrRegSetDword (hkey, c_szTextModeFlags, 0x4);
  1072. }
  1073. }
  1074. RegCloseKey (hkey);
  1075. }
  1076. else if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
  1077. {
  1078. // Not a service. We'll remove from the software key.
  1079. //
  1080. hr = S_OK;
  1081. }
  1082. TraceHr (ttidError, FAL, hr, FALSE, "HrPrepareServiceForUpgrade");
  1083. return hr;
  1084. }
  1085. // ----------------------------------------------------------------------
  1086. //
  1087. // Function: WriteDisableServicesList
  1088. //
  1089. // Purpose: Determine which services need to be disabled during ugprade and
  1090. // write proper info to the answerfile to make that happen.
  1091. // The set of such services consists of
  1092. // - network component services AND
  1093. // - services that depend of atleast one net-service
  1094. //
  1095. // Arguments:
  1096. // pwifAnswerFile [in] pointer to CWInfFile object
  1097. //
  1098. // Returns: TRUE on success, FALSE otherwise
  1099. //
  1100. // Author: kumarp 03-December-97
  1101. //
  1102. BOOL
  1103. WriteDisableServicesList (
  1104. IN CWInfFile *pwifAnswerFile)
  1105. {
  1106. HRESULT hr = S_OK;
  1107. TStringList slNetServices;
  1108. TStringList slNetOcList;
  1109. TStringListIter iter;
  1110. tstring* pstrServiceName;
  1111. CWInfSection* pwisDelReg;
  1112. CWInfSection* pwisDelService;
  1113. CWInfSection* pwisStartTypes;
  1114. PWSTR pmszServicesNotToBeDeleted;
  1115. // We should only be here if we are upgrading from from NT4 or earlier.
  1116. //
  1117. Assert (g_NetUpgradeInfo.From.dwBuildNumber);
  1118. Assert (g_NetUpgradeInfo.From.dwBuildNumber <= wWinNT4BuildNumber)
  1119. // First, collect all network services and optional components.
  1120. //
  1121. GetNetworkServicesList(slNetServices, slNetOcList);
  1122. hr = HrWriteNt4OptionalComponentList(pwifAnswerFile, slNetOcList);
  1123. if (FAILED(hr))
  1124. {
  1125. goto finished;
  1126. }
  1127. pwisDelReg = pwifAnswerFile->AddSectionIfNotPresent(c_szCleanDelRegSection);
  1128. pwisDelService = pwifAnswerFile->AddSectionIfNotPresent(c_szCleanServicesSection);
  1129. pwisStartTypes = pwifAnswerFile->AddSectionIfNotPresent(c_szAfServiceStartTypes);
  1130. if (!pwisDelReg || !pwisDelService || !pwisStartTypes)
  1131. {
  1132. hr = E_OUTOFMEMORY;
  1133. goto finished;
  1134. }
  1135. hr = HrGetListOfServicesNotToBeDeleted(&pmszServicesNotToBeDeleted);
  1136. if (S_OK == hr)
  1137. {
  1138. pwisDelReg->AddRawLine(c_szDelRegNCPA);
  1139. for (iter = slNetServices.begin();
  1140. iter != slNetServices.end();
  1141. iter++)
  1142. {
  1143. pstrServiceName = *iter;
  1144. Assert (pstrServiceName);
  1145. hr = HrPrepareServiceForUpgrade (
  1146. pstrServiceName->c_str(),
  1147. pmszServicesNotToBeDeleted,
  1148. pwisDelReg,
  1149. pwisDelService,
  1150. pwisStartTypes);
  1151. if (S_OK != hr)
  1152. {
  1153. break;
  1154. }
  1155. }
  1156. MemFree (pmszServicesNotToBeDeleted);
  1157. }
  1158. finished:
  1159. EraseAndDeleteAll(&slNetOcList);
  1160. EraseAndDeleteAll(&slNetServices);
  1161. TraceError("WriteDisableServicesList", hr);
  1162. return SUCCEEDED(hr);
  1163. }
  1164. extern const DECLSPEC_SELECTANY WCHAR c_szRegNetKeys[] = L"System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
  1165. extern const DECLSPEC_SELECTANY WCHAR c_szRegKeyConFmt[] = L"System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection";
  1166. extern const DECLSPEC_SELECTANY WCHAR c_szafNICsWithIcons[] = L"NetworkAdaptersWithIcons";
  1167. static const WCHAR c_szShowIcon[] = L"ShowIcon";
  1168. // ----------------------------------------------------------------------
  1169. //
  1170. // Function: WritePerAdapterInfoForNT5
  1171. //
  1172. // Purpose: Determine which services need to be disabled during ugprade from
  1173. // Windows 2000 and write proper info to the answerfile to make that happen.
  1174. // The set of such services consists of
  1175. // - network component services
  1176. //
  1177. // Arguments:
  1178. // pwifAnswerFile [in] pointer to CWInfFile object
  1179. //
  1180. // Returns: TRUE on success, FALSE otherwise
  1181. //
  1182. // Author: deonb 10-July-2000
  1183. //
  1184. BOOL
  1185. WritePerAdapterInfoForNT5 (
  1186. IN CWInfFile *pwifAnswerFile)
  1187. {
  1188. HRESULT hr = S_OK;
  1189. HKEY hkey;
  1190. // Check for the existence of the connection sub-key
  1191. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegNetKeys, KEY_READ, &hkey);
  1192. if (SUCCEEDED(hr))
  1193. {
  1194. DWORD dwIndex(0);
  1195. TCHAR szName[MAX_PATH+1];
  1196. DWORD dwSize(MAX_PATH);
  1197. FILETIME ftLastWriteTime;
  1198. DWORD dwRetVal(0);
  1199. do
  1200. {
  1201. dwRetVal = RegEnumKeyEx(hkey, dwIndex, szName, &dwSize, NULL, NULL, NULL, &ftLastWriteTime);
  1202. if ( ERROR_SUCCESS == dwRetVal )
  1203. {
  1204. TCHAR szRegKey[MAX_PATH+1];
  1205. swprintf(szRegKey, c_szRegKeyConFmt, szName);
  1206. HKEY hkeyConnection;
  1207. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, KEY_READ, &hkeyConnection);
  1208. if (SUCCEEDED(hr))
  1209. {
  1210. DWORD dwValue;
  1211. HRESULT hr = HrRegQueryDword(hkeyConnection, c_szShowIcon, &dwValue);
  1212. if (SUCCEEDED(hr) && dwValue)
  1213. {
  1214. CWInfSection* pwisStartTypes;
  1215. pwisStartTypes = pwifAnswerFile->AddSectionIfNotPresent(c_szafNICsWithIcons);
  1216. if (!pwisStartTypes)
  1217. {
  1218. hr = E_OUTOFMEMORY;
  1219. }
  1220. else
  1221. {
  1222. pwisStartTypes->AddKey (szName, 1);
  1223. }
  1224. }
  1225. RegSafeCloseKey(hkeyConnection);
  1226. }
  1227. }
  1228. } while ( (ERROR_SUCCESS == dwRetVal) && (SUCCEEDED(hr)) );
  1229. RegSafeCloseKey(hkey);
  1230. }
  1231. TraceError("WritePerAdapterInfoForNT5", hr);
  1232. return SUCCEEDED(hr);
  1233. }
  1234. // ----------------------------------------------------------------------
  1235. //
  1236. // Function: WriteDisableServicesListForNT5
  1237. //
  1238. // Purpose: Determine which services need to be disabled during ugprade from
  1239. // Windows 2000 and write proper info to the answerfile to make that happen.
  1240. // The set of such services consists of
  1241. // - network component services
  1242. //
  1243. // Arguments:
  1244. // pwifAnswerFile [in] pointer to CWInfFile object
  1245. //
  1246. // Returns: TRUE on success, FALSE otherwise
  1247. //
  1248. // Author: deonb 10-July-2000
  1249. //
  1250. BOOL
  1251. WriteDisableServicesListForNT5 (
  1252. IN CWInfFile *pwifAnswerFile)
  1253. {
  1254. static PCWSTR c_aszNT5UpgrdCheckComponents[] =
  1255. {
  1256. L"Browser",
  1257. L"LanmanServer",
  1258. c_szSvcDhcpServer
  1259. };
  1260. HRESULT hr = S_OK;
  1261. PCWSTR pstrServiceName;
  1262. CWInfSection* pwisStartTypes;
  1263. PWSTR pmszServicesNotToBeDeleted;
  1264. // We should only be here if we are upgrading from NT5 or later.
  1265. //
  1266. Assert (g_NetUpgradeInfo.From.dwBuildNumber);
  1267. Assert (g_NetUpgradeInfo.From.dwBuildNumber > wWinNT4BuildNumber)
  1268. // First, collect all network services and optional components.
  1269. //
  1270. pwisStartTypes = pwifAnswerFile->AddSectionIfNotPresent(c_szAfServiceStartTypes);
  1271. if (!pwisStartTypes)
  1272. {
  1273. hr = E_OUTOFMEMORY;
  1274. goto finished;
  1275. }
  1276. if (S_OK == hr)
  1277. {
  1278. DWORD x;
  1279. for (x = 0, pstrServiceName = c_aszNT5UpgrdCheckComponents[0];
  1280. x < sizeof(c_aszNT5UpgrdCheckComponents)/sizeof(c_aszNT5UpgrdCheckComponents[0]);
  1281. x++, pstrServiceName = c_aszNT5UpgrdCheckComponents[x])
  1282. {
  1283. Assert (pstrServiceName);
  1284. HKEY hkey;
  1285. hr = HrRegOpenServiceKey (pstrServiceName, KEY_READ, &hkey);
  1286. if (S_OK == hr)
  1287. {
  1288. // Save the start type (only if disabled) so that we can restore it after we install
  1289. // the service for Windows 2000.
  1290. DWORD dwValue;
  1291. hr = HrRegQueryDword (hkey, c_szRegValStart, &dwValue);
  1292. if ( (S_OK == hr) && (SERVICE_DISABLED == dwValue) )
  1293. {
  1294. pwisStartTypes->AddKey (pstrServiceName, dwValue);
  1295. }
  1296. RegCloseKey (hkey);
  1297. }
  1298. }
  1299. }
  1300. finished:
  1301. TraceError("WriteDisableServicesListNT5", hr);
  1302. return SUCCEEDED(hr);
  1303. }
  1304. // ----------------------------------------------------------------------
  1305. //
  1306. // Function: GetProductTypeStr
  1307. //
  1308. // Purpose: Get string representation of PRODUCTTYPE
  1309. //
  1310. // Arguments:
  1311. // pt [in] Product type
  1312. //
  1313. // Returns: pointer to string representation of PRODUCTTYPE
  1314. //
  1315. // Author: kumarp 03-December-97
  1316. //
  1317. PCWSTR
  1318. GetProductTypeStr (
  1319. IN PRODUCTTYPE pt)
  1320. {
  1321. PCWSTR szProductType;
  1322. switch(pt)
  1323. {
  1324. case NT_WORKSTATION:
  1325. szProductType = c_szAfNtWorkstation;
  1326. break;
  1327. case NT_SERVER:
  1328. szProductType = c_szAfNtServer;
  1329. break;
  1330. default:
  1331. szProductType = NULL;
  1332. break;
  1333. }
  1334. return szProductType;
  1335. }
  1336. // ----------------------------------------------------------------------
  1337. //
  1338. // Function: WriteNetComponentsToRemove
  1339. //
  1340. // Purpose: Write the network components in the answerfile
  1341. // that will be removed.
  1342. //
  1343. // Arguments:
  1344. // pwisNetworking [in] pointer to [Networking] section
  1345. //
  1346. // Returns: none
  1347. //
  1348. // Author: asinha 29-March-2001
  1349. //
  1350. void WriteNetComponentsToRemove (IN CWInfSection* pwisNetworking)
  1351. {
  1352. DefineFunctionName("WriteNetComponentsToRemove");
  1353. TraceFunctionEntry(ttidNetUpgrade);
  1354. TraceTag(ttidNetUpgrade, "netupgrd.dll: WriteNetComponentsToRemove");
  1355. if ( ShouldRemoveDLC(NULL, NULL) )
  1356. {
  1357. PCWInfKey pwisKey;
  1358. TStringList slNetComponentsToRemove;
  1359. pwisKey = pwisNetworking->FindKey(c_szAfNetComponentsToRemove,
  1360. ISM_FromBeginning);
  1361. if ( pwisKey )
  1362. {
  1363. // Read the old value of NetComponentsToRemove
  1364. pwisKey->GetStringListValue(slNetComponentsToRemove);
  1365. }
  1366. else
  1367. {
  1368. pwisKey = pwisNetworking->AddKey(c_szAfNetComponentsToRemove);
  1369. }
  1370. // Make sure to write the new infId/PnpId.
  1371. AddAtEndOfStringList(slNetComponentsToRemove,
  1372. sz_MS_DLC);
  1373. pwisKey->SetValue( slNetComponentsToRemove );
  1374. }
  1375. return;
  1376. }
  1377. // ----------------------------------------------------------------------
  1378. //
  1379. // Function: WriteProductTypeInfo
  1380. //
  1381. // Purpose: Write product-type info to the answerfile
  1382. //
  1383. // Arguments:
  1384. // pwisNetworking [in] pointer to [Networking] section
  1385. //
  1386. // Returns: none
  1387. //
  1388. // Author: kumarp 03-December-97
  1389. //
  1390. void
  1391. WriteProductTypeInfo (
  1392. IN CWInfSection* pwisNetworking)
  1393. {
  1394. PCWSTR pszProduct;
  1395. pszProduct = GetProductTypeStr(g_NetUpgradeInfo.From.ProductType);
  1396. Assert(pszProduct);
  1397. //UpgradeFromProduct
  1398. pwisNetworking->AddKey(c_szAfUpgradeFromProduct, pszProduct);
  1399. //BuildNumber
  1400. Assert (g_NetUpgradeInfo.From.dwBuildNumber);
  1401. pwisNetworking->AddKey(c_szAfBuildNumber, g_NetUpgradeInfo.From.dwBuildNumber);
  1402. }
  1403. // ----------------------------------------------------------------------
  1404. //
  1405. // Function: WriteNetworkInfoToAnswerFile
  1406. //
  1407. // Purpose: Write information about current network components
  1408. // to the answerfile
  1409. //
  1410. // Arguments:
  1411. // pwifAnswerFile [in] pointer to CWInfFile object
  1412. //
  1413. // Returns: TRUE on success, FALSE otherwise
  1414. //
  1415. // Author: kumarp 03-December-97
  1416. //
  1417. BOOL
  1418. WriteNetworkInfoToAnswerFile (
  1419. IN CWInfFile *pwifAnswerFile)
  1420. {
  1421. DefineFunctionName("WriteNetworkInfoToAnswerFile");
  1422. BOOL status=FALSE;
  1423. g_pslNetCard = new TStringList;
  1424. g_pslNetCardInstance = new TStringList;
  1425. g_pslNetCardAFileName = new TStringList;
  1426. Assert (g_NetUpgradeInfo.From.dwBuildNumber);
  1427. if ((g_NetUpgradeInfo.From.dwBuildNumber <= wWinNT4BuildNumber) &&
  1428. !FIsPreNT5NetworkingInstalled())
  1429. {
  1430. // this is NT4 or earlier and networking is not installed
  1431. // dont need to dump answerfile
  1432. TraceTag(ttidNetUpgrade, "%s: Networking is not installed, "
  1433. "answerfile will not be dumped", __FUNCNAME__);
  1434. goto return_from_function;
  1435. }
  1436. CWInfSection* pwisNetworking;
  1437. pwisNetworking =
  1438. pwifAnswerFile->AddSectionIfNotPresent(c_szAfSectionNetworking);
  1439. //The order in which these functions are called is important
  1440. //DO NOT change it
  1441. WriteProductTypeInfo(pwisNetworking);
  1442. status = WriteNt5OptionalComponentList(pwifAnswerFile);
  1443. status = HandlePostConnectionsSfmOcUpgrade(pwifAnswerFile);
  1444. WriteNetComponentsToRemove(pwisNetworking);
  1445. if (g_NetUpgradeInfo.From.dwBuildNumber > wWinNT4BuildNumber)
  1446. {
  1447. status = WriteDisableServicesListForNT5(pwifAnswerFile);
  1448. status = WritePerAdapterInfoForNT5(pwifAnswerFile);
  1449. // we dont want netsetup to process other sections
  1450. //
  1451. pwisNetworking->AddBoolKey(c_szAfProcessPageSections, FALSE);
  1452. //for NT5 to NT5 upgrade, no need to dump other info
  1453. //
  1454. goto return_from_function;
  1455. }
  1456. // we want netsetup to process other sections
  1457. //
  1458. pwisNetworking->AddBoolKey(c_szAfProcessPageSections, TRUE);
  1459. (void) HrWriteMainCleanSection(pwifAnswerFile);
  1460. status = WriteIdentificationInfo(pwifAnswerFile);
  1461. status = WriteNetAdaptersInfo(pwifAnswerFile);
  1462. pwifAnswerFile->GotoEnd();
  1463. g_pwisBindings = pwifAnswerFile->AddSection(c_szAfSectionNetBindings);
  1464. g_pwisBindings->AddComment(L"Only the disabled bindings are listed");
  1465. HrWriteNetComponentsInfo(pwifAnswerFile);
  1466. status = WriteDisableServicesList(pwifAnswerFile);
  1467. (void) HrHandleMiscSpecialCases(pwifAnswerFile);
  1468. WriteWinsockOrder(pwifAnswerFile);
  1469. return_from_function:
  1470. EraseAndDeleteAll(g_pslNetCard);
  1471. EraseAndDeleteAll(g_pslNetCardInstance);
  1472. EraseAndDeleteAll(g_pslNetCardAFileName);
  1473. DeleteIfNotNull(g_pslNetCard);
  1474. DeleteIfNotNull(g_pslNetCardInstance);
  1475. DeleteIfNotNull(g_pslNetCardAFileName);
  1476. return status;
  1477. }
  1478. //+---------------------------------------------------------------------------
  1479. //
  1480. // Function: WriteWinsockOrder
  1481. //
  1482. // Purpose: Records the order of winsock providers in NT4 so that they
  1483. // can be restored after upgrade.
  1484. //
  1485. // Arguments:
  1486. // pwifAnswerFile [in] Answer file structure
  1487. //
  1488. // Returns: Nothing
  1489. //
  1490. // Author: danielwe 1 Jun 1999
  1491. //
  1492. // Notes:
  1493. //
  1494. VOID WriteWinsockOrder (
  1495. IN CWInfFile* pwifAnswerFile)
  1496. {
  1497. AssertValidReadPtr(pwifAnswerFile);
  1498. DefineFunctionName("WriteWinsockOrder");
  1499. CWInfSection* pwisWinsock;
  1500. pwisWinsock = pwifAnswerFile->AddSection(c_szAfSectionWinsock);
  1501. if (pwisWinsock)
  1502. {
  1503. tstring strWinsockOrder;
  1504. INT nErr;
  1505. ULONG ulRes;
  1506. DWORD cbInfo = 0;
  1507. WSAPROTOCOL_INFO* pwpi = NULL;
  1508. WSAPROTOCOL_INFO* pwpiInfo = NULL;
  1509. LPWSCENUMPROTOCOLS pfnWSCEnumProtocols = NULL;
  1510. HMODULE hmod;
  1511. if (SUCCEEDED(HrLoadLibAndGetProc(L"ws2_32.dll",
  1512. "WSCEnumProtocols",
  1513. &hmod,
  1514. reinterpret_cast<FARPROC *>(&pfnWSCEnumProtocols))))
  1515. {
  1516. // First get the size needed
  1517. //
  1518. ulRes = pfnWSCEnumProtocols(NULL, NULL, &cbInfo, &nErr);
  1519. if ((SOCKET_ERROR == ulRes) && (WSAENOBUFS == nErr))
  1520. {
  1521. pwpi = reinterpret_cast<WSAPROTOCOL_INFO*>(new BYTE[cbInfo]);
  1522. if (pwpi)
  1523. {
  1524. // Find out all the protocols on the system
  1525. //
  1526. ulRes = pfnWSCEnumProtocols(NULL, pwpi, &cbInfo, &nErr);
  1527. if (SOCKET_ERROR != ulRes)
  1528. {
  1529. ULONG cProt;
  1530. WCHAR szCatId[64];
  1531. for (pwpiInfo = pwpi, cProt = ulRes;
  1532. cProt;
  1533. cProt--, pwpiInfo++)
  1534. {
  1535. wsprintfW(szCatId, L"%lu", pwpiInfo->dwCatalogEntryId);
  1536. if (cProt < ulRes)
  1537. {
  1538. // prepend a semicolon if not first time through
  1539. // we can't use a comma because setup will munge
  1540. // this string into separate strings and we don't
  1541. // want that
  1542. //
  1543. strWinsockOrder.append(L".");
  1544. }
  1545. strWinsockOrder.append(szCatId);
  1546. }
  1547. }
  1548. delete pwpi;
  1549. }
  1550. }
  1551. pwisWinsock->AddKey(c_szAfKeyWinsockOrder, strWinsockOrder.c_str());
  1552. FreeLibrary(hmod);
  1553. }
  1554. }
  1555. }
  1556. //+---------------------------------------------------------------------------
  1557. //
  1558. // Function: HrHandleMiscSpecialCases
  1559. //
  1560. // Purpose: Handle misc. special cases for upgrade
  1561. //
  1562. // Arguments:
  1563. // pwifAnswerFile [in] pointer to CWInfFile object
  1564. //
  1565. // Returns: S_OK on success, otherwise an error code
  1566. //
  1567. // Author: kumarp 28-January-99
  1568. //
  1569. HRESULT
  1570. HrHandleMiscSpecialCases (
  1571. IN CWInfFile* pwifAnswerFile)
  1572. {
  1573. AssertValidReadPtr(pwifAnswerFile);
  1574. DefineFunctionName("HrHandleMiscSpecialCases");
  1575. HRESULT hr=S_OK;
  1576. CWInfSection* pwisMiscUpgradeData;
  1577. pwisMiscUpgradeData = pwifAnswerFile->AddSection(c_szAfMiscUpgradeData);
  1578. // -------------------------------------------------------
  1579. // Tapi server upgrade
  1580. //
  1581. static const WCHAR c_szRegKeyTapiServer[] =
  1582. L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Server";
  1583. static const WCHAR c_szDisableSharing[] = L"DisableSharing";
  1584. HKEY hkeyTapiServer;
  1585. DWORD dwDisableSharing;
  1586. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyTapiServer,
  1587. KEY_READ, &hkeyTapiServer);
  1588. if (S_OK == hr)
  1589. {
  1590. hr = HrRegQueryDword(hkeyTapiServer, c_szDisableSharing,
  1591. &dwDisableSharing);
  1592. if ((S_OK == hr) && !dwDisableSharing)
  1593. {
  1594. pwisMiscUpgradeData->AddBoolKey(c_szAfTapiSrvRunInSeparateInstance,
  1595. TRUE);
  1596. }
  1597. RegCloseKey(hkeyTapiServer);
  1598. }
  1599. // -------------------------------------------------------
  1600. TraceErrorOptional(__FUNCNAME__, hr,
  1601. (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)));
  1602. return hr;
  1603. }
  1604. // ----------------------------------------------------------------------
  1605. // Computer Identification Page
  1606. // ----------------------------------------------------------------------
  1607. // ----------------------------------------------------------------------
  1608. //
  1609. // Function: GetDomainMembershipInfo
  1610. //
  1611. // Purpose: Determine domain membership status
  1612. //
  1613. // Arguments:
  1614. // fDomainMember [out] pointer to
  1615. // strName [out] name of name of
  1616. //
  1617. // Returns: TRUE on success, FALSE otherwise
  1618. //
  1619. // Author: kumarp 03-December-97
  1620. //
  1621. // Notes: Information on the APIs used in this function is in the file:
  1622. // public\spec\se\lsa\lsaapi.doc
  1623. //
  1624. BOOL
  1625. GetDomainMembershipInfo (
  1626. OUT BOOL* fDomainMember,
  1627. OUT tstring& strName)
  1628. {
  1629. BOOL status=FALSE;
  1630. LSA_HANDLE h=0;
  1631. POLICY_PRIMARY_DOMAIN_INFO* ppdi;
  1632. LSA_OBJECT_ATTRIBUTES loa;
  1633. ZeroMemory (&loa, sizeof(loa));
  1634. loa.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
  1635. NTSTATUS ntstatus;
  1636. ntstatus = LsaOpenPolicy(NULL, &loa, POLICY_VIEW_LOCAL_INFORMATION, &h);
  1637. if (FALSE == LSA_SUCCESS(ntstatus))
  1638. return FALSE;
  1639. ntstatus = LsaQueryInformationPolicy(h, PolicyPrimaryDomainInformation,
  1640. (VOID **) &ppdi);
  1641. if (LSA_SUCCESS(ntstatus))
  1642. {
  1643. *fDomainMember = ppdi->Sid > 0;
  1644. strName = ppdi->Name.Buffer;
  1645. status = TRUE;
  1646. }
  1647. LsaClose(h);
  1648. return status;
  1649. }
  1650. // ----------------------------------------------------------------------
  1651. //
  1652. // Function: WriteIdentificationInfo
  1653. //
  1654. // Purpose: Write computer identification info to the answerfile
  1655. //
  1656. // Arguments:
  1657. // pwifAnswerFile [in] pointer to CWInfFile object
  1658. //
  1659. // Returns: TRUE on success, FALSE otherwise
  1660. //
  1661. // Author: kumarp 03-December-97
  1662. //
  1663. BOOL
  1664. WriteIdentificationInfo (
  1665. IN CWInfFile *pwifAnswerFile)
  1666. {
  1667. DefineFunctionName("WriteIdentificationInfo");
  1668. TraceFunctionEntry(ttidNetUpgrade);
  1669. BOOL fStatus=FALSE;
  1670. PCWInfSection pwisIdentification =
  1671. pwifAnswerFile->AddSectionIfNotPresent(c_szAfSectionIdentification);
  1672. CORegKey *prkComputerName =
  1673. new CORegKey(HKEY_LOCAL_MACHINE, c_szRegValComputerName);
  1674. tstring strValue, strComment;
  1675. if(!prkComputerName)
  1676. {
  1677. goto error_cleanup;
  1678. }
  1679. //ComputerName
  1680. prkComputerName->QueryValue(c_szComputerName, strValue);
  1681. strComment = L"Computer '" + strValue + L"' is a member of the ";
  1682. BOOL fDomainMember;
  1683. fStatus = GetDomainMembershipInfo(&fDomainMember, strValue);
  1684. if (!fStatus)
  1685. goto error_cleanup;
  1686. strComment = strComment + L"'" + strValue + L"' ";
  1687. if (fDomainMember)
  1688. {
  1689. strComment = strComment + L"domain ";
  1690. }
  1691. else
  1692. {
  1693. strComment = strComment + L"workgroup ";
  1694. }
  1695. pwisIdentification->AddComment(strComment.c_str());
  1696. fStatus=TRUE;
  1697. goto cleanup;
  1698. error_cleanup:
  1699. fStatus = FALSE;
  1700. cleanup:
  1701. DeleteIfNotNull(prkComputerName);
  1702. return fStatus;
  1703. }
  1704. // ----------------------------------------------------------------------
  1705. // Net Cards Page
  1706. // ----------------------------------------------------------------------
  1707. //$ REVIEW kumarp 10-September-97
  1708. // this is a temporary fix only
  1709. //
  1710. // we want to avoid queryin the mac addr for these drivers because
  1711. // the drivers are faulty. the query never returns and it hangs netupgrd.dll
  1712. //
  1713. static const PCWSTR c_aszDriversToIgnoreWhenGettingMacAddr[] =
  1714. {
  1715. L"Diehl_ISDNSDI",
  1716. };
  1717. static const PCWSTR c_aszIrq[] =
  1718. {
  1719. L"IRQ",
  1720. L"INTERRUPT",
  1721. L"InterruptNumber",
  1722. L"IRQLevel"
  1723. };
  1724. static const PCWSTR c_aszIoAddr[] =
  1725. {
  1726. L"IOADDRESS",
  1727. L"IoBaseAddress",
  1728. L"BaseAddr"
  1729. };
  1730. static const PCWSTR c_aszMem[] =
  1731. {
  1732. L"Mem",
  1733. L"MemoryMappedBaseAddress"
  1734. };
  1735. static const PCWSTR c_aszDma[] =
  1736. {
  1737. L"DMA",
  1738. L"DMALevel"
  1739. };
  1740. static const PCWSTR c_aszAdapterParamsToIgnore[] =
  1741. {
  1742. L"BusType"
  1743. };
  1744. // ----------------------------------------------------------------------
  1745. //
  1746. // Function: WriteNetAdaptersInfo
  1747. //
  1748. // Purpose: Write information about installed net-adapters to the answerfile
  1749. //
  1750. // Arguments:
  1751. // pwifAnswerFile [in] pointer to CWInfFile object
  1752. //
  1753. // Returns: TRUE on success, FALSE otherwise
  1754. //
  1755. // Author: kumarp 03-December-97
  1756. //
  1757. BOOL
  1758. WriteNetAdaptersInfo (
  1759. IN CWInfFile *pwifAnswerFile)
  1760. {
  1761. DefineFunctionName("WriteNetAdaptersInfo");
  1762. TraceFunctionEntry(ttidNetUpgrade);
  1763. HRESULT hr=E_FAIL;
  1764. BOOL fStatus=FALSE;
  1765. UINT cNumPhysicalAdapters=0;
  1766. // ignore the errror, it is a non-error if we cannot find
  1767. // the cNumPhysicalAdapters
  1768. (void) HrGetNumPhysicalNetAdapters(&cNumPhysicalAdapters);
  1769. CORegKey *prkNetworkCards = NULL;
  1770. tstring strNetAdapterInstance;
  1771. tstring strUnsupportedMessage;
  1772. CORegKeyIter *prkiNetAdapters = NULL;
  1773. CORegKey *prkNetAdapterInstance=NULL, *prkNetRules=NULL;
  1774. CWInfSection *pwisNetAdapters;
  1775. CWInfSection *pwisNetAdapterParams=NULL;
  1776. CWInfSection *pwisNetAdapterAdditionalParams=NULL;
  1777. tstring strNT5InfId;
  1778. tstring strAdapterType;
  1779. // WLBS: find out which netcard WLBS is bound to
  1780. pszWlbsClusterAdapterName[0] = pszWlbsVirtualAdapterName[0] = 0;
  1781. tstring strWlbsClusterAdapterDriver, strWlbsVirtualAdapterDriver;
  1782. TStringList slWlbsLinkage;
  1783. CORegKey *prkWlbsLinkage =
  1784. new CORegKey(HKEY_LOCAL_MACHINE, c_szRegWlbsLinkage, KEY_READ);
  1785. if(!prkWlbsLinkage) {
  1786. return false;
  1787. }
  1788. CORegKey *prkConvoyLinkage =
  1789. new CORegKey(HKEY_LOCAL_MACHINE, c_szRegConvoyLinkage, KEY_READ);
  1790. if(!prkConvoyLinkage) {
  1791. delete prkWlbsLinkage;
  1792. return false;
  1793. }
  1794. if ((prkWlbsLinkage->HKey() != NULL && prkWlbsLinkage->QueryValue(c_szRegValBind, slWlbsLinkage) == ERROR_SUCCESS) ||
  1795. (prkConvoyLinkage->HKey() != NULL && prkConvoyLinkage->QueryValue(c_szRegValBind, slWlbsLinkage) == ERROR_SUCCESS))
  1796. {
  1797. TraceTag(ttidNetUpgrade, "%s: WLBS found - iterating", __FUNCNAME__);
  1798. TStringListIter iter;
  1799. tstring strTmp;
  1800. DWORD i;
  1801. // proper WLBS configuration will have only two bindings - one to the
  1802. // wlbs virtual NIC, the other to the cluster NIC
  1803. for (i = 0, iter = slWlbsLinkage.begin();
  1804. i < 2 && iter != slWlbsLinkage.end(); i++, iter++)
  1805. {
  1806. strTmp = **iter;
  1807. TraceTag(ttidNetUpgrade, "%s: WLBS bound to %S",
  1808. __FUNCNAME__, strTmp.c_str());
  1809. strTmp.erase(0, 8);
  1810. TraceTag(ttidNetUpgrade, "%s: WLBS now bound to %S",
  1811. __FUNCNAME__, strTmp.c_str());
  1812. if (strTmp.find(c_szWLBS) != tstring::npos ||
  1813. strTmp.find(c_szConvoy) != tstring::npos)
  1814. {
  1815. strWlbsVirtualAdapterDriver = strTmp;
  1816. }
  1817. else
  1818. {
  1819. strWlbsClusterAdapterDriver = strTmp;
  1820. }
  1821. }
  1822. if (iter != slWlbsLinkage.end())
  1823. {
  1824. TraceTag(ttidNetUpgrade, "%s: WLBS bound to more than one NIC!",
  1825. __FUNCNAME__);
  1826. }
  1827. TraceTag(ttidNetUpgrade, "%s: WLBS is bound to %S and %S", __FUNCNAME__,
  1828. strWlbsVirtualAdapterDriver.c_str(),
  1829. strWlbsClusterAdapterDriver.c_str());
  1830. }
  1831. delete prkWlbsLinkage;
  1832. delete prkConvoyLinkage;
  1833. // end WLBS:
  1834. pwisNetAdapters = pwifAnswerFile->AddSection(c_szAfSectionNetAdapters);
  1835. prkNetworkCards =
  1836. new CORegKey(HKEY_LOCAL_MACHINE, c_szRegKeyAdapterHome, KEY_READ);
  1837. if(prkNetworkCards)
  1838. {
  1839. prkiNetAdapters = new CORegKeyIter(*prkNetworkCards);
  1840. prkiNetAdapters->Reset();
  1841. }
  1842. WORD wNumAdapters = 0;
  1843. CORegKey *prkAdapterDriverParams=NULL;
  1844. BOOL fAbortFunction=FALSE;
  1845. // This determines if we will write the line under NetAdapters to
  1846. // reference the params section for this adapter.
  1847. //
  1848. BOOL fWriteNetAdaptersReference;
  1849. while (!fAbortFunction && prkiNetAdapters && !prkiNetAdapters->Next(&strNetAdapterInstance))
  1850. {
  1851. DWORD dwHidden=0, err=0;
  1852. WCHAR pszAdapterName[16], pszAdapterSectionName[256];
  1853. WCHAR pszAdapterAdditionalParamsSectionName[256];
  1854. tstring strPreNT5InfId, strAdapterDescription, strAdapterDescComment;
  1855. fWriteNetAdaptersReference = FALSE;
  1856. prkNetAdapterInstance =
  1857. new CORegKey(*prkNetworkCards, strNetAdapterInstance.c_str());
  1858. // for REAL netcards, "Hidden" is absent or if present the value is 0
  1859. BOOL fRealNetCard;
  1860. err = prkNetAdapterInstance->QueryValue(L"Hidden", dwHidden);
  1861. fRealNetCard = (err != ERROR_SUCCESS) || (dwHidden == 0);
  1862. prkNetAdapterInstance->QueryValue(c_szRegValDescription,
  1863. strAdapterDescription);
  1864. swprintf(pszAdapterName, L"Adapter%02d", ++wNumAdapters);
  1865. TraceTag(ttidNetUpgrade, "%s: writing info for adapter %S (%S)",
  1866. __FUNCNAME__, pszAdapterName, strNetAdapterInstance.c_str());
  1867. // Now, create adapter parameters sections
  1868. swprintf(pszAdapterSectionName, L"%s%s", c_szAfParams, pszAdapterName);
  1869. //pwisNetAdapters->AddKey(pszAdapterName, pszAdapterSectionName);
  1870. swprintf(pszAdapterAdditionalParamsSectionName, L"%s%s.Additional",
  1871. c_szAfParams, pszAdapterName);
  1872. if (NULL != pwisNetAdapterParams)
  1873. pwifAnswerFile->GotoEndOfSection(pwisNetAdapterParams);
  1874. pwisNetAdapterParams = pwifAnswerFile->AddSection(pszAdapterSectionName);
  1875. pwisNetAdapterAdditionalParams =
  1876. pwifAnswerFile->AddSection(pszAdapterAdditionalParamsSectionName);
  1877. // moved up here from below so that for WLBS adapter we can set
  1878. // fRealNetCard to FALSE
  1879. tstring strAdapterDriver;
  1880. prkNetAdapterInstance->QueryValue(c_szRegValServiceName,
  1881. strAdapterDriver);
  1882. // WLBS: based on pre-upgrade instance, find out virtual and cluster
  1883. // NIC adapter instances
  1884. if (_wcsicmp (strAdapterDriver.c_str(),
  1885. strWlbsVirtualAdapterDriver.c_str()) == 0)
  1886. {
  1887. TraceTag(ttidNetUpgrade, "%s: WLBS virtual adapter is %S",
  1888. __FUNCNAME__, pszAdapterName);
  1889. wcscpy(pszWlbsVirtualAdapterName, pszAdapterName);
  1890. fRealNetCard = FALSE;
  1891. }
  1892. else if (_wcsicmp (strAdapterDriver.c_str(),
  1893. strWlbsClusterAdapterDriver.c_str()) == 0)
  1894. {
  1895. TraceTag(ttidNetUpgrade, "%s: WLBS cluster adapter is %S",
  1896. __FUNCNAME__, pszAdapterName);
  1897. wcscpy(pszWlbsClusterAdapterName, pszAdapterName);
  1898. }
  1899. // end WLBS:
  1900. prkNetRules = new CORegKey(*prkNetAdapterInstance, c_szRegKeyNetRules);
  1901. prkNetRules->QueryValue(c_szRegValInfOption, strPreNT5InfId);
  1902. if (fRealNetCard)
  1903. {
  1904. strAdapterDescComment =
  1905. tstring(L"Net Card: ") + strPreNT5InfId +
  1906. tstring(L" (") + strAdapterDescription + tstring(L")");
  1907. }
  1908. else
  1909. {
  1910. strAdapterDescComment =
  1911. tstring(L"Pseudo Adapter: ") + strAdapterDescription;
  1912. }
  1913. ReplaceCharsInString((PWSTR) strAdapterDescComment.c_str(),
  1914. L"\n\r", L' ');
  1915. pwisNetAdapterParams->AddComment(strAdapterDescComment.c_str());
  1916. pwisNetAdapterParams->AddKey(c_szAfAdditionalParams,
  1917. pszAdapterAdditionalParamsSectionName);
  1918. pwisNetAdapterParams->AddBoolKey(c_szAfPseudoAdapter, !fRealNetCard);
  1919. pwisNetAdapterParams->AddKey(c_szAfPreUpgradeInstance,
  1920. strAdapterDriver.c_str());
  1921. tstring strProductName;
  1922. prkNetAdapterInstance->QueryValue(L"ProductName", strProductName);
  1923. AddToNetCardDB(pszAdapterName, strProductName.c_str(),
  1924. strAdapterDriver.c_str());
  1925. // We need to look at the ndiswan instances (if any) to decide
  1926. // which RAS components we need to install.
  1927. // the algorithm is like this
  1928. //
  1929. // - for each <instance> in
  1930. // software\microsoft\windows nt\currentversion\networkcards\<instance>
  1931. // - if atleast one <intance>\ProductName
  1932. // - begins with "ndiswan" AND
  1933. // - has string "in" in it --> install ms_rassrv
  1934. // - has string "out" in it --> install ms_rascli
  1935. //
  1936. PCWSTR pszProductName;
  1937. pszProductName = strProductName.c_str();
  1938. if (FIsPrefix(c_szNdisWan, pszProductName))
  1939. {
  1940. static const WCHAR c_szIn[] = L"in";
  1941. static const WCHAR c_szOut[] = L"out";
  1942. if (wcsstr(pszProductName, c_szIn))
  1943. {
  1944. TraceTag(ttidNetUpgrade,
  1945. "%s: g_fAtLeastOneDialInUsingNdisWan set to TRUE because of %S",
  1946. __FUNCNAME__, pszProductName);
  1947. g_fAtLeastOneDialInUsingNdisWan = TRUE;
  1948. }
  1949. if (wcsstr(pszProductName, c_szOut))
  1950. {
  1951. TraceTag(ttidNetUpgrade,
  1952. "%s: g_fAtLeastOneDialOutUsingNdisWan set to TRUE because of %S",
  1953. __FUNCNAME__, pszProductName);
  1954. g_fAtLeastOneDialOutUsingNdisWan = TRUE;
  1955. }
  1956. }
  1957. if (!fRealNetCard)
  1958. {
  1959. pwisNetAdapterParams->AddKey(c_szAfInfid, strPreNT5InfId.c_str());
  1960. //The rest of the keys are for real net cards only
  1961. goto cleanup_for_this_iteration;
  1962. }
  1963. //EthernetAddress
  1964. if (!FIsInStringArray(c_aszDriversToIgnoreWhenGettingMacAddr,
  1965. celems(c_aszDriversToIgnoreWhenGettingMacAddr),
  1966. strProductName.c_str()))
  1967. {
  1968. QWORD qwEthernetAddress;
  1969. // ignore the error if we cannot get the netcard address
  1970. // this error is non-fatal
  1971. // Based on what build we are on, we call a different API to
  1972. // get netcard address. Currently, this code path isn't executed
  1973. // on any NT5 to NT5 upgrade, but if it changes, we want to use
  1974. // the newer api.
  1975. //
  1976. if (g_NetUpgradeInfo.From.dwBuildNumber < 2031) // Pre-Beta3
  1977. {
  1978. (VOID) HrGetNetCardAddrOld(strAdapterDriver.c_str(), &qwEthernetAddress);
  1979. }
  1980. else
  1981. {
  1982. (VOID) HrGetNetCardAddr(strAdapterDriver.c_str(), &qwEthernetAddress);
  1983. }
  1984. pwisNetAdapterParams->AddQwordKey(c_szAfNetCardAddr, qwEthernetAddress);
  1985. fWriteNetAdaptersReference = (0 != qwEthernetAddress);
  1986. }
  1987. else
  1988. {
  1989. TraceTag(ttidNetUpgrade, "%s: did not query %S for mac address",
  1990. __FUNCNAME__, strProductName.c_str());
  1991. }
  1992. GetServiceParamsKey(strAdapterDriver.c_str(), prkAdapterDriverParams);
  1993. //write INFID key
  1994. HKEY hkeyAdapterDriverParams;
  1995. if (prkAdapterDriverParams)
  1996. {
  1997. hkeyAdapterDriverParams = prkAdapterDriverParams->HKey();
  1998. }
  1999. else
  2000. {
  2001. hkeyAdapterDriverParams = NULL;
  2002. }
  2003. BOOL fIsOemAdapter;
  2004. CNetMapInfo* pnmi;
  2005. fIsOemAdapter = FALSE;
  2006. pnmi = NULL;
  2007. hr = HrMapPreNT5NetCardInfIdToNT5InfId(hkeyAdapterDriverParams,
  2008. strPreNT5InfId.c_str(),
  2009. &strNT5InfId,
  2010. &strAdapterType,
  2011. &fIsOemAdapter, &pnmi);
  2012. if (S_OK == hr)
  2013. {
  2014. if (!lstrcmpiW(strAdapterType.c_str(), c_szAsyncAdapters) ||
  2015. !lstrcmpiW(strAdapterType.c_str(), c_szOemAsyncAdapters))
  2016. {
  2017. CWInfSection* pwisAsyncCards;
  2018. pwisAsyncCards =
  2019. pwifAnswerFile->AddSectionIfNotPresent(c_szAsyncAdapters);
  2020. if (pwisAsyncCards)
  2021. {
  2022. pwisAsyncCards->AddKey(pszAdapterName,
  2023. pszAdapterSectionName);
  2024. }
  2025. }
  2026. else
  2027. {
  2028. fWriteNetAdaptersReference = TRUE;
  2029. }
  2030. }
  2031. else
  2032. {
  2033. GetUnsupportedMessage(c_szNetCard, strAdapterDescription.c_str(),
  2034. strPreNT5InfId.c_str(), &strUnsupportedMessage);
  2035. pwisNetAdapterParams->AddComment(strUnsupportedMessage.c_str());
  2036. strNT5InfId = c_szAfUnknown;
  2037. TraceTag(ttidNetUpgrade, "WriteNetAdaptersInfo: %S",
  2038. strUnsupportedMessage.c_str());
  2039. }
  2040. if (fWriteNetAdaptersReference)
  2041. {
  2042. // We have enough information to determine which adapter goes
  2043. // with this section so write out the reference.
  2044. //
  2045. pwisNetAdapters->AddKey(pszAdapterName, pszAdapterSectionName);
  2046. }
  2047. if (1 == cNumPhysicalAdapters)
  2048. {
  2049. TraceTag(ttidNetUpgrade, "%s: dumped '*' as InfID for %S",
  2050. __FUNCNAME__, strNT5InfId.c_str());
  2051. pwisNetAdapterParams->AddKey(c_szAfInfid, L"*");
  2052. pwisNetAdapterParams->AddKey(c_szAfInfidReal, strNT5InfId.c_str());
  2053. }
  2054. else
  2055. {
  2056. pwisNetAdapterParams->AddKey(c_szAfInfid, strNT5InfId.c_str());
  2057. }
  2058. if (!prkAdapterDriverParams)
  2059. {
  2060. // since we could not open the driver params key
  2061. // we cant dump parameters. just skip this card and continue
  2062. goto cleanup_for_this_iteration;
  2063. }
  2064. // -----------------------------------------------------------------
  2065. // OEM upgrade code
  2066. //
  2067. if (fIsOemAdapter)
  2068. {
  2069. hr = HrProcessOemComponentAndUpdateAfSection(
  2070. pnmi, NULL,
  2071. prkAdapterDriverParams->HKey(),
  2072. strPreNT5InfId.c_str(),
  2073. strAdapterDriver.c_str(),
  2074. strNT5InfId.c_str(),
  2075. strAdapterDescription.c_str(),
  2076. pwisNetAdapterParams);
  2077. // OEM upgrade may be aborted because of a fatal error or
  2078. // if an OEM DLL requests it. in both cases we need to stop
  2079. // our current answerfile generation
  2080. //
  2081. if (FIsUpgradeAborted())
  2082. {
  2083. fAbortFunction = TRUE;
  2084. goto cleanup_for_this_iteration;
  2085. }
  2086. }
  2087. // -----------------------------------------------------------------
  2088. //BusType
  2089. DWORD dwBusType;
  2090. INTERFACE_TYPE eBusType;
  2091. prkAdapterDriverParams->QueryValue(L"BusType", dwBusType);
  2092. eBusType = (INTERFACE_TYPE) dwBusType;
  2093. pwisNetAdapterParams->AddKey(c_szAfBusType,
  2094. GetBusTypeName(eBusType));
  2095. // for certain ISA cards the driver parameters store EISA as the bus type
  2096. // when these cards are installed in EISA slots. Thus we have to dump parameters
  2097. // when BusType is Eisa.
  2098. //
  2099. BOOL fDumpResources;
  2100. fDumpResources = ((eBusType == Isa) || (eBusType == Eisa));
  2101. // kumarp 14-July-97
  2102. // this fix has been requested by billbe.
  2103. // we do not dump hardware resources for the ISAPNP cards
  2104. //
  2105. if (!lstrcmpiW(strPreNT5InfId.c_str(), L"IEEPRO") ||
  2106. !lstrcmpiW(strPreNT5InfId.c_str(), L"ELNK3ISA509"))
  2107. {
  2108. fDumpResources = FALSE;
  2109. }
  2110. DWORD dwIndex;
  2111. dwIndex = 0;
  2112. DWORD dwValueNameLen, dwValueType;
  2113. WCHAR szValueName[REGSTR_MAX_VALUE_LENGTH+1];
  2114. PCWSTR pszResourceName;
  2115. DWORD dwValueDumpFormat;
  2116. do
  2117. {
  2118. dwValueNameLen = REGSTR_MAX_VALUE_LENGTH;
  2119. hr = HrRegEnumValue(prkAdapterDriverParams->HKey(),
  2120. dwIndex, szValueName, &dwValueNameLen,
  2121. &dwValueType, NULL, NULL);
  2122. if (hr == S_OK)
  2123. {
  2124. pszResourceName = NULL;
  2125. dwValueDumpFormat = REG_HEX;
  2126. dwIndex++;
  2127. if (FIsInStringArray(c_aszIrq,
  2128. celems(c_aszIrq), szValueName))
  2129. {
  2130. pszResourceName = c_szAfIrq;
  2131. dwValueDumpFormat = REG_DWORD;
  2132. }
  2133. else if (FIsInStringArray(c_aszIoAddr,
  2134. celems(c_aszIoAddr), szValueName))
  2135. {
  2136. pszResourceName = c_szAfIoAddr;
  2137. }
  2138. else if (FIsInStringArray(c_aszMem,
  2139. celems(c_aszMem), szValueName))
  2140. {
  2141. pszResourceName = c_szAfMem;
  2142. }
  2143. else if (FIsInStringArray(c_aszDma,
  2144. celems(c_aszDma), szValueName))
  2145. {
  2146. pszResourceName = c_szAfDma;
  2147. }
  2148. if (pszResourceName)
  2149. {
  2150. if (fDumpResources)
  2151. {
  2152. WriteRegValueToAFile(pwisNetAdapterParams,
  2153. *prkAdapterDriverParams,
  2154. szValueName, dwValueDumpFormat,
  2155. pszResourceName);
  2156. }
  2157. }
  2158. else if (!FIsInStringArray(c_aszAdapterParamsToIgnore,
  2159. celems(c_aszAdapterParamsToIgnore),
  2160. szValueName))
  2161. {
  2162. WriteRegValueToAFile(pwisNetAdapterAdditionalParams,
  2163. *prkAdapterDriverParams,
  2164. szValueName, dwValueType);
  2165. }
  2166. }
  2167. }
  2168. while (hr == S_OK);
  2169. cleanup_for_this_iteration:
  2170. DeleteIfNotNull(prkNetAdapterInstance);
  2171. DeleteIfNotNull(prkNetRules);
  2172. DeleteIfNotNull(prkAdapterDriverParams);
  2173. }
  2174. // WLBS: if either cluster or virtual adapter were not matched - blow off
  2175. // WLBS-specific upgrade code
  2176. if (pszWlbsClusterAdapterName[0] == 0 || pszWlbsVirtualAdapterName[0] ==0)
  2177. {
  2178. pszWlbsClusterAdapterName[0] = pszWlbsVirtualAdapterName[0] = 0;
  2179. }
  2180. // end WLBS:
  2181. fStatus=TRUE;
  2182. goto cleanup;
  2183. fStatus=FALSE;
  2184. cleanup:
  2185. DeleteIfNotNull(prkNetworkCards);
  2186. DeleteIfNotNull(prkiNetAdapters);
  2187. return fStatus;
  2188. }
  2189. // ----------------------------------------------------------------------
  2190. //
  2191. // Function: HrGetNumPhysicalNetAdapters
  2192. //
  2193. // Purpose: Count and return number of physical adapters installed
  2194. //
  2195. // Arguments:
  2196. // puNumAdapters [out] pointer to num adapters
  2197. //
  2198. // Returns: S_OK on success, otherwise an error code
  2199. //
  2200. // Author: kumarp 29-May-98
  2201. //
  2202. HRESULT
  2203. HrGetNumPhysicalNetAdapters (
  2204. OUT UINT* puNumAdapters)
  2205. {
  2206. AssertValidWritePtr(puNumAdapters);
  2207. DefineFunctionName("HrGetNumPhysicalNetAdapters");
  2208. HRESULT hr;
  2209. HKEY hkeyAdapters;
  2210. HKEY hkeyAdapter;
  2211. DWORD dwHidden;
  2212. BOOL fRealNetCard = FALSE;
  2213. *puNumAdapters = 0;
  2214. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeyAdapterHome,
  2215. KEY_READ, &hkeyAdapters);
  2216. if (S_OK == hr)
  2217. {
  2218. WCHAR szBuf[MAX_PATH];
  2219. FILETIME time;
  2220. DWORD dwSize;
  2221. DWORD dwRegIndex;
  2222. for (dwRegIndex = 0, dwSize = celems(szBuf);
  2223. S_OK == HrRegEnumKeyEx(hkeyAdapters, dwRegIndex, szBuf,
  2224. &dwSize, NULL, NULL, &time);
  2225. dwRegIndex++, dwSize = celems(szBuf))
  2226. {
  2227. Assert(*szBuf);
  2228. hr = HrRegOpenKeyEx(hkeyAdapters, szBuf, KEY_READ, &hkeyAdapter);
  2229. if (hr == S_OK)
  2230. {
  2231. hr = HrRegQueryDword(hkeyAdapter, c_szHidden, &dwHidden);
  2232. // for REAL netcards, "Hidden" is absent or if present the value is 0
  2233. if (S_OK == hr)
  2234. {
  2235. fRealNetCard = (0 == dwHidden);
  2236. }
  2237. else if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
  2238. {
  2239. fRealNetCard = TRUE;
  2240. hr = S_OK;
  2241. }
  2242. if ((S_OK == hr) && fRealNetCard)
  2243. {
  2244. (*puNumAdapters)++;
  2245. }
  2246. RegCloseKey(hkeyAdapter);
  2247. }
  2248. }
  2249. RegCloseKey(hkeyAdapters);
  2250. }
  2251. TraceTag(ttidNetUpgrade, "%s: Found %d physical net adapters",
  2252. __FUNCNAME__, *puNumAdapters);
  2253. TraceError(__FUNCNAME__, hr);
  2254. return hr;
  2255. }
  2256. // ----------------------------------------------------------------------
  2257. //
  2258. // Function: IsNetworkComponent
  2259. //
  2260. // Purpose: Determine if a component is a net-component
  2261. //
  2262. // Arguments:
  2263. // prkSoftwareMicrosoft [in] pointer to CORegKey object
  2264. // strComponentName [in] constTString object name of
  2265. //
  2266. // Returns:
  2267. //
  2268. // Author: kumarp 03-December-97
  2269. //
  2270. // Notes: any software that has a NetRules key under the CurrentVersion
  2271. // key is considered a network component
  2272. //
  2273. BOOL
  2274. IsNetworkComponent (
  2275. IN CORegKey *prkSoftwareMicrosoft,
  2276. IN const tstring strComponentName)
  2277. {
  2278. tstring strNetRules = strComponentName + L"\\CurrentVersion\\NetRules";
  2279. CORegKey rkNetRules((HKEY) *prkSoftwareMicrosoft, strNetRules.c_str());
  2280. return (((HKEY) rkNetRules) != NULL);
  2281. }
  2282. // ----------------------------------------------------------------------
  2283. // Network components (protocols, services)
  2284. // ----------------------------------------------------------------------
  2285. typedef BOOL (*WriteNetComponentParamsFn)(
  2286. IN CWInfFile* pwifAnswerFile,
  2287. IN CWInfSection* pwisGlobalParams);
  2288. static PCWSTR c_aszNetComponents[] =
  2289. {
  2290. L"RASPPTP",
  2291. L"Browser",
  2292. c_szSvcWorkstation,
  2293. L"RpcLocator",
  2294. L"LanmanServer",
  2295. c_szSvcNetBIOS,
  2296. c_szSvcNWCWorkstation,
  2297. c_szSvcDhcpServer,
  2298. L"ISOTP",
  2299. c_szWLBS,
  2300. c_szConvoy
  2301. };
  2302. static WriteNetComponentParamsFn c_afpWriteParamsFns[] =
  2303. {
  2304. WritePPTPParams,
  2305. WriteBrowserParams,
  2306. WriteLanmanWorkstationParams,
  2307. WriteRPCLocatorParams,
  2308. WriteLanmanServerParams,
  2309. WriteNetBIOSParams,
  2310. WriteNWCWorkstationParams,
  2311. WriteDhcpServerParams,
  2312. WriteTp4Params,
  2313. WriteWLBSParams,
  2314. WriteConvoyParams
  2315. };
  2316. typedef BOOL (*WriteNetComponentParamsAndAdapterSectionsFn)(
  2317. IN CWInfFile* pwifAnswerFile,
  2318. IN CWInfSection* pwisGlobalParams,
  2319. OUT TStringList& slAdditionalParamsSections);
  2320. static const PCWSTR c_aszNetComponentsWithAdapterSpecificParams[] =
  2321. {
  2322. L"Tcpip",
  2323. L"NwlnkIpx",
  2324. L"AppleTalk"
  2325. };
  2326. static WriteNetComponentParamsAndAdapterSectionsFn
  2327. c_afpWriteParamsAndAdapterSectionsFns[] =
  2328. {
  2329. WriteTCPIPParams,
  2330. WriteIPXParams,
  2331. WriteAppleTalkParams
  2332. };
  2333. // ----------------------------------------------------------------------
  2334. //
  2335. // Function: HrWriteNetComponentInfo
  2336. //
  2337. // Purpose: Write info of the specified component to the answerfile
  2338. //
  2339. // Arguments:
  2340. // szNetComponent [in] net component
  2341. // pwifAnswerFile [in] pointer to CWInfFile object (answerfile)
  2342. // hkeyCurrentVersion [in] handle of CurrentVersion regkey
  2343. //
  2344. // Returns: S_OK on success, otherwise an error code
  2345. //
  2346. // Author: kumarp 13-May-98
  2347. //
  2348. HRESULT
  2349. HrWriteNetComponentInfo (
  2350. IN PCWSTR szNetComponent,
  2351. IN CWInfFile* pwifAnswerFile,
  2352. IN HKEY hkeyCurrentVersion)
  2353. {
  2354. DefineFunctionName("HrWriteNetComponentInfo");
  2355. HRESULT hr=S_OK;
  2356. tstring strPreNT5InfId;
  2357. tstring strNT5InfId;
  2358. tstring strProductCurrentVersion;
  2359. tstring strDescription;
  2360. tstring strSoftwareType;
  2361. tstring strParamsSectionName;
  2362. TStringList slAdditionalParamsSections;
  2363. BOOL fIsOemComponent;
  2364. UINT uIndex;
  2365. CWInfSection* pwisNetComponents;
  2366. CWInfSection* pwisNetComponentParams;
  2367. ENetComponentType nct=NCT_Unknown;
  2368. PCWSTR szNetComponentsSection;
  2369. CNetMapInfo* pnmi;
  2370. static BOOL fRasParamsDumped=FALSE;
  2371. hr = HrGetPreNT5InfIdAndDesc(hkeyCurrentVersion,
  2372. &strPreNT5InfId, &strDescription,
  2373. NULL);
  2374. if (S_OK == hr)
  2375. {
  2376. TraceTag(ttidNetUpgrade, "%s: processing '[%S] %S'",
  2377. __FUNCNAME__, strPreNT5InfId.c_str(), strDescription.c_str());
  2378. hr = HrMapPreNT5NetComponentInfIDToNT5InfID(
  2379. strPreNT5InfId.c_str(), &strNT5InfId,
  2380. &fIsOemComponent, &nct, &pnmi);
  2381. if (S_OK == hr)
  2382. {
  2383. Assert((nct >= NCT_Adapter) &&
  2384. (nct <= NCT_Client));
  2385. // add the top level section [Net*] if not present
  2386. szNetComponentsSection =
  2387. g_szNetComponentSectionName[nct];
  2388. pwisNetComponents =
  2389. pwifAnswerFile->AddSectionIfNotPresent(
  2390. szNetComponentsSection);
  2391. strParamsSectionName = c_szAfParams + strNT5InfId;
  2392. if (!pwisNetComponents->FindKey(strNT5InfId.c_str(),
  2393. ISM_FromBeginning))
  2394. {
  2395. pwisNetComponentParams =
  2396. pwifAnswerFile->AddSection(strParamsSectionName.c_str());
  2397. // RAS is a special case.
  2398. if (0 != _wcsicmp(strNT5InfId.c_str(), c_szRAS))
  2399. {
  2400. pwisNetComponents->AddKey(strNT5InfId.c_str(),
  2401. strParamsSectionName.c_str());
  2402. }
  2403. }
  2404. else
  2405. {
  2406. pwisNetComponentParams =
  2407. pwifAnswerFile->FindSection(strParamsSectionName.c_str());
  2408. }
  2409. AssertSz(pwisNetComponentParams,
  2410. "HrWriteNetComponentInfo: Need a section to add key to!");
  2411. if (FIsInStringArray(c_aszNetComponents,
  2412. celems(c_aszNetComponents),
  2413. szNetComponent, &uIndex))
  2414. {
  2415. c_afpWriteParamsFns[uIndex](pwifAnswerFile,
  2416. pwisNetComponentParams);
  2417. }
  2418. else if (FIsInStringArray(
  2419. c_aszNetComponentsWithAdapterSpecificParams,
  2420. celems(c_aszNetComponentsWithAdapterSpecificParams),
  2421. szNetComponent, &uIndex))
  2422. {
  2423. EraseAndDeleteAll(slAdditionalParamsSections);
  2424. c_afpWriteParamsAndAdapterSectionsFns[uIndex]
  2425. (pwifAnswerFile,
  2426. pwisNetComponentParams,
  2427. slAdditionalParamsSections);
  2428. if (!slAdditionalParamsSections.empty())
  2429. {
  2430. pwisNetComponentParams->AddKey(c_szAfAdapterSections,
  2431. slAdditionalParamsSections);
  2432. }
  2433. }
  2434. else if (!lstrcmpiW(strNT5InfId.c_str(), c_szRAS) &&
  2435. !fRasParamsDumped)
  2436. {
  2437. fRasParamsDumped = TRUE;
  2438. WriteRASParams(pwifAnswerFile,
  2439. pwisNetComponents,
  2440. pwisNetComponentParams);
  2441. }
  2442. else if (fIsOemComponent)
  2443. {
  2444. HKEY hkeyServiceParams=NULL;
  2445. tstring strServiceName;
  2446. hr = HrRegQueryString(hkeyCurrentVersion,
  2447. c_szRegValServiceName,
  2448. &strServiceName);
  2449. if (S_OK == hr)
  2450. {
  2451. AssertSz(!strServiceName.empty(),
  2452. "Service name is empty for OEM component!!");
  2453. hr = HrRegOpenServiceSubKey(strServiceName.c_str(),
  2454. c_szParameters,
  2455. KEY_READ,
  2456. &hkeyServiceParams);
  2457. if (S_OK == hr)
  2458. {
  2459. hr = HrProcessOemComponentAndUpdateAfSection(
  2460. pnmi, NULL,
  2461. hkeyServiceParams, // Parameters reg key
  2462. strPreNT5InfId.c_str(),
  2463. strServiceName.c_str(),
  2464. strNT5InfId.c_str(),
  2465. strDescription.c_str(),
  2466. pwisNetComponentParams);
  2467. // OEM upgrade may be aborted because of a fatal error or
  2468. // if an OEM DLL requests it. in both cases we need to
  2469. // stop our current answerfile generation
  2470. if (FIsUpgradeAborted())
  2471. {
  2472. TraceTag(ttidNetUpgrade,
  2473. "%s: upgrade aborted by %S",
  2474. __FUNCNAME__, strNT5InfId.c_str());
  2475. }
  2476. }
  2477. else
  2478. {
  2479. TraceTag(ttidNetUpgrade,
  2480. "%s: could not open Parameters key for '%S'",
  2481. __FUNCNAME__, strServiceName.c_str());
  2482. }
  2483. }
  2484. }
  2485. else
  2486. {
  2487. TraceTag(ttidNetUpgrade, "%s: '%S' Unknown component!!",
  2488. __FUNCNAME__, strPreNT5InfId.c_str());
  2489. }
  2490. }
  2491. else if (S_FALSE == hr)
  2492. {
  2493. CWInfSection* pwisNetworking;
  2494. pwisNetworking = pwifAnswerFile->FindSection(c_szAfSectionNetworking);
  2495. if (pwisNetworking)
  2496. {
  2497. tstring strUnsupportedMessage;
  2498. GetUnsupportedMessage(NULL,
  2499. strDescription.c_str(),
  2500. strPreNT5InfId.c_str(),
  2501. &strUnsupportedMessage);
  2502. pwisNetworking->AddComment(strUnsupportedMessage.c_str());
  2503. }
  2504. }
  2505. else if (FAILED(hr))
  2506. {
  2507. TraceTag(ttidNetUpgrade,
  2508. "%s: mapping failed, skipped '%S'",
  2509. __FUNCNAME__, szNetComponent);
  2510. hr = S_OK;
  2511. }
  2512. }
  2513. else
  2514. {
  2515. TraceTag(ttidNetUpgrade,
  2516. "%s: HrGetPreNT5InfIdAndDesc failed, "
  2517. "skipped '%S'", __FUNCNAME__, szNetComponent);
  2518. hr = S_OK;
  2519. }
  2520. TraceError(__FUNCNAME__, hr);
  2521. return hr;
  2522. }
  2523. // ----------------------------------------------------------------------
  2524. //
  2525. // Function: WriteNetComponentInfoForProvider
  2526. //
  2527. // Purpose: Write info on installed net components (except net cards)
  2528. // of the specified provider to the answerfile
  2529. //
  2530. // Arguments:
  2531. // pszSoftwareProvider [in] name of provider
  2532. // pwifAnswerFile [in] pointer to CWInfFile object (answerfile)
  2533. //
  2534. // Returns: S_OK on success, otherwise an error code
  2535. //
  2536. // Author: kumarp 13-May-98
  2537. //
  2538. VOID
  2539. WriteNetComponentInfoForProvider(
  2540. IN HKEY hkeyProvider,
  2541. IN PCWSTR pszSoftwareProvider,
  2542. IN CWInfFile* pwifAnswerFile)
  2543. {
  2544. AssertValidReadPtr(pszSoftwareProvider);
  2545. AssertValidReadPtr(pwifAnswerFile);
  2546. HRESULT hr;
  2547. HKEY hkeyProductCurrentVersion;
  2548. tstring strProductCurrentVersion;
  2549. tstring strSoftwareType;
  2550. WCHAR szNetComponent[MAX_PATH];
  2551. FILETIME time;
  2552. DWORD dwSize;
  2553. DWORD dwRegIndex;
  2554. for (dwRegIndex = 0, dwSize = celems(szNetComponent);
  2555. !FIsUpgradeAborted() &&
  2556. (S_OK == HrRegEnumKeyEx(hkeyProvider, dwRegIndex, szNetComponent,
  2557. &dwSize, NULL, NULL, &time));
  2558. dwRegIndex++, dwSize = celems(szNetComponent))
  2559. {
  2560. Assert(*szNetComponent);
  2561. strProductCurrentVersion = szNetComponent;
  2562. AppendToPath(&strProductCurrentVersion, c_szRegKeyCurrentVersion);
  2563. hr = HrRegOpenKeyEx(hkeyProvider, strProductCurrentVersion.c_str(),
  2564. KEY_READ, &hkeyProductCurrentVersion);
  2565. if (S_OK == hr)
  2566. {
  2567. hr = HrRegQueryString(hkeyProductCurrentVersion,
  2568. c_szRegValSoftwareType,
  2569. &strSoftwareType);
  2570. // ignore components of type "driver"
  2571. if ((S_OK == hr) &&
  2572. (0 != lstrcmpiW(strSoftwareType.c_str(), c_szSoftwareTypeDriver)))
  2573. {
  2574. // Don't write disabled bindings of NdisWan and NetBT.
  2575. // They should always be enabled on upgrade.
  2576. //
  2577. if ((0 != lstrcmpiW(szNetComponent, L"NdisWan")) &&
  2578. (0 != lstrcmpiW(szNetComponent, L"NetBT")))
  2579. {
  2580. WriteBindings(szNetComponent);
  2581. }
  2582. if (!ShouldIgnoreComponent(szNetComponent))
  2583. {
  2584. (VOID) HrWriteNetComponentInfo(
  2585. szNetComponent, pwifAnswerFile,
  2586. hkeyProductCurrentVersion);
  2587. }
  2588. }
  2589. RegCloseKey(hkeyProductCurrentVersion);
  2590. }
  2591. }
  2592. }
  2593. // ----------------------------------------------------------------------
  2594. //
  2595. // Function: HrWriteNetComponentsInfo
  2596. //
  2597. // Purpose: Write info on installed net components (except net cards)
  2598. // of all providers to the answerfile
  2599. //
  2600. // Arguments:
  2601. // pwifAnswerFile [in] pointer to CWInfFile object (answerfile)
  2602. //
  2603. // Returns: S_OK on success, otherwise an error code
  2604. //
  2605. // Author: kumarp 13-May-98
  2606. //
  2607. HRESULT
  2608. HrWriteNetComponentsInfo(
  2609. IN CWInfFile* pwifAnswerFile)
  2610. {
  2611. AssertValidReadPtr(pwifAnswerFile);
  2612. HRESULT hr;
  2613. HKEY hkeySoftware;
  2614. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeySoftware,
  2615. KEY_READ, &hkeySoftware);
  2616. if (S_OK == hr)
  2617. {
  2618. WCHAR szBuf[MAX_PATH];
  2619. FILETIME time;
  2620. DWORD dwSize;
  2621. DWORD dwRegIndex;
  2622. for (dwRegIndex = 0, dwSize = celems(szBuf);
  2623. S_OK == HrRegEnumKeyEx(hkeySoftware, dwRegIndex, szBuf,
  2624. &dwSize, NULL, NULL, &time);
  2625. dwRegIndex++, dwSize = celems(szBuf))
  2626. {
  2627. Assert(*szBuf);
  2628. HKEY hkeyProvider;
  2629. hr = HrRegOpenKeyEx(hkeySoftware, szBuf, KEY_READ, &hkeyProvider);
  2630. if (S_OK == hr)
  2631. {
  2632. // We want to continue even if there is any error dumping info
  2633. // of one provider
  2634. //
  2635. WriteNetComponentInfoForProvider(
  2636. hkeyProvider,
  2637. szBuf,
  2638. pwifAnswerFile);
  2639. if (0 == _wcsicmp(szBuf, L"Microsoft"))
  2640. {
  2641. (VOID) HrWritePreSP3ComponentsToSteelHeadUpgradeParams(
  2642. pwifAnswerFile);
  2643. }
  2644. RegCloseKey(hkeyProvider);
  2645. }
  2646. }
  2647. RegCloseKey(hkeySoftware);
  2648. }
  2649. return hr;
  2650. }
  2651. // ----------------------------------------------------------------------
  2652. // TCPIP related
  2653. // ----------------------------------------------------------------------
  2654. static const WCHAR c_szTcpipParams[] = L"Tcpip\\Parameters";
  2655. VOID
  2656. WriteRegValueToAFile(
  2657. IN PCWInfSection pwisSection,
  2658. IN CORegKey& rk,
  2659. IN const ValueTypePair* prgVtp,
  2660. IN ULONG crg)
  2661. {
  2662. for (ULONG idx = 0; idx < crg; idx++)
  2663. {
  2664. if (REG_FILE == prgVtp[idx].dwType)
  2665. {
  2666. //This is just for "PersistentRoute" which we handle specifically
  2667. continue;
  2668. }
  2669. WriteRegValueToAFile(pwisSection, rk, prgVtp[idx].pszValueName,
  2670. prgVtp[idx].dwType);
  2671. }
  2672. }
  2673. // ----------------------------------------------------------------------
  2674. //
  2675. // Function: WriteTCPIPParams
  2676. //
  2677. // Purpose: Write parameters of TCPIP to the answerfile
  2678. //
  2679. // Arguments:
  2680. // pwifAnswerFile [in] pointer to CWInfFile object
  2681. // pwisTCPIPGlobalParams [in] pointer to TCPIP global params section
  2682. // slAdditionalParamsSections [out] list of adapter sections
  2683. //
  2684. // Returns: TRUE on success, FALSE otherwise
  2685. //
  2686. // Author: kumarp 03-December-97
  2687. //
  2688. BOOL
  2689. WriteTCPIPParams (
  2690. IN PCWInfFile pwifAnswerFile,
  2691. IN PCWInfSection pwisTCPIPGlobalParams,
  2692. OUT TStringList& slAdditionalParamsSections)
  2693. {
  2694. DefineFunctionName("WriteTCPIPParams");
  2695. TraceFunctionEntry(ttidNetUpgrade);
  2696. HRESULT hr;
  2697. TStringList slList;
  2698. PCORegKey prkRouter=NULL;
  2699. PCORegKey prkTCPIP=NULL;
  2700. PCORegKey prkTcpipParams=NULL;
  2701. PCORegKey prkTCPIPLinkage=NULL;
  2702. PCORegKey prkNetBT=NULL;
  2703. DWORD dwEnableDNS=0;
  2704. BOOL fEnableDNS=FALSE;
  2705. GetServiceKey(c_szSvcTcpip, prkTCPIP);
  2706. prkTcpipParams = new CORegKey(*prkTCPIP, c_szParameters);
  2707. tstring strValue;
  2708. DWORD dwValue;
  2709. //first write the global parameters
  2710. // UseDomainNameDevolution
  2711. WriteServiceRegValueToAFile(pwisTCPIPGlobalParams,
  2712. L"DnsCache\\Parameters",
  2713. L"UseDomainNameDevolution",
  2714. REG_BOOL,
  2715. NULL, // dont change value name
  2716. TRUE, // use default
  2717. (BOOL) TRUE); // default value
  2718. // EnableSecurity
  2719. dwValue = 0;
  2720. if (0 == prkTcpipParams->QueryValue(L"EnableSecurityFilters", dwValue))
  2721. pwisTCPIPGlobalParams->AddBoolKey(c_szAfEnableSecurity, dwValue);
  2722. // DNS
  2723. GetServiceParamsKey(c_szSvcNetBT, prkNetBT);
  2724. if (prkNetBT)
  2725. {
  2726. if (0 == prkNetBT->QueryValue(L"EnableDNS", dwEnableDNS))
  2727. {
  2728. fEnableDNS = dwEnableDNS;
  2729. }
  2730. // EnableLMHosts
  2731. WriteRegValueToAFile(pwisTCPIPGlobalParams, *prkNetBT, NULL,
  2732. c_szAfEnableLmhosts, REG_BOOL,
  2733. NULL, TRUE, (BOOL)FALSE);
  2734. // Write any present optional parameters to the answerfile
  2735. //
  2736. WriteRegValueToAFile(pwisTCPIPGlobalParams, *prkNetBT,
  2737. rgVtpNetBt, celems(rgVtpNetBt));
  2738. }
  2739. pwisTCPIPGlobalParams->AddBoolKey(c_szAfDns, fEnableDNS);
  2740. // DNSDomain
  2741. // Fix bug 349343, if the Domain value is empty, don't upgrade it
  2742. strValue.erase();
  2743. prkTcpipParams->QueryValue(c_szDomain, strValue);
  2744. if (!strValue.empty())
  2745. {
  2746. pwisTCPIPGlobalParams->AddKey(c_szAfDnsDomain, strValue.c_str());
  2747. }
  2748. // HostName
  2749. // 391590: save the hostname so we can maintain the capitalization
  2750. strValue.erase();
  2751. prkTcpipParams->QueryValue(c_szHostname, strValue);
  2752. if (!strValue.empty())
  2753. {
  2754. pwisTCPIPGlobalParams->AddKey(c_szAfDnsHostname, strValue.c_str());
  2755. }
  2756. // --------------------------------------------------
  2757. //$ ISSUE: kumarp 12-December-97
  2758. //
  2759. // this should be removed for Connections
  2760. // (they have been moved to adapter specific sections
  2761. //
  2762. //DNSServerSearchOrder
  2763. strValue.erase();
  2764. prkTcpipParams->QueryValue(c_szNameServer, strValue);
  2765. ConvertDelimitedListToStringList(strValue, ' ', slList);
  2766. pwisTCPIPGlobalParams->AddKey(c_szAfDnsServerSearchOrder, slList);
  2767. // --------------------------------------------------
  2768. // DNSSuffixSearchOrder
  2769. strValue.erase();
  2770. prkTcpipParams->QueryValue(L"SearchList", strValue);
  2771. ConvertDelimitedListToStringList(strValue, ' ', slList);
  2772. pwisTCPIPGlobalParams->AddKey(c_szAfDnsSuffixSearchOrder, slList);
  2773. // ImportLMHostsFile
  2774. // REVIEW: how to migrate the user-modified-lmhosts file ?
  2775. // Per AmritanR, drop the upgrade support of IpEnableRouter (EnableIPForwarding in the answer file) to fix bug 345700
  2776. // EnableIPForwarding (i.e. IpEnableRouter)
  2777. // If Steelhead is installed then write the following otherwise do nothing
  2778. //
  2779. if (TRUE == GetServiceKey(c_szRouter, prkRouter))
  2780. {
  2781. pwisTCPIPGlobalParams->AddBoolKey(c_szAfEnableICMPRedirect, FALSE);
  2782. pwisTCPIPGlobalParams->AddBoolKey(c_szAfDeadGWDetectDefault, FALSE);
  2783. pwisTCPIPGlobalParams->AddBoolKey(c_szAfDontAddDefaultGatewayDefault, TRUE);
  2784. }
  2785. // DatabasePath (REG_EXPAND_SZ)
  2786. strValue.erase();
  2787. prkTcpipParams->QueryValue(c_szDatabasePath, strValue);
  2788. if (!strValue.empty())
  2789. {
  2790. pwisTCPIPGlobalParams->AddKey(c_szDatabasePath, strValue.c_str());
  2791. }
  2792. // Write any present optional parameters to the answerfile
  2793. //
  2794. WriteRegValueToAFile(pwisTCPIPGlobalParams, *prkTcpipParams,
  2795. rgVtpIp, celems(rgVtpIp));
  2796. //PersistentRoutes
  2797. (void) HrNetRegSaveKeyAndAddToSection(prkTcpipParams->HKey(),
  2798. c_szPersistentRoutes,
  2799. c_szAfTcpip,
  2800. c_szPersistentRoutes,
  2801. pwisTCPIPGlobalParams);
  2802. //Write Adapter specific parameters
  2803. prkTCPIPLinkage = new CORegKey(*prkTCPIP, c_szLinkage);
  2804. prkTCPIPLinkage->QueryValue(L"Bind", slList);
  2805. TraceStringList(ttidNetUpgrade, L"TCPIP: enabled adapters", slList);
  2806. CORegKey* prkTCPIPLinkageDisabled;
  2807. TStringList slDisabled;
  2808. prkTCPIPLinkageDisabled = new CORegKey(*prkTCPIP, c_szLinkageDisabled);
  2809. prkTCPIPLinkageDisabled->QueryValue(L"Bind", slDisabled);
  2810. TraceStringList(ttidNetUpgrade, L"TCPIP: disabled adapters", slDisabled);
  2811. slList.splice(slList.end(), slDisabled);
  2812. delete prkTCPIPLinkageDisabled;
  2813. // $REVIEW(tongl 2/18/99): Added for bug #192576
  2814. // Get the list of disabled adapters to DHCP server, if it is installed
  2815. HKEY hkey;
  2816. ListStrings lstDisabledToDhcp;
  2817. ListStrings lstDisabledNetbt;
  2818. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE,
  2819. c_szDhcpServerLinkageDisabled, KEY_READ, &hkey);
  2820. if (S_OK == hr)
  2821. {
  2822. hr = HrRegQueryColString(hkey, L"Bind", &lstDisabledToDhcp);
  2823. RegCloseKey (hkey);
  2824. }
  2825. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE,
  2826. L"SYSTEM\\CurrentControlSet\\Services\\Netbt\\Linkage\\Disabled",
  2827. KEY_READ,
  2828. &hkey);
  2829. if (S_OK == hr)
  2830. {
  2831. hr = HrRegQueryColString(hkey, L"Bind", &lstDisabledNetbt);
  2832. RegCloseKey (hkey);
  2833. }
  2834. TStringListIter iter;
  2835. for (iter = slList.begin();
  2836. iter != slList.end();
  2837. iter++)
  2838. {
  2839. static WCHAR szAdapterDriver[256];
  2840. if (swscanf((*iter)->c_str(), L"\\Device\\%s", szAdapterDriver) == 1)
  2841. {
  2842. // $REVIEW(tongl 2/18/99): Added for bug #192576
  2843. // If this adapter was on the disabled list to DHCP server,
  2844. // set this to FALSE, otherwise, don't do anything
  2845. BOOL fDisabledToDhcpServer = FALSE;
  2846. BOOL fDisableNetbios = FALSE;
  2847. if (lstDisabledToDhcp.size())
  2848. {
  2849. TraceTag(ttidNetUpgrade, "szAdapterDriver: %S", szAdapterDriver);
  2850. TStringListIter iterD;
  2851. for (iterD = lstDisabledToDhcp.begin();
  2852. iterD != lstDisabledToDhcp.end();
  2853. iterD++)
  2854. {
  2855. TraceTag(ttidNetUpgrade, "binding string: %S",
  2856. (*iterD)->c_str());
  2857. if (FIsSubstr(szAdapterDriver, (*iterD)->c_str()))
  2858. {
  2859. TraceTag(ttidNetUpgrade,
  2860. "Adapter %S is disabled to Dhcp Server",
  2861. szAdapterDriver);
  2862. fDisabledToDhcpServer = TRUE;
  2863. break;
  2864. }
  2865. }
  2866. }
  2867. if (lstDisabledNetbt.size())
  2868. {
  2869. TraceTag(ttidNetUpgrade, "szAdapterDriver: %S", szAdapterDriver);
  2870. TStringListIter iterD;
  2871. for (iterD = lstDisabledNetbt.begin();
  2872. iterD != lstDisabledNetbt.end();
  2873. iterD++)
  2874. {
  2875. TraceTag(ttidNetUpgrade, "binding string: %S",
  2876. (*iterD)->c_str());
  2877. if (FIsSubstr(szAdapterDriver, (*iterD)->c_str()))
  2878. {
  2879. TraceTag(ttidNetUpgrade,
  2880. "Adapter %S is disabled for NetBIOS over TCP/IP",
  2881. szAdapterDriver);
  2882. fDisableNetbios = TRUE;
  2883. break;
  2884. }
  2885. }
  2886. }
  2887. WriteTCPIPAdapterParams(
  2888. pwifAnswerFile,
  2889. szAdapterDriver,
  2890. slAdditionalParamsSections,
  2891. fDisabledToDhcpServer,
  2892. fDisableNetbios);
  2893. }
  2894. }
  2895. DeleteIfNotNull(prkTCPIP);
  2896. DeleteIfNotNull(prkTcpipParams);
  2897. DeleteIfNotNull(prkNetBT);
  2898. DeleteIfNotNull(prkTCPIPLinkage);
  2899. DeleteIfNotNull(prkRouter);
  2900. EraseAndDeleteAll(slList);
  2901. return TRUE;
  2902. }
  2903. // ----------------------------------------------------------------------
  2904. //
  2905. // Function: WriteTCPIPAdapterParams
  2906. //
  2907. // Purpose: Write adapter-specific parameters of TCPIP to the answerfile
  2908. //
  2909. // Arguments:
  2910. // pwifAnswerFile [in] pointer to answerfile
  2911. // pszAdapterDriver [in] instance name of the adapter driver
  2912. // (e.g. ieepro2)
  2913. // slAdditionalParamsSections [out] list of adapter sections
  2914. //
  2915. // Returns: TRUE on success, FALSE otherwise
  2916. //
  2917. // Author: kumarp 03-December-97
  2918. //
  2919. BOOL
  2920. WriteTCPIPAdapterParams (
  2921. IN PCWInfFile pwifAnswerFile,
  2922. IN PCWSTR pszAdapterDriver,
  2923. OUT TStringList& slAdditionalParamsSections,
  2924. BOOL fDisabledToDhcpServer,
  2925. BOOL fDisableNetbios)
  2926. {
  2927. DefineFunctionName("WriteTCPIPAdapterParams");
  2928. TraceFunctionEntry(ttidNetUpgrade);
  2929. BOOL fStatus=FALSE;
  2930. PCORegKey prkNetBTParams=NULL;
  2931. tstring strValue;
  2932. TStringList slList;
  2933. tstring strAdapterParamsSectionName;
  2934. PCWInfSection pwisParams;
  2935. tstring strParamsKeyName;
  2936. PCORegKey prkParams = NULL;
  2937. PCWSTR pszAdapter = MapNetCardInstanceToAFileName(pszAdapterDriver);
  2938. if (!pszAdapter)
  2939. {
  2940. // this is most likely due to corrupt or inconsistent registry
  2941. //
  2942. TraceTag(ttidNetUpgrade, "%s: skipped writing adapter specific ",
  2943. "parameters for %S", __FUNCNAME__, pszAdapterDriver);
  2944. goto error_cleanup;
  2945. }
  2946. // WLBS: write WLBS TCP/IP parameters under the name of the cluster adapter,
  2947. // and skip cluster adapter TCP/IP parameters alltogether.
  2948. if (pszWlbsClusterAdapterName[0] != 0)
  2949. {
  2950. if (_wcsicmp(pszAdapter, pszWlbsClusterAdapterName) == 0)
  2951. {
  2952. TraceTag(ttidNetUpgrade, "%s: skipping %S section",
  2953. __FUNCNAME__, pszAdapter);
  2954. goto error_cleanup;
  2955. }
  2956. else if (_wcsicmp(pszAdapter, pszWlbsVirtualAdapterName) == 0)
  2957. {
  2958. TraceTag(ttidNetUpgrade, "%s: replacing %S section with %S",
  2959. __FUNCNAME__, pszAdapter, pszWlbsClusterAdapterName);
  2960. pszAdapter = pszWlbsClusterAdapterName;
  2961. }
  2962. }
  2963. // end WLBS:
  2964. strAdapterParamsSectionName = tstring(c_szAfParams) +
  2965. c_szInfId_MS_TCPIP + L"." + pszAdapter;
  2966. AddAtEndOfStringList(slAdditionalParamsSections, strAdapterParamsSectionName);
  2967. pwisParams = pwifAnswerFile->AddSection(strAdapterParamsSectionName.c_str());
  2968. pwisParams->AddKey(c_szAfSpecificTo, pszAdapter);
  2969. // TCPIP parameters for <adapter> are found at
  2970. // Services\<adapter-driver>\Parameters\Tcpip
  2971. strParamsKeyName = tstring(c_szRegKeyServices) + L"\\" +
  2972. pszAdapterDriver + L"\\Parameters\\Tcpip";
  2973. prkParams = new CORegKey(HKEY_LOCAL_MACHINE, strParamsKeyName.c_str());
  2974. if (!prkParams)
  2975. goto error_cleanup;
  2976. //DNSServerSearchOrder
  2977. //
  2978. HRESULT hr;
  2979. HKEY hkeyTcpipParams;
  2980. hr = HrRegOpenServiceKey(c_szTcpipParams, KEY_READ, &hkeyTcpipParams);
  2981. if (S_OK == hr)
  2982. {
  2983. tstring strDnsServerSearchOrder;
  2984. hr = HrRegQueryString(hkeyTcpipParams, c_szNameServer,
  2985. &strDnsServerSearchOrder);
  2986. if (S_OK == hr)
  2987. {
  2988. TStringList slDnsServerSearchOrder;
  2989. ConvertDelimitedListToStringList(strDnsServerSearchOrder,
  2990. ' ', slDnsServerSearchOrder);
  2991. pwisParams->AddKey(c_szAfDnsServerSearchOrder,
  2992. slDnsServerSearchOrder);
  2993. }
  2994. }
  2995. //DNSDomain
  2996. WriteServiceRegValueToAFile(pwisParams,
  2997. c_szTcpipParams,
  2998. c_szDomain,
  2999. REG_SZ,
  3000. c_szAfDnsDomain);
  3001. DWORD dwValue;
  3002. prkParams->QueryValue(L"EnableDHCP", dwValue);
  3003. pwisParams->AddBoolKey(c_szAfDhcp, dwValue);
  3004. if (!dwValue)
  3005. {
  3006. //IPAddress
  3007. WriteRegValueToAFile(pwisParams, *prkParams,
  3008. c_szAfIpaddress, REG_MULTI_SZ);
  3009. //SubnetMask
  3010. WriteRegValueToAFile(pwisParams, *prkParams,
  3011. c_szAfSubnetmask, REG_MULTI_SZ);
  3012. }
  3013. //Gateway
  3014. WriteRegValueToAFile(pwisParams, *prkParams,
  3015. c_szAfDefaultGateway, REG_MULTI_SZ);
  3016. // TcpAllowedPorts
  3017. WriteRegValueToAFile(pwisParams, *prkParams,
  3018. L"TcpAllowedPorts",
  3019. REG_MULTI_SZ,
  3020. c_szAfTcpAllowedPorts);
  3021. // UdpAllowedPorts
  3022. WriteRegValueToAFile(pwisParams, *prkParams,
  3023. L"UdpAllowedPorts",
  3024. REG_MULTI_SZ,
  3025. c_szAfUdpAllowedPorts);
  3026. // IpAllowedProtocols
  3027. WriteRegValueToAFile(pwisParams, *prkParams,
  3028. L"RawIPAllowedProtocols",
  3029. REG_MULTI_SZ,
  3030. c_szAfIpAllowedProtocols);
  3031. // Write any present optional parameters to the answerfile
  3032. //
  3033. WriteRegValueToAFile(pwisParams, *prkParams,
  3034. rgVtpIpAdapter, celems(rgVtpIpAdapter));
  3035. strValue = L"Adapters\\";
  3036. strValue += pszAdapterDriver;
  3037. GetServiceSubkey(c_szSvcNetBT, strValue.c_str(), prkNetBTParams);
  3038. if (!prkNetBTParams)
  3039. goto error_cleanup;
  3040. strValue.erase();
  3041. prkNetBTParams->QueryValue(c_szNameServer, strValue);
  3042. if (strValue.empty())
  3043. {
  3044. //WINS=No
  3045. pwisParams->AddKey(c_szAfWins, c_szNo);
  3046. }
  3047. else
  3048. {
  3049. //WINS=Yes
  3050. pwisParams->AddKey(c_szAfWins, c_szYes);
  3051. tstring strWinsServerList;
  3052. strWinsServerList = strValue;
  3053. prkNetBTParams->QueryValue(L"NameServerBackup", strValue);
  3054. if (!strValue.empty())
  3055. {
  3056. strWinsServerList += L",";
  3057. strWinsServerList += strValue;
  3058. }
  3059. pwisParams->AddKey(c_szAfWinsServerList, strWinsServerList.c_str());
  3060. }
  3061. // BindToDhcpServer
  3062. // $REVIEW(tongl 2/18/99): Added for bug #192576
  3063. // If this adapter was on the disabled list to DHCP server, set this to FALSE
  3064. // otherwise, don't do anything
  3065. if (fDisabledToDhcpServer)
  3066. {
  3067. pwisParams->AddBoolKey(c_szAfBindToDhcpServer, !fDisabledToDhcpServer);
  3068. }
  3069. if (fDisableNetbios)
  3070. {
  3071. // Value of 2 means disable netbios over tcpip for this interface.
  3072. pwisParams->AddKey(c_szAfNetBIOSOptions, 2);
  3073. }
  3074. fStatus=TRUE;
  3075. goto cleanup;
  3076. error_cleanup:
  3077. fStatus = FALSE;
  3078. cleanup:
  3079. DeleteIfNotNull(prkParams);
  3080. DeleteIfNotNull(prkNetBTParams);
  3081. return fStatus;
  3082. }
  3083. // ----------------------------------------------------------------------
  3084. //
  3085. // Function: WriteAppleTalkParams
  3086. //
  3087. // Purpose: Write parameters of AppleTalk protocol
  3088. //
  3089. // Arguments:
  3090. // pwifAnswerFile [in] pointer to answerfile
  3091. // pwisGlobalParams [in] pointer to global params section
  3092. // slAdditionalParamsSections [out] list of adapter params sections
  3093. //
  3094. // Returns: TRUE on success, FALSE otherwise
  3095. //
  3096. // Author: kumarp 11-December-97
  3097. //
  3098. BOOL
  3099. WriteAppleTalkParams (
  3100. IN PCWInfFile pwifAnswerFile,
  3101. IN PCWInfSection pwisGlobalParams,
  3102. OUT TStringList& slAdditionalParamsSections)
  3103. {
  3104. DefineFunctionName("WriteAppleTalkParams");
  3105. TraceFunctionEntry(ttidNetUpgrade);
  3106. BOOL fStatus=FALSE;
  3107. tstring strTemp;
  3108. CORegKeyIter *prkiAdapters=NULL;
  3109. tstring strAdapterInstance;
  3110. PCORegKey prkAdapters=NULL;
  3111. tstring strDefaultPort;
  3112. PCORegKey prkParams=NULL;
  3113. GetServiceSubkey(L"AppleTalk", L"Parameters", prkParams);
  3114. if (!prkParams)
  3115. goto error_cleanup;
  3116. //Write Global Parameters
  3117. // DefaultPort
  3118. prkParams->QueryValue(L"DefaultPort", strDefaultPort);
  3119. WCHAR szTemp[256];
  3120. PCWSTR pszNetCardAFileName;
  3121. if ((swscanf(strDefaultPort.c_str(), L"\\Device\\%s", szTemp) == 1) &&
  3122. ((pszNetCardAFileName = MapNetCardInstanceToAFileName(szTemp)) != NULL))
  3123. {
  3124. pwisGlobalParams->AddKey(L"DefaultPort", pszNetCardAFileName);
  3125. }
  3126. // DesiredZone
  3127. WriteRegValueToAFile(pwisGlobalParams,
  3128. *prkParams,
  3129. L"DesiredZone");
  3130. // EnableRouter
  3131. WriteRegValueToAFile(pwisGlobalParams,
  3132. *prkParams,
  3133. L"EnableRouter",
  3134. REG_BOOL,
  3135. NULL, // dont change value name
  3136. TRUE, // use default
  3137. (BOOL) FALSE); // default value
  3138. //Write Adapter specific parameters
  3139. GetServiceSubkey(L"AppleTalk", L"Adapters", prkAdapters);
  3140. DoErrorCleanupIf(!prkAdapters);
  3141. prkiAdapters = new CORegKeyIter(*prkAdapters);
  3142. prkiAdapters->Reset();
  3143. strTemp = tstring(c_szAfParams) + c_szInfId_MS_AppleTalk + L".";
  3144. while (!prkiAdapters->Next(&strAdapterInstance))
  3145. {
  3146. ContinueIf(strAdapterInstance.empty());
  3147. CORegKey rkAdapterInstance(*prkAdapters, strAdapterInstance.c_str());
  3148. PCWSTR pszNetCardAFileName =
  3149. MapNetCardInstanceToAFileName(strAdapterInstance.c_str());
  3150. ContinueIf(!pszNetCardAFileName);
  3151. tstring strAdapterParamsSection = strTemp + pszNetCardAFileName;
  3152. AddAtEndOfStringList(slAdditionalParamsSections, strAdapterParamsSection);
  3153. PCWInfSection pwisAdapterParams;
  3154. pwisAdapterParams =
  3155. pwifAnswerFile->AddSection(strAdapterParamsSection.c_str());
  3156. //SpecificTo
  3157. pwisAdapterParams->AddKey(c_szAfSpecificTo, pszNetCardAFileName);
  3158. // DefaultZone
  3159. WriteRegValueToAFile(pwisAdapterParams,
  3160. rkAdapterInstance,
  3161. L"DefaultZone");
  3162. // NetworkRangeLowerEnd
  3163. WriteRegValueToAFile(pwisAdapterParams,
  3164. rkAdapterInstance,
  3165. L"NetworkRangeLowerEnd",
  3166. REG_DWORD);
  3167. // NetworkRangeUpperEnd
  3168. WriteRegValueToAFile(pwisAdapterParams,
  3169. rkAdapterInstance,
  3170. L"NetworkRangeUpperEnd",
  3171. REG_DWORD);
  3172. // PortName
  3173. //
  3174. //$ REVIEW kumarp 24-May-97
  3175. // the value is of the form ieepro2@kumarp1
  3176. // this may need to be changed to Adapter03@kumarp1
  3177. //
  3178. WriteRegValueToAFile(pwisAdapterParams,
  3179. rkAdapterInstance,
  3180. L"PortName");
  3181. // SeedingNetwork
  3182. WriteRegValueToAFile(pwisAdapterParams,
  3183. rkAdapterInstance,
  3184. L"SeedingNetwork",
  3185. REG_DWORD,
  3186. NULL, // dont change value name
  3187. TRUE, // use default
  3188. (DWORD) 0); // default value
  3189. // ZoneList
  3190. WriteRegValueToAFile(pwisAdapterParams,
  3191. rkAdapterInstance,
  3192. L"ZoneList",
  3193. REG_MULTI_SZ);
  3194. }
  3195. fStatus = TRUE;
  3196. goto cleanup;
  3197. error_cleanup:
  3198. fStatus = FALSE;
  3199. cleanup:
  3200. DeleteIfNotNull(prkParams);
  3201. DeleteIfNotNull(prkAdapters);
  3202. DeleteIfNotNull(prkiAdapters);
  3203. return fStatus;
  3204. }
  3205. // ----------------------------------------------------------------------
  3206. //
  3207. // Function: WritePPTPParams
  3208. //
  3209. // Purpose: Write parameters of PPTP protocol
  3210. //
  3211. // Arguments:
  3212. // pwifAnswerFile [in] pointer to answerfile
  3213. // pwisParams [in] pointer to global params section
  3214. //
  3215. // Returns: TRUE on success, FALSE otherwise
  3216. //
  3217. // Author: kumarp 11-December-97
  3218. //
  3219. BOOL
  3220. WritePPTPParams (
  3221. PCWInfFile pwifAnswerFile,
  3222. PCWInfSection pwisParams)
  3223. {
  3224. DefineFunctionName("WritePPTPParams");
  3225. TraceFunctionEntry(ttidNetUpgrade);
  3226. //NumberLineDevices
  3227. WriteServiceRegValueToAFile(pwisParams,
  3228. L"RASPPTPE\\Parameters\\Configuration",
  3229. L"NumberLineDevices",
  3230. REG_DWORD);
  3231. return TRUE;
  3232. }
  3233. // ----------------------------------------------------------------------
  3234. //
  3235. // Function: WriteIPXParams
  3236. //
  3237. // Purpose: Write parameters of IPX protocol
  3238. //
  3239. // Arguments:
  3240. // pwifAnswerFile [in] pointer to answerfile
  3241. // pwisIPXGlobalParams [in] pointer to global params section
  3242. // slAdditionalParamsSections [out] list of adapter params sections
  3243. //
  3244. // Returns: TRUE on success, FALSE otherwise
  3245. //
  3246. // Author: kumarp 11-December-97
  3247. //
  3248. BOOL
  3249. WriteIPXParams (
  3250. IN PCWInfFile pwifAnswerFile,
  3251. IN PCWInfSection pwisIPXGlobalParams,
  3252. OUT TStringList& slAdditionalParamsSections)
  3253. {
  3254. DefineFunctionName("WriteIPXParams");
  3255. TraceFunctionEntry(ttidNetUpgrade);
  3256. BOOL fStatus=FALSE;
  3257. tstring strTemp;
  3258. CORegKeyIter *prkiNetConfig=NULL;
  3259. //InternalNetworkNumber
  3260. WriteServiceRegValueToAFile(pwisIPXGlobalParams,
  3261. L"NwlnkIpx\\Parameters",
  3262. L"VirtualNetworkNumber",
  3263. REG_HEX,
  3264. c_szAfInternalNetworkNumber);
  3265. // DedicatedRouter
  3266. WriteServiceRegValueToAFile(pwisIPXGlobalParams,
  3267. L"NwlnkIpx\\Parameters",
  3268. L"DedicatedRouter",
  3269. REG_BOOL,
  3270. NULL, // dont change value name
  3271. TRUE, // use default
  3272. (BOOL) FALSE); // default value
  3273. // EnableWANRouter
  3274. WriteServiceRegValueToAFile(pwisIPXGlobalParams,
  3275. L"NwlnkIpx\\Parameters",
  3276. L"EnableWANRouter",
  3277. REG_BOOL,
  3278. NULL, // dont change value name
  3279. TRUE, // use default
  3280. TRUE); // default value
  3281. // RipRoute
  3282. WriteServiceRegValueToAFile(pwisIPXGlobalParams,
  3283. L"NwlnkIpx\\Parameters",
  3284. L"RipRoute",
  3285. REG_DWORD);
  3286. // ------------------------------------------------------------------------------
  3287. //Write Adapter specific parameters
  3288. tstring strAdapterInstance;
  3289. PCORegKey prkNetConfig=NULL;
  3290. GetServiceSubkey(L"NwlnkIpx", L"NetConfig", prkNetConfig);
  3291. if (!prkNetConfig)
  3292. goto error_cleanup;
  3293. prkiNetConfig = new CORegKeyIter(*prkNetConfig);
  3294. prkiNetConfig->Reset();
  3295. strTemp = tstring(c_szAfParams) + c_szInfId_MS_NWIPX + L".";
  3296. while (!prkiNetConfig->Next(&strAdapterInstance))
  3297. {
  3298. ContinueIf(strAdapterInstance.empty());
  3299. CORegKey rkAdapterInstance(*prkNetConfig, strAdapterInstance.c_str());
  3300. PCWSTR pszNetCardAFileName =
  3301. MapNetCardInstanceToAFileName(strAdapterInstance.c_str());
  3302. ContinueIf(!pszNetCardAFileName);
  3303. tstring strAdapterParamsSection = strTemp + pszNetCardAFileName;
  3304. AddAtEndOfStringList(slAdditionalParamsSections, strAdapterParamsSection);
  3305. PCWInfSection pwisAdapterParams;
  3306. pwisAdapterParams =
  3307. pwifAnswerFile->AddSection(strAdapterParamsSection.c_str());
  3308. //SpecificTo
  3309. pwisAdapterParams->AddKey(c_szAfSpecificTo, pszNetCardAFileName);
  3310. // PktType
  3311. WriteRegValueToAFile(pwisAdapterParams,
  3312. rkAdapterInstance,
  3313. L"PktType",
  3314. REG_MULTI_SZ);
  3315. // MaxPktSize
  3316. WriteRegValueToAFile(pwisAdapterParams,
  3317. rkAdapterInstance,
  3318. L"MaxPktSize",
  3319. REG_DWORD,
  3320. NULL, // dont change value name
  3321. TRUE, // use default
  3322. (DWORD) 0); // default value
  3323. // NetworkNumber
  3324. WriteRegValueToAFile(pwisAdapterParams,
  3325. rkAdapterInstance,
  3326. L"NetworkNumber",
  3327. REG_MULTI_SZ);
  3328. // BindSap
  3329. WriteRegValueToAFile(pwisAdapterParams,
  3330. rkAdapterInstance,
  3331. L"BindSap",
  3332. REG_HEX,
  3333. NULL, // dont change value name
  3334. TRUE, // use default
  3335. (DWORD) 0x8137); // default value
  3336. // EnableFuncAddr
  3337. WriteRegValueToAFile(pwisAdapterParams,
  3338. rkAdapterInstance,
  3339. L"EnableFuncaddr",
  3340. REG_BOOL,
  3341. NULL, // dont change value name
  3342. TRUE, // use default
  3343. TRUE); // default value
  3344. // SourceRouteDef
  3345. WriteRegValueToAFile(pwisAdapterParams,
  3346. rkAdapterInstance,
  3347. L"SourceRouteDef",
  3348. REG_DWORD,
  3349. NULL, // dont change value name
  3350. TRUE, // use default
  3351. (DWORD) 0); // default value
  3352. // SourceRouteMcast
  3353. WriteRegValueToAFile(pwisAdapterParams,
  3354. rkAdapterInstance,
  3355. L"SourceRouteMcast",
  3356. REG_BOOL,
  3357. NULL, // dont change value name
  3358. TRUE, // use default
  3359. (BOOL) FALSE); // default value
  3360. // SourceRouting
  3361. WriteRegValueToAFile(pwisAdapterParams,
  3362. rkAdapterInstance,
  3363. L"SourceRouting",
  3364. REG_BOOL,
  3365. NULL, // dont change value name
  3366. TRUE, // use default
  3367. (BOOL) FALSE); // default value
  3368. strAdapterInstance.erase();
  3369. }
  3370. fStatus=TRUE;
  3371. goto cleanup;
  3372. error_cleanup:
  3373. fStatus=FALSE;
  3374. cleanup:
  3375. // DeleteIfNotNull(prkParams);
  3376. DeleteIfNotNull(prkNetConfig);
  3377. DeleteIfNotNull(prkiNetConfig);
  3378. return fStatus;
  3379. }
  3380. static const WCHAR c_szRegKeyRas[] = L"Software\\Microsoft\\RAS";
  3381. static const WCHAR c_szRegKeyRasMan[] = L"System\\CurrentControlSet\\Services\\Rasman\\PPP";
  3382. static const WCHAR c_szRegKeyRasManSH[] = L"System\\CurrentControlSet\\Services\\Rasman\\PPP\\COMPCP";
  3383. static const WCHAR c_szRegKeyUnimodem[] = L"TAPI DEVICES\\Unimodem";
  3384. static const WCHAR c_szAddress[] = L"Address";
  3385. static const WCHAR c_szUsage[] = L"Usage";
  3386. // ----------------------------------------------------------------------
  3387. //
  3388. // Function: HrGetRasPortsInfo
  3389. //
  3390. // Purpose: Find out ports' usage info from registry.
  3391. // If the registry does not have this info (in case of NT3.51)
  3392. // then try to get it from serial.ini file
  3393. //
  3394. // Arguments:
  3395. // pslPorts [out] list of ports
  3396. // pslUsage [out] usage of ports in the above list
  3397. //
  3398. // Returns: S_OK on success, otherwise an error code
  3399. //
  3400. // Author: kumarp 17-December-97
  3401. //
  3402. HRESULT
  3403. HrGetRasPortsInfo (
  3404. OUT TStringList* pslPorts,
  3405. OUT TStringList* pslUsage)
  3406. {
  3407. DefineFunctionName("HrGetRasPortsInfo");
  3408. HRESULT hr=S_OK;
  3409. HKEY hkeyUnimodem;
  3410. tstring strUnimodem;
  3411. strUnimodem = c_szRegKeyRas;
  3412. strUnimodem += '\\';
  3413. strUnimodem += c_szRegKeyUnimodem;
  3414. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, strUnimodem.c_str(),
  3415. KEY_READ, &hkeyUnimodem);
  3416. if (S_OK == hr)
  3417. {
  3418. hr = HrRegQueryColString(hkeyUnimodem, c_szAddress, pslPorts);
  3419. if (S_OK == hr)
  3420. {
  3421. hr = HrRegQueryColString(hkeyUnimodem, c_szUsage, pslUsage);
  3422. }
  3423. }
  3424. if (pslPorts->empty())
  3425. {
  3426. TraceTag(ttidNetUpgrade, "%s: there are no entries found under %S",
  3427. __FUNCNAME__, strUnimodem.c_str());
  3428. TraceTag(ttidNetUpgrade, "%s: trying to get port usage info from serial.ini file", __FUNCNAME__);
  3429. HINF hinf;
  3430. tstring strSerialIni;
  3431. hr = HrGetWindowsDir(&strSerialIni);
  3432. if (S_OK == hr)
  3433. {
  3434. static const WCHAR c_szSystem32SerialIni[] =
  3435. L"\\system32\\ras\\serial.ini";
  3436. strSerialIni += c_szSystem32SerialIni;
  3437. hr = HrSetupOpenInfFile(strSerialIni.c_str(), NULL,
  3438. INF_STYLE_OLDNT, NULL, &hinf);
  3439. if (S_OK == hr)
  3440. {
  3441. tstring strUsage;
  3442. WCHAR szPortName[16];
  3443. INFCONTEXT ic;
  3444. for (int i=1; i<=255; i++)
  3445. {
  3446. swprintf(szPortName, L"COM%d", i);
  3447. hr = HrSetupFindFirstLine(hinf, szPortName, c_szUsage, &ic);
  3448. if (S_OK == hr)
  3449. {
  3450. hr = HrSetupGetStringField(ic, 1, &strUsage);
  3451. if (S_OK == hr)
  3452. {
  3453. TraceTag(ttidNetUpgrade,
  3454. "%s: as per serial.ini file: %S --> %S",
  3455. __FUNCNAME__, szPortName, strUsage.c_str());
  3456. pslPorts->push_back(new tstring(szPortName));
  3457. pslUsage->push_back(new tstring(strUsage.c_str()));
  3458. }
  3459. }
  3460. }
  3461. hr = S_OK;
  3462. SetupCloseInfFile(hinf);
  3463. }
  3464. }
  3465. }
  3466. TraceError(__FUNCNAME__, hr);
  3467. return hr;
  3468. }
  3469. // ----------------------------------------------------------------------
  3470. //
  3471. // Function: ConvertIpAddrRangeToAddrAndMask
  3472. //
  3473. // Purpose: Convert a range of IP addr specified using Start/End to
  3474. // equivalent Start+Mask combination
  3475. //
  3476. // Arguments:
  3477. // pszIpBegin [in] Start addr
  3478. // pszIpEnd [in] End addr
  3479. // pstrIpAddr [out] pointer to Start addr
  3480. // pstrIpMask [out] pointer to Mask
  3481. //
  3482. // Returns: None
  3483. //
  3484. // Author: kumarp 27-April-98
  3485. //
  3486. void
  3487. ConvertIpAddrRangeToAddrAndMask(
  3488. IN PCWSTR pszIpBegin,
  3489. IN PCWSTR pszIpEnd,
  3490. OUT tstring* pstrIpAddr,
  3491. OUT tstring* pstrIpMask)
  3492. {
  3493. WCHAR szBuf[16];
  3494. DWORD dwIpBegin = IpPszToHostAddr(pszIpBegin);
  3495. DWORD dwIpEnd = IpPszToHostAddr(pszIpEnd);
  3496. // dwTemp will have a bit set for each common bit between
  3497. // dwIpBegin and dwIpEnd.
  3498. //
  3499. DWORD dwTemp = ~(dwIpBegin ^ dwIpEnd);
  3500. // Compute the subnet mask as the longest run of 1s from
  3501. // the highest order down.
  3502. //
  3503. DWORD dwIpMask = 0;
  3504. while (dwTemp & 0x80000000)
  3505. {
  3506. dwTemp <<= 1; // Eventually shifts a zero to the high bit
  3507. // so the loop will stop.
  3508. // Form the mask by shifting 1 right from the high bit.
  3509. dwIpMask = 0x80000000 | (dwIpMask >> 1);
  3510. }
  3511. // Reset the begin address (if needed) to the base of the subnet mask.
  3512. //
  3513. dwIpBegin &= dwIpMask;
  3514. IpHostAddrToPsz(dwIpBegin, szBuf);
  3515. *pstrIpAddr = szBuf;
  3516. IpHostAddrToPsz(dwIpMask, szBuf);
  3517. *pstrIpMask = szBuf;
  3518. }
  3519. // ----------------------------------------------------------------------
  3520. //
  3521. // Function: ConvertAddrAndMaskToIpAddrRange
  3522. //
  3523. // Purpose: Convert a IP address Start + Mask combination into the
  3524. // equivalent IP address range
  3525. //
  3526. // Arguments:
  3527. // pszIpAddr [in] Start
  3528. // pszIpMask [in] Mask
  3529. // pstrIpBegin [out] pointer to Start addr
  3530. // pstrIpEnd [out] pointer to End addr
  3531. //
  3532. // Returns: None
  3533. //
  3534. // Author: SumitC 28-Jul-99
  3535. //
  3536. void
  3537. ConvertAddrAndMaskToIpAddrRange(
  3538. IN PCWSTR pszIpAddr,
  3539. IN PCWSTR pszIpMask,
  3540. OUT tstring* pstrIpBegin,
  3541. OUT tstring* pstrIpEnd)
  3542. {
  3543. WCHAR szBuf[16];
  3544. DWORD dwIpBegin = IpPszToHostAddr(pszIpAddr);
  3545. // dwEnd is generated by inverting the mask and adding to IpBegin
  3546. //
  3547. DWORD dwIpEnd = dwIpBegin + (~ IpPszToHostAddr(pszIpMask));
  3548. *pstrIpBegin = pszIpAddr;
  3549. IpHostAddrToPsz(dwIpEnd, szBuf);
  3550. *pstrIpEnd = szBuf;
  3551. }
  3552. //+---------------------------------------------------------------------------
  3553. //
  3554. // Function: RasGetDialInUsage
  3555. //
  3556. // Purpose: Find out if at least one RAS port is configured for dialin.
  3557. //
  3558. // Returns: TRUE if at least one port configured for dial in.
  3559. //
  3560. // Author: kumarp 28-January-99
  3561. //
  3562. BOOL
  3563. RasGetDialInUsage (VOID)
  3564. {
  3565. static const WCHAR c_szTapiDevices[] =
  3566. L"Software\\Microsoft\\RAS\\TAPI DEVICES";
  3567. HRESULT hr=S_OK;
  3568. HKEY hkeyTapiDevices;
  3569. HKEY hkeyTapiDevice;
  3570. BOOL fAtLeastOneDialin = FALSE;
  3571. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE,
  3572. c_szTapiDevices, KEY_READ,
  3573. &hkeyTapiDevices);
  3574. if (S_OK == hr)
  3575. {
  3576. WCHAR szBuf[MAX_PATH];
  3577. FILETIME time;
  3578. DWORD dwSize;
  3579. DWORD dwRegIndex;
  3580. for (dwRegIndex = 0, dwSize = celems(szBuf);
  3581. !fAtLeastOneDialin &&
  3582. (S_OK == HrRegEnumKeyEx(hkeyTapiDevices, dwRegIndex, szBuf,
  3583. &dwSize, NULL, NULL, &time));
  3584. dwRegIndex++, dwSize = celems(szBuf))
  3585. {
  3586. Assert(*szBuf);
  3587. hr = HrRegOpenKeyEx(hkeyTapiDevices,
  3588. szBuf, KEY_READ,
  3589. &hkeyTapiDevice);
  3590. if (S_OK == hr)
  3591. {
  3592. PWSTR pmszUsage;
  3593. hr = HrRegQueryMultiSzWithAlloc(hkeyTapiDevice, c_szUsage,
  3594. &pmszUsage);
  3595. if ((S_OK == hr) && pmszUsage)
  3596. {
  3597. PCWSTR pszScan;
  3598. for (pszScan = pmszUsage;
  3599. *pszScan;
  3600. pszScan += wcslen(pszScan) + 1)
  3601. {
  3602. if (FIsSubstr(c_szServer, pszScan) ||
  3603. FIsSubstr(c_szRouter, pszScan))
  3604. {
  3605. fAtLeastOneDialin = TRUE;
  3606. break;
  3607. }
  3608. }
  3609. MemFree(pmszUsage);
  3610. }
  3611. RegCloseKey(hkeyTapiDevice);
  3612. }
  3613. }
  3614. RegCloseKey(hkeyTapiDevices);
  3615. }
  3616. return fAtLeastOneDialin;
  3617. }
  3618. //+---------------------------------------------------------------------------
  3619. //
  3620. // Function: WriteRouterUpgradeInfo
  3621. //
  3622. // Purpose: Write info required for upgrading Router to answerfile.
  3623. //
  3624. // Arguments:
  3625. // pwifAnswerFile [in] pointer to CWInfFile object
  3626. //
  3627. // Returns: None
  3628. //
  3629. // Author: kumarp 16-June-98
  3630. //
  3631. void
  3632. WriteRouterUpgradeInfo (
  3633. IN CWInfFile* pwifAnswerFile)
  3634. {
  3635. DefineFunctionName("HrWriteRouterUpgradeInfo");
  3636. TraceTag(ttidNetUpgrade, "-----> entering %s", __FUNCNAME__);
  3637. tstring strParamsSectionName;
  3638. CWInfSection* pwisNetServices;
  3639. CWInfSection* pwisRouter;
  3640. strParamsSectionName = c_szAfParams;
  3641. strParamsSectionName = strParamsSectionName + L"ms_rasrtr";
  3642. pwisNetServices = pwifAnswerFile->FindSection(c_szAfSectionNetServices);
  3643. AssertSz(pwisNetServices, "No [NetServices] section ??");
  3644. pwisNetServices->AddKey(L"ms_rasrtr", strParamsSectionName.c_str());
  3645. pwisRouter = pwifAnswerFile->AddSection(strParamsSectionName.c_str());
  3646. pwisRouter->AddKey(c_szAfInfid, L"ms_rasrtr");
  3647. pwisRouter->AddKey(c_szAfParamsSection, strParamsSectionName.c_str());
  3648. (void) HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcRouter, NULL,
  3649. c_szAfPreUpgradeRouter,
  3650. pwisRouter);
  3651. (void) HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcSapAgent,
  3652. c_szParameters,
  3653. c_szAfNwSapAgentParams,
  3654. pwisRouter);
  3655. (void) HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcRipForIp,
  3656. c_szParameters,
  3657. c_szAfIpRipParameters,
  3658. pwisRouter);
  3659. (void) HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcDhcpRelayAgent,
  3660. c_szParameters,
  3661. c_szAfDhcpRelayAgentParameters,
  3662. pwisRouter);
  3663. (void) HrNetRegSaveKeyAndAddToSection(HKEY_LOCAL_MACHINE,
  3664. L"Software\\Microsoft\\Ras\\Radius",
  3665. L"Radius",
  3666. c_szAfRadiusParameters,
  3667. pwisRouter);
  3668. }
  3669. // ----------------------------------------------------------------------
  3670. //
  3671. // Function: WriteRASParams
  3672. //
  3673. // Purpose: Write RAS parameters to the answerfile
  3674. //
  3675. // Arguments:
  3676. // pwifAnswerFile [in] pointer to answerfile
  3677. // pwisNetServices [in] pointer to NetServices section
  3678. // pwisParams [in] pointer to global params section
  3679. //
  3680. // Returns: TRUE on success, FALSE otherwise
  3681. //
  3682. // Author: kumarp 11-December-97
  3683. //
  3684. BOOL
  3685. WriteRASParams (
  3686. IN PCWInfFile pwifAnswerFile,
  3687. IN PCWInfSection pwisNetServices,
  3688. IN PCWInfSection pwisParams)
  3689. {
  3690. DefineFunctionName("WriteRASParams");
  3691. TraceFunctionEntry(ttidNetUpgrade);
  3692. PCORegKey prkRAS = new CORegKey(HKEY_LOCAL_MACHINE, c_szRegKeyRas);
  3693. PCORegKey prkProtocols = new CORegKey(*prkRAS, L"Protocols");
  3694. if(!prkRAS || !prkProtocols)
  3695. {
  3696. return false;
  3697. }
  3698. WriteRegValueToAFile(pwisParams, *prkProtocols, c_szAfRouterType, REG_DWORD);
  3699. TStringList slPorts, slUsage, slTemp;
  3700. tstring strPorts, strValue, strTemp, strPortSections;
  3701. tstring strIpAddrStart;
  3702. tstring strIpAddrEnd;
  3703. DWORD dwValue=0;
  3704. BOOL fSteelHeadInstalled=FALSE;
  3705. HRESULT hr=S_OK;
  3706. LONG err;
  3707. // find out if SteelHead is installed.
  3708. // if the service "Router" is found --> SteelHead is installed
  3709. fSteelHeadInstalled = FIsServiceKeyPresent(c_szSvcRouter);
  3710. PCWInfSection pwisPort;
  3711. (void) HrGetRasPortsInfo(&slPorts, &slUsage);
  3712. TStringListIter pos1 = slPorts.begin();
  3713. TStringListIter pos2 = slUsage.begin();
  3714. //Write parameters for each port
  3715. while ((pos1 != slPorts.end()) && (pos2 != slUsage.end()))
  3716. {
  3717. strValue = **pos1++;
  3718. strTemp = c_szAfParams;
  3719. strTemp += strValue;
  3720. if (!strPortSections.empty())
  3721. strPortSections += c_szAfListDelimiter;
  3722. strPortSections += strTemp;
  3723. pwisPort = pwifAnswerFile->AddSection(strTemp.c_str());
  3724. //PortName
  3725. pwisPort->AddKey(c_szAfPortname, strValue.c_str());
  3726. //PortUsage
  3727. strValue = **pos2++;
  3728. //MapPortUsageRegValueToAFileValue(strValue, strValue);
  3729. pwisPort->AddKey(c_szAfPortUsage, strValue.c_str());
  3730. //this decides what we need to install
  3731. // i.e a combination of MS_RasCli / MS_RasSrv
  3732. //
  3733. if (wcsstr(strValue.c_str(), L"Client"))
  3734. {
  3735. TraceTag(ttidNetUpgrade,
  3736. "%s: g_fAtLeastOneDialOut set to TRUE because of PortUsage %S",
  3737. __FUNCNAME__, strValue.c_str());
  3738. g_fAtLeastOneDialOut = TRUE;
  3739. }
  3740. if (wcsstr(strValue.c_str(), c_szServer))
  3741. {
  3742. TraceTag(ttidNetUpgrade,
  3743. "%s: g_fAtLeastOneDialIn set to TRUE because of PortUsage %S",
  3744. __FUNCNAME__, strValue.c_str());
  3745. g_fAtLeastOneDialIn = TRUE;
  3746. }
  3747. }
  3748. // if the Port usage cannot be determined using the ports list
  3749. // then we need to use the values found using ndiswan ProductName
  3750. //
  3751. if (slPorts.size() == 0)
  3752. {
  3753. TraceTag(ttidNetUpgrade, "%s: Since PortUsage is not defined, using flags generated by inspecting ndiswan ProductName",
  3754. __FUNCNAME__);
  3755. g_fAtLeastOneDialIn = g_fAtLeastOneDialInUsingNdisWan;
  3756. g_fAtLeastOneDialOut = g_fAtLeastOneDialOutUsingNdisWan;
  3757. }
  3758. //Now write RAS Global parameters
  3759. ValueTypePair rgVtpRasParams[] = {
  3760. {L"ForceEncryptedPassword", REG_DWORD},
  3761. {L"ForceEncryptedData",REG_BOOL},
  3762. {L"Multilink", REG_BOOL}};
  3763. WriteRegValueToAFile(pwisParams, *prkProtocols,
  3764. rgVtpRasParams, celems(rgVtpRasParams));
  3765. //PortSections
  3766. pwisParams->AddKey(c_szAfPortSections, strPortSections.c_str());
  3767. //DialoutProtocols
  3768. err = prkProtocols->QueryValue(L"fIpxSelected", dwValue);
  3769. if ((0 == err) && dwValue)
  3770. {
  3771. AddAtEndOfStringList(slTemp, c_szAfIpx);
  3772. }
  3773. err = prkProtocols->QueryValue(L"fNetbeuiSelected", dwValue);
  3774. if ((0 == err) && dwValue)
  3775. {
  3776. AddAtEndOfStringList(slTemp, c_szAfNetbeui);
  3777. }
  3778. err = prkProtocols->QueryValue(L"fTcpIpSelected", dwValue);
  3779. if ((0 == err) && dwValue)
  3780. {
  3781. AddAtEndOfStringList(slTemp, c_szAfTcpip);
  3782. }
  3783. if (!slTemp.empty())
  3784. pwisParams->AddKey(L"DialoutProtocols", slTemp);
  3785. //DialinProtocols
  3786. DWORD dwIpxAllowed, dwNetBEUIAllowed, dwTcpIpAllowed;
  3787. EraseAndDeleteAll(slTemp);
  3788. err = prkProtocols->QueryValue(L"fIpxAllowed", dwIpxAllowed);
  3789. if ((0 == err) && dwIpxAllowed)
  3790. {
  3791. AddAtEndOfStringList(slTemp, c_szAfIpx);
  3792. }
  3793. err = prkProtocols->QueryValue(L"fNetbeuiAllowed", dwNetBEUIAllowed);
  3794. if ((0 == err) && dwNetBEUIAllowed)
  3795. {
  3796. AddAtEndOfStringList(slTemp, c_szAfNetbeui);
  3797. }
  3798. err = prkProtocols->QueryValue(L"fTcpIpAllowed", dwTcpIpAllowed);
  3799. if ((0 == err) && dwTcpIpAllowed)
  3800. {
  3801. AddAtEndOfStringList(slTemp, c_szAfTcpip);
  3802. }
  3803. if (!slTemp.empty())
  3804. pwisParams->AddKey(L"DialinProtocols", slTemp);
  3805. if (dwNetBEUIAllowed)
  3806. {
  3807. //NetBEUIClientAccess
  3808. PCORegKey prkNetBEUI = new CORegKey(*prkProtocols, L"NBF");
  3809. err = prkNetBEUI->QueryValue(L"NetbiosGatewayEnabled", dwValue);
  3810. if (0 == err)
  3811. {
  3812. if (dwValue)
  3813. {
  3814. pwisParams->AddKey(c_szAfNetbeuiClientAccess, c_szAfNetwork);
  3815. }
  3816. else
  3817. {
  3818. pwisParams->AddKey(c_szAfNetbeuiClientAccess, c_szAfThisComputer);
  3819. }
  3820. }
  3821. DeleteIfNotNull(prkNetBEUI);
  3822. }
  3823. if (dwTcpIpAllowed)
  3824. {
  3825. //TcpIpClientAccess
  3826. PCORegKey prkTcpIp = new CORegKey(*prkProtocols, L"IP");
  3827. err = prkTcpIp->QueryValue(L"AllowNetworkAccess", dwValue);
  3828. if (0 == err)
  3829. {
  3830. if (dwValue)
  3831. {
  3832. pwisParams->AddKey(c_szAfTcpipClientAccess, c_szAfNetwork);
  3833. }
  3834. else
  3835. {
  3836. pwisParams->AddKey(c_szAfTcpipClientAccess, c_szAfThisComputer);
  3837. }
  3838. }
  3839. //UseDHCP
  3840. err = prkTcpIp->QueryValue(L"UseDHCPAddressing", dwValue);
  3841. if (0 == err)
  3842. {
  3843. pwisParams->AddBoolKey(c_szAfUseDhcp, dwValue);
  3844. if (!dwValue)
  3845. {
  3846. // registry values for NT4
  3847. static const WCHAR c_szIpAddressStart[] = L"IpAddressStart";
  3848. static const WCHAR c_szIpAddressEnd[] = L"IpAddressEnd";
  3849. err = prkTcpIp->QueryValue(c_szIpAddressStart, strIpAddrStart);
  3850. if (0 == err)
  3851. {
  3852. err = prkTcpIp->QueryValue(c_szIpAddressEnd, strIpAddrEnd);
  3853. if (0 == err)
  3854. {
  3855. pwisParams->AddKey(c_szAfIpAddressStart, strIpAddrStart.c_str());
  3856. pwisParams->AddKey(c_szAfIpAddressEnd, strIpAddrEnd.c_str());
  3857. }
  3858. }
  3859. else if (ERROR_FILE_NOT_FOUND == err)
  3860. {
  3861. // IpAddressStart value not found, try for IpAddress/Mask
  3862. static const WCHAR c_szIpAddress[] = L"IpAddress";
  3863. static const WCHAR c_szIpMask[] = L"IpMask";
  3864. tstring strIpAddr;
  3865. tstring strIpMask;
  3866. err = prkTcpIp->QueryValue(c_szIpAddress, strIpAddr);
  3867. if (0 == err)
  3868. {
  3869. err = prkTcpIp->QueryValue(c_szIpMask, strIpMask);
  3870. if (0 == err)
  3871. {
  3872. ConvertAddrAndMaskToIpAddrRange(strIpAddr.c_str(),
  3873. strIpMask.c_str(),
  3874. &strIpAddrStart,
  3875. &strIpAddrEnd);
  3876. pwisParams->AddKey(c_szAfIpAddressStart, strIpAddrStart.c_str());
  3877. pwisParams->AddKey(c_szAfIpAddressEnd, strIpAddrEnd.c_str());
  3878. }
  3879. }
  3880. }
  3881. }
  3882. }
  3883. //ClientCanRequestIPAddress
  3884. if (0 == prkTcpIp->QueryValue(L"AllowClientIPAddresses", dwValue))
  3885. {
  3886. pwisParams->AddBoolKey(c_szAfClientCanReqIpaddr, dwValue);
  3887. }
  3888. DeleteIfNotNull(prkTcpIp);
  3889. }
  3890. if (dwIpxAllowed)
  3891. {
  3892. //IpxClientAccess
  3893. PCORegKey prkIpx = new CORegKey(*prkProtocols, L"IPX");
  3894. err = prkIpx->QueryValue(L"AllowNetworkAccess", dwValue);
  3895. if (0 == err)
  3896. {
  3897. if (dwValue)
  3898. {
  3899. pwisParams->AddKey(c_szAfIpxClientAccess, c_szAfNetwork);
  3900. }
  3901. else
  3902. {
  3903. pwisParams->AddKey(c_szAfIpxClientAccess, c_szAfThisComputer);
  3904. }
  3905. }
  3906. //AutomaticNetworkNumbers
  3907. err = prkIpx->QueryValue(L"AutoWanNetAllocation", dwValue);
  3908. if (0 == err)
  3909. {
  3910. pwisParams->AddBoolKey(c_szAfAutoNetworkNumbers, dwValue);
  3911. }
  3912. //NetworkNumberFrom
  3913. err = prkIpx->QueryValue(L"FirstWanNet", dwValue);
  3914. if (0 == err)
  3915. {
  3916. pwisParams->AddKey(c_szAfNetNumberFrom, dwValue);
  3917. }
  3918. // WanNetPoolSize
  3919. err = prkIpx->QueryValue(L"WanNetPoolSize", dwValue);
  3920. if (0 == err)
  3921. {
  3922. pwisParams->AddKey(c_szAfWanNetPoolSize, dwValue);
  3923. }
  3924. //AssignSameNetworkNumber
  3925. err = prkIpx->QueryValue(L"GlobalWanNet", dwValue);
  3926. if (0 == err)
  3927. {
  3928. pwisParams->AddBoolKey(c_szAfSameNetworkNumber, dwValue);
  3929. }
  3930. //ClientsCanRequestIpxNodeNumber
  3931. err = prkIpx->QueryValue(L"AcceptRemoteNodeNumber", dwValue);
  3932. if (0 == err)
  3933. {
  3934. pwisParams->AddBoolKey(c_szAfClientReqNodeNumber, dwValue);
  3935. }
  3936. DeleteIfNotNull(prkIpx);
  3937. }
  3938. {
  3939. //SecureVPN
  3940. PCORegKey prkRasman = new CORegKey(HKEY_LOCAL_MACHINE, c_szRegKeyRasMan);
  3941. err = prkRasman->QueryValue(L"SecureVPN", dwValue);
  3942. if (0 == err)
  3943. {
  3944. pwisParams->AddKey(c_szAfSecureVPN, dwValue);
  3945. }
  3946. //ForceStrongEncryption
  3947. // 398632: write this value, for both regular RAS case & steelhead case
  3948. dwValue = 0; // to avoid fall-thru problem (writing 0 to the answerfile is ok)
  3949. if (fSteelHeadInstalled)
  3950. {
  3951. err = prkRasman->QueryValue(L"ForceStrongEncryption", dwValue);
  3952. }
  3953. else
  3954. {
  3955. PCORegKey prkComPCP = new CORegKey(HKEY_LOCAL_MACHINE, c_szRegKeyRasManSH);
  3956. err = prkComPCP->QueryValue(L"ForceStrongEncryption", dwValue);
  3957. DeleteIfNotNull(prkComPCP);
  3958. }
  3959. if (0 == err)
  3960. {
  3961. pwisParams->AddBoolKey(c_szAfForceStrongEncryption, dwValue);
  3962. }
  3963. DeleteIfNotNull(prkRasman);
  3964. }
  3965. pwifAnswerFile->GotoEnd();
  3966. tstring strParamsSectionName;
  3967. PCWInfSection pwisRasComponent;
  3968. if (g_fAtLeastOneDialOut)
  3969. {
  3970. strParamsSectionName = c_szAfParams;
  3971. strParamsSectionName = strParamsSectionName + c_szInfId_MS_RasCli;
  3972. pwisNetServices->AddKey(c_szInfId_MS_RasCli, strParamsSectionName.c_str());
  3973. pwisRasComponent = pwifAnswerFile->AddSection(strParamsSectionName.c_str());
  3974. pwisRasComponent->AddKey(c_szAfInfid, c_szInfId_MS_RasCli);
  3975. pwisRasComponent->AddKey(c_szAfParamsSection, pwisParams->Name());
  3976. }
  3977. if (g_fAtLeastOneDialIn)
  3978. {
  3979. strParamsSectionName = c_szAfParams;
  3980. strParamsSectionName = strParamsSectionName + c_szInfId_MS_RasSrv;
  3981. pwisNetServices->AddKey(c_szInfId_MS_RasSrv, strParamsSectionName.c_str());
  3982. pwisRasComponent = pwifAnswerFile->AddSection(strParamsSectionName.c_str());
  3983. pwisRasComponent->AddKey(c_szAfInfid, c_szInfId_MS_RasSrv);
  3984. pwisRasComponent->AddKey(c_szAfParamsSection, pwisParams->Name());
  3985. }
  3986. // SetDialInUsage
  3987. BOOL fSetDialInUsage = TRUE;
  3988. if (g_NetUpgradeInfo.To.ProductType != NT_SERVER)
  3989. {
  3990. fSetDialInUsage = RasGetDialInUsage ();
  3991. }
  3992. pwisParams->AddKey(c_szAfSetDialinUsage, (UINT) fSetDialInUsage);
  3993. if (fSteelHeadInstalled)
  3994. {
  3995. WriteRouterUpgradeInfo(pwifAnswerFile);
  3996. }
  3997. else
  3998. {
  3999. TraceTag(ttidNetUpgrade, "%s: Router is not installed", __FUNCNAME__);
  4000. }
  4001. DeleteIfNotNull(prkRAS);
  4002. DeleteIfNotNull(prkProtocols);
  4003. EraseAndDeleteAll(slTemp);
  4004. EraseAndDeleteAll(slPorts);
  4005. EraseAndDeleteAll(slUsage);
  4006. return TRUE;
  4007. }
  4008. // ----------------------------------------------------------------------
  4009. //
  4010. // Function: HrWritePreSP3ComponentsToSteelHeadUpgradeParams
  4011. //
  4012. // Purpose: Write parameters of pre-SP3 steelhead components to answerfile
  4013. //
  4014. // Arguments:
  4015. // pwifAnswerFile [in] pointer to answerfile
  4016. //
  4017. // Returns: S_OK on success, otherwise an error code
  4018. //
  4019. // Author: kumarp 11-December-97
  4020. //
  4021. // Notes: DHCPRelayAgent, Rip for Ip(x), SapAgent --> Steelhead upgrade
  4022. //
  4023. HRESULT
  4024. HrWritePreSP3ComponentsToSteelHeadUpgradeParams(
  4025. IN CWInfFile* pwifAnswerFile)
  4026. {
  4027. DefineFunctionName("HrWritePreSP3ComponentsToSteelHeadUpgradeParams");
  4028. TraceFunctionEntry(ttidNetUpgrade);
  4029. HRESULT hr=S_OK;
  4030. CWInfSection* pwisServices;
  4031. pwisServices = pwifAnswerFile->FindSection(c_szAfSectionNetServices);
  4032. if (!pwisServices)
  4033. {
  4034. hr = E_FAIL;
  4035. goto return_from_function;
  4036. }
  4037. if (FIsServiceKeyPresent(c_szSvcRouter))
  4038. {
  4039. hr = S_OK;
  4040. TraceTag(ttidNetUpgrade, "%s: SteelHead is found to be installed, individual components will not be upgraded", __FUNCNAME__);
  4041. goto return_from_function;
  4042. }
  4043. BOOL fSrv2SrvUpgrade;
  4044. fSrv2SrvUpgrade = FALSE;
  4045. if (g_NetUpgradeInfo.From.ProductType == NT_SERVER)
  4046. {
  4047. if (g_NetUpgradeInfo.To.ProductType == NT_WORKSTATION)
  4048. {
  4049. AssertSz(FALSE, "Cannot upgrade from srv to wks!!");
  4050. }
  4051. else if (g_NetUpgradeInfo.To.ProductType == NT_SERVER)
  4052. {
  4053. fSrv2SrvUpgrade = TRUE;
  4054. }
  4055. }
  4056. BOOL fInstallSteelHead;
  4057. BOOL fInstallSapAgent;
  4058. fInstallSteelHead = FALSE;
  4059. fInstallSapAgent = FALSE;
  4060. BOOL fSapAgentInstalled;
  4061. BOOL fRipForIpInstalled;
  4062. BOOL fRipForIpxInstalled;
  4063. BOOL fDhcpRelayAgentInstalled;
  4064. fSapAgentInstalled = FALSE;
  4065. fRipForIpInstalled = FALSE;
  4066. fRipForIpxInstalled = FALSE;
  4067. fDhcpRelayAgentInstalled = FALSE;
  4068. // first find out which components are installed.
  4069. //
  4070. fSapAgentInstalled = FIsServiceKeyPresent(c_szSvcSapAgent);
  4071. fRipForIpInstalled = FIsServiceKeyPresent(c_szSvcRipForIp);
  4072. fRipForIpxInstalled = FIsServiceKeyPresent(c_szSvcRipForIpx);
  4073. fDhcpRelayAgentInstalled = FIsServiceKeyPresent(c_szSvcDhcpRelayAgent);
  4074. #ifdef ENABLETRACE
  4075. if (fSapAgentInstalled)
  4076. {
  4077. TraceTag(ttidNetUpgrade, "%s: %S is installed", __FUNCNAME__,
  4078. c_szSvcSapAgent);
  4079. }
  4080. if (fRipForIpInstalled)
  4081. {
  4082. TraceTag(ttidNetUpgrade, "%s: %S is installed", __FUNCNAME__,
  4083. c_szSvcRipForIp);
  4084. }
  4085. if (fRipForIpxInstalled)
  4086. {
  4087. TraceTag(ttidNetUpgrade, "%s: %S is installed", __FUNCNAME__,
  4088. c_szSvcRipForIpx);
  4089. }
  4090. if (fDhcpRelayAgentInstalled)
  4091. {
  4092. TraceTag(ttidNetUpgrade, "%s: %S is installed", __FUNCNAME__,
  4093. c_szSvcDhcpRelayAgent);
  4094. }
  4095. #endif
  4096. // now separate out cases to consider
  4097. //
  4098. if (fSapAgentInstalled &&
  4099. !(fRipForIpxInstalled || fRipForIpInstalled || fDhcpRelayAgentInstalled))
  4100. {
  4101. fInstallSapAgent = TRUE;
  4102. }
  4103. else if (fRipForIpInstalled &&
  4104. !(fRipForIpxInstalled || fSapAgentInstalled ||
  4105. fDhcpRelayAgentInstalled))
  4106. {
  4107. if (fSrv2SrvUpgrade)
  4108. {
  4109. fInstallSteelHead = TRUE;
  4110. }
  4111. }
  4112. else if ((fRipForIpInstalled && fSapAgentInstalled) &&
  4113. !(fRipForIpxInstalled || fDhcpRelayAgentInstalled))
  4114. {
  4115. if (fSrv2SrvUpgrade)
  4116. {
  4117. fInstallSteelHead = TRUE;
  4118. }
  4119. else
  4120. {
  4121. fInstallSapAgent = TRUE;
  4122. }
  4123. }
  4124. else if (fRipForIpxInstalled || fDhcpRelayAgentInstalled)
  4125. {
  4126. fInstallSteelHead = TRUE;
  4127. }
  4128. else
  4129. {
  4130. TraceTag(ttidNetUpgrade, "%s: no pre-SP3 steelhead components found",
  4131. __FUNCNAME__);
  4132. }
  4133. AssertSz(!(fInstallSapAgent && fInstallSteelHead),
  4134. "Both fInstallSteelHead && fInstallSapAgent cannot be TRUE");
  4135. // now go ahead and output the right information for the right case
  4136. // in the answerfile
  4137. //
  4138. if (fInstallSteelHead)
  4139. {
  4140. TraceTag(ttidNetUpgrade,
  4141. "%s: The component(s) found will be upgraded to SteelHead",
  4142. __FUNCNAME__);
  4143. WriteRouterUpgradeInfo(pwifAnswerFile);
  4144. }
  4145. else if (fInstallSapAgent)
  4146. {
  4147. TraceTag(ttidNetUpgrade, "%s: dumping data to upgrade SAP agent", __FUNCNAME__);
  4148. CWInfSection* pwisServices;
  4149. pwisServices = pwifAnswerFile->FindSection(c_szAfSectionNetServices);
  4150. AssertSz(pwisServices, "[NetServices] section missing!!");
  4151. if (pwisServices)
  4152. {
  4153. tstring strSapSection;
  4154. strSapSection = c_szAfParams;
  4155. strSapSection += c_szInfId_MS_NwSapAgent;
  4156. CWInfSection* pwisSap;
  4157. pwisSap = pwifAnswerFile->AddSection(strSapSection.c_str());
  4158. if (pwisSap)
  4159. {
  4160. pwisServices->AddKey(c_szInfId_MS_NwSapAgent,
  4161. strSapSection.c_str());
  4162. (void) HrNetRegSaveServiceSubKeyAndAddToSection(
  4163. c_szSvcSapAgent,
  4164. c_szParameters,
  4165. c_szAfNwSapAgentParams,
  4166. pwisSap);
  4167. }
  4168. }
  4169. }
  4170. return_from_function:
  4171. TraceError(__FUNCNAME__, hr);
  4172. return hr;
  4173. }
  4174. // ----------------------------------------------------------------------
  4175. //
  4176. // Function: WriteNetBIOSParams
  4177. //
  4178. // Purpose: Write parameters of NetBIOS to the specified section
  4179. //
  4180. // Arguments:
  4181. // pwifAnswerFile [in] pointer to answerfile
  4182. // pwisParams [in] section where to write this info
  4183. //
  4184. // Returns: TRUE on success, FALSE otherwise
  4185. //
  4186. // Author: kumarp 17-December-97
  4187. //
  4188. BOOL
  4189. WriteNetBIOSParams (
  4190. IN PCWInfFile pwifAnswerFile,
  4191. IN PCWInfSection pwisParams)
  4192. {
  4193. DefineFunctionName("WriteNetBIOSParams");
  4194. TraceFunctionEntry(ttidNetUpgrade);
  4195. PCORegKey prkLinkage;
  4196. // The netbios section will be used to apply lana config but since
  4197. // MSClient installs NetBIOS we don't want to install it
  4198. // via the answerfilein GUI mode.
  4199. //
  4200. pwisParams->AddBoolKey(c_szAfSkipInstall, TRUE);
  4201. GetServiceSubkey(c_szSvcNetBIOS, c_szLinkage, prkLinkage);
  4202. if (!prkLinkage)
  4203. return FALSE;
  4204. TStringList slRoutes, slRoute, slLanaPath;
  4205. tstring strRoute, strLanaPath, strTemp;
  4206. TStringListIter iter;
  4207. TByteArray baLanaMap;
  4208. prkLinkage->QueryValue(L"LanaMap", baLanaMap);
  4209. BYTE* pbData=NULL;
  4210. if (baLanaMap.size() > 0)
  4211. {
  4212. GetDataFromByteArray(baLanaMap, pbData);
  4213. WORD* pwLanaCodes;
  4214. WORD wLanaNumber;
  4215. WORD wRouteNum;
  4216. pwLanaCodes = (WORD *) pbData;
  4217. prkLinkage->QueryValue(c_szRegValRoute, slRoutes);
  4218. iter = slRoutes.begin();
  4219. wRouteNum=0;
  4220. while (iter != slRoutes.end())
  4221. {
  4222. strRoute = **iter++;
  4223. TraceTag(ttidNetUpgrade, "%s: processing: %S",
  4224. __FUNCNAME__, strRoute.c_str());
  4225. EraseAndDeleteAll(slLanaPath);
  4226. ConvertRouteToStringList(strRoute.c_str(), slRoute);
  4227. TStringListIter pos2 = slRoute.begin();
  4228. while (pos2 != slRoute.end())
  4229. {
  4230. strTemp = **pos2++;
  4231. TraceTag(ttidNetUpgrade, "%s: route component: %S",
  4232. __FUNCNAME__, strTemp.c_str());
  4233. if (IsNetCardProductName(strTemp.c_str()))
  4234. continue;
  4235. MapNetComponentNameForBinding(strTemp.c_str(), strTemp);
  4236. AddAtEndOfStringList(slLanaPath, strTemp.c_str());
  4237. // Stop adding components if the last one soesn't
  4238. // expose its lower components.
  4239. if (FIsDontExposeLowerComponent (strTemp.c_str()))
  4240. {
  4241. break;
  4242. }
  4243. }
  4244. // Note: The following must be written out exactly!!! The
  4245. // consumer of this information expects each LanaPath key to be
  4246. // followed by the corresponding LanaNumber key.
  4247. //
  4248. TraceStringList(ttidNetUpgrade, L"LanaPath: ", slLanaPath);
  4249. pwisParams->AddKey(L"LanaPath", slLanaPath);
  4250. wLanaNumber = HIBYTE (pwLanaCodes[wRouteNum]);
  4251. TraceTag(ttidNetUpgrade, "%s: LanaNumber: 0x%x", __FUNCNAME__, wLanaNumber);
  4252. pwisParams->AddHexKey(L"LanaNumber", wLanaNumber);
  4253. wRouteNum++;
  4254. }
  4255. pwisParams->AddKey (L"NumberOfPaths", wRouteNum);
  4256. }
  4257. else
  4258. {
  4259. TraceTag(ttidNetUpgrade, "%s: LanaMap has no entries!!, skipped LanaMap dump", __FUNCNAME__);
  4260. }
  4261. DeleteIfNotNull(prkLinkage);
  4262. EraseAndDeleteAll(slRoute);
  4263. EraseAndDeleteAll(slRoutes);
  4264. EraseAndDeleteAll(slLanaPath);
  4265. delete pbData;
  4266. return TRUE;
  4267. }
  4268. // ----------------------------------------------------------------------
  4269. //
  4270. // Function: WriteDhcpServerParams
  4271. //
  4272. // Purpose: Write parameters of DHCPServer to the specified section
  4273. //
  4274. // Arguments:
  4275. // pwifAnswerFile [in] pointer to answerfile
  4276. // pwisParams [in] section where to write the parameters
  4277. //
  4278. // Returns: TRUE on success, FALSE otherwise
  4279. //
  4280. // Author: kumarp 17-December-97
  4281. //
  4282. BOOL
  4283. WriteDhcpServerParams (
  4284. IN PCWInfFile pwifAnswerFile,
  4285. IN PCWInfSection pwisParams)
  4286. {
  4287. DefineFunctionName("WriteDhcpServerParams");
  4288. TraceFunctionEntry(ttidNetUpgrade);
  4289. static const WCHAR c_szConfiguration[] = L"Configuration";
  4290. HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcDhcpServer,
  4291. c_szParameters,
  4292. c_szAfDhcpServerParameters,
  4293. pwisParams);
  4294. HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcDhcpServer,
  4295. c_szConfiguration,
  4296. c_szAfDhcpServerConfiguration,
  4297. pwisParams);
  4298. return TRUE;
  4299. }
  4300. // ----------------------------------------------------------------------
  4301. //
  4302. // Function: WriteTp4Params
  4303. //
  4304. // Purpose: Write parameters of Tp4 to the specified section
  4305. //
  4306. // Arguments:
  4307. // pwifAnswerFile [in] pointer to answerfile
  4308. // pwisParams [in] section where to write the parameters
  4309. //
  4310. // Returns: TRUE on success, FALSE otherwise
  4311. //
  4312. // Author: kumarp 01-October-98
  4313. //
  4314. BOOL
  4315. WriteTp4Params (
  4316. IN PCWInfFile pwifAnswerFile,
  4317. IN PCWInfSection pwisParams)
  4318. {
  4319. static const WCHAR c_szCLNP[] = L"IsoTp\\Parameters\\CLNP";
  4320. static const WCHAR c_szLocalMachineName[] = L"LocalMachineName";
  4321. static const WCHAR c_szLocalMachineNSAP[] = L"LocalMachineNSAP";
  4322. WriteServiceRegValueToAFile(pwisParams, c_szCLNP, c_szLocalMachineName);
  4323. WriteServiceRegValueToAFile(pwisParams, c_szCLNP, c_szLocalMachineNSAP);
  4324. return TRUE;
  4325. }
  4326. // ----------------------------------------------------------------------
  4327. //
  4328. // Function:WriteWLBSParams
  4329. //
  4330. // Purpose: Write parameters of WLBS (windows load balancing service)
  4331. // to the specified section
  4332. //
  4333. // Arguments:
  4334. // pwifAnswerFile [in] pointer to answerfile
  4335. // pwisParams [in] section where to write the parameters
  4336. //
  4337. // Returns: TRUE on success, FALSE otherwise
  4338. //
  4339. // Author: SumitC 04-Mar-99 created
  4340. //
  4341. BOOL
  4342. WriteWLBSParams(
  4343. IN PCWInfFile pwifAnswerFile,
  4344. IN PCWInfSection pwisParams)
  4345. {
  4346. DefineFunctionName("WriteWLBSParams");
  4347. TraceFunctionEntry(ttidNetUpgrade);
  4348. /* We should get here only for upgrades from NT4 or earlier */
  4349. Assert (g_NetUpgradeInfo.From.dwBuildNumber);
  4350. Assert (g_NetUpgradeInfo.From.dwBuildNumber <= wWinNT4BuildNumber);
  4351. HRESULT hr = S_OK;
  4352. static const struct
  4353. {
  4354. PCWSTR szName;
  4355. WORD wType;
  4356. } aParams[] =
  4357. {
  4358. { CVY_NAME_VERSION, CVY_TYPE_VERSION },
  4359. { CVY_NAME_DED_IP_ADDR, CVY_TYPE_DED_IP_ADDR },
  4360. { CVY_NAME_DED_NET_MASK, CVY_TYPE_DED_NET_MASK },
  4361. { CVY_NAME_HOST_PRIORITY, CVY_TYPE_HOST_PRIORITY },
  4362. { CVY_NAME_NETWORK_ADDR, CVY_TYPE_NETWORK_ADDR },
  4363. { CVY_NAME_CL_IP_ADDR, CVY_TYPE_CL_IP_ADDR },
  4364. { CVY_NAME_CL_NET_MASK, CVY_TYPE_CL_NET_MASK },
  4365. { CVY_NAME_CLUSTER_MODE, CVY_TYPE_CLUSTER_MODE },
  4366. { CVY_NAME_ALIVE_PERIOD, CVY_TYPE_ALIVE_PERIOD },
  4367. { CVY_NAME_ALIVE_TOLER, CVY_TYPE_ALIVE_TOLER },
  4368. { CVY_NAME_NUM_ACTIONS, CVY_TYPE_NUM_ACTIONS },
  4369. { CVY_NAME_NUM_PACKETS, CVY_TYPE_NUM_PACKETS },
  4370. { CVY_NAME_NUM_SEND_MSGS, CVY_TYPE_NUM_SEND_MSGS },
  4371. { CVY_NAME_DOMAIN_NAME, CVY_TYPE_DOMAIN_NAME },
  4372. { CVY_NAME_LICENSE_KEY, CVY_TYPE_LICENSE_KEY },
  4373. { CVY_NAME_RMT_PASSWORD, CVY_TYPE_RMT_PASSWORD },
  4374. { CVY_NAME_RCT_PASSWORD, CVY_TYPE_RCT_PASSWORD },
  4375. { CVY_NAME_RCT_PORT, CVY_TYPE_RCT_PORT },
  4376. { CVY_NAME_RCT_ENABLED, CVY_TYPE_RCT_ENABLED },
  4377. { CVY_NAME_NUM_RULES, CVY_TYPE_NUM_RULES },
  4378. { CVY_NAME_CUR_VERSION, CVY_TYPE_CUR_VERSION },
  4379. { CVY_NAME_PORT_RULES, CVY_TYPE_PORT_RULES },
  4380. { CVY_NAME_DSCR_PER_ALLOC, CVY_TYPE_DSCR_PER_ALLOC },
  4381. { CVY_NAME_MAX_DSCR_ALLOCS,CVY_TYPE_MAX_DSCR_ALLOCS },
  4382. { CVY_NAME_SCALE_CLIENT, CVY_TYPE_SCALE_CLIENT },
  4383. { CVY_NAME_CLEANUP_DELAY, CVY_TYPE_CLEANUP_DELAY },
  4384. { CVY_NAME_NBT_SUPPORT, CVY_TYPE_NBT_SUPPORT },
  4385. { CVY_NAME_MCAST_SUPPORT, CVY_TYPE_MCAST_SUPPORT },
  4386. { CVY_NAME_MCAST_SPOOF, CVY_TYPE_MCAST_SPOOF },
  4387. { CVY_NAME_MASK_SRC_MAC, CVY_TYPE_MASK_SRC_MAC },
  4388. { CVY_NAME_CONVERT_MAC, CVY_TYPE_CONVERT_MAC },
  4389. };
  4390. // Verify that we have the name of the adapter to which NLB should be bound
  4391. if (0 == pszWlbsClusterAdapterName[0])
  4392. {
  4393. hr = E_UNEXPECTED;
  4394. }
  4395. if (SUCCEEDED(hr))
  4396. {
  4397. static const WCHAR c_szWLBSParams[] = L"WLBS\\Parameters";
  4398. tstring szSectionName = pwisParams->Name();
  4399. // Adapter01 is hardcoded is for an NT4 to Whistler upgrade, we will always only have one WLBS adapter
  4400. szSectionName += L".Adapter01";
  4401. pwisParams->AddKey(c_szAfAdapterSections, szSectionName.c_str());
  4402. PCWInfSection pWlbsAdapterSection = pwifAnswerFile->AddSection(szSectionName.c_str());
  4403. if (!pWlbsAdapterSection)
  4404. {
  4405. hr = E_FAIL;
  4406. }
  4407. if (SUCCEEDED(hr))
  4408. {
  4409. pWlbsAdapterSection->AddKey(c_szAfSpecificTo, pszWlbsClusterAdapterName);
  4410. for (UINT i = 0 ; i < celems(aParams); ++i)
  4411. {
  4412. WriteServiceRegValueToAFile(pWlbsAdapterSection,
  4413. c_szWLBSParams,
  4414. aParams[i].szName,
  4415. aParams[i].wType);
  4416. }
  4417. }
  4418. }
  4419. if (FAILED(hr))
  4420. {
  4421. TraceError("WriteWLBSParams", hr );
  4422. }
  4423. return SUCCEEDED(hr);
  4424. }
  4425. // ----------------------------------------------------------------------
  4426. //
  4427. // Function:WriteConvoyParams
  4428. //
  4429. // Purpose: Write parameters of Convoy (windows load balancing service)
  4430. // to the specified section
  4431. //
  4432. // Arguments:
  4433. // pwifAnswerFile [in] pointer to answerfile
  4434. // pwisParams [in] section where to write the parameters
  4435. //
  4436. // Returns: TRUE on success, FALSE otherwise
  4437. //
  4438. // Author: SumitC 04-Mar-99 created
  4439. //
  4440. BOOL
  4441. WriteConvoyParams(
  4442. IN PCWInfFile pwifAnswerFile,
  4443. IN PCWInfSection pwisParams)
  4444. {
  4445. DefineFunctionName("WriteConvoyParams");
  4446. TraceFunctionEntry(ttidNetUpgrade);
  4447. HRESULT hr = S_OK;
  4448. static const struct
  4449. {
  4450. PCWSTR szName;
  4451. WORD wType;
  4452. } aParams[] =
  4453. {
  4454. { CVY_NAME_VERSION, CVY_TYPE_VERSION },
  4455. { CVY_NAME_DED_IP_ADDR, CVY_TYPE_DED_IP_ADDR },
  4456. { CVY_NAME_DED_NET_MASK, CVY_TYPE_DED_NET_MASK },
  4457. { CVY_NAME_HOST_PRIORITY, CVY_TYPE_HOST_PRIORITY },
  4458. { CVY_NAME_NETWORK_ADDR, CVY_TYPE_NETWORK_ADDR },
  4459. { CVY_NAME_CL_IP_ADDR, CVY_TYPE_CL_IP_ADDR },
  4460. { CVY_NAME_CL_NET_MASK, CVY_TYPE_CL_NET_MASK },
  4461. { CVY_NAME_CLUSTER_MODE, CVY_TYPE_CLUSTER_MODE },
  4462. { CVY_NAME_ALIVE_PERIOD, CVY_TYPE_ALIVE_PERIOD },
  4463. { CVY_NAME_ALIVE_TOLER, CVY_TYPE_ALIVE_TOLER },
  4464. { CVY_NAME_NUM_ACTIONS, CVY_TYPE_NUM_ACTIONS },
  4465. { CVY_NAME_NUM_PACKETS, CVY_TYPE_NUM_PACKETS },
  4466. { CVY_NAME_NUM_SEND_MSGS, CVY_TYPE_NUM_SEND_MSGS },
  4467. { CVY_NAME_DOMAIN_NAME, CVY_TYPE_DOMAIN_NAME },
  4468. { CVY_NAME_LICENSE_KEY, CVY_TYPE_LICENSE_KEY },
  4469. { CVY_NAME_RMT_PASSWORD, CVY_TYPE_RMT_PASSWORD },
  4470. { CVY_NAME_RCT_PASSWORD, CVY_TYPE_RCT_PASSWORD },
  4471. { CVY_NAME_RCT_PORT, CVY_TYPE_RCT_PORT },
  4472. { CVY_NAME_RCT_ENABLED, CVY_TYPE_RCT_ENABLED },
  4473. { CVY_NAME_NUM_RULES, CVY_TYPE_NUM_RULES },
  4474. { CVY_NAME_CUR_VERSION, CVY_TYPE_CUR_VERSION },
  4475. { CVY_NAME_PORT_RULES, CVY_TYPE_PORT_RULES },
  4476. { CVY_NAME_DSCR_PER_ALLOC, CVY_TYPE_DSCR_PER_ALLOC },
  4477. { CVY_NAME_MAX_DSCR_ALLOCS,CVY_TYPE_MAX_DSCR_ALLOCS },
  4478. { CVY_NAME_SCALE_CLIENT, CVY_TYPE_SCALE_CLIENT },
  4479. { CVY_NAME_CLEANUP_DELAY, CVY_TYPE_CLEANUP_DELAY },
  4480. { CVY_NAME_NBT_SUPPORT, CVY_TYPE_NBT_SUPPORT },
  4481. { CVY_NAME_MCAST_SUPPORT, CVY_TYPE_MCAST_SUPPORT },
  4482. { CVY_NAME_MCAST_SPOOF, CVY_TYPE_MCAST_SPOOF },
  4483. { CVY_NAME_MASK_SRC_MAC, CVY_TYPE_MASK_SRC_MAC },
  4484. { CVY_NAME_CONVERT_MAC, CVY_TYPE_CONVERT_MAC },
  4485. };
  4486. static const WCHAR c_szConvoyParams[] = L"Convoy\\Parameters";
  4487. for (UINT i = 0 ; i < celems(aParams); ++i)
  4488. {
  4489. WriteServiceRegValueToAFile(pwisParams,
  4490. c_szConvoyParams,
  4491. aParams[i].szName,
  4492. aParams[i].wType);
  4493. }
  4494. return SUCCEEDED(hr);
  4495. }
  4496. // ----------------------------------------------------------------------
  4497. //
  4498. // Function: WriteNWCWorkstationParams
  4499. //
  4500. // Purpose: Write parameters of Netware Client to the answerfile
  4501. //
  4502. // Arguments:
  4503. // pwifAnswerFile [in] pointer to answerfile
  4504. // pwisParams [in] section where to write the parameters
  4505. //
  4506. // Returns: TRUE on success, FALSE otherwise
  4507. //
  4508. // Author: kumarp 17-December-97
  4509. //
  4510. BOOL
  4511. WriteNWCWorkstationParams (
  4512. IN PCWInfFile pwifAnswerFile,
  4513. IN PCWInfSection pwisParams)
  4514. {
  4515. DefineFunctionName("WriteNWCWorkstationParams");
  4516. TraceFunctionEntry(ttidNetUpgrade);
  4517. HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcNWCWorkstation,
  4518. c_szParameters,
  4519. c_szAfNWCWorkstationParameters,
  4520. pwisParams);
  4521. HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcNWCWorkstation,
  4522. c_szShares,
  4523. c_szAfNWCWorkstationShares,
  4524. pwisParams);
  4525. HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcNWCWorkstation,
  4526. c_szDrives,
  4527. c_szAfNWCWorkstationDrives,
  4528. pwisParams);
  4529. return TRUE;
  4530. // we want to retain this code till jeffspr makes up his mind
  4531. //
  4532. /* PCORegKey prkParams;
  4533. PCWInfSection pwisLogonInfo;
  4534. tstring strId;
  4535. GetServiceParamsKey(c_szSvcNWCWorkstation, prkParams);
  4536. if (!prkParams)
  4537. return FALSE;
  4538. CORegKey rkLogon(*prkParams, L"Logon");
  4539. CORegKey rkOption(*prkParams, L"Option");
  4540. //CORegKeyIter rkiLogon(rkLogon);
  4541. CORegKeyIter rkiOption(rkOption);
  4542. while (!rkiOption.Next(&strId))
  4543. {
  4544. CORegKey rkId(rkLogon, strId.c_str());
  4545. ContinueIf(!rkId.HKey());
  4546. TByteArray abLogonID;
  4547. rkId.QueryValue(L"LogonID", abLogonID);
  4548. QWORD qwLogonID = ConvertToQWord(abLogonID);
  4549. pwisParams->AddKey(L"LogonInfo", strId.c_str());
  4550. pwisLogonInfo = pwifAnswerFile->AddSection(strId.c_str());
  4551. ContinueIf(!pwisParams);
  4552. CORegKey rkOptionLogonId(rkOption, strId.c_str());
  4553. if (!rkOption.HKey())
  4554. {
  4555. continue;
  4556. }
  4557. // LogonId
  4558. pwisLogonInfo->AddQwordKey(L"LogonID", qwLogonID);
  4559. // LogonScript
  4560. WriteRegValueToAFile(pwisLogonInfo, rkOptionLogonId, L"LogonScript",
  4561. REG_DWORD, NULL, TRUE, (DWORD) 0);
  4562. // PreferredServer
  4563. WriteRegValueToAFile(pwisLogonInfo, rkOptionLogonId, L"PreferredServer");
  4564. // PrintOption
  4565. WriteRegValueToAFile(pwisLogonInfo, rkOptionLogonId,
  4566. L"PrintOption", REG_DWORD);
  4567. }
  4568. return TRUE;
  4569. */
  4570. }
  4571. // ----------------------------------------------------------------------
  4572. //
  4573. // Function: WriteBrowserParams
  4574. //
  4575. // Purpose: Write parameters of Browser to the specified section
  4576. //
  4577. // Arguments:
  4578. // pwifAnswerFile [in] pointer to answerfile
  4579. // pwisParams [in] section where to write the parameters
  4580. //
  4581. // Returns: TRUE on success, FALSE otherwise
  4582. //
  4583. // Author: kumarp 17-December-97
  4584. //
  4585. BOOL
  4586. WriteBrowserParams (
  4587. IN PCWInfFile pwifAnswerFile,
  4588. IN PCWInfSection pwisParams)
  4589. {
  4590. DefineFunctionName("WriteBrowserParams");
  4591. TraceFunctionEntry(ttidNetUpgrade);
  4592. PCORegKey prkParams;
  4593. //Browser stores its parameters under the LanmanWorkstation key!
  4594. GetServiceParamsKey(c_szSvcWorkstation, prkParams);
  4595. TStringList slDomains;
  4596. prkParams->QueryValue(L"OtherDomains", slDomains);
  4597. pwisParams->AddKey(c_szAfBrowseDomains, slDomains);
  4598. DeleteIfNotNull(prkParams);
  4599. // now write reg-dump keys
  4600. tstring strFileName;
  4601. tstring strServices = c_szRegKeyServices;
  4602. strServices += L"\\";
  4603. HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcBrowser,
  4604. c_szParameters,
  4605. c_szAfBrowserParameters,
  4606. pwisParams);
  4607. HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcNetLogon,
  4608. c_szParameters,
  4609. c_szAfNetLogonParameters,
  4610. pwisParams);
  4611. EraseAndDeleteAll(slDomains);
  4612. return TRUE;
  4613. }
  4614. // ----------------------------------------------------------------------
  4615. //
  4616. // Function: WriteLanmanServerParams
  4617. //
  4618. // Purpose: Write parameters of LanmanServer to the specified section
  4619. //
  4620. // Arguments:
  4621. // pwifAnswerFile [in] pointer to answerfile
  4622. // pwisParams [in] section where to write the parameters
  4623. //
  4624. // Returns: TRUE on success, FALSE otherwise
  4625. //
  4626. // Author: kumarp 17-December-97
  4627. //
  4628. BOOL
  4629. WriteLanmanServerParams (
  4630. IN PCWInfFile pwifAnswerFile,
  4631. IN PCWInfSection pwisParams)
  4632. {
  4633. DefineFunctionName("WriteLanmanServerParams");
  4634. TraceFunctionEntry(ttidNetUpgrade);
  4635. PCORegKey prkParams;
  4636. static const WCHAR c_szShares[] = L"Shares";
  4637. static const WCHAR c_szAutotunedParameters[] = L"AutotunedParameters";
  4638. static const WCHAR c_szMemoryManagement[] = L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management";
  4639. static const WCHAR c_szLargeSystemCache[] = L"LargeSystemCache";
  4640. GetServiceParamsKey(c_szSvcLmServer, prkParams);
  4641. DWORD dwValue=3;
  4642. HRESULT hr=S_OK;
  4643. //Optimization
  4644. prkParams->QueryValue(L"Size", dwValue);
  4645. if ((dwValue >= 1) && (dwValue <= 3))
  4646. {
  4647. if (dwValue == 3)
  4648. {
  4649. HKEY hkey;
  4650. // need to inspect one more key
  4651. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szMemoryManagement,
  4652. KEY_READ, &hkey);
  4653. if (S_OK == hr)
  4654. {
  4655. DWORD dw;
  4656. hr = HrRegQueryDword(hkey, c_szLargeSystemCache, &dw);
  4657. if (S_OK == hr)
  4658. {
  4659. if (dw == 0)
  4660. {
  4661. dwValue = 4;
  4662. }
  4663. }
  4664. RegCloseKey(hkey);
  4665. }
  4666. }
  4667. pwisParams->AddKey(c_szAfLmServerOptimization, g_pszServerOptimization[dwValue]);
  4668. }
  4669. //BroadcastsToLanman2Clients
  4670. dwValue=0;
  4671. prkParams->QueryValue(L"Lmannounce", dwValue);
  4672. pwisParams->AddBoolKey(c_szAfBroadcastToClients, dwValue);
  4673. // now write reg-dump keys
  4674. tstring strFileName;
  4675. tstring strServices = c_szRegKeyServices;
  4676. strServices += L"\\";
  4677. // ignore the error codes so that we can dump whatever is available/present
  4678. //
  4679. hr = HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcLmServer,
  4680. c_szParameters,
  4681. c_szAfLmServerParameters,
  4682. pwisParams);
  4683. hr = HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcLmServer,
  4684. c_szShares,
  4685. c_szAfLmServerShares,
  4686. pwisParams);
  4687. hr = HrNetRegSaveServiceSubKeyAndAddToSection(c_szSvcLmServer,
  4688. c_szAutotunedParameters,
  4689. c_szAfLmServerAutotunedParameters,
  4690. pwisParams);
  4691. DeleteIfNotNull(prkParams);
  4692. return TRUE;
  4693. }
  4694. // ----------------------------------------------------------------------
  4695. //
  4696. // Function: WriteLanmanWorkstationParams
  4697. //
  4698. // Purpose: Write parameters of LanmanWorkstation to the specified section
  4699. //
  4700. // Arguments:
  4701. // pwifAnswerFile [in] pointer to answerfile
  4702. // pwisParams [in] section where to write the parameters
  4703. //
  4704. // Returns: TRUE on success, FALSE otherwise
  4705. //
  4706. // Author: kumarp 17-December-97
  4707. //
  4708. BOOL
  4709. WriteLanmanWorkstationParams (
  4710. IN PCWInfFile pwifAnswerFile,
  4711. IN PCWInfSection pwisParams)
  4712. {
  4713. DefineFunctionName("WriteLanmanWorkstationParams");
  4714. TraceFunctionEntry(ttidNetUpgrade);
  4715. // pwisParams->AddComment(c_szNoParamsRequired);
  4716. return TRUE;
  4717. }
  4718. // ----------------------------------------------------------------------
  4719. //
  4720. // Function: WriteRPCLocatorParams
  4721. //
  4722. // Purpose: Write parameters of RPCLOCATOR to the specified section
  4723. //
  4724. // Arguments:
  4725. // pwifAnswerFile [in] pointer to answerfile
  4726. // pwisParams [in] section where to write the parameters
  4727. //
  4728. // Returns: TRUE on success, FALSE otherwise
  4729. //
  4730. // Author: kumarp 17-December-97
  4731. //
  4732. BOOL
  4733. WriteRPCLocatorParams (
  4734. IN PCWInfFile pwifAnswerFile,
  4735. IN PCWInfSection pwisParams)
  4736. {
  4737. DefineFunctionName("WriteRPCLocatorParams");
  4738. TraceFunctionEntry(ttidNetUpgrade);
  4739. //DefaultSecurityProvider
  4740. WriteRegValueToAFile(pwisParams,
  4741. HKEY_LOCAL_MACHINE,
  4742. L"SOFTWARE\\Microsoft\\Rpc\\SecurityService",
  4743. L"DefaultProvider", REG_SZ,
  4744. c_szAfDefaultProvider);
  4745. //NameServiceNetworkAddress
  4746. WriteRegValueToAFile(pwisParams,
  4747. HKEY_LOCAL_MACHINE,
  4748. L"SOFTWARE\\Microsoft\\Rpc\\NameService",
  4749. L"NetworkAddress", REG_SZ,
  4750. c_szAfNameServiceAddr);
  4751. //NameServiceProtocol
  4752. WriteRegValueToAFile(pwisParams,
  4753. HKEY_LOCAL_MACHINE,
  4754. L"SOFTWARE\\Microsoft\\Rpc\\NameService",
  4755. L"Protocol", REG_SZ,
  4756. c_szAfNameServiceProtocol);
  4757. return TRUE;
  4758. }
  4759. // ----------------------------------------------------------------------
  4760. //
  4761. // Function: IsNetComponentBindable
  4762. //
  4763. // Purpose: Determine if a component is bindable
  4764. // (it has Bind value under the Linkage key)
  4765. //
  4766. // Arguments:
  4767. // prkNetComponentLinkage [in] Linkage key of the component
  4768. //
  4769. // Returns: TRUE on success, FALSE otherwise
  4770. //
  4771. // Author: kumarp 17-December-97
  4772. //
  4773. BOOL
  4774. IsNetComponentBindable (
  4775. IN const PCORegKey prkNetComponentLinkage)
  4776. {
  4777. BOOL status;
  4778. TStringList slTemp;
  4779. status = prkNetComponentLinkage->QueryValue(c_szRegValBind, slTemp) == ERROR_SUCCESS;
  4780. EraseAndDeleteAll(slTemp);
  4781. return status;
  4782. }
  4783. // ----------------------------------------------------------------------
  4784. //
  4785. // Function: ConvertRouteToStringList
  4786. //
  4787. // Purpose: Convert Linkage\Route value to a tstring list
  4788. //
  4789. // Arguments:
  4790. // pszRoute [in] route
  4791. // slRoute [out] list of route elements
  4792. //
  4793. // Returns: None
  4794. //
  4795. // Author: kumarp 17-December-97
  4796. //
  4797. void
  4798. ConvertRouteToStringList (
  4799. IN PCWSTR pszRoute,
  4800. OUT TStringList &slRoute )
  4801. {
  4802. EraseAndDeleteAll(slRoute);
  4803. const WCHAR CHQUOTE = '"';
  4804. tstring str;
  4805. INT cQuote;
  4806. for ( cQuote = 0 ; *pszRoute ; pszRoute++ )
  4807. {
  4808. if ( *pszRoute == CHQUOTE )
  4809. {
  4810. if ( cQuote++ & 1 ) // If it's a closing quote...
  4811. {
  4812. if ( str.size() )
  4813. {
  4814. if (FIsDontExposeLowerComponent(str.c_str()))
  4815. {
  4816. break;
  4817. }
  4818. AddAtEndOfStringList(slRoute, str.c_str());
  4819. // If the route contains NetBT, then add in TCPIP
  4820. // because TCPIP is in the bind string in Windows 2000.
  4821. // e.g. a binding of NetBT->Adapter will become
  4822. // NetBT->TCPIP->Adapter.
  4823. //
  4824. if (0 == _wcsicmp (str.c_str(), L"NetBT"))
  4825. {
  4826. AddAtEndOfStringList(slRoute, L"TCPIP");
  4827. }
  4828. }
  4829. }
  4830. str.erase();
  4831. }
  4832. else
  4833. {
  4834. str += *pszRoute;
  4835. }
  4836. }
  4837. }
  4838. // ----------------------------------------------------------------------
  4839. //
  4840. // Function: IsMSNetClientComponent
  4841. //
  4842. // Purpose: Determine if the specified component is a subcomponent
  4843. // of MS_MSClient
  4844. //
  4845. // Arguments:
  4846. // pszComponentName [in] name of component
  4847. //
  4848. // Returns: TRUE on success, FALSE otherwise
  4849. //
  4850. // Author: kumarp 17-December-97
  4851. //
  4852. BOOL
  4853. IsMSNetClientComponent (
  4854. IN PCWSTR pszComponentName)
  4855. {
  4856. Assert (pszComponentName && *pszComponentName);
  4857. return ((!_wcsicmp(pszComponentName, c_szSvcBrowser)) ||
  4858. (!_wcsicmp(pszComponentName, c_szSvcWorkstation)) ||
  4859. (!_wcsicmp(pszComponentName, L"RpcLocator")));
  4860. }
  4861. // ----------------------------------------------------------------------
  4862. //
  4863. // Function: WriteBindings
  4864. //
  4865. // Purpose: Write disabled bindings of a component to [NetBindings] section
  4866. //
  4867. // Arguments:
  4868. // pszComponentName [in] name of component
  4869. //
  4870. // Returns: TRUE on success, FALSE otherwise
  4871. //
  4872. // Author: kumarp 17-December-97
  4873. //
  4874. BOOL
  4875. WriteBindings (
  4876. IN PCWSTR pszComponentName)
  4877. {
  4878. Assert (pszComponentName && *pszComponentName);
  4879. DefineFunctionName("WriteBindings");
  4880. BOOL fStatus=TRUE;
  4881. TStringList slBindings, slRoute;
  4882. tstring strRoute, strBindings, strTemp;
  4883. TStringListIter iter;
  4884. // we want to write bindings only for LanmanWorkstation among the
  4885. // MSClient components
  4886. //
  4887. if (IsMSNetClientComponent(pszComponentName) &&
  4888. (lstrcmpiW(pszComponentName, c_szSvcWorkstation)))
  4889. {
  4890. return TRUE;
  4891. }
  4892. TraceTag(ttidNetUpgrade, "%s: writing bindings of '%S'...",
  4893. __FUNCNAME__, pszComponentName);
  4894. PCORegKey prkNetComponentLinkage=NULL,
  4895. prkNetComponentLinkageDisabled=NULL;
  4896. GetServiceSubkey(pszComponentName, c_szLinkage, prkNetComponentLinkage);
  4897. if (!prkNetComponentLinkage || !IsNetComponentBindable(prkNetComponentLinkage))
  4898. goto error_cleanup;
  4899. GetServiceSubkey(pszComponentName,
  4900. c_szLinkageDisabled,
  4901. prkNetComponentLinkageDisabled);
  4902. if (!prkNetComponentLinkageDisabled)
  4903. goto error_cleanup;
  4904. //We write only those bindings that are disabled, others by default are enabled
  4905. // prkNetComponentLinkage->QueryValue(c_szRegValRoute, slBindings);
  4906. prkNetComponentLinkageDisabled->QueryValue(c_szRegValRoute, slBindings);
  4907. for (iter = slBindings.begin(); iter != slBindings.end(); iter++)
  4908. {
  4909. strRoute = **iter;
  4910. MapNetComponentNameForBinding(pszComponentName, strBindings);
  4911. if (!lstrcmpiW(strBindings.c_str(), c_szInfId_MS_NetBT))
  4912. {
  4913. strBindings += L",";
  4914. strBindings += c_szInfId_MS_TCPIP;
  4915. }
  4916. ConvertRouteToStringList(strRoute.c_str(), slRoute);
  4917. TStringListIter iterComponentsInRoute;
  4918. for (iterComponentsInRoute = slRoute.begin();
  4919. iterComponentsInRoute != slRoute.end();
  4920. iterComponentsInRoute++)
  4921. {
  4922. strTemp = **iterComponentsInRoute;
  4923. if (IsNetCardProductName(strTemp.c_str()))
  4924. continue;
  4925. MapNetComponentNameForBinding(strTemp.c_str(), strTemp);
  4926. // pre-NT5 code stores bindings such that MS_NetBT appears to
  4927. // bind directly to a netcard. in NT5 MS_NetBT binds to MS_TCPIP
  4928. // which then binds to a netcard.
  4929. // thus for any binding path having MS_NetBT in it, we need to
  4930. // convert this to MS_NetBT,MS_TCPIP
  4931. //
  4932. // NTRAID9:210426@20001130#deonb.
  4933. // This is redundant. ConvertRouteToStringList already add MS_TCPIP after encountering NETBT,
  4934. // Adding it again will result in a bindpath of MS_NetBT,ms_tcpip,MS_TCPIP which will not be matched
  4935. // by GUI setup. Removing this check.
  4936. // if (!lstrcmpiW(strTemp.c_str(), c_szInfId_MS_NetBT))
  4937. // {
  4938. // strTemp += L",";
  4939. // strTemp += c_szInfId_MS_TCPIP;
  4940. // }
  4941. // 306866: pre-NT5 code stores ISO/TP4 bindings in the form
  4942. // isotp4->streams->adapter. In NT5, each of these binds
  4943. // directly to the adapter. So if we find an isotp Route for
  4944. // which the first component is Streams, we skip it.
  4945. //
  4946. if (!lstrcmpiW(strBindings.c_str(), c_szInfId_MS_Isotpsys) &&
  4947. !lstrcmpiW(strTemp.c_str(), c_szInfId_MS_Streams))
  4948. {
  4949. continue;
  4950. }
  4951. strBindings += L"," + strTemp;
  4952. // 243906: if the component is DONT_EXPOSE_LOWER, terminate the bindpath
  4953. if (!lstrcmpiW(strTemp.c_str(), c_szInfId_MS_NWIPX) ||
  4954. !lstrcmpiW(strTemp.c_str(), c_szInfId_MS_NWNB) ||
  4955. !lstrcmpiW(strTemp.c_str(), c_szInfId_MS_NWSPX))
  4956. {
  4957. break;
  4958. }
  4959. }
  4960. EraseAndDeleteAll(slRoute);
  4961. // WLBS: don't write Disable bindings that contain MS_TCPIP and WLBS
  4962. // cluster adapter.
  4963. if (pszWlbsClusterAdapterName[0] != 0 &&
  4964. (strBindings.find(c_szInfId_MS_TCPIP) != tstring::npos ||
  4965. strBindings.find(c_szMSTCPIP) != tstring::npos) &&
  4966. strBindings.find(pszWlbsClusterAdapterName) != tstring::npos)
  4967. {
  4968. TraceTag(ttidNetUpgrade, "%s: skipping Disable=%S",
  4969. __FUNCNAME__, strBindings.c_str());
  4970. continue;
  4971. }
  4972. // end WLBS:
  4973. g_pwisBindings->AddKey(c_szAfDisable, strBindings.c_str());
  4974. TraceTag(ttidNetUpgrade, "%s: Disable=%S",
  4975. __FUNCNAME__, strBindings.c_str());
  4976. }
  4977. // WLBS: if WLBS is bound to a NIC, then write explicit Enable binding to it.
  4978. // by default, WLBS notifier object will disable all bindings on install.
  4979. if ((_wcsicmp(pszComponentName, c_szWLBS) == 0 ||
  4980. _wcsicmp(pszComponentName, c_szConvoy) == 0)
  4981. && pszWlbsClusterAdapterName[0] != 0)
  4982. {
  4983. strBindings = c_szMSWLBS;
  4984. strBindings += L",";
  4985. strBindings += pszWlbsClusterAdapterName;
  4986. g_pwisBindings->AddKey(c_szAfEnable, strBindings.c_str());
  4987. TraceTag(ttidNetUpgrade, "%s: Enable=%S",
  4988. __FUNCNAME__, strBindings.c_str());
  4989. }
  4990. // end WLBS:
  4991. fStatus=TRUE;
  4992. goto cleanup;
  4993. error_cleanup:
  4994. fStatus = FALSE;
  4995. cleanup:
  4996. DeleteIfNotNull(prkNetComponentLinkage);
  4997. DeleteIfNotNull(prkNetComponentLinkageDisabled);
  4998. EraseAndDeleteAll(slBindings);
  4999. return fStatus;
  5000. }
  5001. // ----------------------------------------------------------------------
  5002. // Misc. Helper Functions
  5003. // ----------------------------------------------------------------------
  5004. // ----------------------------------------------------------------------
  5005. //
  5006. // Function: WriteServiceRegValueToAFile
  5007. //
  5008. // Purpose: Write specified value in registry to the specified section
  5009. // in the answerfile, renaming if required
  5010. //
  5011. // Arguments:
  5012. // pwisSection [in] section to which the value is written
  5013. // pszServiceKey [in] name of service
  5014. // pszValueName [in] name of value under Parameters subkey
  5015. // wValueType [in] type of value
  5016. // pszValueNewName [in] change name to this
  5017. // fDefaultProvided [in] is a default value provided ?
  5018. // ... [in] use this default value if the specified value is
  5019. // not found in the registry
  5020. //
  5021. // Returns: TRUE on success, FALSE otherwise
  5022. //
  5023. // Author: kumarp 17-December-97
  5024. //
  5025. BOOL
  5026. WriteServiceRegValueToAFile(
  5027. IN PCWInfSection pwisSection,
  5028. IN PCWSTR pszServiceKey,
  5029. IN PCWSTR pszValueName,
  5030. IN WORD wValueType,
  5031. IN PCWSTR pszValueNewName,
  5032. IN BOOL fDefaultProvided,
  5033. ...)
  5034. {
  5035. AssertValidReadPtr(pwisSection);
  5036. AssertValidReadPtr(pszValueName);
  5037. tstring strKeyFullPath;
  5038. strKeyFullPath = tstring(L"System\\CurrentControlSet\\Services\\")
  5039. + pszServiceKey;
  5040. va_list arglist;
  5041. va_start (arglist, fDefaultProvided);
  5042. BOOL fStatus =
  5043. WriteRegValueToAFile(pwisSection, HKEY_LOCAL_MACHINE,
  5044. strKeyFullPath.c_str(), pszValueName, wValueType,
  5045. pszValueNewName, fDefaultProvided, arglist);
  5046. va_end(arglist);
  5047. return fStatus;
  5048. }
  5049. // ----------------------------------------------------------------------
  5050. //
  5051. // Function: WriteServiceRegValueToAFile
  5052. //
  5053. // Purpose: Write specified value in registry to the specified section
  5054. // in the answerfile, renaming if required
  5055. //
  5056. // Arguments:
  5057. // pwisSection [in] section to which the value is written
  5058. // hkey [in] handle to a regkey
  5059. // pszSubKey [in] name of subkey
  5060. // pszValueName [in] name of value
  5061. // wValueType [in] type of value
  5062. // pszValueNewName [in] change name to this
  5063. // fDefaultProvided [in] is a default value provided ?
  5064. // ... [in] use this default value if the specified value is
  5065. // not found in the registry
  5066. //
  5067. // Returns: TRUE on success, FALSE otherwise
  5068. //
  5069. // Author: kumarp 17-December-97
  5070. //
  5071. BOOL
  5072. WriteRegValueToAFile(
  5073. IN PCWInfSection pwisSection,
  5074. IN HKEY hKey,
  5075. IN PCWSTR pszSubKey,
  5076. IN PCWSTR pszValueName,
  5077. IN WORD wValueType,
  5078. IN PCWSTR pszValueNewName,
  5079. IN BOOL fDefaultProvided,
  5080. ...)
  5081. {
  5082. BOOL fStatus;
  5083. va_list arglist;
  5084. va_start (arglist, fDefaultProvided);
  5085. fStatus = WriteRegValueToAFile(pwisSection, hKey, pszSubKey,
  5086. pszValueName, wValueType,
  5087. pszValueNewName, fDefaultProvided, arglist);
  5088. va_end(arglist);
  5089. return fStatus;
  5090. }
  5091. // ----------------------------------------------------------------------
  5092. //
  5093. // Function: WriteServiceRegValueToAFile
  5094. //
  5095. // Purpose: Write specified value in registry to the specified section
  5096. // in the answerfile, renaming if required
  5097. //
  5098. // Arguments:
  5099. // pwisSection [in] section to which the value is written
  5100. // hkey [in] handle to a regkey
  5101. // pszSubKey [in] name of subkey
  5102. // pszValueName [in] name of value
  5103. // wValueType [in] type of value
  5104. // pszValueNewName [in] change name to this
  5105. // fDefaultProvided [in] is a default value provided ?
  5106. // arglist [in] use this default value if the specified value is
  5107. // not found in the registry
  5108. //
  5109. // Returns: TRUE on success, FALSE otherwise
  5110. //
  5111. // Author: kumarp 17-December-97
  5112. //
  5113. BOOL
  5114. WriteRegValueToAFile(
  5115. IN PCWInfSection pwisSection,
  5116. IN HKEY hKey,
  5117. IN PCWSTR pszSubKey,
  5118. IN PCWSTR pszValueName,
  5119. IN WORD wValueType,
  5120. IN PCWSTR pszValueNewName,
  5121. IN BOOL fDefaultProvided,
  5122. va_list arglist)
  5123. {
  5124. CORegKey rk(hKey, pszSubKey);
  5125. BOOL fKeyNotFound = (((HKEY) rk) == NULL);
  5126. if (fKeyNotFound && !fDefaultProvided)
  5127. {
  5128. return FALSE;
  5129. }
  5130. else
  5131. {
  5132. //even if key is not found, we need to write the default value
  5133. return WriteRegValueToAFile(pwisSection, rk, pszValueName, wValueType,
  5134. pszValueNewName, fDefaultProvided, arglist);
  5135. }
  5136. }
  5137. // ----------------------------------------------------------------------
  5138. //
  5139. // Function: WriteServiceRegValueToAFile
  5140. //
  5141. // Purpose: Write specified value in registry to the specified section
  5142. // in the answerfile, renaming if required
  5143. //
  5144. // Arguments:
  5145. // pwisSection [in] section to which the value is written
  5146. // rk [in] regkey
  5147. // pszValueName [in] name of value
  5148. // wValueType [in] type of value
  5149. // pszValueNewName [in] change name to this
  5150. // fDefaultProvided [in] is a default value provided ?
  5151. // ... [in] use this default value if the specified value is
  5152. // not found in the registry
  5153. //
  5154. // Returns: TRUE on success, FALSE otherwise
  5155. //
  5156. // Author: kumarp 17-December-97
  5157. //
  5158. BOOL
  5159. WriteRegValueToAFile(
  5160. IN PCWInfSection pwisSection,
  5161. IN CORegKey& rk,
  5162. IN PCWSTR pszValueName,
  5163. IN WORD wValueType,
  5164. IN PCWSTR pszValueNewName,
  5165. IN BOOL fDefaultProvided,
  5166. ...)
  5167. {
  5168. BOOL fStatus;
  5169. va_list arglist;
  5170. va_start (arglist, fDefaultProvided);
  5171. fStatus = WriteRegValueToAFile(pwisSection, rk,
  5172. pszValueName, wValueType,
  5173. pszValueNewName, fDefaultProvided, arglist);
  5174. va_end(arglist);
  5175. return fStatus;
  5176. }
  5177. // ----------------------------------------------------------------------
  5178. //
  5179. // Function: WriteServiceRegValueToAFile
  5180. //
  5181. // Purpose: Write specified value in registry to the specified section
  5182. // in the answerfile, renaming if required
  5183. //
  5184. // Arguments:
  5185. // pwisSection [in] section to which the value is written
  5186. // rk [in] regkey
  5187. // pszValueName [in] name of value
  5188. // wValueType [in] type of value
  5189. // pszValueNewName [in] change name to this
  5190. // fDefaultProvided [in] is a default value provided ?
  5191. // arglist [in] use this default value if the specified value is
  5192. // not found in the registry
  5193. //
  5194. // Returns: TRUE on success, FALSE otherwise
  5195. //
  5196. // Author: kumarp 17-December-97
  5197. //
  5198. BOOL
  5199. WriteRegValueToAFile(
  5200. IN PCWInfSection pwisSection,
  5201. IN CORegKey& rk,
  5202. IN PCWSTR pszValueName,
  5203. IN WORD wValueType,
  5204. IN PCWSTR pszValueNewName,
  5205. IN BOOL fDefaultProvided,
  5206. IN va_list arglist)
  5207. {
  5208. if (!pwisSection)
  5209. {
  5210. return FALSE;
  5211. }
  5212. BOOL fValue, fDefault=FALSE;
  5213. DWORD dwValue, dwDefault=0;
  5214. PCWSTR pszValue, pszDefault=NULL;
  5215. TStringList slValue;
  5216. tstring strValue;
  5217. if (pszValueNewName == NULL)
  5218. {
  5219. pszValueNewName = pszValueName;
  5220. }
  5221. if (fDefaultProvided)
  5222. {
  5223. switch (wValueType)
  5224. {
  5225. default:
  5226. AssertSz(FALSE, "WriteRegValueToAFile: Invalid wValueType");
  5227. break;
  5228. case REG_SZ:
  5229. pszDefault = va_arg(arglist, PCWSTR);
  5230. break;
  5231. case REG_HEX:
  5232. case REG_DWORD:
  5233. dwDefault = va_arg(arglist, DWORD);
  5234. break;
  5235. case REG_BOOL:
  5236. fDefault = va_arg(arglist, BOOL);
  5237. break;
  5238. }
  5239. }
  5240. LONG err;
  5241. BOOL fStatus=FALSE;
  5242. switch(wValueType)
  5243. {
  5244. default:
  5245. AssertSz(FALSE, "WriteRegValueToAFile: Invalid wValueType");
  5246. break;
  5247. case REG_SZ:
  5248. err = rk.QueryValue(pszValueName, strValue);
  5249. if (err)
  5250. {
  5251. if (fDefaultProvided)
  5252. {
  5253. pszValue = pszDefault;
  5254. }
  5255. else
  5256. {
  5257. return FALSE;
  5258. }
  5259. }
  5260. else
  5261. {
  5262. pszValue = strValue.c_str();
  5263. }
  5264. pwisSection->AddKey(pszValueNewName, pszValue);
  5265. fStatus = TRUE;
  5266. break;
  5267. case REG_HEX:
  5268. case REG_DWORD:
  5269. err = rk.QueryValue(pszValueName, dwValue);
  5270. if (err)
  5271. {
  5272. if (fDefaultProvided)
  5273. {
  5274. dwValue = dwDefault;
  5275. }
  5276. else
  5277. {
  5278. return FALSE;
  5279. }
  5280. }
  5281. if (wValueType == REG_HEX)
  5282. {
  5283. pwisSection->AddHexKey(pszValueNewName, dwValue);
  5284. }
  5285. else
  5286. {
  5287. pwisSection->AddKey(pszValueNewName, dwValue);
  5288. }
  5289. fStatus = TRUE;
  5290. break;
  5291. case REG_BOOL:
  5292. err = rk.QueryValue(pszValueName, dwValue);
  5293. if (err)
  5294. {
  5295. if (fDefaultProvided)
  5296. {
  5297. dwValue = fDefault;
  5298. }
  5299. else
  5300. {
  5301. return FALSE;
  5302. }
  5303. }
  5304. fValue = dwValue != 0;
  5305. pwisSection->AddBoolKey(pszValueNewName, fValue);
  5306. fStatus = TRUE;
  5307. break;
  5308. case REG_MULTI_SZ:
  5309. err = rk.QueryValue(pszValueName, slValue);
  5310. if (err)
  5311. {
  5312. // cant specify default for REG_MULTI_SZ, just return FALSE
  5313. return FALSE;
  5314. }
  5315. pwisSection->AddKey(pszValueNewName, slValue);
  5316. EraseAndDeleteAll(slValue);
  5317. fStatus = TRUE;
  5318. break;
  5319. case REG_BINARY:
  5320. {
  5321. TByteArray ab;
  5322. err = rk.QueryValue(pszValueName, ab);
  5323. if (err)
  5324. {
  5325. // cant specify default for REG_BINARY, just return FALSE
  5326. return FALSE;
  5327. }
  5328. ConvertToByteList(ab, strValue);
  5329. pszValue = strValue.c_str();
  5330. pwisSection->AddKey(pszValueNewName, pszValue);
  5331. break;
  5332. }
  5333. }
  5334. return fStatus;
  5335. }
  5336. // ----------------------------------------------------------------------
  5337. //
  5338. // Function: GetBusTypeName
  5339. //
  5340. // Purpose: Get name string for the specify bus-type
  5341. //
  5342. // Arguments:
  5343. // eBusType [in] bus type
  5344. //
  5345. // Returns: name string for the bus-type
  5346. //
  5347. // Author: kumarp 17-December-97
  5348. //
  5349. PCWSTR
  5350. GetBusTypeName (
  5351. IN INTERFACE_TYPE eBusType)
  5352. {
  5353. switch (eBusType)
  5354. {
  5355. case Internal:
  5356. return c_szAfBusInternal;
  5357. case Isa:
  5358. return c_szAfBusIsa;
  5359. case Eisa:
  5360. return c_szAfBusEisa;
  5361. case MicroChannel:
  5362. return c_szAfBusMicrochannel;
  5363. case TurboChannel:
  5364. return c_szAfBusTurbochannel;
  5365. case PCIBus:
  5366. return c_szAfBusPci;
  5367. case VMEBus:
  5368. return c_szAfBusVme;
  5369. case NuBus:
  5370. return c_szAfBusNu;
  5371. case PCMCIABus:
  5372. return c_szAfBusPcmcia;
  5373. case CBus:
  5374. return c_szAfBusC;
  5375. case MPIBus:
  5376. return c_szAfBusMpi;
  5377. case MPSABus:
  5378. return c_szAfBusMpsa;
  5379. case ProcessorInternal:
  5380. return c_szAfBusProcessorinternal;
  5381. case InternalPowerBus:
  5382. return c_szAfBusInternalpower;
  5383. case PNPISABus:
  5384. return c_szAfBusPnpisa;
  5385. default:
  5386. return c_szAfUnknown;
  5387. }
  5388. };
  5389. // ----------------------------------------------------------------------
  5390. //
  5391. // Function: AddToNetCardDB
  5392. //
  5393. // Purpose: Add the given adapter token to a list. This list is later
  5394. // used to map token <--> drivername
  5395. //
  5396. // Arguments:
  5397. // pszAdapterName [in] adapter token (e.g. Adapter01)
  5398. // pszProductName [in] adapter ID (e.g. IEEPRO)
  5399. // pszAdapterDriver [in] instance ID (e.g. IEEPRO3)
  5400. //
  5401. // Returns: None
  5402. //
  5403. // Author: kumarp 17-December-97
  5404. //
  5405. void
  5406. AddToNetCardDB (
  5407. IN PCWSTR pszAdapterName,
  5408. IN PCWSTR pszProductName,
  5409. IN PCWSTR pszAdapterDriver)
  5410. {
  5411. Assert(pszAdapterName && *pszAdapterName);
  5412. Assert(pszProductName && *pszProductName);
  5413. Assert(pszAdapterDriver && *pszAdapterDriver);
  5414. AddAtEndOfStringList(*g_pslNetCardAFileName, pszAdapterName);
  5415. AddAtEndOfStringList(*g_pslNetCard, pszProductName);
  5416. AddAtEndOfStringList(*g_pslNetCardInstance, pszAdapterDriver);
  5417. }
  5418. // ----------------------------------------------------------------------
  5419. //
  5420. // Function: IsNetCardProductName
  5421. //
  5422. // Purpose: Determine if the specified name represents an adapter
  5423. //
  5424. // Arguments:
  5425. // pszName [in] name of a component
  5426. //
  5427. // Returns: TRUE on success, FALSE otherwise
  5428. //
  5429. // Author: kumarp 17-December-97
  5430. //
  5431. BOOL
  5432. IsNetCardProductName (
  5433. IN PCWSTR pszName)
  5434. {
  5435. AssertValidReadPtr(pszName);
  5436. return FIsInStringList(*g_pslNetCard, pszName);
  5437. }
  5438. // ----------------------------------------------------------------------
  5439. //
  5440. // Function: IsNetCardInstance
  5441. //
  5442. // Purpose: Determine if the specified instance represents an adapter
  5443. //
  5444. // Arguments:
  5445. // pszName [in] instance name of a component
  5446. //
  5447. // Returns: TRUE on success, FALSE otherwise
  5448. //
  5449. // Author: kumarp 17-December-97
  5450. //
  5451. BOOL
  5452. IsNetCardInstance(
  5453. IN PCWSTR pszName)
  5454. {
  5455. AssertValidReadPtr(pszName);
  5456. return FIsInStringList(*g_pslNetCardInstance, pszName);
  5457. }
  5458. // ----------------------------------------------------------------------
  5459. //
  5460. // Function: MapNetCardInstanceToAFileName
  5461. //
  5462. // Purpose: Map netcard instance name to its answerfile token
  5463. //
  5464. // Arguments:
  5465. // pszNetCardInstance [in] net card instance
  5466. // strNetCardAFileName [out] answerfile token for that net card
  5467. //
  5468. // Returns: None
  5469. //
  5470. // Author: kumarp 17-December-97
  5471. //
  5472. VOID
  5473. MapNetCardInstanceToAFileName (
  5474. IN PCWSTR pszNetCardInstance,
  5475. OUT tstring& strNetCardAFileName)
  5476. {
  5477. strNetCardAFileName = MapNetCardInstanceToAFileName(pszNetCardInstance);
  5478. }
  5479. // ----------------------------------------------------------------------
  5480. //
  5481. // Function: MapNetCardInstanceToAFileName
  5482. //
  5483. // Purpose: Map netcard instance name to its answerfile token
  5484. //
  5485. // Arguments:
  5486. // pszNetCardInstance [in] net card instance
  5487. //
  5488. // Returns: answerfile token for that net card
  5489. //
  5490. // Author: kumarp 17-December-97
  5491. //
  5492. PCWSTR
  5493. MapNetCardInstanceToAFileName (
  5494. IN PCWSTR pszNetCardInstance)
  5495. {
  5496. DefineFunctionName("MapNetCardInstanceToAFileName");
  5497. Assert(pszNetCardInstance && *pszNetCardInstance);
  5498. tstring strTemp;
  5499. TStringListIter iter = g_pslNetCardInstance->begin();
  5500. TStringListIter pos2;
  5501. DWORD index=0;
  5502. PCWSTR pszNetCardAFileName=NULL;
  5503. while (iter != g_pslNetCardInstance->end())
  5504. {
  5505. strTemp = **iter++;
  5506. if (0 == _wcsicmp(strTemp.c_str(), pszNetCardInstance))
  5507. {
  5508. pszNetCardAFileName = GetNthItem(*g_pslNetCardAFileName, index)->c_str();
  5509. break;
  5510. }
  5511. index++;
  5512. }
  5513. if (!pszNetCardAFileName)
  5514. {
  5515. TraceTag(ttidError, "%s: Couldnt locate %S in g_pslNetCardAFileName",
  5516. __FUNCNAME__, pszNetCardInstance);
  5517. }
  5518. return pszNetCardAFileName;
  5519. }
  5520. // ----------------------------------------------------------------------
  5521. //
  5522. // Function: GetServiceKey
  5523. //
  5524. // Purpose: Get regkey object for the specified service
  5525. //
  5526. // Arguments:
  5527. // pszServiceName [in] name of service
  5528. // prkService [out] pointer to CORegKey object
  5529. //
  5530. // Returns: TRUE on success, FALSE otherwise
  5531. //
  5532. // Author: kumarp 17-December-97
  5533. //
  5534. BOOL
  5535. GetServiceKey (
  5536. IN PCWSTR pszServiceName,
  5537. OUT PCORegKey &prkService)
  5538. {
  5539. DefineFunctionName("GetServiceKey");
  5540. tstring strServiceFullName = tstring(c_szRegKeyServices) + L"\\" +
  5541. pszServiceName;
  5542. prkService = new CORegKey(HKEY_LOCAL_MACHINE, strServiceFullName.c_str());
  5543. if(!prkService)
  5544. {
  5545. return false;
  5546. }
  5547. if (!prkService->HKey())
  5548. {
  5549. delete prkService;
  5550. prkService = NULL;
  5551. TraceHr (ttidError, FAL,
  5552. HRESULT_FROM_WIN32(ERROR_SERVICE_DOES_NOT_EXIST), FALSE,
  5553. "GetServiceKey for service %S", pszServiceName);
  5554. return FALSE;
  5555. }
  5556. return TRUE;
  5557. }
  5558. // ----------------------------------------------------------------------
  5559. //
  5560. // Function: GetServiceParamsKey
  5561. //
  5562. // Purpose: Get regkey object for the Parameters subkey of the specified service
  5563. //
  5564. // Arguments:
  5565. // pszServiceName [in] name of a service
  5566. // prkServiceParams [out] pointer to CORegKey object
  5567. //
  5568. // Returns: TRUE on success, FALSE otherwise
  5569. //
  5570. // Author: kumarp 17-December-97
  5571. //
  5572. BOOL
  5573. GetServiceParamsKey (
  5574. IN PCWSTR pszServiceName,
  5575. OUT PCORegKey &prkServiceParams)
  5576. {
  5577. return GetServiceSubkey(pszServiceName, c_szParameters, prkServiceParams);
  5578. }
  5579. // ----------------------------------------------------------------------
  5580. //
  5581. // Function: GetServiceSubkey
  5582. //
  5583. // Purpose: Get subkey of a service
  5584. //
  5585. // Arguments:
  5586. // pszServiceName [in] name of service
  5587. // pszSubKeyName [in] name of subkey
  5588. // prkServiceSubkey [out] pointer to CORegKey object
  5589. //
  5590. // Returns: TRUE on success, FALSE otherwise
  5591. //
  5592. // Author: kumarp 17-December-97
  5593. //
  5594. BOOL
  5595. GetServiceSubkey (
  5596. IN PCWSTR pszServiceName,
  5597. IN PCWSTR pszSubKeyName,
  5598. OUT PCORegKey &prkServiceSubkey)
  5599. {
  5600. DefineFunctionName("GetServiceSubkey(PCWSTR pszServiceName, )");
  5601. tstring strServiceSubkeyFullName = tstring(c_szRegKeyServices) + L"\\" +
  5602. pszServiceName + L"\\" + pszSubKeyName;
  5603. prkServiceSubkey = new CORegKey(HKEY_LOCAL_MACHINE, strServiceSubkeyFullName.c_str());
  5604. if(!prkServiceSubkey)
  5605. {
  5606. return false;
  5607. }
  5608. if (!prkServiceSubkey->HKey())
  5609. {
  5610. delete prkServiceSubkey;
  5611. prkServiceSubkey = NULL;
  5612. TraceTag(ttidError, "%s: error opening service sub key for %S -- %S",
  5613. __FUNCNAME__, pszServiceName, pszServiceName);
  5614. return FALSE;
  5615. }
  5616. return TRUE;
  5617. }
  5618. // ----------------------------------------------------------------------
  5619. //
  5620. // Function: GetServiceSubkey
  5621. //
  5622. // Purpose: Get subkey of a service
  5623. //
  5624. // Arguments:
  5625. // prkService [in] service regkey
  5626. // pszSubKeyName [in] name of subkey
  5627. // prkServiceSubkey [out] pointer to CORegKey object
  5628. //
  5629. // Returns: TRUE on success, FALSE otherwise
  5630. //
  5631. // Author: kumarp 17-December-97
  5632. //
  5633. BOOL
  5634. GetServiceSubkey (
  5635. IN const PCORegKey prkService,
  5636. IN PCWSTR pszSubKeyName,
  5637. OUT PCORegKey &prkServiceSubkey)
  5638. {
  5639. DefineFunctionName("GetServiceSubkey(PCORegKey prkService, )");
  5640. prkServiceSubkey = new CORegKey(*prkService, pszSubKeyName);
  5641. if(!prkServiceSubkey)
  5642. {
  5643. return false;
  5644. }
  5645. if (!prkServiceSubkey->HKey())
  5646. {
  5647. delete prkServiceSubkey;
  5648. prkServiceSubkey = NULL;
  5649. TraceWin32FunctionError(ERROR_SERVICE_DOES_NOT_EXIST);
  5650. return FALSE;
  5651. }
  5652. return TRUE;
  5653. }
  5654. #pragma BEGIN_CONST_SECTION
  5655. static const PCWSTR c_aszComponentsToIgnore[] =
  5656. {
  5657. // These are installed automatically when TCPIP is installed
  5658. // and has no user settable parameters of its own
  5659. //
  5660. L"NetBT",
  5661. L"TcpipCU",
  5662. L"Wins",
  5663. // This is installed automatically when RAS is installed
  5664. // and has no user settable parameters of its own
  5665. //
  5666. L"NdisWan",
  5667. // Parameters of RAS are under Software\Microsoft\RAS
  5668. // and not under the service key as with other net components
  5669. //
  5670. L"RASPPTPE",
  5671. L"RASPPTPM",
  5672. L"RasAuto",
  5673. L"RemoteAccess",
  5674. L"Router",
  5675. // These are installed automatically when MS_IPX is installed
  5676. // and has no user settable parameters of its own
  5677. //
  5678. L"NwlnkNb",
  5679. L"NwlnkSpx",
  5680. // This is installed automatically when MS_MSClient is installed
  5681. // and has no user settable parameters of its own
  5682. //
  5683. L"RpcBanyan",
  5684. // we dont install this using answer-file
  5685. //
  5686. L"Inetsrv",
  5687. L"DFS",
  5688. // this will be cleaned up by the IIS setup guys.
  5689. // contact "Linan Tong" if you have any questions:
  5690. //
  5691. L"FTPD",
  5692. // these are installed when SFM is installed
  5693. //
  5694. L"MacPrint",
  5695. L"MacFile",
  5696. // pre-sp3 SteelHead components
  5697. //
  5698. L"NwSapAgent",
  5699. L"IPRIP",
  5700. L"NWLNKRIP",
  5701. L"RelayAgent",
  5702. };
  5703. #pragma END_CONST_SECTION
  5704. // ----------------------------------------------------------------------
  5705. //
  5706. // Function: ShouldIgnoreComponent
  5707. //
  5708. // Purpose: Determine if a components should be ignored when
  5709. // writing parameters to answerfile
  5710. //
  5711. // Arguments:
  5712. // pszComponentName [in] name of component
  5713. //
  5714. // Returns: TRUE on success, FALSE otherwise
  5715. //
  5716. // Author: kumarp 17-December-97
  5717. //
  5718. BOOL
  5719. ShouldIgnoreComponent (
  5720. IN PCWSTR pszComponentName)
  5721. {
  5722. BOOL fRet=TRUE;
  5723. DefineFunctionName("ShouldIgnoreComponent");
  5724. TraceFunctionEntry(ttidNetUpgrade);
  5725. TraceTag(ttidNetUpgrade, "%s: Checking if %S should be ignored.",
  5726. __FUNCNAME__, pszComponentName);
  5727. fRet = !FIsInStringArray(c_aszComponentsToIgnore,
  5728. celems(c_aszComponentsToIgnore),
  5729. pszComponentName) &&
  5730. (!FIsOptionalComponent(pszComponentName) ||
  5731. // even though DHCPServer is an optional component,
  5732. // we need to treat it differently and thus must write its
  5733. // parameters
  5734. !lstrcmpiW(pszComponentName, c_szSvcDhcpServer));
  5735. // If none of the above net components then, check if it is DLC.
  5736. if ( fRet == TRUE )
  5737. {
  5738. if ( lstrcmpiW(pszComponentName, sz_DLC) == 0 )
  5739. {
  5740. return ShouldRemoveDLC( NULL, NULL );
  5741. }
  5742. }
  5743. return !fRet;
  5744. }
  5745. // ----------------------------------------------------------------------
  5746. //
  5747. // Function: StringListsIntersect
  5748. //
  5749. // Purpose: Determine if at least one item of sl1 matches with
  5750. // at least one item of sl2
  5751. //
  5752. // Arguments:
  5753. // sl1 [in] list 1
  5754. // sl2 [in] list 2
  5755. //
  5756. // Returns: TRUE on success, FALSE otherwise
  5757. //
  5758. // Author: kumarp 17-December-97
  5759. //
  5760. BOOL
  5761. StringListsIntersect (
  5762. IN const TStringList& sl1,
  5763. IN const TStringList& sl2)
  5764. {
  5765. if ((sl1.size() == 0) || (sl2.size() == 0))
  5766. return FALSE;
  5767. tstring s1, s2;
  5768. TStringListIter pos1, pos2;
  5769. pos1 = sl1.begin();
  5770. while (pos1 != sl1.end())
  5771. {
  5772. s1 = **pos1++;
  5773. pos2 = sl2.begin();
  5774. while (pos2 != sl2.end())
  5775. {
  5776. s2 = **pos2++;
  5777. if (s1 == s2)
  5778. {
  5779. return TRUE;
  5780. }
  5781. }
  5782. }
  5783. return FALSE;
  5784. }
  5785. // ----------------------------------------------------------------------
  5786. //
  5787. // Function: ConvertToQWord
  5788. //
  5789. // Purpose: Convert a size 8 byte array to a qword
  5790. //
  5791. // Arguments:
  5792. // ab [in] byte array
  5793. //
  5794. // Returns:
  5795. //
  5796. // Author: kumarp 17-December-97
  5797. //
  5798. QWORD
  5799. ConvertToQWord (
  5800. IN TByteArray ab)
  5801. {
  5802. Assert(ab.size() == 8);
  5803. QWORD qwRet = 0;
  5804. WORD wShiftBy=0;
  5805. for (int i=0; i<8; i++)
  5806. {
  5807. qwRet |= ((QWORD) ab[i]) << wShiftBy;
  5808. wShiftBy += 8;
  5809. }
  5810. return qwRet;
  5811. }
  5812. // ----------------------------------------------------------------------
  5813. //
  5814. // Function: ConvertToByteList
  5815. //
  5816. // Purpose: Convert TByteArray to comma-separated byte list
  5817. //
  5818. // Arguments:
  5819. // ab [in] byte array
  5820. //
  5821. // Returns:
  5822. //
  5823. // Author: kyrilf 2-April-99
  5824. //
  5825. VOID
  5826. ConvertToByteList (
  5827. IN TByteArray ab,
  5828. OUT tstring& str)
  5829. {
  5830. WCHAR byte [3];
  5831. DWORD size = ab.size();
  5832. for (DWORD i=0; i < size; i++)
  5833. {
  5834. swprintf(byte, L"%0.2X", ab[i]);
  5835. str += byte;
  5836. if (i == size - 1)
  5837. break;
  5838. else
  5839. str += ',';
  5840. }
  5841. }
  5842. // ----------------------------------------------------------------------
  5843. //
  5844. // Function: ReplaceCharsInString
  5845. //
  5846. // Purpose: Replace all occurrances of chFindChar in the specified string
  5847. // by chReplaceWith charater
  5848. //
  5849. // Arguments:
  5850. // pszString [in] string
  5851. // pszFindChars [in] set of chars to find
  5852. // chReplaceWith [in] char to replace with
  5853. //
  5854. // Returns: None
  5855. //
  5856. // Author: kumarp 17-December-97
  5857. //
  5858. void
  5859. ReplaceCharsInString (
  5860. IN OUT PWSTR pszString,
  5861. IN PCWSTR pszFindChars,
  5862. IN WCHAR chReplaceWith)
  5863. {
  5864. UINT uLen = wcslen(pszString);
  5865. UINT uPos;
  5866. while ((uPos = wcscspn(pszString, pszFindChars)) < uLen)
  5867. {
  5868. pszString[uPos] = chReplaceWith;
  5869. pszString += uPos + 1;
  5870. uLen -= uPos + 1;
  5871. }
  5872. }
  5873. // ----------------------------------------------------------------------
  5874. //
  5875. // Function: HrNetRegSaveKey
  5876. //
  5877. // Purpose: Save the entire specified registry tree to a file
  5878. //
  5879. // Arguments:
  5880. // hkeyBase [in] handle of base key
  5881. // pszSubKey [in] name of subkey
  5882. // pszComponent [in] file name prefix to use
  5883. // pstrFileName [out] name of file written
  5884. //
  5885. // Returns: S_OK on success, otherwise an error code
  5886. //
  5887. // Author: kumarp 17-December-97
  5888. //
  5889. HRESULT
  5890. HrNetRegSaveKey (
  5891. IN HKEY hkeyBase,
  5892. IN PCWSTR pszSubKey,
  5893. IN PCWSTR pszComponent,
  5894. OUT tstring* pstrFileName)
  5895. {
  5896. DefineFunctionName("HrNetRegSaveKey");
  5897. Assert(hkeyBase);
  5898. AssertValidReadPtr(pszComponent);
  5899. AssertValidWritePtr(pstrFileName);
  5900. HRESULT hr;
  5901. HKEY hkey;
  5902. hr = HrRegOpenKeyEx(hkeyBase, pszSubKey, KEY_READ, &hkey);
  5903. if (S_OK == hr)
  5904. {
  5905. tstring strFileName;
  5906. strFileName = pszComponent;
  5907. if (pszSubKey)
  5908. {
  5909. AssertValidReadPtr(pszSubKey);
  5910. strFileName += L"-";
  5911. strFileName += pszSubKey;
  5912. ReplaceCharsInString((PWSTR) strFileName.c_str(), L"\\/", '-');
  5913. }
  5914. strFileName += L".reg";
  5915. tstring strFullPath;
  5916. hr = HrGetNetUpgradeTempDir(&strFullPath);
  5917. if (S_OK == hr)
  5918. {
  5919. strFullPath += strFileName;
  5920. TraceTag(ttidNetUpgrade, "%s: dumping key %S to file %S",
  5921. __FUNCNAME__, pszSubKey ? pszSubKey : L"", strFullPath.c_str());
  5922. DeleteFile(strFullPath.c_str());
  5923. extern LONG EnableAllPrivileges ( VOID );
  5924. EnableAllPrivileges();
  5925. DWORD err = ::RegSaveKey(hkey, strFullPath.c_str(), NULL);
  5926. if (err == ERROR_SUCCESS)
  5927. {
  5928. *pstrFileName = strFullPath;
  5929. hr = S_OK;
  5930. }
  5931. else
  5932. {
  5933. hr = HrFromLastWin32Error();
  5934. }
  5935. }
  5936. RegCloseKey(hkey);
  5937. }
  5938. TraceErrorOptional(__FUNCNAME__, hr,
  5939. (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)));
  5940. return hr;
  5941. }
  5942. // ----------------------------------------------------------------------
  5943. //
  5944. // Function: HrNetRegSaveKeyAndAddToSection
  5945. //
  5946. // Purpose: Save the entire specified registry tree to a file and
  5947. // add a key in the specified section to indicate where
  5948. // this file is located
  5949. //
  5950. // Arguments:
  5951. // hkeyBase [in] handle of base key
  5952. // pszSubKey [in] name of subkey
  5953. // pszComponent [in] file name prefix to use
  5954. // pszKeyName [in] name of key to write
  5955. // pwisSection [in] section to write to
  5956. //
  5957. // Returns: S_OK on success, otherwise an error code
  5958. //
  5959. // Author: kumarp 17-December-97
  5960. //
  5961. HRESULT
  5962. HrNetRegSaveKeyAndAddToSection (
  5963. IN HKEY hkeyBase,
  5964. IN PCWSTR pszSubKey,
  5965. IN PCWSTR pszComponent,
  5966. IN PCWSTR pszKeyName,
  5967. IN CWInfSection* pwisSection)
  5968. {
  5969. DefineFunctionName("HrNetRegSaveKeyAndAddToSection");
  5970. Assert(hkeyBase);
  5971. AssertValidReadPtr(pszComponent);
  5972. AssertValidReadPtr(pszKeyName);
  5973. AssertValidReadPtr(pwisSection);
  5974. HRESULT hr;
  5975. tstring strFileName;
  5976. hr = HrNetRegSaveKey(hkeyBase, pszSubKey, pszComponent, &strFileName);
  5977. if (SUCCEEDED(hr))
  5978. {
  5979. pwisSection->AddKey(pszKeyName, strFileName.c_str());
  5980. }
  5981. if (S_OK != hr)
  5982. {
  5983. TraceTag(ttidNetUpgrade, "%s: failed for %S in [%S] -- %S: hr: 0x%08X",
  5984. __FUNCNAME__, pszKeyName, pwisSection->Name(), pszSubKey, hr);
  5985. }
  5986. return hr;
  5987. }
  5988. // ----------------------------------------------------------------------
  5989. //
  5990. // Function: HrNetRegSaveKeyAndAddToSection
  5991. //
  5992. // Purpose: Save the entire specified registry tree to a file and
  5993. // add a key in the specified section to indicate where
  5994. // this file is located
  5995. //
  5996. // Arguments:
  5997. // pszServiceName [in] name of service
  5998. // pszSubKey [in] name of subkey
  5999. // pszKeyName [in] name of key to write
  6000. // pwisSection [in] section to write to
  6001. //
  6002. // Returns: S_OK on success, otherwise an error code
  6003. //
  6004. // Author: kumarp 17-December-97
  6005. //
  6006. HRESULT
  6007. HrNetRegSaveServiceSubKeyAndAddToSection (
  6008. IN PCWSTR pszServiceName,
  6009. IN PCWSTR pszServiceSubKeyName,
  6010. IN PCWSTR pszKeyName,
  6011. IN CWInfSection* pwisSection)
  6012. {
  6013. AssertValidReadPtr(pszServiceName);
  6014. AssertValidReadPtr(pszKeyName);
  6015. AssertValidWritePtr(pwisSection);
  6016. HRESULT hr;
  6017. tstring strServiceSubKey = c_szRegKeyServices;
  6018. strServiceSubKey += L"\\";
  6019. strServiceSubKey += pszServiceName;
  6020. if (pszServiceSubKeyName)
  6021. {
  6022. strServiceSubKey += L"\\";
  6023. strServiceSubKey += pszServiceSubKeyName;
  6024. }
  6025. // we ignore the return code
  6026. hr = HrNetRegSaveKeyAndAddToSection(HKEY_LOCAL_MACHINE,
  6027. strServiceSubKey.c_str(),
  6028. pszServiceName,
  6029. pszKeyName, pwisSection);
  6030. return hr;
  6031. }
  6032. // ----------------------------------------------------------------------
  6033. //
  6034. // Function: HrProcessOemComponentAndUpdateAfSection
  6035. //
  6036. // Purpose: Process the specified OEM component in the following steps:
  6037. // - Load an OEM DLL
  6038. // - call PreUpgradeInitialize once
  6039. // - call DoPreUpgradeProcessing
  6040. // - if the above steps are successful,
  6041. // add the right sections in the answerfile
  6042. //
  6043. // Arguments:
  6044. // pnmi [in] pointer to CNetMapInfo object
  6045. // hParentWindow [in] handle of parent window
  6046. // hkeyParams [in] handle of Parameters registry key
  6047. // pszPreNT5InfId [in] pre-NT5 InfID of a component (e.g. IEEPRO)
  6048. // pszPreNT5Instance [in] pre-NT5 instance of a component (e.g. IEEPRO2)
  6049. // pszNT5InfId [in] NT5 InfID of the component
  6050. // pszDescription [in] description of the component
  6051. // pwisParams [in] pointer to params section of this component
  6052. //
  6053. // Returns: S_OK on success, otherwise an error code
  6054. //
  6055. // Author: kumarp 13-May-98
  6056. //
  6057. HRESULT HrProcessOemComponentAndUpdateAfSection(
  6058. IN CNetMapInfo* pnmi,
  6059. IN HWND hParentWindow,
  6060. IN HKEY hkeyParams,
  6061. IN PCWSTR pszPreNT5InfId,
  6062. IN PCWSTR pszPreNT5Instance,
  6063. IN PCWSTR pszNT5InfId,
  6064. IN PCWSTR pszDescription,
  6065. IN CWInfSection* pwisParams)
  6066. {
  6067. AssertValidReadPtr(pnmi);
  6068. //Assert(hParentWindow);
  6069. Assert(hkeyParams);
  6070. AssertValidReadPtr(pszPreNT5InfId);
  6071. AssertValidReadPtr(pszPreNT5Instance);
  6072. AssertValidReadPtr(pszNT5InfId);
  6073. AssertValidReadPtr(pszDescription);
  6074. AssertValidReadPtr(pwisParams);
  6075. DefineFunctionName("HrProcessOemComponentAndUpdateAfSection");
  6076. HRESULT hr;
  6077. tstring strOemSectionName;
  6078. DWORD dwFlags = 0;
  6079. PCWSTR pszOemSection;
  6080. TraceTag(ttidNetUpgrade, "%s: Component %S (%S) is an OEM component",
  6081. __FUNCNAME__, pszDescription, pszPreNT5Instance);
  6082. strOemSectionName = pwisParams->Name();
  6083. strOemSectionName += L".";
  6084. strOemSectionName += c_szAfOemSection;
  6085. pszOemSection = strOemSectionName.c_str();
  6086. hr = HrProcessOemComponent(pnmi, &g_NetUpgradeInfo,
  6087. hParentWindow,
  6088. hkeyParams,
  6089. pszPreNT5InfId,
  6090. pszPreNT5Instance,
  6091. pszNT5InfId,
  6092. pszDescription,
  6093. pszOemSection,
  6094. &dwFlags);
  6095. if (S_OK == hr)
  6096. {
  6097. tstring strOemInf;
  6098. pwisParams->AddKey(c_szAfOemSection, pszOemSection);
  6099. AssertSz(!pnmi->m_strOemDir.empty(), "Did not get OemDir!!");
  6100. pwisParams->AddKey(c_szAfOemDir, pnmi->m_strOemDir.c_str());
  6101. hr = pnmi->HrGetOemInfName(pszNT5InfId, &strOemInf);
  6102. if (S_OK == hr)
  6103. {
  6104. pwisParams->AddKey(c_szAfOemInf, strOemInf.c_str());
  6105. }
  6106. if (dwFlags & NUA_LOAD_POST_UPGRADE)
  6107. {
  6108. pwisParams->AddKey(c_szAfOemDllToLoad,
  6109. pnmi->m_strOemDllName.c_str());
  6110. }
  6111. // currently the SkipInstall feature is used only by
  6112. // SNA and MS_NetBios for their peculiar upgrade requirements.
  6113. // This may or may not become a documented feature.
  6114. //
  6115. if (dwFlags & NUA_SKIP_INSTALL_IN_GUI_MODE)
  6116. {
  6117. pwisParams->AddBoolKey(c_szAfSkipInstall, TRUE);
  6118. }
  6119. }
  6120. TraceError(__FUNCNAME__, hr);
  6121. return hr;
  6122. }
  6123. /*******************************************************************
  6124. NAME: EnableAllPrivileges
  6125. SYNOPSIS: Enxable all privileges on the current process token. This
  6126. is used just prior to attempting to shut down the system.
  6127. ENTRY: Nothing
  6128. EXIT: Nothing
  6129. RETURNS: LONG error code
  6130. NOTES:
  6131. HISTORY:
  6132. ********************************************************************/
  6133. LONG EnableAllPrivileges ( VOID )
  6134. {
  6135. HANDLE Token = NULL ;
  6136. ULONG ReturnLength = 4096,
  6137. Index ;
  6138. PTOKEN_PRIVILEGES NewState = NULL ;
  6139. BOOL Result = FALSE ;
  6140. LONG Error = 0 ;
  6141. do
  6142. {
  6143. Result = OpenProcessToken( GetCurrentProcess(),
  6144. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  6145. & Token ) ;
  6146. if (! Result)
  6147. {
  6148. Error = GetLastError() ;
  6149. break;
  6150. }
  6151. Result = (NewState = (PTOKEN_PRIVILEGES) MemAlloc( ReturnLength )) != NULL ;
  6152. if (! Result)
  6153. {
  6154. Error = ERROR_NOT_ENOUGH_MEMORY ;
  6155. break;
  6156. }
  6157. Result = GetTokenInformation( Token, // TokenHandle
  6158. TokenPrivileges, // TokenInformationClass
  6159. NewState, // TokenInformation
  6160. ReturnLength, // TokenInformationLength
  6161. &ReturnLength // ReturnLength
  6162. );
  6163. if (! Result)
  6164. {
  6165. Error = GetLastError() ;
  6166. break;
  6167. }
  6168. //
  6169. // Set the state settings so that all privileges are enabled...
  6170. //
  6171. if ( NewState->PrivilegeCount > 0 )
  6172. {
  6173. for (Index = 0; Index < NewState->PrivilegeCount; Index++ )
  6174. {
  6175. NewState->Privileges[Index].Attributes = SE_PRIVILEGE_ENABLED ;
  6176. }
  6177. }
  6178. Result = AdjustTokenPrivileges( Token, // TokenHandle
  6179. FALSE, // DisableAllPrivileges
  6180. NewState, // NewState (OPTIONAL)
  6181. ReturnLength, // BufferLength
  6182. NULL, // PreviousState (OPTIONAL)
  6183. &ReturnLength // ReturnLength
  6184. );
  6185. if (! Result)
  6186. {
  6187. Error = GetLastError() ;
  6188. break;
  6189. }
  6190. }
  6191. while ( FALSE ) ;
  6192. if ( Token != NULL )
  6193. CloseHandle( Token );
  6194. MemFree( NewState ) ;
  6195. return Result ? Error : 0 ;
  6196. }