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.

1239 lines
32 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1996
  5. //
  6. // File: rpc.c
  7. //
  8. // Contents: Various RPC function to accept client request
  9. //
  10. // History: 12-09-98 HueiWang Created
  11. // 05-26-98 HueiWang Move all code to TLSRpcXXX
  12. // API here is only for compatible with
  13. // NT40 Hydra
  14. //---------------------------------------------------------------------------
  15. #include "pch.cpp"
  16. #include "globals.h"
  17. #include "server.h"
  18. #include "init.h"
  19. //+------------------------------------------------------------------------
  20. error_status_t
  21. LSGetRevokeKeyPackList(
  22. /* [in] */ PCONTEXT_HANDLE phContext,
  23. /* [out][in] */ PDWORD pcbNumberOfKeyPack,
  24. /* [size_is][out][in] */ PDWORD pRevokeKeyPackList
  25. )
  26. /*
  27. Note : For backward compatible with NT40 Hydra only
  28. */
  29. {
  30. *pcbNumberOfKeyPack=0;
  31. return ERROR_SUCCESS;
  32. }
  33. //+------------------------------------------------------------------------
  34. error_status_t
  35. LSGetRevokeLicenseList(
  36. /* [in] */ PCONTEXT_HANDLE phContext,
  37. /* [out][in] */ PDWORD pcbNumberOfLicenses,
  38. /* [size_is][out][in] */ PDWORD pRevokeLicenseList
  39. )
  40. /*
  41. Note : For backward compatible with NT40 Hydra only
  42. */
  43. {
  44. *pcbNumberOfLicenses=0;
  45. return ERROR_SUCCESS;
  46. }
  47. //+------------------------------------------------------------------------
  48. error_status_t
  49. LSValidateLicense(
  50. /* [in] */ PCONTEXT_HANDLE phContext,
  51. /* [in] */ DWORD cbLicense,
  52. /* [size_is][in] */ BYTE __RPC_FAR *pbLicense
  53. )
  54. /*
  55. Note : For backward compatible with NT40 Hydra only
  56. */
  57. {
  58. return TLSMapReturnCode(TLS_E_NOTSUPPORTED);
  59. }
  60. //+------------------------------------------------------------------------
  61. error_status_t
  62. LSConnect(
  63. /* [in] */ handle_t hRpcBinding,
  64. /* [out] */ PCONTEXT_HANDLE __RPC_FAR *pphContext
  65. )
  66. {
  67. return TLSRpcConnect( hRpcBinding, pphContext );
  68. }
  69. //-----------------------------------------------------------------------
  70. error_status_t
  71. LSSendServerCertificate(
  72. /* [in] */ PCONTEXT_HANDLE phContext,
  73. /* [in] */ DWORD cbCert,
  74. /* [size_is][in] */ PBYTE pbCert
  75. )
  76. {
  77. DWORD status = ERROR_SUCCESS;
  78. TLSRpcSendServerCertificate(
  79. phContext,
  80. cbCert,
  81. pbCert,
  82. &status
  83. );
  84. return status;
  85. }
  86. //+------------------------------------------------------------------------
  87. error_status_t
  88. LSDisconnect(
  89. /* [out][in] */ PPCONTEXT_HANDLE pphContext
  90. )
  91. {
  92. return TLSRpcDisconnect(pphContext);
  93. }
  94. //+------------------------------------------------------------------------
  95. error_status_t
  96. LSGetServerName(
  97. /* [in] */ PCONTEXT_HANDLE phContext,
  98. /* [size_is][string][out][in] */ LPTSTR szMachineName,
  99. /* [out][in] */ PDWORD pcbSize
  100. )
  101. /*
  102. Description :
  103. Return Server's Machine Name.
  104. Arguments:
  105. phContext - client context handle.
  106. szMachineName - Pointer to a buffer that receives a null-terminated
  107. string containing the computer name. The buffer size
  108. should be large enough to contain
  109. MAX_COMPUTERNAME_LENGTH + 1 characters.
  110. cbSize - Pointer to a DWORD variable. On input, the variable
  111. specifies the size, in bytes or characters, of the buffer.
  112. On output, the variable returns the number of bytes or characters
  113. copied to the destination buffer, not including the terminating
  114. null character.
  115. Returns:
  116. LSERVER_S_SUCCESS
  117. */
  118. {
  119. DWORD dwErrCode=ERROR_SUCCESS;
  120. TLSRpcGetServerName(
  121. phContext,
  122. szMachineName,
  123. pcbSize,
  124. &dwErrCode
  125. );
  126. return dwErrCode;
  127. }
  128. //+------------------------------------------------------------------------
  129. error_status_t
  130. LSGetServerScope(
  131. /* [in] */ PCONTEXT_HANDLE phContext,
  132. /* [size_is][string][out][in] */ LPTSTR szScopeName,
  133. /* [out][in] */ PDWORD pcbSize
  134. )
  135. /*
  136. Description:
  137. Return License Server's scope
  138. Arguments:
  139. IN phContext - Client context
  140. IN OUT szScopeName - return server's scope, must be at least
  141. MAX_COMPUTERNAME_LENGTH in length
  142. Return Value:
  143. LSERVER_S_SUCCESS or error code from WideCharToMultiByte()
  144. */
  145. {
  146. DWORD status=ERROR_SUCCESS;
  147. TLSRpcGetServerScope(
  148. phContext,
  149. szScopeName,
  150. pcbSize,
  151. &status
  152. );
  153. return status;
  154. }
  155. //+------------------------------------------------------------------------
  156. error_status_t
  157. LSGetInfo(
  158. /* [in] */ PCONTEXT_HANDLE phContext,
  159. /* [in] */ DWORD cbHSCert,
  160. /* [size_is][ref][in] */ PBYTE pHSCert,
  161. /* [ref][out] */ PDWORD pcbLSCert,
  162. /* [size_is][size_is][out] */ BYTE __RPC_FAR *__RPC_FAR *pLSCert,
  163. /* [ref][out] */ PDWORD pcbLSSecretKey,
  164. /* [size_is][size_is][out] */ BYTE __RPC_FAR *__RPC_FAR *pLSSecretKey
  165. )
  166. /*
  167. Description:
  168. Routine to exchange Hydra server's certificate and License server's
  169. certificate/private key for signing client machine's hardware ID.
  170. Arguments:
  171. IN phContext - client context handle
  172. IN cbHSCert - size of Hydra Server's certificate
  173. IN pHSCert - Hydra Server's certificate
  174. IN OUT pcbLSCert - return size of License Server's certificate
  175. OUT pLSCert - return License Server's certificate
  176. OUT pcbLSSecretKey - return size of License Server's private key.
  177. OUT pLSSecretKey - retrun License Server's private key
  178. Return Value:
  179. LSERVER_S_SUCCESS success
  180. LSERVER_E_INVALID_DATA Invalid hydra server certificate
  181. LSERVER_E_OUTOFMEMORY Can't allocate required memory
  182. TLS_E_INTERNAL Internal error occurred in License Server
  183. */
  184. {
  185. DWORD status=ERROR_SUCCESS;
  186. TLSRpcGetInfo(
  187. phContext,
  188. cbHSCert,
  189. pHSCert,
  190. pcbLSCert,
  191. pLSCert,
  192. pcbLSSecretKey,
  193. pLSSecretKey,
  194. &status
  195. );
  196. return status;
  197. }
  198. //+------------------------------------------------------------------------
  199. error_status_t
  200. LSGetLastError(
  201. /* [in] */ PCONTEXT_HANDLE phContext,
  202. /* [in] */ DWORD cbBufferSize,
  203. /* [string][out][in] */ LPTSTR szBuffer
  204. )
  205. /*
  206. Description:
  207. Return error description text for client's last LSXXX call
  208. Arguments:
  209. IN phContext - Client context
  210. IN cbBufferSize - max. size of szBuffer
  211. IN OUT szBuffer - Pointer to a buffer to receive the
  212. null-terminated character string containing
  213. error description
  214. Note:
  215. Return ANSI error string.
  216. Returns:
  217. LSERVER_S_SUCCESS
  218. TLS_E_INTERNAL No error or can't find corresponding error
  219. description.
  220. Error code from WideCharToMultiByte().
  221. */
  222. {
  223. DWORD status;
  224. TLSRpcGetLastError(
  225. phContext,
  226. &cbBufferSize,
  227. szBuffer,
  228. &status
  229. );
  230. return status;
  231. }
  232. //+------------------------------------------------------------------------
  233. error_status_t
  234. LSIssuePlatformChallenge(
  235. /* [in] */ PCONTEXT_HANDLE phContext,
  236. /* [in] */ DWORD dwClientInfo,
  237. /* [ref][out] */ PCHALLENGE_CONTEXT pChallengeContext,
  238. /* [out] */ PDWORD pcbChallengeData,
  239. /* [size_is][size_is][out] */ BYTE __RPC_FAR *__RPC_FAR *pChallengeData
  240. )
  241. /*
  242. Description:
  243. Issue a platform challenge to hydra client.
  244. Arguments:
  245. IN phContext - client context handle
  246. IN dwClientInfo - client info.
  247. OUT pChallengeContext - pointer to client challenge context.
  248. OUT pcbChallengeData - size of challenge data.
  249. OUT pChallengeData - random client challenge data.
  250. Returns:
  251. LSERVER_S_SUCCESS
  252. LSERVER_E_OUTOFMEMORY
  253. LSERVER_E_INVALID_DATA Invalid client info.
  254. LSERVER_E_SERVER_BUSY
  255. */
  256. {
  257. DWORD status=ERROR_SUCCESS;
  258. TLSRpcIssuePlatformChallenge(
  259. phContext,
  260. dwClientInfo,
  261. pChallengeContext,
  262. pcbChallengeData,
  263. pChallengeData,
  264. &status
  265. );
  266. return status;
  267. }
  268. //+------------------------------------------------------------------------
  269. error_status_t
  270. LSAllocateConcurrentLicense(
  271. /* [in] */ PCONTEXT_HANDLE phContext,
  272. /* [string][in] */ LPTSTR szHydraServer,
  273. /* [in] */ LICENSE_REQUEST_TYPE __RPC_FAR *pRequest,
  274. /* [ref][out][in] */ LONG __RPC_FAR *dwQuantity
  275. )
  276. /*
  277. Description:
  278. Allocate concurrent licenses base on product.
  279. Arguments:
  280. IN phContext - client context handle
  281. IN szHydraServer - name of hydra server requesting concurrent licenses
  282. IN pRequest - product to request for concurrent license.
  283. IN OUT dwQuantity - See note
  284. Return Value:
  285. LSERVER_S_SUCCESS
  286. LSERVER_E_INVALID_DATA Invalid parameter.
  287. LSERVER_E_NO_PRODUCT request product not installed
  288. LSERVER_E_NO_LICNESE no available license for request product
  289. LSERVER_E_LICENSE_REVOKED Request license has been revoked
  290. LSERVER_E_LICENSE_EXPIRED Request license has expired
  291. LSERVER_E_CORRUPT_DATABASE Corrupt database
  292. LSERVER_E_INTERNAL_ERROR Internal error in license server
  293. Note:
  294. dwQuantity
  295. Input Output
  296. ------------------------- -----------------------------------------
  297. 0 Total number of concurrent license
  298. issued to hydra server.
  299. > 0, number of license Actual number of license allocated
  300. requested
  301. < 0, number of license Actual number of license returned, always
  302. to return positive value.
  303. */
  304. {
  305. DWORD status=ERROR_SUCCESS;
  306. TLSLICENSEREQUEST RpcRequest;
  307. RequestToTlsRequest(pRequest, &RpcRequest);
  308. TLSRpcAllocateConcurrentLicense(
  309. phContext,
  310. szHydraServer,
  311. &RpcRequest,
  312. dwQuantity,
  313. &status
  314. );
  315. return status;
  316. }
  317. //+------------------------------------------------------------------------
  318. error_status_t
  319. LSIssueNewLicense(
  320. /* [in] */ PCONTEXT_HANDLE phContext,
  321. /* [in] */ CHALLENGE_CONTEXT ChallengeContext,
  322. /* [in] */ LICENSE_REQUEST_TYPE __RPC_FAR *pRequest_org,
  323. /* [string][in] */ LPTSTR szMachineName,
  324. /* [string][in] */ LPTSTR szUserName,
  325. /* [in] */ DWORD cbChallengeResponse,
  326. /* [size_is][in] */ PBYTE cbChallenge,
  327. /* [in] */ BOOL bAcceptTemporaryLicense,
  328. /* [out] */ PDWORD pcbLicense,
  329. /* [size_is][size_is][out] */ BYTE __RPC_FAR *__RPC_FAR *ppLicense
  330. )
  331. /*
  332. Description:
  333. Routine to issue new license to hydra client based on product requested,
  334. it returns existing license if client already has a license and the
  335. license is not expired/returned/revoked, if request product has not been
  336. installed, it will issue a temporary license, if license found is temporary
  337. or expired, it will tried to upgrade/re-issue a new license with latest
  338. version of requested product, if the existing license is temporary and
  339. no license can be issued, it returns LSERVER_E_LICENSE_EXPIRED
  340. Arguments:
  341. IN phContext - client context handle.
  342. IN ChallengeContext - client challenge context handle, return from
  343. call LSIssuePlatformChallenge()
  344. IN cbChallengeResponse - size of the client's response to license server's
  345. platform challenge.
  346. IN pbChallenge - client's response to license server's platform challenge
  347. OUT pcbLicense - size of return license.
  348. OUT ppLicense - return license, could be old license
  349. Return Value:
  350. LSERVER_S_SUCCESS
  351. LSERVER_E_OUTOFMEMORY
  352. LSERVER_E_SERVER_BUSY Server is busy to process request.
  353. LSERVER_E_INVALID_DATA Invalid platform challenge response.
  354. LSERVER_E_NO_LICENSE No license available.
  355. LSERVER_E_NO_PRODUCT Request product is not installed on server.
  356. LSERVER_E_LICENSE_REJECTED License request is rejected by cert. server
  357. LSERVER_E_LICENSE_REVOKED Old license found and has been revoked
  358. LSERVER_E_LICENSE_EXPIRED Request product's license has expired
  359. LSERVER_E_CORRUPT_DATABASE Corrupted database.
  360. LSERVER_E_INTERNAL_ERROR Internal error in license server
  361. LSERVER_I_PROXIMATE_LICENSE Closest match license returned.
  362. LSERVER_I_TEMPORARY_LICENSE Temporary license has been issued
  363. LSERVER_I_LICENSE_UPGRADED Old license has been upgraded.
  364. */
  365. {
  366. DWORD status=ERROR_SUCCESS;
  367. TLSLICENSEREQUEST RpcRequest;
  368. RequestToTlsRequest(pRequest_org, &RpcRequest);
  369. TLSRpcRequestNewLicense(
  370. phContext,
  371. ChallengeContext,
  372. &RpcRequest,
  373. szMachineName,
  374. szUserName,
  375. cbChallengeResponse,
  376. cbChallenge,
  377. bAcceptTemporaryLicense,
  378. pcbLicense,
  379. ppLicense,
  380. &status
  381. );
  382. return status;
  383. }
  384. //+------------------------------------------------------------------------
  385. error_status_t
  386. LSUpgradeLicense(
  387. /* [in] */ PCONTEXT_HANDLE phContext,
  388. /* [in] */ DWORD cbOldLicense,
  389. /* [size_is][in] */ PBYTE pbOldLicense,
  390. /* [in] */ DWORD dwClientInfo,
  391. /* [out] */ PDWORD pcbNewLicense,
  392. /* [size_is][size_is][out] */ PBYTE __RPC_FAR *ppbNewLicense
  393. )
  394. /*
  395. Description:
  396. Update an old license.
  397. Arguments:
  398. IN phContext - client context handle.
  399. IN cbOldLicense - size of license to be upgraded.
  400. IN pOldLicense - license to be upgrade.
  401. OUT pcbNewLicense - size of upgraded license
  402. OUT pNewLicense - upgraded license.
  403. Return Value:
  404. LSERVER_S_SUCCESS
  405. TLS_E_INTERNAL
  406. LSERVER_E_INTERNAL_ERROR
  407. LSERVER_E_INVALID_DATA old license is invalid.
  408. LSERVER_E_NO_LICENSE no available license
  409. LSERVER_E_NO_PRODUCT request product not install in current server.
  410. LSERVER_E_CORRUPT_DATABASE Corrupted database.
  411. LSERVER_E_LICENSE_REJECTED License request rejected by cert. server.
  412. LSERVER_E_SERVER_BUSY
  413. Note:
  414. Only support upgrading temporary license to permanent license.
  415. */
  416. {
  417. DWORD status = ERROR_SUCCESS;
  418. PBYTE pbEncodedCert=NULL;
  419. DWORD cbEncodedCert=0;
  420. BOOL bTemporaryLicense;
  421. LPCLIENTCONTEXT lpContext = (LPCLIENTCONTEXT)phContext;
  422. DWORD dwNumLicensedProduct=0;
  423. PLICENSEDPRODUCT pLicensedProduct=NULL;
  424. DBGPrintf(
  425. DBG_INFORMATION,
  426. DBG_FACILITY_RPC,
  427. DBGLEVEL_FUNCTION_TRACE,
  428. _TEXT("%s : LSUpgradeLicense\n"),
  429. lpContext->m_Client
  430. );
  431. InterlockedIncrement( &lpContext->m_RefCount );
  432. do {
  433. if(!(lpContext->m_ClientFlags & CLIENT_ACCESS_REQUEST))
  434. {
  435. status = TLS_E_ACCESS_DENIED;
  436. break;
  437. }
  438. if(CanIssuePermLicense() == FALSE)
  439. {
  440. // no upgrade if certificate not available
  441. status = TLS_E_NO_CERTIFICATE;
  442. break;
  443. }
  444. //
  445. // convert license back to product request structure.
  446. //
  447. status=LSVerifyDecodeClientLicense(
  448. pbOldLicense,
  449. cbOldLicense,
  450. g_pbSecretKey,
  451. g_cbSecretKey,
  452. &dwNumLicensedProduct,
  453. pLicensedProduct
  454. );
  455. if(status != LICENSE_STATUS_OK)
  456. {
  457. break;
  458. }
  459. pLicensedProduct = (PLICENSEDPRODUCT)AllocateMemory(
  460. dwNumLicensedProduct * sizeof(LICENSEDPRODUCT)
  461. );
  462. if(pLicensedProduct == NULL)
  463. {
  464. status = GetLastError();
  465. break;
  466. }
  467. status=LSVerifyDecodeClientLicense(
  468. pbOldLicense,
  469. cbOldLicense,
  470. g_pbSecretKey,
  471. g_cbSecretKey,
  472. &dwNumLicensedProduct,
  473. pLicensedProduct
  474. );
  475. if(status != LICENSE_STATUS_OK)
  476. {
  477. break;
  478. }
  479. RPC_STATUS rpcStatus;
  480. TLSLICENSEREQUEST request;
  481. RequestToTlsRequest(&pLicensedProduct->LicensedProduct, &request);
  482. if( (_tcsnicmp(
  483. _TEXT(HYDRA_PRODUCTID_SKU),
  484. (LPTSTR)pLicensedProduct->LicensedProduct.pProductInfo->pbProductID,
  485. _tcslen(_TEXT(HYDRA_PRODUCTID_SKU)) ) == 0) ||
  486. (_tcsnicmp(
  487. TERMSERV_PRODUCTID_SKU,
  488. (LPTSTR)pLicensedProduct->LicensedProduct.pProductInfo->pbProductID,
  489. _tcslen(TERMSERV_PRODUCTID_SKU) ) == 0) )
  490. {
  491. //
  492. // Terminal Server client specific code
  493. //
  494. request.ProductInfo.pbProductID = (PBYTE) TERMSERV_PRODUCTID_SKU;
  495. request.ProductInfo.cbProductID = (DWORD) (_tcslen(TERMSERV_PRODUCTID_SKU) + 1) * sizeof(TCHAR);
  496. request.dwPlatformID = dwClientInfo;
  497. }
  498. rpcStatus = TLSRpcUpgradeLicense(
  499. phContext,
  500. &request,
  501. TLSERVER_CHALLENGE_CONTEXT,
  502. 0,
  503. NULL,
  504. cbOldLicense,
  505. pbOldLicense,
  506. pcbNewLicense,
  507. ppbNewLicense,
  508. &status
  509. );
  510. } while(FALSE);
  511. if( (status == LSERVER_E_NO_PRODUCT || status == LSERVER_E_NO_LICENSE)
  512. && (pLicensedProduct != NULL) && (pLicensedProduct->pLicensedVersion != NULL)
  513. && !(pLicensedProduct->pLicensedVersion->dwFlags & LICENSED_VERSION_TEMPORARY) )
  514. {
  515. //
  516. // backward compatible - always returns success in the case of perm. license
  517. //
  518. *ppbNewLicense = (PBYTE)midl_user_allocate(cbOldLicense);
  519. if(*ppbNewLicense != NULL)
  520. {
  521. memcpy(*ppbNewLicense, pbOldLicense, cbOldLicense);
  522. *pcbNewLicense = cbOldLicense;
  523. status = ERROR_SUCCESS;
  524. }
  525. else
  526. {
  527. status = TLS_E_ALLOCATE_MEMORY;
  528. }
  529. }
  530. //if(pbSaveData != NULL)
  531. //{
  532. // pLicensedProduct->pbOrgProductID = pbSaveData;
  533. // pLicensedProduct->cbOrgProductID = cbSaveData;
  534. //}
  535. for(DWORD index =0; index < dwNumLicensedProduct; index++)
  536. {
  537. LSFreeLicensedProduct(pLicensedProduct+index);
  538. }
  539. FreeMemory(pLicensedProduct);
  540. lpContext->m_LastError=status;
  541. InterlockedDecrement( &lpContext->m_RefCount );
  542. // midl_user_free(pOldLicense);
  543. #if DBG
  544. lpContext->m_LastCall = RPC_CALL_UPGRADELICENSE;
  545. #endif
  546. return status;
  547. }
  548. //+------------------------------------------------------------------------
  549. error_status_t
  550. LSKeyPackEnumBegin(
  551. /* [in] */ PCONTEXT_HANDLE phContext,
  552. /* [in] */ DWORD dwSearchParm,
  553. /* [in] */ BOOL bMatchAll,
  554. /* [ref][in] */ LPLSKeyPackSearchParm lpSearchParm
  555. )
  556. /*
  557. Description:
  558. Function to begin enumerate through all key pack installed on server
  559. based on search criterial.
  560. Arguments:
  561. IN phContext - client context handle.
  562. IN dwSearchParm - search criterial.
  563. IN bMatchAll - match all search criterial.
  564. IN lpSearchParm - search parameter.
  565. Return Value:
  566. LSERVER_S_SUCCESS
  567. LSERVER_E_SERVER_BUSY Server is too busy to process request
  568. LSERVER_E_OUTOFMEMORY
  569. TLS_E_INTERNAL
  570. LSERVER_E_INTERNAL_ERROR
  571. LSERVER_E_INVALID_DATA Invalid data in search parameter
  572. LSERVER_E_INVALID_SEQUENCE Invalid calling sequence, likely, previous
  573. enumeration has not ended.
  574. */
  575. {
  576. DWORD status=ERROR_SUCCESS;
  577. TLSRpcKeyPackEnumBegin(
  578. phContext,
  579. dwSearchParm,
  580. bMatchAll,
  581. lpSearchParm,
  582. &status
  583. );
  584. return status;
  585. }
  586. //+------------------------------------------------------------------------
  587. DWORD
  588. LSKeyPackEnumNext(
  589. /* [in] */ PCONTEXT_HANDLE phContext,
  590. /* [ref][out] */ LPLSKeyPack lpKeyPack
  591. )
  592. /*
  593. Description:
  594. Return next key pack that match search criterial
  595. Arguments:
  596. IN phContext - client context handle
  597. OUT lpKeyPack - key pack that match search criterial
  598. Return Value:
  599. LSERVER_S_SUCCESS
  600. LSERVER_I_NO_MORE_DATA No more keypack match search criterial
  601. TLS_E_INTERNAL General error in license server
  602. LSERVER_E_INTERNAL_ERROR Internal error in license server
  603. LSERVER_E_SERVER_BUSY License server is too busy to process request
  604. LSERVER_E_OUTOFMEMORY Can't process request due to insufficient memory
  605. LSERVER_E_INVALID_SEQUENCE Invalid calling sequence, must call
  606. LSKeyPackEnumBegin().
  607. */
  608. {
  609. DWORD status=ERROR_SUCCESS;
  610. TLSRpcKeyPackEnumNext(
  611. phContext,
  612. lpKeyPack,
  613. &status
  614. );
  615. return status;
  616. }
  617. //+------------------------------------------------------------------------
  618. error_status_t
  619. LSKeyPackEnumEnd(
  620. /* [in] */ PCONTEXT_HANDLE phContext
  621. )
  622. /*
  623. Description:
  624. Routine to end an enumeration on key pack.
  625. Arguments:
  626. IN phContext - client context handle.
  627. Return Value:
  628. LSERVER_S_SUCCESS
  629. LSERVER_E_INTERNAL_ERROR Internal error occurred in license server
  630. TLS_E_INTERNAL General error occurred in license server
  631. LSERVER_E_INVALID_HANDLE Has not call LSKeyPackEnumBegin()
  632. */
  633. {
  634. DWORD status=ERROR_SUCCESS;
  635. TLSRpcKeyPackEnumEnd(phContext, &status);
  636. return status;
  637. }
  638. //+------------------------------------------------------------------------
  639. error_status_t
  640. LSKeyPackAdd(
  641. /* [in] */ PCONTEXT_HANDLE phContext,
  642. /* [ref][out][in] */ LPLSKeyPack lpKeypack
  643. )
  644. /*
  645. Description:
  646. Add a license key pack.
  647. Arguments:
  648. IN phContext - client context handle.
  649. IN OUT lpKeyPack - key pack to be added.
  650. Return Value:
  651. LSERVER_S_SUCCESS
  652. LSERVER_E_INTERNAL_ERROR
  653. TLS_E_INTERNAL
  654. LSERVER_E_SERVER_BUSY
  655. LSERVER_E_DUPLICATE Product already installed.
  656. LSERVER_E_INVALID_DATA
  657. LSERVER_E_CORRUPT_DATABASE
  658. Note:
  659. Application must call LSKeyPackSetStatus() to activate keypack
  660. */
  661. {
  662. #if !defined(ENFORCE_LICENSING) || defined(PRIVATE_DBG)
  663. DWORD status=ERROR_SUCCESS;
  664. TLSRpcKeyPackAdd(phContext, lpKeypack, &status);
  665. return status;
  666. #else
  667. return TLSMapReturnCode(TLS_E_NOTSUPPORTED);
  668. #endif
  669. }
  670. //+------------------------------------------------------------------------
  671. error_status_t
  672. LSKeyPackSetStatus(
  673. /* [in] */ PCONTEXT_HANDLE phContext,
  674. /* [in] */ DWORD dwSetParam,
  675. /* [ref][in] */ LPLSKeyPack lpKeyPack
  676. )
  677. /*
  678. Description:
  679. Routine to activate/deactivated a key pack.
  680. Arguments:
  681. IN phContext - client context handle
  682. IN dwSetParam - type of key pack status to be set.
  683. IN lpKeyPack - new key pack status.
  684. Return Value:
  685. LSERVER_S_SUCCESS
  686. LSERVER_E_INTERNAL_ERROR
  687. TLS_E_INTERNAL
  688. LSERVER_E_INVALID_DATA
  689. LSERVER_E_SERVER_BUSY
  690. LSERVER_E_DATANOTFOUND Key pack is not in server
  691. LSERVER_E_CORRUPT_DATABASE
  692. */
  693. {
  694. #if !defined(ENFORCE_LICENSING) || defined(PRIVATE_DBG)
  695. DWORD status=ERROR_SUCCESS;
  696. TLSRpcKeyPackSetStatus(
  697. phContext,
  698. dwSetParam,
  699. lpKeyPack,
  700. &status
  701. );
  702. return status;
  703. #else
  704. return TLSMapReturnCode(TLS_E_NOTSUPPORTED);
  705. #endif
  706. }
  707. //+------------------------------------------------------------------------
  708. error_status_t
  709. LSLicenseEnumBegin(
  710. /* [in] */ PCONTEXT_HANDLE phContext,
  711. /* [in] */ DWORD dwSearchParm,
  712. /* [in] */ BOOL bMatchAll,
  713. /* [ref][in] */ LPLSLicenseSearchParm lpSearchParm
  714. )
  715. /*
  716. Description:
  717. Begin enumeration of license issued based on search criterial
  718. Arguments:
  719. IN phContext - client context handle
  720. IN dwSearchParm - license search criterial.
  721. IN bMatchAll - match all search criterial
  722. IN lpSearchParm - license(s) to be enumerated.
  723. Return Value:
  724. Same as LSKeyPackEnumBegin().
  725. */
  726. {
  727. DWORD status=ERROR_SUCCESS;
  728. TLSRpcLicenseEnumBegin(
  729. phContext,
  730. dwSearchParm,
  731. bMatchAll,
  732. lpSearchParm,
  733. &status
  734. );
  735. return status;
  736. }
  737. //+------------------------------------------------------------------------
  738. error_status_t
  739. LSLicenseEnumNext(
  740. /* [in] */ PCONTEXT_HANDLE phContext,
  741. /* [ref][out] */ LPLSLicense lpLicense
  742. )
  743. /*
  744. Description:
  745. Arguments:
  746. IN phContext - client context handle
  747. OUT lpLicense - license match search criterial.
  748. Return Value:
  749. Same as LSKeyPackEnumNext().
  750. */
  751. {
  752. DWORD status=ERROR_SUCCESS;
  753. TLSRpcLicenseEnumNext(phContext, lpLicense, &status);
  754. return status;
  755. }
  756. //+------------------------------------------------------------------------
  757. error_status_t
  758. LSLicenseEnumEnd(
  759. /* [in] */ PCONTEXT_HANDLE phContext
  760. )
  761. /*
  762. Description:
  763. End enumeration of issued licenses.
  764. Arguments:
  765. IN phContext - client context handle.
  766. Return Value:
  767. Same as LSKeyPackEnumEnd().
  768. */
  769. {
  770. DWORD status=ERROR_SUCCESS;
  771. TLSRpcLicenseEnumEnd(phContext, &status);
  772. return status;
  773. }
  774. //+------------------------------------------------------------------------
  775. error_status_t
  776. LSLicenseSetStatus(
  777. /* [in] */ PCONTEXT_HANDLE phContext,
  778. /* [in] */ DWORD dwSetParam,
  779. /* [in] */ LPLSLicense lpLicense
  780. )
  781. /*
  782. Description:
  783. Routine to set status of a issued license.
  784. Arguments:
  785. IN phContext - client context handle.
  786. IN dwSetParam -
  787. IN lpLicense -
  788. Return Value:
  789. Same as LSKeyPackSetStatus().
  790. */
  791. {
  792. DWORD status=ERROR_SUCCESS;
  793. TLSRpcLicenseSetStatus(
  794. phContext,
  795. dwSetParam,
  796. lpLicense,
  797. &status
  798. );
  799. return status;
  800. }
  801. //+------------------------------------------------------------------------
  802. error_status_t
  803. LSLicenseGetCert(
  804. /* [in] */ PCONTEXT_HANDLE phContext,
  805. /* [ref][in] */ LPLSLicense lpLicense,
  806. /* [out] */ LPDWORD cbCert,
  807. /* [size_is][size_is][out] */ PBYTE __RPC_FAR *pbCert
  808. )
  809. /*
  810. Description:
  811. Retrieve actual certificate issued to client.
  812. Arguments:
  813. IN phContext - client context handle
  814. IN lpLicense -
  815. OUT cbCert - size of certificate.
  816. OUT pbCert - actual certificate.
  817. Return Value:
  818. LSERVER_S_SUCCESS
  819. LSERVER_E_INTERNAL_ERROR
  820. TLS_E_INTERNAL
  821. LSERVER_E_INVALID_DATA
  822. LSERVER_E_DATANOTFOUND
  823. LSERVER_E_CORRUPT_DATABASE
  824. */
  825. {
  826. return LSERVER_S_SUCCESS;
  827. }
  828. //+------------------------------------------------------------------------
  829. error_status_t
  830. LSGetAvailableLicenses(
  831. /* [in] */ PCONTEXT_HANDLE phContext,
  832. /* [in] */ DWORD dwSearchParm,
  833. /* [ref][in] */ LPLSKeyPack lplsKeyPack,
  834. /* [ref][out] */ LPDWORD lpdwAvail
  835. )
  836. /*
  837. Description:
  838. Retrieve number of available license for a product.
  839. Arguments:
  840. IN phContext - client context.
  841. IN dwSearchParm -
  842. IN lplsKeyPack -
  843. OUT lpdwAvail -
  844. Return Value:
  845. LSERVER_S_SUCCESS
  846. LSERVER_E_INTERNAL_ERROR
  847. TLS_E_INTERNAL
  848. LSERVER_E_DATANOTFOUND
  849. LSERVER_E_INVALID_DATA
  850. LSERVER_E_CORRUPT_DATABASE
  851. */
  852. {
  853. DWORD status=ERROR_SUCCESS;
  854. TLSRpcGetAvailableLicenses(
  855. phContext,
  856. dwSearchParm,
  857. lplsKeyPack,
  858. lpdwAvail,
  859. &status
  860. );
  861. return status;
  862. }
  863. //+------------------------------------------------------------------------
  864. error_status_t
  865. LSGetServerCertificate(
  866. /* [in] */ PCONTEXT_HANDLE phContext,
  867. /* [in] */ BOOL bSignCert,
  868. /* [size_is][size_is][out] */ LPBYTE __RPC_FAR *ppCertBlob,
  869. /* [ref][out] */ LPDWORD lpdwCertBlobLen
  870. )
  871. /*
  872. Description:
  873. Get License Server's signature or exchange certificate
  874. Arguments:
  875. IN phContext - client context.
  876. IN bSignCert - TRUE if signature certificate, FALSE if exchange certificate
  877. OUT ppCertBlob - pointer to pointer to receive certificate.
  878. OUT lpdwCertBlobLen - size of certificate returned.
  879. Return Value:
  880. LSERVER_S_SUCCESS
  881. LSERVER_E_ACCESS_DENIED Client doesn't have required privilege
  882. LSERVER_E_NO_CERTIFICATE License Server hasn't register yet.
  883. */
  884. {
  885. #if ENFORCE_LICENSING
  886. DWORD status=ERROR_SUCCESS;
  887. TLSRpcGetServerCertificate(
  888. phContext,
  889. bSignCert,
  890. ppCertBlob,
  891. lpdwCertBlobLen,
  892. &status
  893. );
  894. return status;
  895. #else
  896. return TLSMapReturnCode(TLS_E_NOTSUPPORTED);
  897. #endif
  898. }
  899. //+------------------------------------------------------------------------
  900. error_status_t
  901. LSRegisterLicenseKeyPack(
  902. /* [in] */ PCONTEXT_HANDLE phContext,
  903. /* [size_is][in] */ LPBYTE pbCHCertBlob,
  904. /* [in] */ DWORD cbCHCertBlobSize,
  905. /* [size_is][in] */ LPBYTE pbRootCertBlob,
  906. /* [in] */ DWORD cbRootCertBlob,
  907. /* [size_is][in] */ LPBYTE lpKeyPackBlob,
  908. /* [in] */ DWORD dwKeyPackBlobLen
  909. )
  910. /*
  911. Description:
  912. Register (Add) a license key pack into License Server.
  913. Arguments:
  914. IN phContext - client context.
  915. IN pbCHCertBlob - CH's certificate.
  916. IN cbCHCertBlobSize - CH certificate size.
  917. IN pbRootCertBlob - Root's certificate.
  918. IN cbRootCertBlob - Size of Root's certificate.
  919. IN lpKeyPackBlob - pointer to encrypted license KeyPack blob.
  920. IN dwKeyPackBlobLen - size of keypack blob.
  921. Return Value:
  922. LSERVER_S_SUCCESS
  923. LSERVER_E_ACCESS_DENIED Client doesn't have required privilege
  924. LSERVER_E_NO_CERTIFICATE License Server hasn't register yet.
  925. LSERVER_E_INVALID_DATA Can't verify any of the certificate or
  926. can't decode license keypack blob.
  927. LSERVER_E_SERVER_BUSY Server is busy.
  928. LSERVER_E_DUPLICATE KeyPack already register
  929. LSERVER_E_ERROR_GENERAL General ODBC error.
  930. */
  931. {
  932. #if ENFORCE_LICENSING
  933. DWORD status=ERROR_SUCCESS;
  934. TLSRpcRegisterLicenseKeyPack(
  935. phContext,
  936. pbCHCertBlob,
  937. cbCHCertBlobSize,
  938. pbRootCertBlob,
  939. cbRootCertBlob,
  940. lpKeyPackBlob,
  941. dwKeyPackBlobLen,
  942. &status
  943. );
  944. return status;
  945. #else
  946. return TLSMapReturnCode(TLS_E_NOTSUPPORTED);
  947. #endif
  948. }
  949. //+------------------------------------------------------------------------
  950. error_status_t
  951. LSInstallCertificate(
  952. /* [in] */ PCONTEXT_HANDLE phContext,
  953. /* [in] */ DWORD dwCertType,
  954. /* [in] */ DWORD dwCertLevel,
  955. /* [in] */ DWORD cbSignatureCert,
  956. /* [size_is][in] */ PBYTE pbSignatureCert,
  957. /* [in] */ DWORD cbExchangeCert,
  958. /* [size_is][in] */ PBYTE pbExchangeCert
  959. )
  960. /*
  961. Description:
  962. Install CH, CA, or License Server's certificate issued by CA into
  963. License Server.
  964. Arguments:
  965. RETURN:
  966. ACCESS_DENIED No privilege
  967. LSERVER_E_INVALID_DATA Can't verify certificate
  968. LSERVER_E_DUPLICATE Certificate already installed
  969. LSERVER_I_CERTIFICATE_OVERWRITE Overwrite certificate.
  970. */
  971. {
  972. #if ENFORCE_LICENSING
  973. DWORD status=ERROR_SUCCESS;
  974. TLSRpcInstallCertificate(
  975. phContext,
  976. dwCertType,
  977. dwCertLevel,
  978. cbSignatureCert,
  979. pbSignatureCert,
  980. cbExchangeCert,
  981. pbExchangeCert,
  982. &status
  983. );
  984. return status;
  985. #else
  986. return TLSMapReturnCode(TLS_E_NOTSUPPORTED);
  987. #endif
  988. }