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.

417 lines
6.8 KiB

  1. /*
  2. * Policy.cpp
  3. *
  4. * Author: BreenH
  5. *
  6. * The policy base class definition.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include "lscore.h"
  13. #include "session.h"
  14. #include "policy.h"
  15. #include "util.h"
  16. #include <tserrs.h>
  17. /*
  18. * Globals
  19. */
  20. extern "C" WCHAR g_wszProductVersion[];
  21. /*
  22. * Class Implementation
  23. */
  24. /*
  25. * Creation Functions
  26. */
  27. CPolicy::CPolicy(
  28. )
  29. {
  30. m_fActivated = FALSE;
  31. m_RefCount = 0;
  32. }
  33. CPolicy::~CPolicy(
  34. )
  35. {
  36. ASSERT(!m_fActivated);
  37. ASSERT(m_RefCount == 0);
  38. }
  39. /*
  40. * Core Loading and Activation Functions
  41. */
  42. NTSTATUS
  43. CPolicy::CoreActivate(
  44. BOOL fStartup,
  45. ULONG *pulAlternatePolicy
  46. )
  47. {
  48. NTSTATUS Status;
  49. //
  50. // CoreActivate is protected by the g_PolicyCritSec.
  51. //
  52. ASSERT(!m_fActivated);
  53. Status = Activate(fStartup,pulAlternatePolicy);
  54. if (Status == STATUS_SUCCESS)
  55. {
  56. m_fActivated = TRUE;
  57. }
  58. return(Status);
  59. }
  60. NTSTATUS
  61. CPolicy::CoreDeactivate(
  62. BOOL fShutdown
  63. )
  64. {
  65. NTSTATUS Status = STATUS_SUCCESS;
  66. //
  67. // CoreDeactivate is protected by the g_PolicyCritSec.
  68. //
  69. if (m_fActivated)
  70. {
  71. Status = Deactivate(fShutdown);
  72. m_fActivated = FALSE;
  73. }
  74. return(Status);
  75. }
  76. NTSTATUS
  77. CPolicy::CoreLoad(
  78. ULONG ulCoreVersion
  79. )
  80. {
  81. NTSTATUS Status;
  82. //
  83. // CoreLoad is protected by the g_PolicyCritSec.
  84. //
  85. if (ulCoreVersion == LC_VERSION_CURRENT)
  86. {
  87. Status = Load();
  88. }
  89. else
  90. {
  91. Status = STATUS_NOT_SUPPORTED;
  92. }
  93. return(Status);
  94. }
  95. NTSTATUS
  96. CPolicy::CoreUnload(
  97. )
  98. {
  99. NTSTATUS Status;
  100. //
  101. // CoreUnload is protected by the g_PolicyCritSec.
  102. //
  103. ASSERT(!m_fActivated);
  104. if (m_RefCount > 0)
  105. {
  106. Status = STATUS_UNSUCCESSFUL;
  107. }
  108. else
  109. {
  110. Status = Unload();
  111. }
  112. return(Status);
  113. }
  114. /*
  115. * Subclass Loading and Activation Functions
  116. */
  117. NTSTATUS
  118. CPolicy::Activate(
  119. BOOL fStartup,
  120. ULONG *pulAlternatePolicy
  121. )
  122. {
  123. UNREFERENCED_PARAMETER(fStartup);
  124. UNREFERENCED_PARAMETER(pulAlternatePolicy);
  125. return(STATUS_SUCCESS);
  126. }
  127. NTSTATUS
  128. CPolicy::Deactivate(
  129. BOOL fShutdown
  130. )
  131. {
  132. UNREFERENCED_PARAMETER(fShutdown);
  133. return(STATUS_SUCCESS);
  134. }
  135. NTSTATUS
  136. CPolicy::Load(
  137. )
  138. {
  139. return(STATUS_SUCCESS);
  140. }
  141. NTSTATUS
  142. CPolicy::Unload(
  143. )
  144. {
  145. return(STATUS_SUCCESS);
  146. }
  147. /*
  148. * Reference Functions
  149. */
  150. LONG
  151. CPolicy::IncrementReference(
  152. )
  153. {
  154. //
  155. // IncrementReference is protected by the g_PolicyCritSec. No need to
  156. // protect it again here, or do an InterlockedIncrement.
  157. //
  158. return(++m_RefCount);
  159. }
  160. LONG
  161. CPolicy::DecrementReference(
  162. )
  163. {
  164. //
  165. // DecrementReference is protected by the g_PolicyCritSec. No need to
  166. // protect it again here, or do an InterlockedDecrement.
  167. //
  168. return(--m_RefCount);
  169. }
  170. /*
  171. * Administrative Functions
  172. */
  173. NTSTATUS
  174. CPolicy::DestroyPrivateContext(
  175. LPLCCONTEXT lpContext
  176. )
  177. {
  178. UNREFERENCED_PARAMETER(lpContext);
  179. ASSERT(lpContext->lPrivate == NULL);
  180. return(STATUS_SUCCESS);
  181. }
  182. /*
  183. * Licensing Functions
  184. */
  185. NTSTATUS
  186. CPolicy::Connect(
  187. CSession& Session,
  188. UINT32 &dwClientError
  189. )
  190. {
  191. LICENSE_STATUS LsStatus;
  192. NTSTATUS Status;
  193. PBYTE pBuffer;
  194. ULONG cbBuffer;
  195. ULONG cbReturned;
  196. BOOL fExtendedError = FALSE;
  197. pBuffer = NULL;
  198. cbBuffer = 0;
  199. LsStatus = ConstructProtocolResponse(
  200. Session.GetLicenseContext()->hProtocolLibContext,
  201. LICENSE_RESPONSE_VALID_CLIENT,
  202. TS_ERRINFO_NOERROR,
  203. &cbBuffer,
  204. &pBuffer,
  205. fExtendedError
  206. );
  207. if (LsStatus == LICENSE_STATUS_OK)
  208. {
  209. ASSERT(pBuffer != NULL);
  210. ASSERT(cbBuffer > 0);
  211. Status = _IcaStackIoControl(
  212. Session.GetIcaStack(),
  213. IOCTL_ICA_STACK_SEND_CLIENT_LICENSE,
  214. pBuffer,
  215. cbBuffer,
  216. NULL,
  217. 0,
  218. &cbReturned
  219. );
  220. }
  221. else
  222. {
  223. dwClientError = LsStatusToClientError(LsStatus);
  224. Status = LsStatusToNtStatus(LsStatus);
  225. goto errorexit;
  226. }
  227. if (Status == STATUS_SUCCESS)
  228. {
  229. ULONG ulLicenseStatus;
  230. ulLicenseStatus = LICENSE_PROTOCOL_SUCCESS;
  231. Status = _IcaStackIoControl(
  232. Session.GetIcaStack(),
  233. IOCTL_ICA_STACK_LICENSE_PROTOCOL_COMPLETE,
  234. &ulLicenseStatus,
  235. sizeof(ULONG),
  236. NULL,
  237. 0,
  238. &cbReturned
  239. );
  240. }
  241. if (Status != STATUS_SUCCESS)
  242. {
  243. dwClientError = NtStatusToClientError(Status);
  244. }
  245. errorexit:
  246. if (pBuffer != NULL)
  247. {
  248. LocalFree(pBuffer);
  249. }
  250. return(Status);
  251. }
  252. NTSTATUS
  253. CPolicy::AutoLogon(
  254. CSession& Session,
  255. LPBOOL lpfUseCredentials,
  256. LPLCCREDENTIALS lpCredentials
  257. )
  258. {
  259. UNREFERENCED_PARAMETER(Session);
  260. UNREFERENCED_PARAMETER(lpCredentials);
  261. ASSERT(lpfUseCredentials != NULL);
  262. ASSERT(lpCredentials != NULL);
  263. *lpfUseCredentials = FALSE;
  264. return(STATUS_SUCCESS);
  265. }
  266. NTSTATUS
  267. CPolicy::Logon(
  268. CSession& Session
  269. )
  270. {
  271. UNREFERENCED_PARAMETER(Session);
  272. return(STATUS_SUCCESS);
  273. }
  274. NTSTATUS
  275. CPolicy::Disconnect(
  276. CSession& Session
  277. )
  278. {
  279. UNREFERENCED_PARAMETER(Session);
  280. return(STATUS_SUCCESS);
  281. }
  282. NTSTATUS
  283. CPolicy::Reconnect(
  284. CSession& Session,
  285. CSession& TemporarySession
  286. )
  287. {
  288. UNREFERENCED_PARAMETER(Session);
  289. UNREFERENCED_PARAMETER(TemporarySession);
  290. return(STATUS_SUCCESS);
  291. }
  292. NTSTATUS
  293. CPolicy::Logoff(
  294. CSession& Session
  295. )
  296. {
  297. UNREFERENCED_PARAMETER(Session);
  298. return(STATUS_SUCCESS);
  299. }
  300. /*
  301. * Common Helper Functions
  302. */
  303. NTSTATUS
  304. CPolicy::GetLlsLicense(
  305. CSession& Session
  306. )
  307. {
  308. LS_STATUS_CODE LlsStatus;
  309. NTSTATUS Status;
  310. NT_LS_DATA LsData;
  311. ASSERT(!(Session.GetLicenseContext()->fLlsLicense));
  312. LsData.DataType = NT_LS_USER_NAME;
  313. LsData.Data = (PVOID)(Session.GetUserName());
  314. LsData.IsAdmin = Session.IsUserAdmin();
  315. LlsStatus = NtLicenseRequest(
  316. LC_LLS_PRODUCT_NAME,
  317. g_wszProductVersion,
  318. &(Session.GetLicenseContext()->hLlsLicense),
  319. &LsData
  320. );
  321. if (LlsStatus == LS_SUCCESS)
  322. {
  323. Session.GetLicenseContext()->fLlsLicense = TRUE;
  324. Status = STATUS_SUCCESS;
  325. }
  326. else
  327. {
  328. if (LlsStatus == LS_INSUFFICIENT_UNITS)
  329. {
  330. Status = STATUS_CTX_LICENSE_NOT_AVAILABLE;
  331. }
  332. else
  333. {
  334. Status = STATUS_NO_MEMORY;
  335. }
  336. }
  337. return(Status);
  338. }