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.

222 lines
5.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: S A P O B J . C P P
  7. //
  8. // Contents: Implementation of the CSAPCfg notify object
  9. //
  10. // Notes:
  11. //
  12. // Author: jeffspr 31 May 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "sapobj.h"
  18. #include "ncreg.h"
  19. extern const WCHAR c_szInfId_MS_NWIPX[];
  20. extern const WCHAR c_szRegKeyRefCounts[];
  21. extern const WCHAR c_szRegValueComponentId[];
  22. const WCHAR c_szProtoPath[] = L"System\\CurrentControlSet\\Control\\Network\\{4D36E975-E325-11CE-BFC1-08002BE10318}";
  23. const WCHAR c_szOcSapRef[] = L"%Msft%nwsapagent";
  24. CSAPCfg::CSAPCfg()
  25. {
  26. m_pnc = NULL;
  27. m_pncc = NULL;
  28. }
  29. CSAPCfg::~CSAPCfg()
  30. {
  31. ReleaseObj(m_pncc);
  32. ReleaseObj(m_pnc);
  33. }
  34. STDMETHODIMP
  35. CSAPCfg::Initialize (
  36. INetCfgComponent* pnccItem,
  37. INetCfg* pnc,
  38. BOOL fInstalling)
  39. {
  40. Validate_INetCfgNotify_Initialize(pnccItem, pnc, fInstalling);
  41. m_pncc = pnccItem;
  42. m_pnc = pnc;
  43. AssertSz(m_pncc, "m_pncc NULL in CSAPCfg::Initialize");
  44. AssertSz(m_pnc, "m_pnc NULL in CSAPCfg::Initialize");
  45. // Addref the config objects
  46. //
  47. AddRefObj(m_pncc);
  48. AddRefObj(m_pnc);
  49. return S_OK;
  50. }
  51. STDMETHODIMP
  52. CSAPCfg::Validate()
  53. {
  54. return S_OK;
  55. }
  56. STDMETHODIMP
  57. CSAPCfg::CancelChanges()
  58. {
  59. return S_OK;
  60. }
  61. STDMETHODIMP
  62. CSAPCfg::ApplyRegistryChanges()
  63. {
  64. return S_OK;
  65. }
  66. STDMETHODIMP
  67. CSAPCfg::ReadAnswerFile (
  68. PCWSTR pszAnswerFile,
  69. PCWSTR pszAnswerSection)
  70. {
  71. return S_OK;
  72. }
  73. STDMETHODIMP
  74. CSAPCfg::Upgrade(DWORD, DWORD)
  75. {
  76. // Raid 266650 - Need to clean up the registry as in Beta 2 SAP was an optional component.
  77. // Cleanup is done by deleting the NetOC OBO Install ref-count on IPX.
  78. //
  79. HRESULT hr;
  80. HKEY hkeyProto;
  81. // Open the protocol list
  82. //
  83. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szProtoPath, KEY_ALL_ACCESS, &hkeyProto);
  84. if (SUCCEEDED(hr))
  85. {
  86. BOOL fDone = FALSE;
  87. WCHAR szValueName [_MAX_PATH];
  88. DWORD cchBuffSize = _MAX_PATH;
  89. FILETIME ft;
  90. DWORD dwKeyIndex = 0;
  91. // Enum the keys children, search for ms_nwipx
  92. //
  93. while (SUCCEEDED(hr = HrRegEnumKeyEx(hkeyProto, dwKeyIndex, szValueName,
  94. &cchBuffSize, NULL, NULL, &ft)) &&
  95. !fDone)
  96. {
  97. HKEY hkeyComponent;
  98. // Open the key that was enumerated
  99. //
  100. hr = HrRegOpenKeyEx(hkeyProto, szValueName, KEY_ALL_ACCESS, &hkeyComponent);
  101. if (SUCCEEDED(hr))
  102. {
  103. tstring str;
  104. // Is this ms_nwipx?
  105. //
  106. hr = HrRegQueryString(hkeyComponent, c_szRegValueComponentId, &str);
  107. if (SUCCEEDED(hr) && (0 == _wcsicmp(str.c_str(), c_szInfId_MS_NWIPX)))
  108. {
  109. HKEY hkeyRefCounts;
  110. // Open the "RefCounts" subkey
  111. //
  112. hr = HrRegOpenKeyEx(hkeyComponent, c_szRegKeyRefCounts,
  113. KEY_ALL_ACCESS, &hkeyRefCounts);
  114. if (SUCCEEDED(hr))
  115. {
  116. // Enumerate the values under here searching for %Msft%nwsapagent
  117. //
  118. for (DWORD dwIndex = 0; SUCCEEDED(hr); dwIndex++)
  119. {
  120. WCHAR pszValueName [_MAX_PATH];
  121. DWORD cchValueName = celems (pszValueName);
  122. DWORD dwType;
  123. DWORD dwRefCount = 0;
  124. DWORD cbData = sizeof (dwRefCount);
  125. hr = HrRegEnumValue (hkeyRefCounts, dwIndex,
  126. pszValueName, &cchValueName,
  127. &dwType, (LPBYTE)&dwRefCount, &cbData);
  128. if (SUCCEEDED(hr) && (0 == _wcsicmp(pszValueName, c_szOcSapRef)))
  129. {
  130. // Delete the value and exit the loop
  131. //
  132. hr = HrRegDeleteValue (hkeyRefCounts, pszValueName);
  133. break;
  134. }
  135. }
  136. RegCloseKey(hkeyRefCounts);
  137. }
  138. fDone = TRUE;
  139. }
  140. RegCloseKey(hkeyComponent);
  141. }
  142. cchBuffSize = _MAX_PATH;
  143. dwKeyIndex++;
  144. }
  145. if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  146. {
  147. hr = S_OK;
  148. }
  149. RegCloseKey(hkeyProto);
  150. }
  151. return S_OK;
  152. }
  153. STDMETHODIMP
  154. CSAPCfg::Install (
  155. DWORD dw)
  156. {
  157. Validate_INetCfgNotify_Install(dw);
  158. // Install IPX
  159. //
  160. HRESULT hr = HrInstallComponentOboComponent(m_pnc, NULL,
  161. GUID_DEVCLASS_NETTRANS,
  162. c_szInfId_MS_NWIPX,
  163. m_pncc, NULL);
  164. TraceError("CSAPCfg::Install", hr);
  165. return hr;
  166. }
  167. STDMETHODIMP
  168. CSAPCfg::Removing()
  169. {
  170. // Remove IPX
  171. //
  172. HRESULT hr = HrRemoveComponentOboComponent (m_pnc,
  173. GUID_DEVCLASS_NETTRANS,
  174. c_szInfId_MS_NWIPX,
  175. m_pncc);
  176. // Normalize the HRESULT. (NETCFG_S_STILL_REFERENCED or NETCFG_S_REBOOT
  177. // may have been returned.)
  178. if (SUCCEEDED(hr))
  179. {
  180. hr = S_OK;
  181. }
  182. Validate_INetCfgNotify_Removing_Return (hr);
  183. TraceError ("CSAPCfg::Removing", hr);
  184. return hr;
  185. }