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.

249 lines
5.6 KiB

  1. // nwlnknb.cpp : Implementation of CNwlnkNB
  2. #include "pch.h"
  3. #pragma hdrstop
  4. #include <ncxbase.h>
  5. #include "ncreg.h"
  6. #include "ncsvc.h"
  7. #include "nwlnknb.h"
  8. #include "nwlnkipx.h"
  9. CNwlnkNB::CNwlnkNB() :
  10. m_pnccMe(NULL),
  11. m_pNetCfg(NULL),
  12. m_eInstallAction(eActUnknown),
  13. m_eNbState(eStateNoChange)
  14. {
  15. }
  16. CNwlnkNB::~CNwlnkNB()
  17. {
  18. ReleaseObj(m_pNetCfg);
  19. ReleaseObj(m_pnccMe);
  20. }
  21. // INetCfgNotify
  22. STDMETHODIMP CNwlnkNB::Initialize (
  23. INetCfgComponent* pncc,
  24. INetCfg* pNetCfg,
  25. BOOL fInstalling)
  26. {
  27. Validate_INetCfgNotify_Initialize(pncc, pNetCfg, fInstalling);
  28. // Hold on to our the component representing us and our host
  29. // INetCfg object.
  30. AddRefObj (m_pnccMe = pncc);
  31. AddRefObj (m_pNetCfg = pNetCfg);
  32. // See if DNS is already installed. If it is we need to be disabled
  33. if (fInstalling &&
  34. (S_OK == m_pNetCfg->FindComponent(L"MS_DNSServer", NULL)))
  35. {
  36. m_eNbState = eStateDisable;
  37. }
  38. return S_OK;
  39. }
  40. STDMETHODIMP CNwlnkNB::ReadAnswerFile (
  41. PCWSTR pszAnswerFile,
  42. PCWSTR pszAnswerSection)
  43. {
  44. Validate_INetCfgNotify_ReadAnswerFile(pszAnswerFile, pszAnswerSection);
  45. return S_OK;
  46. }
  47. STDMETHODIMP CNwlnkNB::Install (
  48. DWORD dwSetupFlags)
  49. {
  50. m_eInstallAction = eActInstall;
  51. return S_OK;
  52. }
  53. STDMETHODIMP CNwlnkNB::Removing ()
  54. {
  55. m_eInstallAction = eActRemove;
  56. return S_OK;
  57. }
  58. STDMETHODIMP CNwlnkNB::Validate ()
  59. {
  60. return S_OK;
  61. }
  62. STDMETHODIMP CNwlnkNB::CancelChanges ()
  63. {
  64. return S_OK;
  65. }
  66. STDMETHODIMP CNwlnkNB::ApplyRegistryChanges ()
  67. {
  68. UpdateBrowserDirectHostBinding ();
  69. if ((eActRemove != m_eInstallAction) &&
  70. (eStateNoChange != m_eNbState))
  71. {
  72. UpdateNwlnkNbStartType();
  73. }
  74. return S_OK;
  75. }
  76. // INetCfgSystemNotify
  77. STDMETHODIMP CNwlnkNB::GetSupportedNotifications (
  78. DWORD* pdwSupportedNotifications )
  79. {
  80. Validate_INetCfgSystemNotify_GetSupportedNotifications(pdwSupportedNotifications);
  81. // Want to know when DNS comes and goes
  82. *pdwSupportedNotifications = NCN_NETSERVICE | NCN_ADD | NCN_REMOVE;
  83. return S_OK;
  84. }
  85. STDMETHODIMP CNwlnkNB::SysQueryBindingPath (
  86. DWORD dwChangeFlag,
  87. INetCfgBindingPath* pIPath)
  88. {
  89. return S_OK;
  90. }
  91. STDMETHODIMP CNwlnkNB::SysQueryComponent (
  92. DWORD dwChangeFlag,
  93. INetCfgComponent* pIComp)
  94. {
  95. return S_OK;
  96. }
  97. STDMETHODIMP CNwlnkNB::SysNotifyBindingPath (
  98. DWORD dwChangeFlag,
  99. INetCfgBindingPath* pIPath)
  100. {
  101. return S_OK;
  102. }
  103. STDMETHODIMP CNwlnkNB::SysNotifyComponent (
  104. DWORD dwChangeFlag,
  105. INetCfgComponent* pnccItem)
  106. {
  107. Validate_INetCfgSystemNotify_SysNotifyComponent(dwChangeFlag, pnccItem);
  108. // Assume we won't be dirty as a result of this notification.
  109. //
  110. HRESULT hr = S_FALSE;
  111. // If this component does not identify itself as DNS then skip it...
  112. if (FIsComponentId(L"MS_DNSServer", pnccItem))
  113. {
  114. // Disable/Enable NetBIOS when DNS is Added/Removed
  115. if (dwChangeFlag & NCN_ADD)
  116. {
  117. // Disable and shutdown NwlnkNb
  118. m_eNbState = eStateDisable;
  119. hr = S_OK;
  120. }
  121. else if (dwChangeFlag & NCN_REMOVE)
  122. {
  123. // Re-enable NwlnkNb
  124. m_eNbState = eStateEnable;
  125. hr = S_OK;
  126. }
  127. }
  128. return hr;
  129. }
  130. //
  131. // Function: CNwlnkNB::UpdateNwlnkNbStartType
  132. //
  133. // Purpose: Enable or disable NwlnkNb
  134. //
  135. //
  136. VOID
  137. CNwlnkNB::UpdateNwlnkNbStartType(
  138. VOID)
  139. {
  140. HRESULT hr;
  141. CServiceManager scm;
  142. CService svc;
  143. hr = scm.HrOpenService(&svc, L"NwlnkNb");
  144. if (S_OK == hr)
  145. {
  146. if (eStateDisable == m_eNbState)
  147. {
  148. (VOID) svc.HrSetStartType(SERVICE_DISABLED);
  149. svc.Close();
  150. (VOID) scm.HrStopServiceNoWait(L"NwlnkNb");
  151. }
  152. else if (eStateEnable == m_eNbState)
  153. {
  154. (VOID) svc.HrSetStartType(SERVICE_DEMAND_START);
  155. }
  156. }
  157. }
  158. VOID
  159. CNwlnkNB::UpdateBrowserDirectHostBinding(
  160. VOID)
  161. {
  162. HRESULT hr;
  163. BOOL fBound = FALSE;
  164. // We don't need to check if client is bound to us if we are being
  165. // removed.
  166. //
  167. if (eActRemove != m_eInstallAction)
  168. {
  169. INetCfgComponent* pMsClient;
  170. hr = m_pNetCfg->FindComponent (L"ms_msclient", &pMsClient);
  171. if (S_OK == hr)
  172. {
  173. INetCfgComponentBindings* pMsClientBindings;
  174. hr = pMsClient->QueryInterface (IID_INetCfgComponentBindings,
  175. (VOID**)&pMsClientBindings);
  176. if (S_OK == hr)
  177. {
  178. fBound = (S_OK == pMsClientBindings->IsBoundTo (m_pnccMe));
  179. ReleaseObj (pMsClientBindings);
  180. }
  181. ReleaseObj (pMsClient);
  182. }
  183. }
  184. HKEY hkey;
  185. hr = HrRegOpenKeyEx (
  186. HKEY_LOCAL_MACHINE,
  187. L"System\\CurrentControlSet\\Services\\Browser\\Parameters",
  188. KEY_ALL_ACCESS, &hkey);
  189. if (S_OK == hr)
  190. {
  191. static const WCHAR c_szDirectHostBinding[] = L"DirectHostBinding";
  192. if (fBound)
  193. {
  194. // Write the DirectHostBinding info since we are directly bound
  195. //
  196. hr = HrRegSetMultiSz (hkey,
  197. c_szDirectHostBinding,
  198. L"\\Device\\NwlnkIpx\0\\Device\\NwlnkNb\0");
  199. }
  200. else
  201. {
  202. // Remove the DirectHostBinding value
  203. //
  204. (VOID) HrRegDeleteValue (hkey, c_szDirectHostBinding);
  205. }
  206. RegCloseKey (hkey);
  207. }
  208. }