Source code of Windows XP (NT5)
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.

469 lines
11 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: server.h
  7. //
  8. // Contents: Hydra License Server Service Control Manager Interface
  9. //
  10. // History: 12-09-97 HueiWang Modified from MSDN RPC Service Sample
  11. // 07-27-98 HueiWang Port to JetBlue
  12. //
  13. //---------------------------------------------------------------------------
  14. #ifndef __SERVER_H_
  15. #define __SERVER_H_
  16. #include <windows.h>
  17. #include <winsock2.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <tchar.h>
  21. #include <time.h>
  22. #include "license.h"
  23. //
  24. // TLSDb
  25. //
  26. #include "JBDef.h"
  27. #include "JetBlue.h"
  28. #include "TLSDb.h"
  29. #include "backup.h"
  30. #include "KPDesc.h"
  31. #include "Licensed.h"
  32. #include "licpack.h"
  33. #include "version.h"
  34. #include "workitem.h"
  35. //
  36. // Current RPC interface
  37. //
  38. #include "tlsrpc.h"
  39. #include "tlsdef.h"
  40. #include "tlsapi.h"
  41. #include "tlsapip.h"
  42. #include "tlspol.h"
  43. //
  44. //
  45. #include "messages.h"
  46. #include "tlsassrt.h"
  47. #include "trust.h"
  48. #include "svcrole.h"
  49. #include "common.h"
  50. #include "lscommon.h"
  51. #include "Cryptkey.h"
  52. #include "licekpak.h"
  53. #include "clrhouse.h"
  54. #include "dblevel.h"
  55. #include "SrvDef.h"
  56. #include "policy.h"
  57. #include "wkspace.h"
  58. #include "tlsjob.h"
  59. #include "srvlist.h"
  60. #include "debug.h"
  61. #if DBG
  62. typedef enum {
  63. RPC_CALL_CONNECT,
  64. RPC_CALL_SEND_CERTIFICATE,
  65. RPC_CALL_GET_SERVERNAME,
  66. RPC_CALL_GET_SERVERSCOPE,
  67. RPC_CALL_GETINFO,
  68. RPC_CALL_GET_LASTERROR,
  69. RPC_CALL_ISSUEPLATFORMCHLLENGE,
  70. RPC_CALL_ALLOCATECONCURRENT,
  71. RPC_CALL_ISSUENEWLICENSE,
  72. RPC_CALL_UPGRADELICENSE,
  73. RPC_CALL_KEYPACKENUMBEGIN,
  74. RPC_CALL_KEYPACKENUMNEXT,
  75. RPC_CALL_KEYPACKENUMEND,
  76. RPC_CALL_KEYPACKADD,
  77. RPC_CALL_KEYPACKSETSTATUS,
  78. RPC_CALL_LICENSEENUMBEGIN,
  79. RPC_CALL_LICENSEENUMNEXT,
  80. RPC_CALL_LICENSEENUMEND,
  81. RPC_CALL_LICENSESETSTATUS,
  82. RPC_CALL_INSTALL_SERV_CERT,
  83. RPC_CALL_GETSERV_CERT,
  84. RPC_CALL_REGISTER_LICENSE_PACK,
  85. RPC_CALL_REQUEST_TERMSRV_CERT,
  86. RPC_CALL_RETRIEVE_TERMSRV_CERT,
  87. RPC_CALL_GETPKCS10CERT_REQUEST,
  88. RPC_CALL_ANNOUNCE_SERVER,
  89. RPC_CALL_SERVERLOOKUP,
  90. RPC_CALL_ANNOUNCELICENSEPACK,
  91. RPC_CALL_RETURNLICENSE,
  92. RPC_CALL_RETURNKEYPACK,
  93. RPC_CALL_GETPRIVATEDATA,
  94. RPC_CALL_SETPRIVATEDATA,
  95. RPC_CALL_CHALLENGESERVER,
  96. RPC_CALL_RESPONSESERVERCHALLENGE,
  97. RPC_CALL_TRIGGERREGENKEY,
  98. RPC_CALL_TELEPHONEREGISTERLKP,
  99. RPC_CALL_ALLOCATEINTERNETLICNESEEX,
  100. RPC_CALL_RETURNINTERNETLICENSEEX,
  101. RPC_CALL_RETURNINTERNETLICENSE
  102. } DBG_RPC_CALL;
  103. #endif
  104. //---------------------------------------------------------------------------
  105. typedef enum {
  106. LSCERT_RDN_STRING_TYPE,
  107. LSCERT_RDN_NAME_INFO_TYPE,
  108. LSCERT_RDN_NAME_BLOB_TYPE,
  109. LSCERT_CLIENT_INFO_TYPE
  110. } TLSCLIENTCERTRDNTYPE;
  111. typedef struct __LSClientInfo {
  112. LPTSTR szUserName;
  113. LPTSTR szMachineName;
  114. PHWID pClientID;
  115. } TLSClientInfo, *PTLSClientInfo, *LPTLSClientInfo;
  116. typedef struct __LSClientCertRDN {
  117. TLSCLIENTCERTRDNTYPE type;
  118. union {
  119. LPTSTR szRdn;
  120. PCERT_NAME_INFO pCertNameInfo;
  121. TLSClientInfo ClientInfo;
  122. PCERT_NAME_BLOB pNameBlob;
  123. };
  124. } TLSClientCertRDN, *PTLSClientCertRDN, *LPTLSClientCertRDN;
  125. //---------------------------------------------------------------------------
  126. typedef struct _DbLicensedProduct {
  127. DWORD dwQuantity;
  128. ULARGE_INTEGER ulSerialNumber;
  129. DWORD dwKeyPackId;
  130. DWORD dwLicenseId;
  131. DWORD dwKeyPackLicenseId;
  132. DWORD dwNumLicenseLeft;
  133. HWID ClientHwid;
  134. FILETIME NotBefore;
  135. FILETIME NotAfter;
  136. BOOL bTemp; // temporary license
  137. // licensed product version
  138. DWORD dwProductVersion;
  139. // manufaturer name
  140. TCHAR szCompanyName[LSERVER_MAX_STRING_SIZE+1];
  141. // licensed product Id
  142. TCHAR szLicensedProductId[LSERVER_MAX_STRING_SIZE+1];
  143. // original license request product ID
  144. TCHAR szRequestProductId[LSERVER_MAX_STRING_SIZE+1];
  145. TCHAR szUserName[LSERVER_MAX_STRING_SIZE+1];
  146. TCHAR szMachineName[LSERVER_MAX_STRING_SIZE+1];
  147. //
  148. DWORD dwLanguageID;
  149. DWORD dwPlatformID;
  150. PBYTE pbPolicyData;
  151. DWORD cbPolicyData;
  152. PCERT_PUBLIC_KEY_INFO pSubjectPublicKeyInfo;
  153. } TLSDBLICENSEDPRODUCT, *PTLSDBLICENSEDPRODUCT, *LPTLSDBLICENSEDPRODUCT;
  154. //---------------------------------------------------------------------------
  155. typedef struct __TLSDbLicenseRequest {
  156. CTLSPolicy* pPolicy;
  157. PMHANDLE hClient;
  158. //
  159. // Product request
  160. //
  161. DWORD dwProductVersion;
  162. LPTSTR pszCompanyName;
  163. LPTSTR pszProductId;
  164. DWORD dwLanguageID;
  165. DWORD dwPlatformID;
  166. //
  167. // Client information
  168. //
  169. HWID hWid;
  170. PBYTE pbEncryptedHwid;
  171. DWORD cbEncryptedHwid;
  172. TCHAR szMachineName[MAX_COMPUTERNAME_LENGTH + 2];
  173. TCHAR szUserName[MAXUSERNAMELENGTH+1];
  174. //
  175. // detail of licensing chain
  176. WORD wLicenseDetail;
  177. //
  178. // special things to be put into certificate
  179. //
  180. PCERT_PUBLIC_KEY_INFO pClientPublicKey;
  181. TLSClientCertRDN clientCertRdn;
  182. DWORD dwNumExtensions;
  183. PCERT_EXTENSION pExtensions;
  184. //
  185. // Policy Extension Data
  186. //
  187. //PBYTE pbPolicyExtensionData;
  188. //DWORD cbPolicyExtensionData;
  189. PPMLICENSEREQUEST pClientLicenseRequest; // original client license request
  190. PPMLICENSEREQUEST pPolicyLicenseRequest; // policy adjusted license request
  191. //
  192. // To do ?
  193. // consider a callback routine but are we getting
  194. // into issuing certificate business.
  195. //
  196. } TLSDBLICENSEREQUEST, *PTLSDBLICENSEREQUEST, *LPTLSDBLICENSEREQUEST;
  197. typedef struct __ForwardNewLicenseRequest {
  198. CHALLENGE_CONTEXT m_ChallengeContext;
  199. TLSLICENSEREQUEST* m_pRequest;
  200. LPTSTR m_szMachineName;
  201. LPTSTR m_szUserName;
  202. DWORD m_cbChallengeResponse;
  203. PBYTE m_pbChallengeResponse;
  204. // no forward on request.
  205. } TLSForwardNewLicenseRequest, *PTLSForwardNewLicenseRequest, *LPTLSForwardNewLicenseRequest;
  206. typedef struct __ForwardUpgradeRequest {
  207. TLSLICENSEREQUEST* m_pRequest;
  208. CHALLENGE_CONTEXT m_ChallengeContext;
  209. DWORD m_cbChallengeResponse;
  210. PBYTE m_pbChallengeResponse;
  211. DWORD m_cbOldLicense;
  212. PBYTE m_pbOldLicense;
  213. } TLSForwardUpgradeLicenseRequest, *PTLSForwardUpgradeLicenseRequest, *LPTLSForwardUpgradeLicenseRequest;
  214. //---------------------------------------------------------------------------
  215. //
  216. #define CLIENT_INFO_HYDRA_SERVER 0xFFFFFFFF
  217. typedef enum {
  218. CONTEXTHANDLE_EMPTY_TYPE=0,
  219. CONTEXTHANDLE_KEYPACK_ENUM_TYPE,
  220. CONTEXTHANDLE_LICENSE_ENUM_TYPE,
  221. CONTEXTHANDLE_CLIENTINFO_TYPE,
  222. CONTEXTHANDLE_CLIENTCHALLENGE_TYPE,
  223. CONTEXTHANDLE_HYDRA_REQUESTCERT_TYPE,
  224. CONTEXTHANDLE_CHALLENGE_SERVER_TYPE,
  225. CONTEXTHANDLE_CHALLENGE_LRWIZ_TYPE,
  226. CONTEXTHANDLE_CHALLENGE_TERMSRV_TYPE
  227. } CONTEXTHANDLE_TYPE;
  228. // No access
  229. #define CLIENT_ACCESS_NONE 0x00000000
  230. // only keypack/license enumeration
  231. #define CLIENT_ACCESS_USER 0x00000001
  232. // Administrator, can update value but can't
  233. // request license
  234. #define CLIENT_ACCESS_ADMIN 0x00000002
  235. // Client can request license no update
  236. // database value
  237. #define CLIENT_ACCESS_REQUEST 0x00000004
  238. // client is registration wizard
  239. // only install certificate
  240. #define CLIENT_ACCESS_LRWIZ 0x00000008
  241. // client is license server, allow
  242. // full access
  243. #define CLIENT_ACCESS_LSERVER 0xFFFFFFFF
  244. #define CLIENT_ACCESS_DEFAULT CLIENT_ACCESS_USER
  245. typedef struct __ClientContext {
  246. #if DBG
  247. DWORD m_PreDbg[2]; // debug signature
  248. DBG_RPC_CALL m_LastCall; // last call
  249. #endif
  250. LPTSTR m_Client;
  251. long m_RefCount;
  252. DWORD m_ClientFlags;
  253. DWORD m_LastError;
  254. CONTEXTHANDLE_TYPE m_ContextType;
  255. HANDLE m_ContextHandle;
  256. // NEEDED - A list to store all memory/handle
  257. // allocated for the client
  258. #if DBG
  259. DWORD m_PostDbg[2]; // debug signature
  260. #endif
  261. } CLIENTCONTEXT, *LPCLIENTCONTEXT;
  262. //---------------------------------------------------------------
  263. typedef struct __ENUMHANDLE {
  264. typedef enum {
  265. FETCH_NEXT_KEYPACK=1,
  266. FETCH_NEXT_KEYPACKDESC,
  267. FETCH_NEW_KEYPACKDESC
  268. } ENUM_FETCH_CODE;
  269. PTLSDbWorkSpace pbWorkSpace;
  270. TLSLICENSEPACK CurrentKeyPack; // current fetched keypack record
  271. LICPACKDESC KPDescSearchValue; // licensepack search value
  272. DWORD dwKPDescSearchParm; // licensepackdesc search parameter
  273. BOOL bKPDescMatchAll; // match all condition for keypackdesc
  274. CHAR chFetchState;
  275. } ENUMHANDLE, *LPENUMHANDLE;
  276. typedef struct __TERMSERVCERTREQHANDLE {
  277. PTLSHYDRACERTREQUEST pCertRequest;
  278. DWORD cbChallengeData;
  279. PBYTE pbChallengeData;
  280. } TERMSERVCERTREQHANDLE, *LPTERMSERVCERTREQHANDLE;
  281. typedef struct __ClientChallengeContext {
  282. DWORD m_ClientInfo;
  283. HANDLE m_ChallengeContext;
  284. } CLIENTCHALLENGECONTEXT, *LPCLIENTCHALLENGECONTEXT;
  285. typedef enum {
  286. ALLOCATE_EXACT_VERSION=0,
  287. ALLOCATE_ANY_GREATER_VERSION,
  288. ALLOCATE_LATEST_VERSION // not supported
  289. } LICENSE_ALLOCATION_SCHEME;
  290. typedef struct __AllocateRequest {
  291. UCHAR ucAgreementType; // keypack type
  292. LPTSTR szCompanyName; // company name
  293. LPTSTR szProductId; // product
  294. DWORD dwVersion; // version wanted
  295. DWORD dwPlatformId; // license platform
  296. DWORD dwLangId; // unused
  297. DWORD dwNumLicenses; // number of license wanted/returned
  298. LICENSE_ALLOCATION_SCHEME dwScheme;
  299. // TODO - CallBack function to let calling
  300. // function decide
  301. } TLSDBAllocateRequest, *PTLSDBAllocateRequest, *LPTLSDBAllocateRequest;
  302. typedef struct __LicenseAllocation {
  303. // array size for dwAllocationVector
  304. DWORD dwBufSize;
  305. //
  306. // Total license allocated
  307. DWORD dwTotalAllocated;
  308. // number of license allocate from
  309. // each keypack
  310. DWORD* pdwAllocationVector;
  311. // keypack that license allocate from
  312. PLICENSEPACK lpAllocateKeyPack;
  313. } TLSDBLicenseAllocation, *PTLSDBLicenseAllocation, *LPTLSDBLicenseAllocation;
  314. //---------------------------------------------------------------------
  315. //----------------------------------------------------------------------------
  316. #ifdef __cplusplus
  317. extern "C" {
  318. #endif
  319. BOOL
  320. WaitForMyTurnOrShutdown(
  321. HANDLE hHandle,
  322. DWORD dwWaitTime
  323. );
  324. HANDLE
  325. GetServiceShutdownHandle();
  326. void
  327. ServiceSignalShutdown();
  328. void
  329. ServiceResetShutdownEvent();
  330. BOOL
  331. AcquireRPCExclusiveLock(
  332. IN DWORD dwWaitTime
  333. );
  334. void
  335. ReleaseRPCExclusiveLock();
  336. BOOL
  337. AcquireAdministrativeLock(
  338. IN DWORD dwWaitTime
  339. );
  340. void
  341. ReleaseAdministrativeLock();
  342. DWORD
  343. TLSMapReturnCode(DWORD);
  344. unsigned int WINAPI
  345. MailSlotThread(
  346. void* ptr
  347. );
  348. HANDLE
  349. ServerInit(
  350. BOOL bDebug
  351. );
  352. DWORD
  353. InitNamedPipeThread();
  354. DWORD
  355. InitMailSlotThread();
  356. DWORD
  357. InitExpirePermanentThread();
  358. BOOL
  359. IsServiceShuttingdown();
  360. #ifdef __cplusplus
  361. }
  362. #endif
  363. void __cdecl
  364. trans_se_func(
  365. unsigned int u,
  366. _EXCEPTION_POINTERS* pExp
  367. );
  368. #endif