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.

298 lines
6.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: tls236.h
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #ifndef __TLSA02_H__
  13. #define __TLSA02_H__
  14. #include "tlsstl.h" // STL
  15. #include <stdio.h>
  16. #include <tchar.h>
  17. #include <assert.h>
  18. #include "tlsapi.h"
  19. #include "tlspol.h"
  20. #include "ntverp.h"
  21. #include "locks.h"
  22. #define US_IDS_COMPANYNAME _TEXT("Microsoft Corporation")
  23. #define US_IDS_EX_PRODUCTNAME _TEXT("Existing Windows Server - Terminal Services CAL Token (per device)")
  24. #define US_IDS_EX_PRODUCTDESC _TEXT("Existing Windows 2000 Server - Terminal Services CAL Token (per device)")
  25. #define US_IDS_S_PRODUCTNAME _TEXT("Windows Server - Terminal Server Per Device CAL Token")
  26. #define US_IDS_S_PRODUCTDESC _TEXT("Windows 2000 Server - Terminal Services CAL Token (per device)")
  27. #define US_IDS_S_PRODUCTDESC51 _TEXT("Windows Server 2003 - Terminal Server Per Device CAL Token")
  28. #define US_IDS_I_PRODUCTNAME _TEXT("Windows Server - Terminal Services Internet Connector License Token")
  29. #define US_IDS_I_PRODUCTDESC _TEXT("Windows 2000 Server - Terminal Services Internet Connector License Token")
  30. #define US_IDS_C_PRODUCTNAME _TEXT("Windows Server - Terminal Server Per User CAL Token")
  31. #define US_IDS_C_PRODUCTDESC51 _TEXT("Windows Server 2003 - Terminal Server Per User CAL Token")
  32. //
  33. // A02 Product ID
  34. //
  35. #define PLATFORMID_UPGRADE 1
  36. #define PLATFORMID_FREE 2
  37. #define PLATFORMID_OTHERS 0xFF // also used for Concurrent and Internet
  38. #define LSKEYPACK_LOCAL_TYPE 0x40
  39. //
  40. // 236 is for NT4 TS client.
  41. //
  42. #define TERMSERV_PRODUCTID_CH _TEXT("001")
  43. #define TERMSERV_PRODUCTID_SKU _TEXT("A02")
  44. #define TERMSERV_FULLVERSION_TYPE _TEXT("S")
  45. #define TERMSERV_FREE_TYPE _TEXT("EX")
  46. //
  47. // Internet Package
  48. //
  49. #define TERMSERV_INTERNET_CH _TEXT("002")
  50. #define TERMSERV_INTERNET_SKU _TEXT("B96")
  51. #define TERMSERV_INTERNET_TYPE _TEXT("I")
  52. //
  53. // Concurrent Package
  54. //
  55. #define TERMSERV_CONCURRENT_CH _TEXT("003")
  56. #define TERMSERV_CONCURRENT_SKU _TEXT("C50")
  57. #define TERMSERV_CONCURRENT_TYPE _TEXT("C")
  58. //
  59. // Whistler Package
  60. //
  61. #define TERMSERV_WHISTLER_PRODUCTID_CH _TEXT("004")
  62. #define TERMSERV_PRODUCTID_FORMAT _TEXT("%3s-%ld.%02ld-%s")
  63. #define TERMSERV_PRODUCTID_SCAN_FORMAT _TEXT("%3s-%ld.%02ld-%9s")
  64. #define MAX_TERMSRV_PRODUCTID LSERVER_MAX_STRING_SIZE
  65. //
  66. // keypack ID is ProductID+MajorVersion+MinorVersion+SerialNumber
  67. //
  68. #define TERMSERV_KEYPACKID_FORMAT _TEXT("%s%02d%02d%02d%d")
  69. #define TLSA02_VERSION (MAKELONG(MAKEWORD(0, HIBYTE(VER_PRODUCTVERSION_W)), 0))
  70. #define CURRENT_TLSA02_VERSION HIBYTE(LOWORD(TLSA02_VERSION))
  71. #define WINDOWS_VERSION_NT5 5
  72. #define WINDOWS_VERSION_BASE 2000
  73. #define MAX_SKU_PREFIX 10
  74. #define MAX_SKU_POSTFIX 10
  75. #define MALLOC(size) LocalAlloc(LPTR, size)
  76. #define FREE(ptr) \
  77. if(ptr) \
  78. { \
  79. LocalFree(ptr); \
  80. ptr=NULL; \
  81. }
  82. #define SAFESTRCPY(dest, source) \
  83. { \
  84. _tcsncpy(dest, source, min(_tcslen(source), sizeof(dest)/sizeof(TCHAR))); \
  85. dest[min(_tcslen(source), (sizeof(dest)/sizeof(TCHAR) - 1))] = _TEXT('\0'); \
  86. }
  87. #define STRBUFSIZE(x) (sizeof(x) / sizeof(x[0]))
  88. //---------------------------------------------------
  89. typedef enum {
  90. MEMORY_UNKNOWN,
  91. MEMORY_GENERAL,
  92. MEMORY_STRING,
  93. MEMORY_KEYPACKDESC,
  94. MEMORY_LICENSE_REQUEST,
  95. MEMORY_CERTEXTENSION,
  96. MEMORY_LICENSEREGISTRATION
  97. } MEMORYPOINTERTYPE;
  98. //----------------------------------------------------
  99. typedef struct __PointerType {
  100. MEMORYPOINTERTYPE m_MemoryType;
  101. HLOCAL m_Ptr;
  102. //-----------------------------------------
  103. __PointerType() :
  104. m_MemoryType(MEMORY_UNKNOWN),
  105. m_Ptr(NULL)
  106. {
  107. }
  108. //--------------------------------------
  109. __PointerType(
  110. MEMORYPOINTERTYPE ptrType,
  111. HLOCAL ptr
  112. ) :
  113. m_MemoryType(ptrType),
  114. m_Ptr(ptr)
  115. /*++
  116. ++*/
  117. {
  118. }
  119. //---------------------------------------
  120. PVOID
  121. GetPointer()
  122. {
  123. return m_Ptr;
  124. }
  125. } PointerType;
  126. //----------------------------------------------
  127. class CRefCounter {
  128. private:
  129. long m_RefCounter;
  130. public:
  131. CRefCounter() : m_RefCounter(0) {}
  132. ~CRefCounter()
  133. {
  134. if(DecRef() == 0)
  135. {
  136. delete this;
  137. }
  138. }
  139. long
  140. AddRef() {
  141. return InterlockedIncrement(&m_RefCounter);
  142. }
  143. long
  144. DecRef() {
  145. return InterlockedDecrement(&m_RefCounter);
  146. }
  147. };
  148. //---------------------------------------------
  149. class CClient {
  150. private:
  151. PMHANDLE m_hClient; // client handle
  152. //
  153. // list of memory allocated
  154. list<PointerType> m_AllocatedMemory;
  155. public:
  156. CClient(PMHANDLE hClient);
  157. ~CClient();
  158. //-----------------------------------------
  159. HLOCAL
  160. AllocateMemory(
  161. MEMORYPOINTERTYPE ptrType,
  162. DWORD dwSize
  163. );
  164. //-----------------------------------------
  165. PMHANDLE
  166. GetPMHANDLE() {
  167. return m_hClient;
  168. }
  169. };
  170. //------------------------------------------------------
  171. class CClientMgr {
  172. private:
  173. CCriticalSection m_HandleMapLock;
  174. typedef map<PMHANDLE, CClient*, less<PMHANDLE> > MapHandleToClient;
  175. MapHandleToClient m_HandleMap;
  176. public:
  177. CClientMgr() {}
  178. ~CClientMgr();
  179. void
  180. Cleanup();
  181. CClient*
  182. FindClient(PMHANDLE hClient);
  183. BOOL
  184. DestroyClient(PMHANDLE hClient);
  185. };
  186. #ifdef __cplusplus
  187. extern "C" {
  188. #endif
  189. void
  190. InitPolicyModule(
  191. IN HMODULE
  192. );
  193. BOOL
  194. LoadResourceString(
  195. IN DWORD dwId,
  196. IN OUT LPTSTR szBuf,
  197. IN DWORD dwBufSize
  198. );
  199. DWORD
  200. AddA02KeyPack(
  201. DWORD dwVersion
  202. );
  203. DWORD
  204. InsertLicensePack(
  205. IN TLS_HANDLE tlsHandle,
  206. IN DWORD dwProdVersion,
  207. IN DWORD dwDescVersion,
  208. IN DWORD dwPlatformType,
  209. IN UCHAR ucAgreementType,
  210. IN LPTSTR pszProductId,
  211. IN LPTSTR pszKeyPackId,
  212. IN LPTSTR pszUsDesc[],
  213. IN LPTSTR pszLocalizedDesc[]
  214. );
  215. POLICYSTATUS
  216. ProcessUpgradeRequest(
  217. PMHANDLE hClient,
  218. PPMUPGRADEREQUEST pUpgrade,
  219. PPMLICENSEREQUEST* pbAdjustedRequest,
  220. PDWORD pdwErrCode,
  221. DWORD dwIndex
  222. );
  223. BOOL LicenseTypeFromLookupTable(
  224. IN DWORD dwClientVer,
  225. IN DWORD dwTermSrvVer,
  226. OUT PDWORD pdwCALType
  227. );
  228. #ifdef __cplusplus
  229. }
  230. #endif
  231. #endif