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.

287 lines
5.8 KiB

  1. /*
  2. * peruser.cpp
  3. *
  4. * Author: Rashmip
  5. *
  6. * The Per User licensing policy.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include "lscore.h"
  13. #include "session.h"
  14. #include "peruser.h"
  15. #include "util.h"
  16. #include "lctrace.h"
  17. #include <icaevent.h>
  18. #define STRSAFE_NO_DEPRECATE
  19. #include "strsafe.h"
  20. /*
  21. * extern globals
  22. */
  23. extern "C"
  24. extern HANDLE hModuleWin;
  25. /*
  26. * Class Implementation
  27. */
  28. /*
  29. * Creation Functions
  30. */
  31. CPerUserPolicy::CPerUserPolicy(
  32. ) : CPolicy()
  33. {
  34. }
  35. CPerUserPolicy::~CPerUserPolicy(
  36. )
  37. {
  38. }
  39. /*
  40. * Administrative Functions
  41. */
  42. ULONG
  43. CPerUserPolicy::GetFlags(
  44. )
  45. {
  46. return(LC_FLAG_INTERNAL_POLICY | LC_FLAG_REQUIRE_APP_COMPAT);
  47. }
  48. ULONG
  49. CPerUserPolicy::GetId(
  50. )
  51. {
  52. return(4);
  53. }
  54. NTSTATUS
  55. CPerUserPolicy::GetInformation(
  56. LPLCPOLICYINFOGENERIC lpPolicyInfo
  57. )
  58. {
  59. NTSTATUS Status;
  60. ASSERT(lpPolicyInfo != NULL);
  61. if (lpPolicyInfo->ulVersion == LCPOLICYINFOTYPE_V1)
  62. {
  63. int retVal;
  64. LPLCPOLICYINFO_V1 lpPolicyInfoV1 = (LPLCPOLICYINFO_V1)lpPolicyInfo;
  65. LPWSTR pName;
  66. LPWSTR pDescription;
  67. ASSERT(lpPolicyInfoV1->lpPolicyName == NULL);
  68. ASSERT(lpPolicyInfoV1->lpPolicyDescription == NULL);
  69. //
  70. // The strings loaded in this fashion are READ-ONLY. They are also
  71. // NOT NULL terminated. Allocate and zero out a buffer, then copy the
  72. // string over.
  73. //
  74. retVal = LoadString(
  75. (HINSTANCE)hModuleWin,
  76. IDS_LSCORE_PERUSER_NAME,
  77. (LPWSTR)(&pName),
  78. 0
  79. );
  80. if (retVal != 0)
  81. {
  82. lpPolicyInfoV1->lpPolicyName = (LPWSTR)LocalAlloc(LPTR, (retVal + 1) * sizeof(WCHAR));
  83. if (lpPolicyInfoV1->lpPolicyName != NULL)
  84. {
  85. StringCbCopyN(lpPolicyInfoV1->lpPolicyName, (retVal+1) * sizeof(WCHAR), pName, (retVal+1) * sizeof(WCHAR));
  86. }
  87. else
  88. {
  89. Status = STATUS_NO_MEMORY;
  90. goto V1error;
  91. }
  92. }
  93. else
  94. {
  95. Status = STATUS_INTERNAL_ERROR;
  96. goto V1error;
  97. }
  98. retVal = LoadString(
  99. (HINSTANCE)hModuleWin,
  100. IDS_LSCORE_PERUSER_DESC,
  101. (LPWSTR)(&pDescription),
  102. 0
  103. );
  104. if (retVal != 0)
  105. {
  106. lpPolicyInfoV1->lpPolicyDescription = (LPWSTR)LocalAlloc(LPTR, (retVal + 1) * sizeof(WCHAR));
  107. if (lpPolicyInfoV1->lpPolicyDescription != NULL)
  108. {
  109. StringCbCopyN(lpPolicyInfoV1->lpPolicyDescription, (retVal+1) * sizeof(WCHAR), pDescription, (retVal+1) * sizeof(WCHAR));
  110. }
  111. else
  112. {
  113. Status = STATUS_NO_MEMORY;
  114. goto V1error;
  115. }
  116. }
  117. else
  118. {
  119. Status = STATUS_INTERNAL_ERROR;
  120. goto V1error;
  121. }
  122. Status = STATUS_SUCCESS;
  123. goto exit;
  124. V1error:
  125. //
  126. // An error occurred loading/copying the strings.
  127. //
  128. if (lpPolicyInfoV1->lpPolicyName != NULL)
  129. {
  130. LocalFree(lpPolicyInfoV1->lpPolicyName);
  131. lpPolicyInfoV1->lpPolicyName = NULL;
  132. }
  133. if (lpPolicyInfoV1->lpPolicyDescription != NULL)
  134. {
  135. LocalFree(lpPolicyInfoV1->lpPolicyDescription);
  136. lpPolicyInfoV1->lpPolicyDescription = NULL;
  137. }
  138. }
  139. else
  140. {
  141. Status = STATUS_REVISION_MISMATCH;
  142. }
  143. exit:
  144. return(Status);
  145. }
  146. /*
  147. * Loading and Activation Functions
  148. */
  149. NTSTATUS
  150. CPerUserPolicy::Activate(
  151. BOOL fStartup,
  152. ULONG *pulAlternatePolicy
  153. )
  154. {
  155. UNREFERENCED_PARAMETER(fStartup);
  156. if (NULL != pulAlternatePolicy)
  157. {
  158. // don't set an explicit alternate policy
  159. *pulAlternatePolicy = ULONG_MAX;
  160. }
  161. return(StartCheckingGracePeriod());
  162. }
  163. NTSTATUS
  164. CPerUserPolicy::Deactivate(
  165. BOOL fShutdown
  166. )
  167. {
  168. if (!fShutdown)
  169. {
  170. return(StopCheckingGracePeriod());
  171. }
  172. else
  173. {
  174. return STATUS_SUCCESS;
  175. }
  176. }
  177. /*
  178. * Licensing Functions
  179. */
  180. NTSTATUS
  181. CPerUserPolicy::Logon(
  182. CSession& Session
  183. )
  184. {
  185. if (!Session.IsSessionZero()
  186. && !Session.IsUserHelpAssistant())
  187. {
  188. if (!AllowLicensingGracePeriodConnection())
  189. {
  190. if(FALSE == RegisteredWithLicenseServer())
  191. {
  192. LicenseLogEvent(EVENTLOG_WARNING_TYPE,
  193. EVENT_NO_LICENSE_SERVER,
  194. 0,
  195. NULL
  196. );
  197. return STATUS_CTX_WINSTATION_ACCESS_DENIED;
  198. }
  199. else
  200. {
  201. return STATUS_SUCCESS;
  202. }
  203. }
  204. else
  205. {
  206. return STATUS_SUCCESS;
  207. }
  208. }
  209. return STATUS_SUCCESS;
  210. }
  211. NTSTATUS
  212. CPerUserPolicy::Reconnect(
  213. CSession& Session,
  214. CSession& TemporarySession
  215. )
  216. {
  217. UNREFERENCED_PARAMETER(Session);
  218. if (!Session.IsSessionZero()
  219. && !Session.IsUserHelpAssistant())
  220. {
  221. if (!AllowLicensingGracePeriodConnection())
  222. {
  223. if(FALSE == RegisteredWithLicenseServer())
  224. {
  225. LicenseLogEvent(EVENTLOG_WARNING_TYPE,
  226. EVENT_NO_LICENSE_SERVER,
  227. 0,
  228. NULL
  229. );
  230. return STATUS_CTX_WINSTATION_ACCESS_DENIED;
  231. }
  232. else
  233. {
  234. return STATUS_SUCCESS;
  235. }
  236. }
  237. else
  238. {
  239. return STATUS_SUCCESS;
  240. }
  241. }
  242. return STATUS_SUCCESS;
  243. }