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.

259 lines
4.9 KiB

  1. /*
  2. * RA.cpp
  3. *
  4. * Author: BreenH
  5. *
  6. * The Remote Administration policy.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include "lscore.h"
  13. #include "session.h"
  14. #include "ra.h"
  15. /*
  16. * extern globals
  17. */
  18. extern "C"
  19. extern HANDLE hModuleWin;
  20. /*
  21. * Class Implementation
  22. */
  23. /*
  24. * Creation Functions
  25. */
  26. CRAPolicy::CRAPolicy(
  27. ) : CPolicy()
  28. {
  29. m_SessionCount = 0;
  30. }
  31. CRAPolicy::~CRAPolicy(
  32. )
  33. {
  34. ASSERT(m_SessionCount == 0);
  35. }
  36. /*
  37. * Administrative Functions
  38. */
  39. ULONG
  40. CRAPolicy::GetFlags(
  41. )
  42. {
  43. return(LC_FLAG_INTERNAL_POLICY);
  44. }
  45. ULONG
  46. CRAPolicy::GetId(
  47. )
  48. {
  49. return(1);
  50. }
  51. NTSTATUS
  52. CRAPolicy::GetInformation(
  53. LPLCPOLICYINFOGENERIC lpPolicyInfo
  54. )
  55. {
  56. NTSTATUS Status;
  57. ASSERT(lpPolicyInfo != NULL);
  58. if (lpPolicyInfo->ulVersion == LCPOLICYINFOTYPE_V1)
  59. {
  60. int retVal;
  61. LPLCPOLICYINFO_V1 lpPolicyInfoV1 = (LPLCPOLICYINFO_V1)lpPolicyInfo;
  62. LPWSTR pName;
  63. LPWSTR pDescription;
  64. ASSERT(lpPolicyInfoV1->lpPolicyName == NULL);
  65. ASSERT(lpPolicyInfoV1->lpPolicyDescription == NULL);
  66. //
  67. // The strings loaded in this fashion are READ-ONLY. They are also
  68. // NOT NULL terminated. Allocate and zero out a buffer, then copy the
  69. // string over.
  70. //
  71. retVal = LoadString(
  72. (HINSTANCE)hModuleWin,
  73. IDS_LSCORE_RA_NAME,
  74. (LPWSTR)(&pName),
  75. 0
  76. );
  77. if (retVal != 0)
  78. {
  79. lpPolicyInfoV1->lpPolicyName = (LPWSTR)LocalAlloc(LPTR, (retVal + 1) * sizeof(WCHAR));
  80. if (lpPolicyInfoV1->lpPolicyName != NULL)
  81. {
  82. lstrcpynW(lpPolicyInfoV1->lpPolicyName, pName, retVal + 1);
  83. }
  84. else
  85. {
  86. Status = STATUS_NO_MEMORY;
  87. goto V1error;
  88. }
  89. }
  90. else
  91. {
  92. Status = STATUS_INTERNAL_ERROR;
  93. goto V1error;
  94. }
  95. retVal = LoadString(
  96. (HINSTANCE)hModuleWin,
  97. IDS_LSCORE_RA_DESC,
  98. (LPWSTR)(&pDescription),
  99. 0
  100. );
  101. if (retVal != 0)
  102. {
  103. lpPolicyInfoV1->lpPolicyDescription = (LPWSTR)LocalAlloc(LPTR, (retVal + 1) * sizeof(WCHAR));
  104. if (lpPolicyInfoV1->lpPolicyDescription != NULL)
  105. {
  106. lstrcpynW(lpPolicyInfoV1->lpPolicyDescription, pDescription, retVal + 1);
  107. }
  108. else
  109. {
  110. Status = STATUS_NO_MEMORY;
  111. goto V1error;
  112. }
  113. }
  114. else
  115. {
  116. Status = STATUS_INTERNAL_ERROR;
  117. goto V1error;
  118. }
  119. Status = STATUS_SUCCESS;
  120. goto exit;
  121. V1error:
  122. //
  123. // An error occurred loading/copying the strings.
  124. //
  125. if (lpPolicyInfoV1->lpPolicyName != NULL)
  126. {
  127. LocalFree(lpPolicyInfoV1->lpPolicyName);
  128. lpPolicyInfoV1->lpPolicyName = NULL;
  129. }
  130. if (lpPolicyInfoV1->lpPolicyDescription != NULL)
  131. {
  132. LocalFree(lpPolicyInfoV1->lpPolicyDescription);
  133. lpPolicyInfoV1->lpPolicyDescription = NULL;
  134. }
  135. }
  136. else
  137. {
  138. Status = STATUS_REVISION_MISMATCH;
  139. }
  140. exit:
  141. return(Status);
  142. }
  143. /*
  144. * Licensing Functions
  145. */
  146. NTSTATUS
  147. CRAPolicy::Logon(
  148. CSession& Session
  149. )
  150. {
  151. NTSTATUS Status;
  152. if ((!Session.IsSessionZero()) && (!(Session.IsUserHelpAssistant())))
  153. {
  154. Status = UseLicense(Session);
  155. }
  156. else
  157. {
  158. Status = STATUS_SUCCESS;
  159. }
  160. return(Status);
  161. }
  162. NTSTATUS
  163. CRAPolicy::Logoff(
  164. CSession& Session
  165. )
  166. {
  167. NTSTATUS Status;
  168. if (Session.GetLicenseContext()->fTsLicense)
  169. {
  170. Status = ReleaseLicense(Session);
  171. }
  172. else
  173. {
  174. Status = STATUS_SUCCESS;
  175. }
  176. return(Status);
  177. }
  178. /*
  179. * Private Functions
  180. */
  181. NTSTATUS
  182. CRAPolicy::ReleaseLicense(
  183. CSession& Session
  184. )
  185. {
  186. LONG lSessions;
  187. ASSERT(Session.GetLicenseContext()->fTsLicense);
  188. lSessions = InterlockedDecrement(&m_SessionCount);
  189. Session.GetLicenseContext()->fTsLicense = FALSE;
  190. ASSERT(lSessions >= 0);
  191. return(STATUS_SUCCESS);
  192. }
  193. NTSTATUS
  194. CRAPolicy::UseLicense(
  195. CSession& Session
  196. )
  197. {
  198. NTSTATUS Status;
  199. LONG lSessions;
  200. ASSERT(!(Session.GetLicenseContext()->fTsLicense));
  201. lSessions = InterlockedIncrement(&m_SessionCount);
  202. if (lSessions <= LC_POLICY_RA_MAX_SESSIONS)
  203. {
  204. Session.GetLicenseContext()->fTsLicense = TRUE;
  205. Status = STATUS_SUCCESS;
  206. }
  207. else
  208. {
  209. InterlockedDecrement(&m_SessionCount);
  210. Status = STATUS_CTX_LICENSE_NOT_AVAILABLE;
  211. }
  212. return(Status);
  213. }