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.

408 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: R A S S R V . C P P
  7. //
  8. // Contents: Implementation of RAS Server configuration object.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 21 Mar 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include <ncreg.h>
  18. #include <mprapip.h>
  19. #include "rasobj.h"
  20. #include "ncnetcfg.h"
  21. extern const WCHAR c_szInfId_MS_Steelhead[];
  22. //+---------------------------------------------------------------------------
  23. // HrMprConfigServerUnattendedInstall
  24. //
  25. // This function dynamically links to the mprsnap.dll and calls the
  26. // utility function for unattended install of RAS/Routing.
  27. //
  28. typedef HRESULT (APIENTRY *PFNMPRINSTALL)(PCWSTR, BOOL);
  29. typedef DWORD (APIENTRY *PFSETPORTUSAGE)(IN DWORD dwUsage);
  30. const WCHAR g_pszNotificationPackages[] = L"Notification Packages";
  31. HRESULT HrMprConfigServerUnattendedInstall(PCWSTR pszServer, BOOL fInstall)
  32. {
  33. HINSTANCE hLib = NULL;
  34. PFNMPRINSTALL pMprConfigServerUnattendedInstall = NULL;
  35. HRESULT hr = S_OK;
  36. DWORD dwErr;
  37. hLib = LoadLibrary(L"mprsnap.dll");
  38. if (hLib == NULL)
  39. {
  40. dwErr = GetLastError();
  41. hr = HRESULT_FROM_WIN32( dwErr );
  42. }
  43. if (SUCCEEDED(hr))
  44. {
  45. pMprConfigServerUnattendedInstall = (PFNMPRINSTALL) GetProcAddress(hLib,
  46. "MprConfigServerUnattendedInstall");
  47. if (pMprConfigServerUnattendedInstall == NULL)
  48. {
  49. dwErr = GetLastError();
  50. hr = HRESULT_FROM_WIN32( dwErr );
  51. }
  52. }
  53. if (SUCCEEDED(hr))
  54. {
  55. hr = pMprConfigServerUnattendedInstall(pszServer, fInstall);
  56. }
  57. if (hLib)
  58. {
  59. FreeLibrary(hLib);
  60. }
  61. TraceError("HrMprConfigServerUnattendedInstall", hr);
  62. return hr;
  63. }
  64. //+---------------------------------------------------------------------------
  65. // HrSetUsageOnAllRasPorts
  66. //
  67. // This function dynamically links to rtrupg.dll and calls the
  68. // utility function for setting port usage.
  69. //
  70. HRESULT HrSetUsageOnAllRasPorts(IN DWORD dwUsage)
  71. {
  72. HINSTANCE hLib = NULL;
  73. PFSETPORTUSAGE pSetPortUsage = NULL;
  74. HRESULT hr = S_OK;
  75. DWORD dwErr;
  76. hLib = ::LoadLibrary(L"mprapi.dll");
  77. if (hLib == NULL)
  78. {
  79. dwErr = ::GetLastError();
  80. hr = HRESULT_FROM_WIN32( dwErr );
  81. }
  82. if (SUCCEEDED(hr))
  83. {
  84. pSetPortUsage = (PFSETPORTUSAGE) ::GetProcAddress(hLib,
  85. "MprPortSetUsage");
  86. if (pSetPortUsage == NULL)
  87. {
  88. dwErr = ::GetLastError();
  89. hr = HRESULT_FROM_WIN32( dwErr );
  90. }
  91. }
  92. if (SUCCEEDED(hr))
  93. hr = pSetPortUsage(dwUsage);
  94. if (hLib)
  95. ::FreeLibrary(hLib);
  96. TraceError("HrSetUsageOnAllRasPorts", hr);
  97. return hr;
  98. }
  99. //+---------------------------------------------------------------------------
  100. // HrSetLsaNotificationPackage
  101. //
  102. // Installs the given package as an LSA notification package if it is not
  103. // already installed.
  104. //
  105. HRESULT
  106. HrSetLsaNotificationPackage(
  107. IN PWCHAR pszPackage)
  108. {
  109. HRESULT hr = S_OK;
  110. HKEY hkLsa = NULL;
  111. DWORD dwErr = NO_ERROR, dwType, dwSize, dwLen, dwTotalLen;
  112. WCHAR pszPackageList[1024];
  113. PWCHAR pszCur = NULL;
  114. BOOL bFound = FALSE;
  115. do
  116. {
  117. // Open the Lsa key
  118. //
  119. hr = HrRegOpenKeyEx (
  120. HKEY_LOCAL_MACHINE,
  121. L"System\\CurrentControlSet\\Control\\Lsa",
  122. KEY_ALL_ACCESS,
  123. &hkLsa);
  124. if (FAILED(hr))
  125. {
  126. break;
  127. }
  128. // Query the value for the notification packages
  129. //
  130. dwType = REG_MULTI_SZ;
  131. dwSize = sizeof(pszPackageList);
  132. hr = HrRegQueryValueEx(
  133. hkLsa,
  134. g_pszNotificationPackages,
  135. &dwType,
  136. (LPBYTE)pszPackageList,
  137. &dwSize);
  138. if (FAILED(hr))
  139. {
  140. break;
  141. }
  142. // See if the given package is already installed
  143. //
  144. pszCur = (PWCHAR)pszPackageList;
  145. dwTotalLen = 0;
  146. while (*pszCur)
  147. {
  148. if (lstrcmpi(pszCur, pszPackage) == 0)
  149. {
  150. bFound = TRUE;
  151. }
  152. dwLen = (wcslen(pszCur) + 1);
  153. pszCur += dwLen;
  154. dwTotalLen += dwLen;
  155. }
  156. // If the package isn't already installed, add it.
  157. //
  158. if (!bFound)
  159. {
  160. dwLen = wcslen(pszPackage) + 1;
  161. wcscpy(pszCur, pszPackage);
  162. pszCur[dwLen] = L'\0';
  163. dwTotalLen += (dwLen + 1);
  164. hr = HrRegSetValueEx(
  165. hkLsa,
  166. g_pszNotificationPackages,
  167. REG_MULTI_SZ,
  168. (CONST BYTE*)pszPackageList,
  169. dwTotalLen * sizeof(WCHAR));
  170. if (FAILED(hr))
  171. {
  172. break;
  173. }
  174. }
  175. } while (FALSE);
  176. // Cleanup
  177. {
  178. if (hkLsa)
  179. {
  180. RegCloseKey(hkLsa);
  181. }
  182. }
  183. return hr;
  184. }
  185. CRasSrv::CRasSrv () : CRasBindObject ()
  186. {
  187. m_pnccMe = NULL;
  188. m_fRemoving = FALSE;
  189. m_fNt4ServerUpgrade = FALSE;
  190. m_fSaveAfData = FALSE;
  191. }
  192. CRasSrv::~CRasSrv ()
  193. {
  194. ReleaseObj (m_pnccMe);
  195. }
  196. //+---------------------------------------------------------------------------
  197. // INetCfgComponentControl
  198. //
  199. STDMETHODIMP
  200. CRasSrv::Initialize (
  201. INetCfgComponent* pncc,
  202. INetCfg* pnc,
  203. BOOL fInstalling)
  204. {
  205. Validate_INetCfgNotify_Initialize (pncc, pnc, fInstalling);
  206. // Hold on to our the component representing us and our host
  207. // INetCfg object.
  208. AddRefObj (m_pnccMe = pncc);
  209. AddRefObj (m_pnc = pnc);
  210. m_fInstalling = fInstalling;
  211. return S_OK;
  212. }
  213. STDMETHODIMP
  214. CRasSrv::Validate ()
  215. {
  216. return S_OK;
  217. }
  218. STDMETHODIMP
  219. CRasSrv::CancelChanges ()
  220. {
  221. return S_OK;
  222. }
  223. STDMETHODIMP
  224. CRasSrv::ApplyRegistryChanges ()
  225. {
  226. if (!m_fRemoving)
  227. {
  228. if (m_fSaveAfData)
  229. {
  230. m_AfData.SaveToRegistry ();
  231. m_fSaveAfData = FALSE;
  232. if (m_AfData.m_fRouterTypeSpecified)
  233. {
  234. HRESULT hr = HrMprConfigServerUnattendedInstall(NULL, TRUE);
  235. TraceError("CRasSrv::ApplyRegistryChanges unattend inst (ignoring)", hr);
  236. if (m_AfData.m_dataSrvCfg.dwRouterType & 4)
  237. {
  238. hr = HrSetUsageOnAllRasPorts(MPRFLAG_PORT_Router);
  239. TraceError("CRasSrv::ApplyRegistryChanges set router usage (ignoring)", hr);
  240. }
  241. }
  242. // pmay: 251736
  243. //
  244. // On NTS, we set all usage to dialin
  245. //
  246. if (m_fNt4ServerUpgrade)
  247. {
  248. HRESULT hr = HrSetUsageOnAllRasPorts(MPRFLAG_PORT_Dialin);
  249. TraceError("CRasSrv::ApplyRegistryChanges set dialin usage (ignoring)", hr);
  250. }
  251. // On professional, we set non-vpn port usage to to dialin if
  252. // a flag in the af tells us to do so.
  253. //
  254. else if (m_AfData.m_fSetUsageToDialin)
  255. {
  256. HRESULT hr = HrSetUsageOnAllRasPorts(MPRFLAG_PORT_NonVpnDialin);
  257. TraceError("CRasSrv::ApplyRegistryChanges set dialin usage (ignoring)", hr);
  258. }
  259. }
  260. if (m_fInstalling)
  261. {
  262. NT_PRODUCT_TYPE ProductType;
  263. if (RtlGetNtProductType (&ProductType))
  264. {
  265. // Upgrade local RAS user objects. Do not do this if we are
  266. // a domain controller as local RAS user objects translates to
  267. // all domain users. For the domain controller case, Dcpromo
  268. // handles upgrading the objects in a much more efficient
  269. // manner.
  270. //
  271. if (NtProductLanManNt != ProductType)
  272. {
  273. DWORD dwErr = MprAdminUpgradeUsers (NULL, TRUE);
  274. TraceError ("MprAdminUpgradeUsers", HRESULT_FROM_WIN32(dwErr));
  275. }
  276. // pmay: 407019
  277. //
  278. // Make sure that rassfm is installed as a notification package on all
  279. // flavors of nt servers
  280. //
  281. if ((NtProductServer == ProductType) || (NtProductLanManNt == ProductType))
  282. {
  283. HRESULT hr = HrSetLsaNotificationPackage(L"RASSFM");
  284. TraceError("CRasSrv::ApplyRegistryChanges set lsa not package usage (ignoring)", hr);
  285. }
  286. }
  287. }
  288. }
  289. return S_OK;
  290. }
  291. //+---------------------------------------------------------------------------
  292. // INetCfgComponentSetup
  293. //
  294. STDMETHODIMP
  295. CRasSrv::ReadAnswerFile (
  296. PCWSTR pszAnswerFile,
  297. PCWSTR pszAnswerSection)
  298. {
  299. Validate_INetCfgNotify_ReadAnswerFile (pszAnswerFile, pszAnswerSection);
  300. // Read data from the answer file.
  301. // Don't let this affect the HRESULT we return.
  302. //
  303. if (SUCCEEDED(m_AfData.HrOpenAndRead (pszAnswerFile, pszAnswerSection)))
  304. {
  305. m_fSaveAfData = TRUE;
  306. }
  307. return S_OK;
  308. }
  309. STDMETHODIMP
  310. CRasSrv::Install (DWORD dwSetupFlags)
  311. {
  312. HRESULT hr;
  313. Validate_INetCfgNotify_Install (dwSetupFlags);
  314. if (NSF_WINNT_SVR_UPGRADE & dwSetupFlags)
  315. {
  316. m_fNt4ServerUpgrade = TRUE;
  317. }
  318. // Install Steelhead.
  319. //
  320. hr = HrInstallComponentOboComponent (m_pnc, NULL,
  321. GUID_DEVCLASS_NETSERVICE,
  322. c_szInfId_MS_Steelhead,
  323. m_pnccMe,
  324. NULL);
  325. TraceHr (ttidError, FAL, hr, FALSE, "CRasSrv::Install");
  326. return hr;
  327. }
  328. STDMETHODIMP
  329. CRasSrv::Removing ()
  330. {
  331. HRESULT hr;
  332. m_fRemoving = TRUE;
  333. // Remove Steelhead.
  334. //
  335. hr = HrRemoveComponentOboComponent (m_pnc,
  336. GUID_DEVCLASS_NETSERVICE,
  337. c_szInfId_MS_Steelhead,
  338. m_pnccMe);
  339. TraceHr (ttidError, FAL, hr, FALSE, "CRasSrv::Removing");
  340. return hr;
  341. }
  342. STDMETHODIMP
  343. CRasSrv::Upgrade (
  344. DWORD dwSetupFlags,
  345. DWORD dwUpgradeFromBuildNo)
  346. {
  347. return S_FALSE;
  348. }