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.

939 lines
24 KiB

  1. /*
  2. * LSCore.cpp
  3. *
  4. * Author: BreenH
  5. *
  6. * The licensing core.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include "lscore.h"
  13. #include "lscorep.h"
  14. #include "lcreg.h"
  15. #include "lcrpcint.h"
  16. #include "session.h"
  17. #include "policy.h"
  18. #include "pollist.h"
  19. #include "lctrace.h"
  20. #include "util.h"
  21. /*
  22. * Globals
  23. */
  24. extern "C" BOOL g_fAppCompat;
  25. CRITICAL_SECTION g_PolicyCritSec;
  26. LCINITMODE g_lcInitMode;
  27. CPolicy *g_pCurrentPolicy = NULL;
  28. BOOL g_fInitialized = FALSE;
  29. /*
  30. * Initialization Function Implementations
  31. */
  32. extern "C"
  33. NTSTATUS
  34. LCInitialize(
  35. LCINITMODE lcInitMode,
  36. BOOL fAppCompat
  37. )
  38. {
  39. CPolicy *pPolicy;
  40. DWORD dwStatus;
  41. LICENSE_STATUS LsStatus;
  42. NTSTATUS Status;
  43. ULONG ulPolicyId;
  44. ULONG ulAlternatePolicyId = ULONG_MAX;
  45. Status = RegistryInitialize();
  46. if (Status == STATUS_SUCCESS)
  47. {
  48. #if DBG
  49. TraceInitialize();
  50. #endif
  51. TRACEPRINT((LCTRACETYPE_API, "LCInitialize: Entered with lcInitMode: %d", lcInitMode));
  52. Status = RtlInitializeCriticalSection(&g_PolicyCritSec);
  53. }
  54. else
  55. {
  56. goto errorreginit;
  57. }
  58. if (Status == STATUS_SUCCESS)
  59. {
  60. dwStatus = TLSInit();
  61. }
  62. else
  63. {
  64. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to RtlInitializeCriticalSection: 0x%x", Status));
  65. goto errorcritsecalloc;
  66. }
  67. if (dwStatus == ERROR_SUCCESS)
  68. {
  69. LsStatus = InitializeProtocolLib();
  70. }
  71. else
  72. {
  73. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to TLSInit: %d", dwStatus));
  74. Status = STATUS_UNSUCCESSFUL;
  75. goto errortlsinit;
  76. }
  77. if ( (lcInitMode == LC_INIT_ALL ) && fAppCompat)
  78. {
  79. dwStatus = TLSStartDiscovery();
  80. if (dwStatus != ERROR_SUCCESS)
  81. {
  82. //
  83. // This error is not fatal.
  84. //
  85. TRACEPRINT((LCTRACETYPE_WARNING, "LCInitialize: Failed to TLSStartDiscovery: %d", dwStatus));
  86. }
  87. }
  88. if (LsStatus == LICENSE_STATUS_OK)
  89. {
  90. Status = PolicyListInitialize();
  91. }
  92. else
  93. {
  94. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to InitializeProtocolLib: 0x%x", LsStatus));
  95. Status = STATUS_UNSUCCESSFUL;
  96. goto errorprotlib;
  97. }
  98. if (Status == STATUS_SUCCESS)
  99. {
  100. Status = InitializePolicies(lcInitMode, fAppCompat);
  101. }
  102. else
  103. {
  104. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to PolicyListInitialize: 0x%x", Status));
  105. goto errorinitpollist;
  106. }
  107. if (Status == STATUS_SUCCESS)
  108. {
  109. ulPolicyId = GetInitialPolicy(lcInitMode, fAppCompat);
  110. pPolicy = PolicyListFindById(ulPolicyId);
  111. }
  112. else
  113. {
  114. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to InitializePolicies: 0x%x", Status));
  115. goto errorinitpol;
  116. }
  117. ASSERT(pPolicy != NULL);
  118. if(pPolicy == NULL)
  119. {
  120. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: pPolicy is NULL"));
  121. goto errorinitpol;
  122. }
  123. Status = pPolicy->CoreActivate(TRUE,&ulAlternatePolicyId);
  124. if (Status != STATUS_SUCCESS)
  125. {
  126. if ((ulAlternatePolicyId != ULONG_MAX)
  127. && (ulAlternatePolicyId != ulPolicyId))
  128. {
  129. TRACEPRINT((LCTRACETYPE_WARNING, "LCInitialize: Trying to activate the alternate policy, ID: %d, Status: 0x%x", ulAlternatePolicyId, Status));
  130. pPolicy = PolicyListFindById(ulAlternatePolicyId);
  131. if (NULL != pPolicy)
  132. {
  133. Status = pPolicy->CoreActivate(TRUE,NULL);
  134. if (Status == STATUS_SUCCESS)
  135. {
  136. goto foundpolicy;
  137. }
  138. }
  139. else
  140. {
  141. TRACEPRINT((LCTRACETYPE_WARNING, "LCInitialize: Alternate policy could not be loaded, ID: %d", ulAlternatePolicyId));
  142. }
  143. }
  144. {
  145. ULONG ulNewPolicyId;
  146. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to activate the initial policy, ID: %d, Status: 0x%x", ulPolicyId, Status));
  147. ulNewPolicyId = GetHardcodedPolicyId(lcInitMode, fAppCompat);
  148. if ((ulNewPolicyId != ulPolicyId)
  149. && (ulNewPolicyId != ulAlternatePolicyId))
  150. {
  151. TRACEPRINT((LCTRACETYPE_WARNING, "LCInitialize: Trying to activate the default policy, ID: %d, Status: 0x%x", ulNewPolicyId, Status));
  152. pPolicy = PolicyListFindById(ulNewPolicyId);
  153. ASSERT(pPolicy != NULL);
  154. Status = pPolicy->CoreActivate(TRUE,NULL);
  155. }
  156. else
  157. {
  158. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed policy is default policy!"));
  159. }
  160. }
  161. }
  162. if (Status != STATUS_SUCCESS)
  163. {
  164. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to activate any policy!"));
  165. goto erroractpol;
  166. }
  167. foundpolicy:
  168. g_pCurrentPolicy = pPolicy;
  169. if (lcInitMode == LC_INIT_ALL)
  170. {
  171. Status = InitializeRpcInterface();
  172. if (Status != STATUS_SUCCESS)
  173. {
  174. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Failed to InitializeRpcInterface: 0x%x", Status));
  175. goto errorrpcinit;
  176. }
  177. }
  178. g_lcInitMode = lcInitMode;
  179. TRACEPRINT((LCTRACETYPE_API, "LCInitialize: Returning success"));
  180. g_fInitialized = TRUE;
  181. return(STATUS_SUCCESS);
  182. errorrpcinit:
  183. erroractpol:
  184. ShutdownPolicies();
  185. errorinitpol:
  186. ShutdownProtocolLib();
  187. errorinitpollist:
  188. errorprotlib:
  189. TLSShutdown();
  190. errortlsinit:
  191. RtlDeleteCriticalSection(&g_PolicyCritSec);
  192. errorcritsecalloc:
  193. errorreginit:
  194. TRACEPRINT((LCTRACETYPE_ERROR, "LCInitialize: Returning: 0x%x", Status));
  195. return(Status);
  196. }
  197. // This function should invoke only the most important and required
  198. // destruction code, since we're on a strict time limit on system shutdown.
  199. extern "C"
  200. VOID
  201. LCShutdown(
  202. )
  203. {
  204. // Note: this can be called without LCInitialize having been called
  205. if (g_fInitialized)
  206. {
  207. g_fInitialized = FALSE;
  208. RtlEnterCriticalSection(&g_PolicyCritSec);
  209. if (NULL != g_pCurrentPolicy)
  210. {
  211. g_pCurrentPolicy->CoreDeactivate(TRUE);
  212. g_pCurrentPolicy = NULL;
  213. }
  214. ShutdownPolicies();
  215. RtlLeaveCriticalSection(&g_PolicyCritSec);
  216. }
  217. }
  218. /*
  219. * Policy Activation Function Implementations
  220. */
  221. extern "C"
  222. NTSTATUS
  223. LCDeactivateCurrentPolicy(
  224. )
  225. {
  226. NTSTATUS Status;
  227. TRACEPRINT((LCTRACETYPE_API, "LCDeactivateCurrentPolicy:"));
  228. RtlEnterCriticalSection(&g_PolicyCritSec);
  229. Status = g_pCurrentPolicy->CoreDeactivate(FALSE);
  230. RtlLeaveCriticalSection(&g_PolicyCritSec);
  231. return(Status);
  232. }
  233. extern "C"
  234. NTSTATUS
  235. LCSetPolicy(
  236. ULONG ulPolicyId,
  237. PNTSTATUS pNewPolicyStatus
  238. )
  239. {
  240. CPolicy *pNewPolicy;
  241. NTSTATUS Status;
  242. TRACEPRINT((LCTRACETYPE_API, "LCSetPolicy: Entered with ulPolicyId: %d, pNewPolicyStatus: 0x%p", ulPolicyId, pNewPolicyStatus));
  243. ASSERT(pNewPolicyStatus != NULL);
  244. *pNewPolicyStatus = STATUS_SUCCESS;
  245. RtlEnterCriticalSection(&g_PolicyCritSec);
  246. if (ulPolicyId == g_pCurrentPolicy->GetId())
  247. {
  248. Status = STATUS_SUCCESS;
  249. goto exit;
  250. }
  251. pNewPolicy = PolicyListFindById(ulPolicyId);
  252. if (pNewPolicy == NULL)
  253. {
  254. Status = STATUS_INVALID_SERVER_STATE;
  255. goto exit;
  256. }
  257. *pNewPolicyStatus = pNewPolicy->CoreActivate(FALSE,NULL);
  258. if (*pNewPolicyStatus == STATUS_SUCCESS)
  259. {
  260. Status = SetInitialPolicy(ulPolicyId, g_fAppCompat);
  261. if (Status == STATUS_SUCCESS)
  262. {
  263. g_pCurrentPolicy->CoreDeactivate(FALSE);
  264. g_pCurrentPolicy = pNewPolicy;
  265. }
  266. else
  267. {
  268. pNewPolicy->CoreDeactivate(FALSE);
  269. }
  270. }
  271. else
  272. {
  273. TRACEPRINT((LCTRACETYPE_ERROR, "LCSetPolicy: Failed to pNewPolicy->CoreActivate: 0x%x", *pNewPolicyStatus));
  274. Status = STATUS_UNSUCCESSFUL;
  275. }
  276. exit:
  277. RtlLeaveCriticalSection(&g_PolicyCritSec);
  278. TRACEPRINT((LCTRACETYPE_API, "LCSetPolicy: Returning 0x%x", Status));
  279. return(Status);
  280. }
  281. /*
  282. * Administrative Function Implementations
  283. */
  284. extern "C"
  285. VOID
  286. LCAssignPolicy(
  287. PWINSTATION pWinStation
  288. )
  289. {
  290. LPLCCONTEXT lpContext;
  291. ASSERT(pWinStation != NULL);
  292. TRACEPRINT((LCTRACETYPE_API, "LCAssignPolicy: Entered with Session: %d", pWinStation->LogonId));
  293. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  294. ASSERT(lpContext != NULL);
  295. ASSERT(lpContext->pPolicy == NULL);
  296. TRACEPRINT((LCTRACETYPE_INFO, "LCAssignPolicy: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  297. //
  298. // Always enter the context critical section first.
  299. //
  300. RtlEnterCriticalSection(&(lpContext->CritSec));
  301. RtlEnterCriticalSection(&g_PolicyCritSec);
  302. ASSERT(g_pCurrentPolicy != NULL);
  303. TRACEPRINT((LCTRACETYPE_API, "LCAssignPolicy: Session: %d, Assigning policy: %d", pWinStation->LogonId, g_pCurrentPolicy->GetId()));
  304. lpContext->pPolicy = g_pCurrentPolicy;
  305. lpContext->pPolicy->IncrementReference();
  306. RtlLeaveCriticalSection(&g_PolicyCritSec);
  307. RtlLeaveCriticalSection(&(lpContext->CritSec));
  308. TRACEPRINT((LCTRACETYPE_API, "LCAssignPolicy: Session: %d, Returning", pWinStation->LogonId));
  309. }
  310. extern "C"
  311. NTSTATUS
  312. LCCreateContext(
  313. PWINSTATION pWinStation
  314. )
  315. {
  316. LPLCCONTEXT lpContext;
  317. NTSTATUS Status;
  318. ASSERT(pWinStation != NULL);
  319. ASSERT(pWinStation->lpLicenseContext == NULL);
  320. TRACEPRINT((LCTRACETYPE_API, "LCCreateContext: Entered with Session: %d", pWinStation->LogonId));
  321. lpContext = (LPLCCONTEXT)LocalAlloc(LPTR, sizeof(LCCONTEXT));
  322. if (lpContext != NULL)
  323. {
  324. Status = RtlInitializeCriticalSection(&(lpContext->CritSec));
  325. if (Status == STATUS_SUCCESS)
  326. {
  327. TRACEPRINT((LCTRACETYPE_INFO, "LCCreateContext: Session: %d, Context initialized", pWinStation->LogonId));
  328. pWinStation->lpLicenseContext = (LPARAM)lpContext;
  329. }
  330. else
  331. {
  332. TRACEPRINT((LCTRACETYPE_ERROR, "LCCreateContext: Session: %d, Failed RtlInitializeCriticalSection: 0x%x", pWinStation->LogonId, Status));
  333. LocalFree(lpContext);
  334. }
  335. }
  336. else
  337. {
  338. TRACEPRINT((LCTRACETYPE_ERROR, "LCCreateContext: Session: %d, Failed lpContext allocation", pWinStation->LogonId));
  339. Status = STATUS_NO_MEMORY;
  340. }
  341. TRACEPRINT((LCTRACETYPE_API, "LCCreateContext: Session: %d, Returning 0x%x", pWinStation->LogonId, Status));
  342. return(Status);
  343. }
  344. extern "C"
  345. VOID
  346. LCDestroyContext(
  347. PWINSTATION pWinStation
  348. )
  349. {
  350. LPLCCONTEXT lpContext;
  351. ASSERT(pWinStation != NULL);
  352. TRACEPRINT((LCTRACETYPE_API, "LCDestroyContext: Entered with Session: %d", pWinStation->LogonId));
  353. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  354. if (lpContext != NULL)
  355. {
  356. TRACEPRINT((LCTRACETYPE_INFO, "LCDestroyContext: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  357. //
  358. // Idle winstations may not have a policy assigned.
  359. //
  360. if (lpContext->pPolicy != NULL)
  361. {
  362. TRACEPRINT((LCTRACETYPE_INFO, "LCDestroyContext: Session: %d, Policy: %d", pWinStation->LogonId, lpContext->pPolicy->GetId()));
  363. if (lpContext->lPrivate != NULL)
  364. {
  365. lpContext->pPolicy->DestroyPrivateContext(lpContext);
  366. }
  367. RtlEnterCriticalSection(&g_PolicyCritSec);
  368. lpContext->pPolicy->DecrementReference();
  369. RtlLeaveCriticalSection(&g_PolicyCritSec);
  370. lpContext->pPolicy = NULL;
  371. }
  372. }
  373. else
  374. {
  375. TRACEPRINT((LCTRACETYPE_INFO, "LCDestroyContext: Session: %d, lpContext is NULL", pWinStation->LogonId));
  376. goto exit;
  377. }
  378. //
  379. // The lPrivate member should have been freed and set to NULL by the
  380. // policy during the DestroyPrivateContext call.
  381. //
  382. ASSERT(lpContext->lPrivate == NULL);
  383. if (lpContext->hProtocolLibContext != NULL)
  384. {
  385. DeleteProtocolContext(lpContext->hProtocolLibContext);
  386. }
  387. if (lpContext->fLlsLicense)
  388. {
  389. NtLSFreeHandle(lpContext->hLlsLicense);
  390. }
  391. RtlDeleteCriticalSection(&(lpContext->CritSec));
  392. #if DBG
  393. RtlFillMemory(lpContext, sizeof(LCCONTEXT), (BYTE)0xFE);
  394. #endif
  395. LocalFree(lpContext);
  396. pWinStation->lpLicenseContext = (LPARAM)NULL;
  397. exit:
  398. TRACEPRINT((LCTRACETYPE_API, "LCDestroyContext: Session: %d, Returning", pWinStation->LogonId));
  399. }
  400. extern "C"
  401. NTSTATUS
  402. LCGetAvailablePolicyIds(
  403. PULONG *ppulPolicyIds,
  404. PULONG pcPolicies
  405. )
  406. {
  407. NTSTATUS Status;
  408. TRACEPRINT((LCTRACETYPE_API, "LCGetAvailablePolicyIds: Entered with ppulPolicyIds: 0x%p, pcPolicies: 0x%p", ppulPolicyIds, pcPolicies));
  409. ASSERT(ppulPolicyIds != NULL);
  410. ASSERT(pcPolicies != NULL);
  411. RtlEnterCriticalSection(&g_PolicyCritSec);
  412. Status = PolicyListEnumerateIds(ppulPolicyIds, pcPolicies);
  413. RtlLeaveCriticalSection(&g_PolicyCritSec);
  414. TRACEPRINT((LCTRACETYPE_API, "LCGetAvailablePolicyIds: Returning 0x%x", Status));
  415. return(Status);
  416. }
  417. extern "C"
  418. ULONG
  419. LCGetPolicy(
  420. VOID
  421. )
  422. {
  423. ULONG ulPolicyId;
  424. TRACEPRINT((LCTRACETYPE_API, "LCGetPolicy: Entered"));
  425. ASSERT(g_pCurrentPolicy != NULL);
  426. RtlEnterCriticalSection(&g_PolicyCritSec);
  427. ulPolicyId = g_pCurrentPolicy->GetId();
  428. RtlLeaveCriticalSection(&g_PolicyCritSec);
  429. TRACEPRINT((LCTRACETYPE_API, "LCGetPolicy: Returning %d", ulPolicyId));
  430. return(ulPolicyId);
  431. }
  432. extern "C"
  433. NTSTATUS
  434. LCGetPolicyInformation(
  435. ULONG ulPolicyId,
  436. LPLCPOLICYINFOGENERIC lpPolicyInfo
  437. )
  438. {
  439. CPolicy *pPolicy;
  440. NTSTATUS Status;
  441. TRACEPRINT((LCTRACETYPE_API, "LCGetPolicyInformation: Entered with ulPolicyId: %d, lpPolicyInfo: 0x%p", ulPolicyId, lpPolicyInfo));
  442. ASSERT(lpPolicyInfo != NULL);
  443. RtlEnterCriticalSection(&g_PolicyCritSec);
  444. pPolicy = PolicyListFindById(ulPolicyId);
  445. if (pPolicy != NULL)
  446. {
  447. Status = pPolicy->GetInformation(lpPolicyInfo);
  448. }
  449. else
  450. {
  451. Status = STATUS_INVALID_PARAMETER;
  452. }
  453. RtlLeaveCriticalSection(&g_PolicyCritSec);
  454. TRACEPRINT((LCTRACETYPE_API, "LCGetPolicyInformation: Returning 0x%x", Status));
  455. return(Status);
  456. }
  457. /*
  458. * Licensing Event Function Implementations
  459. */
  460. extern "C"
  461. NTSTATUS
  462. LCProcessConnectionProtocol(
  463. PWINSTATION pWinStation
  464. )
  465. {
  466. CSession Session(pWinStation);
  467. LICENSE_CAPABILITIES lcCap;
  468. LICENSE_STATUS LsStatus;
  469. LPLCCONTEXT lpContext;
  470. NTSTATUS Status;
  471. ULONG cbReturned;
  472. WCHAR szClientName[CLIENTNAME_LENGTH + 1];
  473. UINT32 dwClientError;
  474. ASSERT(pWinStation != NULL);
  475. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionProtocol: Entered with Session: %d", pWinStation->LogonId));
  476. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionProtocol: Session: %d, Current Policy ID: 0x%x", pWinStation->LogonId, g_pCurrentPolicy->GetId()));
  477. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  478. ASSERT(lpContext != NULL);
  479. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionProtocol: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  480. RtlEnterCriticalSection(&(lpContext->CritSec));
  481. //
  482. // Get the client capabilities.
  483. //
  484. ZeroMemory(&lcCap, sizeof(LICENSE_CAPABILITIES));
  485. lcCap.pbClientName = (LPBYTE)szClientName;
  486. lcCap.cbClientName = sizeof(szClientName);
  487. Status = _IcaStackIoControl(
  488. pWinStation->hStack,
  489. IOCTL_ICA_STACK_QUERY_LICENSE_CAPABILITIES,
  490. NULL,
  491. 0,
  492. &lcCap,
  493. sizeof(LICENSE_CAPABILITIES),
  494. &cbReturned
  495. );
  496. if (Status == STATUS_SUCCESS)
  497. {
  498. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionProtocol: Session: %d, Queried license capabilities", pWinStation->LogonId));
  499. //
  500. // Save the protocol version for later use.
  501. //
  502. lpContext->ulClientProtocolVersion = lcCap.ProtocolVer;
  503. }
  504. else
  505. {
  506. TRACEPRINT((LCTRACETYPE_ERROR, "LCProcessConnectionProtocol: Session: %d, Failed to query license capabilities: 0x%x", pWinStation->LogonId, Status));
  507. dwClientError = NtStatusToClientError(Status);
  508. goto error;
  509. }
  510. //
  511. // Create the protocol library context.
  512. //
  513. LsStatus = CreateProtocolContext(&lcCap, &(lpContext->hProtocolLibContext));
  514. if (LsStatus == LICENSE_STATUS_OK)
  515. {
  516. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionProtocol: Session: %d, Created protocol context", pWinStation->LogonId));
  517. //
  518. // Pass the call to the policy assigned to the connection.
  519. //
  520. Status = lpContext->pPolicy->Connect(Session, dwClientError);
  521. }
  522. else
  523. {
  524. TRACEPRINT((LCTRACETYPE_ERROR, "LCProcessConnectionProtocol: Session: %d, Failed to CreateProtocolContext: 0x%x", pWinStation->LogonId, LsStatus));
  525. dwClientError = LsStatusToClientError(LsStatus);
  526. Status = LsStatusToNtStatus(LsStatus);
  527. }
  528. #if DBG
  529. if (Status == STATUS_SUCCESS)
  530. {
  531. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionProtocol: Session: %d, Succeeded pPolicy->Protocol", pWinStation->LogonId));
  532. }
  533. else
  534. {
  535. TRACEPRINT((LCTRACETYPE_ERROR, "LCProcessConnectionProtocol: Session: %d, Failed pPolicy->Protocol: 0x%x", pWinStation->LogonId, Status));
  536. }
  537. #endif
  538. error:
  539. RtlLeaveCriticalSection(&(lpContext->CritSec));
  540. if (Status != STATUS_SUCCESS)
  541. {
  542. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionProtocol: Session: %d, Reporting: 0x%x", pWinStation->LogonId, dwClientError));
  543. Session.SetErrorInfo(dwClientError);
  544. }
  545. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionProtocol: Session: %d, Returning: 0x%x", pWinStation->LogonId, Status));
  546. return(Status);
  547. }
  548. extern "C"
  549. NTSTATUS
  550. LCProcessConnectionPostLogon(
  551. PWINSTATION pWinStation
  552. )
  553. {
  554. CSession Session(pWinStation);
  555. LPLCCONTEXT lpContext;
  556. NTSTATUS Status;
  557. ASSERT(pWinStation != NULL);
  558. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionPostLogon: Entered with Session: %d", pWinStation->LogonId));
  559. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  560. ASSERT(lpContext != NULL);
  561. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionPostLogon: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  562. RtlEnterCriticalSection(&(lpContext->CritSec));
  563. //
  564. // Pass the call to the policy assigned to the connection.
  565. //
  566. Status = lpContext->pPolicy->Logon(Session);
  567. #if DBG
  568. if (Status != STATUS_SUCCESS)
  569. {
  570. TRACEPRINT((LCTRACETYPE_ERROR, "LCProcessConnectionPostLogon: Session: %d, Failed to pPolicy->Logon: 0x%x", pWinStation->LogonId, Status));
  571. }
  572. #endif
  573. RtlLeaveCriticalSection(&(lpContext->CritSec));
  574. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionPostLogon: Session: %d, Returning: 0x%x", pWinStation->LogonId, Status));
  575. return(Status);
  576. }
  577. extern "C"
  578. NTSTATUS
  579. LCProcessConnectionDisconnect(
  580. PWINSTATION pWinStation
  581. )
  582. {
  583. CSession Session(pWinStation);
  584. LPLCCONTEXT lpContext;
  585. NTSTATUS Status;
  586. ASSERT(pWinStation != NULL);
  587. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionDisconnect: Entered with Session: %d", pWinStation->LogonId));
  588. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  589. //
  590. // Console licensing is not yet supported.
  591. //
  592. ASSERT(lpContext != NULL);
  593. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionDisconnect: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  594. RtlEnterCriticalSection(&(lpContext->CritSec));
  595. //
  596. // Pass the call to the policy assigned to the connection.
  597. //
  598. Status = lpContext->pPolicy->Disconnect(Session);
  599. #if DBG
  600. if (Status != STATUS_SUCCESS)
  601. {
  602. TRACEPRINT((LCTRACETYPE_ERROR, "LCProcessConnectionDisconnect: Session: %d, Failed to pPolicy->Disconnect: 0x%x", pWinStation->LogonId, Status));
  603. }
  604. #endif
  605. RtlLeaveCriticalSection(&(lpContext->CritSec));
  606. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionDisconnect: Session: %d, Returning: 0x%x", pWinStation->LogonId, Status));
  607. return(Status);
  608. }
  609. extern "C"
  610. NTSTATUS
  611. LCProcessConnectionReconnect(
  612. PWINSTATION pWinStation,
  613. PWINSTATION pTemporaryWinStation
  614. )
  615. {
  616. CSession Session(pWinStation);
  617. CSession TemporarySession(pTemporaryWinStation);
  618. LPLCCONTEXT lpContext;
  619. NTSTATUS Status;
  620. ASSERT(pWinStation != NULL);
  621. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionReconnect: Entered with Session: %d", pWinStation->LogonId));
  622. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  623. ASSERT(lpContext != NULL);
  624. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionReconnect: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  625. RtlEnterCriticalSection(&(lpContext->CritSec));
  626. //
  627. // Pass the call to the policy assigned to the connection.
  628. //
  629. Status = lpContext->pPolicy->Reconnect(Session, TemporarySession);
  630. #if DBG
  631. if (Status != STATUS_SUCCESS)
  632. {
  633. TRACEPRINT((LCTRACETYPE_ERROR, "LCProcessConnectionReconnect: Session: %d, Failed to pPolicy->Reconnect: 0x%x", pWinStation->LogonId, Status));
  634. }
  635. #endif
  636. RtlLeaveCriticalSection(&(lpContext->CritSec));
  637. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionReconnect: Session: %d, Returning: 0x%x", pWinStation->LogonId, Status));
  638. return(Status);
  639. }
  640. extern "C"
  641. NTSTATUS
  642. LCProcessConnectionLogoff(
  643. PWINSTATION pWinStation
  644. )
  645. {
  646. CSession Session(pWinStation);
  647. LPLCCONTEXT lpContext;
  648. NTSTATUS Status;
  649. ASSERT(pWinStation != NULL);
  650. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionLogoff: Entered with Session: %d", pWinStation->LogonId));
  651. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  652. ASSERT(lpContext != NULL);
  653. TRACEPRINT((LCTRACETYPE_INFO, "LCProcessConnectionLogoff: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  654. RtlEnterCriticalSection(&(lpContext->CritSec));
  655. //
  656. // Pass the call to the policy assigned to the connection.
  657. //
  658. Status = lpContext->pPolicy->Logoff(Session);
  659. #if DBG
  660. if (Status != STATUS_SUCCESS)
  661. {
  662. TRACEPRINT((LCTRACETYPE_ERROR, "LCProcessConnectionLogoff: Session: %d, Failed to pPolicy->Reconnect: 0x%x", pWinStation->LogonId, Status));
  663. }
  664. #endif
  665. RtlLeaveCriticalSection(&(lpContext->CritSec));
  666. TRACEPRINT((LCTRACETYPE_API, "LCProcessConnectionLogoff: Session: %d, Returning: 0x%x", pWinStation->LogonId, Status));
  667. return(Status);
  668. }
  669. extern "C"
  670. NTSTATUS
  671. LCProvideAutoLogonCredentials(
  672. PWINSTATION pWinStation,
  673. LPBOOL lpfUseCredentials,
  674. LPLCCREDENTIALS lpCredentials
  675. )
  676. {
  677. CSession Session(pWinStation);
  678. LPLCCONTEXT lpContext;
  679. NTSTATUS Status;
  680. ASSERT(pWinStation != NULL);
  681. ASSERT(lpfUseCredentials != NULL);
  682. ASSERT(lpCredentials != NULL);
  683. ASSERT(lpCredentials->pUserName == NULL);
  684. ASSERT(lpCredentials->pDomain == NULL);
  685. ASSERT(lpCredentials->pPassword == NULL);
  686. TRACEPRINT((LCTRACETYPE_API, "LCProvideAutoLogonCredentials: Entered with Session: %d", pWinStation->LogonId));
  687. lpContext = (LPLCCONTEXT)(pWinStation->lpLicenseContext);
  688. ASSERT(lpContext != NULL);
  689. TRACEPRINT((LCTRACETYPE_INFO, "LCProvideAutoLogonCredentials: Session: %d, lpContext: 0x%p", pWinStation->LogonId, lpContext));
  690. RtlEnterCriticalSection(&(lpContext->CritSec));
  691. //
  692. // Pass the call to the policy assigned to the connection.
  693. //
  694. Status = lpContext->pPolicy->AutoLogon(Session, lpfUseCredentials, lpCredentials);
  695. #if DBG
  696. if (Status != STATUS_SUCCESS)
  697. {
  698. TRACEPRINT((LCTRACETYPE_ERROR, "LCProvideAutoLogonCredentials: Session: %d, Failed to pPolicy->AutoLogon: 0x%x", pWinStation->LogonId, Status));
  699. }
  700. #endif
  701. RtlLeaveCriticalSection(&(lpContext->CritSec));
  702. TRACEPRINT((LCTRACETYPE_API, "LCProvideAutoLogonCredentials: Session: %d, Returning: 0x%x", pWinStation->LogonId, Status));
  703. return(Status);
  704. }