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.

1130 lines
38 KiB

  1. // ----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: I N F M A P . C P P
  7. //
  8. // Contents: Functions that work on netmap.inf file.
  9. //
  10. // Notes:
  11. //
  12. // Author: kumarp 22-December-97
  13. //
  14. // ----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "infmap.h"
  18. #include "kkcwinf.h"
  19. #include "kkutils.h"
  20. #include "ncreg.h"
  21. #include "ncsetup.h"
  22. #include "netupgrd.h"
  23. #include "nustrs.h"
  24. #include "nuutils.h"
  25. #include "oemupg.h"
  26. extern const WCHAR c_szNetUpgradeDll[];
  27. // -----------------------------------------------------------------
  28. // Structure of netmap.inf file
  29. //
  30. // We use netmap.inf file to map pre-NT5 InfID of a netcard to its
  31. // NT5 InfID (PnPID).
  32. //
  33. // This file has a number of top-level sections.
  34. // Each top-level section holds entries for mapping netcards of a particular
  35. // bus type. the format of each line is
  36. //
  37. // <pre-NT5 InfID>=<NT5 InfID>
  38. // OR
  39. // <pre-NT5 InfID>=<mapping-method-#>,<section-name>
  40. //
  41. // the former is a 1-1 mapping while the latter offers a way to map a single
  42. // preNT5 InfID to multiple InfIDs
  43. //
  44. // Mapping method 0
  45. // ----------------
  46. // This method is used when a single pre-NT5 InfID represents more than one
  47. // net card which means that a single pre-NT5 InfID is mapped onto many
  48. // NT5 PnPIDs. The only way to differentiate between the different types of
  49. // net cards is to inspect a single value under the parameters key.
  50. //
  51. // In this mapping method, two keys are required to be specified for
  52. // each net card.
  53. // - ValueName: this specifies the value to be inspected under the Parameters key
  54. // - ValueType: this specifies the type of ValueName
  55. //
  56. // there can be any number of additional keys in this section.
  57. // each such line is of the form
  58. // <NT5 InfID>=<some value of type ValueType>
  59. //
  60. // we first find out the value of ValueName
  61. // then we enumerate each key in this section to see if the value matches the
  62. // value of any of the keys.
  63. // if we find a match, then the name of the found key represents <NT5 InfID>
  64. //
  65. // e.g.
  66. // 5 flavors of the ELNK3MCA card are represented by the same InfID in NT4
  67. // the only way to distinguish between them is to inspect the McaPosId value
  68. // for this card we have the mapping section defined as follows:
  69. //
  70. // [McaAdapters]
  71. // ELNK3MCA = 0,ELNK3MCA ; 0 --> mapping method 0
  72. // ... other mca card entries ...
  73. //
  74. // [ELNK3MCA]
  75. // ValueName= McaPosId
  76. // ValueType= 4 ; REG_DWORD
  77. // mca_627c = 0x0000627c ; if value of McaPosId is 0x627c then PnPID == mca_627c
  78. // mca_627d = 0x0000627d
  79. // mca_61db = 0x000061db
  80. // mca_62f6 = 0x000062f6
  81. // mca_62f7 = 0x000062f7
  82. //
  83. // Note: a special keyword "ValueNotPresent" can be used to make a mapping
  84. // for the case when a value is not present.
  85. // List of sections that can appear in the netmap.inf
  86. //
  87. const WCHAR c_szIsaAdapters[] = L"IsaAdapters";
  88. const WCHAR c_szEisaAdapters[] = L"EisaAdapters";
  89. const WCHAR c_szPciAdapters[] = L"PciAdapters";
  90. const WCHAR c_szMcaAdapters[] = L"McaAdapters";
  91. const WCHAR c_szPcmciaAdapters[] = L"PcmciaAdapters";
  92. const WCHAR c_szOemNetAdapters[] = L"OemNetAdapters";
  93. const WCHAR c_szAsyncAdapters[] = L"AsyncAdapters";
  94. const WCHAR c_szOemAsyncAdapters[] = L"OemAsyncAdapters";
  95. static PCWSTR g_aszInfMapNetCardSections[] =
  96. {
  97. c_szIsaAdapters,
  98. c_szEisaAdapters,
  99. c_szPciAdapters,
  100. c_szMcaAdapters,
  101. c_szPcmciaAdapters,
  102. c_szOemNetAdapters,
  103. c_szAsyncAdapters,
  104. c_szOemAsyncAdapters
  105. };
  106. const BYTE g_cNumNetCardSections = celems(g_aszInfMapNetCardSections);
  107. const WCHAR c_szNetProtocols[] = L"NetProtocols";
  108. const WCHAR c_szOemNetProtocols[] = L"OemNetProtocols";
  109. const WCHAR c_szNetServices[] = L"NetServices";
  110. const WCHAR c_szOemNetServices[] = L"OemNetServices";
  111. const WCHAR c_szNetClients[] = L"NetClients";
  112. const WCHAR c_szOemNetClients[] = L"OemNetClients";
  113. const WCHAR c_szOemUpgradeSupport[] = L"OemUpgradeSupport";
  114. // value in netmap.inf indicating the absence of a value in the registry
  115. //
  116. const WCHAR c_szValueNotPresent[] = L"ValueNotPresent";
  117. // ----------------------------------------------------------------------
  118. // prototypes
  119. //
  120. HRESULT HrMapPreNT5InfIdToNT5InfIdInSection(IN HINF hinf,
  121. IN HKEY hkeyAdapterParams,
  122. IN PCWSTR pszSectionName,
  123. IN PCWSTR pszPreNT5InfId,
  124. OUT tstring* pstrNT5InfId,
  125. OUT BOOL* pfOemComponent);
  126. HRESULT HrMapPreNT5InfIdToNT5InfIdUsingMethod0(IN HKEY hkeyAdapterParams,
  127. IN HINF hInf,
  128. IN PCWSTR pszAdapterSection,
  129. OUT tstring* pstrNT5InfId);
  130. HRESULT HrSetupFindKeyWithStringValue(IN HINF hInf,
  131. IN PCWSTR pszSection,
  132. IN PCWSTR pszValue,
  133. OUT tstring* pstrKey);
  134. // ----------------------------------------------------------------------
  135. #pragma BEGIN_CONST_SECTION
  136. const WCHAR c_szNetMapInf[] = L"netmap.inf";
  137. const WCHAR c_szKeyValueName[] = L"ValueName";
  138. const WCHAR c_szKeyValueType[] = L"ValueType";
  139. const WCHAR c_szInfId_MS_ATMUNI[] = L"MS_ATMUNI";
  140. const WCHAR c_szInfId_MS_ATMARPS[] = L"MS_ATMARPS";
  141. #pragma END_CONST_SECTION
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Function: HrMapPreNT5NetCardInfIdInInf
  145. //
  146. // Purpose: Maps using hinf, pre-NT5 InfID of a net card to its NT5 equivalent
  147. //
  148. // Arguments:
  149. // hinf [in] handle of netmap.inf file
  150. // hkeyAdapterParams [in] handle to Parameters key under the netcard driver key
  151. // pszPreNT5InfId [in] pre-NT5 InfID
  152. // pstrNT5InfId [out] NT5 InfID
  153. // pstrAdapterType [out] section in which the map was found
  154. // pfOemComponent [out] set to TRUE if it is an OEM card
  155. //
  156. // Returns: S_OK if found, S_FALSE if not,
  157. // otherwise HRESULT_FROM_WIN32 error code.
  158. //
  159. // Author: kumarp 24-July-97
  160. //
  161. // Notes:
  162. //
  163. HRESULT HrMapPreNT5NetCardInfIdInInf(IN HINF hinf,
  164. IN HKEY hkeyAdapterParams,
  165. IN PCWSTR pszPreNT5InfId,
  166. OUT tstring* pstrNT5InfId,
  167. OUT tstring* pstrAdapterType,
  168. OUT BOOL* pfOemComponent)
  169. {
  170. DefineFunctionName("HrMapPreNT5InfIdToNT5InfId");
  171. Assert(hinf);
  172. Assert(hkeyAdapterParams);
  173. AssertValidReadPtr(pszPreNT5InfId);
  174. AssertValidWritePtr(pstrNT5InfId);
  175. AssertValidWritePtr(pfOemComponent);
  176. HRESULT hr=S_FALSE;
  177. PCWSTR pszSectionName;
  178. for (int iSection=0; iSection < g_cNumNetCardSections; iSection++)
  179. {
  180. pszSectionName = g_aszInfMapNetCardSections[iSection];
  181. hr = HrMapPreNT5InfIdToNT5InfIdInSection(hinf, hkeyAdapterParams,
  182. pszSectionName,
  183. pszPreNT5InfId, pstrNT5InfId,
  184. pfOemComponent);
  185. if (hr == S_OK)
  186. {
  187. if (pstrAdapterType)
  188. {
  189. *pstrAdapterType = pszSectionName;
  190. }
  191. if (!lstrcmpiW(pszSectionName, c_szOemNetAdapters) ||
  192. !lstrcmpiW(pszSectionName, c_szAsyncAdapters) ||
  193. !lstrcmpiW(pszSectionName, c_szOemAsyncAdapters))
  194. {
  195. *pfOemComponent = TRUE;
  196. }
  197. else
  198. {
  199. *pfOemComponent = FALSE;
  200. }
  201. break;
  202. }
  203. }
  204. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  205. return hr;
  206. }
  207. //+---------------------------------------------------------------------------
  208. //
  209. // Function: HrMapPreNT5NetCardInfIdToNT5InfId
  210. //
  211. // Purpose: Maps pre-NT5 InfID of a net card to its NT5 equivalent
  212. //
  213. // Arguments:
  214. // hkeyAdapterParams [in] handle to Parameters key under the netcard driver key
  215. // pszPreNT5InfId [in] pre-NT5 InfID
  216. // pstrNT5InfId [out] NT5 InfID
  217. // pstrAdapterType [out] section in which the map was found
  218. // pfOemComponent [out] set to TRUE if it is an OEM card
  219. // ppnmi [out] CNetMapInfo object representing the map found
  220. //
  221. // Returns: S_OK if found, S_FALSE if not,
  222. // otherwise HRESULT_FROM_WIN32 error code.
  223. //
  224. // Author: kumarp 24-July-97
  225. //
  226. // Notes:
  227. //
  228. HRESULT HrMapPreNT5NetCardInfIdToNT5InfId(IN HKEY hkeyAdapterParams,
  229. IN PCWSTR pszPreNT5InfId,
  230. OUT tstring* pstrNT5InfId,
  231. OUT tstring* pstrAdapterType,
  232. OUT BOOL* pfOemComponent,
  233. OUT CNetMapInfo** ppnmi)
  234. {
  235. DefineFunctionName("HrMapPreNT5NetCardInfIdToNT5InfId");
  236. Assert(hkeyAdapterParams);
  237. AssertValidReadPtr(pszPreNT5InfId);
  238. AssertValidWritePtr(pstrNT5InfId);
  239. AssertValidWritePtr(pstrAdapterType);
  240. AssertValidWritePtr(pfOemComponent);
  241. AssertValidReadPtr(g_pnmaNetMap);
  242. HRESULT hr=E_FAIL;
  243. TraceTag(ttidNetUpgrade, "finding mapping for %S...", pszPreNT5InfId);
  244. if (g_pnmaNetMap)
  245. {
  246. CNetMapInfo* pnmi;
  247. size_t cNumNetMapEntries = g_pnmaNetMap->size();
  248. for (size_t i = 0; i < cNumNetMapEntries; i++)
  249. {
  250. pnmi = (CNetMapInfo*) (*g_pnmaNetMap)[i];
  251. hr = HrMapPreNT5NetCardInfIdInInf(pnmi->m_hinfNetMap,
  252. hkeyAdapterParams,
  253. pszPreNT5InfId,
  254. pstrNT5InfId,
  255. pstrAdapterType,
  256. pfOemComponent);
  257. if (S_OK == hr)
  258. {
  259. if (ppnmi)
  260. {
  261. *ppnmi = pnmi;
  262. }
  263. TraceTag(ttidNetUpgrade, "%s: %S --> %S (type: %S)", __FUNCNAME__,
  264. pszPreNT5InfId, pstrNT5InfId->c_str(),
  265. pstrAdapterType->c_str());
  266. break;
  267. }
  268. }
  269. }
  270. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  271. return hr;
  272. }
  273. //+---------------------------------------------------------------------------
  274. //
  275. // Function: HrMapPreNT5InfIdToNT5InfIdInSection
  276. //
  277. // Purpose: Searches in szSectionName section to
  278. // map pre-NT5 InfID of a net card to its NT5 equivalent
  279. //
  280. // Arguments:
  281. // hinf [in] handle of netmap.inf file
  282. // hkeyAdapterParams [in] handle to Parameters key under the netcard driver key
  283. // pszSectionName [in] name of section to search
  284. // pszPreNT5InfId [in] pre-NT5 InfID
  285. // pstrNT5InfId [out] NT5 InfID
  286. // pfOemComponent [out] set to TRUE if it is an OEM card
  287. //
  288. // Returns: S_OK if found, S_FALSE if not,
  289. // otherwise HRESULT_FROM_WIN32 error code.
  290. //
  291. // Author: kumarp 24-July-97
  292. //
  293. // Notes:
  294. //
  295. HRESULT HrMapPreNT5InfIdToNT5InfIdInSection(IN HINF hinf,
  296. IN HKEY hkeyAdapterParams,
  297. IN PCWSTR pszSectionName,
  298. IN PCWSTR pszPreNT5InfId,
  299. OUT tstring* pstrNT5InfId,
  300. OUT BOOL* pfOemComponent)
  301. {
  302. DefineFunctionName("HrMapPreNT5InfIdToNT5InfIdInSection");
  303. Assert(hinf);
  304. AssertValidReadPtr(pszSectionName);
  305. AssertValidReadPtr(pszPreNT5InfId);
  306. AssertValidWritePtr(pstrNT5InfId);
  307. HRESULT hr=S_FALSE;
  308. INFCONTEXT ic;
  309. hr = HrSetupFindFirstLine(hinf, pszSectionName, pszPreNT5InfId, &ic);
  310. if (SUCCEEDED(hr))
  311. {
  312. DWORD dwMappingMethod=-1;
  313. // key found, get value
  314. // we do not use the common function HrSetupGetIntField because it causes
  315. // tons of TraceError messages for 1-1 mapping where the first value
  316. // is not an integer
  317. if (::SetupGetIntField(&ic, 1, (int*) &dwMappingMethod))
  318. {
  319. // value begins with a number --> this is a special case mapping
  320. //
  321. if (dwMappingMethod == 0)
  322. {
  323. // use mapping method 0
  324. Assert(hkeyAdapterParams);
  325. tstring strAdapterSection;
  326. hr = HrSetupGetStringField(ic, 2, &strAdapterSection);
  327. if (S_OK == hr)
  328. {
  329. hr = HrMapPreNT5InfIdToNT5InfIdUsingMethod0(hkeyAdapterParams,
  330. hinf, strAdapterSection.c_str(), pstrNT5InfId);
  331. }
  332. }
  333. else
  334. {
  335. // currently we support only mapping-method 0
  336. //
  337. hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  338. }
  339. }
  340. else
  341. {
  342. // the first field was not an integer which means
  343. // this is a straight forward (1 to 1) mapping
  344. //
  345. hr = HrSetupGetStringField(ic, 1, pstrNT5InfId);
  346. }
  347. }
  348. if (HRESULT_FROM_SETUPAPI(ERROR_LINE_NOT_FOUND) == hr)
  349. {
  350. hr = S_FALSE;
  351. }
  352. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  353. return hr;
  354. }
  355. //+---------------------------------------------------------------------------
  356. //
  357. // Function: HrMapPreNT5InfIdToNT5InfIdUsingMethod0
  358. //
  359. // Purpose: map pre-NT5 InfID of a net card to its NT5 equivalent
  360. // using mapping method 0
  361. //
  362. // Arguments:
  363. // hkeyAdapterParams [in] handle to Parameters key under the netcard driver key
  364. // hInf [in] handle of netmap.inf
  365. // pszSectionName [in] name of section to search
  366. // pstrNT5InfId [out] NT5 InfID
  367. //
  368. // Returns: S_OK if found, S_FALSE if not, otherwise HRESULT_FROM_WIN32 error code.
  369. //
  370. // Author: kumarp 24-July-97
  371. //
  372. // Notes:
  373. //
  374. // Mapping method 0
  375. // ----------------
  376. // This method is used when a single pre-NT5 InfID represents more than one
  377. // net card which means that a single pre-NT5 InfID is mapped onto many
  378. // NT5 PnPIDs. The only way to differentiate between the different types of
  379. // net cards is to inspect a single value under the parameters key.
  380. //
  381. // In this mapping method, two keys are required to be specified for
  382. // each net card.
  383. // - ValueName: this specifies the value to be inspected under the Parameters key
  384. // - ValueType: this specifies the type of ValueName
  385. //
  386. // there can be any number of additional keys in this section.
  387. // each such line is of the form
  388. // <NT5 InfID>=<some value of type ValueType>
  389. //
  390. // we first find out the value of ValueName
  391. // then we enumerate each key in this section to see if the value matches the
  392. // value of any of the keys.
  393. // if we find a match, then the name of the found key represents <NT5 InfID>
  394. //
  395. // e.g.
  396. // 5 flavors of the ELNK3MCA card are represented by the same InfID in NT4
  397. // the only way to distinguish between them is to inspect the McaPosId value
  398. // for this card we have the mapping section defined as follows:
  399. //
  400. // [McaAdapters]
  401. // ELNK3MCA = 0,ELNK3MCA ; 0 --> mapping method 0
  402. // ... other mca card entries ...
  403. //
  404. // [ELNK3MCA]
  405. // ValueName= McaPosId
  406. // ValueType= 4 ; REG_DWORD
  407. // mca_627c = 0x0000627c ; if value of McaPosId is 0x627c then PnPID == mca_627c
  408. // mca_627d = 0x0000627d
  409. // mca_61db = 0x000061db
  410. // mca_62f6 = 0x000062f6
  411. // mca_62f7 = 0x000062f7
  412. //
  413. // Note: a special keyword "ValueNotPresent" can be used to make a mapping
  414. // for the case when a value is not present.
  415. //
  416. HRESULT HrMapPreNT5InfIdToNT5InfIdUsingMethod0(IN HKEY hkeyAdapterParams,
  417. IN HINF hInf,
  418. IN PCWSTR pszAdapterSection,
  419. OUT tstring* pstrNT5InfId)
  420. {
  421. DefineFunctionName("HrMapPreNT5InfIdToNT5InfIdUsingMethod0");
  422. Assert(hkeyAdapterParams);
  423. Assert(hInf);
  424. AssertValidReadPtr(pszAdapterSection);
  425. AssertValidWritePtr(pstrNT5InfId);
  426. HRESULT hr=S_FALSE;
  427. INFCONTEXT ic;
  428. tstring strValueName;
  429. // get ValueName
  430. hr = HrSetupGetFirstString(hInf, pszAdapterSection,
  431. c_szKeyValueName, &strValueName);
  432. if (SUCCEEDED(hr))
  433. {
  434. DWORD dwRegValue=0;
  435. DWORD dwInfValue=0;
  436. DWORD dwValueType;
  437. tstring strRegValue;
  438. tstring strInfValue;
  439. tstring strValue;
  440. // get ValueType
  441. hr = HrSetupGetFirstDword(hInf, pszAdapterSection,
  442. c_szKeyValueType, &dwValueType);
  443. if (SUCCEEDED(hr))
  444. {
  445. switch (dwValueType)
  446. {
  447. case REG_DWORD:
  448. // find the value in under adapter driver parameters key
  449. //
  450. hr = HrRegQueryDword(hkeyAdapterParams,
  451. strValueName.c_str(), &dwRegValue);
  452. if (SUCCEEDED(hr))
  453. {
  454. // goto the ValueType line
  455. hr = HrSetupFindFirstLine(hInf, pszAdapterSection,
  456. c_szKeyValueType, &ic);
  457. if (S_OK == hr)
  458. {
  459. // move the context from the ValueType line to
  460. // the next line, where values begin
  461. hr = HrSetupFindNextLine(ic, &ic);
  462. }
  463. while (S_OK == hr)
  464. {
  465. // now enumerate over all keys in this section and
  466. // try to locate the key with dwRegValue in the infmap
  467. hr = HrSetupGetIntField(ic, 1, (int*) &dwInfValue);
  468. if ((S_OK == hr) && (dwRegValue == dwInfValue))
  469. {
  470. // value matches, now find the key name
  471. hr = HrSetupGetStringField(ic, 0, pstrNT5InfId);
  472. if (S_OK == hr)
  473. {
  474. // the key name (NT5 infid)
  475. // is returned in pstrNT5InfId
  476. break;
  477. }
  478. }
  479. hr = HrSetupFindNextLine(ic, &ic);
  480. }
  481. }
  482. else if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
  483. {
  484. hr = HrSetupFindKeyWithStringValue(hInf, pszAdapterSection,
  485. c_szValueNotPresent,
  486. pstrNT5InfId);
  487. }
  488. break;
  489. case REG_SZ:
  490. // find the value in under adapter driver parameters key
  491. //
  492. hr = HrRegQueryString(hkeyAdapterParams,
  493. strValueName.c_str(), &strRegValue);
  494. if (SUCCEEDED(hr))
  495. {
  496. // goto the ValueType line
  497. hr = HrSetupFindFirstLine(hInf, pszAdapterSection,
  498. c_szKeyValueType, &ic);
  499. if (S_OK == hr)
  500. {
  501. // move the context from the ValueType line to
  502. // the next line, where values begin
  503. hr = HrSetupFindNextLine(ic, &ic);
  504. }
  505. while (S_OK == hr)
  506. {
  507. // now enumerate over all keys in this section and
  508. // try to locate the key with dwRegValue in the infmap
  509. hr = HrSetupGetStringField(ic, 1, &strInfValue);
  510. if ((S_OK == hr) &&
  511. !lstrcmpiW(strRegValue.c_str(), strInfValue.c_str()))
  512. {
  513. // value matches, now find the key name
  514. hr = HrSetupGetStringField(ic, 0, pstrNT5InfId);
  515. if (S_OK == hr)
  516. {
  517. // the key name (NT5 infid)
  518. // is returned in pstrNT5InfId
  519. break;
  520. }
  521. }
  522. hr = HrSetupFindNextLine(ic, &ic);
  523. }
  524. }
  525. else if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
  526. {
  527. hr = HrSetupFindKeyWithStringValue(hInf, pszAdapterSection,
  528. c_szValueNotPresent,
  529. pstrNT5InfId);
  530. }
  531. break;
  532. default:
  533. hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  534. // currently we support only REG_DWORD and REG_SZ type values
  535. TraceTag(ttidError, "%s: ValueType %d is not supported",
  536. __FUNCNAME__, dwValueType);
  537. break;
  538. }
  539. }
  540. }
  541. TraceError(__FUNCNAME__, hr);
  542. return hr;
  543. }
  544. // ----------------------------------------------------------------------
  545. //
  546. // Function: HrMapPreNT5NetComponentInfIDUsingInfHelper
  547. //
  548. // Purpose:
  549. //
  550. // Arguments:
  551. // hinf [in] handle of netmap.inf file
  552. // pszOldInfID [in] pre NT5 InfID
  553. // pszMSSection [in] section having MS components
  554. // pszOemSection [in] section having OEM components
  555. // pstrNT5InfId [out] mapped NT5 InfID
  556. // pfOemComponent [out] set to TRUE for OEM component
  557. //
  558. // Returns: S_OK on success,
  559. // S_FALSE if a mapping is not found
  560. // otherwise an error code
  561. //
  562. // Author: kumarp 17-December-97
  563. //
  564. // Notes:
  565. //
  566. HRESULT HrMapPreNT5NetComponentInfIDUsingInfHelper(IN HINF hinf,
  567. IN PCWSTR pszOldInfID,
  568. IN PCWSTR pszMSSection,
  569. IN PCWSTR pszOemSection,
  570. OUT tstring* pstrNT5InfId,
  571. OUT BOOL* pfOemComponent)
  572. {
  573. DefineFunctionName("HrMapPreNT5NetComponentInfIDUsingInfHelper");
  574. Assert(hinf);
  575. AssertValidReadPtr(pszOldInfID);
  576. AssertValidReadPtr(pszMSSection);
  577. AssertValidReadPtr(pszOemSection);
  578. AssertValidWritePtr(pstrNT5InfId);
  579. AssertValidWritePtr(pfOemComponent);
  580. HRESULT hr=S_FALSE;
  581. INFCONTEXT ic;
  582. hr = HrSetupFindFirstLine(hinf, pszMSSection, pszOldInfID, &ic);
  583. if (S_OK == hr)
  584. {
  585. *pfOemComponent = FALSE;
  586. }
  587. else
  588. {
  589. hr = HrSetupFindFirstLine(hinf, pszOemSection, pszOldInfID, &ic);
  590. if (S_OK == hr)
  591. {
  592. *pfOemComponent = TRUE;
  593. }
  594. }
  595. if (S_OK == hr)
  596. {
  597. hr = HrSetupGetStringField(ic, 1, pstrNT5InfId);
  598. if (S_OK == hr)
  599. {
  600. if (*pfOemComponent)
  601. {
  602. tstring strOemDll;
  603. tstring strOemInf;
  604. HRESULT hrT;
  605. hrT = HrGetOemUpgradeInfoInInf(hinf,
  606. pstrNT5InfId->c_str(),
  607. &strOemDll, &strOemInf);
  608. if ((S_OK == hrT) &&
  609. !lstrcmpiW(strOemDll.c_str(), c_szNotSupported))
  610. {
  611. TraceTag(ttidNetUpgrade, "%s: %S --> %S",__FUNCNAME__,
  612. pszOldInfID, c_szNotSupported);
  613. hr = S_FALSE;
  614. }
  615. }
  616. }
  617. }
  618. else if (HRESULT_FROM_SETUPAPI(ERROR_LINE_NOT_FOUND) == hr)
  619. {
  620. hr = S_FALSE;
  621. }
  622. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  623. return hr;
  624. }
  625. // ----------------------------------------------------------------------
  626. //
  627. // Function: HrMapPreNT5NetComponentInfIDInInf
  628. //
  629. // Purpose: Search the specified netmap.inf file for mapping
  630. // the specified pre-NT5 InfID of a s/w component to its NT5 value
  631. //
  632. // Arguments:
  633. // hinf [in] handle of netmap.inf file
  634. // pszOldInfID [in] pre-NT5 InfID
  635. // pstrNT5InfId [out] mapped ID
  636. // pfOemComponent [out] set to TRUE for OEM component
  637. //
  638. // Returns: S_OK on success,
  639. // S_FALSE if a mapping is not found
  640. // otherwise an error code
  641. //
  642. // Author: kumarp 17-December-97
  643. //
  644. // Notes:
  645. //
  646. HRESULT HrMapPreNT5NetComponentInfIDInInf(IN HINF hinf,
  647. IN PCWSTR pszOldInfID,
  648. OUT tstring* pstrNT5InfId,
  649. OUT ENetComponentType* pnct,
  650. OUT BOOL* pfOemComponent)
  651. {
  652. DefineFunctionName("HrMapPreNT5NetComponentInfIDUsingInf");
  653. Assert(hinf);
  654. AssertValidReadPtr(pszOldInfID);
  655. AssertValidWritePtr(pstrNT5InfId);
  656. AssertValidWritePtr(pfOemComponent);
  657. HRESULT hr=S_FALSE;
  658. ENetComponentType nct = NCT_Unknown;
  659. hr = HrMapPreNT5NetComponentInfIDUsingInfHelper(hinf, pszOldInfID,
  660. c_szNetProtocols,
  661. c_szOemNetProtocols,
  662. pstrNT5InfId,
  663. pfOemComponent);
  664. if (S_OK == hr)
  665. {
  666. nct = NCT_Protocol;
  667. }
  668. else
  669. {
  670. hr = HrMapPreNT5NetComponentInfIDUsingInfHelper(hinf, pszOldInfID,
  671. c_szNetServices,
  672. c_szOemNetServices,
  673. pstrNT5InfId,
  674. pfOemComponent);
  675. if (S_OK == hr)
  676. {
  677. nct = NCT_Service;
  678. }
  679. else
  680. {
  681. hr = HrMapPreNT5NetComponentInfIDUsingInfHelper(hinf, pszOldInfID,
  682. c_szNetClients,
  683. c_szOemNetClients,
  684. pstrNT5InfId,
  685. pfOemComponent);
  686. if (S_OK == hr)
  687. {
  688. nct = NCT_Client;
  689. }
  690. }
  691. }
  692. if ((S_OK == hr) && pnct)
  693. {
  694. *pnct = nct;
  695. }
  696. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  697. return hr;
  698. }
  699. // ----------------------------------------------------------------------
  700. //
  701. // Function: HrMapPreNT5NetComponentInfIDToNT5InfID
  702. //
  703. // Purpose: maps pre-NT5 InfID of a service or protocol to its NT5 equivalent
  704. //
  705. // Arguments:
  706. // pszPreNT5InfId [in] pre-NT5 InfID
  707. // pstrNT5InfId [out] mapped ID
  708. // pfOemComponent [out] set to TRUE for OEM component
  709. // pdwNetMapIndex [out] the index in netmap array for which map was found
  710. //
  711. // Returns: S_OK on success,
  712. // S_FALSE if a mapping is not found
  713. // otherwise an error code
  714. //
  715. // Author: kumarp 17-December-97
  716. //
  717. // Notes:
  718. //
  719. HRESULT HrMapPreNT5NetComponentInfIDToNT5InfID(IN PCWSTR pszPreNT5InfId,
  720. OUT tstring* pstrNT5InfId,
  721. OUT BOOL* pfOemComponent,
  722. OUT ENetComponentType* pnct,
  723. OUT CNetMapInfo** ppnmi)
  724. {
  725. DefineFunctionName("HrMapPreNT5NetComponentInfIDToNT5InfID");
  726. AssertValidReadPtr(pszPreNT5InfId);
  727. AssertValidWritePtr(pstrNT5InfId);
  728. AssertValidReadPtr(g_pnmaNetMap);
  729. HRESULT hr=E_FAIL;
  730. TraceTag(ttidNetUpgrade, "finding mapping for %S...", pszPreNT5InfId);
  731. if (g_pnmaNetMap)
  732. {
  733. CNetMapInfo* pnmi;
  734. size_t cNumNetMapEntries = g_pnmaNetMap->size();
  735. for (size_t i = 0; i < cNumNetMapEntries; i++)
  736. {
  737. pnmi = (CNetMapInfo*) (*g_pnmaNetMap)[i];
  738. hr = HrMapPreNT5NetComponentInfIDInInf(pnmi->m_hinfNetMap,
  739. pszPreNT5InfId,
  740. pstrNT5InfId,
  741. pnct,
  742. pfOemComponent);
  743. if (SUCCEEDED(hr))
  744. {
  745. if (ppnmi)
  746. {
  747. *ppnmi = pnmi;
  748. }
  749. if (S_OK == hr)
  750. {
  751. TraceTag(ttidNetUpgrade, "%s: %S --> %S", __FUNCNAME__,
  752. pszPreNT5InfId, pstrNT5InfId->c_str());
  753. break;
  754. }
  755. }
  756. }
  757. }
  758. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  759. return hr;
  760. }
  761. // ----------------------------------------------------------------------
  762. //
  763. // Function: HrGetSoftwareProductKey
  764. //
  765. // Purpose: Get handle to registry key for a software product of a provider
  766. //
  767. // Arguments:
  768. // pszProvider [in] name of provider
  769. // pszProduct [in] name of product
  770. // phkey [out] pointer to handle of regkey
  771. //
  772. // Returns: S_OK on success, otherwise an error code
  773. //
  774. // Author: kumarp 17-December-97
  775. //
  776. // Notes:
  777. //
  778. HRESULT HrGetSoftwareProductKey(IN PCWSTR pszProvider,
  779. IN PCWSTR pszProduct,
  780. OUT HKEY* phkey)
  781. {
  782. DefineFunctionName("HrGetSoftwareProductKey");
  783. AssertValidReadPtr(pszProvider);
  784. AssertValidReadPtr(pszProduct);
  785. AssertValidWritePtr(phkey);
  786. HRESULT hr=S_OK;
  787. tstring strProduct;
  788. strProduct = c_szRegKeySoftware;
  789. AppendToPath(&strProduct, pszProvider);
  790. AppendToPath(&strProduct, pszProduct);
  791. AppendToPath(&strProduct, c_szRegKeyCurrentVersion);
  792. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, strProduct.c_str(),
  793. KEY_READ, phkey);
  794. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  795. return hr;
  796. }
  797. // ----------------------------------------------------------------------
  798. //
  799. // Function: HrMapPreNT5NetComponentServiceNameToNT5InfId
  800. //
  801. // Purpose: Map pre-NT5 InfID of a service to its NT5 value
  802. //
  803. // Arguments:
  804. // pszServiceName [in] name of service
  805. // pstrNT5InfId [out] mapped ID
  806. //
  807. // Returns: S_OK on success,
  808. // S_FALSE if a mapping is not found
  809. // otherwise an error code
  810. //
  811. // Author: kumarp 17-December-97
  812. //
  813. // Notes:
  814. //
  815. HRESULT HrMapPreNT5NetComponentServiceNameToNT5InfId(IN PCWSTR pszServiceName,
  816. OUT tstring* pstrNT5InfId)
  817. {
  818. DefineFunctionName("HrMapPreNT5NetComponentServiceNameToNT5InfId");
  819. AssertValidReadPtr(pszServiceName);
  820. AssertValidWritePtr(pstrNT5InfId);
  821. tstring strPreNT5InfId;
  822. HKEY hkey;
  823. HRESULT hr=S_OK;
  824. hr = HrGetSoftwareProductKey(c_szRegKeyMicrosoft, pszServiceName, &hkey);
  825. if (S_OK == hr)
  826. {
  827. hr = HrGetPreNT5InfIdAndDesc(hkey, &strPreNT5InfId, NULL, NULL);
  828. if (S_OK == hr)
  829. {
  830. BOOL fIsOemComponent;
  831. hr = HrMapPreNT5NetComponentInfIDToNT5InfID(strPreNT5InfId.c_str(),
  832. pstrNT5InfId,
  833. &fIsOemComponent, NULL,
  834. NULL);
  835. #ifdef ENABLETRACE
  836. if (FAILED(hr))
  837. {
  838. TraceTag(ttidNetUpgrade, "%s: could not map %S to NT5 InfID",
  839. __FUNCNAME__, pszServiceName);
  840. }
  841. #endif
  842. }
  843. RegCloseKey(hkey);
  844. }
  845. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  846. return hr;
  847. }
  848. // ----------------------------------------------------------------------
  849. //
  850. // Function: HrGetOemUpgradeInfoInInf
  851. //
  852. // Purpose: Find out which OEM DLL to load for a component
  853. //
  854. // Arguments:
  855. // hinf [in] handle of netmap.inf file
  856. // pszNT5InfId [in] NT5 InfID of a component
  857. // pstrUpgradeDllName [out] name of the upgrade DLL found
  858. // pstrInf [out] INF file for this component
  859. //
  860. // Returns: S_OK on success, otherwise an error code
  861. //
  862. // Author: kumarp 17-December-97
  863. //
  864. // Notes:
  865. //
  866. HRESULT HrGetOemUpgradeInfoInInf(IN HINF hinf,
  867. IN PCWSTR pszNT5InfId,
  868. OUT tstring* pstrUpgradeDllName,
  869. OUT tstring* pstrInf)
  870. {
  871. DefineFunctionName("HrGetOemUpgradeInfoInInf");
  872. Assert(hinf);
  873. AssertValidReadPtr(pszNT5InfId);
  874. AssertValidWritePtr(pstrUpgradeDllName);
  875. AssertValidWritePtr(pstrInf);
  876. HRESULT hr=S_FALSE;
  877. INFCONTEXT ic;
  878. pstrUpgradeDllName->erase();
  879. pstrInf->erase();
  880. // each line in this section is of the format
  881. // <NT5-InfId>=<oem-upgrade-dll-name>[,<inf-file-name>]
  882. hr = HrSetupFindFirstLine(hinf, c_szOemUpgradeSupport,
  883. pszNT5InfId, &ic);
  884. if (S_OK == hr)
  885. {
  886. hr = HrSetupGetStringField(ic, 1, pstrUpgradeDllName);
  887. if (S_OK == hr)
  888. {
  889. // the value OemInfFile is optional, so we dont
  890. // complain if we cannot find it.
  891. if (HRESULT_FROM_SETUPAPI(ERROR_INVALID_PARAMETER)
  892. == HrSetupGetStringField(ic, 2, pstrInf))
  893. {
  894. TraceTag(ttidNetUpgrade, "%s: OemInf is not specified for %S",
  895. __FUNCNAME__, pszNT5InfId);
  896. }
  897. }
  898. }
  899. TraceTag(ttidNetUpgrade, "%s: OemDll: %S, OemInf: %S",
  900. __FUNCNAME__, pstrUpgradeDllName->c_str(), pstrInf->c_str());
  901. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  902. return hr;
  903. }
  904. // ----------------------------------------------------------------------
  905. //
  906. // Function: HrGetOemUpgradeDllInfo
  907. //
  908. // Purpose: Find out which OEM DLL to load for a component
  909. //
  910. // Arguments:
  911. // pszNT5InfId [in] InfID of OEM component
  912. // pstrUpgradeDllName [out] name of OEM DLL found
  913. //
  914. // Returns: S_OK on success, otherwise an error code
  915. //
  916. // Author: kumarp 17-December-97
  917. //
  918. // Notes:
  919. //
  920. HRESULT HrGetOemUpgradeInfo(IN PCWSTR pszNT5InfId,
  921. OUT tstring* pstrUpgradeDllName,
  922. OUT tstring* pstrInf)
  923. {
  924. DefineFunctionName("HrGetOemUpgradeInfo");
  925. AssertValidReadPtr(pszNT5InfId);
  926. AssertValidWritePtr(pstrUpgradeDllName);
  927. Assert(g_pnmaNetMap);
  928. HRESULT hr=E_FAIL;
  929. TraceTag(ttidNetUpgrade, "finding upgrade dll info for %S...",
  930. pszNT5InfId);
  931. if (g_pnmaNetMap)
  932. {
  933. CNetMapInfo* pnmi;
  934. size_t cNumNetMapEntries = g_pnmaNetMap->size();
  935. for (size_t i = 0; i < cNumNetMapEntries; i++)
  936. {
  937. pnmi = (CNetMapInfo*) (*g_pnmaNetMap)[i];
  938. hr = HrGetOemUpgradeInfoInInf(pnmi->m_hinfNetMap, pszNT5InfId,
  939. pstrUpgradeDllName, pstrInf);
  940. if (S_OK == hr)
  941. {
  942. TraceTag(ttidNetUpgrade, "%s: %S --> Dll: %S, Inf: %S",
  943. __FUNCNAME__, pszNT5InfId,
  944. pstrUpgradeDllName->c_str(),
  945. pstrInf->c_str());
  946. break;
  947. }
  948. }
  949. }
  950. TraceErrorOptional(__FUNCNAME__, hr, (hr == S_FALSE));
  951. return hr;
  952. }
  953. // ----------------------------------------------------------------------
  954. //
  955. // Function: HrSetupFindKeyWithStringValue
  956. //
  957. // Purpose: Find the key in a section that has the specified value
  958. //
  959. // Arguments:
  960. // hInf [in] handle of netmap.inf file
  961. // szSection [in] name of section
  962. // szValue [in] value to find
  963. // pstrKey [out] name of the key found
  964. //
  965. // Returns: S_OK on success, otherwise an error code
  966. //
  967. // Author: kumarp 17-December-97
  968. //
  969. // Notes:
  970. //
  971. HRESULT HrSetupFindKeyWithStringValue(IN HINF hInf,
  972. IN PCWSTR szSection,
  973. IN PCWSTR szValue,
  974. OUT tstring* pstrKey)
  975. {
  976. DefineFunctionName("HrSetupFindKeyWithStringValue");
  977. HRESULT hr=S_OK;
  978. INFCONTEXT ic;
  979. tstring strValue;
  980. hr = HrSetupFindFirstLine(hInf, szSection, NULL, &ic);
  981. while (S_OK == hr)
  982. {
  983. // now enumerate over all keys in this section and
  984. // try to locate the key with value szValue
  985. hr = HrSetupGetStringField(ic, 1, &strValue);
  986. if ((S_OK == hr) && !lstrcmpiW(strValue.c_str(), szValue))
  987. {
  988. // value matches, now find the key name
  989. hr = HrSetupGetStringField(ic, 0, pstrKey);
  990. break;
  991. }
  992. hr = HrSetupFindNextLine(ic, &ic);
  993. }
  994. if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  995. {
  996. hr = S_FALSE;
  997. }
  998. TraceError(__FUNCNAME__, hr);
  999. return hr;
  1000. }