Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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