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.

295 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: S R V R D L G . C P P
  7. //
  8. // Contents: Dialog box handling for the Server object.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 5 Mar 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "srvrdlg.h"
  18. #include "ncreg.h"
  19. static const WCHAR c_szServerParams[] = L"System\\CurrentControlSet\\Services\\LanmanServer\\Parameters";
  20. static const WCHAR c_szLmAnnounce[] = L"Lmannounce";
  21. static const WCHAR c_szSize[] = L"Size";
  22. static const WCHAR c_szMemoryManagement[] = L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management";
  23. static const WCHAR c_szLargeCache[] = L"LargeSystemCache";
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Member: CSrvrcfg::HrSetupPropSheets
  27. //
  28. // Purpose: Inits the prop sheet page objects and creates the pages to be
  29. // returned to the installer object.
  30. //
  31. // Arguments:
  32. // pahpsp [out] Array of handles to property sheet pages.
  33. // cPages [in] Number of pages.
  34. //
  35. // Returns: HRESULT, Error code.
  36. //
  37. // Author: danielwe 5 Mar 1997
  38. //
  39. // Notes:
  40. //
  41. HRESULT CSrvrcfg::HrSetupPropSheets(HPROPSHEETPAGE **pahpsp, INT cPages)
  42. {
  43. HRESULT hr = S_OK;
  44. HPROPSHEETPAGE *ahpsp = NULL;
  45. Assert(pahpsp);
  46. *pahpsp = NULL;
  47. // Allocate a buffer large enough to hold the handles to all of our
  48. // property pages.
  49. ahpsp = (HPROPSHEETPAGE *)CoTaskMemAlloc(sizeof(HPROPSHEETPAGE)
  50. * cPages);
  51. if (!ahpsp)
  52. {
  53. hr = E_OUTOFMEMORY;
  54. goto err;
  55. }
  56. if (!m_apspObj[0])
  57. {
  58. // Allocate each of the CPropSheetPage objects
  59. m_apspObj[0] = new CServerConfigDlg(this);
  60. }
  61. // Create the actual PROPSHEETPAGE for each object.
  62. ahpsp[0] = m_apspObj[0]->CreatePage(DLG_ServerConfig, 0);
  63. Assert(SUCCEEDED(hr));
  64. *pahpsp = ahpsp;
  65. cleanup:
  66. TraceError("HrSetupPropSheets", hr);
  67. return hr;
  68. err:
  69. CoTaskMemFree(ahpsp);
  70. goto cleanup;
  71. }
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Member: CSrvrcfg::CleanupPropPages
  75. //
  76. // Purpose: Loop thru each of the pages and free the objects associated
  77. // with them.
  78. //
  79. // Arguments:
  80. // (none)
  81. //
  82. // Returns: Nothing.
  83. //
  84. // Author: danielwe 5 Mar 1997
  85. //
  86. // Notes:
  87. //
  88. VOID CSrvrcfg::CleanupPropPages()
  89. {
  90. INT ipage;
  91. for (ipage = 0; ipage < c_cPages; ipage++)
  92. {
  93. delete m_apspObj[ipage];
  94. m_apspObj[ipage] = NULL;
  95. }
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Member: CSrvrcfg::HrOpenRegKeys
  100. //
  101. // Purpose: Open the various registry keys we'll be working with for the
  102. // lifetime of our object.
  103. //
  104. // Arguments: pnc - An INetCfg interface
  105. //
  106. // Returns: HRESULT, Error code.
  107. //
  108. // Author: danielwe 5 Mar 1997
  109. //
  110. // Notes:
  111. //
  112. HRESULT CSrvrcfg::HrOpenRegKeys(INetCfg *pnc)
  113. {
  114. HRESULT hr = S_OK;
  115. hr = HrRegOpenKeyBestAccess(HKEY_LOCAL_MACHINE, c_szMemoryManagement,
  116. &m_hkeyMM);
  117. if (FAILED(hr))
  118. goto err;
  119. err:
  120. TraceError("CSrvrcfg::HrOpenRegKeys", hr);
  121. return hr;
  122. }
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Member: CSrvrcfg::HrGetRegistryInfo
  126. //
  127. // Purpose: Fill our in-memory state with data from the registry.
  128. //
  129. // Arguments:
  130. // fInstalling [in] TRUE if component is being installed, FALSE if
  131. // it is just being initialized (already installed)
  132. //
  133. // Returns: HRESULT, Error code.
  134. //
  135. // Author: danielwe 5 Mar 1997
  136. //
  137. // Notes:
  138. //
  139. HRESULT CSrvrcfg::HrGetRegistryInfo(BOOL fInstalling)
  140. {
  141. HRESULT hr = S_OK;
  142. HKEY hkeyParams;
  143. // Set reasonable defaults in case the key is missing
  144. m_sdd.fAnnounce = FALSE;
  145. if (m_pf == PF_SERVER)
  146. {
  147. m_sdd.dwSize = 3;
  148. m_sdd.fLargeCache = TRUE;
  149. }
  150. else
  151. {
  152. m_sdd.dwSize = 1;
  153. m_sdd.fLargeCache = FALSE;
  154. }
  155. if (!m_fUpgradeFromWks)
  156. {
  157. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szServerParams, KEY_READ,
  158. &hkeyParams);
  159. if (SUCCEEDED(hr))
  160. {
  161. DWORD dwSize;
  162. hr = HrRegQueryDword(hkeyParams, c_szLmAnnounce,
  163. (DWORD *)&m_sdd.fAnnounce);
  164. if (FAILED(hr))
  165. {
  166. if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
  167. {
  168. hr = S_OK;
  169. }
  170. else
  171. {
  172. goto err;
  173. }
  174. }
  175. hr = HrRegQueryDword(hkeyParams, c_szSize, &dwSize);
  176. if (FAILED(hr))
  177. {
  178. if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
  179. {
  180. hr = S_OK;
  181. }
  182. else
  183. {
  184. goto err;
  185. }
  186. }
  187. else
  188. {
  189. AssertSz(dwSize != 0, "This shouldn't be 0!");
  190. m_sdd.dwSize = dwSize;
  191. }
  192. RegCloseKey(hkeyParams);
  193. }
  194. if (!fInstalling)
  195. {
  196. // RAID #94442
  197. // Only read old value if this is not an initial install.
  198. // We want our default to be written when this is a first time install.
  199. AssertSz(m_hkeyMM, "No MM registry key??");
  200. hr = HrRegQueryDword(m_hkeyMM, c_szLargeCache,
  201. (DWORD *) &m_sdd.fLargeCache);
  202. if (FAILED(hr))
  203. {
  204. if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
  205. {
  206. hr = S_OK;
  207. }
  208. else
  209. {
  210. goto err;
  211. }
  212. }
  213. }
  214. }
  215. else
  216. {
  217. TraceTag(ttidSrvrCfg, "Upgrading from workstation product so we're "
  218. "ignoring the registry read code.");
  219. }
  220. err:
  221. TraceError("CSrvrcfg::HrGetRegistryInfo", hr);
  222. return hr;
  223. }
  224. //+---------------------------------------------------------------------------
  225. //
  226. // Member: CSrvrcfg::HrSetRegistryInfo
  227. //
  228. // Purpose: Save out our in-memory state to the registry.
  229. //
  230. // Arguments:
  231. // (none)
  232. //
  233. // Returns: HRESULT, Error code.
  234. //
  235. // Author: danielwe 5 Mar 1997
  236. //
  237. // Notes:
  238. //
  239. HRESULT CSrvrcfg::HrSetRegistryInfo()
  240. {
  241. HRESULT hr = S_OK;
  242. HKEY hkeyParams;
  243. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szServerParams,
  244. KEY_ALL_ACCESS, &hkeyParams);
  245. if (SUCCEEDED(hr))
  246. {
  247. hr = HrRegSetDword(hkeyParams, c_szLmAnnounce, m_sdd.fAnnounce);
  248. if (SUCCEEDED(hr))
  249. {
  250. hr = HrRegSetDword(hkeyParams, c_szSize, m_sdd.dwSize);
  251. }
  252. RegCloseKey(hkeyParams);
  253. }
  254. if (SUCCEEDED(hr))
  255. {
  256. AssertSz(m_hkeyMM, "Why is this not open?");
  257. hr = HrRegSetDword(m_hkeyMM, c_szLargeCache, m_sdd.fLargeCache);
  258. }
  259. TraceError("CSrvrcfg::HrSetRegistryInfo", hr);
  260. return hr;
  261. }