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.

1109 lines
26 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: licensed.h
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #ifndef __TLS_LICENSED_H__
  13. #define __TLS_LICENSED_H__
  14. #include "JetBlue.h"
  15. #include "TlsDb.h"
  16. //
  17. // Not exported - not defined in tlsdef.h
  18. //
  19. #define LICENSE_COLUMN_SEARCH_SYSTEMBOIS 0x00200000
  20. #define LICENSE_COLUMN_SEARCH_VIDEOBIOS 0x00400000
  21. #define LICENSE_COLUMN_SEARCH_FLOPPYBIOS 0x00800000
  22. #define LICENSE_COLUMN_SEARCH_HARDDISKSIZE 0x01000000
  23. #define LICENSE_COLUMN_SEARCH_RAMSIZE 0x02000000
  24. #define LICENSE_COLUMN_SEARCH_HWID \
  25. (LICENSE_COLUMN_SEARCH_SYSTEMBOIS | LICENSE_COLUMN_SEARCH_VIDEOBIOS | \
  26. LICENSE_COLUMN_SEARCH_FLOPPYBIOS | LICENSE_COLUMN_SEARCH_HARDDISKSIZE | \
  27. LICENSE_COLUMN_SEARCH_RAMSIZE)
  28. #define LICENSE_PROCESS_LICENSEID LSLICENSE_SEARCH_LICENSEID
  29. #define LICENSE_PROCESS_KEYPACKID LSLICENSE_SEARCH_KEYPACKID
  30. #define LICENSE_PROCESS_MACHINENAME LSLICENSE_SEARCH_MACHINENAME
  31. #define LICENSE_PROCESS_USERNAME LSLICENSE_SEARCH_USERNAME
  32. #define LICENSE_PROCESS_ISSUEDATE LSLICENSE_SEARCH_ISSUEDATE
  33. #define LICENSE_PROCESS_EXPIREDATE LSLICENSE_SEARCH_EXPIREDATE
  34. #define LICENSE_PROCESS_NUMLICENSES LSLICENSE_SEARCH_NUMLICENSES
  35. #define LICENSE_PROCESS_LICENSESTATUS LSLICENSE_EXSEARCH_LICENSESTATUS
  36. #define LICENSE_PROCESS_SYSTEMBIOS LICENSE_COLUMN_SEARCH_SYSTEMBOIS
  37. #define LICENSE_PROCESS_VIDEOBIOS LICENSE_COLUMN_SEARCH_VIDEOBIOS
  38. #define LICENSE_PROCESS_FLOPPYBIOS LICENSE_COLUMN_SEARCH_FLOPPYBIOS
  39. #define LICENSE_PROCESS_HARDDISKSIZE LICENSE_COLUMN_SEARCH_HARDDISKSIZE
  40. #define LICENSE_PROCESS_RAMSIZE LICENSE_COLUMN_SEARCH_RAMSIZE
  41. #define LICENSE_PROCESS_MATCHHWID 0x04000000
  42. #define LICENSE_PROCESS_HWID LICENSE_COLUMN_SEARCH_HWID
  43. #define LICENSE_PROCESS_LASTMODIFYTIME 0x08000000
  44. #define LICENSE_PROCESS_KEYPACKLICENSEID 0x10000000
  45. #define LICENSE_PROCESS_ENTRYSTATUS LSLICENSE_SEARCH_ENTRY_STATUS
  46. //
  47. // Licensed table
  48. //
  49. #define LICENSE_TABLE_NAME _TEXT("IssuedLicense")
  50. #define LICENSE_COLUMN_ID_COLUMN _TEXT("InternalLicenseID")
  51. #define LICENSE_COLUMN_KEYPACKID _TEXT("InternalKeyPackId")
  52. #define LICENSE_COLUMN_LICENSEID _TEXT("KeyPackLicenseId")
  53. #define LICENSE_COLUMN_LASTMODIFYTIME _TEXT("LastModifyTime")
  54. #define LICENSE_COLUMN_SYSTEMBIOS _TEXT("SystemBIOS")
  55. #define LICENSE_COLUMN_VIDEOBIOS _TEXT("VideoBIOS")
  56. #define LICENSE_COLUMN_FLOPPYBIOS _TEXT("FloppyBIOS")
  57. #define LICENSE_COLUMN_HARDDISKSIZE _TEXT("HarddiskSize")
  58. #define LICENSE_COLUMN_RAMSIZE _TEXT("RAMSize")
  59. #define LICENSE_COLUMN_MATCHHWID _TEXT("MatchHint1")
  60. #define LICENSE_COLUMN_MACHINENAME _TEXT("MachineName")
  61. #define LICENSE_COLUMN_USERNAME _TEXT("UserName")
  62. #define LICENSE_COLUMN_NUMLICENSES _TEXT("NumLicenses")
  63. #define LICENSE_COLUMN_ISSUEDATE _TEXT("IssueDate")
  64. #define LICENSE_COLUMN_EXPIREDATE _TEXT("ExpireDate")
  65. #define LICENSE_COLUMN_LICENSESTATUS _TEXT("LicenseStatus")
  66. #define LICENSE_COLUMN_ENTRYSTATUS _TEXT("EntryStatus")
  67. typedef TLSReplLicenseClient LICENSEDCLIENT;
  68. typedef TLSReplLicenseClient* PLICENSEDCLIENT;
  69. typedef TLSReplLicenseClient* LPLICENSEDCLIENT;
  70. ////////////////////////////////////////////////////////////
  71. //
  72. // Index structure for IssuedLicense table
  73. //
  74. ////////////////////////////////////////////////////////////
  75. // --------------------------------------------------------
  76. // Primary index on License ID - internal tracking number
  77. // --------------------------------------------------------
  78. //
  79. // IssuedLicense_LicenseId_idx
  80. //
  81. #define LICENSE_ID_INDEXNAME \
  82. LICENSE_TABLE_NAME SEPERATOR LICENSE_COLUMN_ID_COLUMN SEPERATOR INDEXNAME
  83. //
  84. // Index key on license ID column - "+LicenseID"
  85. //
  86. #define LICENSE_ID_INDEXNAME_INDEXKEY \
  87. INDEX_SORT_ASCENDING LICENSE_COLUMN_ID_COLUMN INDEX_END_COLNAME
  88. typedef struct __LicensedIndexOnLicenseId : public JBKeyBase {
  89. DWORD dwLicenseId;
  90. static LPCTSTR pszIndexName;
  91. static LPCTSTR pszIndexKey;
  92. //--------------------------------------------------------
  93. __LicensedIndexOnLicenseId(
  94. const LICENSEDCLIENT& v
  95. ) :
  96. JBKeyBase()
  97. /*++
  98. ++*/
  99. {
  100. *this = v;
  101. }
  102. //-------------------------------------------------------
  103. __LicensedIndexOnLicenseId(
  104. const LICENSEDCLIENT* v=NULL
  105. ) :
  106. JBKeyBase()
  107. /*++
  108. ++*/
  109. {
  110. if(v)
  111. {
  112. *this = *v;
  113. }
  114. }
  115. //-------------------------------------------------------
  116. __LicensedIndexOnLicenseId&
  117. operator=(const LICENSEDCLIENT& v) {
  118. dwLicenseId = v.dwLicenseId;
  119. SetEmptyValue(FALSE);
  120. return *this;
  121. }
  122. //--------------------------------------------------------
  123. inline LPCTSTR
  124. GetIndexName()
  125. {
  126. return pszIndexName;
  127. }
  128. inline LPCTSTR
  129. GetIndexKey()
  130. {
  131. return pszIndexKey;
  132. }
  133. DWORD
  134. GetNumKeyComponents() { return 1; }
  135. inline BOOL
  136. GetSearchKey(
  137. DWORD dwComponentIndex,
  138. PVOID* pbData,
  139. unsigned long* cbData,
  140. JET_GRBIT* grbit,
  141. DWORD dwSearchParm
  142. )
  143. /*
  144. */
  145. {
  146. if(dwComponentIndex >= GetNumKeyComponents())
  147. {
  148. JB_ASSERT(FALSE);
  149. return FALSE;
  150. }
  151. *pbData = &(dwLicenseId);
  152. *cbData = sizeof(dwLicenseId);
  153. *grbit = JET_bitNewKey;
  154. return TRUE;
  155. }
  156. } TLSLicensedIndexLicenseId;
  157. // ----------------------------------------------------------
  158. // Index on Issued License Pack Id (internal tracking number)
  159. // ----------------------------------------------------------
  160. //
  161. // IssuedLicense_KeyPackId_idx
  162. //
  163. #define LICENSE_KEYPACKID_INDEXNAME \
  164. LICENSE_TABLE_NAME SEPERATOR LICENSE_COLUMN_KEYPACKID SEPERATOR INDEXNAME
  165. //
  166. // Index key on License KeyPack ID - "+KeyPackId"
  167. //
  168. #define LICENSE_KEYPACKID_INDEXNAME_INDEXKEY \
  169. INDEX_SORT_ASCENDING LICENSE_COLUMN_KEYPACKID INDEX_END_COLNAME
  170. typedef struct __LicensedIndexOnKeyPackId : public JBKeyBase{
  171. DWORD dwKeyPackId;
  172. static LPCTSTR pszIndexName;
  173. static LPCTSTR pszIndexKey;
  174. //----------------------------------------------
  175. __LicensedIndexOnKeyPackId(
  176. const LICENSEDCLIENT& v
  177. ) :
  178. JBKeyBase()
  179. /*++
  180. ++*/
  181. {
  182. *this = v;
  183. }
  184. //----------------------------------------------
  185. __LicensedIndexOnKeyPackId(
  186. const LICENSEDCLIENT* v=NULL
  187. ) :
  188. JBKeyBase()
  189. /*++
  190. ++*/
  191. {
  192. if(v)
  193. {
  194. *this = *v;
  195. }
  196. }
  197. __LicensedIndexOnKeyPackId&
  198. operator=(const LICENSEDCLIENT& v) {
  199. dwKeyPackId = v.dwKeyPackId;
  200. SetEmptyValue(FALSE);
  201. return *this;
  202. }
  203. //----------------------------------------------
  204. inline LPCTSTR
  205. GetIndexName()
  206. {
  207. return pszIndexName;
  208. }
  209. inline LPCTSTR
  210. GetIndexKey()
  211. {
  212. return pszIndexKey;
  213. }
  214. DWORD
  215. GetNumKeyComponents() { return 1; }
  216. inline BOOL
  217. GetSearchKey(
  218. DWORD dwComponentIndex,
  219. PVOID* pbData,
  220. unsigned long* cbData,
  221. JET_GRBIT* grbit,
  222. DWORD dwSearchParm
  223. )
  224. /*
  225. */
  226. {
  227. if(dwComponentIndex >= GetNumKeyComponents())
  228. {
  229. JB_ASSERT(FALSE);
  230. return FALSE;
  231. }
  232. *pbData = &(dwKeyPackId);
  233. *cbData = sizeof(dwKeyPackId);
  234. *grbit = JET_bitNewKey;
  235. return TRUE;
  236. }
  237. } TLSLicensedIndexKeyPackId;
  238. // ----------------------------------------------------------
  239. // Index on LastModifyTime
  240. // ----------------------------------------------------------
  241. //
  242. // IssuedLicense_LastModifyTime_idx
  243. //
  244. #define LICENSE_LASTMODIFY_INDEXNAME \
  245. LICENSE_TABLE_NAME SEPERATOR LICENSE_COLUMN_LASTMODIFYTIME SEPERATOR INDEXNAME
  246. //
  247. // Index key - "+LastModifyTime"
  248. //
  249. #define LICENSE_LASTMODIFY_INDEXNAME_INDEXKEY \
  250. INDEX_SORT_ASCENDING LICENSE_COLUMN_LASTMODIFYTIME INDEX_END_COLNAME
  251. typedef struct __LicensedIndexOnLastModifyTime : public JBKeyBase {
  252. FILETIME ftLastModifyTime;
  253. static LPCTSTR pszIndexName;
  254. static LPCTSTR pszIndexKey;
  255. //----------------------------------------------
  256. __LicensedIndexOnLastModifyTime(
  257. const LICENSEDCLIENT& v
  258. ) :
  259. JBKeyBase()
  260. /*++
  261. ++*/
  262. {
  263. *this = v;
  264. }
  265. //----------------------------------------------
  266. __LicensedIndexOnLastModifyTime(
  267. const LICENSEDCLIENT* v=NULL
  268. ) :
  269. JBKeyBase()
  270. /*++
  271. ++*/
  272. {
  273. if(v)
  274. {
  275. *this = *v;
  276. }
  277. }
  278. __LicensedIndexOnLastModifyTime&
  279. operator=(const LICENSEDCLIENT& v) {
  280. ftLastModifyTime = v.ftLastModifyTime;
  281. SetEmptyValue(FALSE);
  282. return *this;
  283. }
  284. //----------------------------------------------
  285. inline LPCTSTR
  286. GetIndexName()
  287. {
  288. return pszIndexName;
  289. }
  290. inline LPCTSTR
  291. GetIndexKey()
  292. {
  293. return pszIndexKey;
  294. }
  295. DWORD
  296. GetNumKeyComponents() { return 1; }
  297. inline BOOL
  298. GetSearchKey(
  299. DWORD dwComponentIndex,
  300. PVOID* pbData,
  301. unsigned long* cbData,
  302. JET_GRBIT* grbit,
  303. DWORD dwSearchParm
  304. )
  305. /*
  306. */
  307. {
  308. if(dwComponentIndex >= GetNumKeyComponents())
  309. {
  310. JB_ASSERT(FALSE);
  311. return FALSE;
  312. }
  313. *pbData = &(ftLastModifyTime);
  314. *cbData = sizeof(ftLastModifyTime);
  315. *grbit = JET_bitNewKey;
  316. return TRUE;
  317. }
  318. } TLSLicensedIndexLastModifyTime;
  319. // ----------------------------------------------------------
  320. // Index on ExpireDate
  321. // ----------------------------------------------------------
  322. //
  323. // IssuedLicense_ExpireDate_idx
  324. //
  325. #define LICENSE_EXPIREDATE_INDEXNAME \
  326. LICENSE_TABLE_NAME SEPERATOR LICENSE_COLUMN_EXPIREDATE SEPERATOR INDEXNAME
  327. //
  328. // Index key - "+ExpireDate"
  329. //
  330. #define LICENSE_EXPIREDATE_INDEXNAME_INDEXKEY \
  331. INDEX_SORT_ASCENDING LICENSE_COLUMN_EXPIREDATE INDEX_END_COLNAME
  332. typedef struct __LicensedIndexOnExpireDate : public JBKeyBase {
  333. DWORD ftExpireDate;
  334. static LPCTSTR pszIndexName;
  335. static LPCTSTR pszIndexKey;
  336. //----------------------------------------------
  337. __LicensedIndexOnExpireDate(
  338. const LICENSEDCLIENT& v
  339. ) :
  340. JBKeyBase()
  341. /*++
  342. ++*/
  343. {
  344. *this = v;
  345. }
  346. //----------------------------------------------
  347. __LicensedIndexOnExpireDate(
  348. const LICENSEDCLIENT* v=NULL
  349. ) :
  350. JBKeyBase()
  351. /*++
  352. ++*/
  353. {
  354. if(v)
  355. {
  356. *this = *v;
  357. }
  358. }
  359. __LicensedIndexOnExpireDate&
  360. operator=(const LICENSEDCLIENT& v) {
  361. ftExpireDate = v.ftExpireDate;
  362. SetEmptyValue(FALSE);
  363. return *this;
  364. }
  365. //----------------------------------------------
  366. inline LPCTSTR
  367. GetIndexName()
  368. {
  369. return pszIndexName;
  370. }
  371. inline LPCTSTR
  372. GetIndexKey()
  373. {
  374. return pszIndexKey;
  375. }
  376. DWORD
  377. GetNumKeyComponents() { return 1; }
  378. inline BOOL
  379. GetSearchKey(
  380. DWORD dwComponentIndex,
  381. PVOID* pbData,
  382. unsigned long* cbData,
  383. JET_GRBIT* grbit,
  384. DWORD dwSearchParm
  385. )
  386. /*
  387. */
  388. {
  389. if(dwComponentIndex >= GetNumKeyComponents())
  390. {
  391. JB_ASSERT(FALSE);
  392. return FALSE;
  393. }
  394. *pbData = &(ftExpireDate);
  395. *cbData = sizeof(ftExpireDate);
  396. *grbit = JET_bitNewKey;
  397. return TRUE;
  398. }
  399. } TLSLicensedIndexExpireDate;
  400. //-------------------------------------------------------------
  401. // Index on client machine name
  402. //-------------------------------------------------------------
  403. //
  404. // IssuedLicense_MachineName_idx
  405. //
  406. #define LICENSE_CLIENT_MACHINENAME_INDEXNAME \
  407. LICENSE_TABLE_NAME SEPERATOR LICENSE_COLUMN_MACHINENAME SEPERATOR INDEXNAME
  408. //
  409. // "+MachineName\0"
  410. #define LICENSE_CLIENT_MACHINENAME_INDEXNAME_INDEXKEY \
  411. INDEX_SORT_ASCENDING LICENSE_COLUMN_MACHINENAME INDEX_END_COLNAME
  412. typedef struct __LicensedIndexOnMachineName : public JBKeyBase {
  413. TCHAR szMachineName[ MAXCOMPUTERNAMELENGTH+1 ];
  414. static LPCTSTR pszIndexName;
  415. static LPCTSTR pszIndexKey;
  416. //-------------------------------------------------------
  417. __LicensedIndexOnMachineName(
  418. const LICENSEDCLIENT* v=NULL
  419. ) :
  420. JBKeyBase()
  421. /*++
  422. ++*/
  423. {
  424. if(v)
  425. {
  426. *this = *v;
  427. }
  428. }
  429. //-------------------------------------------------------
  430. __LicensedIndexOnMachineName(
  431. const LICENSEDCLIENT& v
  432. ) :
  433. JBKeyBase()
  434. /*++
  435. ++*/
  436. {
  437. *this = v;
  438. }
  439. //-------------------------------------------------------
  440. __LicensedIndexOnMachineName&
  441. operator=(const LICENSEDCLIENT& v) {
  442. _tcscpy(szMachineName, v.szMachineName);
  443. SetEmptyValue(FALSE);
  444. return *this;
  445. }
  446. //------------------------------------------
  447. inline LPCTSTR
  448. GetIndexName()
  449. {
  450. return pszIndexName;
  451. }
  452. inline LPCTSTR
  453. GetIndexKey()
  454. {
  455. return pszIndexKey;
  456. }
  457. DWORD
  458. GetNumKeyComponents() { return 1; }
  459. inline BOOL
  460. GetSearchKey(
  461. DWORD dwComponentIndex,
  462. PVOID* pbData,
  463. unsigned long* cbData,
  464. JET_GRBIT* grbit,
  465. DWORD dwSearchParm
  466. )
  467. /*
  468. */
  469. {
  470. if(dwComponentIndex >= GetNumKeyComponents())
  471. {
  472. JB_ASSERT(FALSE);
  473. return FALSE;
  474. }
  475. *pbData = &(szMachineName[0]);
  476. *cbData = _tcslen(szMachineName) * sizeof(TCHAR);
  477. *grbit = JET_bitNewKey;
  478. return TRUE;
  479. }
  480. } TLSLicensedIndexMachineName;
  481. //-------------------------------------------------------------
  482. // Index on client UserName name
  483. //-------------------------------------------------------------
  484. //
  485. // IssuedLicense_UserName_idx
  486. //
  487. #define LICENSE_CLIENT_USERNAME_INDEXNAME \
  488. LICENSE_TABLE_NAME SEPERATOR LICENSE_COLUMN_USERNAME SEPERATOR INDEXNAME
  489. //
  490. // "+UserName\0"
  491. #define LICENSE_CLIENT_USERNAME_INDEXNAME_INDEXKEY \
  492. INDEX_SORT_ASCENDING LICENSE_COLUMN_USERNAME INDEX_END_COLNAME
  493. typedef struct __LicensedIndexOnUserName : public JBKeyBase {
  494. TCHAR szUserName[ MAXUSERNAMELENGTH+1 ];
  495. static LPCTSTR pszIndexName;
  496. static LPCTSTR pszIndexKey;
  497. //-------------------------------------------------------
  498. __LicensedIndexOnUserName(const LICENSEDCLIENT& v) : JBKeyBase() {
  499. *this = v;
  500. }
  501. //-------------------------------------------------------
  502. __LicensedIndexOnUserName(
  503. const LICENSEDCLIENT* v=NULL
  504. ) :
  505. JBKeyBase()
  506. /*++
  507. ++*/
  508. {
  509. *this = *v;
  510. }
  511. //-------------------------------------------------------
  512. __LicensedIndexOnUserName&
  513. operator=(const LICENSEDCLIENT& v) {
  514. _tcscpy(szUserName, v.szUserName);
  515. SetEmptyValue(FALSE);
  516. return *this;
  517. }
  518. inline LPCTSTR
  519. GetIndexName()
  520. {
  521. return pszIndexName;
  522. }
  523. inline LPCTSTR
  524. GetIndexKey()
  525. {
  526. return pszIndexKey;
  527. }
  528. DWORD
  529. GetNumKeyComponents() { return 1; }
  530. inline BOOL
  531. GetSearchKey(
  532. DWORD dwComponentIndex,
  533. PVOID* pbData,
  534. unsigned long* cbData,
  535. JET_GRBIT* grbit,
  536. DWORD dwSearchParm
  537. )
  538. /*
  539. */
  540. {
  541. if(dwComponentIndex >= GetNumKeyComponents())
  542. {
  543. JB_ASSERT(FALSE);
  544. return FALSE;
  545. }
  546. *pbData = &(szUserName[0]);
  547. *cbData = _tcslen(szUserName) * sizeof(TCHAR);
  548. *grbit = JET_bitNewKey;
  549. return TRUE;
  550. }
  551. } TLSLicensedIndexUserName;
  552. //-------------------------------------------------------------
  553. // Index on client's HWID
  554. //-------------------------------------------------------------
  555. //
  556. // IssuedLicense_Hwid_idx
  557. //
  558. #define LICENSE_CLIENT_HWID_INDEXNAME \
  559. LICENSE_TABLE_NAME SEPERATOR _TEXT("ClientHwid") SEPERATOR INDEXNAME
  560. //
  561. // Index Key on Client Hwid - "+SystemBIOS\0+VideoBIOS\0+FloppyBIOS\0+HarddiskSize\0+RAMSize\0"
  562. //
  563. #define LICENSE_CLIENT_HWID_INDEXNAME_INDEXKEY \
  564. INDEX_SORT_ASCENDING LICENSE_COLUMN_SYSTEMBIOS INDEX_END_COLNAME \
  565. INDEX_SORT_ASCENDING LICENSE_COLUMN_VIDEOBIOS INDEX_END_COLNAME \
  566. INDEX_SORT_ASCENDING LICENSE_COLUMN_FLOPPYBIOS INDEX_END_COLNAME \
  567. INDEX_SORT_ASCENDING LICENSE_COLUMN_HARDDISKSIZE INDEX_END_COLNAME \
  568. INDEX_SORT_ASCENDING LICENSE_COLUMN_RAMSIZE INDEX_END_COLNAME
  569. #define LICENSE_CLIENT_HWID_INDEXNAME_INDEXKEY_COMPONENTS 5
  570. typedef struct __LicensedIndexOnHwid : public JBKeyBase {
  571. //
  572. // Need to change LICENSE_CLIENT_HWID_INDEXNAME_INDEXKEY_COMPONENTS
  573. // if add/remove from this structure
  574. //
  575. LONG dwSystemBiosChkSum;
  576. LONG dwVideoBiosChkSum;
  577. LONG dwFloppyBiosChkSum;
  578. LONG dwHardDiskSize;
  579. LONG dwRamSize;
  580. static LPCTSTR pszIndexName;
  581. static LPCTSTR pszIndexKey;
  582. //------------------------------------------------
  583. __LicensedIndexOnHwid(
  584. const LICENSEDCLIENT* v=NULL
  585. ) :
  586. JBKeyBase()
  587. /*++
  588. ++*/
  589. {
  590. if(v)
  591. {
  592. *this = *v;
  593. }
  594. }
  595. //------------------------------------------------
  596. __LicensedIndexOnHwid(
  597. const LICENSEDCLIENT& v
  598. ) :
  599. JBKeyBase()
  600. /*++
  601. ++*/
  602. {
  603. *this = v;
  604. }
  605. //------------------------------------------------
  606. __LicensedIndexOnHwid&
  607. operator=(const LICENSEDCLIENT hwid) {
  608. dwSystemBiosChkSum = hwid.dwSystemBiosChkSum;
  609. dwVideoBiosChkSum = hwid.dwVideoBiosChkSum;
  610. dwFloppyBiosChkSum = hwid.dwFloppyBiosChkSum;
  611. dwHardDiskSize = hwid.dwHardDiskSize;
  612. dwRamSize = hwid.dwRamSize;
  613. SetEmptyValue(FALSE);
  614. return *this;
  615. }
  616. //------------------------------------------------
  617. inline LPCTSTR
  618. GetIndexName()
  619. {
  620. return pszIndexName;
  621. }
  622. inline LPCTSTR
  623. GetIndexKey()
  624. {
  625. return pszIndexKey;
  626. }
  627. DWORD
  628. GetNumKeyComponents() {
  629. return LICENSE_CLIENT_HWID_INDEXNAME_INDEXKEY_COMPONENTS;
  630. }
  631. inline BOOL
  632. GetSearchKey(
  633. DWORD dwComponentIndex,
  634. PVOID* pbData,
  635. unsigned long* cbData,
  636. JET_GRBIT* grbit,
  637. DWORD dwSearchParam
  638. )
  639. /*
  640. */
  641. {
  642. BOOL retCode=TRUE;
  643. if(dwComponentIndex >= GetNumKeyComponents())
  644. {
  645. JB_ASSERT(FALSE);
  646. return FALSE;
  647. }
  648. *cbData = 0;
  649. *grbit = 0;
  650. switch(dwComponentIndex)
  651. {
  652. case 0:
  653. *pbData = &(dwSystemBiosChkSum);
  654. *cbData = sizeof(dwSystemBiosChkSum);
  655. *grbit = JET_bitNewKey;
  656. break;
  657. case 1:
  658. *pbData = &(dwVideoBiosChkSum);
  659. *cbData = sizeof(dwVideoBiosChkSum);
  660. break;
  661. case 2:
  662. *pbData = &(dwFloppyBiosChkSum);
  663. *cbData = sizeof(dwFloppyBiosChkSum);
  664. break;
  665. case 3:
  666. *pbData = &(dwHardDiskSize);
  667. *cbData = sizeof(dwHardDiskSize);
  668. break;
  669. case 4:
  670. *pbData = &(dwRamSize);
  671. *cbData = sizeof(dwRamSize);
  672. break;
  673. default:
  674. JB_ASSERT(FALSE);
  675. retCode = FALSE;
  676. }
  677. return retCode;
  678. }
  679. } TLSLicensedIndexHwid;
  680. //------------------------------------------------------
  681. // Index for matching client HWID
  682. //------------------------------------------------------
  683. //
  684. // IssuedLicense_MatchHwid_idx
  685. //
  686. #define LICENSE_MATCHHWID_INDEXNAME \
  687. LICENSE_TABLE_NAME SEPERATOR _TEXT("MatchHwid") SEPERATOR INDEXNAME
  688. //
  689. // Index key on search hint column "+MatchHint1\0"
  690. //
  691. #define LICENSE_MATCHHWID_INDEXNAME_INDEXKEY \
  692. INDEX_SORT_ASCENDING LICENSE_COLUMN_MATCHHWID INDEX_END_COLNAME
  693. typedef struct __LicensedIndexOnMatchHwid : public JBKeyBase {
  694. double dbLowerBound;
  695. static LPCTSTR pszIndexName;
  696. static LPCTSTR pszIndexKey;
  697. static int __cdecl compare(const void *p1, const void* p2) {
  698. return *(DWORD *)p1 - *(DWORD *)p2;
  699. }
  700. //------------------------------------------------
  701. __LicensedIndexOnMatchHwid(
  702. const LICENSEDCLIENT* v=NULL
  703. ) :
  704. JBKeyBase()
  705. /*++
  706. ++*/
  707. {
  708. if(v)
  709. {
  710. *this = *v;
  711. }
  712. }
  713. //------------------------------------------------
  714. __LicensedIndexOnMatchHwid(
  715. const LICENSEDCLIENT& v
  716. ) :
  717. JBKeyBase()
  718. /*++
  719. ++*/
  720. {
  721. *this = v;
  722. }
  723. //------------------------------------------------
  724. __LicensedIndexOnMatchHwid&
  725. operator=(const LICENSEDCLIENT& v) {
  726. //
  727. // Allow to mismatch, so lower bound of matching hint is
  728. // Sum of all HWID minus two lagest value
  729. //
  730. LONG ptr[] = {
  731. v.dwSystemBiosChkSum,
  732. v.dwVideoBiosChkSum,
  733. v.dwFloppyBiosChkSum,
  734. v.dwHardDiskSize,
  735. v.dwRamSize
  736. };
  737. int count=sizeof(ptr) / sizeof(ptr[0]);
  738. qsort(ptr, count, sizeof(DWORD), __LicensedIndexOnMatchHwid::compare);
  739. dbLowerBound = (double) 0.0;
  740. for(int i=0; i < count - 2; i++)
  741. {
  742. dbLowerBound += (double)ptr[i];
  743. }
  744. SetEmptyValue(FALSE);
  745. return *this;
  746. }
  747. inline LPCTSTR
  748. GetIndexName()
  749. {
  750. return pszIndexName;
  751. }
  752. inline LPCTSTR
  753. GetIndexKey()
  754. {
  755. return pszIndexKey;
  756. }
  757. DWORD
  758. GetNumKeyComponents() {
  759. return 1;
  760. }
  761. inline BOOL
  762. GetSearchKey(
  763. DWORD dwComponentIndex,
  764. PVOID* pbData,
  765. unsigned long* cbData,
  766. JET_GRBIT* grbit,
  767. DWORD dwSearchParm
  768. )
  769. /*
  770. */
  771. {
  772. if(dwComponentIndex >= GetNumKeyComponents())
  773. {
  774. JB_ASSERT(FALSE);
  775. return FALSE;
  776. }
  777. *pbData = &(dbLowerBound);
  778. *cbData = sizeof(dbLowerBound);
  779. *grbit = JET_bitNewKey;
  780. return TRUE;
  781. }
  782. } TLSLicensedIndexMatchHwid;
  783. //------------------------------------------------------------------------
  784. class LicensedTable : public TLSTable<LICENSEDCLIENT> {
  785. private:
  786. static LPCTSTR pszTableName;
  787. BOOL
  788. ProcessSingleColumn(
  789. BOOL bFetch,
  790. TLSColumnBase& column,
  791. DWORD offset,
  792. PVOID pbData,
  793. DWORD cbData,
  794. PDWORD pcbDataReturn,
  795. LPCTSTR szColumnName
  796. );
  797. BOOL
  798. ProcessRecord(
  799. LICENSEDCLIENT* v,
  800. BOOL bFetch, // TRUE - fetch, FALSE insert
  801. DWORD dwParam,
  802. BOOL bUpdate
  803. );
  804. public:
  805. TLSColumnUchar ucEntryStatus;
  806. TLSColumnFileTime ftLastModifyTime;
  807. TLSColumnDword dwLicenseId;
  808. TLSColumnDword dwKeyPackId;
  809. TLSColumnDword dwKeyPackLicenseId;
  810. TLSColumnText szMachineName;
  811. TLSColumnText szUserName;
  812. TLSColumnDword ftIssueDate;
  813. TLSColumnDword ftExpireDate;
  814. TLSColumnUchar ucLicenseStatus;
  815. TLSColumnDword dwNumLicenses;
  816. TLSColumnDword dwSystemBiosChkSum;
  817. TLSColumnDword dwVideoBiosChkSum;
  818. TLSColumnDword dwFloppyBiosChkSum;
  819. TLSColumnDword dwHardDiskSize;
  820. TLSColumnDword dwRamSize;
  821. TLSColumnDouble dbLowerBound;
  822. //---------------------------------------------------------
  823. virtual LPCTSTR
  824. GetTableName()
  825. {
  826. return pszTableName;
  827. }
  828. //-----------------------------------------------------
  829. LicensedTable(
  830. JBDatabase& database
  831. ) : TLSTable<LICENSEDCLIENT>(database)
  832. /*
  833. */
  834. {
  835. }
  836. //-----------------------------------------------------
  837. virtual BOOL
  838. ResolveToTableColumn();
  839. //-----------------------------------------------------
  840. virtual BOOL
  841. FetchRecord(
  842. LICENSEDCLIENT& licensed,
  843. DWORD dwParam=PROCESS_ALL_COLUMNS
  844. )
  845. /*
  846. */
  847. {
  848. if(IsValid() == FALSE)
  849. {
  850. DebugOutput(
  851. _TEXT("Table %s is not valid...\n"),
  852. GetTableName()
  853. );
  854. JB_ASSERT(FALSE);
  855. SetLastJetError(JET_errInvalidParameter);
  856. return FALSE;
  857. }
  858. //CCriticalSectionLocker Lock(GetTableLock());
  859. return ProcessRecord(&licensed, TRUE, dwParam, FALSE);
  860. }
  861. //-----------------------------------------------------
  862. virtual BOOL
  863. InsertRecord(
  864. LICENSEDCLIENT& licensed,
  865. DWORD dwParam=PROCESS_ALL_COLUMNS
  866. )
  867. /*
  868. */
  869. {
  870. if(IsValid() == FALSE)
  871. {
  872. DebugOutput(
  873. _TEXT("Table %s is not valid...\n"),
  874. GetTableName()
  875. );
  876. JB_ASSERT(FALSE);
  877. SetLastJetError(JET_errInvalidParameter);
  878. return FALSE;
  879. }
  880. //CCriticalSectionLocker Lock(GetTableLock());
  881. return ProcessRecord(&licensed, FALSE, dwParam, FALSE);
  882. }
  883. //-------------------------------------------------------
  884. virtual BOOL
  885. UpdateRecord(
  886. LICENSEDCLIENT& licensed,
  887. DWORD dwParam=PROCESS_ALL_COLUMNS
  888. )
  889. /*
  890. */
  891. {
  892. if(IsValid() == FALSE)
  893. {
  894. DebugOutput(
  895. _TEXT("Table %s is not valid...\n"),
  896. GetTableName()
  897. );
  898. JB_ASSERT(FALSE);
  899. SetLastJetError(JET_errInvalidParameter);
  900. return FALSE;
  901. }
  902. //CCriticalSectionLocker Lock(GetTableLock());
  903. return ProcessRecord(&licensed, FALSE, dwParam, TRUE);
  904. }
  905. //-------------------------------------------------------
  906. virtual BOOL
  907. Initialize() { return TRUE; }
  908. //-------------------------------------------------------
  909. virtual JBKeyBase*
  910. EnumerationIndex(
  911. BOOL bMatchAll,
  912. DWORD dwParam,
  913. LICENSEDCLIENT* pLicensed,
  914. BOOL* bCompareKey
  915. );
  916. virtual BOOL
  917. EqualValue(
  918. LICENSEDCLIENT& s1,
  919. LICENSEDCLIENT& s2,
  920. BOOL bMatchAll,
  921. DWORD dwParam
  922. );
  923. virtual BOOL
  924. UpgradeTable(
  925. IN DWORD dwOldVersion,
  926. IN DWORD dwNewVersion
  927. );
  928. };
  929. #endif