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.

775 lines
24 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: templic.cpp
  7. //
  8. // Contents:
  9. // all routine deal with temporary license
  10. //
  11. // History:
  12. // Feb 4, 98 HueiWang Created
  13. //---------------------------------------------------------------------------
  14. #include "pch.cpp"
  15. #include "globals.h"
  16. #include "templic.h"
  17. #include "misc.h"
  18. #include "db.h"
  19. #include "clilic.h"
  20. #include "keypack.h"
  21. #include "kp.h"
  22. #include "lkpdesc.h"
  23. #define USSTRING_TEMPORARY _TEXT("Temporary Licenses for")
  24. DWORD
  25. TLSDBGetTemporaryLicense(
  26. IN PTLSDbWorkSpace pDbWkSpace,
  27. IN PTLSDBLICENSEREQUEST pRequest,
  28. IN OUT PTLSLICENSEPACK pLicensePack
  29. );
  30. //+-------------------------------------------------------------
  31. DWORD
  32. TLSDBIssueTemporaryLicense(
  33. IN PTLSDbWorkSpace pDbWkSpace,
  34. IN PTLSDBLICENSEREQUEST pRequest,
  35. IN FILETIME* pNotBefore,
  36. IN FILETIME* pNotAfter,
  37. IN OUT PTLSDBLICENSEDPRODUCT pLicensedProduct
  38. )
  39. /*++
  40. Abstract:
  41. Issue a temporary license, insert a temporary license
  42. pack if necessary
  43. Parameters:
  44. pDbWkSpace - workspace handle.
  45. pRequest - license request.
  46. Returns:
  47. Note:
  48. Seperate routine for issuing perm license just in case
  49. we decide to use our own format for temp. license
  50. ++*/
  51. {
  52. DWORD dwStatus=ERROR_SUCCESS;
  53. ULARGE_INTEGER ulSerialNumber;
  54. DWORD dwLicenseId;
  55. LPTSTR lpRequest=NULL;
  56. LICENSEDCLIENT issuedLicense;
  57. TLSLICENSEPACK LicensePack;
  58. PMGENERATELICENSE PolModGenLicense;
  59. PPMCERTEXTENSION pPolModCertExtension=NULL;
  60. FILETIME notBefore, notAfter;
  61. // ----------------------------------------------------------
  62. // Issue license
  63. memset(&ulSerialNumber, 0, sizeof(ulSerialNumber));
  64. //-----------------------------------------------------------------------------
  65. // this step require reduce available license by 1
  66. //
  67. long numLicense=1;
  68. dwStatus=TLSDBGetTemporaryLicense(
  69. pDbWkSpace,
  70. pRequest,
  71. &LicensePack
  72. );
  73. if(dwStatus != ERROR_SUCCESS)
  74. {
  75. goto cleanup;
  76. }
  77. if((LicensePack.ucAgreementType & ~LSKEYPACK_RESERVED_TYPE) != LSKEYPACKTYPE_TEMPORARY &&
  78. (LicensePack.ucKeyPackStatus & ~LSKEYPACKSTATUS_RESERVED) != LSKEYPACKSTATUS_TEMPORARY )
  79. {
  80. SetLastError(dwStatus = TLS_E_INTERNAL);
  81. TLSASSERT(FALSE);
  82. goto cleanup;
  83. }
  84. // reset status
  85. dwStatus = ERROR_SUCCESS;
  86. dwLicenseId=TLSDBGetNextLicenseId();
  87. ulSerialNumber.LowPart = dwLicenseId;
  88. ulSerialNumber.HighPart = LicensePack.dwKeyPackId;
  89. //
  90. // Update License Table Here
  91. //
  92. memset(&issuedLicense, 0, sizeof(LICENSEDCLIENT));
  93. issuedLicense.dwLicenseId = dwLicenseId;
  94. issuedLicense.dwKeyPackId = LicensePack.dwKeyPackId;
  95. issuedLicense.dwKeyPackLicenseId = LicensePack.dwNextSerialNumber;
  96. issuedLicense.dwNumLicenses = 1;
  97. if(pNotBefore == NULL || pNotAfter == NULL)
  98. {
  99. issuedLicense.ftIssueDate = time(NULL);
  100. issuedLicense.ftExpireDate = issuedLicense.ftIssueDate + g_GracePeriod * 24 * 60 * 60;
  101. }
  102. else
  103. {
  104. FileTimeToLicenseDate(pNotBefore, &(issuedLicense.ftIssueDate));
  105. FileTimeToLicenseDate(pNotAfter, &(issuedLicense.ftExpireDate));
  106. }
  107. issuedLicense.ucLicenseStatus = LSLICENSE_STATUS_TEMPORARY;
  108. _tcscpy(issuedLicense.szMachineName, pRequest->szMachineName);
  109. _tcscpy(issuedLicense.szUserName, pRequest->szUserName);
  110. issuedLicense.dwSystemBiosChkSum = pRequest->hWid.dwPlatformID;
  111. issuedLicense.dwVideoBiosChkSum = pRequest->hWid.Data1;
  112. issuedLicense.dwFloppyBiosChkSum = pRequest->hWid.Data2;
  113. issuedLicense.dwHardDiskSize = pRequest->hWid.Data3;
  114. issuedLicense.dwRamSize = pRequest->hWid.Data4;
  115. UnixTimeToFileTime(issuedLicense.ftIssueDate, &notBefore);
  116. UnixTimeToFileTime(issuedLicense.ftExpireDate, &notAfter);
  117. //
  118. // Inform Policy Module of license generation.
  119. //
  120. PolModGenLicense.pLicenseRequest = pRequest->pPolicyLicenseRequest;
  121. PolModGenLicense.dwKeyPackType = LSKEYPACKTYPE_TEMPORARY;
  122. PolModGenLicense.dwKeyPackId = LicensePack.dwKeyPackId;
  123. PolModGenLicense.dwKeyPackLicenseId = LicensePack.dwNextSerialNumber;
  124. PolModGenLicense.ClientLicenseSerialNumber = ulSerialNumber;
  125. PolModGenLicense.ftNotBefore = notBefore;
  126. PolModGenLicense.ftNotAfter = notAfter;
  127. dwStatus = pRequest->pPolicy->PMLicenseRequest(
  128. pRequest->hClient,
  129. REQUEST_GENLICENSE,
  130. (PVOID)&PolModGenLicense,
  131. (PVOID *)&pPolModCertExtension
  132. );
  133. if(dwStatus != ERROR_SUCCESS)
  134. {
  135. //
  136. // Error in policy module
  137. //
  138. goto cleanup;
  139. }
  140. //
  141. // Check error return from policy module
  142. //
  143. if(pPolModCertExtension != NULL)
  144. {
  145. if(pPolModCertExtension->pbData != NULL && pPolModCertExtension->cbData == 0 ||
  146. pPolModCertExtension->pbData == NULL && pPolModCertExtension->cbData != 0 )
  147. {
  148. // assuming no extension data
  149. pPolModCertExtension->cbData = 0;
  150. pPolModCertExtension->pbData = NULL;
  151. }
  152. if(CompareFileTime(&(pPolModCertExtension->ftNotBefore), &(pPolModCertExtension->ftNotAfter)) > 0)
  153. {
  154. //
  155. // invalid data return from policy module
  156. //
  157. TLSLogEvent(
  158. EVENTLOG_ERROR_TYPE,
  159. TLS_E_GENERATECLIENTELICENSE,
  160. dwStatus = TLS_E_POLICYMODULEERROR,
  161. pRequest->pPolicy->GetCompanyName(),
  162. pRequest->pPolicy->GetProductId()
  163. );
  164. goto cleanup;
  165. }
  166. //
  167. // do not accept changes to license expiration date
  168. //
  169. if(pNotBefore != NULL && pNotAfter != NULL)
  170. {
  171. if( FileTimeToLicenseDate(&(pPolModCertExtension->ftNotBefore), &issuedLicense.ftIssueDate) == FALSE ||
  172. FileTimeToLicenseDate(&(pPolModCertExtension->ftNotAfter), &issuedLicense.ftExpireDate) == FALSE )
  173. {
  174. //
  175. // Invalid data return from policy module
  176. //
  177. TLSLogEvent(
  178. EVENTLOG_ERROR_TYPE,
  179. TLS_E_GENERATECLIENTELICENSE,
  180. dwStatus = TLS_E_POLICYMODULEERROR,
  181. pRequest->pPolicy->GetCompanyName(),
  182. pRequest->pPolicy->GetProductId()
  183. );
  184. goto cleanup;
  185. }
  186. }
  187. notBefore = pPolModCertExtension->ftNotBefore;
  188. notAfter = pPolModCertExtension->ftNotAfter;
  189. }
  190. //
  191. // Add license into license table
  192. //
  193. dwStatus = TLSDBLicenseAdd(
  194. pDbWkSpace,
  195. &issuedLicense,
  196. 0,
  197. NULL
  198. );
  199. //
  200. // Return licensed product
  201. //
  202. pLicensedProduct->pSubjectPublicKeyInfo = NULL;
  203. pLicensedProduct->dwQuantity = 1;
  204. pLicensedProduct->ulSerialNumber = ulSerialNumber;
  205. pLicensedProduct->dwKeyPackId = LicensePack.dwKeyPackId;
  206. pLicensedProduct->dwLicenseId = dwLicenseId;
  207. pLicensedProduct->dwKeyPackLicenseId = LicensePack.dwNextSerialNumber;
  208. pLicensedProduct->ClientHwid = pRequest->hWid;
  209. pLicensedProduct->bTemp = TRUE;
  210. pLicensedProduct->NotBefore = notBefore;
  211. pLicensedProduct->NotAfter = notAfter;
  212. pLicensedProduct->dwProductVersion = MAKELONG(LicensePack.wMinorVersion, LicensePack.wMajorVersion);
  213. _tcscpy(pLicensedProduct->szCompanyName, LicensePack.szCompanyName);
  214. _tcscpy(pLicensedProduct->szLicensedProductId, LicensePack.szProductId);
  215. _tcscpy(pLicensedProduct->szRequestProductId, pRequest->pClientLicenseRequest->pszProductId);
  216. _tcscpy(pLicensedProduct->szUserName, pRequest->szUserName);
  217. _tcscpy(pLicensedProduct->szMachineName, pRequest->szMachineName);
  218. pLicensedProduct->dwLanguageID = pRequest->dwLanguageID;
  219. pLicensedProduct->dwPlatformID = pRequest->dwPlatformID;
  220. pLicensedProduct->pbPolicyData = (pPolModCertExtension) ? pPolModCertExtension->pbData : NULL;
  221. pLicensedProduct->cbPolicyData = (pPolModCertExtension) ? pPolModCertExtension->cbData : 0;
  222. cleanup:
  223. return dwStatus;
  224. }
  225. //-----------------------------------------------------------------
  226. DWORD
  227. TLSDBAddTemporaryKeyPack(
  228. IN PTLSDbWorkSpace pDbWkSpace,
  229. IN PTLSDBLICENSEREQUEST pRequest,
  230. IN OUT LPTLSLICENSEPACK lpTmpKeyPackAdd
  231. )
  232. /*++
  233. Abstract:
  234. Add a temporary keypack into database.
  235. Parameter:
  236. pDbWkSpace : workspace handle.
  237. szCompanyName :
  238. szProductId :
  239. dwVersion :
  240. dwPlatformId :
  241. dwLangId :
  242. lpTmpKeyPackAdd : added keypack.
  243. Returns:
  244. ++*/
  245. {
  246. DWORD dwStatus;
  247. TLSLICENSEPACK LicPack;
  248. TLSLICENSEPACK existingLicPack;
  249. LICPACKDESC LicPackDesc;
  250. LICPACKDESC existingLicPackDesc;
  251. BOOL bAddDefDescription=FALSE;
  252. TCHAR szDefProductDesc[LSERVER_MAX_STRING_SIZE];
  253. int count=0;
  254. memset(&LicPack, 0, sizeof(TLSLICENSEPACK));
  255. memset(&existingLicPack, 0, sizeof(TLSLICENSEPACK));
  256. memset(&LicPackDesc, 0, sizeof(LICPACKDESC));
  257. memset(szDefProductDesc, 0, sizeof(szDefProductDesc));
  258. memset(&existingLicPackDesc, 0, sizeof(LICPACKDESC));
  259. //
  260. // Load product description prefix
  261. //
  262. LoadResourceString(
  263. IDS_TEMPORARY_PRODUCTDESC,
  264. szDefProductDesc,
  265. sizeof(szDefProductDesc) / sizeof(szDefProductDesc[0])
  266. );
  267. LicPack.ucAgreementType = LSKEYPACKTYPE_TEMPORARY;
  268. _tcsncpy(
  269. LicPack.szCompanyName,
  270. pRequest->pszCompanyName,
  271. min(_tcslen(pRequest->pszCompanyName), LSERVER_MAX_STRING_SIZE)
  272. );
  273. _tcsncpy(
  274. LicPack.szProductId,
  275. pRequest->pszProductId,
  276. min(_tcslen(pRequest->pszProductId), LSERVER_MAX_STRING_SIZE)
  277. );
  278. _tcsncpy(
  279. LicPack.szInstallId,
  280. (LPTSTR)g_pszServerPid,
  281. min(_tcslen((LPTSTR)g_pszServerPid), LSERVER_MAX_STRING_SIZE)
  282. );
  283. _tcsncpy(
  284. LicPack.szTlsServerName,
  285. g_szComputerName,
  286. min(_tcslen(g_szComputerName), LSERVER_MAX_STRING_SIZE)
  287. );
  288. LicPack.wMajorVersion = HIWORD(pRequest->dwProductVersion);
  289. LicPack.wMinorVersion = LOWORD(pRequest->dwProductVersion);
  290. LicPack.dwPlatformType = pRequest->dwPlatformID;
  291. LicPack.ucChannelOfPurchase = LSKEYPACKCHANNELOFPURCHASE_UNKNOWN;
  292. LicPack.dwTotalLicenseInKeyPack = INT_MAX;
  293. LoadResourceString(
  294. IDS_TEMPORARY_KEYPACKID,
  295. LicPack.szKeyPackId,
  296. sizeof(LicPack.szKeyPackId)/sizeof(LicPack.szKeyPackId[0])
  297. );
  298. LoadResourceString(
  299. IDS_TEMPORARY_BSERIALNUMBER,
  300. LicPack.szBeginSerialNumber,
  301. sizeof(LicPack.szBeginSerialNumber)/sizeof(LicPack.szBeginSerialNumber[0])
  302. );
  303. do {
  304. //
  305. // Add entry into keypack table.
  306. //
  307. dwStatus = TLSDBKeyPackAdd(
  308. pDbWkSpace,
  309. &LicPack
  310. );
  311. *lpTmpKeyPackAdd = LicPack;
  312. LicPack.pbDomainSid = NULL;
  313. LicPack.cbDomainSid = 0;
  314. if(dwStatus == TLS_E_DUPLICATE_RECORD)
  315. {
  316. //
  317. // temporary keypack already exist
  318. //
  319. dwStatus = ERROR_SUCCESS;
  320. break;
  321. }
  322. else if(dwStatus != ERROR_SUCCESS)
  323. {
  324. //
  325. // some other error occurred
  326. //
  327. break;
  328. }
  329. //
  330. // Activate KeyPack
  331. //
  332. LicPack.ucKeyPackStatus = LSKEYPACKSTATUS_TEMPORARY;
  333. LicPack.dwActivateDate = (DWORD) time(NULL);
  334. LicPack.dwExpirationDate = INT_MAX;
  335. LicPack.dwNumberOfLicenses = 0;
  336. dwStatus=TLSDBKeyPackSetValues(
  337. pDbWkSpace,
  338. FALSE,
  339. LSKEYPACK_SET_ACTIVATEDATE | LSKEYPACK_SET_KEYPACKSTATUS |
  340. LSKEYPACK_SET_EXPIREDATE | LSKEYPACK_EXSEARCH_AVAILABLE,
  341. &LicPack
  342. );
  343. bAddDefDescription = TRUE;
  344. //
  345. // Find existing keypack description
  346. //
  347. dwStatus = TLSDBKeyPackEnumBegin(
  348. pDbWkSpace,
  349. TRUE,
  350. LSKEYPACK_SEARCH_PRODUCTID | LSKEYPACK_SEARCH_COMPANYNAME | LSKEYPACK_SEARCH_PLATFORMTYPE,
  351. &LicPack
  352. );
  353. if(dwStatus != ERROR_SUCCESS)
  354. break;
  355. do {
  356. dwStatus = TLSDBKeyPackEnumNext(
  357. pDbWkSpace,
  358. &existingLicPack
  359. );
  360. if(existingLicPack.dwKeyPackId != LicPack.dwKeyPackId)
  361. {
  362. break;
  363. }
  364. } while(dwStatus == ERROR_SUCCESS);
  365. TLSDBKeyPackEnumEnd(pDbWkSpace);
  366. if(dwStatus != ERROR_SUCCESS || existingLicPack.dwKeyPackId != LicPack.dwKeyPackId)
  367. {
  368. break;
  369. }
  370. //
  371. // Copy existing keypack description into keypack description table
  372. //
  373. existingLicPackDesc.dwKeyPackId = existingLicPack.dwKeyPackId;
  374. dwStatus = TLSDBKeyPackDescEnumBegin(
  375. pDbWkSpace,
  376. TRUE,
  377. LICPACKDESCRECORD_TABLE_SEARCH_KEYPACKID,
  378. &existingLicPackDesc
  379. );
  380. while(dwStatus == ERROR_SUCCESS)
  381. {
  382. dwStatus = TLSDBKeyPackDescEnumNext(
  383. pDbWkSpace,
  384. &existingLicPackDesc
  385. );
  386. if(dwStatus != ERROR_SUCCESS)
  387. break;
  388. LicPackDesc.dwKeyPackId = LicPack.dwKeyPackId;
  389. LicPackDesc.dwLanguageId = existingLicPackDesc.dwLanguageId;
  390. _tcscpy(LicPackDesc.szCompanyName, existingLicPackDesc.szCompanyName);
  391. _tcscpy(LicPackDesc.szProductName, existingLicPackDesc.szProductName);
  392. //
  393. // pretty format the description
  394. //
  395. _sntprintf(
  396. LicPackDesc.szProductDesc,
  397. sizeof(LicPackDesc.szProductDesc)/sizeof(LicPackDesc.szProductDesc[0])-1,
  398. _TEXT("%s %s"),
  399. (existingLicPackDesc.dwLanguageId != GetSystemDefaultLangID()) ? USSTRING_TEMPORARY : szDefProductDesc,
  400. existingLicPackDesc.szProductDesc
  401. );
  402. // quick and dirty fix,
  403. //
  404. // TODO - need to do a duplicate table then use the duplicate handle to
  405. // insert the record, SetValue uses enumeration to verify if record exist
  406. // which fail because we are already in enumeration
  407. //
  408. if(pDbWkSpace->m_LicPackDescTable.InsertRecord(LicPackDesc) != TRUE)
  409. {
  410. SetLastError(dwStatus = SET_JB_ERROR(pDbWkSpace->m_LicPackDescTable.GetLastJetError()));
  411. break;
  412. }
  413. //dwStatus = TLSDBKeyPackDescSetValue(
  414. // pDbWkSpace,
  415. // KEYPACKDESC_SET_ADD_ENTRY,
  416. // &keyPackDesc
  417. // );
  418. count++;
  419. }
  420. if(count != 0)
  421. {
  422. bAddDefDescription = FALSE;
  423. }
  424. if(dwStatus == TLS_I_NO_MORE_DATA)
  425. {
  426. dwStatus = ERROR_SUCCESS;
  427. }
  428. } while(FALSE);
  429. if(bAddDefDescription)
  430. {
  431. //
  432. // ask policy module if they have description
  433. //
  434. PMKEYPACKDESCREQ kpDescReq;
  435. PPMKEYPACKDESC pKpDesc;
  436. //
  437. // Ask for English description
  438. //
  439. kpDescReq.pszProductId = pRequest->pszProductId;
  440. kpDescReq.dwLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  441. kpDescReq.dwVersion = pRequest->dwProductVersion;
  442. pKpDesc = NULL;
  443. dwStatus = pRequest->pPolicy->PMLicenseRequest(
  444. pRequest->hClient,
  445. REQUEST_KEYPACKDESC,
  446. (PVOID)&kpDescReq,
  447. (PVOID *)&pKpDesc
  448. );
  449. if(dwStatus == ERROR_SUCCESS && pKpDesc != NULL)
  450. {
  451. LicPackDesc.dwKeyPackId = LicPack.dwKeyPackId;
  452. LicPackDesc.dwLanguageId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  453. _tcscpy(LicPackDesc.szCompanyName, pKpDesc->szCompanyName);
  454. _tcscpy(LicPackDesc.szProductName, pKpDesc->szProductName);
  455. //
  456. // pretty format the description
  457. //
  458. _sntprintf(
  459. LicPackDesc.szProductDesc,
  460. sizeof(LicPackDesc.szProductDesc)/sizeof(LicPackDesc.szProductDesc[0])-1,
  461. _TEXT("%s %s"),
  462. USSTRING_TEMPORARY, // US langid, don't use localized one
  463. pKpDesc->szProductDesc
  464. );
  465. //
  466. // Ignore error
  467. //
  468. dwStatus = TLSDBKeyPackDescAddEntry(
  469. pDbWkSpace,
  470. &LicPackDesc
  471. );
  472. if(dwStatus == ERROR_SUCCESS)
  473. {
  474. bAddDefDescription = FALSE;
  475. }
  476. }
  477. if(GetSystemDefaultLangID() != kpDescReq.dwLangId)
  478. {
  479. //
  480. // Get System default language id
  481. //
  482. kpDescReq.pszProductId = pRequest->pszProductId;
  483. kpDescReq.dwLangId = GetSystemDefaultLangID();
  484. kpDescReq.dwVersion = pRequest->dwProductVersion;
  485. pKpDesc = NULL;
  486. dwStatus = pRequest->pPolicy->PMLicenseRequest(
  487. pRequest->hClient,
  488. REQUEST_KEYPACKDESC,
  489. (PVOID)&kpDescReq,
  490. (PVOID *)&pKpDesc
  491. );
  492. if(dwStatus == ERROR_SUCCESS && pKpDesc != NULL)
  493. {
  494. LicPackDesc.dwKeyPackId = LicPack.dwKeyPackId;
  495. LicPackDesc.dwLanguageId = GetSystemDefaultLangID();
  496. _tcscpy(LicPackDesc.szCompanyName, pKpDesc->szCompanyName);
  497. _tcscpy(LicPackDesc.szProductName, pKpDesc->szProductName);
  498. //
  499. // pretty format the description
  500. //
  501. _sntprintf(
  502. LicPackDesc.szProductDesc,
  503. sizeof(LicPackDesc.szProductDesc)/sizeof(LicPackDesc.szProductDesc[0])-1,
  504. _TEXT("%s %s"),
  505. szDefProductDesc,
  506. pKpDesc->szProductDesc
  507. );
  508. //
  509. // Ignore error
  510. //
  511. dwStatus = TLSDBKeyPackDescAddEntry(
  512. pDbWkSpace,
  513. &LicPackDesc
  514. );
  515. if(dwStatus == ERROR_SUCCESS)
  516. {
  517. bAddDefDescription = FALSE;
  518. }
  519. }
  520. }
  521. }
  522. if(bAddDefDescription)
  523. {
  524. //
  525. // No existing keypack description, add predefined product description
  526. // "temporary license for <product ID>"
  527. //
  528. LicPackDesc.dwKeyPackId = LicPack.dwKeyPackId;
  529. _tcscpy(LicPackDesc.szCompanyName, LicPack.szCompanyName);
  530. _tcscpy(LicPackDesc.szProductName, LicPackDesc.szProductDesc);
  531. LicPackDesc.dwLanguageId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  532. _sntprintf(LicPackDesc.szProductDesc,
  533. sizeof(LicPackDesc.szProductDesc)/sizeof(LicPackDesc.szProductDesc[0])-1,
  534. _TEXT("%s %s"),
  535. USSTRING_TEMPORARY,
  536. pRequest->pszProductId);
  537. dwStatus = TLSDBKeyPackDescAddEntry(
  538. pDbWkSpace,
  539. &LicPackDesc
  540. );
  541. if(GetSystemDefaultLangID() != MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US))
  542. {
  543. LicPackDesc.dwLanguageId = GetSystemDefaultLangID();
  544. _sntprintf(LicPackDesc.szProductDesc,
  545. sizeof(LicPackDesc.szProductDesc)/sizeof(LicPackDesc.szProductDesc[0])-1,
  546. _TEXT("%s %s"),
  547. szDefProductDesc,
  548. pRequest->pszProductId);
  549. dwStatus = TLSDBKeyPackDescAddEntry(
  550. pDbWkSpace,
  551. &LicPackDesc
  552. );
  553. }
  554. }
  555. return dwStatus;
  556. }
  557. //++----------------------------------------------------------
  558. DWORD
  559. TLSDBGetTemporaryLicense(
  560. IN PTLSDbWorkSpace pDbWkSpace,
  561. IN PTLSDBLICENSEREQUEST pRequest,
  562. IN OUT PTLSLICENSEPACK pLicensePack
  563. )
  564. /*++
  565. Abstract:
  566. Allocate a temporary license from temporary license pack.
  567. Parameter:
  568. pDbWkSpace : workspace handle.
  569. pRequest : Product to request license from.
  570. lpdwKeyPackId : return keypack ID that license is allocated from.
  571. lpdwKeyPackLicenseId : license ID for the keypack.
  572. lpdwExpirationDate : expiration date of license pack.
  573. lpucKeyPackStatus : status of keypack.
  574. lpucKeyPackType : type of keypack, always temporary.
  575. Returns:
  576. ++*/
  577. {
  578. DWORD dwStatus=ERROR_SUCCESS;
  579. DWORD dump;
  580. TLSLICENSEPACK LicenseKeyPack;
  581. TLSDBLicenseAllocation allocated;
  582. TLSDBAllocateRequest AllocateRequest;
  583. BOOL bAcceptTemp=TRUE;
  584. LicenseKeyPack.pbDomainSid = NULL;
  585. //
  586. // Tell policy module we are about to allocate a license from temporary
  587. // license pack
  588. //
  589. dwStatus = pRequest->pPolicy->PMLicenseRequest(
  590. pRequest->hClient,
  591. REQUEST_TEMPORARY,
  592. NULL,
  593. (PVOID *)&bAcceptTemp
  594. );
  595. //
  596. // Policy Module error
  597. //
  598. if(dwStatus != ERROR_SUCCESS)
  599. {
  600. return dwStatus;
  601. }
  602. //
  603. // Policy module does not accept temporary license
  604. //
  605. if(bAcceptTemp == FALSE)
  606. {
  607. return dwStatus = TLS_I_POLICYMODULETEMPORARYLICENSE;
  608. }
  609. AllocateRequest.ucAgreementType = LSKEYPACKTYPE_TEMPORARY;
  610. AllocateRequest.szCompanyName = (LPTSTR)pRequest->pszCompanyName;
  611. AllocateRequest.szProductId = (LPTSTR)pRequest->pszProductId;
  612. AllocateRequest.dwVersion = pRequest->dwProductVersion;
  613. AllocateRequest.dwPlatformId = pRequest->dwPlatformID;
  614. AllocateRequest.dwLangId = pRequest->dwLanguageID;
  615. AllocateRequest.dwNumLicenses = 1;
  616. AllocateRequest.dwScheme = ALLOCATE_ANY_GREATER_VERSION;
  617. memset(&allocated, 0, sizeof(allocated));
  618. allocated.dwBufSize = 1;
  619. allocated.pdwAllocationVector = &dump;
  620. allocated.lpAllocateKeyPack = &LicenseKeyPack;
  621. dwStatus = TLSDBAddTemporaryKeyPack(
  622. pDbWkSpace,
  623. pRequest,
  624. &LicenseKeyPack
  625. );
  626. if(dwStatus == ERROR_SUCCESS)
  627. {
  628. allocated.dwBufSize = 1;
  629. dwStatus = AllocateLicensesFromDB(
  630. pDbWkSpace,
  631. &AllocateRequest,
  632. TRUE, // fCheckAgreementType
  633. &allocated
  634. );
  635. }
  636. if(dwStatus == ERROR_SUCCESS)
  637. {
  638. *pLicensePack = LicenseKeyPack;
  639. }
  640. else if(dwStatus == TLS_I_NO_MORE_DATA)
  641. {
  642. SetLastError(dwStatus = TLS_E_INTERNAL);
  643. }
  644. return dwStatus;
  645. }