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.

216 lines
5.6 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include <ncxbase.h>
  4. #include "ncreg.h"
  5. #include "nwlnkipx.h"
  6. #define ChLowX L'x'
  7. #define ChUpX L'X'
  8. //
  9. // Function: FIsNetwareIpxInstalled
  10. //
  11. // Purpose: Check for the existance of the IPXSPSII key in the
  12. // HKLM\SYSTEM\...\Services hive
  13. //
  14. BOOL FIsNetwareIpxInstalled(
  15. VOID)
  16. {
  17. HRESULT hr;
  18. HKEY hkey;
  19. BOOL fRet;
  20. fRet = FALSE;
  21. hr = HrRegOpenKeyEx(
  22. HKEY_LOCAL_MACHINE,
  23. L"SYSTEM\\CurrentControlSet\\Services\\IPXSPXII",
  24. KEY_READ,
  25. &hkey);
  26. if (S_OK == hr)
  27. {
  28. fRet = TRUE;
  29. RegCloseKey(hkey);
  30. }
  31. return fRet;
  32. }
  33. DWORD DwFromSz(PCWSTR sz, int nBase)
  34. {
  35. PCWSTR psz = sz;
  36. WCHAR *pszStop;
  37. WCHAR szBuf[12];
  38. Assert(NULL != psz);
  39. if ((16 == nBase) && (ChLowX != sz[1]) && (ChUpX != sz[1]))
  40. {
  41. psz = szBuf;
  42. wcscpy(szBuf,L"0x");
  43. wcsncpy(szBuf+2, sz, 8);
  44. szBuf[10]=L'\0';
  45. }
  46. return wcstoul(psz, &pszStop, nBase);
  47. }
  48. DWORD DwFromLstPtstring(const list<tstring *> & lstpstr, DWORD dwDefault,
  49. int nBase)
  50. {
  51. if (lstpstr.empty())
  52. return dwDefault;
  53. else
  54. return DwFromSz(lstpstr.front()->c_str(), nBase);
  55. }
  56. void UpdateLstPtstring(TSTRING_LIST & lstpstr, DWORD dw)
  57. {
  58. WCHAR szBuf[12];
  59. DeleteColString(&lstpstr);
  60. // Stringize the supplied dword as a hex with no "0x" prefix
  61. wsprintfW(szBuf,L"%0.8lX",dw);
  62. // Set as first item in the list
  63. lstpstr.push_front(new tstring(szBuf));
  64. }
  65. // Apply our special Hex Format to a DWORD. Assumes adequately sized 'sz'
  66. void HexSzFromDw(PWSTR sz, DWORD dw)
  67. {
  68. wsprintfW(sz,L"%0.8lX",dw);
  69. }
  70. HRESULT HrQueryAdapterComponentInfo(INetCfgComponent *pncc,
  71. CIpxAdapterInfo * pAI)
  72. {
  73. HRESULT hr;
  74. PWSTR pszwDesc = NULL;
  75. PWSTR pszwBindName = NULL;
  76. DWORD dwCharacteristics = 0L;
  77. Assert(NULL != pAI);
  78. Assert(NULL != pncc);
  79. // Get Description
  80. hr = pncc->GetDisplayName(&pszwDesc);
  81. if (FAILED(hr))
  82. goto Error;
  83. if (*pszwDesc)
  84. pAI->SetAdapterDesc(pszwDesc);
  85. else
  86. pAI->SetAdapterDesc(SzLoadIds(IDS_UNKNOWN_NETWORK_CARD));
  87. CoTaskMemFree(pszwDesc);
  88. // Get the Component's Instance Guid
  89. hr = pncc->GetInstanceGuid(pAI->PInstanceGuid());
  90. if (S_OK != hr)
  91. goto Error;
  92. // Get the Component's Bind Name
  93. hr = pncc->GetBindName(&pszwBindName);
  94. if (S_OK != hr)
  95. goto Error;
  96. Assert(NULL != pszwBindName);
  97. Assert(0 != lstrlenW(pszwBindName));
  98. pAI->SetBindName(pszwBindName);
  99. CoTaskMemFree(pszwBindName);
  100. // Failure is non-fatal
  101. hr = pncc->GetCharacteristics(&dwCharacteristics);
  102. if (SUCCEEDED(hr))
  103. {
  104. pAI->SetCharacteristics(dwCharacteristics);
  105. }
  106. // Get the media type (Optional key)
  107. {
  108. DWORD dwMediaType = ETHERNET_MEDIA;
  109. INetCfgComponentBindings* pnccBindings = NULL;
  110. hr = pncc->QueryInterface(IID_INetCfgComponentBindings,
  111. reinterpret_cast<void**>(&pnccBindings));
  112. if (SUCCEEDED(hr))
  113. {
  114. struct
  115. {
  116. PCWSTR pszInterface;
  117. DWORD dwInterface;
  118. } InterfaceMap[] = {{L"ethernet", ETHERNET_MEDIA},
  119. {L"tokenring", TOKEN_MEDIA},
  120. {L"arcnet", ARCNET_MEDIA},
  121. {L"fddi", FDDI_MEDIA}};
  122. for (UINT nIdx=0; nIdx < celems(InterfaceMap); nIdx++)
  123. {
  124. hr = pnccBindings->SupportsBindingInterface(NCF_LOWER,
  125. InterfaceMap[nIdx].pszInterface);
  126. if (S_OK == hr)
  127. {
  128. dwMediaType = InterfaceMap[nIdx].dwInterface;
  129. break;
  130. }
  131. }
  132. ReleaseObj(pnccBindings);
  133. }
  134. pAI->SetMediaType(dwMediaType);
  135. hr = S_OK;
  136. }
  137. Error:
  138. TraceError("HrQueryAdapterComponentInfo",hr);
  139. return hr;
  140. }
  141. // Note: Can successfully return *ppncc = NULL
  142. HRESULT HrAnswerFileAdapterToPNCC(INetCfg *pnc, PCWSTR szAdapterId,
  143. INetCfgComponent** ppncc)
  144. {
  145. GUID guidAdapter;
  146. GUID guidInstance;
  147. HRESULT hr = S_FALSE; // assume we don't find it.
  148. Assert(NULL != szAdapterId);
  149. Assert(NULL != ppncc);
  150. Assert(lstrlenW(szAdapterId));
  151. *ppncc = NULL;
  152. // Get the Instance ID for the specified adapter
  153. if (FGetInstanceGuidOfComponentInAnswerFile(szAdapterId,
  154. pnc, &guidAdapter))
  155. {
  156. // Search for the specified adapter in the set of existing adapters
  157. CIterNetCfgComponent nccIter(pnc, &GUID_DEVCLASS_NET);
  158. INetCfgComponent* pncc;
  159. while (SUCCEEDED(hr) &&
  160. (S_OK == (hr = nccIter.HrNext (&pncc))))
  161. {
  162. hr = pncc->GetInstanceGuid(&guidInstance);
  163. if (SUCCEEDED(hr))
  164. {
  165. if (guidInstance == guidAdapter)
  166. {
  167. // Found the adapter. Transfer ownership and get out.
  168. *ppncc = pncc;
  169. break;
  170. }
  171. }
  172. ReleaseObj(pncc);
  173. }
  174. }
  175. TraceError("HrAnswerFileAdapterToPNCC", (S_FALSE == hr) ? S_OK : hr);
  176. return hr;
  177. }