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.

816 lines
24 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A F I L E X P . C P P
  7. //
  8. // Contents: Functions exported from netsetup for answerfile related work.
  9. //
  10. // Author: kumarp 25-November-97
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pch.h"
  14. #pragma hdrstop
  15. #include "afileint.h"
  16. #include "afilexp.h"
  17. #include "compid.h"
  18. #include "kkenet.h"
  19. #include "kkutils.h"
  20. #include "ncerror.h"
  21. #include "ncnetcfg.h"
  22. #include "ncsetup.h"
  23. #include "nsbase.h"
  24. #include "oemupgrd.h"
  25. #include "resource.h"
  26. #include "upgrade.h"
  27. #include <wdmguid.h>
  28. #include "nslog.h"
  29. //+---------------------------------------------------------------------------
  30. // Global variables
  31. //
  32. CNetInstallInfo* g_pnii;
  33. CNetInstallInfo* g_pniiTemp;
  34. DWORD g_dwOperationFlags = 0;
  35. //+---------------------------------------------------------------------------
  36. //
  37. // Function: HrDoUnattend
  38. //
  39. // Purpose: call member function of CNetInstallInfo to perform
  40. // answerfile based install/upgrade work
  41. //
  42. // Arguments:
  43. // hwndParent [in] handle of parent window
  44. // punk [in] pointer to an interface
  45. // idPage [in] id indicating which section to run
  46. // ppdm [out] pointer to page display mode
  47. // pfAllowChanges [out] pointer to flag controlling read/write behavior
  48. //
  49. // Returns: S_OK on success, otherwise an error code
  50. //
  51. // Author: kumarp 26-November-97
  52. //
  53. EXTERN_C
  54. HRESULT
  55. WINAPI
  56. HrDoUnattend (
  57. IN HWND hwndParent,
  58. IN IUnknown* punk,
  59. IN EUnattendWorkType uawType,
  60. OUT EPageDisplayMode* ppdm,
  61. OUT BOOL* pfAllowChanges)
  62. {
  63. TraceFileFunc(ttidGuiModeSetup);
  64. Assert(punk);
  65. Assert(ppdm);
  66. Assert(pfAllowChanges);
  67. Assert(g_pnii);
  68. HRESULT hr = S_OK;
  69. #if DBG
  70. if (FIsDebugFlagSet (dfidBreakOnDoUnattend))
  71. {
  72. AssertSz(FALSE, "THIS IS NOT A BUG! The debug flag "
  73. "\"BreakOnDoUnattend\" has been set. Set your breakpoints now.");
  74. }
  75. #endif //_DEBUG
  76. hr = g_pnii->HrDoUnattended(hwndParent, punk, uawType, ppdm, pfAllowChanges);
  77. TraceHr(ttidError, FAL, hr, FALSE, "HrDoUnattend");
  78. return hr;
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Function: HrInitForRepair
  83. //
  84. // Purpose: Initialize in repair mode.
  85. //
  86. // Arguments:
  87. //
  88. // Returns: S_OK on success, otherwise an error code
  89. //
  90. // Author: asinha 17-October-2001
  91. //
  92. HRESULT
  93. HrInitForRepair (VOID)
  94. {
  95. TraceFileFunc(ttidGuiModeSetup);
  96. HRESULT hr = S_OK;
  97. g_pnii = NULL;
  98. hr = CNetInstallInfo::HrCreateInstance (
  99. NULL,
  100. &g_pnii);
  101. TraceHr(ttidError, FAL, hr, FALSE,
  102. "HrInitForRepair");
  103. return hr;
  104. }
  105. //+---------------------------------------------------------------------------
  106. //
  107. // Function: HrInitForUnattendedNetSetup
  108. //
  109. // Purpose: Initialize net setup for answerfile processing
  110. //
  111. // Arguments:
  112. // pnc [in] pointer to INetCfg object
  113. // pisd [in] pointer to private data supplied by base setup
  114. //
  115. // Returns: S_OK on success, otherwise an error code
  116. //
  117. // Author: kumarp 26-November-97
  118. //
  119. HRESULT
  120. HrInitForUnattendedNetSetup (
  121. IN INetCfg* pnc,
  122. IN PINTERNAL_SETUP_DATA pisd)
  123. {
  124. TraceFileFunc(ttidGuiModeSetup);
  125. Assert(pnc);
  126. Assert(pisd);
  127. HRESULT hr = S_OK;
  128. g_dwOperationFlags = pisd->OperationFlags;
  129. if (pisd->OperationFlags & SETUPOPER_BATCH)
  130. {
  131. Assert(pisd->UnattendFile);
  132. AssertSz(!g_pnii, "who initialized g_pnii ??");
  133. hr = HrInitAnswerFileProcessing(pisd->UnattendFile, &g_pnii);
  134. }
  135. TraceHr(ttidError, FAL, hr,
  136. (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) ||
  137. (hr == NETSETUP_E_NO_ANSWERFILE),
  138. "HrInitNetSetup");
  139. return hr;
  140. }
  141. //+---------------------------------------------------------------------------
  142. //
  143. // Function: HrCleanupNetSetup
  144. //
  145. // Purpose: Do cleanup work in NetSetup
  146. //
  147. // Arguments: None
  148. //
  149. // Returns: Nothing
  150. //
  151. // Author: kumarp 26-November-97
  152. //
  153. VOID
  154. HrCleanupNetSetup()
  155. {
  156. TraceFileFunc(ttidGuiModeSetup);
  157. DeleteIfNotNull(g_pnii);
  158. DeleteIfNotNull(g_pniiTemp);
  159. }
  160. //+---------------------------------------------------------------------------
  161. //
  162. // Function: HrGetAnswerFileName
  163. //
  164. // Purpose: Generate full path to the answerfile
  165. //
  166. // Arguments:
  167. // pstrAnswerFileName [out] pointer to name of answerfile
  168. //
  169. // Returns: S_OK on success, otherwise an error code
  170. //
  171. // Author: kumarp 26-November-97
  172. //
  173. // Notes: !!!This function has a dependency on the base setup.!!!
  174. // If base setup changes name of the answerfile, this fn
  175. // function will break.
  176. //
  177. HRESULT
  178. HrGetAnswerFileName(
  179. OUT tstring* pstrAnswerFileName)
  180. {
  181. TraceFileFunc(ttidGuiModeSetup);
  182. static const WCHAR c_szAfSubDirAndName[] = L"\\system32\\$winnt$.inf";
  183. HRESULT hr=S_OK;
  184. WCHAR szWinDir[MAX_PATH+1];
  185. DWORD cNumCharsReturned = GetSystemWindowsDirectory(szWinDir, MAX_PATH);
  186. if (cNumCharsReturned)
  187. {
  188. *pstrAnswerFileName = szWinDir;
  189. *pstrAnswerFileName += c_szAfSubDirAndName;
  190. }
  191. else
  192. {
  193. hr = HrFromLastWin32Error();
  194. }
  195. TraceHr(ttidError, FAL, hr, FALSE, "HrGetAnswerFileName");
  196. return hr;
  197. }
  198. //+---------------------------------------------------------------------------
  199. //
  200. // Function: HrInitAnswerFileProcessing
  201. //
  202. // Purpose: Initialize answerfile processing
  203. //
  204. // Arguments:
  205. // szAnswerFileName [in] name of answerfile
  206. // ppnii [out] pointer to pointer to CNetInstallInfo object
  207. //
  208. // Returns: S_OK on success, otherwise an error code
  209. //
  210. // Author: kumarp 26-November-97
  211. //
  212. HRESULT
  213. HrInitAnswerFileProcessing (
  214. IN PCWSTR szAnswerFileName,
  215. OUT CNetInstallInfo** ppnii)
  216. {
  217. TraceFileFunc(ttidGuiModeSetup);
  218. Assert(ppnii);
  219. HRESULT hr = S_OK;
  220. tstring strAnswerFileName;
  221. *ppnii = NULL;
  222. if (!szAnswerFileName)
  223. {
  224. hr = HrGetAnswerFileName(&strAnswerFileName);
  225. }
  226. else
  227. {
  228. strAnswerFileName = szAnswerFileName;
  229. }
  230. if (S_OK == hr)
  231. {
  232. hr = CNetInstallInfo::HrCreateInstance (
  233. strAnswerFileName.c_str(),
  234. ppnii);
  235. }
  236. TraceHr(ttidError, FAL, hr,
  237. (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) ||
  238. (hr == NETSETUP_E_NO_ANSWERFILE),
  239. "HrInitAnswerFileProcessing");
  240. return hr;
  241. }
  242. //+---------------------------------------------------------------------------
  243. //
  244. // Function: HrOemUpgrade
  245. //
  246. // Purpose: Process special OEM upgrades by running an inf section
  247. //
  248. // Arguments:
  249. // hkeyDriver [in] the driver key
  250. // pszAnswerFile [in] pointer to answer filename string.
  251. // pszAnswerSection [in] pointer to answer filname sections string
  252. //
  253. // Returns: S_OK on success, otherwise an error code
  254. //
  255. // Date: 30 Mar 1998
  256. //
  257. EXTERN_C
  258. HRESULT
  259. WINAPI
  260. HrOemUpgrade(
  261. IN HKEY hkeyDriver,
  262. IN PCWSTR pszAnswerFile,
  263. IN PCWSTR pszAnswerSection)
  264. {
  265. TraceFileFunc(ttidGuiModeSetup);
  266. Assert(hkeyDriver);
  267. Assert(pszAnswerFile);
  268. Assert(pszAnswerSection);
  269. // Open the answer file.
  270. HINF hinf;
  271. HRESULT hr = HrSetupOpenInfFile(pszAnswerFile, NULL,
  272. INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL, &hinf);
  273. if (SUCCEEDED(hr))
  274. {
  275. tstring strInfToRun;
  276. tstring strSectionToRun;
  277. tstring strInfToRunType;
  278. // Get the file and section to run for upgrade
  279. hr = HrAfGetInfToRunValue(hinf, pszAnswerFile, pszAnswerSection,
  280. I2R_AfterInstall, &strInfToRun, &strSectionToRun, &strInfToRunType);
  281. if (S_OK == hr)
  282. {
  283. HINF hinfToRun;
  284. // Open the inf file containing the section to run
  285. hr = HrSetupOpenInfFile(strInfToRun.c_str(), NULL,
  286. INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL,
  287. &hinfToRun);
  288. if (SUCCEEDED(hr))
  289. {
  290. TraceTag(ttidNetSetup, "Running section %S in %S",
  291. strSectionToRun.c_str(), strInfToRun.c_str());
  292. // Run the section against the key
  293. hr = HrSetupInstallFromInfSection (NULL,
  294. hinfToRun, strSectionToRun.c_str(), SPINST_REGISTRY,
  295. hkeyDriver, NULL, 0, NULL, NULL, NULL, NULL);
  296. NetSetupLogHrStatusV(hr, SzLoadIds (IDS_STATUS_OF_APPLYING),
  297. pszAnswerSection,
  298. strInfToRunType.c_str(),
  299. strSectionToRun.c_str(),
  300. strInfToRun.c_str());
  301. SetupCloseInfFile(hinfToRun);
  302. }
  303. }
  304. else if (SPAPI_E_LINE_NOT_FOUND == hr)
  305. {
  306. // Nothing to run.
  307. hr = S_FALSE;
  308. }
  309. SetupCloseInfFile(hinf);
  310. }
  311. TraceHr(ttidError, FAL, hr, FALSE, "HrOemUpgrade");
  312. return hr;
  313. }
  314. //+---------------------------------------------------------------------------
  315. //
  316. // Function: HrGetAnswerFileParametersForComponent
  317. //
  318. // Purpose: Search in answerfile for a component whose InfId matches
  319. // the one specified.
  320. //
  321. // Arguments:
  322. // pszInfId [in] inf id of component
  323. // ppszAnswerFile [out] pointer to answer filename string.
  324. // ppszAnswerSection [out] pointer to answer filename section string
  325. //
  326. // Returns: S_OK on success, otherwise an error code
  327. //
  328. // Author: billbe 12 July 1999
  329. //
  330. // Notes: This fcn is not for adapters. If you need the answerfile
  331. // parameters for an adapter, use
  332. // HrGetAnswerFileParametersForNetCard.
  333. //
  334. HRESULT
  335. HrGetAnswerFileParametersForComponent (
  336. IN PCWSTR pszInfId,
  337. OUT PWSTR* ppszAnswerFile,
  338. OUT PWSTR* ppszAnswerSection)
  339. {
  340. TraceFileFunc(ttidGuiModeSetup);
  341. Assert(pszInfId);
  342. Assert(ppszAnswerFile);
  343. Assert(ppszAnswerSection);
  344. HRESULT hr = S_OK;
  345. TraceTag (ttidNetSetup, "In HrGetAnswerFileParametersForComponent");
  346. *ppszAnswerFile = NULL;
  347. *ppszAnswerSection = NULL;
  348. // If we don't already have a cached pointer...
  349. if (!g_pniiTemp)
  350. {
  351. // Initialize our net install info.
  352. hr = HrInitAnswerFileProcessing(NULL, &g_pniiTemp);
  353. }
  354. if (S_OK == hr)
  355. {
  356. Assert(g_pniiTemp);
  357. if (!g_pniiTemp->AnswerFileInitialized())
  358. {
  359. hr = NETSETUP_E_NO_ANSWERFILE;
  360. TraceTag (ttidNetSetup, "No answerfile");
  361. }
  362. if (S_OK == hr)
  363. {
  364. // Find the component in the list of component's with
  365. // answer file sections.
  366. CNetComponent* pnetcomp;
  367. pnetcomp = g_pniiTemp->FindFromInfID (pszInfId);
  368. if (!pnetcomp)
  369. {
  370. // The component doesn't have a section. Return
  371. // no answer file.
  372. hr = NETSETUP_E_NO_ANSWERFILE;
  373. TraceTag (ttidNetSetup, "Component not found");
  374. }
  375. else
  376. {
  377. if (NCT_Adapter == pnetcomp->Type())
  378. {
  379. // We don't support getting answerfile parameters
  380. // for adapters. HrGetAnswerFileParametersForNetCard
  381. // is the fcn for adapters.
  382. hr = NETSETUP_E_NO_ANSWERFILE;
  383. }
  384. else
  385. {
  386. // Allocate and save the answerfile name and the
  387. // component's section.
  388. hr = HrCoTaskMemAllocAndDupSz (g_pniiTemp->AnswerFileName(),
  389. ppszAnswerFile, MAX_PATH);
  390. if (S_OK == hr)
  391. {
  392. hr = HrCoTaskMemAllocAndDupSz (
  393. pnetcomp->ParamsSections().c_str(),
  394. ppszAnswerSection, MAX_PATH);
  395. }
  396. }
  397. }
  398. }
  399. }
  400. else
  401. {
  402. TraceTag (ttidNetSetup, "Answerfile could not be initialized");
  403. }
  404. TraceHr (ttidError, FAL, hr,
  405. (NETSETUP_E_NO_ANSWERFILE == hr) ||
  406. (HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND) == hr),
  407. "HrGetAnswerFileParametersForComponent");
  408. return hr;
  409. }
  410. //+---------------------------------------------------------------------------
  411. //
  412. // Function: HrGetAnswerFileParametersForNetCard
  413. //
  414. // Purpose: Search in answerfile for a net card whose InfID matches
  415. // at least one in the supplied multi-sz list.
  416. //
  417. // Arguments:
  418. // mszInfIDs [in] list of InfIDs
  419. // pszDeviceName [in] exported device name of the card to search
  420. // pguidNetCardInstance [in] pointer to instance guid of the card
  421. // pszAnswerFile [out] pointer to answer filename string.
  422. // pszAnswerSection [out] pointer to answer filname sections string
  423. //
  424. // Returns: S_OK on success, otherwise an error code
  425. //
  426. // Author: kumarp 26-November-97
  427. //
  428. // Notes: If more than one such card is found in the answerfile, then
  429. // resolve between the cards by finding out the net-card-address
  430. // of the pszServiceInstance and matching it against that
  431. // stored in the answerfile.
  432. //
  433. EXTERN_C
  434. HRESULT
  435. WINAPI
  436. HrGetAnswerFileParametersForNetCard(
  437. IN HDEVINFO hdi,
  438. IN PSP_DEVINFO_DATA pdeid,
  439. IN PCWSTR pszDeviceName,
  440. IN const GUID* pguidNetCardInstance,
  441. OUT PWSTR* ppszwAnswerFile,
  442. OUT PWSTR* ppszwAnswerSections)
  443. {
  444. TraceFileFunc(ttidGuiModeSetup);
  445. Assert(IsValidHandle(hdi));
  446. Assert(pdeid);
  447. Assert(pguidNetCardInstance);
  448. Assert(ppszwAnswerFile);
  449. Assert(ppszwAnswerSections);
  450. HRESULT hr=E_FAIL;
  451. CNetAdapter* pna=NULL;
  452. WORD wNumAdapters=0;
  453. QWORD qwNetCardAddr=0;
  454. *ppszwAnswerFile = NULL;
  455. *ppszwAnswerSections = NULL;
  456. if (!g_pniiTemp)
  457. {
  458. hr = HrInitAnswerFileProcessing(NULL, &g_pniiTemp);
  459. #if DBG
  460. if (S_OK == hr)
  461. {
  462. Assert(g_pniiTemp);
  463. }
  464. #endif
  465. if (FAILED(hr) || !g_pniiTemp->AnswerFileInitialized())
  466. {
  467. TraceHr (ttidNetSetup, FAL, hr, (hr == NETSETUP_E_NO_ANSWERFILE) ||
  468. hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
  469. "HrGetAnswerFileParametersForNetCard");
  470. return hr;
  471. }
  472. }
  473. // the defs of HIDWORD and LODWORD are wrong in byteorder.hxx
  474. # define LODWORD(a) (DWORD)( (a) & ( (DWORD)~0 ))
  475. # define HIDWORD(a) (DWORD)( (a) >> (sizeof(DWORD)*8) )
  476. hr = HrGetNetCardAddr(pszDeviceName, &qwNetCardAddr);
  477. if ((S_OK == hr) && qwNetCardAddr)
  478. {
  479. // there is a bug in wvsprintfA (used in trace.cpp) which does not
  480. // handle %I64x therefore we need to show the QWORD addr as follows
  481. //
  482. TraceTag(ttidNetSetup, "net card address of %S is 0x%x%x",
  483. pszDeviceName, HIDWORD(qwNetCardAddr),
  484. LODWORD(qwNetCardAddr));
  485. hr = g_pniiTemp->FindAdapter(qwNetCardAddr, &pna);
  486. if (NETSETUP_E_NO_EXACT_MATCH == hr)
  487. {
  488. TraceTag(ttidError, "there is no card with this netcard address in the answer-file");
  489. }
  490. }
  491. else
  492. {
  493. TraceTag(ttidError, "error getting netcard address of %S",
  494. pszDeviceName);
  495. // if we either (a) failed to get the NetCard address, or
  496. // (b) if the netcard address was 0 (ISDN adapters), we try other means
  497. //
  498. hr = NETSETUP_E_AMBIGUOUS_MATCH;
  499. }
  500. if (NETSETUP_E_AMBIGUOUS_MATCH == hr)
  501. {
  502. // could not match netcard using the mac addr. If this device is
  503. // PCI, try to match using location info.
  504. //
  505. TraceTag (ttidNetSetup, "Did not find a match for netcard address. "
  506. "But there was at least one section that did not specify an "
  507. "address.\nChecking bus type of installed adapter.");
  508. GUID BusTypeGuid;
  509. hr = HrSetupDiGetDeviceRegistryProperty (hdi, pdeid,
  510. SPDRP_BUSTYPEGUID, NULL, (BYTE*)&BusTypeGuid,
  511. sizeof (BusTypeGuid), NULL);
  512. if (S_OK == hr)
  513. {
  514. if (GUID_BUS_TYPE_PCI == BusTypeGuid)
  515. {
  516. TraceTag (ttidNetSetup, "Installed adapter is PCI. "
  517. "Retrieving its location info.");
  518. DWORD BusNumber;
  519. hr = HrSetupDiGetDeviceRegistryProperty (hdi, pdeid,
  520. SPDRP_BUSNUMBER, NULL, (BYTE*)&BusNumber,
  521. sizeof (BusNumber), NULL);
  522. if (S_OK == hr)
  523. {
  524. DWORD Address;
  525. hr = HrSetupDiGetDeviceRegistryProperty (hdi, pdeid,
  526. SPDRP_ADDRESS, NULL, (BYTE*)&Address,
  527. sizeof (Address), NULL);
  528. if (S_OK == hr)
  529. {
  530. TraceTag (ttidNetSetup, "Installed device location: "
  531. "Bus: %X, Device %x, Function %x\n Will try to "
  532. "use location info to find a match with the "
  533. "remaining ambiguous sections.", BusNumber,
  534. HIWORD(Address), LOWORD(Address));
  535. hr = g_pniiTemp->FindAdapter (BusNumber,
  536. Address, &pna);
  537. #ifdef ENABLETRACE
  538. if (NETSETUP_E_NO_EXACT_MATCH == hr)
  539. {
  540. TraceTag (ttidNetSetup, "No match was found "
  541. "using PCI location info.");
  542. }
  543. else if (NETSETUP_E_AMBIGUOUS_MATCH == hr)
  544. {
  545. TraceTag (ttidNetSetup, "Location info did not "
  546. "match but some sections did not specify "
  547. "location info.");
  548. }
  549. #endif // ENABLETRACE
  550. }
  551. }
  552. }
  553. else
  554. {
  555. hr = NETSETUP_E_AMBIGUOUS_MATCH;
  556. }
  557. }
  558. if (FAILED(hr) && (NETSETUP_E_AMBIGUOUS_MATCH != hr) &&
  559. (NETSETUP_E_NO_EXACT_MATCH != hr))
  560. {
  561. TraceHr(ttidNetSetup, FAL, hr, FALSE, "Trying to retrieve/use "
  562. "PCI location info.");
  563. hr = NETSETUP_E_AMBIGUOUS_MATCH;
  564. }
  565. if (NETSETUP_E_AMBIGUOUS_MATCH == hr)
  566. {
  567. // could not match netcard using the mac addr. try to match
  568. // using the PnP ID
  569. TraceTag (ttidNetSetup, "Will try to use pnp id to find a match "
  570. "with the remaining ambiguous sections.");
  571. PWSTR mszInfIds;
  572. hr = HrGetCompatibleIds (hdi, pdeid, &mszInfIds);
  573. if (S_OK == hr)
  574. {
  575. #ifdef ENABLETRACE
  576. TStringList slInfIds;
  577. tstring strInfIds;
  578. MultiSzToColString(mszInfIds, &slInfIds);
  579. ConvertStringListToCommaList(slInfIds, strInfIds);
  580. TraceTag(ttidNetSetup, "(InfIDs (%d): %S\tDeviceName: %S)",
  581. slInfIds.size(), strInfIds.c_str(), pszDeviceName);
  582. #endif
  583. // find out how many adapters have this InfID
  584. wNumAdapters = (WORD)g_pniiTemp->AdaptersPage()->GetNumCompatibleAdapters(mszInfIds);
  585. TraceTag(ttidNetSetup, "%d adapters of type '%S' found in the answer-file",
  586. wNumAdapters, mszInfIds);
  587. if (wNumAdapters == 1)
  588. {
  589. // a definite match found
  590. pna = (CNetAdapter*) g_pniiTemp->AdaptersPage()->FindCompatibleAdapter(mszInfIds);
  591. Assert(pna);
  592. // Since matching by inf id can cause one section to be
  593. // matched to multiple adapters, we pass on sections that
  594. // have already been give to an adapter.
  595. //
  596. GUID guid = GUID_NULL;
  597. pna->GetInstanceGuid(&guid);
  598. if (GUID_NULL == guid)
  599. {
  600. // The section is still available.
  601. hr = S_OK;
  602. }
  603. else
  604. {
  605. // This section was given to another adapter.
  606. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  607. }
  608. }
  609. else
  610. {
  611. // either there are no adapters of this type in the answerfile
  612. // or there are multiple adapters of the same type.
  613. // we couldn't match the card using the mac addr earlier.
  614. // must return error
  615. //
  616. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  617. }
  618. MemFree (mszInfIds);
  619. }
  620. }
  621. }
  622. if (S_OK == hr)
  623. {
  624. Assert(pna);
  625. pna->SetInstanceGuid(pguidNetCardInstance);
  626. hr = HrCoTaskMemAllocAndDupSz(g_pniiTemp->AnswerFileName(),
  627. (PWSTR*) ppszwAnswerFile, MAX_PATH);
  628. if (S_OK == hr)
  629. {
  630. hr = HrCoTaskMemAllocAndDupSz(pna->ParamsSections().c_str(),
  631. (PWSTR*) ppszwAnswerSections, MAX_PATH);
  632. }
  633. }
  634. if (S_OK != hr && (NETSETUP_E_NO_ANSWERFILE != hr))
  635. {
  636. // add log so that we know why adapter specific params
  637. // are lost after upgrade
  638. //
  639. if (g_dwOperationFlags & SETUPOPER_NTUPGRADE)
  640. { // bug 124805 - We only want to see this during upgradres
  641. WCHAR szGuid[c_cchGuidWithTerm];
  642. StringFromGUID2(*pguidNetCardInstance, szGuid, c_cchGuidWithTerm);
  643. NetSetupLogStatusV(LogSevWarning,
  644. SzLoadIds (IDS_ANSWERFILE_SECTION_NOT_FOUND),
  645. szGuid);
  646. }
  647. }
  648. if ((NETSETUP_E_AMBIGUOUS_MATCH == hr) ||
  649. (NETSETUP_E_NO_EXACT_MATCH == hr))
  650. {
  651. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  652. }
  653. TraceHr(ttidError, FAL, hr,
  654. (hr == NETSETUP_E_NO_ANSWERFILE) ||
  655. (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)),
  656. "HrGetAnswerFileParametersForNetCard");
  657. return hr;
  658. }
  659. //+---------------------------------------------------------------------------
  660. //
  661. // Function: HrGetInstanceGuidOfPreNT5NetCardInstance
  662. //
  663. // Purpose: Finds the instance guid of a component specified in the answerfile
  664. // or an already installed component
  665. //
  666. // Arguments:
  667. // szPreNT5NetCardInstance [in] pre-NT5 net card instance name e.g. "ieepro2"
  668. // pguid [out] instance guid of the same card
  669. //
  670. // Returns: S_OK if found, S_FALSE if not, or an error code.
  671. //
  672. // Author: kumarp 12-AUG-97
  673. //
  674. // Notes:
  675. //
  676. EXTERN_C
  677. HRESULT
  678. WINAPI
  679. HrGetInstanceGuidOfPreNT5NetCardInstance (
  680. IN PCWSTR szPreNT5NetCardInstance,
  681. OUT LPGUID pguid)
  682. {
  683. TraceFileFunc(ttidGuiModeSetup);
  684. Assert(szPreNT5NetCardInstance);
  685. Assert(pguid);
  686. HRESULT hr = E_FAIL;
  687. if (IsBadStringPtr(szPreNT5NetCardInstance, 64) ||
  688. IsBadWritePtr(pguid, sizeof(GUID)))
  689. {
  690. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  691. }
  692. else if (g_pnii)
  693. {
  694. hr = g_pnii->HrGetInstanceGuidOfPreNT5NetCardInstance (
  695. szPreNT5NetCardInstance, pguid);
  696. }
  697. TraceHr(ttidError, FAL, hr, FALSE,
  698. "HrGetInstanceGuidOfPreNT5NetCardInstance");
  699. return hr;
  700. }
  701. HRESULT
  702. HrResolveAnswerFileAdapters (
  703. IN INetCfg* pnc)
  704. {
  705. TraceFileFunc(ttidGuiModeSetup);
  706. Assert(g_pnii);
  707. HRESULT hr = S_OK;
  708. if (g_pnii)
  709. {
  710. hr = g_pnii->AdaptersPage()->HrResolveNetAdapters(pnc);
  711. }
  712. TraceHr(ttidError, FAL, hr, FALSE, "HrResolveAnswerFileAdapters");
  713. return hr;
  714. }