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.

229 lines
6.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: M S C A P P L Y . C P P
  7. //
  8. // Contents: Functions called when MSClient is applied.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 25 Feb 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include <ncxbase.h>
  18. #include "ncnetcfg.h"
  19. #include "mscliobj.h"
  20. #include "ncmisc.h"
  21. #include "ncsvc.h"
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Member: CMSClient::HrApplyChanges
  25. //
  26. // Purpose: Writes out changes that occurred during the lifetime of our
  27. // object.
  28. //
  29. // Arguments:
  30. // (none)
  31. //
  32. // Returns: HRESULT, Error code.
  33. //
  34. // Author: danielwe 25 Feb 1997
  35. //
  36. // Notes: This will do several things.
  37. // 1) Set info for the RPC nameservice and security service that
  38. // was indicated by the UI for the RPC config dialog.
  39. // 2) Set the parameters for the browser configuration to the
  40. // registry.
  41. //
  42. // If no changes were detected, this will do nothing.
  43. //
  44. HRESULT CMSClient::HrApplyChanges()
  45. {
  46. HRESULT hr;
  47. // Write out any changes to RPC info
  48. hr = HrSetRPCRegistryInfo();
  49. if (SUCCEEDED(hr))
  50. {
  51. // Write out any changes to Browser info
  52. hr = HrSetBrowserRegistryInfo();
  53. }
  54. if (SUCCEEDED(hr) && (m_fOneTimeInstall || m_fUpgradeFromWks))
  55. {
  56. // Note: This function will do the workstation/server detection,
  57. // and won't install if we're running the workstation build.
  58. //
  59. hr = HrInstallDfs();
  60. }
  61. TraceError("CMSClient::HrApplyChanges", hr);
  62. return hr;
  63. }
  64. static const CHAR c_szaDfsCheck[] = "DfsCheckForOldDfsService";
  65. static const CHAR c_szaDfsSetupDfs[] = "DfsSetupDfs";
  66. static const WCHAR c_szDfsSetupDll[] = L"dfssetup.dll";
  67. typedef BOOLEAN (APIENTRY *PDFSCHECKFOROLDDFSSERVICE)(void);
  68. typedef DWORD (APIENTRY *PDFSSETUPDFS)(DWORD, PSTR, PSTR *);
  69. //+---------------------------------------------------------------------------
  70. //
  71. // Function: HrInstallDfs
  72. //
  73. // Purpose: Take care of installation of DFS components
  74. //
  75. // Arguments:
  76. // (none)
  77. //
  78. // Returns: Win32 HRESULT if failure.
  79. //
  80. // Author: danielwe 23 Jul 1997
  81. //
  82. // Notes: Shortcut creation is handled by this function and not
  83. // the netmscli.inf file because it is conditional on whether
  84. // the DFS components are installed.
  85. //
  86. HRESULT HrInstallDfs()
  87. {
  88. HRESULT hr = S_OK;
  89. PRODUCT_FLAVOR pf; // Server/Workstation
  90. // Get the product flavor (PF_WORKSTATION or PF_SERVER). Use this
  91. // to decide whether or not we need to install DFS.
  92. //
  93. GetProductFlavor(NULL, &pf);
  94. if (PF_SERVER == pf)
  95. {
  96. PDFSCHECKFOROLDDFSSERVICE pfnDfsCheckForOldDfsService = NULL;
  97. HMODULE hMod = NULL;
  98. TraceTag(ttidMSCliCfg, "Attempting to install DFS, since we're in a "
  99. "server install");
  100. hr = HrLoadLibAndGetProc(c_szDfsSetupDll, c_szaDfsCheck, &hMod,
  101. reinterpret_cast<FARPROC *>(&pfnDfsCheckForOldDfsService));
  102. if (SUCCEEDED(hr))
  103. {
  104. AssertSz(hMod, "Module handle cannot be NULL!");
  105. BOOL fDFSInstalled = pfnDfsCheckForOldDfsService();
  106. // If DFS is not installed, go ahead and install it now.
  107. if (!fDFSInstalled)
  108. {
  109. PDFSSETUPDFS pfnDfsSetupDfs = NULL;
  110. hr = HrGetProcAddress(hMod, c_szaDfsSetupDfs,
  111. reinterpret_cast<FARPROC *>(&pfnDfsSetupDfs));
  112. if (SUCCEEDED(hr))
  113. {
  114. PSTR szResult = NULL;
  115. if (!pfnDfsSetupDfs(0, NULL, &szResult))
  116. {
  117. // DFS setup failed!
  118. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  119. TraceError("HrInstallDfs - pfnDfsSetupDfs", hr);
  120. }
  121. }
  122. }
  123. FreeLibrary(hMod);
  124. }
  125. }
  126. else
  127. {
  128. TraceTag(ttidMSCliCfg, "Not attempting to install DFS, since we're in a "
  129. "workstation install");
  130. }
  131. TraceError("HrInstallDfs", hr);
  132. return hr;
  133. }
  134. //+---------------------------------------------------------------------------
  135. //
  136. // Function: HrEnableBrowserService
  137. //
  138. // Purpose: Enables the 'Browser' service
  139. //
  140. // Arguments:
  141. // (none)
  142. //
  143. // Returns: S_OK if success, WIN32 error if not
  144. //
  145. // Author: danielwe 9 Sep 1998
  146. //
  147. // Notes:
  148. //
  149. HRESULT HrEnableBrowserService()
  150. {
  151. HRESULT hr;
  152. CServiceManager sm;
  153. CService srv;
  154. hr = sm.HrOpenService(&srv, L"Browser");
  155. if (SUCCEEDED(hr))
  156. {
  157. DWORD dwStartType;
  158. hr = srv.HrQueryStartType(&dwStartType);
  159. if (SUCCEEDED(hr) && (dwStartType != SERVICE_DISABLED))
  160. {
  161. // Change the Browser StartType registry setting back to auto start
  162. hr = srv.HrSetStartType(SERVICE_AUTO_START);
  163. }
  164. }
  165. TraceError("HrEnableBrowserService",hr);
  166. return hr;
  167. }
  168. //+---------------------------------------------------------------------------
  169. //
  170. // Function: HrDisableBrowserService
  171. //
  172. // Purpose: Disables the 'Browser' service
  173. //
  174. // Arguments:
  175. // (none)
  176. //
  177. // Returns: S_OK if success, WIN32 error if not
  178. //
  179. // Author: danielwe 9 Sep 1998
  180. //
  181. // Notes:
  182. //
  183. HRESULT HrDisableBrowserService()
  184. {
  185. HRESULT hr;
  186. CServiceManager sm;
  187. CService srv;
  188. hr = sm.HrOpenService(&srv, L"Browser");
  189. if (SUCCEEDED(hr))
  190. {
  191. DWORD dwStartType;
  192. hr = srv.HrQueryStartType(&dwStartType);
  193. if (SUCCEEDED(hr) && (dwStartType != SERVICE_DISABLED))
  194. {
  195. // Change the Browser StartType registry setting to demand start
  196. hr = srv.HrSetStartType(SERVICE_DEMAND_START);
  197. if (SUCCEEDED(hr))
  198. {
  199. hr = sm.HrStopServiceNoWait(L"Browser");
  200. }
  201. }
  202. }
  203. TraceError("CNbfObj::HrDisableNetBEUI",hr);
  204. return hr;
  205. }