Source code of Windows XP (NT5)
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.

311 lines
6.7 KiB

  1. // Nbfobj.cpp : Implementation of CNbfObj
  2. #include "pch.h"
  3. #pragma hdrstop
  4. #include "nbfobj.h"
  5. #include "ncsvc.h"
  6. static const WCHAR c_szNbfServiceName[] = L"Nbf";
  7. /////////////////////////////////////////////////////////////////////////////
  8. //
  9. //
  10. // Function: CNbfObj::CNbfObj
  11. //
  12. // Purpose: ctor for the CNbfObj class
  13. //
  14. // Parameters: none
  15. //
  16. // Returns: none
  17. //
  18. CNbfObj::CNbfObj() : m_pNetCfg(NULL),
  19. m_pNCC(NULL),
  20. m_fFirstTimeInstall(FALSE),
  21. m_eNBFState(eStateNoChange),
  22. m_eInstallAction(eActConfig)
  23. {
  24. }
  25. //
  26. // Function: CNbfObj::CNbfObj
  27. //
  28. // Purpose: dtor for the CNbfObj class
  29. //
  30. // Parameters: none
  31. //
  32. // Returns: none
  33. //
  34. CNbfObj::~CNbfObj()
  35. {
  36. ReleaseObj(m_pNetCfg);
  37. ReleaseObj(m_pNCC);
  38. }
  39. // INetCfgNotify
  40. STDMETHODIMP CNbfObj::Initialize ( INetCfgComponent* pnccItem,
  41. INetCfg* pNetCfg, BOOL fInstalling )
  42. {
  43. Validate_INetCfgNotify_Initialize(pnccItem, pNetCfg, fInstalling);
  44. ReleaseObj(m_pNCC);
  45. m_pNCC = pnccItem;
  46. AddRefObj(m_pNCC);
  47. ReleaseObj(m_pNetCfg);
  48. m_pNetCfg = pNetCfg;
  49. AddRefObj(m_pNetCfg);
  50. m_fFirstTimeInstall = fInstalling;
  51. INetCfgComponent* pncc = NULL;
  52. // See if DNS is already installed. If it is we need to be disabled
  53. if (S_OK == pNetCfg->FindComponent( L"MS_DNSServer", &pncc))
  54. {
  55. m_eNBFState = eStateDisable;
  56. ReleaseObj(pncc);
  57. }
  58. return S_OK;
  59. }
  60. STDMETHODIMP CNbfObj::ReadAnswerFile (PCWSTR pszAnswerFile,
  61. PCWSTR pszAnswerSection )
  62. {
  63. Validate_INetCfgNotify_ReadAnswerFile(pszAnswerFile, pszAnswerSection );
  64. return S_OK;
  65. }
  66. STDMETHODIMP CNbfObj::Install (DWORD)
  67. {
  68. m_eInstallAction = eActInstall;
  69. return S_OK;
  70. }
  71. STDMETHODIMP CNbfObj::Removing ()
  72. {
  73. m_eInstallAction = eActRemove;
  74. return S_OK;
  75. }
  76. STDMETHODIMP CNbfObj::Validate ()
  77. {
  78. return S_OK;
  79. }
  80. STDMETHODIMP CNbfObj::CancelChanges ()
  81. {
  82. return S_OK;
  83. }
  84. STDMETHODIMP CNbfObj::ApplyRegistryChanges ()
  85. {
  86. HRESULT hr = S_OK;
  87. switch(m_eInstallAction)
  88. {
  89. case eActInstall:
  90. hr = HrUpdateNetBEUI();
  91. break;
  92. case eActRemove:
  93. hr = S_OK;
  94. break;
  95. default:
  96. // Update NetBEUI's state if necessary
  97. hr = HrUpdateNetBEUI();
  98. break;
  99. }
  100. TraceError("CNbfObj::ApplyRegistryChanges", hr);
  101. return hr;
  102. }
  103. STDMETHODIMP CNbfObj::ApplyPnpChanges (
  104. IN INetCfgPnpReconfigCallback* pICallback )
  105. {
  106. HRESULT hr = S_OK;
  107. CServiceManager sm;
  108. CService service;
  109. // RAID #336321: (danielwe) Query the RemoteAccess service to see if
  110. // it's running and if so, return that a reboot is necessary (assumimg we
  111. // are installing or removing Nbf)
  112. //
  113. hr = sm.HrOpenService(&service, L"RemoteAccess");
  114. if (SUCCEEDED(hr))
  115. {
  116. DWORD dwState;
  117. hr = service.HrQueryState(&dwState);
  118. if (SUCCEEDED(hr) &&
  119. (SERVICE_STOPPED != dwState) && (SERVICE_STOP_PENDING != dwState) &&
  120. ((m_eInstallAction == eActRemove) ||
  121. (m_eInstallAction == eActInstall)))
  122. {
  123. hr = NETCFG_S_REBOOT;
  124. }
  125. }
  126. TraceError("CNbfObj::ApplyPnpChanges", hr);
  127. return hr;
  128. }
  129. // INetCfgSystemNotify
  130. STDMETHODIMP CNbfObj::GetSupportedNotifications (
  131. DWORD* pdwNotificationFlag )
  132. {
  133. Validate_INetCfgSystemNotify_GetSupportedNotifications(pdwNotificationFlag);
  134. // Want to know when DNS comes and goes
  135. *pdwNotificationFlag = NCN_NETSERVICE | NCN_ADD | NCN_REMOVE;
  136. return S_OK;
  137. }
  138. STDMETHODIMP CNbfObj::SysQueryBindingPath ( DWORD dwChangeFlag,
  139. INetCfgBindingPath* pncbpItem )
  140. {
  141. Validate_INetCfgSystemNotify_SysQueryBindingPath(dwChangeFlag,
  142. pncbpItem);
  143. return S_OK;
  144. }
  145. STDMETHODIMP CNbfObj::SysQueryComponent ( DWORD dwChangeFlag,
  146. INetCfgComponent* pnccItem )
  147. {
  148. Validate_INetCfgSystemNotify_SysQueryComponent(dwChangeFlag,
  149. pnccItem);
  150. return S_OK;
  151. }
  152. STDMETHODIMP CNbfObj::SysNotifyBindingPath ( DWORD dwChangeFlag,
  153. INetCfgBindingPath* pncbpItem )
  154. {
  155. Validate_INetCfgSystemNotify_SysNotifyBindingPath(dwChangeFlag,
  156. pncbpItem);
  157. return S_FALSE;
  158. }
  159. STDMETHODIMP CNbfObj::SysNotifyComponent ( DWORD dwChangeFlag,
  160. INetCfgComponent* pnccItem )
  161. {
  162. HRESULT hr;
  163. Validate_INetCfgSystemNotify_SysNotifyComponent(dwChangeFlag, pnccItem);
  164. // Assume we won't be dirty as a result of this notification.
  165. //
  166. hr = S_FALSE;
  167. if (FIsComponentId(L"MS_DnsServer", pnccItem))
  168. {
  169. // Disable/Enable NetBEUI when DNS is Added/Removed
  170. if (dwChangeFlag & NCN_ADD)
  171. {
  172. // Disable NetBEUI, and shutdown NetBEUI
  173. m_eNBFState = eStateDisable;
  174. hr = S_OK;
  175. }
  176. else if (dwChangeFlag & NCN_REMOVE)
  177. {
  178. // Re-enable NetBEUI
  179. m_eNBFState = eStateEnable;
  180. hr = S_OK;
  181. }
  182. }
  183. return hr;
  184. }
  185. //
  186. // Function: CNbfObj::HrEnableNetBEUI
  187. //
  188. // Purpose: Enable NetBEUI
  189. //
  190. // Parameters: none
  191. //
  192. // Returns: HRESULT, S_OK on success
  193. //
  194. HRESULT CNbfObj::HrEnableNetBEUI()
  195. {
  196. HRESULT hr;
  197. CServiceManager sm;
  198. CService srv;
  199. hr = sm.HrOpenService(&srv, c_szNbfServiceName);
  200. if (SUCCEEDED(hr))
  201. {
  202. // Change the Nbf StartType registry setting back to demand_start
  203. hr = srv.HrSetStartType(SERVICE_DEMAND_START);
  204. }
  205. // TODO: LogError any errors
  206. TraceError("CNbfObj::HrEnableNetBEUI",hr);
  207. return hr;
  208. }
  209. //
  210. // Function: CNbfObj::HrDisableNetBEUI
  211. //
  212. // Purpose: Disable NetBEUI and shut down the service if it is running
  213. //
  214. // Parameters: none
  215. //
  216. // Returns: HRESULT, S_OK on success
  217. //
  218. HRESULT CNbfObj::HrDisableNetBEUI()
  219. {
  220. HRESULT hr;
  221. CServiceManager sm;
  222. CService srv;
  223. hr = sm.HrOpenService(&srv, c_szNbfServiceName);
  224. if (SUCCEEDED(hr))
  225. {
  226. // Note: (shaunco) 8 Jan 1998: Need the SCM to be locked.
  227. // Change the Nbf StartType registry setting to disabled
  228. hr = srv.HrSetStartType(SERVICE_DISABLED);
  229. if (SUCCEEDED(hr))
  230. {
  231. hr = sm.HrStopServiceNoWait(c_szNbfServiceName);
  232. }
  233. }
  234. // TODO: LogError any errors
  235. TraceError("CNbfObj::HrDisableNetBEUI",hr);
  236. return hr;
  237. }
  238. //
  239. // Function: CNbfObj::HrUpdateNetBEUI
  240. //
  241. // Purpose: Enable, Disable, or no nothing to NetBEUI
  242. // based on the presence of DNS Server
  243. //
  244. // Parameters: none
  245. //
  246. // Returns: HRESULT, S_OK on success
  247. //
  248. HRESULT CNbfObj::HrUpdateNetBEUI()
  249. {
  250. HRESULT hr = S_OK;
  251. switch(m_eNBFState)
  252. {
  253. case eStateDisable:
  254. hr = HrDisableNetBEUI();
  255. break;
  256. case eStateEnable:
  257. hr = HrEnableNetBEUI();
  258. break;
  259. default:
  260. break;
  261. }
  262. return hr;
  263. }