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.

941 lines
30 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: U P G R A D E . C P P
  7. //
  8. // Contents: functions related only to network upgrade
  9. // (i.e. not used when installing fresh)
  10. //
  11. // Notes:
  12. //
  13. // Author: kumarp
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "pch.h"
  17. #pragma hdrstop
  18. #include "nsbase.h"
  19. #include "afileint.h"
  20. #include "afilestr.h"
  21. #include "afilexp.h"
  22. #include "kkreg.h"
  23. #include "kkutils.h"
  24. #include "ncatl.h"
  25. #include "nceh.h"
  26. #include "ncnetcfg.h"
  27. #include "ncreg.h"
  28. #include "ncsetup.h"
  29. #include "ncsvc.h"
  30. #include "resource.h"
  31. #include "upgrade.h"
  32. #include "nslog.h"
  33. #include "winsock2.h" // For WSCEnumProtocols
  34. #include "ws2spi.h"
  35. #include "sporder.h" // For WSCWriteProviderOrder
  36. // ----------------------------------------------------------------------
  37. // String constants
  38. // ----------------------------------------------------------------------
  39. extern const WCHAR c_szSvcRasAuto[];
  40. extern const WCHAR c_szSvcRouter[];
  41. extern const WCHAR c_szSvcRemoteAccess[];
  42. extern const WCHAR c_szSvcRipForIp[];
  43. extern const WCHAR c_szSvcRipForIpx[];
  44. extern const WCHAR c_szSvcDhcpRelayAgent[];
  45. extern const WCHAR c_szInfId_MS_RasSrv[];
  46. // ----------------------------------------------------------------------
  47. // forward declarations
  48. // ----------------------------------------------------------------------
  49. // returns S_OK on success.
  50. typedef HRESULT (*HrOemComponentUpgradeFnPrototype) (IN DWORD dwUpgradeFlag,
  51. IN DWORD dwUpgradeFromBuildNumber,
  52. IN PCWSTR pszAnswerFileName,
  53. IN PCWSTR pszAnswerFileSectionName);
  54. BOOL InitWorkForWizIntro();
  55. // ----------------------------------------------------------------------
  56. static const WCHAR c_szCleanSection[] = L"Clean";
  57. static const WCHAR c_szCleanServicesSection[]= L"Clean.Services";
  58. const WCHAR c_szRouterUpgradeDll[] = L"rtrupg.dll";
  59. const CHAR c_szRouterUpgradeFn[] = "RouterUpgrade";
  60. // ----------------------------------------------------------------------
  61. #define RGAS_SERVICES_HOME L"SYSTEM\\CurrentControlSet\\Services"
  62. // ----------------------------------------------------------------------
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Function: HrRunAnswerFileCleanSection
  66. //
  67. // Purpose: Runs the [Clean] section of the answer file to remove old
  68. // registry entries and services.
  69. //
  70. // Arguments:
  71. // (none)
  72. //
  73. // Returns: S_OK if succeeded, SetupAPI error otherwise
  74. //
  75. // Author: danielwe 12 Jun 1997
  76. //
  77. // Notes:
  78. //
  79. HRESULT HrRunAnswerFileCleanSection(IN PCWSTR pszAnswerFileName)
  80. {
  81. TraceFileFunc(ttidGuiModeSetup);
  82. DefineFunctionName("HrRunAnswerFileCleanSection");
  83. TraceFunctionEntry(ttidNetSetup);
  84. AssertValidReadPtr(pszAnswerFileName);
  85. TraceTag(ttidNetSetup, "%s: Cleaning services and registry keys based "
  86. "on params in the answer file %S.", __FUNCNAME__, pszAnswerFileName);
  87. HRESULT hr;
  88. HINF hinf;
  89. hr = HrSetupOpenInfFile(pszAnswerFileName, NULL,
  90. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  91. NULL, &hinf);
  92. if (S_OK == hr)
  93. {
  94. BOOL frt;
  95. // It may say "Install" but this really deletes a bunch of
  96. // registry "leftovers" from previous installs
  97. frt = SetupInstallFromInfSection(NULL, hinf, c_szCleanSection,
  98. SPINST_ALL, NULL, NULL, NULL,
  99. NULL, NULL, NULL, NULL);
  100. if (frt)
  101. {
  102. frt = SetupInstallServicesFromInfSection(hinf,
  103. c_szCleanServicesSection,
  104. 0);
  105. if (!frt)
  106. {
  107. hr = HrFromLastWin32Error();
  108. TraceErrorOptional("SetupInstallServicesFromInfSection", hr,
  109. (hr == HRESULT_FROM_SETUPAPI(ERROR_SECTION_NOT_FOUND)));
  110. }
  111. }
  112. else
  113. {
  114. hr = HrFromLastWin32Error();
  115. TraceErrorOptional("SetupInstallServicesFromInfSection", hr,
  116. (hr == HRESULT_FROM_SETUPAPI(ERROR_SECTION_NOT_FOUND)));
  117. }
  118. SetupCloseInfFile(hinf);
  119. }
  120. if (HRESULT_FROM_SETUPAPI(ERROR_SECTION_NOT_FOUND) == hr)
  121. {
  122. hr = S_OK;
  123. }
  124. TraceError("HrRunAnswerFileCleanSection", hr);
  125. return hr;
  126. }
  127. // ----------------------------------------------------------------------
  128. //
  129. // Function: HrSaveInstanceGuid
  130. //
  131. // Purpose: Save instance guid of the specified component to the registry
  132. //
  133. // Arguments:
  134. // pszComponentName [in] name of
  135. // pguidInstance [in] pointer to
  136. //
  137. // Returns: S_OK on success, otherwise an error code
  138. //
  139. // Author: kumarp 23-December-97
  140. //
  141. // Notes:
  142. //
  143. HRESULT HrSaveInstanceGuid(
  144. IN PCWSTR pszComponentName,
  145. IN const GUID* pguidInstance)
  146. {
  147. TraceFileFunc(ttidGuiModeSetup);
  148. DefineFunctionName("HrSaveInstanceGuid");
  149. AssertValidReadPtr(pszComponentName);
  150. AssertValidReadPtr(pguidInstance);
  151. HRESULT hr;
  152. HKEY hkeyMap;
  153. hr = HrRegCreateKeyEx (
  154. HKEY_LOCAL_MACHINE,
  155. c_szRegKeyAnswerFileMap,
  156. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  157. &hkeyMap, NULL);
  158. if (S_OK == hr)
  159. {
  160. hr = HrRegSetGuidAsSz (hkeyMap, pszComponentName, *pguidInstance);
  161. RegCloseKey (hkeyMap);
  162. }
  163. TraceFunctionError(hr);
  164. return hr;
  165. }
  166. // ----------------------------------------------------------------------
  167. //
  168. // Function: HrLoadInstanceGuid
  169. //
  170. // Purpose: Load instance guid of the specified component from registry
  171. //
  172. // Arguments:
  173. // pszComponentName [in] name of
  174. // pguidInstance [out] pointer to
  175. //
  176. // Returns: S_OK on success, otherwise an error code
  177. //
  178. // Author: kumarp 23-December-97
  179. //
  180. // Notes:
  181. //
  182. HRESULT HrLoadInstanceGuid(
  183. IN PCWSTR pszComponentName,
  184. OUT LPGUID pguidInstance)
  185. {
  186. TraceFileFunc(ttidGuiModeSetup);
  187. DefineFunctionName("HrLoadInstanceGuid");
  188. Assert (pszComponentName);
  189. Assert (pguidInstance);
  190. HRESULT hr;
  191. HKEY hkeyMap;
  192. ZeroMemory(pguidInstance, sizeof(GUID));
  193. hr = HrRegOpenKeyEx (
  194. HKEY_LOCAL_MACHINE,
  195. c_szRegKeyAnswerFileMap,
  196. KEY_READ,
  197. &hkeyMap);
  198. if (S_OK == hr)
  199. {
  200. WCHAR szGuid[c_cchGuidWithTerm];
  201. DWORD cbGuid = sizeof(szGuid);
  202. hr = HrRegQuerySzBuffer (
  203. hkeyMap,
  204. pszComponentName,
  205. szGuid,
  206. &cbGuid);
  207. if (S_OK == hr)
  208. {
  209. hr = IIDFromString (szGuid, pguidInstance);
  210. }
  211. RegCloseKey (hkeyMap);
  212. }
  213. TraceFunctionError(hr);
  214. return hr;
  215. }
  216. static const PCWSTR c_aszServicesToIgnore[] =
  217. {
  218. L"afd",
  219. L"asyncmac",
  220. L"atmarp",
  221. L"dhcp",
  222. L"nbf", // see bug 143346
  223. L"ndistapi",
  224. L"ndiswan",
  225. L"nwlnkipx",
  226. L"nwlnknb",
  227. L"nwlnkspx",
  228. L"rpcss",
  229. L"wanarp",
  230. };
  231. // ----------------------------------------------------------------------
  232. //
  233. // Function: HrRestoreServiceStartValuesToPreUpgradeSetting
  234. //
  235. // Purpose: Restore start value of each network service to
  236. // what was before upgrade
  237. //
  238. // Arguments:
  239. // pwifAnswerFile [in] pointer to CWInfFile object
  240. //
  241. // Returns: S_OK on success, otherwise an error code
  242. //
  243. // Author: kumarp 23-December-97
  244. //
  245. // Notes:
  246. //
  247. HRESULT HrRestoreServiceStartValuesToPreUpgradeSetting(IN CWInfFile* pwifAnswerFile)
  248. {
  249. TraceFileFunc(ttidGuiModeSetup);
  250. DefineFunctionName("HrRestoreServiceStartValuesToPreUpgradeSetting");
  251. CWInfSection* pwisServiceStartTypes;
  252. pwisServiceStartTypes = pwifAnswerFile->FindSection(c_szAfServiceStartTypes);
  253. if (!pwisServiceStartTypes)
  254. {
  255. return S_OK;
  256. }
  257. HRESULT hr;
  258. CServiceManager scm;
  259. hr = scm.HrOpen();
  260. if (SUCCEEDED(hr))
  261. {
  262. DWORD dwPreUpgRouterStartType=0;
  263. DWORD dwPreUpgRemoteAccessStartType=0;
  264. DWORD dwRRASStartType=0;
  265. DWORD dwPreUpgRipForIpStartType=0;
  266. DWORD dwPreUpgRipForIpxStartType=0;
  267. DWORD dwPreUpgDhcpRelayAgentStartType=0;
  268. // In Windows2000, Router and RemoteAccess have merged.
  269. // If they have differing service start types before upgrade
  270. // we use the lower of the two start-type values to set
  271. // the start-type of "Routing and remote access" service.
  272. //
  273. // for more info see bug# 260253
  274. //
  275. if (pwisServiceStartTypes->GetIntValue(c_szSvcRouter,
  276. &dwPreUpgRouterStartType) &&
  277. pwisServiceStartTypes->GetIntValue(c_szSvcRemoteAccess,
  278. &dwPreUpgRemoteAccessStartType))
  279. {
  280. dwRRASStartType = min(dwPreUpgRemoteAccessStartType,
  281. dwPreUpgRouterStartType);
  282. TraceTag(ttidNetSetup, "%s: pre-upg start-types:: Router: %d, RemoteAccess: %d",
  283. __FUNCNAME__, dwPreUpgRouterStartType,
  284. dwPreUpgRemoteAccessStartType);
  285. }
  286. // 306202: if IPRIP/IPXRIP/DHCPrelayagent were in use on NT4, set RRAS to Auto
  287. //
  288. if (pwisServiceStartTypes->GetIntValue(c_szSvcRipForIp, &dwPreUpgRipForIpStartType) &&
  289. (SERVICE_AUTO_START == dwPreUpgRipForIpStartType))
  290. {
  291. TraceTag(ttidNetSetup, "%s: pre-upg start-types:: IPRIP: %d, RemoteAccess: %d",
  292. __FUNCNAME__, dwPreUpgRipForIpStartType,
  293. dwPreUpgRemoteAccessStartType);
  294. dwRRASStartType = SERVICE_AUTO_START;
  295. }
  296. if (pwisServiceStartTypes->GetIntValue(c_szSvcRipForIpx, &dwPreUpgRipForIpxStartType) &&
  297. (SERVICE_AUTO_START == dwPreUpgRipForIpxStartType))
  298. {
  299. TraceTag(ttidNetSetup, "%s: pre-upg start-types:: RipForIpx: %d, RemoteAccess: %d",
  300. __FUNCNAME__, dwPreUpgRipForIpxStartType,
  301. dwPreUpgRemoteAccessStartType);
  302. dwRRASStartType = SERVICE_AUTO_START;
  303. }
  304. if (pwisServiceStartTypes->GetIntValue(c_szSvcDhcpRelayAgent, &dwPreUpgDhcpRelayAgentStartType) &&
  305. (SERVICE_AUTO_START == dwPreUpgDhcpRelayAgentStartType))
  306. {
  307. TraceTag(ttidNetSetup, "%s: pre-upg start-types:: DHCPRelayAgent: %d, RemoteAccess: %d",
  308. __FUNCNAME__, dwPreUpgDhcpRelayAgentStartType,
  309. dwPreUpgRemoteAccessStartType);
  310. dwRRASStartType = SERVICE_AUTO_START;
  311. }
  312. // end 306202
  313. for (CWInfKey* pwik = pwisServiceStartTypes->FirstKey();
  314. pwik;
  315. pwik = pwisServiceStartTypes->NextKey())
  316. {
  317. PCWSTR pszServiceName;
  318. DWORD dwPreUpgradeStartValue;
  319. pszServiceName = pwik->Name();
  320. AssertValidReadPtr(pszServiceName);
  321. dwPreUpgradeStartValue = pwik->GetIntValue(-1);
  322. if (dwPreUpgradeStartValue > SERVICE_DISABLED)
  323. {
  324. NetSetupLogStatusV(
  325. LogSevWarning,
  326. SzLoadIds (IDS_INVALID_PREUPGRADE_START),
  327. dwPreUpgradeStartValue,
  328. pszServiceName);
  329. continue;
  330. }
  331. // We do not want to restore the pre-upgrade start type if:
  332. // - it is one of c_aszServicesToIgnore AND
  333. //
  334. if (FIsInStringArray(c_aszServicesToIgnore,
  335. celems(c_aszServicesToIgnore),
  336. pszServiceName))
  337. {
  338. NetSetupLogStatusV(
  339. LogSevInformation,
  340. SzLoadIds (IDS_IGNORED_SERVICE_PREUPGRADE), pszServiceName);
  341. continue;
  342. }
  343. // special case for RRAS, see the comment before the while loop
  344. if ((dwRRASStartType != 0) &&
  345. !lstrcmpiW(pszServiceName, c_szSvcRemoteAccess))
  346. {
  347. dwPreUpgradeStartValue = dwRRASStartType;
  348. }
  349. // 305065: if RasAuto was not disabled on NT4, make it demand-start on NT5
  350. else if ((SERVICE_DISABLED != dwPreUpgradeStartValue) &&
  351. !lstrcmpiW(pszServiceName, c_szSvcRasAuto))
  352. {
  353. dwPreUpgradeStartValue = SERVICE_DEMAND_START;
  354. NetSetupLogStatusV(
  355. LogSevInformation,
  356. SzLoadIds (IDS_FORCING_DEMAND_START),
  357. pszServiceName);
  358. }
  359. CService service;
  360. hr = scm.HrOpenService(&service, pszServiceName);
  361. if (S_OK == hr)
  362. {
  363. DWORD dwStartValue;
  364. hr = service.HrQueryStartType(&dwStartValue);
  365. if ((S_OK == hr) && (dwStartValue != dwPreUpgradeStartValue))
  366. {
  367. hr = service.HrSetStartType(dwPreUpgradeStartValue);
  368. NetSetupLogHrStatusV(hr,
  369. SzLoadIds (IDS_RESTORING_START_TYPE),
  370. pszServiceName, dwStartValue, dwPreUpgradeStartValue, hr);
  371. }
  372. }
  373. }
  374. // ignore any errors
  375. hr = S_OK;
  376. }
  377. TraceError(__FUNCNAME__, hr);
  378. return hr;
  379. }
  380. // GUIDs provided for the sole use of this function, which removes incompatible
  381. // Intel Winsock providers
  382. //
  383. const GUID GUID_INTEL_RSVP =
  384. { 0x0f1e5156L, 0xf07a, 0x11cf, 0x98, 0x0e, 0x00, 0xaa, 0x00, 0x58, 0x0a, 0x07 };
  385. const GUID GUID_INTEL_GQOS1 =
  386. { 0xbca8a790L, 0xc186, 0x11d0, 0xb8, 0x69, 0x00, 0xa0, 0xc9, 0x08, 0x1e, 0x34 };
  387. const GUID GUID_INTEL_GQOS2 =
  388. { 0xf80d1d20L, 0x8b7a, 0x11d0, 0xb8, 0x53, 0x00, 0xa0, 0xc9, 0x08, 0x1e, 0x34 };
  389. //+---------------------------------------------------------------------------
  390. //
  391. // Function: HrRemoveEvilIntelRSVPWinsockSPs
  392. //
  393. // Purpose: Remove the Intel RSVP Winsock SP's so they don't conflict
  394. // with the Windows 2000 RSVP provider. This is a complete hack
  395. // to cure RAID 332622, but it's all we can do this late in the
  396. // ship cycle. There's not a good general-case fix for this
  397. // problem.
  398. //
  399. // Arguments:
  400. // (none)
  401. //
  402. // Returns:
  403. //
  404. // Author: jeffspr 22 Aug 1999
  405. //
  406. // Notes:
  407. //
  408. HRESULT HrRemoveEvilIntelWinsockSPs()
  409. {
  410. TraceFileFunc(ttidGuiModeSetup);
  411. HRESULT hr = S_OK;
  412. // Now read the new IDs and order them in memory
  413. //
  414. INT nErr = NO_ERROR;
  415. ULONG ulRes;
  416. DWORD cbInfo = 0;
  417. WSAPROTOCOL_INFO* pwpi = NULL;
  418. WSAPROTOCOL_INFO* pwpiInfo = NULL;
  419. // First get the size needed
  420. //
  421. ulRes = WSCEnumProtocols(NULL, NULL, &cbInfo, &nErr);
  422. if ((SOCKET_ERROR == ulRes) && (WSAENOBUFS == nErr))
  423. {
  424. pwpi = reinterpret_cast<WSAPROTOCOL_INFO*>(new BYTE[cbInfo]);
  425. if (pwpi)
  426. {
  427. // Find out all the protocols on the system
  428. //
  429. ulRes = WSCEnumProtocols(NULL, pwpi, &cbInfo, &nErr);
  430. if (SOCKET_ERROR != ulRes)
  431. {
  432. ULONG cProt = 0;
  433. for (pwpiInfo = pwpi, cProt = ulRes;
  434. cProt;
  435. cProt--, pwpiInfo++)
  436. {
  437. BOOL fDeleteMe = FALSE;
  438. if (IsEqualGUID(GUID_INTEL_RSVP, pwpiInfo->ProviderId))
  439. {
  440. fDeleteMe = TRUE;
  441. }
  442. else if (IsEqualGUID(GUID_INTEL_GQOS1, pwpiInfo->ProviderId))
  443. {
  444. fDeleteMe = TRUE;
  445. }
  446. else if (IsEqualGUID(GUID_INTEL_GQOS2, pwpiInfo->ProviderId))
  447. {
  448. fDeleteMe = TRUE;
  449. }
  450. if (fDeleteMe)
  451. {
  452. int iErrNo = 0;
  453. int iReturn = WSCDeinstallProvider(
  454. &pwpiInfo->ProviderId, &iErrNo);
  455. TraceTag(ttidNetSetup,
  456. "SP Removal guid: %08x %04x %04x %02x%02x %02x%02x%02x%02x%02x%02x",
  457. pwpiInfo->ProviderId.Data1,
  458. pwpiInfo->ProviderId.Data2,
  459. pwpiInfo->ProviderId.Data3,
  460. pwpiInfo->ProviderId.Data4[0],
  461. pwpiInfo->ProviderId.Data4[1],
  462. pwpiInfo->ProviderId.Data4[2],
  463. pwpiInfo->ProviderId.Data4[3],
  464. pwpiInfo->ProviderId.Data4[4],
  465. pwpiInfo->ProviderId.Data4[5],
  466. pwpiInfo->ProviderId.Data4[6],
  467. pwpiInfo->ProviderId.Data4[7],
  468. pwpiInfo->ProviderId.Data4[8]);
  469. TraceTag(ttidNetSetup,
  470. "Removing incompatible RSVP WS provider: %S (%d, %04x), ret=%d, ierr=%d",
  471. pwpiInfo->szProtocol, pwpiInfo->dwCatalogEntryId,
  472. pwpiInfo->dwCatalogEntryId,
  473. iReturn, iErrNo);
  474. }
  475. }
  476. }
  477. else
  478. {
  479. TraceTag(ttidNetSetup, "Socket error in secondary WSCEnumProtocols");
  480. }
  481. delete pwpi;
  482. }
  483. }
  484. else
  485. {
  486. TraceTag(ttidNetSetup, "Socket error in initial WSCEnumProtocols");
  487. }
  488. TraceHr(ttidNetSetup, FAL, hr, FALSE, "HrRemoveEvilIntelWinsockSPs");
  489. // Yes, we track hr for debugging purposes, but we don't ever want to
  490. // fail based on a failed removal of incompatible Winsock providers
  491. //
  492. return S_OK;
  493. }
  494. BOOL FIsValidCatalogId(WSAPROTOCOL_INFO *pwpi, ULONG cProt, DWORD dwCatId)
  495. {
  496. TraceFileFunc(ttidGuiModeSetup);
  497. for (; cProt; cProt--, pwpi++)
  498. {
  499. if (dwCatId == pwpi->dwCatalogEntryId)
  500. return TRUE;
  501. }
  502. return FALSE;
  503. }
  504. HRESULT HrRestoreWinsockProviderOrder(IN CWInfFile* pwifAnswerFile)
  505. {
  506. TraceFileFunc(ttidGuiModeSetup);
  507. HRESULT hr = S_OK;
  508. vector<DWORD> vecIds;
  509. CWInfSection * pwisWinsock;
  510. DefineFunctionName("HrRestoreWinsockProviderOrder");
  511. // First get the old IDs into a vector of DWORDs
  512. //
  513. pwisWinsock = pwifAnswerFile->FindSection(c_szAfSectionWinsock);
  514. if (pwisWinsock)
  515. {
  516. tstring strOrder;
  517. PWSTR pszOrder;
  518. PWSTR pszId;
  519. pwisWinsock->GetStringValue(c_szAfKeyWinsockOrder, strOrder);
  520. if (!strOrder.empty())
  521. {
  522. pszOrder = SzDupSz(strOrder.c_str());
  523. pszId = wcstok(pszOrder, L".");
  524. while (pszId)
  525. {
  526. DWORD dwId = wcstoul(pszId, NULL, 10);
  527. vecIds.push_back(dwId);
  528. pszId = wcstok(NULL, L".");
  529. }
  530. delete pszOrder;
  531. // Now read the new IDs and order them in memory
  532. //
  533. INT nErr;
  534. ULONG ulRes;
  535. DWORD cbInfo = 0;
  536. WSAPROTOCOL_INFO* pwpi = NULL;
  537. WSAPROTOCOL_INFO* pwpiInfo = NULL;
  538. // First get the size needed
  539. //
  540. ulRes = WSCEnumProtocols(NULL, NULL, &cbInfo, &nErr);
  541. if ((SOCKET_ERROR == ulRes) && (WSAENOBUFS == nErr))
  542. {
  543. pwpi = reinterpret_cast<WSAPROTOCOL_INFO*>(new BYTE[cbInfo]);
  544. if (pwpi)
  545. {
  546. // Find out all the protocols on the system
  547. //
  548. ulRes = WSCEnumProtocols(NULL, pwpi, &cbInfo, &nErr);
  549. if (SOCKET_ERROR != ulRes)
  550. {
  551. ULONG cProt;
  552. vector<DWORD>::iterator iterLocation;
  553. iterLocation = vecIds.begin();
  554. for (pwpiInfo = pwpi, cProt = ulRes;
  555. cProt;
  556. cProt--, pwpiInfo++)
  557. {
  558. if (vecIds.end() == find(vecIds.begin(),
  559. vecIds.end(),
  560. pwpiInfo->dwCatalogEntryId))
  561. {
  562. // Not already in the list.. Add it after the last
  563. // entry we added (or the front if this is the first
  564. // addition)
  565. iterLocation = vecIds.insert(iterLocation,
  566. pwpiInfo->dwCatalogEntryId);
  567. }
  568. }
  569. DWORD * pdwIds = NULL;
  570. DWORD * pdwCurId;
  571. DWORD cdwIds = vecIds.size();
  572. pdwIds = new DWORD[ulRes];
  573. if (pdwIds)
  574. {
  575. #if DBG
  576. DWORD cValid = 0;
  577. #endif
  578. for (pdwCurId = pdwIds, iterLocation = vecIds.begin();
  579. iterLocation != vecIds.end();
  580. iterLocation++, pdwCurId++)
  581. {
  582. // Make sure we only re-order valid catalog
  583. // IDs
  584. if (FIsValidCatalogId(pwpi, ulRes, *iterLocation))
  585. {
  586. #if DBG
  587. cValid++;
  588. #endif
  589. *pdwCurId = *iterLocation;
  590. }
  591. }
  592. AssertSz(ulRes == cValid, "Number of providers is"
  593. " different!");
  594. // Restore the winsock provider order
  595. //
  596. nErr = WSCWriteProviderOrder(pdwIds, cdwIds);
  597. delete pdwIds;
  598. }
  599. }
  600. delete pwpi;
  601. }
  602. }
  603. }
  604. }
  605. TraceError(__FUNCNAME__, hr);
  606. return hr;
  607. }
  608. // ----------------------------------------------------------------------
  609. //
  610. // Function: HrUpgradeOemComponent
  611. //
  612. // Purpose: Upgrade a component. This started as a generalized function
  613. // but currently it is being used only by HrUpgradeRouterIfPresent
  614. //
  615. // Arguments:
  616. // pszComponentToUpgrade [in] component to upgrade
  617. // pszDllName [in] name of DLL to load
  618. // psznEntryPoint [in] entry point to call
  619. // dwUpgradeFlag [in] upgrade flag
  620. // dwUpgradeFromBuildNumber [in] upgrade to build number
  621. // pszAnswerFileName [in] name of answerfile
  622. // pszAnswerFileSectionName [in] name of answerfile section name to use
  623. //
  624. // Returns: S_OK on success, otherwise an error code
  625. //
  626. // Author: kumarp 23-December-97
  627. //
  628. // Notes:
  629. //
  630. HRESULT
  631. HrUpgradeOemComponent (
  632. IN PCWSTR pszComponentToUpgrade,
  633. IN PCWSTR pszDllName,
  634. IN PCSTR psznEntryPoint,
  635. IN DWORD dwUpgradeFlag,
  636. IN DWORD dwUpgradeFromBuildNumber,
  637. IN PCWSTR pszAnswerFileName,
  638. IN PCWSTR pszAnswerFileSectionName)
  639. {
  640. TraceFileFunc(ttidGuiModeSetup);
  641. DefineFunctionName("HrUpgradeOemComponent");
  642. HRESULT hr=E_FAIL;
  643. HrOemComponentUpgradeFnPrototype pfn;
  644. HMODULE hLib;
  645. TraceTag(ttidNetSetup,
  646. "%s: calling function '%s' in '%S' to upgrade component: %S...",
  647. __FUNCNAME__, psznEntryPoint, pszDllName, pszComponentToUpgrade);
  648. hr = HrLoadLibAndGetProc(pszDllName, psznEntryPoint, &hLib, (FARPROC*) &pfn);
  649. if (S_OK == hr)
  650. {
  651. NC_TRY
  652. {
  653. hr = pfn(dwUpgradeFlag, dwUpgradeFromBuildNumber,
  654. pszAnswerFileName, pszAnswerFileSectionName);
  655. }
  656. NC_CATCH_ALL
  657. {
  658. hr = E_UNEXPECTED;
  659. }
  660. FreeLibrary(hLib);
  661. }
  662. TraceError(__FUNCNAME__, hr);
  663. return hr;
  664. }
  665. // ----------------------------------------------------------------------
  666. //
  667. // Function: HrUpgradeRouterIfPresent
  668. //
  669. // Purpose: Upgrade the Router service if present
  670. //
  671. // Arguments:
  672. // pnii [in] pointer to CNetInstallInfo object
  673. //
  674. // Returns: S_OK on success, otherwise an error code
  675. //
  676. // Author: kumarp 23-December-97
  677. //
  678. // Notes:
  679. //
  680. HRESULT HrUpgradeRouterIfPresent(
  681. IN INetCfg* pNetCfg,
  682. IN CNetInstallInfo* pnii)
  683. {
  684. TraceFileFunc(ttidGuiModeSetup);
  685. DefineFunctionName("HrUpgradeRouterIfPresent");
  686. HRESULT hr=S_FALSE;
  687. INFCONTEXT ic;
  688. PCWSTR pszRouterParamsSection=NULL;
  689. CNetComponent* pnc = pnii->FindFromInfID(L"ms_rasrtr");
  690. if (pnc)
  691. {
  692. // Ensure RemoteAccess is installed. In the case of upgrade from
  693. // NT4 with Steelhead, we wouldn't have written a section to
  694. // the answerfile for RemoteAccess and consequently it would not
  695. // have been installed yet. We need to install it before we turn
  696. // the router upgrade DLL loose. In the case when RemoteAccess
  697. // is already installed, this is a no-op.
  698. //
  699. hr = HrInstallComponentOboUser (pNetCfg, NULL,
  700. GUID_DEVCLASS_NETSERVICE,
  701. c_szInfId_MS_RasSrv,
  702. NULL);
  703. if (SUCCEEDED(hr))
  704. {
  705. // we call rtrupg.dll if atleast one of the following keys
  706. // is present in the params.MS_RasRtr section
  707. // - PreUpgradeRouter
  708. // - Sap.Parameters
  709. // - IpRip.Parameters
  710. //
  711. pszRouterParamsSection = pnc->ParamsSections().c_str();
  712. hr = HrSetupFindFirstLine(pnii->m_hinfAnswerFile, pszRouterParamsSection,
  713. c_szAfPreUpgradeRouter, &ic);
  714. if (S_OK != hr)
  715. {
  716. hr = HrSetupFindFirstLine(pnii->m_hinfAnswerFile, pszRouterParamsSection,
  717. c_szAfNwSapAgentParams, &ic);
  718. }
  719. if (S_OK != hr)
  720. {
  721. hr = HrSetupFindFirstLine(pnii->m_hinfAnswerFile, pszRouterParamsSection,
  722. c_szAfIpRipParameters, &ic);
  723. }
  724. if (S_OK != hr)
  725. {
  726. hr = HrSetupFindFirstLine(pnii->m_hinfAnswerFile, pszRouterParamsSection,
  727. c_szAfDhcpRelayAgentParameters, &ic);
  728. }
  729. if (S_OK == hr)
  730. {
  731. hr = HrUpgradeOemComponent(L"ms_rasrtr",
  732. c_szRouterUpgradeDll,
  733. c_szRouterUpgradeFn,
  734. pnii->UpgradeFlag(),
  735. pnii->BuildNumber(),
  736. pnii->AnswerFileName(),
  737. pszRouterParamsSection);
  738. }
  739. }
  740. }
  741. if (!pnc ||
  742. (SPAPI_E_LINE_NOT_FOUND == hr))
  743. {
  744. TraceTag(ttidNetSetup, "%s: PreUpgradeRouter/Sap.Parameters/IpRip.Parameters key is not in answerfile, %S will not be called", __FUNCNAME__,
  745. c_szRouterUpgradeDll);
  746. }
  747. TraceErrorOptional(__FUNCNAME__, hr, ((hr == S_FALSE) ||
  748. (SPAPI_E_LINE_NOT_FOUND == hr)));
  749. return hr;
  750. }
  751. //+---------------------------------------------------------------------------
  752. //
  753. // Function: HrUpgradeTapiServer
  754. //
  755. // Purpose: Handle upgrade requirements of TAPI server
  756. //
  757. // Arguments:
  758. // hinfAnswerFile [in] handle of AnswerFile
  759. //
  760. // Returns: S_OK on success, otherwise an error code
  761. //
  762. // Author: kumarp 28-January-99
  763. //
  764. // Notes:
  765. //
  766. HRESULT HrUpgradeTapiServer(IN HINF hinfAnswerFile)
  767. {
  768. TraceFileFunc(ttidGuiModeSetup);
  769. Assert(hinfAnswerFile);
  770. DefineFunctionName("HrUpgradeTapiServer");
  771. TraceFunctionEntry(ttidNetSetup);
  772. HRESULT hr=S_OK;
  773. BOOL fRunInSeparateInstance=FALSE;
  774. hr = HrSetupGetFirstStringAsBool(hinfAnswerFile,
  775. c_szAfMiscUpgradeData,
  776. c_szAfTapiSrvRunInSeparateInstance,
  777. &fRunInSeparateInstance);
  778. if ((S_OK == hr) && fRunInSeparateInstance)
  779. {
  780. static const WCHAR c_szTapisrv[] = L"Tapisrv";
  781. static const CHAR c_szSvchostChangeSvchostGroup[] =
  782. "SvchostChangeSvchostGroup";
  783. static const WCHAR c_szNetcfgxDll[] = L"netcfgx.dll";
  784. TraceTag(ttidNetSetup, "%s: TapiSrvRunInSeparateInstance is TRUE...",
  785. __FUNCNAME__);
  786. typedef HRESULT (STDAPICALLTYPE *SvchostChangeSvchostGroupFn) (PCWSTR pszService, PCWSTR pszNewGroup);
  787. SvchostChangeSvchostGroupFn pfnSvchostChangeSvchostGroup;
  788. HMODULE hNetcfgx;
  789. hr = HrLoadLibAndGetProc(c_szNetcfgxDll, c_szSvchostChangeSvchostGroup,
  790. &hNetcfgx,
  791. (FARPROC*) &pfnSvchostChangeSvchostGroup);
  792. if (S_OK == hr)
  793. {
  794. hr = pfnSvchostChangeSvchostGroup(c_szTapisrv, c_szTapisrv);
  795. FreeLibrary(hNetcfgx);
  796. }
  797. }
  798. if ((SPAPI_E_LINE_NOT_FOUND == hr) ||
  799. (SPAPI_E_SECTION_NOT_FOUND == hr))
  800. {
  801. TraceTag(ttidNetSetup, "%s: %S not found in section [%S]",
  802. __FUNCNAME__, c_szAfTapiSrvRunInSeparateInstance,
  803. c_szAfMiscUpgradeData);
  804. hr = S_OK;
  805. }
  806. TraceError(__FUNCNAME__, hr);
  807. return hr;
  808. }