Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

599 lines
15 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: kpDesc.cpp
  7. //
  8. // Contents:
  9. // KeyPackDesc Table related function.
  10. //
  11. // History:
  12. // Feb. 4, 98 HueiWang Created.
  13. //
  14. // Note :
  15. // Bind Parameter and Bind Column need to to in sync with select column
  16. //---------------------------------------------------------------------------
  17. #include "pch.cpp"
  18. #include "lkpdesc.h"
  19. #include "globals.h"
  20. //---------------------------------------------------------------------------
  21. // Functions : LSDBLockKeyPackDescTable()
  22. // LSDBUnlockKeyPackDescTable()
  23. //
  24. // Abstract : Lock and Unlock single access to key pack desc. table.
  25. //---------------------------------------------------------------------------
  26. void
  27. TLSDBLockKeyPackDescTable()
  28. {
  29. DBGPrintf(
  30. DBG_INFORMATION,
  31. DBG_FACILITY_LOCK,
  32. DBGLEVEL_FUNCTION_TRACE,
  33. _TEXT("Locking table KeyPackDescTable\n")
  34. );
  35. LicPackDescTable::LockTable();
  36. return;
  37. }
  38. void
  39. TLSDBUnlockKeyPackDescTable()
  40. {
  41. DBGPrintf(
  42. DBG_INFORMATION,
  43. DBG_FACILITY_LOCK,
  44. DBGLEVEL_FUNCTION_TRACE,
  45. _TEXT("Unlocking table KeyPackDescTable\n")
  46. );
  47. LicPackDescTable::UnlockTable();
  48. return;
  49. }
  50. //++--------------------------------------------------------------------
  51. DWORD
  52. TLSDBKeyPackDescEnumBegin(
  53. IN PTLSDbWorkSpace pDbWkSpace,
  54. IN BOOL bMatchAll,
  55. IN DWORD dwSearchParm,
  56. IN PLICPACKDESC lpKeyPackDesc
  57. )
  58. /*++
  59. Abstract:
  60. Begin enumeration of license pack description table.
  61. Parameters:
  62. pDbWkSpace : Workspace handle.
  63. bMatchAll : TRUE if matching all license pack
  64. description search value, FALSE otherwise
  65. dwSearchParam : Field that will be search on.
  66. lpKeyPackDesc : value to be search, subject to bMatchAll criteral
  67. Returns:
  68. */
  69. {
  70. DWORD dwStatus=ERROR_SUCCESS;
  71. BOOL bSuccess=TRUE;
  72. if(pDbWkSpace == NULL)
  73. {
  74. SetLastError(dwStatus = ERROR_INVALID_PARAMETER);
  75. TLSASSERT(FALSE);
  76. return dwStatus;
  77. }
  78. bSuccess = pDbWkSpace->m_LicPackDescTable.EnumerateBegin(
  79. bMatchAll,
  80. dwSearchParm,
  81. lpKeyPackDesc
  82. );
  83. if(bSuccess == FALSE)
  84. {
  85. LPTSTR pString = NULL;
  86. TLSGetESEError(
  87. pDbWkSpace->m_LicPackDescTable.GetLastJetError(),
  88. &pString
  89. );
  90. TLSLogEvent(
  91. EVENTLOG_ERROR_TYPE,
  92. TLS_E_DBGENERAL,
  93. TLS_E_JB_BASE,
  94. pDbWkSpace->m_LicPackDescTable.GetLastJetError(),
  95. (pString != NULL) ? pString : _TEXT("")
  96. );
  97. if(pString != NULL)
  98. {
  99. LocalFree(pString);
  100. }
  101. SetLastError(dwStatus = SET_JB_ERROR(pDbWkSpace->m_LicPackDescTable.GetLastJetError()));
  102. TLSASSERT(FALSE);
  103. }
  104. return dwStatus;
  105. }
  106. //++----------------------------------------------------------------------
  107. DWORD
  108. TLSDBKeyPackDescEnumNext(
  109. IN PTLSDbWorkSpace pDbWkSpace,
  110. IN OUT PLICPACKDESC lpKeyPackDesc
  111. )
  112. /*++
  113. Abstract:
  114. Fetch next record in LicPackDesc table that match search condition.
  115. Parameter:
  116. pDbWkSpace : Workspace handle.
  117. lpKeyPackDesc : return record that match search condition.
  118. Returns:
  119. ++*/
  120. {
  121. DWORD dwStatus=ERROR_SUCCESS;
  122. if(pDbWkSpace == NULL)
  123. {
  124. SetLastError(dwStatus = ERROR_INVALID_PARAMETER);
  125. TLSASSERT(FALSE);
  126. return dwStatus;
  127. }
  128. switch(pDbWkSpace->m_LicPackDescTable.EnumerateNext(*lpKeyPackDesc))
  129. {
  130. case RECORD_ENUM_ERROR:
  131. {
  132. LPTSTR pString = NULL;
  133. TLSGetESEError(
  134. pDbWkSpace->m_LicPackDescTable.GetLastJetError(),
  135. &pString
  136. );
  137. TLSLogEvent(
  138. EVENTLOG_ERROR_TYPE,
  139. TLS_E_DBGENERAL,
  140. TLS_E_JB_BASE,
  141. pDbWkSpace->m_LicPackDescTable.GetLastJetError(),
  142. (pString != NULL) ? pString : _TEXT("")
  143. );
  144. if(pString != NULL)
  145. {
  146. LocalFree(pString);
  147. }
  148. }
  149. dwStatus = SET_JB_ERROR(pDbWkSpace->m_LicPackDescTable.GetLastJetError());
  150. TLSASSERT(FALSE);
  151. break;
  152. case RECORD_ENUM_MORE_DATA:
  153. dwStatus = ERROR_SUCCESS;
  154. break;
  155. case RECORD_ENUM_END:
  156. dwStatus = TLS_I_NO_MORE_DATA;
  157. }
  158. return dwStatus;
  159. }
  160. //++-----------------------------------------------------------------------
  161. DWORD
  162. TLSDBKeyPackDescEnumEnd(
  163. IN PTLSDbWorkSpace pDbWkSpace
  164. )
  165. /*++
  166. Abstract:
  167. End enumeration of LicPackDesc. table
  168. Parameter:
  169. pdbWkSpace : Workspace handle.
  170. Returns:
  171. ++*/
  172. {
  173. pDbWkSpace->m_LicPackDescTable.EnumerateEnd();
  174. return ERROR_SUCCESS;
  175. }
  176. //++-----------------------------------------------------------------------
  177. DWORD
  178. TLSDBKeyPackDescAddEntry(
  179. IN PTLSDbWorkSpace pDbWkSpace,
  180. IN PLICPACKDESC lpKeyPackDesc
  181. )
  182. /*++
  183. Abstract:
  184. Add a record into licensepackdesc table.
  185. Parameter:
  186. pDbWkSpace : workspace handle.
  187. lpKeyPackDesc : record to be added into table.
  188. Returns:
  189. ++*/
  190. {
  191. DWORD dwStatus = ERROR_SUCCESS;
  192. LicPackDescTable& kpDescTable = pDbWkSpace->m_LicPackDescTable;
  193. //
  194. // Check for duplicate entry
  195. //
  196. dwStatus = TLSDBKeyPackDescFind(
  197. pDbWkSpace,
  198. TRUE,
  199. LICPACKDESCRECORD_TABLE_SEARCH_KEYPACKID | LICPACKDESCRECORD_TABLE_SEARCH_LANGID,
  200. lpKeyPackDesc,
  201. NULL
  202. );
  203. if(dwStatus == ERROR_SUCCESS)
  204. {
  205. SetLastError(dwStatus = TLS_E_DUPLICATE_RECORD);
  206. goto cleanup;
  207. }
  208. else if(dwStatus != TLS_E_RECORD_NOTFOUND)
  209. {
  210. goto cleanup;
  211. }
  212. SetLastError(dwStatus = ERROR_SUCCESS);
  213. if(kpDescTable.InsertRecord(*lpKeyPackDesc) == FALSE)
  214. {
  215. if(kpDescTable.GetLastJetError() == JET_errKeyDuplicate)
  216. {
  217. SetLastError(dwStatus=TLS_E_DUPLICATE_RECORD);
  218. }
  219. else
  220. {
  221. LPTSTR pString = NULL;
  222. TLSGetESEError(kpDescTable.GetLastJetError(), &pString);
  223. TLSLogEvent(
  224. EVENTLOG_ERROR_TYPE,
  225. TLS_E_DBGENERAL,
  226. TLS_E_JB_BASE,
  227. kpDescTable.GetLastJetError(),
  228. (pString != NULL) ? pString : _TEXT("")
  229. );
  230. if(pString != NULL)
  231. {
  232. LocalFree(pString);
  233. }
  234. SetLastError(dwStatus = SET_JB_ERROR(kpDescTable.GetLastJetError()));
  235. TLSASSERT(FALSE);
  236. }
  237. }
  238. cleanup:
  239. return dwStatus;
  240. }
  241. //++------------------------------------------------------------------------
  242. DWORD
  243. TLSDBKeyPackDescDeleteEntry(
  244. IN PTLSDbWorkSpace pDbWkSpace,
  245. IN PLICPACKDESC lpKeyPackDesc
  246. )
  247. /*++
  248. Abstract:
  249. Delete all record from LicPackDesc table that match the keypack id
  250. Parameter:
  251. pDbWkSpace : workspace handle.
  252. lpKeyPackDesc : keypack Id to be deleted
  253. Returns:
  254. */
  255. {
  256. DWORD dwStatus = ERROR_SUCCESS;
  257. LicPackDescTable& kpDescTable = pDbWkSpace->m_LicPackDescTable;
  258. BOOL bSuccess;
  259. bSuccess = kpDescTable.DeleteAllRecord(
  260. TRUE,
  261. LICPACKDESCRECORD_TABLE_SEARCH_KEYPACKID,
  262. *lpKeyPackDesc
  263. );
  264. if( bSuccess == FALSE )
  265. {
  266. SetLastError(dwStatus = SET_JB_ERROR(kpDescTable.GetLastJetError()));
  267. // ignore record not found error
  268. if(kpDescTable.GetLastJetError() != JET_errRecordNotFound)
  269. {
  270. LPTSTR pString = NULL;
  271. TLSGetESEError(kpDescTable.GetLastJetError(), &pString);
  272. TLSLogEvent(
  273. EVENTLOG_ERROR_TYPE,
  274. TLS_E_DBGENERAL,
  275. TLS_E_JB_BASE,
  276. kpDescTable.GetLastJetError(),
  277. (pString != NULL) ? pString : _TEXT("")
  278. );
  279. if(pString != NULL)
  280. {
  281. LocalFree(pString);
  282. }
  283. TLSASSERT(kpDescTable.GetLastJetError() == JET_errRecordNotFound);
  284. }
  285. }
  286. return dwStatus;
  287. }
  288. //++------------------------------------------------------------------------
  289. DWORD
  290. TLSDBKeyPackDescUpdateEntry(
  291. IN PTLSDbWorkSpace pDbWkSpace,
  292. IN DWORD dwUpdateParm,
  293. IN PLICPACKDESC lpKeyPackDesc
  294. )
  295. /*++
  296. Abstract:
  297. Update column value of record in LicPackDescTable that match
  298. the keypackid
  299. Parameter:
  300. pDbWkSpace : Work space handle.
  301. dwUpdateParm : Fields that will be updated, note, keypack ID and language ID
  302. can't be update.
  303. lpKeyPackDesc : Record/value to be update
  304. Returns:
  305. Note:
  306. dwKeyPackId and dwLangId can't be update.
  307. ++*/
  308. {
  309. DWORD dwStatus = ERROR_SUCCESS;
  310. LicPackDescTable& kpDescTable = pDbWkSpace->m_LicPackDescTable;
  311. BOOL bSuccess;
  312. //
  313. // Check for duplicate entry
  314. //
  315. dwStatus = TLSDBKeyPackDescFind(
  316. pDbWkSpace,
  317. TRUE,
  318. LICPACKDESCRECORD_TABLE_SEARCH_KEYPACKID | LICPACKDESCRECORD_TABLE_SEARCH_LANGID,
  319. lpKeyPackDesc,
  320. NULL
  321. );
  322. if(dwStatus != ERROR_SUCCESS)
  323. {
  324. TLSASSERT(dwStatus == ERROR_SUCCESS);
  325. goto cleanup;
  326. }
  327. bSuccess = kpDescTable.UpdateRecord(
  328. *lpKeyPackDesc,
  329. dwUpdateParm & ~(LICPACKDESCRECORD_TABLE_SEARCH_KEYPACKID | LICPACKDESCRECORD_TABLE_SEARCH_LANGID)
  330. );
  331. if(bSuccess == FALSE)
  332. {
  333. LPTSTR pString = NULL;
  334. TLSGetESEError(kpDescTable.GetLastJetError(), &pString);
  335. TLSLogEvent(
  336. EVENTLOG_ERROR_TYPE,
  337. TLS_E_DBGENERAL,
  338. TLS_E_JB_BASE,
  339. kpDescTable.GetLastJetError(),
  340. (pString != NULL) ? pString : _TEXT("")
  341. );
  342. if(pString != NULL)
  343. {
  344. LocalFree(pString);
  345. }
  346. SetLastError(dwStatus = SET_JB_ERROR(kpDescTable.GetLastJetError()));
  347. TLSASSERT(FALSE);
  348. }
  349. cleanup:
  350. return dwStatus;
  351. }
  352. //++----------------------------------------------------------------------
  353. DWORD
  354. TLSDBKeyPackDescSetValue(
  355. PTLSDbWorkSpace pDbWkSpace,
  356. DWORD dwSetParm,
  357. PLICPACKDESC lpKeyPackDesc
  358. )
  359. /*++
  360. Abstract:
  361. Add/Delete/Update a record in LicPackDescTable.
  362. Parameter:
  363. pDbWkSpace : workspace handle.
  364. dwSetParm : Columns to be update.
  365. lpKeyPackDesc : record/value to be update/delete/add.
  366. Return:
  367. Note:
  368. Wrapper around TLSDBKeyPackDescDeleteEntry(),
  369. TLSDBKeyPackDescAddEntry(), TLSDBKeyPackDescUpdateEntry()
  370. base on dwSetParm value.
  371. ++*/
  372. {
  373. DWORD dwStatus=ERROR_SUCCESS;
  374. if(pDbWkSpace == NULL || lpKeyPackDesc == NULL)
  375. {
  376. SetLastError(dwStatus = ERROR_INVALID_PARAMETER);
  377. goto cleanup;
  378. }
  379. TLSDBLockKeyPackDescTable();
  380. if(dwSetParm & KEYPACKDESC_SET_DELETE_ENTRY)
  381. {
  382. dwStatus = TLSDBKeyPackDescDeleteEntry(
  383. pDbWkSpace,
  384. lpKeyPackDesc
  385. );
  386. }
  387. else if(dwSetParm & KEYPACKDESC_SET_ADD_ENTRY)
  388. {
  389. dwStatus = TLSDBKeyPackDescAddEntry(
  390. pDbWkSpace,
  391. lpKeyPackDesc
  392. );
  393. }
  394. else
  395. {
  396. dwStatus = TLSDBKeyPackDescUpdateEntry(
  397. pDbWkSpace,
  398. dwSetParm,
  399. lpKeyPackDesc
  400. );
  401. }
  402. TLSDBUnlockKeyPackDescTable();
  403. cleanup:
  404. return dwStatus;
  405. }
  406. //++---------------------------------------------------------------------
  407. DWORD
  408. TLSDBKeyPackDescFind(
  409. IN PTLSDbWorkSpace pDbWkSpace,
  410. IN BOOL bMatchAllParam,
  411. IN DWORD dwSearchParm,
  412. IN PLICPACKDESC lpKeyPackDesc,
  413. IN OUT PLICPACKDESC lpKeyPackDescFound
  414. )
  415. /*
  416. Abstract:
  417. Find a LicPackDesc record based on search parameters.
  418. Parameter:
  419. pDbWkSpace - workspace handle.
  420. bMatchAllParam - TRUE match all search parameters, FALSE otherwise.
  421. dwSearchParam - Fields that will participate in search.
  422. lpKeyPackDesc - value to be search.
  423. lpKeyPackDescFound - return found record.
  424. Returns:
  425. Note:
  426. */
  427. {
  428. DWORD dwStatus=ERROR_SUCCESS;
  429. BOOL bSuccess;
  430. LICPACKDESC kpDescFound;
  431. if(pDbWkSpace == NULL || lpKeyPackDesc == NULL)
  432. {
  433. SetLastError(dwStatus = ERROR_INVALID_PARAMETER);
  434. TLSASSERT(pDbWkSpace != NULL);
  435. return dwStatus;
  436. }
  437. LicPackDescTable& kpDescTable = pDbWkSpace->m_LicPackDescTable;
  438. bSuccess = kpDescTable.FindRecord(
  439. bMatchAllParam,
  440. dwSearchParm,
  441. *lpKeyPackDesc,
  442. kpDescFound
  443. );
  444. if(bSuccess != TRUE)
  445. {
  446. if(kpDescTable.GetLastJetError() == JET_errRecordNotFound)
  447. {
  448. SetLastError(dwStatus = TLS_E_RECORD_NOTFOUND);
  449. }
  450. else
  451. {
  452. LPTSTR pString = NULL;
  453. TLSGetESEError(kpDescTable.GetLastJetError(), &pString);
  454. TLSLogEvent(
  455. EVENTLOG_ERROR_TYPE,
  456. TLS_E_DBGENERAL,
  457. TLS_E_JB_BASE,
  458. kpDescTable.GetLastJetError(),
  459. (pString != NULL) ? pString : _TEXT("")
  460. );
  461. if(pString != NULL)
  462. {
  463. LocalFree(pString);
  464. }
  465. SetLastError(
  466. dwStatus = (SET_JB_ERROR(kpDescTable.GetLastJetError()))
  467. );
  468. TLSASSERT(kpDescTable.GetLastJetError() == JET_errRecordNotFound);
  469. }
  470. }
  471. else
  472. {
  473. if(lpKeyPackDescFound != NULL)
  474. {
  475. *lpKeyPackDescFound = kpDescFound;
  476. }
  477. }
  478. return dwStatus;
  479. }