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.

1154 lines
28 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: lictab.cpp
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "Licensed.h"
  13. LPCTSTR __LicensedIndexOnLicenseId::pszIndexName = LICENSE_ID_INDEXNAME;
  14. LPCTSTR __LicensedIndexOnLicenseId::pszIndexKey = LICENSE_ID_INDEXNAME_INDEXKEY;
  15. LPCTSTR __LicensedIndexOnKeyPackId::pszIndexName = LICENSE_KEYPACKID_INDEXNAME;
  16. LPCTSTR __LicensedIndexOnKeyPackId::pszIndexKey = LICENSE_KEYPACKID_INDEXNAME_INDEXKEY;
  17. LPCTSTR __LicensedIndexOnLastModifyTime::pszIndexName = LICENSE_KEYPACKID_INDEXNAME;
  18. LPCTSTR __LicensedIndexOnLastModifyTime::pszIndexKey = LICENSE_KEYPACKID_INDEXNAME_INDEXKEY;
  19. LPCTSTR __LicensedIndexOnMachineName::pszIndexName = LICENSE_CLIENT_MACHINENAME_INDEXNAME;
  20. LPCTSTR __LicensedIndexOnMachineName::pszIndexKey = LICENSE_CLIENT_MACHINENAME_INDEXNAME_INDEXKEY;
  21. LPCTSTR __LicensedIndexOnUserName::pszIndexName = LICENSE_CLIENT_USERNAME_INDEXNAME;
  22. LPCTSTR __LicensedIndexOnUserName::pszIndexKey = LICENSE_CLIENT_USERNAME_INDEXNAME_INDEXKEY;
  23. LPCTSTR __LicensedIndexOnHwid::pszIndexName = LICENSE_CLIENT_HWID_INDEXNAME;
  24. LPCTSTR __LicensedIndexOnHwid::pszIndexKey = LICENSE_CLIENT_HWID_INDEXNAME_INDEXKEY;
  25. LPCTSTR __LicensedIndexOnMatchHwid::pszIndexName = LICENSE_MATCHHWID_INDEXNAME;
  26. LPCTSTR __LicensedIndexOnMatchHwid::pszIndexKey = LICENSE_MATCHHWID_INDEXNAME_INDEXKEY;
  27. LPCTSTR __LicensedIndexOnExpireDate::pszIndexName = LICENSE_EXPIREDATE_INDEXNAME;
  28. LPCTSTR __LicensedIndexOnExpireDate::pszIndexKey = LICENSE_EXPIREDATE_INDEXNAME_INDEXKEY;
  29. CCriticalSection LicensedTable::g_TableLock;
  30. LPCTSTR LicensedTable::pszTableName = LICENSE_TABLE_NAME;
  31. //-------------------------------------------------------------------
  32. TLSJBIndex
  33. LicensedTable::g_TableIndex[] =
  34. {
  35. // Index on license ID.
  36. {
  37. LICENSE_ID_INDEXNAME,
  38. LICENSE_ID_INDEXNAME_INDEXKEY,
  39. -1,
  40. JET_bitIndexPrimary,
  41. TLSTABLE_INDEX_DEFAULT_DENSITY
  42. },
  43. //
  44. // Index on licensed keypack id.
  45. {
  46. LICENSE_KEYPACKID_INDEXNAME,
  47. LICENSE_KEYPACKID_INDEXNAME_INDEXKEY,
  48. -1,
  49. JET_bitIndexIgnoreNull,
  50. TLSTABLE_INDEX_DEFAULT_DENSITY
  51. },
  52. // index on last modify time.
  53. {
  54. LICENSE_LASTMODIFY_INDEXNAME,
  55. LICENSE_LASTMODIFY_INDEXNAME_INDEXKEY,
  56. -1,
  57. JET_bitIndexIgnoreNull,
  58. TLSTABLE_INDEX_DEFAULT_DENSITY
  59. },
  60. // Index on machine name
  61. {
  62. LICENSE_CLIENT_MACHINENAME_INDEXNAME,
  63. LICENSE_CLIENT_MACHINENAME_INDEXNAME_INDEXKEY,
  64. -1,
  65. 0,
  66. TLSTABLE_INDEX_DEFAULT_DENSITY
  67. },
  68. // index on user name
  69. {
  70. LICENSE_CLIENT_USERNAME_INDEXNAME,
  71. LICENSE_CLIENT_USERNAME_INDEXNAME_INDEXKEY,
  72. -1,
  73. 0,
  74. TLSTABLE_INDEX_DEFAULT_DENSITY
  75. },
  76. // index on client machine's hardware id
  77. {
  78. LICENSE_CLIENT_HWID_INDEXNAME,
  79. LICENSE_CLIENT_HWID_INDEXNAME_INDEXKEY,
  80. -1,
  81. JET_bitIndexIgnoreNull,
  82. TLSTABLE_INDEX_DEFAULT_DENSITY
  83. },
  84. // index on client hardware id matching hint
  85. {
  86. LICENSE_MATCHHWID_INDEXNAME,
  87. LICENSE_MATCHHWID_INDEXNAME_INDEXKEY,
  88. -1,
  89. JET_bitIndexIgnoreNull,
  90. TLSTABLE_INDEX_DEFAULT_DENSITY
  91. },
  92. // index on license expiration date
  93. {
  94. LICENSE_EXPIREDATE_INDEXNAME,
  95. LICENSE_EXPIREDATE_INDEXNAME_INDEXKEY,
  96. -1,
  97. JET_bitIndexIgnoreNull,
  98. TLSTABLE_INDEX_DEFAULT_DENSITY
  99. },
  100. };
  101. int
  102. LicensedTable::g_NumTableIndex = sizeof(LicensedTable::g_TableIndex) / sizeof(LicensedTable::g_TableIndex[0]);
  103. TLSJBColumn
  104. LicensedTable::g_Columns[] =
  105. {
  106. //
  107. // Entry status
  108. {
  109. LICENSE_COLUMN_ENTRYSTATUS,
  110. JET_coltypUnsignedByte,
  111. 0,
  112. JET_bitColumnFixed,
  113. NULL,
  114. 0,
  115. TLS_JETBLUE_COLUMN_CODE_PAGE,
  116. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  117. TLS_JETBLUE_COLUMN_LANGID
  118. },
  119. //
  120. // Licensed ID
  121. {
  122. LICENSE_COLUMN_ID_COLUMN,
  123. JET_coltypLong,
  124. 0,
  125. JET_bitColumnFixed | JET_bitColumnNotNULL,
  126. NULL,
  127. 0,
  128. TLS_JETBLUE_COLUMN_CODE_PAGE,
  129. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  130. TLS_JETBLUE_COLUMN_LANGID
  131. },
  132. //
  133. // KeyPackId
  134. {
  135. LICENSE_COLUMN_KEYPACKID,
  136. JET_coltypLong,
  137. 0,
  138. JET_bitColumnFixed | JET_bitColumnNotNULL,
  139. NULL,
  140. 0,
  141. TLS_JETBLUE_COLUMN_CODE_PAGE,
  142. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  143. TLS_JETBLUE_COLUMN_LANGID
  144. },
  145. //
  146. // KeyPackLicenseId
  147. {
  148. LICENSE_COLUMN_LICENSEID,
  149. JET_coltypLong,
  150. 0,
  151. JET_bitColumnFixed,
  152. NULL,
  153. 0,
  154. TLS_JETBLUE_COLUMN_CODE_PAGE,
  155. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  156. TLS_JETBLUE_COLUMN_LANGID
  157. },
  158. //
  159. // Last modify time
  160. {
  161. LICENSE_COLUMN_LASTMODIFYTIME,
  162. JET_coltypBinary,
  163. sizeof(FILETIME),
  164. JET_bitColumnNotNULL,
  165. NULL,
  166. 0,
  167. TLS_JETBLUE_COLUMN_CODE_PAGE,
  168. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  169. TLS_JETBLUE_COLUMN_LANGID
  170. },
  171. //
  172. // SystemBios
  173. {
  174. LICENSE_COLUMN_SYSTEMBIOS,
  175. JET_coltypLong,
  176. 0,
  177. JET_bitColumnFixed | JET_bitColumnNotNULL,
  178. NULL,
  179. 0,
  180. TLS_JETBLUE_COLUMN_CODE_PAGE,
  181. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  182. TLS_JETBLUE_COLUMN_LANGID
  183. },
  184. //
  185. // Video Bios
  186. {
  187. LICENSE_COLUMN_VIDEOBIOS,
  188. JET_coltypLong,
  189. 0,
  190. JET_bitColumnFixed | JET_bitColumnNotNULL,
  191. NULL,
  192. 0,
  193. TLS_JETBLUE_COLUMN_CODE_PAGE,
  194. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  195. TLS_JETBLUE_COLUMN_LANGID
  196. },
  197. //
  198. // Floppy Bios
  199. {
  200. LICENSE_COLUMN_FLOPPYBIOS,
  201. JET_coltypLong,
  202. 0,
  203. JET_bitColumnFixed | JET_bitColumnNotNULL,
  204. NULL,
  205. 0,
  206. TLS_JETBLUE_COLUMN_CODE_PAGE,
  207. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  208. TLS_JETBLUE_COLUMN_LANGID
  209. },
  210. //
  211. // Harddisk size
  212. {
  213. LICENSE_COLUMN_HARDDISKSIZE,
  214. JET_coltypLong,
  215. 0,
  216. JET_bitColumnFixed | JET_bitColumnNotNULL,
  217. NULL,
  218. 0,
  219. TLS_JETBLUE_COLUMN_CODE_PAGE,
  220. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  221. TLS_JETBLUE_COLUMN_LANGID
  222. },
  223. //
  224. // RAM size
  225. {
  226. LICENSE_COLUMN_RAMSIZE,
  227. JET_coltypLong,
  228. 0,
  229. JET_bitColumnFixed | JET_bitColumnNotNULL,
  230. NULL,
  231. 0,
  232. TLS_JETBLUE_COLUMN_CODE_PAGE,
  233. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  234. TLS_JETBLUE_COLUMN_LANGID
  235. },
  236. //
  237. // Match HWID
  238. {
  239. LICENSE_COLUMN_MATCHHWID,
  240. JET_coltypIEEEDouble,
  241. 0,
  242. JET_bitColumnFixed | JET_bitColumnNotNULL,
  243. NULL,
  244. 0,
  245. TLS_JETBLUE_COLUMN_CODE_PAGE,
  246. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  247. TLS_JETBLUE_COLUMN_LANGID
  248. },
  249. //
  250. // Machine name
  251. {
  252. LICENSE_COLUMN_MACHINENAME,
  253. //JET_coltypLongText,
  254. JB_COLTYPE_TEXT,
  255. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  256. 0,
  257. JBSTRING_NULL,
  258. _tcslen(JBSTRING_NULL),
  259. TLS_JETBLUE_COLUMN_CODE_PAGE,
  260. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  261. TLS_JETBLUE_COLUMN_LANGID
  262. },
  263. //
  264. // User Name
  265. {
  266. LICENSE_COLUMN_USERNAME,
  267. //JET_coltypLongText,
  268. JB_COLTYPE_TEXT,
  269. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  270. 0,
  271. JBSTRING_NULL,
  272. _tcslen(JBSTRING_NULL),
  273. TLS_JETBLUE_COLUMN_CODE_PAGE,
  274. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  275. TLS_JETBLUE_COLUMN_LANGID
  276. },
  277. //
  278. // Number of licenses for this client
  279. {
  280. LICENSE_COLUMN_NUMLICENSES,
  281. JET_coltypLong,
  282. 0,
  283. JET_bitColumnFixed | JET_bitColumnNotNULL,
  284. NULL,
  285. 0,
  286. TLS_JETBLUE_COLUMN_CODE_PAGE,
  287. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  288. TLS_JETBLUE_COLUMN_LANGID
  289. },
  290. //
  291. // IssuedDate
  292. {
  293. LICENSE_COLUMN_ISSUEDATE,
  294. JET_coltypLong,
  295. 0,
  296. JET_bitColumnFixed | JET_bitColumnNotNULL,
  297. NULL,
  298. 0,
  299. TLS_JETBLUE_COLUMN_CODE_PAGE,
  300. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  301. TLS_JETBLUE_COLUMN_LANGID
  302. },
  303. //
  304. // ExpireDate
  305. {
  306. LICENSE_COLUMN_EXPIREDATE,
  307. JET_coltypLong,
  308. 0,
  309. JET_bitColumnFixed | JET_bitColumnNotNULL,
  310. NULL,
  311. 0,
  312. TLS_JETBLUE_COLUMN_CODE_PAGE,
  313. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  314. TLS_JETBLUE_COLUMN_LANGID
  315. },
  316. //
  317. // License Status
  318. {
  319. LICENSE_COLUMN_LICENSESTATUS,
  320. JET_coltypUnsignedByte,
  321. 0,
  322. JET_bitColumnFixed | JET_bitColumnNotNULL,
  323. NULL,
  324. 0,
  325. TLS_JETBLUE_COLUMN_CODE_PAGE,
  326. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  327. TLS_JETBLUE_COLUMN_LANGID
  328. }
  329. };
  330. int
  331. LicensedTable::g_NumColumns=sizeof(LicensedTable::g_Columns) / sizeof(LicensedTable::g_Columns[0]);
  332. ///////////////////////////////////////////////////////////////////////
  333. //----------------------------------------------------------------------
  334. BOOL
  335. LicensedTable::ResolveToTableColumn()
  336. /*
  337. */
  338. {
  339. m_JetErr = ucEntryStatus.AttachToTable(
  340. *this,
  341. LICENSE_COLUMN_ENTRYSTATUS
  342. );
  343. if(IsSuccess() == FALSE)
  344. goto cleanup;
  345. m_JetErr = dwKeyPackLicenseId.AttachToTable(
  346. *this,
  347. LICENSE_COLUMN_LICENSEID
  348. );
  349. if(IsSuccess() == FALSE)
  350. goto cleanup;
  351. m_JetErr = ftLastModifyTime.AttachToTable(
  352. *this,
  353. LICENSE_COLUMN_LASTMODIFYTIME
  354. );
  355. if(IsSuccess() == FALSE)
  356. goto cleanup;
  357. m_JetErr = dwLicenseId.AttachToTable(
  358. *this,
  359. LICENSE_COLUMN_ID_COLUMN
  360. );
  361. if(IsSuccess() == FALSE)
  362. goto cleanup;
  363. m_JetErr = dwKeyPackId.AttachToTable(
  364. *this,
  365. LICENSE_COLUMN_KEYPACKID
  366. );
  367. if(IsSuccess() == FALSE)
  368. goto cleanup;
  369. m_JetErr = szMachineName.AttachToTable(
  370. *this,
  371. LICENSE_COLUMN_MACHINENAME
  372. );
  373. if(IsSuccess() == FALSE)
  374. goto cleanup;
  375. m_JetErr = szUserName.AttachToTable(
  376. *this,
  377. LICENSE_COLUMN_USERNAME
  378. );
  379. if(IsSuccess() == FALSE)
  380. goto cleanup;
  381. m_JetErr = ftIssueDate.AttachToTable(
  382. *this,
  383. LICENSE_COLUMN_ISSUEDATE
  384. );
  385. if(IsSuccess() == FALSE)
  386. goto cleanup;
  387. m_JetErr = ftExpireDate.AttachToTable(
  388. *this,
  389. LICENSE_COLUMN_EXPIREDATE
  390. );
  391. if(IsSuccess() == FALSE)
  392. goto cleanup;
  393. m_JetErr = ucLicenseStatus.AttachToTable(
  394. *this,
  395. LICENSE_COLUMN_LICENSESTATUS
  396. );
  397. if(IsSuccess() == FALSE)
  398. goto cleanup;
  399. m_JetErr = dwNumLicenses.AttachToTable(
  400. *this,
  401. LICENSE_COLUMN_NUMLICENSES
  402. );
  403. if(IsSuccess() == FALSE)
  404. goto cleanup;
  405. m_JetErr = dwSystemBiosChkSum.AttachToTable(
  406. *this,
  407. LICENSE_COLUMN_SYSTEMBIOS
  408. );
  409. if(IsSuccess() == FALSE)
  410. goto cleanup;
  411. m_JetErr = dwVideoBiosChkSum.AttachToTable(
  412. *this,
  413. LICENSE_COLUMN_VIDEOBIOS
  414. );
  415. if(IsSuccess() == FALSE)
  416. goto cleanup;
  417. m_JetErr = dwFloppyBiosChkSum.AttachToTable(
  418. *this,
  419. LICENSE_COLUMN_FLOPPYBIOS
  420. );
  421. if(IsSuccess() == FALSE)
  422. goto cleanup;
  423. m_JetErr = dwHardDiskSize.AttachToTable(
  424. *this,
  425. LICENSE_COLUMN_HARDDISKSIZE
  426. );
  427. if(IsSuccess() == FALSE)
  428. goto cleanup;
  429. m_JetErr = dwRamSize.AttachToTable(
  430. *this,
  431. LICENSE_COLUMN_RAMSIZE
  432. );
  433. if(IsSuccess() == FALSE)
  434. goto cleanup;
  435. m_JetErr = dbLowerBound.AttachToTable(
  436. *this,
  437. LICENSE_COLUMN_MATCHHWID
  438. );
  439. cleanup:
  440. return IsSuccess();
  441. }
  442. //------------------------------------------------------------
  443. inline CLASS_PRIVATE BOOL
  444. LicensedTable::ProcessSingleColumn(
  445. BOOL bFetch,
  446. TLSColumnBase& column,
  447. DWORD offset,
  448. PVOID pbData,
  449. DWORD cbData,
  450. PDWORD pcbDataReturn,
  451. LPCTSTR szColumnName
  452. )
  453. /*
  454. */
  455. {
  456. if(bFetch)
  457. {
  458. m_JetErr = column.FetchColumnValue(
  459. pbData,
  460. cbData,
  461. offset,
  462. pcbDataReturn
  463. );
  464. }
  465. else
  466. {
  467. m_JetErr = column.InsertColumnValue(
  468. pbData,
  469. cbData,
  470. offset
  471. );
  472. }
  473. REPORTPROCESSFAILED(
  474. bFetch,
  475. GetTableName(),
  476. szColumnName,
  477. m_JetErr
  478. );
  479. return IsSuccess();
  480. }
  481. //------------------------------------------------------------
  482. CLASS_PRIVATE BOOL
  483. LicensedTable::ProcessRecord(
  484. LICENSEDCLIENT* licensed,
  485. BOOL bFetch,
  486. DWORD dwParam,
  487. BOOL bUpdate
  488. )
  489. /*
  490. */
  491. {
  492. DWORD dwSize;
  493. if(bFetch == FALSE)
  494. {
  495. BeginUpdate(bUpdate);
  496. // any update will require update on lastmodifytime column
  497. if(!(dwParam & LICENSE_PROCESS_LASTMODIFYTIME))
  498. {
  499. JB_ASSERT(FALSE);
  500. dwParam |= LICENSE_PROCESS_LASTMODIFYTIME;
  501. }
  502. }
  503. else
  504. {
  505. SetLastJetError(JET_errSuccess);
  506. }
  507. if(IsSuccess() == FALSE)
  508. goto cleanup;
  509. if(dwParam & LICENSE_PROCESS_KEYPACKLICENSEID)
  510. {
  511. ProcessSingleColumn(
  512. bFetch,
  513. dwKeyPackLicenseId,
  514. 0,
  515. &(licensed->dwKeyPackLicenseId),
  516. sizeof(licensed->dwKeyPackLicenseId),
  517. &dwSize,
  518. LICENSE_COLUMN_LICENSEID
  519. );
  520. }
  521. if(IsSuccess() == FALSE)
  522. goto cleanup;
  523. if(dwParam & LICENSE_PROCESS_LASTMODIFYTIME)
  524. {
  525. ProcessSingleColumn(
  526. bFetch,
  527. ftLastModifyTime,
  528. 0,
  529. &(licensed->ftLastModifyTime),
  530. sizeof(licensed->ftLastModifyTime),
  531. &dwSize,
  532. LICENSE_COLUMN_LASTMODIFYTIME
  533. );
  534. }
  535. if(IsSuccess() == FALSE)
  536. goto cleanup;
  537. if(dwParam & LICENSE_PROCESS_LICENSEID)
  538. {
  539. // primary index, can't change
  540. if(bUpdate == FALSE)
  541. {
  542. ProcessSingleColumn(
  543. bFetch,
  544. dwLicenseId,
  545. 0,
  546. &(licensed->dwLicenseId),
  547. sizeof(licensed->dwLicenseId),
  548. &dwSize,
  549. LICENSE_COLUMN_ID_COLUMN
  550. );
  551. }
  552. }
  553. if(IsSuccess() == FALSE)
  554. goto cleanup;
  555. if(dwParam & LICENSE_PROCESS_KEYPACKID)
  556. {
  557. ProcessSingleColumn(
  558. bFetch,
  559. dwKeyPackId,
  560. 0,
  561. &(licensed->dwKeyPackId),
  562. sizeof(licensed->dwKeyPackId),
  563. &dwSize,
  564. LICENSE_COLUMN_KEYPACKID
  565. );
  566. }
  567. if(IsSuccess() == FALSE)
  568. goto cleanup;
  569. if(dwParam & LICENSE_PROCESS_MACHINENAME)
  570. {
  571. ProcessSingleColumn(
  572. bFetch,
  573. szMachineName,
  574. 0,
  575. licensed->szMachineName,
  576. sizeof(licensed->szMachineName),
  577. &dwSize,
  578. LICENSE_COLUMN_MACHINENAME
  579. );
  580. }
  581. if(IsSuccess() == FALSE)
  582. goto cleanup;
  583. if(dwParam & LICENSE_PROCESS_USERNAME)
  584. {
  585. ProcessSingleColumn(
  586. bFetch,
  587. szUserName,
  588. 0,
  589. licensed->szUserName,
  590. sizeof(licensed->szUserName),
  591. &dwSize,
  592. LICENSE_COLUMN_USERNAME
  593. );
  594. }
  595. if(IsSuccess() == FALSE)
  596. goto cleanup;
  597. if(dwParam & LICENSE_PROCESS_ISSUEDATE)
  598. {
  599. ProcessSingleColumn(
  600. bFetch,
  601. ftIssueDate,
  602. 0,
  603. &(licensed->ftIssueDate),
  604. sizeof(licensed->ftIssueDate),
  605. &dwSize,
  606. LICENSE_COLUMN_ISSUEDATE
  607. );
  608. }
  609. if(IsSuccess() == FALSE)
  610. goto cleanup;
  611. if(dwParam & LICENSE_PROCESS_EXPIREDATE)
  612. {
  613. ProcessSingleColumn(
  614. bFetch,
  615. ftExpireDate,
  616. 0,
  617. &(licensed->ftExpireDate),
  618. sizeof(licensed->ftExpireDate),
  619. &dwSize,
  620. LICENSE_COLUMN_EXPIREDATE
  621. );
  622. }
  623. if(IsSuccess() == FALSE)
  624. goto cleanup;
  625. if(dwParam & LICENSE_PROCESS_NUMLICENSES)
  626. {
  627. ProcessSingleColumn(
  628. bFetch,
  629. dwNumLicenses,
  630. 0,
  631. &(licensed->dwNumLicenses),
  632. sizeof(licensed->dwNumLicenses),
  633. &dwSize,
  634. LICENSE_COLUMN_NUMLICENSES
  635. );
  636. }
  637. if(IsSuccess() == FALSE)
  638. goto cleanup;
  639. if(dwParam & LICENSE_PROCESS_LICENSESTATUS)
  640. {
  641. ProcessSingleColumn(
  642. bFetch,
  643. ucLicenseStatus,
  644. 0,
  645. &(licensed->ucLicenseStatus),
  646. sizeof(licensed->ucLicenseStatus),
  647. &dwSize,
  648. LICENSE_COLUMN_LICENSESTATUS
  649. );
  650. }
  651. if(IsSuccess() == FALSE)
  652. goto cleanup;
  653. if(dwParam & LICENSE_PROCESS_SYSTEMBIOS)
  654. {
  655. ProcessSingleColumn(
  656. bFetch,
  657. dwSystemBiosChkSum,
  658. 0,
  659. &(licensed->dwSystemBiosChkSum),
  660. sizeof(licensed->dwSystemBiosChkSum),
  661. &dwSize,
  662. LICENSE_COLUMN_SYSTEMBIOS
  663. );
  664. }
  665. if(IsSuccess() == FALSE)
  666. goto cleanup;
  667. if(dwParam & LICENSE_PROCESS_VIDEOBIOS)
  668. {
  669. ProcessSingleColumn(
  670. bFetch,
  671. dwVideoBiosChkSum,
  672. 0,
  673. &(licensed->dwVideoBiosChkSum),
  674. sizeof(licensed->dwVideoBiosChkSum),
  675. &dwSize,
  676. LICENSE_COLUMN_VIDEOBIOS
  677. );
  678. }
  679. if(IsSuccess() == FALSE)
  680. goto cleanup;
  681. if(dwParam & LICENSE_PROCESS_FLOPPYBIOS)
  682. {
  683. ProcessSingleColumn(
  684. bFetch,
  685. dwFloppyBiosChkSum,
  686. 0,
  687. &(licensed->dwFloppyBiosChkSum),
  688. sizeof(licensed->dwFloppyBiosChkSum),
  689. &dwSize,
  690. LICENSE_COLUMN_FLOPPYBIOS
  691. );
  692. }
  693. if(IsSuccess() == FALSE)
  694. goto cleanup;
  695. if(dwParam & LICENSE_PROCESS_HARDDISKSIZE)
  696. {
  697. ProcessSingleColumn(
  698. bFetch,
  699. dwHardDiskSize,
  700. 0,
  701. &(licensed->dwHardDiskSize),
  702. sizeof(licensed->dwHardDiskSize),
  703. &dwSize,
  704. LICENSE_COLUMN_HARDDISKSIZE
  705. );
  706. }
  707. if(IsSuccess() == FALSE)
  708. goto cleanup;
  709. if(dwParam & LICENSE_PROCESS_RAMSIZE)
  710. {
  711. ProcessSingleColumn(
  712. bFetch,
  713. dwRamSize,
  714. 0,
  715. &(licensed->dwRamSize),
  716. sizeof(licensed->dwRamSize),
  717. &dwSize,
  718. LICENSE_COLUMN_RAMSIZE
  719. );
  720. }
  721. if(IsSuccess() == FALSE)
  722. goto cleanup;
  723. if(dwParam & LICENSE_PROCESS_ENTRYSTATUS)
  724. {
  725. ProcessSingleColumn(
  726. bFetch,
  727. ucEntryStatus,
  728. 0,
  729. &(licensed->ucEntryStatus),
  730. sizeof(licensed->ucEntryStatus),
  731. &dwSize,
  732. LICENSE_COLUMN_ENTRYSTATUS
  733. );
  734. }
  735. if(IsSuccess() == FALSE)
  736. goto cleanup;
  737. if(dwParam & LICENSE_PROCESS_MATCHHWID)
  738. {
  739. ProcessSingleColumn(
  740. bFetch,
  741. dbLowerBound,
  742. 0,
  743. &(licensed->dbLowerBound),
  744. sizeof(licensed->dbLowerBound),
  745. &dwSize,
  746. LICENSE_COLUMN_MATCHHWID
  747. );
  748. }
  749. cleanup:
  750. //
  751. // For inserting/updating record
  752. if(bFetch == FALSE)
  753. {
  754. JET_ERR jetErr;
  755. jetErr = GetLastJetError();
  756. EndUpdate(IsSuccess() == FALSE);
  757. if(jetErr != JET_errSuccess && IsSuccess() == FALSE)
  758. SetLastJetError(jetErr);
  759. }
  760. return IsSuccess();
  761. }
  762. //-------------------------------------------------------
  763. JBKeyBase*
  764. LicensedTable::EnumerationIndex(
  765. BOOL bMatchAll,
  766. DWORD dwParam,
  767. LICENSEDCLIENT* pLicensed,
  768. BOOL* bCompareKey
  769. )
  770. /*
  771. */
  772. {
  773. JBKeyBase* index=NULL;
  774. *bCompareKey = bMatchAll;
  775. if(dwParam == LICENSE_COLUMN_SEARCH_HWID)
  776. {
  777. if(bMatchAll)
  778. {
  779. index = new TLSLicensedIndexHwid(pLicensed);
  780. }
  781. else
  782. {
  783. index = new TLSLicensedIndexMatchHwid(pLicensed);
  784. }
  785. }
  786. else if(dwParam & LICENSE_PROCESS_KEYPACKID)
  787. {
  788. index = new TLSLicensedIndexKeyPackId(pLicensed);
  789. }
  790. else if(dwParam & LICENSE_PROCESS_MACHINENAME)
  791. {
  792. index = new TLSLicensedIndexMachineName(pLicensed);
  793. }
  794. else if(dwParam & LICENSE_PROCESS_USERNAME)
  795. {
  796. index = new TLSLicensedIndexUserName(pLicensed);
  797. }
  798. else if(dwParam & LICENSE_PROCESS_LASTMODIFYTIME)
  799. {
  800. index = new TLSLicensedIndexLastModifyTime(pLicensed);
  801. }
  802. else if(dwParam & LICENSE_PROCESS_EXPIREDATE)
  803. {
  804. index = new TLSLicensedIndexExpireDate(pLicensed);
  805. }
  806. else
  807. {
  808. // use default primary index for iteration, compare key
  809. // is depends on whether primary index column is in the
  810. // field.
  811. index = new TLSLicensedIndexLicenseId(pLicensed);
  812. *bCompareKey = (bMatchAll && (dwParam & LICENSE_PROCESS_LICENSEID));
  813. }
  814. return index;
  815. }
  816. //-------------------------------------------------------
  817. BOOL
  818. LicensedTable::EqualValue(
  819. LICENSEDCLIENT& s1,
  820. LICENSEDCLIENT& s2,
  821. BOOL bMatchAll,
  822. DWORD dwParam
  823. )
  824. /*
  825. */
  826. {
  827. BOOL bRetCode = TRUE;
  828. if(dwParam & LICENSE_PROCESS_ENTRYSTATUS)
  829. {
  830. bRetCode = (s1.ucEntryStatus == s2.ucEntryStatus);
  831. if(bMatchAll != bRetCode)
  832. goto cleanup;
  833. }
  834. if(dwParam & LICENSE_PROCESS_KEYPACKLICENSEID)
  835. {
  836. bRetCode = (s1.dwKeyPackLicenseId == s2.dwKeyPackLicenseId);
  837. if(bMatchAll != bRetCode)
  838. goto cleanup;
  839. }
  840. if(dwParam & LICENSE_PROCESS_LASTMODIFYTIME)
  841. {
  842. bRetCode = (CompareFileTime(&s1.ftLastModifyTime, &s2.ftLastModifyTime) == 0);
  843. if(bMatchAll != bRetCode)
  844. goto cleanup;
  845. }
  846. if(dwParam & LICENSE_PROCESS_LICENSEID)
  847. {
  848. bRetCode = (s1.dwLicenseId == s2.dwLicenseId);
  849. if(bMatchAll != bRetCode)
  850. goto cleanup;
  851. }
  852. if(dwParam & LICENSE_PROCESS_KEYPACKID)
  853. {
  854. bRetCode = (s1.dwKeyPackId == s2.dwKeyPackId);
  855. if(bMatchAll != bRetCode)
  856. goto cleanup;
  857. }
  858. if(dwParam & LICENSE_PROCESS_MACHINENAME)
  859. {
  860. bRetCode = (_tcscmp(s1.szMachineName, s2.szMachineName) == 0);
  861. if(bMatchAll != bRetCode)
  862. goto cleanup;
  863. }
  864. if(dwParam & LICENSE_PROCESS_USERNAME)
  865. {
  866. bRetCode = (_tcscmp(s1.szUserName, s2.szUserName) == 0);
  867. if(bMatchAll != bRetCode)
  868. goto cleanup;
  869. }
  870. if(dwParam & LICENSE_PROCESS_ISSUEDATE)
  871. {
  872. bRetCode = (s1.ftIssueDate == s2.ftIssueDate);
  873. if(bMatchAll != bRetCode)
  874. goto cleanup;
  875. }
  876. if(dwParam & LICENSE_PROCESS_EXPIREDATE)
  877. {
  878. bRetCode = (s1.ftExpireDate == s2.ftExpireDate);
  879. if(bMatchAll != bRetCode)
  880. goto cleanup;
  881. }
  882. if(dwParam & LICENSE_PROCESS_NUMLICENSES)
  883. {
  884. bRetCode = (s1.dwNumLicenses == s2.dwNumLicenses);
  885. if(bMatchAll != bRetCode)
  886. goto cleanup;
  887. }
  888. if(dwParam & LICENSE_PROCESS_LICENSESTATUS)
  889. {
  890. bRetCode = (s1.ucLicenseStatus == s2.ucLicenseStatus);
  891. if(bMatchAll != bRetCode)
  892. goto cleanup;
  893. }
  894. if(dwParam & LICENSE_PROCESS_SYSTEMBIOS)
  895. {
  896. bRetCode = (s1.dwSystemBiosChkSum == s2.dwSystemBiosChkSum);
  897. if(bMatchAll != bRetCode)
  898. goto cleanup;
  899. }
  900. if(dwParam & LICENSE_PROCESS_VIDEOBIOS)
  901. {
  902. bRetCode = (s1.dwVideoBiosChkSum == s2.dwVideoBiosChkSum);
  903. if(bMatchAll != bRetCode)
  904. goto cleanup;
  905. }
  906. if(dwParam & LICENSE_PROCESS_FLOPPYBIOS)
  907. {
  908. bRetCode = (s1.dwFloppyBiosChkSum == s2.dwFloppyBiosChkSum);
  909. if(bMatchAll != bRetCode)
  910. goto cleanup;
  911. }
  912. if(dwParam & LICENSE_PROCESS_HARDDISKSIZE)
  913. {
  914. bRetCode = (s1.dwHardDiskSize == s2.dwHardDiskSize);
  915. if(bMatchAll != bRetCode)
  916. goto cleanup;
  917. }
  918. if(dwParam & LICENSE_PROCESS_RAMSIZE)
  919. {
  920. bRetCode = (s1.dwRamSize == s2.dwRamSize);
  921. }
  922. if(dwParam & LICENSE_PROCESS_MATCHHWID)
  923. {
  924. bRetCode = (s1.dbLowerBound == s2.dbLowerBound);
  925. }
  926. cleanup:
  927. return bRetCode;
  928. }
  929. //--------------------------------------------------------
  930. BOOL
  931. LicensedTable::UpgradeTable(
  932. IN DWORD dwOldVersion,
  933. IN DWORD dwNewVersion
  934. )
  935. /*++
  936. ++*/
  937. {
  938. int nExpDate = g_NumTableIndex-1;
  939. unsigned long keylength;
  940. BOOL fRet = TRUE;
  941. if(dwOldVersion > dwNewVersion)
  942. {
  943. // We don't know how to handle later versions
  944. JB_ASSERT(FALSE);
  945. return FALSE;
  946. }
  947. if(OpenTable(TRUE, JET_bitTableUpdatable) == FALSE)
  948. return FALSE;
  949. //
  950. // check if expiration date index exists
  951. //
  952. if (DoesIndexExist(g_TableIndex[nExpDate].pszIndexName))
  953. {
  954. goto cleanup;
  955. }
  956. //
  957. // Insert new index for expiration date
  958. //
  959. if (g_TableIndex[nExpDate].cbKey == -1)
  960. {
  961. // calculate index key length
  962. keylength = 2;
  963. while(g_TableIndex[nExpDate].pszIndexKey[keylength-1] != _TEXT('\0') ||
  964. (g_TableIndex[nExpDate].pszIndexKey[keylength-2] != _TEXT('\0')))
  965. {
  966. keylength++;
  967. }
  968. if(keylength >= TLS_JETBLUE_MAX_INDEXKEY_LENGTH)
  969. {
  970. fRet = FALSE;
  971. goto cleanup;
  972. }
  973. }
  974. else
  975. {
  976. keylength = g_TableIndex[nExpDate].cbKey;
  977. }
  978. AddJetIndex(g_TableIndex[nExpDate].pszIndexName,
  979. g_TableIndex[nExpDate].pszIndexKey,
  980. keylength,
  981. g_TableIndex[nExpDate].jbGrbit,
  982. g_TableIndex[nExpDate].ulDensity
  983. );
  984. cleanup:
  985. return CloseTable() && fRet;
  986. }