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.

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