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.

2679 lines
74 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: request.cpp
  6. //
  7. // Contents: TLS236 policy module routines
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "pch.cpp"
  13. #include <rpc.h>
  14. #include <time.h>
  15. extern CClientMgr* g_ClientMgr;
  16. HMODULE g_hInstance;
  17. #define NUMBER_PRODUCTSTRING_RESOURCE 3
  18. #define INDEX_COMPANYNAME 0
  19. #define INDEX_PRODUCTNAME 1
  20. #define INDEX_PRODUCTDESC 2
  21. #define NUMBER_OF_CLIENT_OS 4
  22. #define NUMBER_OF_TERMSRV_OS 3
  23. #define DENY_BUILTIN 0
  24. #define ALLOW_BUILTIN 1
  25. static char LicenseTable[NUMBER_OF_CLIENT_OS][NUMBER_OF_TERMSRV_OS] =
  26. {
  27. {DENY_BUILTIN, DENY_BUILTIN, DENY_BUILTIN },
  28. {ALLOW_BUILTIN, DENY_BUILTIN, DENY_BUILTIN },
  29. {ALLOW_BUILTIN, DENY_BUILTIN, DENY_BUILTIN },
  30. {ALLOW_BUILTIN, DENY_BUILTIN, DENY_BUILTIN }
  31. };
  32. //
  33. // Windows 2000
  34. //
  35. LPTSTR g_pszUSFreeKeyPackProductDesc[NUMBER_PRODUCTSTRING_RESOURCE] = {
  36. US_IDS_COMPANYNAME,
  37. US_IDS_EX_PRODUCTNAME,
  38. US_IDS_EX_PRODUCTDESC
  39. };
  40. LPTSTR g_pszLocalizedFreeKeyPackProductDesc[NUMBER_PRODUCTSTRING_RESOURCE] = {
  41. NULL,
  42. NULL,
  43. NULL
  44. };
  45. LPTSTR g_pszUSStandardKeyPackProductString[NUMBER_PRODUCTSTRING_RESOURCE] = {
  46. US_IDS_COMPANYNAME,
  47. US_IDS_S_PRODUCTNAME,
  48. US_IDS_S_PRODUCTDESC
  49. };
  50. LPTSTR g_pszLocalizedStandardKeyPackProductString[NUMBER_PRODUCTSTRING_RESOURCE] = {
  51. NULL,
  52. NULL,
  53. NULL
  54. };
  55. LPTSTR g_pszUSInternetKeyPackProductDesc [NUMBER_PRODUCTSTRING_RESOURCE] = {
  56. US_IDS_COMPANYNAME,
  57. US_IDS_I_PRODUCTNAME,
  58. US_IDS_I_PRODUCTDESC
  59. };
  60. LPTSTR g_pszLocalizedInternetKeyPackProductDesc [NUMBER_PRODUCTSTRING_RESOURCE] = {
  61. NULL,
  62. NULL,
  63. NULL,
  64. };
  65. //
  66. // Whistler
  67. //
  68. LPTSTR g_pszUSStandardKeyPackProductString51[NUMBER_PRODUCTSTRING_RESOURCE] = {
  69. US_IDS_COMPANYNAME,
  70. US_IDS_S_PRODUCTNAME,
  71. US_IDS_S_PRODUCTDESC51
  72. };
  73. LPTSTR g_pszLocalizedStandardKeyPackProductString51[NUMBER_PRODUCTSTRING_RESOURCE] = {
  74. NULL,
  75. NULL,
  76. NULL
  77. };
  78. LPTSTR g_pszUSConcurrentKeyPackProductDesc51 [NUMBER_PRODUCTSTRING_RESOURCE] = {
  79. US_IDS_COMPANYNAME,
  80. US_IDS_C_PRODUCTNAME,
  81. US_IDS_C_PRODUCTDESC51
  82. };
  83. LPTSTR g_pszLocalizedConcurrentKeyPackProductDesc51 [NUMBER_PRODUCTSTRING_RESOURCE] = {
  84. NULL,
  85. NULL,
  86. NULL,
  87. };
  88. PMSUPPORTEDPRODUCT g_pszSupportedProduct[] = {
  89. { TERMSERV_PRODUCTID_CH, TERMSERV_PRODUCTID_SKU},
  90. { TERMSERV_INTERNET_CH, TERMSERV_INTERNET_SKU},
  91. { TERMSERV_CONCURRENT_CH, TERMSERV_CONCURRENT_SKU},
  92. { TERMSERV_WHISTLER_PRODUCTID_CH, TERMSERV_PRODUCTID_SKU}
  93. };
  94. DWORD g_dwNumSupportedProduct = sizeof(g_pszSupportedProduct)/sizeof(g_pszSupportedProduct[0]);
  95. DWORD g_dwVersion=CURRENT_TLSA02_VERSION;
  96. ////////////////////////////////////////////////////////
  97. LPTSTR
  98. LoadProductDescFromResource(
  99. IN DWORD dwResId,
  100. IN DWORD dwMaxSize
  101. )
  102. /*++
  103. Internal Routine
  104. --*/
  105. {
  106. LPTSTR pszString = NULL;
  107. pszString = (LPTSTR) MALLOC( sizeof(TCHAR) * (dwMaxSize + 1) );
  108. if(pszString != NULL)
  109. {
  110. if(LoadResourceString(dwResId, pszString, dwMaxSize + 1) == FALSE)
  111. {
  112. FREE(pszString);
  113. }
  114. }
  115. return pszString;
  116. }
  117. //-----------------------------------------------------
  118. void
  119. FreeProductDescString()
  120. {
  121. for(int i=0;
  122. i < sizeof(g_pszLocalizedFreeKeyPackProductDesc)/sizeof(g_pszLocalizedFreeKeyPackProductDesc[0]);
  123. i++)
  124. {
  125. if(g_pszLocalizedFreeKeyPackProductDesc[i] != NULL)
  126. {
  127. FREE(g_pszLocalizedFreeKeyPackProductDesc[i]);
  128. g_pszLocalizedFreeKeyPackProductDesc[i] = NULL;
  129. }
  130. }
  131. for(i=0;
  132. i < sizeof(g_pszLocalizedStandardKeyPackProductString)/sizeof(g_pszLocalizedStandardKeyPackProductString[0]);
  133. i++)
  134. {
  135. if(g_pszLocalizedStandardKeyPackProductString[i] != NULL)
  136. {
  137. FREE(g_pszLocalizedStandardKeyPackProductString[i]);
  138. g_pszLocalizedStandardKeyPackProductString[i] = NULL;
  139. }
  140. }
  141. for(i=0;
  142. i < sizeof(g_pszLocalizedInternetKeyPackProductDesc)/sizeof(g_pszLocalizedInternetKeyPackProductDesc[0]);
  143. i++)
  144. {
  145. if(g_pszLocalizedInternetKeyPackProductDesc[i] != NULL)
  146. {
  147. FREE(g_pszLocalizedInternetKeyPackProductDesc[i]);
  148. g_pszLocalizedInternetKeyPackProductDesc[i] = NULL;
  149. }
  150. }
  151. for(i=0;
  152. i < sizeof(g_pszLocalizedConcurrentKeyPackProductDesc51)/sizeof(g_pszLocalizedConcurrentKeyPackProductDesc51[0]);
  153. i++)
  154. {
  155. if(g_pszLocalizedConcurrentKeyPackProductDesc51[i] != NULL)
  156. {
  157. FREE(g_pszLocalizedConcurrentKeyPackProductDesc51[i]);
  158. g_pszLocalizedConcurrentKeyPackProductDesc51[i] = NULL;
  159. }
  160. }
  161. return;
  162. }
  163. ////////////////////////////////////////////////////////
  164. void
  165. InitPolicyModule(
  166. IN HMODULE hModule
  167. )
  168. /*++
  169. Initialize policy module, ignore error if we can't find localized string, we always
  170. insert a english product desc.
  171. --*/
  172. {
  173. BOOL bSuccess = TRUE;
  174. g_hInstance = hModule;
  175. //
  176. // Build IN CAL product desc.
  177. //
  178. g_pszLocalizedFreeKeyPackProductDesc[INDEX_COMPANYNAME] =
  179. LoadProductDescFromResource(
  180. IDS_COMPANYNAME,
  181. MAX_TERMSRV_PRODUCTID + 1
  182. );
  183. if(g_pszLocalizedFreeKeyPackProductDesc[INDEX_COMPANYNAME] == NULL)
  184. {
  185. bSuccess = FALSE;
  186. goto cleanup;
  187. }
  188. g_pszLocalizedFreeKeyPackProductDesc[INDEX_PRODUCTNAME] =
  189. LoadProductDescFromResource(
  190. IDS_EX_PRODUCTNAME,
  191. MAX_TERMSRV_PRODUCTID + 1
  192. );
  193. if(g_pszLocalizedFreeKeyPackProductDesc[INDEX_PRODUCTNAME] == NULL)
  194. {
  195. bSuccess = FALSE;
  196. goto cleanup;
  197. }
  198. g_pszLocalizedFreeKeyPackProductDesc[INDEX_PRODUCTDESC] =
  199. LoadProductDescFromResource(
  200. IDS_EX_PRODUCTDESC,
  201. MAX_TERMSRV_PRODUCTID + 1
  202. );
  203. if(g_pszLocalizedFreeKeyPackProductDesc[INDEX_PRODUCTDESC] == NULL)
  204. {
  205. bSuccess = FALSE;
  206. goto cleanup;
  207. }
  208. //
  209. // FULL CAL product Desc.
  210. //
  211. g_pszLocalizedStandardKeyPackProductString[INDEX_COMPANYNAME] =
  212. LoadProductDescFromResource(
  213. IDS_COMPANYNAME,
  214. MAX_TERMSRV_PRODUCTID + 1
  215. );
  216. if(g_pszLocalizedStandardKeyPackProductString[INDEX_COMPANYNAME] == NULL)
  217. {
  218. bSuccess = FALSE;
  219. goto cleanup;
  220. }
  221. g_pszLocalizedStandardKeyPackProductString[INDEX_PRODUCTNAME] =
  222. LoadProductDescFromResource(
  223. IDS_S_PRODUCTNAME,
  224. MAX_TERMSRV_PRODUCTID + 1
  225. );
  226. if(g_pszLocalizedStandardKeyPackProductString[INDEX_PRODUCTNAME] == NULL)
  227. {
  228. bSuccess = FALSE;
  229. goto cleanup;
  230. }
  231. g_pszLocalizedStandardKeyPackProductString[INDEX_PRODUCTDESC] =
  232. LoadProductDescFromResource(
  233. IDS_S_PRODUCTDESC,
  234. MAX_TERMSRV_PRODUCTID + 1
  235. );
  236. if(g_pszLocalizedStandardKeyPackProductString[INDEX_PRODUCTDESC] == NULL)
  237. {
  238. bSuccess = FALSE;
  239. goto cleanup;
  240. }
  241. //
  242. // Internet CAL product Desc.
  243. //
  244. g_pszLocalizedInternetKeyPackProductDesc[INDEX_COMPANYNAME] =
  245. LoadProductDescFromResource(
  246. IDS_COMPANYNAME,
  247. MAX_TERMSRV_PRODUCTID + 1
  248. );
  249. if(g_pszLocalizedInternetKeyPackProductDesc[INDEX_COMPANYNAME] == NULL)
  250. {
  251. bSuccess = FALSE;
  252. goto cleanup;
  253. }
  254. g_pszLocalizedInternetKeyPackProductDesc[INDEX_PRODUCTNAME] =
  255. LoadProductDescFromResource(
  256. IDS_I_PRODUCTNAME,
  257. MAX_TERMSRV_PRODUCTID + 1
  258. );
  259. if(g_pszLocalizedInternetKeyPackProductDesc[INDEX_PRODUCTNAME] == NULL)
  260. {
  261. bSuccess = FALSE;
  262. goto cleanup;
  263. }
  264. g_pszLocalizedInternetKeyPackProductDesc[INDEX_PRODUCTDESC] =
  265. LoadProductDescFromResource(
  266. IDS_I_PRODUCTDESC,
  267. MAX_TERMSRV_PRODUCTID + 1
  268. );
  269. if(g_pszLocalizedInternetKeyPackProductDesc[INDEX_PRODUCTDESC] == NULL)
  270. {
  271. bSuccess = FALSE;
  272. goto cleanup;
  273. }
  274. //
  275. // Whistler FULL CAL product Desc.
  276. //
  277. g_pszLocalizedStandardKeyPackProductString51[INDEX_COMPANYNAME] = LoadProductDescFromResource(
  278. IDS_COMPANYNAME,
  279. MAX_TERMSRV_PRODUCTID + 1
  280. );
  281. if(g_pszLocalizedStandardKeyPackProductString51[INDEX_COMPANYNAME] == NULL)
  282. {
  283. bSuccess = FALSE;
  284. goto cleanup;
  285. }
  286. g_pszLocalizedStandardKeyPackProductString51[INDEX_PRODUCTNAME] = LoadProductDescFromResource(
  287. IDS_S_PRODUCTNAME,
  288. MAX_TERMSRV_PRODUCTID + 1
  289. );
  290. if(g_pszLocalizedStandardKeyPackProductString51[INDEX_PRODUCTNAME] == NULL)
  291. {
  292. bSuccess = FALSE;
  293. goto cleanup;
  294. }
  295. g_pszLocalizedStandardKeyPackProductString51[INDEX_PRODUCTDESC] = LoadProductDescFromResource(
  296. IDS_S_PRODUCTDESC51,
  297. MAX_TERMSRV_PRODUCTID + 1
  298. );
  299. if(g_pszLocalizedStandardKeyPackProductString51[INDEX_PRODUCTDESC] == NULL)
  300. {
  301. bSuccess = FALSE;
  302. goto cleanup;
  303. }
  304. //
  305. // Whistler Concurrent CAL product Desc.
  306. //
  307. g_pszLocalizedConcurrentKeyPackProductDesc51[INDEX_COMPANYNAME] = LoadProductDescFromResource(
  308. IDS_COMPANYNAME,
  309. MAX_TERMSRV_PRODUCTID + 1
  310. );
  311. if(g_pszLocalizedConcurrentKeyPackProductDesc51[INDEX_COMPANYNAME] == NULL)
  312. {
  313. bSuccess = FALSE;
  314. goto cleanup;
  315. }
  316. g_pszLocalizedConcurrentKeyPackProductDesc51[INDEX_PRODUCTNAME] = LoadProductDescFromResource(
  317. IDS_C_PRODUCTNAME,
  318. MAX_TERMSRV_PRODUCTID + 1
  319. );
  320. if(g_pszLocalizedConcurrentKeyPackProductDesc51[INDEX_PRODUCTNAME] == NULL)
  321. {
  322. bSuccess = FALSE;
  323. goto cleanup;
  324. }
  325. g_pszLocalizedConcurrentKeyPackProductDesc51[INDEX_PRODUCTDESC] = LoadProductDescFromResource(
  326. IDS_C_PRODUCTDESC51,
  327. MAX_TERMSRV_PRODUCTID + 1
  328. );
  329. if(g_pszLocalizedConcurrentKeyPackProductDesc51[INDEX_PRODUCTDESC] == NULL)
  330. {
  331. bSuccess = FALSE;
  332. goto cleanup;
  333. }
  334. cleanup:
  335. if(bSuccess == FALSE)
  336. {
  337. FreeProductDescString();
  338. }
  339. return;
  340. }
  341. ////////////////////////////////////////////////////////
  342. BOOL
  343. LoadResourceString(
  344. IN DWORD dwId,
  345. IN OUT LPTSTR szBuf,
  346. IN DWORD dwBufSize
  347. )
  348. /*++
  349. ++*/
  350. {
  351. int dwRet=0;
  352. EXCEPTION_RECORD ExceptionCode;
  353. __try {
  354. dwRet = LoadString(
  355. g_hInstance,
  356. dwId,
  357. szBuf,
  358. dwBufSize
  359. );
  360. }
  361. __except (
  362. ExceptionCode = *(GetExceptionInformation())->ExceptionRecord,
  363. EXCEPTION_EXECUTE_HANDLER )
  364. {
  365. SetLastError(ExceptionCode.ExceptionCode);
  366. }
  367. return (dwRet != 0);
  368. }
  369. ////////////////////////////////////////////////////////
  370. DWORD
  371. AddA02KeyPack(
  372. IN LPCTSTR pszProductCode,
  373. IN DWORD dwVersion, // NT version
  374. IN BOOL bFreeOnly // add free license pack only
  375. )
  376. /*++
  377. ++*/
  378. {
  379. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 2];
  380. DWORD dwSize = MAX_COMPUTERNAME_LENGTH+1;
  381. TCHAR pszProductId[MAX_TERMSRV_PRODUCTID+1];
  382. TLS_HANDLE tlsHandle=NULL;
  383. DWORD dwStatus = ERROR_SUCCESS;
  384. DWORD dwLkpVersion=0;
  385. LPTSTR* pszDescs;
  386. LPTSTR* pszLocalizedDescs;
  387. //
  388. // Connect to license server
  389. //
  390. memset(szComputerName, 0, sizeof(szComputerName));
  391. if(GetComputerName(szComputerName, &dwSize) == FALSE)
  392. {
  393. dwStatus = GetLastError();
  394. goto cleanup;
  395. }
  396. tlsHandle = TLSConnectToLsServer( szComputerName );
  397. if(tlsHandle == NULL)
  398. {
  399. dwStatus = GetLastError();
  400. goto cleanup;
  401. }
  402. //
  403. // Windows 2000 resource string
  404. //
  405. if(HIWORD(dwVersion) < WINDOWS_VERSION_NT5)
  406. {
  407. dwLkpVersion = HIWORD(dwVersion);
  408. }
  409. else
  410. {
  411. dwLkpVersion = WINDOWS_VERSION_BASE + (HIWORD(dwVersion) - WINDOWS_VERSION_NT5);
  412. }
  413. if(_tcsicmp(pszProductCode, TERMSERV_PRODUCTID_SKU) == 0)
  414. {
  415. //
  416. // Add a free keypack
  417. //
  418. if (HIWORD(dwVersion) == 5 && LOWORD(dwVersion) == 0)
  419. {
  420. _stprintf(
  421. pszProductId,
  422. TERMSERV_PRODUCTID_FORMAT,
  423. TERMSERV_PRODUCTID_SKU,
  424. HIWORD(dwVersion),
  425. 0,
  426. TERMSERV_FREE_TYPE
  427. );
  428. pszDescs = g_pszUSFreeKeyPackProductDesc;
  429. pszLocalizedDescs = g_pszLocalizedFreeKeyPackProductDesc;
  430. dwStatus = InsertLicensePack(
  431. tlsHandle,
  432. dwVersion,
  433. dwLkpVersion,
  434. PLATFORMID_FREE,
  435. LSKEYPACKTYPE_FREE, // local license pack no replication
  436. pszProductId,
  437. pszProductId,
  438. pszDescs,
  439. pszLocalizedDescs
  440. );
  441. }
  442. if(bFreeOnly)
  443. {
  444. goto cleanup;
  445. }
  446. //
  447. // Don't add this if enforce licenses.
  448. //
  449. #if !defined(ENFORCE_LICENSING) || defined(PRIVATE_DBG)
  450. //
  451. // Add a full version keypack, platform type is always 0xFF
  452. //
  453. if (HIWORD(dwVersion) == 5 && LOWORD(dwVersion) == 1)
  454. {
  455. _stprintf(
  456. pszProductId,
  457. TERMSERV_PRODUCTID_FORMAT,
  458. TERMSERV_PRODUCTID_SKU,
  459. HIWORD(dwVersion),
  460. 0,
  461. TERMSERV_FULLVERSION_TYPE
  462. );
  463. pszDescs = g_pszUSStandardKeyPackProductString51;
  464. pszLocalizedDescs = g_pszLocalizedStandardKeyPackProductString51;
  465. }
  466. else if (HIWORD(dwVersion) == 5 && LOWORD(dwVersion) == 0)
  467. {
  468. _stprintf(
  469. pszProductId,
  470. TERMSERV_PRODUCTID_FORMAT,
  471. TERMSERV_PRODUCTID_SKU,
  472. HIWORD(dwVersion),
  473. 0,
  474. TERMSERV_FULLVERSION_TYPE
  475. );
  476. pszDescs = g_pszUSStandardKeyPackProductString;
  477. pszLocalizedDescs = g_pszLocalizedStandardKeyPackProductString;
  478. }
  479. else
  480. {
  481. dwStatus = ERROR_INVALID_PARAMETER;
  482. goto cleanup;
  483. }
  484. dwStatus = InsertLicensePack(
  485. tlsHandle,
  486. dwVersion,
  487. dwLkpVersion,
  488. PLATFORMID_OTHERS,
  489. LSKEYPACKTYPE_RETAIL,
  490. pszProductId,
  491. pszProductId,
  492. pszDescs,
  493. pszLocalizedDescs
  494. );
  495. #endif
  496. }
  497. else if(_tcsicmp(pszProductCode, TERMSERV_INTERNET_SKU) == 0)
  498. {
  499. //
  500. // Don't add this if enforce licenses.
  501. //
  502. #if !defined(ENFORCE_LICENSING) || defined(PRIVATE_DBG)
  503. //
  504. // Add internet package
  505. //
  506. if (HIWORD(dwVersion) == 5 && LOWORD(dwVersion) == 0)
  507. {
  508. _stprintf(
  509. pszProductId,
  510. TERMSERV_PRODUCTID_FORMAT,
  511. TERMSERV_INTERNET_SKU,
  512. HIWORD(dwVersion),
  513. 0,
  514. TERMSERV_INTERNET_TYPE
  515. );
  516. pszDescs = g_pszUSInternetKeyPackProductDesc;
  517. pszLocalizedDescs = g_pszLocalizedInternetKeyPackProductDesc;
  518. }
  519. else
  520. {
  521. dwStatus = ERROR_INVALID_PARAMETER;
  522. goto cleanup;
  523. }
  524. dwStatus = InsertLicensePack(
  525. tlsHandle,
  526. dwVersion,
  527. dwLkpVersion,
  528. PLATFORMID_OTHERS,
  529. LSKEYPACKTYPE_RETAIL,
  530. pszProductId,
  531. pszProductId,
  532. pszDescs,
  533. pszLocalizedDescs
  534. );
  535. #endif
  536. }
  537. else if(_tcsicmp(pszProductCode, TERMSERV_CONCURRENT_SKU) == 0)
  538. {
  539. //
  540. // Don't add this if enforce licenses.
  541. //
  542. #if !defined(ENFORCE_LICENSING) || defined(PRIVATE_DBG)
  543. //
  544. // Add Concurrent package
  545. //
  546. if (HIWORD(dwVersion) == 5 && LOWORD(dwVersion) == 1)
  547. {
  548. _stprintf(
  549. pszProductId,
  550. TERMSERV_PRODUCTID_FORMAT,
  551. TERMSERV_CONCURRENT_SKU,
  552. HIWORD(dwVersion),
  553. 0,
  554. TERMSERV_CONCURRENT_TYPE
  555. );
  556. pszDescs = g_pszUSConcurrentKeyPackProductDesc51;
  557. pszLocalizedDescs = g_pszLocalizedConcurrentKeyPackProductDesc51;
  558. }
  559. else
  560. {
  561. dwStatus = ERROR_INVALID_PARAMETER;
  562. goto cleanup;
  563. }
  564. dwStatus = InsertLicensePack(
  565. tlsHandle,
  566. dwVersion,
  567. dwLkpVersion,
  568. PLATFORMID_OTHERS,
  569. LSKEYPACKTYPE_RETAIL,
  570. pszProductId,
  571. pszProductId,
  572. pszDescs,
  573. pszLocalizedDescs
  574. );
  575. #endif
  576. }
  577. cleanup:
  578. if(tlsHandle != NULL)
  579. {
  580. TLSDisconnectFromServer(tlsHandle);
  581. }
  582. return dwStatus;
  583. }
  584. ////////////////////////////////////////////////////////
  585. DWORD
  586. InsertLicensePack(
  587. IN TLS_HANDLE tlsHandle,
  588. IN DWORD dwProdVersion,
  589. IN DWORD dwDescVersion,
  590. IN DWORD dwPlatformType,
  591. IN UCHAR ucAgreementType,
  592. IN LPTSTR pszProductId,
  593. IN LPTSTR pszKeyPackId,
  594. IN LPTSTR pszUsDesc[],
  595. IN LPTSTR pszLocalizedDesc[]
  596. )
  597. /*++
  598. pdwResourceId
  599. US Company Name
  600. US Product Name
  601. US Product Desc
  602. Localize Company Name
  603. Localize Product Name
  604. Localize Product Desc
  605. ++*/
  606. {
  607. RPC_STATUS rpcStatus;
  608. BOOL bSuccess;
  609. DWORD dwStatus = ERROR_SUCCESS;
  610. TCHAR buffer[LSERVER_MAX_STRING_SIZE];
  611. struct tm expired_tm;
  612. LSKeyPack keypack;
  613. if(pszProductId == NULL || pszKeyPackId == NULL)
  614. {
  615. SetLastError(ERROR_INVALID_PARAMETER);
  616. goto cleanup;
  617. }
  618. memset(&keypack, 0, sizeof(keypack));
  619. keypack.ucKeyPackType = ucAgreementType;
  620. SAFESTRCPY(keypack.szKeyPackId, pszKeyPackId);
  621. SAFESTRCPY(keypack.szProductId, pszProductId);
  622. SAFESTRCPY(keypack.szCompanyName, pszUsDesc[INDEX_COMPANYNAME]);
  623. SAFESTRCPY(keypack.szProductName, pszUsDesc[INDEX_PRODUCTNAME]);
  624. SAFESTRCPY(keypack.szProductDesc, pszUsDesc[INDEX_PRODUCTDESC]);
  625. keypack.wMajorVersion = HIWORD(dwProdVersion);
  626. keypack.wMinorVersion = LOWORD(dwProdVersion);
  627. keypack.dwPlatformType = dwPlatformType;
  628. keypack.ucLicenseType = LSKEYPACKLICENSETYPE_NEW;
  629. keypack.dwLanguageId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  630. keypack.ucChannelOfPurchase = LSKEYPACKCHANNELOFPURCHASE_RETAIL;
  631. SAFESTRCPY(
  632. keypack.szBeginSerialNumber,
  633. _TEXT("0000001")
  634. );
  635. keypack.dwTotalLicenseInKeyPack = (ucAgreementType == LSKEYPACKTYPE_FREE) ? INT_MAX : 0;
  636. keypack.dwProductFlags = 0x00;
  637. keypack.ucKeyPackStatus = LSKEYPACKSTATUS_ACTIVE;
  638. keypack.dwActivateDate = (DWORD) time(NULL);
  639. memset(&expired_tm, 0, sizeof(expired_tm));
  640. expired_tm.tm_year = 2036 - 1900; // expire on 2036/1/1
  641. expired_tm.tm_mday = 1;
  642. keypack.dwExpirationDate = mktime(&expired_tm);
  643. rpcStatus = TLSKeyPackAdd(
  644. tlsHandle,
  645. &keypack,
  646. &dwStatus
  647. );
  648. if(rpcStatus != RPC_S_OK)
  649. {
  650. dwStatus = GetLastError();
  651. goto cleanup;
  652. }
  653. if(dwStatus != ERROR_SUCCESS)
  654. {
  655. goto cleanup;
  656. }
  657. if(GetSystemDefaultLangID() != keypack.dwLanguageId)
  658. {
  659. if( pszLocalizedDesc[INDEX_COMPANYNAME] != NULL &&
  660. pszLocalizedDesc[INDEX_PRODUCTNAME] != NULL &&
  661. pszLocalizedDesc[INDEX_PRODUCTDESC] != NULL
  662. )
  663. {
  664. //
  665. // Insert localize license pack description
  666. //
  667. keypack.dwLanguageId = GetSystemDefaultLangID();
  668. SAFESTRCPY(keypack.szCompanyName, pszLocalizedDesc[INDEX_COMPANYNAME]);
  669. SAFESTRCPY(keypack.szProductName, pszLocalizedDesc[INDEX_PRODUCTNAME]);
  670. SAFESTRCPY(keypack.szProductDesc, pszLocalizedDesc[INDEX_PRODUCTDESC]);
  671. keypack.ucKeyPackStatus = LSKEYPACKSTATUS_ADD_DESC;
  672. rpcStatus = TLSKeyPackAdd(
  673. tlsHandle,
  674. &keypack,
  675. &dwStatus
  676. );
  677. if(rpcStatus != RPC_S_OK)
  678. {
  679. dwStatus = GetLastError();
  680. goto cleanup;
  681. }
  682. if(dwStatus != ERROR_SUCCESS)
  683. {
  684. goto cleanup;
  685. }
  686. }
  687. }
  688. //
  689. // Activate keypack
  690. //
  691. keypack.ucKeyPackStatus = LSKEYPACKSTATUS_ACTIVE;
  692. keypack.dwActivateDate = (DWORD) time(NULL);
  693. memset(&expired_tm, 0, sizeof(expired_tm));
  694. expired_tm.tm_year = 2036 - 1900; // expire on 2036/1/1
  695. expired_tm.tm_mday = 1;
  696. keypack.dwExpirationDate = mktime(&expired_tm);
  697. rpcStatus = TLSKeyPackSetStatus(
  698. tlsHandle,
  699. LSKEYPACK_SET_KEYPACKSTATUS | LSKEYPACK_SET_ACTIVATEDATE | LSKEYPACK_SET_EXPIREDATE,
  700. &keypack,
  701. &dwStatus
  702. );
  703. if(rpcStatus != RPC_S_OK)
  704. {
  705. dwStatus = GetLastError();
  706. }
  707. cleanup:
  708. return dwStatus;
  709. }
  710. ////////////////////////////////////////////////////////
  711. BOOL
  712. LicenseTypeFromLookupTable(
  713. IN DWORD dwClientVer,
  714. IN DWORD dwTermSrvVer,
  715. OUT PDWORD pdwCALType
  716. )
  717. {
  718. if (dwClientVer < NUMBER_OF_CLIENT_OS && dwTermSrvVer < NUMBER_OF_TERMSRV_OS)
  719. {
  720. *pdwCALType = LicenseTable[dwClientVer][dwTermSrvVer];
  721. return TRUE;
  722. }
  723. else
  724. {
  725. return FALSE;
  726. }
  727. }
  728. ////////////////////////////////////////////////////////
  729. POLICYSTATUS
  730. AdjustNewLicenseRequest(
  731. IN CClient* pClient,
  732. IN PPMLICENSEREQUEST pRequest,
  733. IN OUT PPMLICENSEREQUEST* pAdjustedRequest,
  734. IN UCHAR ucMarkedTemp,
  735. OUT PDWORD pdwErrCode
  736. )
  737. /*++
  738. Abstract:
  739. AdjustNewLicenseRequest fine tune license request for product 236
  740. Parameter:
  741. pClient - Pointer to CClient object.
  742. pRequest - Original request from TermSrv.
  743. pAdjustedRequest - 'Fine tuned' license request.
  744. ucMarkedTemp - Flags on the temporary license passed in (if any)
  745. pdwErrCode - error code
  746. Return:
  747. ERROR_SUCCESS or error code.
  748. ++*/
  749. {
  750. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  751. DWORD dwTermSrvOSId;
  752. DWORD dwTermSrvProductVersion;
  753. LPTSTR pszProductType=NULL;
  754. TCHAR pszProductId[MAX_TERMSRV_PRODUCTID+1];
  755. BOOL bTryInsert=FALSE;
  756. DWORD dwClientOSId;
  757. DWORD dwLicType;
  758. DWORD dwTermSrvIndex = 0;
  759. DWORD dwClientIndex = 0;
  760. //
  761. // Allocate memory for adjusted product ID
  762. //
  763. *pAdjustedRequest = (PPMLICENSEREQUEST) pClient->AllocateMemory(
  764. MEMORY_LICENSE_REQUEST,
  765. sizeof(PMLICENSEREQUEST)
  766. );
  767. if(*pAdjustedRequest == NULL)
  768. {
  769. dwStatus = POLICY_CRITICAL_ERROR;
  770. SetLastError( *pdwErrCode = ERROR_OUTOFMEMORY );
  771. goto cleanup;
  772. }
  773. //
  774. // Fields we don't modify
  775. //
  776. (*pAdjustedRequest)->dwProductVersion = pRequest->dwProductVersion;
  777. (*pAdjustedRequest)->pszCompanyName = pRequest->pszCompanyName;
  778. (*pAdjustedRequest)->dwLanguageId = pRequest->dwLanguageId;
  779. (*pAdjustedRequest)->pszMachineName = pRequest->pszMachineName;
  780. (*pAdjustedRequest)->pszUserName = pRequest->pszUserName;
  781. (*pAdjustedRequest)->dwSupportFlags = pRequest->dwSupportFlags;
  782. //
  783. // request platform ID is the OS ID
  784. //
  785. //
  786. // TermServ exists from NT40 so termsrv OS ID start 2,
  787. // see platform.h
  788. //
  789. dwTermSrvOSId = HIWORD(pRequest->dwProductVersion) - 2;
  790. if((HIWORD(pRequest->dwProductVersion) == 5) && (LOWORD(pRequest->dwProductVersion) == 0))
  791. {
  792. dwTermSrvIndex = TERMSRV_OS_INDEX_WINNT_5_0;
  793. }
  794. else if((HIWORD(pRequest->dwProductVersion) == 5) && (LOWORD(pRequest->dwProductVersion) == 1))
  795. {
  796. dwTermSrvIndex = TERMSRV_OS_INDEX_WINNT_5_1;
  797. }
  798. else if((HIWORD(pRequest->dwProductVersion) > 5) || ((HIWORD(pRequest->dwProductVersion) == 5) && (LOWORD(pRequest->dwProductVersion) > 1)))
  799. {
  800. dwTermSrvIndex = TERMSRV_OS_INDEX_WINNT_POST_5_1;
  801. }
  802. else
  803. {
  804. dwStatus = POLICY_CRITICAL_ERROR;
  805. }
  806. dwClientOSId = GetOSId(pRequest->dwPlatformId);
  807. (*pAdjustedRequest)->fTemporary = FALSE;
  808. if(_tcsicmp(pRequest->pszProductId, TERMSERV_PRODUCTID_SKU) == 0)
  809. {
  810. switch(GetOSId(pRequest->dwPlatformId))
  811. {
  812. case CLIENT_OS_ID_WINNT_351:
  813. case CLIENT_OS_ID_WINNT_40:
  814. case CLIENT_OS_ID_OTHER:
  815. dwClientIndex = CLIENT_OS_INDEX_OTHER;
  816. break;
  817. case CLIENT_OS_ID_WINNT_50:
  818. {
  819. if((GetImageRevision(pRequest->dwPlatformId)) == 0)
  820. {
  821. dwClientIndex = CLIENT_OS_INDEX_WINNT_50;
  822. }
  823. else if((GetImageRevision(pRequest->dwPlatformId)) == CLIENT_OS_ID_MINOR_WINNT_51)
  824. {
  825. dwClientIndex = CLIENT_OS_INDEX_WINNT_51;
  826. }
  827. else
  828. {
  829. dwClientIndex = CLIENT_OS_INDEX_WINNT_POST_51;
  830. }
  831. }
  832. break;
  833. case CLIENT_OS_ID_WINNT_POST_51:
  834. dwClientIndex = CLIENT_OS_INDEX_WINNT_POST_51;
  835. break;
  836. default:
  837. dwStatus = POLICY_CRITICAL_ERROR;
  838. break;
  839. }
  840. pszProductType = TERMSERV_FULLVERSION_TYPE;
  841. (*pAdjustedRequest)->dwPlatformId = PLATFORMID_OTHERS;
  842. dwTermSrvProductVersion = pRequest->dwProductVersion;
  843. if(LicenseTypeFromLookupTable(dwClientIndex, dwTermSrvIndex, &dwLicType))
  844. {
  845. if(dwLicType == ALLOW_BUILTIN)
  846. {
  847. pszProductType = TERMSERV_FREE_TYPE;
  848. (*pAdjustedRequest)->dwPlatformId = PLATFORMID_FREE;
  849. //
  850. // Add license pack if necessary
  851. //
  852. if(HIWORD(pRequest->dwProductVersion) != CURRENT_TLSA02_VERSION)
  853. {
  854. AddA02KeyPack( TERMSERV_PRODUCTID_SKU, pRequest->dwProductVersion, TRUE );
  855. }
  856. }
  857. }
  858. if ((*pAdjustedRequest)->dwPlatformId != PLATFORMID_FREE)
  859. {
  860. if (pRequest->dwSupportFlags & SUPPORT_PER_SEAT_POST_LOGON)
  861. {
  862. // We're doing the Per-Seat Post-Logon fix for DoS
  863. if (!(ucMarkedTemp & MARK_FLAG_USER_AUTHENTICATED))
  864. {
  865. // No previous temporary, or temporary wasn't marked
  866. // as authenticated
  867. (*pAdjustedRequest)->fTemporary = TRUE;
  868. }
  869. }
  870. }
  871. }
  872. else
  873. {
  874. if (_tcsicmp(pRequest->pszProductId, TERMSERV_CONCURRENT_SKU) == 0)
  875. {
  876. pszProductType = TERMSERV_CONCURRENT_TYPE;
  877. }
  878. else if (_tcsicmp(pRequest->pszProductId, TERMSERV_INTERNET_SKU) == 0)
  879. {
  880. pszProductType = TERMSERV_INTERNET_TYPE;
  881. }
  882. else
  883. {
  884. dwStatus = POLICY_CRITICAL_ERROR;
  885. SetLastError( *pdwErrCode = ERROR_INVALID_PARAMETER );
  886. goto cleanup;
  887. }
  888. dwTermSrvProductVersion = pRequest->dwProductVersion;
  889. (*pAdjustedRequest)->dwPlatformId = PLATFORMID_OTHERS;
  890. }
  891. _sntprintf(pszProductId,
  892. MAX_TERMSRV_PRODUCTID,
  893. TERMSERV_PRODUCTID_FORMAT,
  894. pRequest->pszProductId,
  895. HIWORD(dwTermSrvProductVersion),
  896. LOWORD(dwTermSrvProductVersion),
  897. pszProductType);
  898. //
  899. // allocate memory for product Id
  900. //
  901. (*pAdjustedRequest)->pszProductId = (LPTSTR)pClient->AllocateMemory(
  902. MEMORY_STRING,
  903. (_tcslen(pszProductId) + 1) * sizeof(TCHAR)
  904. );
  905. if((*pAdjustedRequest)->pszProductId == NULL)
  906. {
  907. dwStatus = POLICY_CRITICAL_ERROR;
  908. SetLastError( *pdwErrCode = ERROR_OUTOFMEMORY );
  909. goto cleanup;
  910. }
  911. _tcscpy(
  912. (*pAdjustedRequest)->pszProductId,
  913. pszProductId
  914. );
  915. cleanup:
  916. return dwStatus;
  917. }
  918. ////////////////////////////////////////////////////////
  919. POLICYSTATUS
  920. ProcessLicenseRequest(
  921. PMHANDLE client,
  922. PPMLICENSEREQUEST pbRequest,
  923. PPMLICENSEREQUEST* pbAdjustedRequest,
  924. PDWORD pdwErrCode
  925. )
  926. /*++
  927. ++*/
  928. {
  929. CClient* pClient;
  930. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  931. //
  932. // find client's object, client handle manager will
  933. // create a new one.
  934. pClient = g_ClientMgr->FindClient((PMHANDLE)client);
  935. if(pClient == NULL)
  936. {
  937. dwStatus = POLICY_CRITICAL_ERROR;
  938. *pdwErrCode = TLSA02_E_INTERNALERROR;
  939. goto cleanup;
  940. }
  941. //
  942. // AdjustNewLicenseRequest
  943. //
  944. dwStatus = AdjustNewLicenseRequest(
  945. pClient,
  946. pbRequest,
  947. pbAdjustedRequest,
  948. NULL, // no previous license
  949. pdwErrCode
  950. );
  951. cleanup:
  952. return dwStatus;
  953. }
  954. //--------------------------------------------------------------
  955. POLICYSTATUS
  956. ProcessAllocateRequest(
  957. PMHANDLE client,
  958. DWORD dwSuggestType,
  959. PDWORD pdwKeyPackType,
  960. PDWORD pdwErrCode
  961. )
  962. /*++
  963. Default sequence is always FREE/RETAIL/OPEN/SELECT/TEMPORARY
  964. ++*/
  965. {
  966. switch(dwSuggestType)
  967. {
  968. case LSKEYPACKTYPE_UNKNOWN:
  969. *pdwKeyPackType = LSKEYPACKTYPE_FREE;
  970. break;
  971. case LSKEYPACKTYPE_FREE:
  972. *pdwKeyPackType = LSKEYPACKTYPE_RETAIL;
  973. break;
  974. case LSKEYPACKTYPE_RETAIL:
  975. *pdwKeyPackType = LSKEYPACKTYPE_OPEN;
  976. break;
  977. case LSKEYPACKTYPE_OPEN:
  978. *pdwKeyPackType = LSKEYPACKTYPE_SELECT;
  979. break;
  980. case LSKEYPACKTYPE_SELECT:
  981. //
  982. // FALL THRU
  983. //
  984. default:
  985. //
  986. // No more keypack to look for, instruct license
  987. // server to terminate.
  988. //
  989. *pdwKeyPackType = LSKEYPACKTYPE_UNKNOWN;
  990. break;
  991. }
  992. *pdwErrCode = ERROR_SUCCESS;
  993. return POLICY_SUCCESS;
  994. }
  995. //-------------------------------------------------------------
  996. POLICYSTATUS WINAPI
  997. ProcessKeyPackDesc(
  998. IN PMHANDLE client,
  999. IN PPMKEYPACKDESCREQ pDescReq,
  1000. IN OUT PPMKEYPACKDESC* pDesc,
  1001. IN OUT PDWORD pdwErrCode
  1002. )
  1003. /*++
  1004. ++*/
  1005. {
  1006. CClient* pClient;
  1007. POLICYSTATUS dwStatus=POLICY_SUCCESS;
  1008. DWORD usLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  1009. BOOL bSuccess;
  1010. DWORD dwMajorVersion;
  1011. DWORD dwMinorVersion;
  1012. DWORD dwDescVersion;
  1013. TCHAR szPreFix[MAX_SKU_PREFIX];
  1014. TCHAR szPostFix[MAX_SKU_POSTFIX];
  1015. TCHAR szDesc[MAX_TERMSRV_PRODUCTID+1];
  1016. DWORD i;
  1017. LPTSTR* pszKeyPackDesc;
  1018. LPTSTR* pszUSKeyPackDesc;
  1019. if(pDescReq == NULL || pDesc == NULL)
  1020. {
  1021. dwStatus = POLICY_ERROR;
  1022. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1023. goto cleanup;
  1024. }
  1025. //
  1026. // find client's object, client handle manager will
  1027. // create a new one.
  1028. pClient = g_ClientMgr->FindClient((PMHANDLE)client);
  1029. if(pClient == NULL)
  1030. {
  1031. dwStatus = POLICY_CRITICAL_ERROR;
  1032. *pdwErrCode = TLSA02_E_INTERNALERROR;
  1033. goto cleanup;
  1034. }
  1035. for (i = 0; i < g_dwNumSupportedProduct; i++)
  1036. {
  1037. if(_tcsnicmp(
  1038. pDescReq->pszProductId,
  1039. g_pszSupportedProduct[i].szTLSProductCode,
  1040. _tcslen(g_pszSupportedProduct[i].szTLSProductCode)) == 0)
  1041. {
  1042. break;
  1043. }
  1044. }
  1045. if (i >= g_dwNumSupportedProduct)
  1046. {
  1047. //
  1048. // This is not ours
  1049. //
  1050. dwStatus = POLICY_ERROR;
  1051. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1052. goto cleanup;
  1053. }
  1054. _stscanf(
  1055. pDescReq->pszProductId,
  1056. TERMSERV_PRODUCTID_FORMAT,
  1057. szPreFix,
  1058. &dwMajorVersion,
  1059. &dwMinorVersion,
  1060. szPostFix
  1061. );
  1062. if(dwMajorVersion < WINDOWS_VERSION_NT5)
  1063. {
  1064. dwDescVersion = dwMajorVersion;
  1065. }
  1066. else
  1067. {
  1068. dwDescVersion = WINDOWS_VERSION_BASE + dwMajorVersion - WINDOWS_VERSION_NT5;
  1069. }
  1070. //
  1071. // Detemine which resource string we should load,
  1072. // string dependency on resource ID.
  1073. //
  1074. if(_tcsicmp(szPreFix, TERMSERV_PRODUCTID_SKU) == 0)
  1075. {
  1076. if(_tcsicmp(szPostFix, TERMSERV_FULLVERSION_TYPE) == 0)
  1077. {
  1078. if (dwMajorVersion == 5 && dwMinorVersion == 1)
  1079. {
  1080. pszKeyPackDesc = g_pszLocalizedStandardKeyPackProductString51;
  1081. pszUSKeyPackDesc = g_pszUSStandardKeyPackProductString51;
  1082. }
  1083. else if (dwMajorVersion == 5 && dwMinorVersion == 0)
  1084. {
  1085. pszKeyPackDesc = g_pszLocalizedStandardKeyPackProductString;
  1086. pszUSKeyPackDesc = g_pszUSStandardKeyPackProductString;
  1087. }
  1088. else
  1089. {
  1090. dwStatus = POLICY_ERROR;
  1091. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1092. goto cleanup;
  1093. }
  1094. if( pDescReq->dwLangId == usLangId ||
  1095. pszKeyPackDesc[INDEX_COMPANYNAME] == NULL ||
  1096. pszKeyPackDesc[INDEX_PRODUCTNAME] == NULL ||
  1097. pszKeyPackDesc[INDEX_PRODUCTDESC] == NULL )
  1098. {
  1099. //
  1100. // resource not found, use english desc.
  1101. pszKeyPackDesc = pszUSKeyPackDesc;
  1102. }
  1103. }
  1104. else if(_tcsicmp(szPostFix, TERMSERV_FREE_TYPE) == 0)
  1105. {
  1106. if (dwMajorVersion == 5 && dwMinorVersion == 0)
  1107. {
  1108. pszKeyPackDesc = g_pszLocalizedFreeKeyPackProductDesc;
  1109. pszUSKeyPackDesc = g_pszUSFreeKeyPackProductDesc;
  1110. }
  1111. else
  1112. {
  1113. dwStatus = POLICY_ERROR;
  1114. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1115. goto cleanup;
  1116. }
  1117. if( pDescReq->dwLangId == usLangId ||
  1118. pszKeyPackDesc[INDEX_COMPANYNAME] == NULL ||
  1119. pszKeyPackDesc[INDEX_PRODUCTNAME] == NULL ||
  1120. pszKeyPackDesc[INDEX_PRODUCTDESC] == NULL )
  1121. {
  1122. //
  1123. // resource not found, use english desc.
  1124. pszKeyPackDesc = pszUSKeyPackDesc;
  1125. }
  1126. }
  1127. else
  1128. {
  1129. //
  1130. // Something wrong, this is not ours
  1131. //
  1132. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1133. dwStatus = POLICY_ERROR;
  1134. goto cleanup;
  1135. }
  1136. }
  1137. else if(_tcsicmp(szPreFix, TERMSERV_INTERNET_SKU) == 0 && _tcsicmp(szPostFix, TERMSERV_INTERNET_TYPE) == 0)
  1138. {
  1139. if (dwMajorVersion == 5 && dwMinorVersion == 0)
  1140. {
  1141. pszKeyPackDesc = g_pszLocalizedInternetKeyPackProductDesc;
  1142. pszUSKeyPackDesc = g_pszUSInternetKeyPackProductDesc;
  1143. }
  1144. else
  1145. {
  1146. dwStatus = POLICY_ERROR;
  1147. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1148. goto cleanup;
  1149. }
  1150. if( pDescReq->dwLangId == usLangId ||
  1151. pszKeyPackDesc[INDEX_COMPANYNAME] == NULL ||
  1152. pszKeyPackDesc[INDEX_PRODUCTNAME] == NULL ||
  1153. pszKeyPackDesc[INDEX_PRODUCTDESC] == NULL )
  1154. {
  1155. //
  1156. // resource not found, use english desc.
  1157. pszKeyPackDesc = pszUSKeyPackDesc;
  1158. }
  1159. }
  1160. else if(_tcsicmp(szPreFix, TERMSERV_CONCURRENT_SKU) == 0 && _tcsicmp(szPostFix, TERMSERV_CONCURRENT_TYPE) == 0)
  1161. {
  1162. if (dwMajorVersion == 5 && dwMinorVersion == 1)
  1163. {
  1164. pszKeyPackDesc = g_pszLocalizedConcurrentKeyPackProductDesc51;
  1165. pszUSKeyPackDesc = g_pszUSConcurrentKeyPackProductDesc51;
  1166. }
  1167. else
  1168. {
  1169. dwStatus = POLICY_ERROR;
  1170. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1171. goto cleanup;
  1172. }
  1173. if( pDescReq->dwLangId == usLangId ||
  1174. pszKeyPackDesc[INDEX_COMPANYNAME] == NULL ||
  1175. pszKeyPackDesc[INDEX_PRODUCTNAME] == NULL ||
  1176. pszKeyPackDesc[INDEX_PRODUCTDESC] == NULL )
  1177. {
  1178. //
  1179. // resource not found, use english desc.
  1180. pszKeyPackDesc = g_pszUSConcurrentKeyPackProductDesc51;
  1181. }
  1182. }
  1183. else
  1184. {
  1185. //
  1186. // Something wrong, this is not ours
  1187. //
  1188. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1189. dwStatus = POLICY_ERROR;
  1190. goto cleanup;
  1191. }
  1192. *pDesc = (PPMKEYPACKDESC)pClient->AllocateMemory(
  1193. MEMORY_KEYPACKDESC,
  1194. sizeof(PMKEYPACKDESC)
  1195. );
  1196. if(*pDesc == NULL)
  1197. {
  1198. SetLastError(*pdwErrCode = ERROR_OUTOFMEMORY);
  1199. dwStatus = POLICY_CRITICAL_ERROR;
  1200. goto cleanup;
  1201. }
  1202. SAFESTRCPY((*pDesc)->szCompanyName, pszKeyPackDesc[INDEX_COMPANYNAME]);
  1203. SAFESTRCPY((*pDesc)->szProductName, pszKeyPackDesc[INDEX_PRODUCTNAME]);
  1204. SAFESTRCPY((*pDesc)->szProductDesc, pszKeyPackDesc[INDEX_PRODUCTDESC]);
  1205. cleanup:
  1206. if(dwStatus != POLICY_SUCCESS)
  1207. {
  1208. *pDesc = NULL;
  1209. }
  1210. return dwStatus;
  1211. }
  1212. //-------------------------------------------------------------
  1213. POLICYSTATUS
  1214. ProcessGenLicenses(
  1215. PMHANDLE client,
  1216. PPMGENERATELICENSE pGenLicense,
  1217. PPMCERTEXTENSION *pCertExtension,
  1218. PDWORD pdwErrCode
  1219. )
  1220. /*++
  1221. ++*/
  1222. {
  1223. // No policy extension to return.
  1224. *pCertExtension = NULL;
  1225. *pdwErrCode = ERROR_SUCCESS;
  1226. return POLICY_SUCCESS;
  1227. }
  1228. //--------------------------------------------------------------
  1229. POLICYSTATUS
  1230. ProcessComplete(
  1231. PMHANDLE client,
  1232. DWORD dwErrCode,
  1233. PDWORD pdwErrCode
  1234. )
  1235. /*++
  1236. ++*/
  1237. {
  1238. //
  1239. // We don't store any data so ignore
  1240. // error code from license server
  1241. //
  1242. UNREFERENCED_PARAMETER(dwErrCode);
  1243. //
  1244. // Free memory allocated for the client
  1245. //
  1246. g_ClientMgr->DestroyClient( client );
  1247. *pdwErrCode = ERROR_SUCCESS;
  1248. return POLICY_SUCCESS;
  1249. }
  1250. //--------------------------------------------------------------
  1251. POLICYSTATUS WINAPI
  1252. PMLicenseRequest(
  1253. PMHANDLE client,
  1254. DWORD dwProgressCode,
  1255. PVOID pbProgressData,
  1256. PVOID* pbNewProgressData,
  1257. PDWORD pdwErrCode
  1258. )
  1259. /*++
  1260. ++*/
  1261. {
  1262. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1263. switch( dwProgressCode )
  1264. {
  1265. case REQUEST_NEW:
  1266. //
  1267. // License Server ask to fine tune the request.
  1268. //
  1269. dwStatus = ProcessLicenseRequest(
  1270. client,
  1271. (PPMLICENSEREQUEST) pbProgressData,
  1272. (PPMLICENSEREQUEST *) pbNewProgressData,
  1273. pdwErrCode
  1274. );
  1275. break;
  1276. case REQUEST_KEYPACKTYPE:
  1277. //
  1278. // License Server ask for the license pack type
  1279. //
  1280. dwStatus = ProcessAllocateRequest(
  1281. client,
  1282. #ifdef _WIN64
  1283. PtrToUlong(pbProgressData),
  1284. #else
  1285. (DWORD) pbProgressData,
  1286. #endif
  1287. (PDWORD) pbNewProgressData,
  1288. pdwErrCode
  1289. );
  1290. break;
  1291. case REQUEST_TEMPORARY:
  1292. //
  1293. // License Server ask if temporary license should be issued
  1294. //
  1295. *(BOOL *)pbNewProgressData = TRUE;
  1296. *pdwErrCode = ERROR_SUCCESS;
  1297. break;
  1298. case REQUEST_KEYPACKDESC:
  1299. //
  1300. // License Server is requesting a keypack description.
  1301. //
  1302. dwStatus = ProcessKeyPackDesc(
  1303. client,
  1304. (PPMKEYPACKDESCREQ) pbProgressData,
  1305. (PPMKEYPACKDESC *) pbNewProgressData,
  1306. pdwErrCode
  1307. );
  1308. break;
  1309. case REQUEST_GENLICENSE:
  1310. //
  1311. // License Server ask for certificate extension
  1312. //
  1313. dwStatus = ProcessGenLicenses(
  1314. client,
  1315. (PPMGENERATELICENSE) pbProgressData,
  1316. (PPMCERTEXTENSION *) pbNewProgressData,
  1317. pdwErrCode
  1318. );
  1319. break;
  1320. case REQUEST_COMPLETE:
  1321. //
  1322. // Request complete
  1323. //
  1324. dwStatus = ProcessComplete(
  1325. client,
  1326. #ifdef _WIN64
  1327. PtrToUlong(pbNewProgressData),
  1328. #else
  1329. (DWORD) pbNewProgressData,
  1330. #endif
  1331. pdwErrCode
  1332. );
  1333. break;
  1334. default:
  1335. //
  1336. // This tell License Server to use default value
  1337. //
  1338. *pbNewProgressData = NULL;
  1339. dwStatus = POLICY_ERROR;
  1340. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1341. }
  1342. return dwStatus;
  1343. }
  1344. //------------------------------------------------------------
  1345. typedef enum {
  1346. UPGRADELICENSE_ERROR=0,
  1347. UPGRADELICENSE_INVALID_LICENSE,
  1348. UPGRADELICENSE_NEWLICENSE,
  1349. UPGRADELICENSE_UPGRADE,
  1350. UPGRADELICENSE_ALREADYHAVE
  1351. } UPGRADELICENSE_STATUS;
  1352. ////////////////////////////////////////////////////////
  1353. UPGRADELICENSE_STATUS
  1354. RequireUpgradeType(
  1355. PPMUPGRADEREQUEST pUpgrade
  1356. )
  1357. /*++
  1358. ++*/
  1359. {
  1360. UPGRADELICENSE_STATUS dwRetCode = UPGRADELICENSE_UPGRADE;
  1361. DWORD index;
  1362. DWORD dwClientOSId;
  1363. DWORD dwTermSrvOSId;
  1364. DWORD dwClientMinorOSId;
  1365. //
  1366. // Verify input parameters
  1367. //
  1368. if(pUpgrade == NULL || pUpgrade->dwNumProduct == 0 || pUpgrade->pProduct == NULL)
  1369. {
  1370. SetLastError(ERROR_INVALID_PARAMETER);
  1371. dwRetCode = UPGRADELICENSE_ERROR;
  1372. goto cleanup;
  1373. }
  1374. //
  1375. // Make sure we only upgrade to same product
  1376. //
  1377. if(_tcsnicmp(pUpgrade->pUpgradeRequest->pszProductId, TERMSERV_PRODUCTID_SKU, _tcslen(TERMSERV_PRODUCTID_SKU)) != 0)
  1378. {
  1379. dwRetCode = UPGRADELICENSE_ERROR;
  1380. goto cleanup;
  1381. }
  1382. //
  1383. // simple licensed product verification,
  1384. // licensed product is in decending order
  1385. //
  1386. for(index=0; index < pUpgrade->dwNumProduct-1; index++)
  1387. {
  1388. if( pUpgrade->pProduct[index].bTemporary == FALSE &&
  1389. pUpgrade->pProduct[index+1].bTemporary == TRUE )
  1390. {
  1391. dwRetCode = UPGRADELICENSE_INVALID_LICENSE;
  1392. break;
  1393. }
  1394. }
  1395. if(dwRetCode == UPGRADELICENSE_INVALID_LICENSE)
  1396. {
  1397. goto cleanup;
  1398. }
  1399. //
  1400. // Skip licensed product that has later version
  1401. //
  1402. for(index=0; index < pUpgrade->dwNumProduct; index ++)
  1403. {
  1404. //
  1405. // If Licensed product version is older than request
  1406. if(CompareTLSVersions(pUpgrade->pProduct[index].LicensedProduct.dwProductVersion, pUpgrade->pUpgradeRequest->dwProductVersion) < 0)
  1407. {
  1408. break;
  1409. }
  1410. if( (CompareTLSVersions(pUpgrade->pProduct[index].LicensedProduct.dwProductVersion, pUpgrade->pUpgradeRequest->dwProductVersion) == 0) &&
  1411. (pUpgrade->pProduct[index].bTemporary))
  1412. {
  1413. // we want to break out of loop in the case where we have same version as request but is a temporary license
  1414. break;
  1415. }
  1416. if ((CompareTLSVersions(pUpgrade->pProduct[index].LicensedProduct.dwProductVersion,
  1417. pUpgrade->pUpgradeRequest->dwProductVersion) >= 0) &&
  1418. (!(pUpgrade->pProduct[index].bTemporary)))
  1419. {
  1420. // we already have a license.
  1421. dwRetCode = UPGRADELICENSE_ALREADYHAVE;
  1422. break;
  1423. }
  1424. }
  1425. //
  1426. // Win98 client connect to TS 5 to get a Full CAL, then upgrade to NT5, instruct
  1427. // license server to issue a Free CAL.
  1428. //
  1429. dwTermSrvOSId = HIWORD(pUpgrade->pUpgradeRequest->dwProductVersion) - 2;
  1430. dwClientOSId = GetOSId(pUpgrade->pUpgradeRequest->dwPlatformId);
  1431. dwClientMinorOSId = GetImageRevision(pUpgrade->pUpgradeRequest->dwPlatformId);
  1432. if(dwRetCode == UPGRADELICENSE_ALREADYHAVE)
  1433. {
  1434. //
  1435. // do nothing.
  1436. }
  1437. else if(index >= pUpgrade->dwNumProduct || pUpgrade->pProduct[index].bTemporary == TRUE)
  1438. {
  1439. // all license is temp, ask for new license.
  1440. dwRetCode = UPGRADELICENSE_NEWLICENSE;
  1441. }
  1442. else
  1443. {
  1444. // prev. licensed product is perm, ask for upgrade license
  1445. // ClientOSId: HIBYTE(HIWORD) contains Major version and LOBYTE(LOWORD) contains Minor version
  1446. // TermsrvOSId: LOBYTE(HIWORD) contains Major version and LOBYTE(LOWORD) contains Minor version
  1447. if((HIBYTE(HIWORD(dwClientOSId)) == LOBYTE(HIWORD(dwTermSrvOSId)) ? LOBYTE(LOWORD(dwClientMinorOSId)) - LOBYTE(LOWORD(dwTermSrvOSId)) : \
  1448. HIBYTE(HIWORD(dwClientOSId)) - LOBYTE(HIWORD(dwTermSrvOSId))) >= 0)
  1449. {
  1450. dwRetCode = UPGRADELICENSE_NEWLICENSE;
  1451. }
  1452. else
  1453. {
  1454. dwRetCode = UPGRADELICENSE_UPGRADE;
  1455. }
  1456. }
  1457. cleanup:
  1458. return dwRetCode;
  1459. }
  1460. ////////////////////////////////////////////////////////
  1461. POLICYSTATUS
  1462. AdjustUpgradeLicenseRequest(
  1463. IN CClient* pClient,
  1464. IN PPMUPGRADEREQUEST pUpgradeRequest,
  1465. IN PPMLICENSEREQUEST* pAdjustedRequest,
  1466. OUT PDWORD pdwErrCode
  1467. )
  1468. /*++
  1469. ++*/
  1470. {
  1471. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1472. PPMLICENSEREQUEST pRequest;
  1473. TCHAR pszProductId[MAX_TERMSRV_PRODUCTID+1];
  1474. if(pUpgradeRequest == NULL || pUpgradeRequest->pUpgradeRequest == NULL)
  1475. {
  1476. SetLastError(*pdwErrCode = ERROR_INVALID_PARAMETER);
  1477. dwStatus = POLICY_ERROR;
  1478. goto cleanup;
  1479. }
  1480. *pAdjustedRequest = (PPMLICENSEREQUEST) pClient->AllocateMemory(
  1481. MEMORY_LICENSE_REQUEST,
  1482. sizeof(PMLICENSEREQUEST)
  1483. );
  1484. if(*pAdjustedRequest == NULL)
  1485. {
  1486. SetLastError(*pdwErrCode = ERROR_OUTOFMEMORY);
  1487. dwStatus = POLICY_CRITICAL_ERROR;
  1488. goto cleanup;
  1489. }
  1490. pRequest = pUpgradeRequest->pUpgradeRequest;
  1491. //
  1492. // Fields we don't modify
  1493. //
  1494. (*pAdjustedRequest)->dwProductVersion = pRequest->dwProductVersion;
  1495. (*pAdjustedRequest)->pszCompanyName = pRequest->pszCompanyName;
  1496. (*pAdjustedRequest)->dwLanguageId = pRequest->dwLanguageId;
  1497. (*pAdjustedRequest)->pszMachineName = pRequest->pszMachineName;
  1498. (*pAdjustedRequest)->pszUserName = pRequest->pszUserName;
  1499. (*pAdjustedRequest)->dwSupportFlags = pRequest->dwSupportFlags;
  1500. //
  1501. // Change Request platform ID for upgrade
  1502. //
  1503. (*pAdjustedRequest)->dwPlatformId = PLATFORMID_OTHERS;
  1504. if (pRequest->dwSupportFlags & SUPPORT_PER_SEAT_POST_LOGON)
  1505. {
  1506. // We're doing the Per-Seat Post-Logon fix for DoS
  1507. (*pAdjustedRequest)->fTemporary = TRUE;
  1508. }
  1509. _sntprintf(
  1510. pszProductId,
  1511. MAX_TERMSRV_PRODUCTID,
  1512. TERMSERV_PRODUCTID_FORMAT,
  1513. TERMSERV_PRODUCTID_SKU,
  1514. HIWORD(pRequest->dwProductVersion),
  1515. LOWORD(pRequest->dwProductVersion),
  1516. TERMSERV_FULLVERSION_TYPE //PLATFORMID_OTHERS
  1517. );
  1518. //
  1519. // allocate memory for product Id
  1520. //
  1521. (*pAdjustedRequest)->pszProductId = (LPTSTR)pClient->AllocateMemory(
  1522. MEMORY_STRING,
  1523. (_tcslen(pszProductId) + 1) * sizeof(TCHAR)
  1524. );
  1525. if((*pAdjustedRequest)->pszProductId == NULL)
  1526. {
  1527. SetLastError( *pdwErrCode = ERROR_OUTOFMEMORY );
  1528. dwStatus = POLICY_CRITICAL_ERROR;
  1529. goto cleanup;
  1530. }
  1531. _tcscpy(
  1532. (*pAdjustedRequest)->pszProductId,
  1533. pszProductId
  1534. );
  1535. cleanup:
  1536. return dwStatus;
  1537. }
  1538. ////////////////////////////////////////////////////////
  1539. POLICYSTATUS
  1540. ProcessUpgradeRequest(
  1541. PMHANDLE hClient,
  1542. PPMUPGRADEREQUEST pUpgrade,
  1543. PPMLICENSEREQUEST* pbAdjustedRequest,
  1544. PDWORD pdwErrCode
  1545. )
  1546. /*++
  1547. ++*/
  1548. {
  1549. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1550. CClient* pClient;
  1551. UPGRADELICENSE_STATUS upgradeStatus;
  1552. //
  1553. // find client's object, client handle manager will
  1554. // create a new one.
  1555. pClient = g_ClientMgr->FindClient(hClient);
  1556. if(pClient == NULL)
  1557. {
  1558. *pdwErrCode = TLSA02_E_INTERNALERROR;
  1559. dwStatus = POLICY_CRITICAL_ERROR;
  1560. goto cleanup;
  1561. }
  1562. upgradeStatus = RequireUpgradeType(pUpgrade);
  1563. switch(upgradeStatus)
  1564. {
  1565. case UPGRADELICENSE_NEWLICENSE:
  1566. dwStatus = AdjustNewLicenseRequest(
  1567. pClient,
  1568. pUpgrade->pUpgradeRequest,
  1569. pbAdjustedRequest,
  1570. pUpgrade->pProduct[0].ucMarked,
  1571. pdwErrCode
  1572. );
  1573. break;
  1574. case UPGRADELICENSE_UPGRADE:
  1575. dwStatus = AdjustUpgradeLicenseRequest(
  1576. pClient,
  1577. pUpgrade,
  1578. pbAdjustedRequest,
  1579. pdwErrCode
  1580. );
  1581. break;
  1582. case UPGRADELICENSE_ALREADYHAVE:
  1583. *pbAdjustedRequest = &(pUpgrade->pProduct->LicensedProduct);
  1584. *pdwErrCode = ERROR_SUCCESS;
  1585. break;
  1586. default:
  1587. SetLastError(*pdwErrCode = TLSA02_E_INVALIDDATA);
  1588. dwStatus = POLICY_ERROR;
  1589. }
  1590. cleanup:
  1591. return dwStatus;
  1592. }
  1593. ////////////////////////////////////////////////////////
  1594. POLICYSTATUS WINAPI
  1595. PMLicenseUpgrade(
  1596. PMHANDLE hClient,
  1597. DWORD dwProgressCode,
  1598. PVOID pbProgressData,
  1599. PVOID *ppbReturnData,
  1600. PDWORD pdwErrCode
  1601. )
  1602. /*++
  1603. ++*/
  1604. {
  1605. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1606. switch(dwProgressCode)
  1607. {
  1608. case REQUEST_UPGRADE:
  1609. dwStatus = ProcessUpgradeRequest(
  1610. hClient,
  1611. (PPMUPGRADEREQUEST) pbProgressData,
  1612. (PPMLICENSEREQUEST *) ppbReturnData,
  1613. pdwErrCode
  1614. );
  1615. break;
  1616. case REQUEST_COMPLETE:
  1617. dwStatus = ProcessComplete(
  1618. hClient,
  1619. #ifdef _WIN64
  1620. PtrToUlong(pbProgressData),
  1621. #else
  1622. (DWORD) (pbProgressData),
  1623. #endif
  1624. pdwErrCode
  1625. );
  1626. break;
  1627. default:
  1628. //
  1629. // use default
  1630. //
  1631. *ppbReturnData = NULL;
  1632. *pdwErrCode = ERROR_SUCCESS;
  1633. }
  1634. return dwStatus;
  1635. }
  1636. ////////////////////////////////////////////////////////
  1637. POLICYSTATUS
  1638. PMReturnLicense(
  1639. IN PMHANDLE hClient,
  1640. IN ULARGE_INTEGER* pLicenseSerialNumber,
  1641. IN PPMLICENSETOBERETURN pLicenseTobeReturn,
  1642. OUT PDWORD pdwLicenseStatus,
  1643. OUT PDWORD pdwErrCode
  1644. )
  1645. /*++
  1646. Abstract
  1647. Return module specific license return policy.
  1648. Parameters
  1649. hClient - Client handle, assign by License Server.
  1650. pLicenseSerialNumber - client license serial number.
  1651. LicensePackId - License Pack where license was allocated from.
  1652. LicensePackLicenseId - License serial number in license pack.
  1653. pdwLicenseStatus - return what license server should
  1654. do with the license
  1655. Returns:
  1656. Function returns ERROR_SUCCESS or any policy module specific
  1657. error code, pdwLicenseStatus returns license return policy
  1658. Currently defined code:
  1659. LICENSE_RETURN_KEEP - keep license, no return to license pack
  1660. LICENSE_RETURN_DELETE - delete license and return to license pack.
  1661. ++*/
  1662. {
  1663. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1664. *pdwErrCode = ERROR_SUCCESS;
  1665. if ((_tcsicmp(pLicenseTobeReturn->pszOrgProductId,
  1666. TERMSERV_INTERNET_SKU) == 0)
  1667. || (_tcsicmp(pLicenseTobeReturn->pszOrgProductId,
  1668. TERMSERV_CONCURRENT_SKU) == 0))
  1669. {
  1670. *pdwLicenseStatus = LICENSE_RETURN_DELETE;
  1671. }
  1672. else if(_tcsicmp(pLicenseTobeReturn->pszOrgProductId,
  1673. TERMSERV_PRODUCTID_SKU) == 0)
  1674. {
  1675. // Always return license back to license pack
  1676. *pdwLicenseStatus = (pLicenseTobeReturn->bTemp == TRUE) ?
  1677. LICENSE_RETURN_DELETE : LICENSE_RETURN_KEEP;
  1678. }
  1679. else
  1680. {
  1681. *pdwErrCode = ERROR_INVALID_DATA;
  1682. dwStatus = POLICY_ERROR;
  1683. }
  1684. return dwStatus;
  1685. }
  1686. ////////////////////////////////////////////////////////
  1687. POLICYSTATUS WINAPI
  1688. PMInitialize(
  1689. IN DWORD dwVersion,
  1690. IN LPCTSTR pszCompanyName,
  1691. IN LPCTSTR pszProductCode,
  1692. IN OUT PDWORD pdwNumProduct,
  1693. IN OUT PPMSUPPORTEDPRODUCT* ppszProduct,
  1694. OUT PDWORD pdwErrCode
  1695. )
  1696. /*++
  1697. Abstract:
  1698. Initialize internal data use by this policy module. License
  1699. Server calls PMInitialize() after all API is available.
  1700. Parameters:
  1701. dwVersion - License Server version
  1702. pszCompanyName : Name of the company as listed in license server's registry key.
  1703. pszProductCode : Name of the product that license server assume this product supported.
  1704. pdwNumProduct : Pointer to DWORD, on return, ploicy module will set product supported.
  1705. ppszProduct : Pointer array to list of product supported by this policy module.
  1706. Returns:
  1707. ERROR_SUCCESS or error code.
  1708. ++*/
  1709. {
  1710. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1711. EXCEPTION_RECORD ExceptionCode;
  1712. //
  1713. // Initialize internal data here
  1714. //
  1715. if (CURRENT_TLSERVER_VERSION(dwVersion) < CURRENT_TLSA02_VERSION)
  1716. {
  1717. dwStatus = POLICY_CRITICAL_ERROR;
  1718. *pdwErrCode = TLSA02_E_INVALIDDATA;
  1719. goto cleanup;
  1720. }
  1721. try {
  1722. g_ClientMgr = new CClientMgr;
  1723. if(g_ClientMgr != NULL)
  1724. {
  1725. g_dwVersion = dwVersion;
  1726. if(pdwNumProduct != NULL && ppszProduct != NULL)
  1727. {
  1728. *pdwNumProduct = g_dwNumSupportedProduct;
  1729. *ppszProduct = g_pszSupportedProduct;
  1730. }
  1731. else
  1732. {
  1733. //
  1734. // Stop processing since this might be license server critical error.
  1735. //
  1736. dwStatus = POLICY_CRITICAL_ERROR;
  1737. *pdwErrCode = TLSA02_E_INVALIDDATA;
  1738. }
  1739. }
  1740. else
  1741. {
  1742. dwStatus = POLICY_CRITICAL_ERROR;
  1743. *pdwErrCode = ERROR_OUTOFMEMORY;
  1744. }
  1745. }
  1746. catch( SE_Exception e )
  1747. {
  1748. dwStatus = POLICY_CRITICAL_ERROR;
  1749. *pdwErrCode = e.getSeNumber();
  1750. }
  1751. catch( ... )
  1752. {
  1753. dwStatus = POLICY_CRITICAL_ERROR;
  1754. *pdwErrCode = TLSA02_E_INTERNALERROR;
  1755. }
  1756. cleanup:
  1757. return dwStatus;
  1758. }
  1759. ////////////////////////////////////////////////////////
  1760. void WINAPI
  1761. PMTerminate()
  1762. /*++
  1763. Abstract:
  1764. Free all internal data allocated by this policy module. License
  1765. Server calls PMTerminate() before it unload this policy module.
  1766. Parameter:
  1767. None.
  1768. Returns:
  1769. None.
  1770. ++*/
  1771. {
  1772. if(g_ClientMgr)
  1773. {
  1774. //
  1775. // Free internal data here
  1776. //
  1777. delete g_ClientMgr;
  1778. g_ClientMgr = NULL;
  1779. }
  1780. FreeProductDescString();
  1781. return;
  1782. }
  1783. ////////////////////////////////////////////////////////
  1784. POLICYSTATUS WINAPI
  1785. PMInitializeProduct(
  1786. IN LPCTSTR pszCompanyName,
  1787. IN LPCTSTR pszCHProductCode,
  1788. IN LPCTSTR pszTLSProductCode,
  1789. OUT PDWORD pdwErrCode
  1790. )
  1791. /*++
  1792. Abstract:
  1793. Return list of product code that this policy module supported
  1794. Parameters:
  1795. Returns:
  1796. ERROR_SUCCESS or error code.
  1797. Note:
  1798. License Server will not free the memory, policy module will need to
  1799. keep track.
  1800. ++*/
  1801. {
  1802. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1803. for(DWORD index = 0; index < g_dwNumSupportedProduct; index ++)
  1804. {
  1805. if( _tcsicmp(pszCHProductCode, g_pszSupportedProduct[index].szCHSetupCode) == 0 &&
  1806. _tcsicmp(pszTLSProductCode, g_pszSupportedProduct[index].szTLSProductCode) == 0)
  1807. {
  1808. break;
  1809. }
  1810. }
  1811. if(index >= g_dwNumSupportedProduct)
  1812. {
  1813. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1814. dwStatus = POLICY_ERROR;
  1815. }
  1816. else
  1817. {
  1818. //
  1819. // Ignore error here
  1820. //
  1821. AddA02KeyPack(
  1822. pszTLSProductCode,
  1823. MAKELONG(0, CURRENT_TLSERVER_VERSION(g_dwVersion)),
  1824. FALSE
  1825. );
  1826. }
  1827. *pdwErrCode = ERROR_SUCCESS;
  1828. return dwStatus;
  1829. }
  1830. ////////////////////////////////////////////////////////
  1831. POLICYSTATUS WINAPI
  1832. PMUnloadProduct(
  1833. IN LPCTSTR pszCompanyName,
  1834. IN LPCTSTR pszCHProductCode,
  1835. IN LPCTSTR pszTLSProductCode,
  1836. OUT PDWORD pdwErrCode
  1837. )
  1838. /*++
  1839. Abstract:
  1840. Return list of product code that this policy module supported
  1841. Parameters:
  1842. Returns:
  1843. ERROR_SUCCESS or error code.
  1844. Note:
  1845. License Server will not free the memory, policy module will need to
  1846. keep track.
  1847. ++*/
  1848. {
  1849. *pdwErrCode = ERROR_SUCCESS;
  1850. return POLICY_SUCCESS;
  1851. }
  1852. ////////////////////////////////////////////////////////
  1853. POLICYSTATUS
  1854. ProcessRegisterLicensePack(
  1855. IN PMHANDLE client,
  1856. IN PPMREGISTERLICENSEPACK pmLicensePack,
  1857. IN OUT PPMLSKEYPACK pmLsKeyPack,
  1858. OUT PDWORD pdwErrCode
  1859. )
  1860. /*++
  1861. --*/
  1862. {
  1863. TCHAR* szUuid = NULL;
  1864. BOOL bInternetPackage=FALSE;
  1865. BOOL bConcurrentPackage=FALSE;
  1866. CClient* pClient;
  1867. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  1868. if( pmLicensePack->SourceType != REGISTER_SOURCE_INTERNET &&
  1869. pmLicensePack->SourceType != REGISTER_SOURCE_PHONE )
  1870. {
  1871. dwStatus = POLICY_NOT_SUPPORTED;
  1872. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1873. goto cleanup;
  1874. }
  1875. if( pmLicensePack->SourceType == REGISTER_SOURCE_INTERNET &&
  1876. (pmLicensePack->dwDescriptionCount == 0 || pmLicensePack->pDescription == NULL) )
  1877. {
  1878. dwStatus = POLICY_ERROR;
  1879. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1880. goto cleanup;
  1881. }
  1882. if(CompareFileTime(&pmLicensePack->ActiveDate, &pmLicensePack->ExpireDate) > 0)
  1883. {
  1884. dwStatus = POLICY_ERROR;
  1885. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1886. goto cleanup;
  1887. }
  1888. //
  1889. // find client's object, client handle manager will
  1890. // create a new one.
  1891. pClient = g_ClientMgr->FindClient((PMHANDLE)client);
  1892. if(pClient == NULL)
  1893. {
  1894. dwStatus = POLICY_CRITICAL_ERROR;
  1895. *pdwErrCode = TLSA02_E_INTERNALERROR;
  1896. goto cleanup;
  1897. }
  1898. bInternetPackage = (_tcsicmp(pmLicensePack->szProductId, TERMSERV_INTERNET_SKU) == 0);
  1899. if (!bInternetPackage)
  1900. {
  1901. bConcurrentPackage = (_tcsicmp(pmLicensePack->szProductId, TERMSERV_CONCURRENT_SKU) == 0);
  1902. }
  1903. switch(pmLicensePack->dwKeyPackType)
  1904. {
  1905. case LICENSE_KEYPACK_TYPE_SELECT:
  1906. pmLsKeyPack->keypack.ucKeyPackType = LSKEYPACKTYPE_SELECT;
  1907. break;
  1908. case LICENSE_KEYPACK_TYPE_MOLP:
  1909. pmLsKeyPack->keypack.ucKeyPackType = LSKEYPACKTYPE_OPEN;
  1910. break;
  1911. case LICENSE_KEYPACK_TYPE_RETAIL:
  1912. pmLsKeyPack->keypack.ucKeyPackType = LSKEYPACKTYPE_RETAIL;
  1913. break;
  1914. default:
  1915. dwStatus = POLICY_ERROR;
  1916. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1917. goto cleanup;
  1918. }
  1919. // we only use 0xFF
  1920. pmLsKeyPack->keypack.dwPlatformType = PLATFORMID_OTHERS;
  1921. pmLsKeyPack->keypack.ucLicenseType = (UCHAR)pmLicensePack->dwLicenseType;
  1922. pmLsKeyPack->keypack.dwLanguageId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); // field ignore by license server.
  1923. pmLsKeyPack->keypack.ucChannelOfPurchase = (pmLicensePack->dwDistChannel == LICENSE_DISTRIBUTION_CHANNEL_OEM) ?
  1924. LSKEYPACKCHANNELOFPURCHASE_OEM :
  1925. LSKEYPACKCHANNELOFPURCHASE_RETAIL;
  1926. pmLsKeyPack->keypack.dwProductFlags = LSKEYPACKPRODUCTFLAG_UNKNOWN;
  1927. pmLsKeyPack->IssueDate = pmLicensePack->IssueDate;
  1928. pmLsKeyPack->ActiveDate = pmLicensePack->ActiveDate;
  1929. pmLsKeyPack->ExpireDate = pmLicensePack->ExpireDate;
  1930. //
  1931. // Tel. registration does not pass us any begin serial number, ignore this field
  1932. //
  1933. _stprintf(
  1934. pmLsKeyPack->keypack.szBeginSerialNumber,
  1935. _TEXT("%ld"),
  1936. 0 // pmLicensePack->dwBeginSerialNum
  1937. );
  1938. pmLsKeyPack->keypack.wMajorVersion = HIWORD(pmLicensePack->dwProductVersion);
  1939. pmLsKeyPack->keypack.wMinorVersion = LOWORD(pmLicensePack->dwProductVersion);
  1940. _tcscpy(
  1941. pmLsKeyPack->keypack.szCompanyName,
  1942. pmLicensePack->szCompanyName
  1943. );
  1944. //
  1945. // KeyPackId, tel. registration does not pass any begin license serial number so to be able
  1946. // to track duplicate, pmLicensePack->KeypackSerialNum.Data1 is the actual license pack
  1947. // serial number, all other field are ignored.
  1948. //
  1949. _sntprintf(
  1950. pmLsKeyPack->keypack.szKeyPackId,
  1951. sizeof(pmLsKeyPack->keypack.szKeyPackId)/sizeof(pmLsKeyPack->keypack.szKeyPackId[0]),
  1952. TERMSERV_KEYPACKID_FORMAT,
  1953. pmLicensePack->szProductId,
  1954. pmLsKeyPack->keypack.wMajorVersion,
  1955. pmLsKeyPack->keypack.wMinorVersion,
  1956. pmLsKeyPack->keypack.dwPlatformType,
  1957. pmLicensePack->KeypackSerialNum.Data1
  1958. );
  1959. _sntprintf(
  1960. pmLsKeyPack->keypack.szProductId,
  1961. sizeof(pmLsKeyPack->keypack.szProductId)/sizeof(pmLsKeyPack->keypack.szProductId[0]),
  1962. TERMSERV_PRODUCTID_FORMAT,
  1963. pmLicensePack->szProductId,
  1964. pmLsKeyPack->keypack.wMajorVersion,
  1965. pmLsKeyPack->keypack.wMinorVersion,
  1966. (!bInternetPackage)
  1967. ? ((!bConcurrentPackage) ? TERMSERV_FULLVERSION_TYPE : TERMSERV_CONCURRENT_TYPE)
  1968. : TERMSERV_INTERNET_TYPE
  1969. );
  1970. pmLsKeyPack->keypack.dwTotalLicenseInKeyPack = pmLicensePack->dwQuantity;
  1971. pmLsKeyPack->keypack.dwNumberOfLicenses = pmLicensePack->dwQuantity;
  1972. //
  1973. // Fill in list of product description
  1974. //
  1975. if( pmLicensePack->SourceType == REGISTER_SOURCE_INTERNET )
  1976. {
  1977. pmLsKeyPack->dwDescriptionCount = pmLicensePack->dwDescriptionCount;
  1978. pmLsKeyPack->pDescription = pmLicensePack->pDescription;
  1979. }
  1980. else
  1981. {
  1982. LPTSTR *pszDescs;
  1983. LPTSTR *pszLocalizedDescs;
  1984. //
  1985. // Verify version first...
  1986. //
  1987. if (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  1988. pmLsKeyPack->keypack.wMinorVersion == 1)
  1989. {
  1990. if (bConcurrentPackage)
  1991. {
  1992. pszDescs = g_pszUSConcurrentKeyPackProductDesc51;
  1993. pszLocalizedDescs = g_pszLocalizedConcurrentKeyPackProductDesc51;
  1994. }
  1995. else if (bInternetPackage)
  1996. {
  1997. *pdwErrCode = ERROR_INVALID_PARAMETER;
  1998. dwStatus = POLICY_CRITICAL_ERROR;
  1999. goto cleanup;
  2000. }
  2001. else
  2002. {
  2003. pszDescs = g_pszUSStandardKeyPackProductString51;
  2004. pszLocalizedDescs = g_pszLocalizedStandardKeyPackProductString51;
  2005. }
  2006. }
  2007. else if (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2008. pmLsKeyPack->keypack.wMinorVersion == 0)
  2009. {
  2010. if (bInternetPackage)
  2011. {
  2012. pszDescs = g_pszUSInternetKeyPackProductDesc;
  2013. pszLocalizedDescs = g_pszLocalizedInternetKeyPackProductDesc;
  2014. }
  2015. else if (bConcurrentPackage)
  2016. {
  2017. *pdwErrCode = ERROR_INVALID_PARAMETER;
  2018. dwStatus = POLICY_CRITICAL_ERROR;
  2019. goto cleanup;
  2020. }
  2021. else
  2022. {
  2023. pszDescs = g_pszUSStandardKeyPackProductString;
  2024. pszLocalizedDescs = g_pszLocalizedStandardKeyPackProductString;
  2025. }
  2026. }
  2027. else
  2028. {
  2029. *pdwErrCode = ERROR_INVALID_PARAMETER;
  2030. dwStatus = POLICY_CRITICAL_ERROR;
  2031. goto cleanup;
  2032. }
  2033. // one for english and one for localized version
  2034. pmLsKeyPack->dwDescriptionCount = (GetSystemDefaultLangID() != MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)) ? 2 : 1;
  2035. pmLsKeyPack->pDescription =
  2036. (PPMREGISTERLKPDESC) pClient->AllocateMemory(
  2037. MEMORY_LICENSEREGISTRATION,
  2038. sizeof(PMREGISTERLKPDESC) * pmLsKeyPack->dwDescriptionCount
  2039. );
  2040. if(pmLsKeyPack->pDescription == NULL)
  2041. {
  2042. *pdwErrCode = ERROR_OUTOFMEMORY;
  2043. dwStatus = POLICY_CRITICAL_ERROR;
  2044. goto cleanup;
  2045. }
  2046. pmLsKeyPack->pDescription->Locale = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  2047. if (bInternetPackage && (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2048. pmLsKeyPack->keypack.wMinorVersion == 0))
  2049. {
  2050. _tcscpy(
  2051. pmLsKeyPack->pDescription->szProductName,
  2052. g_pszUSInternetKeyPackProductDesc[INDEX_PRODUCTNAME]
  2053. );
  2054. _tcscpy(
  2055. pmLsKeyPack->pDescription->szProductDesc,
  2056. pszDescs[INDEX_PRODUCTDESC]
  2057. );
  2058. }
  2059. else if (bConcurrentPackage && (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2060. pmLsKeyPack->keypack.wMinorVersion == 1))
  2061. {
  2062. _tcscpy(
  2063. pmLsKeyPack->pDescription->szProductName,
  2064. g_pszUSConcurrentKeyPackProductDesc51[INDEX_PRODUCTNAME]
  2065. );
  2066. _tcscpy(
  2067. pmLsKeyPack->pDescription->szProductDesc,
  2068. pszDescs[INDEX_PRODUCTDESC]
  2069. );
  2070. }
  2071. else
  2072. {
  2073. if(bInternetPackage || bConcurrentPackage)
  2074. {
  2075. *pdwErrCode = ERROR_INVALID_PARAMETER;
  2076. dwStatus = POLICY_CRITICAL_ERROR;
  2077. goto cleanup;
  2078. }
  2079. if (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2080. pmLsKeyPack->keypack.wMinorVersion == 0)
  2081. {
  2082. _tcscpy(
  2083. pmLsKeyPack->pDescription->szProductName,
  2084. g_pszUSStandardKeyPackProductString[INDEX_PRODUCTNAME]
  2085. );
  2086. _tcscpy(
  2087. pmLsKeyPack->pDescription->szProductDesc,
  2088. pszDescs[INDEX_PRODUCTDESC]
  2089. );
  2090. }
  2091. else if(pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2092. pmLsKeyPack->keypack.wMinorVersion == 1)
  2093. {
  2094. _tcscpy(
  2095. pmLsKeyPack->pDescription->szProductName,
  2096. g_pszUSStandardKeyPackProductString51[INDEX_PRODUCTNAME]
  2097. );
  2098. _tcscpy(
  2099. pmLsKeyPack->pDescription->szProductDesc,
  2100. pszDescs[INDEX_PRODUCTDESC]
  2101. );
  2102. }
  2103. }
  2104. if(GetSystemDefaultLangID() != MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US))
  2105. {
  2106. pmLsKeyPack->pDescription[1].Locale = GetSystemDefaultLangID();
  2107. if (bInternetPackage && (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2108. pmLsKeyPack->keypack.wMinorVersion == 0))
  2109. {
  2110. _tcscpy(
  2111. pmLsKeyPack->pDescription[1].szProductName,
  2112. g_pszLocalizedInternetKeyPackProductDesc[INDEX_PRODUCTNAME]
  2113. );
  2114. _tcscpy(
  2115. pmLsKeyPack->pDescription[1].szProductDesc,
  2116. pszDescs[INDEX_PRODUCTDESC]
  2117. );
  2118. }
  2119. else if (bConcurrentPackage && (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2120. pmLsKeyPack->keypack.wMinorVersion == 1))
  2121. {
  2122. _tcscpy(
  2123. pmLsKeyPack->pDescription[1].szProductName,
  2124. g_pszLocalizedConcurrentKeyPackProductDesc51[INDEX_PRODUCTNAME]
  2125. );
  2126. _tcscpy(
  2127. pmLsKeyPack->pDescription[1].szProductDesc,
  2128. pszDescs[INDEX_PRODUCTDESC]
  2129. );
  2130. }
  2131. else
  2132. {
  2133. if(bInternetPackage || bConcurrentPackage)
  2134. {
  2135. *pdwErrCode = ERROR_INVALID_PARAMETER;
  2136. dwStatus = POLICY_CRITICAL_ERROR;
  2137. goto cleanup;
  2138. }
  2139. else if (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2140. pmLsKeyPack->keypack.wMinorVersion == 0)
  2141. {
  2142. _tcscpy(
  2143. pmLsKeyPack->pDescription[1].szProductName,
  2144. g_pszLocalizedStandardKeyPackProductString[INDEX_PRODUCTNAME]
  2145. );
  2146. _tcscpy(
  2147. pmLsKeyPack->pDescription[1].szProductDesc,
  2148. pszDescs[INDEX_PRODUCTDESC]
  2149. );
  2150. }
  2151. else if (pmLsKeyPack->keypack.wMajorVersion == 5 &&
  2152. pmLsKeyPack->keypack.wMinorVersion == 1)
  2153. {
  2154. _tcscpy(
  2155. pmLsKeyPack->pDescription->szProductName,
  2156. g_pszUSStandardKeyPackProductString51[INDEX_PRODUCTNAME]
  2157. );
  2158. _tcscpy(
  2159. pmLsKeyPack->pDescription->szProductDesc,
  2160. pszDescs[INDEX_PRODUCTDESC]
  2161. );
  2162. }
  2163. }
  2164. }
  2165. }
  2166. cleanup:
  2167. return dwStatus;
  2168. }
  2169. ////////////////////////////////////////////////////////
  2170. POLICYSTATUS
  2171. CompleteRegisterLicensePack(
  2172. IN PMHANDLE client,
  2173. IN DWORD dwErrCode,
  2174. OUT PDWORD pdwErrCode
  2175. )
  2176. /*++
  2177. --*/
  2178. {
  2179. UNREFERENCED_PARAMETER(dwErrCode);
  2180. //
  2181. // Free memory allocated for the client
  2182. //
  2183. g_ClientMgr->DestroyClient( client );
  2184. *pdwErrCode = ERROR_SUCCESS;
  2185. return POLICY_SUCCESS;
  2186. }
  2187. ////////////////////////////////////////////////////////
  2188. POLICYSTATUS WINAPI
  2189. PMRegisterLicensePack(
  2190. PMHANDLE client,
  2191. DWORD dwProgressCode,
  2192. PVOID pbProgressData,
  2193. PVOID pbReturnData,
  2194. PDWORD pdwErrCode
  2195. )
  2196. /*++
  2197. --*/
  2198. {
  2199. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  2200. switch(dwProgressCode)
  2201. {
  2202. case REGISTER_PROGRESS_NEW:
  2203. dwStatus = ProcessRegisterLicensePack(
  2204. client,
  2205. (PPMREGISTERLICENSEPACK) pbProgressData,
  2206. (PPMLSKEYPACK)pbReturnData,
  2207. pdwErrCode
  2208. );
  2209. break;
  2210. case REGISTER_PROGRESS_END:
  2211. dwStatus = CompleteRegisterLicensePack(
  2212. client,
  2213. #ifdef _WIN64
  2214. PtrToUlong(pbProgressData),
  2215. #else
  2216. (DWORD) pbProgressData,
  2217. #endif
  2218. pdwErrCode
  2219. );
  2220. break;
  2221. default:
  2222. *pdwErrCode = ERROR_INVALID_PARAMETER;
  2223. dwStatus = POLICY_ERROR;
  2224. }
  2225. return dwStatus;
  2226. }