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.

177 lines
7.5 KiB

  1. /****************************************************************************/
  2. // slicense.c
  3. //
  4. // Server License Manager code
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #include <precomp.h>
  9. #pragma hdrstop
  10. #include "license.h"
  11. #include <slicense.h>
  12. #include <at120ex.h>
  13. /****************************************************************************/
  14. /* Name: SLicenseInit */
  15. /* */
  16. /* Purpose: Initialize License Manager */
  17. /* */
  18. /* Returns: Handle to be passed to subsequent License Manager functions */
  19. /* */
  20. /* Operation: LicenseInit is called during Server initialization. Its */
  21. /* purpose is to allow one-time initialization. It returns a */
  22. /* handle which is subsequently passed to all License Manager */
  23. /* functions. A typical use for this handle is as a pointer to */
  24. /* memory containing per-instance data. */
  25. /****************************************************************************/
  26. LPVOID _stdcall SLicenseInit(VOID)
  27. {
  28. PLicense_Handle pLicenseHandle;
  29. // create a license handle
  30. pLicenseHandle = ExAllocatePoolWithTag(PagedPool,
  31. sizeof(License_Handle),
  32. 'clST');
  33. if (pLicenseHandle != NULL) {
  34. pLicenseHandle->pDataBuf = NULL;
  35. pLicenseHandle->cbDataBuf = 0;
  36. pLicenseHandle->pCacheBuf = NULL;
  37. pLicenseHandle->cbCacheBuf = 0;
  38. // allocate memory for the data event and initialize the event
  39. pLicenseHandle->pDataEvent = ExAllocatePoolWithTag(NonPagedPool,
  40. sizeof(KEVENT), WD_ALLOC_TAG);
  41. if (pLicenseHandle->pDataEvent != NULL) {
  42. KeInitializeEvent(pLicenseHandle->pDataEvent, NotificationEvent,
  43. FALSE);
  44. }
  45. else {
  46. ExFreePool(pLicenseHandle);
  47. pLicenseHandle = NULL;
  48. }
  49. }
  50. else {
  51. KdPrint(("SLicenseInit: Failed to alloc License Handle\n"));
  52. }
  53. return (LPVOID)pLicenseHandle;
  54. }
  55. /****************************************************************************/
  56. /* Name: SLicenseData */
  57. /* */
  58. /* Purpose: Handle license data received from the Client */
  59. /* */
  60. /* Params: pHandle - handle returned by LicenseInit */
  61. /* pSMHandle - SM Handle */
  62. /* pData - data received from Client */
  63. /* dataLen - length of data received */
  64. /* */
  65. /* Operation: This function is passed all license packets received from the */
  66. /* Client. It should parse the packet and respond (by calling */
  67. /* suitable SM functions - see asmapi.h) as required. The SM */
  68. /* Handle is provided so that SM calls can be made. */
  69. /* */
  70. /* If license negotiation is complete and successful, the */
  71. /* License Manager must call SM_LicenseOK. */
  72. /* */
  73. /* If license negotiation is complete but unsuccessful, the */
  74. /* License Manager must disconnect the session. */
  75. /* */
  76. /* Incoming packets from the Client will continue to be */
  77. /* interpreted as license packets until SM_LicenseOK is called, */
  78. /* or the session is disconnected. */
  79. /****************************************************************************/
  80. void _stdcall SLicenseData(
  81. LPVOID pHandle,
  82. LPVOID pSMHandle,
  83. LPVOID pData,
  84. UINT dataLen)
  85. {
  86. PLicense_Handle pLicenseHandle;
  87. pLicenseHandle = (PLicense_Handle)pHandle;
  88. // only copy the incoming data if the buffer provided is large enough
  89. if (pLicenseHandle->cbDataBuf < dataLen)
  90. {
  91. // The provided data buffer is too small, we'll cache the data
  92. // for the caller.
  93. if (pLicenseHandle->pCacheBuf != NULL)
  94. {
  95. // free the previously cached data
  96. ExFreePool(pLicenseHandle->pCacheBuf);
  97. }
  98. // allocate new buffer to cache the data
  99. pLicenseHandle->pCacheBuf = ExAllocatePoolWithTag( PagedPool,
  100. dataLen,
  101. 'eciL' );
  102. if (pLicenseHandle->pCacheBuf != NULL) {
  103. memcpy(pLicenseHandle->pCacheBuf,
  104. pData,
  105. dataLen);
  106. pLicenseHandle->cbCacheBuf = dataLen;
  107. pLicenseHandle->Status = STATUS_BUFFER_TOO_SMALL;
  108. }
  109. else {
  110. pLicenseHandle->Status = STATUS_NO_MEMORY;
  111. }
  112. goto done;
  113. }
  114. // We got here because the caller has provided a buffer large enough to copy
  115. // copy the incoming data.
  116. if ((pLicenseHandle->pDataBuf) && (dataLen > 0))
  117. {
  118. memcpy(pLicenseHandle->pDataBuf,
  119. pData,
  120. dataLen);
  121. pLicenseHandle->cbDataBuf = dataLen;
  122. // set the status for this operation
  123. pLicenseHandle->Status = STATUS_SUCCESS;
  124. goto done;
  125. }
  126. done:
  127. // wake up the IOCTL waiting for incoming data
  128. KeSetEvent(pLicenseHandle->pDataEvent, 0, FALSE);
  129. }
  130. /****************************************************************************/
  131. /* Name: SLicenseTerm */
  132. /* */
  133. /* Purpose: Terminate Server License Manager */
  134. /* */
  135. /* Params: pHandle - handle returned from LicenseInit */
  136. /* */
  137. /* Operation: This function is provided to do one-time termination of the */
  138. /* License Manager. For example, if pHandle points to per- */
  139. /* instance memory, this would be a good place to free it. */
  140. /****************************************************************************/
  141. VOID _stdcall SLicenseTerm(LPVOID pHandle)
  142. {
  143. PLicense_Handle pLicenseHandle;
  144. pLicenseHandle = (PLicense_Handle)pHandle;
  145. if (pLicenseHandle != NULL) {
  146. if (pLicenseHandle->pCacheBuf != NULL)
  147. ExFreePool(pLicenseHandle->pCacheBuf);
  148. // free the memory for the data event and the license handle
  149. if (NULL != pLicenseHandle->pDataEvent)
  150. ExFreePool(pLicenseHandle->pDataEvent);
  151. ExFreePool(pLicenseHandle);
  152. }
  153. }