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.

338 lines
7.3 KiB

  1. /*
  2. * LSCoreP.cpp
  3. *
  4. * Author: BreenH
  5. *
  6. * Internal functions for the core.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include "lscore.h"
  13. #include "lscorep.h"
  14. #include "lcreg.h"
  15. #include "lctrace.h"
  16. #include "session.h"
  17. #include "policy.h"
  18. #include "pollist.h"
  19. #include "perseat.h"
  20. #include "peruser.h"
  21. #include "pts.h"
  22. #include "ra.h"
  23. #include <icaevent.h>
  24. /*
  25. * Internal Function Prototypes
  26. */
  27. ULONG
  28. InitializeBuiltinPolicies(
  29. LCINITMODE lcInitMode,
  30. BOOL fAppCompat
  31. );
  32. ULONG
  33. InitializeExternalPolicies(
  34. LCINITMODE lcInitMode,
  35. BOOL fAppCompat
  36. );
  37. /*
  38. * Function Implementations
  39. */
  40. NTSTATUS
  41. AllocatePolicyInformation(
  42. LPLCPOLICYINFOGENERIC *ppPolicyInfo,
  43. ULONG ulVersion
  44. )
  45. {
  46. NTSTATUS Status;
  47. ASSERT(ppPolicyInfo != NULL);
  48. if (ulVersion == LCPOLICYINFOTYPE_V1)
  49. {
  50. *ppPolicyInfo = (LPLCPOLICYINFOGENERIC)LocalAlloc(LPTR, sizeof(LCPOLICYINFO_V1));
  51. if (*ppPolicyInfo != NULL)
  52. {
  53. (*ppPolicyInfo)->ulVersion = LCPOLICYINFOTYPE_V1;
  54. Status = STATUS_SUCCESS;
  55. }
  56. else
  57. {
  58. Status = STATUS_NO_MEMORY;
  59. }
  60. }
  61. else
  62. {
  63. Status = STATUS_REVISION_MISMATCH;
  64. }
  65. return(Status);
  66. }
  67. VOID
  68. FreePolicyInformation(
  69. LPLCPOLICYINFOGENERIC *ppPolicyInfo
  70. )
  71. {
  72. ASSERT(ppPolicyInfo != NULL);
  73. ASSERT(*ppPolicyInfo != NULL);
  74. ASSERT((*ppPolicyInfo)->ulVersion <= LCPOLICYINFOTYPE_CURRENT);
  75. if ((*ppPolicyInfo)->ulVersion == LCPOLICYINFOTYPE_V1)
  76. {
  77. LPLCPOLICYINFO_V1 pPolicyInfoV1 = (LPLCPOLICYINFO_V1)(*ppPolicyInfo);
  78. ASSERT(pPolicyInfoV1->lpPolicyName != NULL);
  79. ASSERT(pPolicyInfoV1->lpPolicyDescription != NULL);
  80. LocalFree(pPolicyInfoV1->lpPolicyName);
  81. LocalFree(pPolicyInfoV1->lpPolicyDescription);
  82. LocalFree(pPolicyInfoV1);
  83. *ppPolicyInfo = NULL;
  84. }
  85. }
  86. ULONG
  87. GetHardcodedPolicyId(
  88. LCINITMODE lcInitMode,
  89. BOOL fAppCompat
  90. )
  91. {
  92. //
  93. // WARNING: HARDCODED VALUES:
  94. //
  95. // This function will return the ID of the default policy to activate upon
  96. // system boot. It will return the ID for Remote Admin or Per Seat based
  97. // on fAppCompat, or PTS, based on lcInitMode. Theoretically, the core
  98. // should not know these ID values, but it is necessary in this case.
  99. //
  100. return(lcInitMode == LC_INIT_LIMITED ? 0 : (fAppCompat ? 2 : 1));
  101. }
  102. ULONG
  103. GetInitialPolicy(
  104. LCINITMODE lcInitMode,
  105. BOOL fAppCompat
  106. )
  107. {
  108. ULONG ulPolicyId;
  109. if (lcInitMode == LC_INIT_ALL)
  110. {
  111. DWORD cbSize;
  112. DWORD dwStatus;
  113. DWORD dwType;
  114. cbSize = sizeof(ULONG);
  115. //
  116. // Query the value for the current App Compat mode.
  117. //
  118. dwStatus = RegQueryValueEx(
  119. GetBaseKey(),
  120. fAppCompat ? LCREG_ACONMODE : LCREG_ACOFFMODE,
  121. NULL,
  122. &dwType,
  123. (LPBYTE)&ulPolicyId,
  124. &cbSize
  125. );
  126. //
  127. // Make sure that the data type is good.
  128. //
  129. if ((dwStatus == ERROR_SUCCESS) && (dwType == REG_DWORD))
  130. {
  131. BOOL fLimitedInit;
  132. BOOL fRequireAC;
  133. CPolicy *pPolicy;
  134. //
  135. // Internet Connector is no longer supported; switch to Per User.
  136. //
  137. if (3 == ulPolicyId)
  138. {
  139. ulPolicyId = 4;
  140. SetInitialPolicy(ulPolicyId,fAppCompat);
  141. LicenseLogEvent(EVENTLOG_ERROR_TYPE,
  142. EVENT_LICENSING_IC_TO_PER_USER,
  143. 0,
  144. NULL );
  145. }
  146. //
  147. // Make sure that the policy specified actually exists, and
  148. // that it matches the settings.
  149. //
  150. pPolicy = PolicyListFindById(ulPolicyId);
  151. if (NULL != pPolicy)
  152. {
  153. fLimitedInit = pPolicy->GetFlags() & LC_FLAG_LIMITED_INIT_ONLY;
  154. fRequireAC = pPolicy->GetFlags() & LC_FLAG_REQUIRE_APP_COMPAT;
  155. if (!fLimitedInit)
  156. {
  157. if ((fRequireAC && fAppCompat) || (!fRequireAC && !fAppCompat))
  158. {
  159. goto exit;
  160. }
  161. }
  162. }
  163. }
  164. }
  165. //
  166. // For LC_INIT_LIMITED or for failure from above, get the hardcoded
  167. // value.
  168. //
  169. ulPolicyId = GetHardcodedPolicyId(lcInitMode, fAppCompat);
  170. exit:
  171. return(ulPolicyId);
  172. }
  173. NTSTATUS
  174. InitializePolicies(
  175. LCINITMODE lcInitMode,
  176. BOOL fAppCompat
  177. )
  178. {
  179. ULONG cLoadedPolicies;
  180. cLoadedPolicies = InitializeBuiltinPolicies(lcInitMode, fAppCompat);
  181. cLoadedPolicies += InitializeExternalPolicies(lcInitMode, fAppCompat);
  182. return(cLoadedPolicies > 0 ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
  183. }
  184. NTSTATUS
  185. SetInitialPolicy(
  186. ULONG ulPolicyId,
  187. BOOL fAppCompat
  188. )
  189. {
  190. DWORD cbSize;
  191. DWORD dwStatus;
  192. //
  193. // Set the value based on the app compat mode.
  194. //
  195. cbSize = sizeof(ULONG);
  196. dwStatus = RegSetValueEx(
  197. GetBaseKey(),
  198. fAppCompat ? LCREG_ACONMODE : LCREG_ACOFFMODE,
  199. NULL,
  200. REG_DWORD,
  201. (LPBYTE)&ulPolicyId,
  202. cbSize
  203. );
  204. return(dwStatus == ERROR_SUCCESS ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
  205. }
  206. VOID
  207. ShutdownPolicies(
  208. )
  209. {
  210. CPolicy *pPolicy;
  211. while ((pPolicy = PolicyListPop()) != NULL)
  212. {
  213. pPolicy->CoreUnload();
  214. delete pPolicy;
  215. }
  216. }
  217. /*
  218. * Internal Function Implementations
  219. */
  220. ULONG
  221. InitializeBuiltinPolicies(
  222. LCINITMODE lcInitMode,
  223. BOOL fAppCompat
  224. )
  225. {
  226. CPolicy *ppPolicy[3];
  227. NTSTATUS Status;
  228. ULONG cLoadedPolicies = 0;
  229. ULONG cPolicyArray;
  230. ULONG i;
  231. cPolicyArray = (lcInitMode == LC_INIT_LIMITED ? 1 : (fAppCompat ? 2 : 1));
  232. //
  233. // WARNING: HARDCODED POLICY NAMES (and flags, as this will
  234. // only load policies that will work in the current environment, even
  235. // though the core shouldn't know this)
  236. //
  237. if (lcInitMode == LC_INIT_ALL)
  238. {
  239. if (fAppCompat)
  240. {
  241. ppPolicy[0] = new CPerSeatPolicy();
  242. ppPolicy[1] = new CPerUserPolicy();
  243. }
  244. else
  245. {
  246. ppPolicy[0] = new CRAPolicy();
  247. }
  248. }
  249. else
  250. {
  251. ppPolicy[0] = new CPtsPolicy();
  252. }
  253. for (i = 0; i < cPolicyArray; i++)
  254. {
  255. if (ppPolicy[i] != NULL)
  256. {
  257. Status = ppPolicy[i]->CoreLoad(LC_VERSION_CURRENT);
  258. if (Status == STATUS_SUCCESS)
  259. {
  260. Status = PolicyListAdd(ppPolicy[i]);
  261. if (Status == STATUS_SUCCESS)
  262. {
  263. cLoadedPolicies++;
  264. continue;
  265. }
  266. }
  267. delete ppPolicy[i];
  268. ppPolicy[i] = NULL;
  269. }
  270. }
  271. return(cLoadedPolicies);
  272. }
  273. ULONG
  274. InitializeExternalPolicies(
  275. LCINITMODE lcInitMode,
  276. BOOL fAppCompat
  277. )
  278. {
  279. DBG_UNREFERENCED_PARAMETER(lcInitMode);
  280. DBG_UNREFERENCED_PARAMETER(fAppCompat);
  281. return(0);
  282. }