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.

2105 lines
55 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. wzclog.c
  5. Abstract:
  6. This module contains all of the code to service the
  7. API calls made to the SPD logging server.
  8. Author:
  9. abhisheV 18-October-2001
  10. Environment
  11. User Level: Win32
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. DWORD
  16. OpenWZCDbLogSession(
  17. LPWSTR pServerName,
  18. DWORD dwVersion,
  19. PHANDLE phSession
  20. )
  21. /*++
  22. Routine Description:
  23. This function opens a new session for a client.
  24. Arguments:
  25. pServerName - Pointer to the server name.
  26. phSession - Pointer to hold the handle for the opened session.
  27. Return Value:
  28. Windows Error.
  29. --*/
  30. {
  31. DWORD Error = 0;
  32. PSESSION_CONTAINER pSessionCont = NULL;
  33. Error = CreateSessionCont(
  34. &pSessionCont
  35. );
  36. BAIL_ON_WIN32_ERROR(Error);
  37. AcquireExclusiveLock(gpWZCDbSessionRWLock);
  38. Error = IniOpenWZCDbLogSession(pSessionCont);
  39. BAIL_ON_LOCK_ERROR(Error);
  40. pSessionCont->pNext = gpSessionCont;
  41. gpSessionCont = pSessionCont;
  42. *phSession = (HANDLE) pSessionCont;
  43. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  44. return (Error);
  45. lock:
  46. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  47. error:
  48. if (pSessionCont) {
  49. FreeSessionCont(pSessionCont);
  50. }
  51. *phSession = NULL;
  52. return (Error);
  53. }
  54. DWORD
  55. CreateSessionCont(
  56. PSESSION_CONTAINER * ppSessionCont
  57. )
  58. {
  59. DWORD dwError = 0;
  60. PSESSION_CONTAINER pSessionCont = NULL;
  61. pSessionCont = LocalAlloc(LMEM_ZEROINIT, sizeof(SESSION_CONTAINER));
  62. if (!pSessionCont) {
  63. dwError = ERROR_OUTOFMEMORY;
  64. BAIL_ON_WIN32_ERROR(dwError);
  65. }
  66. memset(pSessionCont, 0, sizeof(SESSION_CONTAINER));
  67. *ppSessionCont = pSessionCont;
  68. return (dwError);
  69. error:
  70. *ppSessionCont = NULL;
  71. return (dwError);
  72. }
  73. DWORD
  74. IniOpenWZCDbLogSession(
  75. PSESSION_CONTAINER pSessionCont
  76. )
  77. /*++
  78. Routine Description:
  79. This function opens a new session for a client.
  80. Arguments:
  81. pSessionCont - Pointer to hold the opened session data.
  82. Return Value:
  83. Windows Error.
  84. --*/
  85. {
  86. JET_ERR JetError = JET_errSuccess;
  87. DWORD Error = 0;
  88. char DBFilePath[MAX_PATH];
  89. char * pc = NULL;
  90. JET_SESID * pMyJetServerSession = NULL;
  91. JET_DBID * pMyJetDatabaseHandle = NULL;
  92. JET_TABLEID * pMyClientTableHandle = NULL;
  93. memset(DBFilePath, 0, sizeof(CHAR)*MAX_PATH);
  94. pMyJetServerSession = (JET_SESID *) &(pSessionCont->SessionID);
  95. pMyJetDatabaseHandle = (JET_DBID *) &(pSessionCont->DbID);
  96. pMyClientTableHandle = (JET_TABLEID *) &(pSessionCont->TableID);
  97. //
  98. // Create database file name.
  99. //
  100. pc = getenv(DBFILENAMEPREFIX);
  101. if (pc != NULL) {
  102. if (lstrlenA(pc) >
  103. MAX_PATH - lstrlenA(DBFILENAMESUFFIX) - lstrlenA(DBFILENAME) -1)
  104. {
  105. Error = ERROR_FILENAME_EXCED_RANGE;
  106. BAIL_ON_WIN32_ERROR(Error);
  107. }
  108. strcpy(DBFilePath, pc);
  109. strcat(DBFilePath, DBFILENAMESUFFIX);
  110. }
  111. else {
  112. strcpy(DBFilePath, DBFILENAMESUFFIX);
  113. }
  114. strcat(DBFilePath, DBFILENAME);
  115. //
  116. // Convert name to ANSI.
  117. //
  118. OemToCharA(DBFilePath, DBFilePath);
  119. JetError = JetBeginSession(
  120. gJetInstance,
  121. pMyJetServerSession,
  122. "admin",
  123. ""
  124. );
  125. Error = WZCMapJetError(JetError, "JetBeginSession");
  126. BAIL_ON_WIN32_ERROR(Error);
  127. JetError = JetOpenDatabase(
  128. *pMyJetServerSession,
  129. DBFilePath,
  130. 0,
  131. pMyJetDatabaseHandle,
  132. 0
  133. );
  134. Error = WZCMapJetError(JetError, "JetOpenDatabase");
  135. BAIL_ON_WIN32_ERROR(Error);
  136. JetError = JetOpenTable(
  137. *pMyJetServerSession,
  138. *pMyJetDatabaseHandle,
  139. LOG_RECORD_TABLE,
  140. NULL,
  141. 0,
  142. 0,
  143. pMyClientTableHandle
  144. );
  145. Error = WZCMapJetError(JetError, "JetOpenTable");
  146. BAIL_ON_WIN32_ERROR(Error);
  147. return (Error);
  148. error:
  149. if (pMyJetServerSession && *pMyJetServerSession) {
  150. JetError = JetEndSession(*pMyJetServerSession, 0);
  151. WZCMapJetError(JetError, "JetEndSession");
  152. *pMyJetServerSession = 0;
  153. }
  154. return (Error);
  155. }
  156. VOID
  157. FreeSessionCont(
  158. PSESSION_CONTAINER pSessionCont
  159. )
  160. {
  161. if (pSessionCont) {
  162. LocalFree(pSessionCont);
  163. }
  164. return;
  165. }
  166. DWORD
  167. CloseWZCDbLogSession(
  168. HANDLE hSession
  169. )
  170. /*++
  171. Routine Description:
  172. This function ends a session for a client.
  173. Arguments:
  174. hSession - Handle for the session to end.
  175. Return Value:
  176. Windows Error.
  177. --*/
  178. {
  179. DWORD Error = 0;
  180. PSESSION_CONTAINER pSessionCont = NULL;
  181. AcquireExclusiveLock(gpWZCDbSessionRWLock);
  182. Error = GetSessionContainer(hSession, &pSessionCont);
  183. BAIL_ON_LOCK_ERROR(Error);
  184. Error = IniCloseWZCDbLogSession(pSessionCont);
  185. BAIL_ON_LOCK_ERROR(Error);
  186. RemoveSessionCont(
  187. pSessionCont
  188. );
  189. FreeSessionCont(pSessionCont);
  190. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  191. return (Error);
  192. lock:
  193. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  194. return (Error);
  195. }
  196. DWORD
  197. GetSessionContainer(
  198. HANDLE hSession,
  199. PSESSION_CONTAINER * ppSessionCont
  200. )
  201. {
  202. DWORD Error = ERROR_INVALID_HANDLE;
  203. PSESSION_CONTAINER * ppTemp = NULL;
  204. PSESSION_CONTAINER pSessionCont = (PSESSION_CONTAINER) hSession;
  205. *ppSessionCont = NULL;
  206. ppTemp = &gpSessionCont;
  207. while (*ppTemp) {
  208. if (*ppTemp == pSessionCont) {
  209. break;
  210. }
  211. ppTemp = &((*ppTemp)->pNext);
  212. }
  213. if (*ppTemp) {
  214. *ppSessionCont = *ppTemp;
  215. Error = ERROR_SUCCESS;
  216. }
  217. return (Error);
  218. }
  219. DWORD
  220. IniCloseWZCDbLogSession(
  221. PSESSION_CONTAINER pSessionCont
  222. )
  223. /*++
  224. Routine Description:
  225. This function ends a session for a client.
  226. Arguments:
  227. pSessionCont - Pointer to the session data for the session to end.
  228. Return Value:
  229. Windows Error.
  230. --*/
  231. {
  232. JET_ERR JetError = JET_errSuccess;
  233. DWORD Error = 0;
  234. JET_SESID * pMyJetServerSession = NULL;
  235. pMyJetServerSession = (JET_SESID *) &(pSessionCont->SessionID);
  236. if (*pMyJetServerSession) {
  237. JetError = JetEndSession(*pMyJetServerSession, 0);
  238. Error = WZCMapJetError(JetError, "JetEndSession");
  239. BAIL_ON_WIN32_ERROR(Error);
  240. *pMyJetServerSession = 0;
  241. }
  242. error:
  243. return (Error);
  244. }
  245. VOID
  246. RemoveSessionCont(
  247. PSESSION_CONTAINER pSessionCont
  248. )
  249. {
  250. PSESSION_CONTAINER * ppTemp = NULL;
  251. ppTemp = &gpSessionCont;
  252. while (*ppTemp) {
  253. if (*ppTemp == pSessionCont) {
  254. break;
  255. }
  256. ppTemp = &((*ppTemp)->pNext);
  257. }
  258. if (*ppTemp) {
  259. *ppTemp = pSessionCont->pNext;
  260. }
  261. return;
  262. }
  263. VOID
  264. DestroySessionContList(
  265. PSESSION_CONTAINER pSessionContList
  266. )
  267. {
  268. PSESSION_CONTAINER pSessionCont = NULL;
  269. PSESSION_CONTAINER pTemp = NULL;
  270. pSessionCont = pSessionContList;
  271. while (pSessionCont) {
  272. pTemp = pSessionCont;
  273. pSessionCont = pSessionCont->pNext;
  274. (VOID) IniCloseWZCDbLogSession(pTemp);
  275. FreeSessionCont(pTemp);
  276. }
  277. }
  278. DWORD
  279. WZCOpenAppendSession(
  280. PSESSION_CONTAINER pSessionCont
  281. )
  282. /*++
  283. Routine Description:
  284. This function tries to open a database in DBFILENAME and its table.
  285. If the database does not exist, it creates the database and creates
  286. the table as well.
  287. If just the table does not exist, it creates the table and opens it.
  288. Arguments:
  289. pSessionCont - Pointer to the session container.
  290. Return Value:
  291. Windows Error.
  292. --*/
  293. {
  294. DWORD dwError = 0;
  295. DWORD dwTempIdx = 0;
  296. DWORD dwReqSize = 0;
  297. BOOL bInitializedDb = FALSE;
  298. JET_SESID * pMyJetServerSession = NULL;
  299. JET_DBID * pMyJetDatabaseHandle = NULL;
  300. JET_TABLEID * pMyClientTableHandle = NULL;
  301. JET_ERR JetError = JET_errSuccess;
  302. pMyJetServerSession = (JET_SESID *) &(pSessionCont->SessionID);
  303. pMyJetDatabaseHandle = (JET_DBID *) &(pSessionCont->DbID);
  304. pMyClientTableHandle = (JET_TABLEID *) &(pSessionCont->TableID);
  305. gdwCurrentHeader = 1;
  306. gdwCurrentTableSize = 0;
  307. gdwCurrentMaxRecordID = 0;
  308. dwError = WZCInitializeDatabase(
  309. pMyJetServerSession
  310. );
  311. BAIL_ON_WIN32_ERROR(dwError);
  312. bInitializedDb = TRUE;
  313. dwError = WZCCreateDatabase(
  314. *pMyJetServerSession,
  315. 0,
  316. pMyJetDatabaseHandle,
  317. 0
  318. );
  319. if (!dwError) {
  320. dwError = WZCGetTableDataHandle(
  321. pMyJetServerSession,
  322. pMyJetDatabaseHandle,
  323. pMyClientTableHandle
  324. );
  325. BAIL_ON_WIN32_ERROR(dwError);
  326. return (ERROR_SUCCESS);
  327. }
  328. //
  329. // Database already exists.
  330. //
  331. dwError = WZCOpenDatabase(
  332. *pMyJetServerSession,
  333. 0,
  334. pMyJetDatabaseHandle,
  335. 0
  336. );
  337. BAIL_ON_WIN32_ERROR(dwError);
  338. dwError = WZCGetTableDataHandle(
  339. pMyJetServerSession,
  340. pMyJetDatabaseHandle,
  341. pMyClientTableHandle
  342. );
  343. //
  344. // If the table does not have correct columns, delete it and create a
  345. // new table.
  346. //
  347. if (dwError != JET_errColumnNotFound) {
  348. BAIL_ON_WIN32_ERROR(dwError);
  349. }
  350. else {
  351. JetError = JetCloseTable(
  352. *pMyJetServerSession,
  353. *pMyClientTableHandle
  354. );
  355. dwError = WZCMapJetError(JetError, "JetCloseTable");
  356. BAIL_ON_WIN32_ERROR(dwError);
  357. *pMyClientTableHandle = 0;
  358. JetError = JetDeleteTable(
  359. *pMyJetServerSession,
  360. *pMyJetDatabaseHandle,
  361. LOG_RECORD_TABLE
  362. );
  363. dwError = WZCMapJetError(JetError, "JetDeleteTable");
  364. BAIL_ON_WIN32_ERROR(dwError);
  365. dwError = WZCGetTableDataHandle(
  366. pMyJetServerSession,
  367. pMyJetDatabaseHandle,
  368. pMyClientTableHandle
  369. );
  370. BAIL_ON_WIN32_ERROR(dwError);
  371. }
  372. //
  373. // Initialize current table size and current header.
  374. // Find out total number of records in table.
  375. //
  376. JetError = JetSetCurrentIndex(
  377. *pMyJetServerSession,
  378. *pMyClientTableHandle,
  379. gLogRecordTable[RECORD_IDX_IDX].ColName
  380. );
  381. dwError = WZCMapJetError(JetError, "JetSetCurrentIndex");
  382. BAIL_ON_WIN32_ERROR(dwError);
  383. //
  384. // Jump to the last record.
  385. //
  386. JetError = JetMove(
  387. *pMyJetServerSession,
  388. *pMyClientTableHandle,
  389. JET_MoveLast,
  390. 0
  391. );
  392. dwError = WZCMapJetError(JetError, "JetMove");
  393. if (dwError != ERROR_SUCCESS) {
  394. dwError = ERROR_SUCCESS;
  395. return (dwError);
  396. }
  397. //
  398. // Check if the logical end of table has been hit.
  399. //
  400. dwError = WZCJetGetValue(
  401. *pMyJetServerSession,
  402. *pMyClientTableHandle,
  403. gLogRecordTable[RECORD_IDX_IDX].ColHandle,
  404. &dwTempIdx,
  405. sizeof(dwTempIdx),
  406. &dwReqSize
  407. );
  408. BAIL_ON_WIN32_ERROR(dwError);
  409. gdwCurrentTableSize = dwTempIdx;
  410. //
  411. // Find out the current header.
  412. //
  413. JetError = JetSetCurrentIndex(
  414. *pMyJetServerSession,
  415. *pMyClientTableHandle,
  416. gLogRecordTable[TIMESTAMP_IDX].ColName
  417. );
  418. dwError = WZCMapJetError(JetError, "JetSetCurrentIndex");
  419. BAIL_ON_WIN32_ERROR(dwError);
  420. JetError = JetMove(
  421. *pMyJetServerSession,
  422. *pMyClientTableHandle,
  423. JET_MoveFirst,
  424. 0
  425. );
  426. dwError = WZCMapJetError(JetError, "JetMove");
  427. BAIL_ON_WIN32_ERROR(dwError);
  428. dwError = WZCJetGetValue(
  429. *pMyJetServerSession,
  430. *pMyClientTableHandle,
  431. gLogRecordTable[RECORD_IDX_IDX].ColHandle,
  432. &dwTempIdx,
  433. sizeof(dwTempIdx),
  434. &dwReqSize
  435. );
  436. BAIL_ON_WIN32_ERROR(dwError);
  437. gdwCurrentHeader = dwTempIdx;
  438. return (dwError);
  439. error:
  440. if (bInitializedDb) {
  441. WZCCloseAppendSession(pSessionCont);
  442. }
  443. return (dwError);
  444. }
  445. DWORD
  446. WZCCloseAppendSession(
  447. PSESSION_CONTAINER pSessionCont
  448. )
  449. /*++
  450. Routine Description:
  451. This function tries to close the database and the append session.
  452. Arguments:
  453. pSessionCont - Pointer to the session container.
  454. Return Value:
  455. Windows Error.
  456. --*/
  457. {
  458. DWORD dwError = 0;
  459. JET_ERR JetError = JET_errSuccess;
  460. JET_SESID * pMyJetServerSession = NULL;
  461. pMyJetServerSession = (JET_SESID *) &(pSessionCont->SessionID);
  462. if (*pMyJetServerSession != 0) {
  463. JetError = JetEndSession(*pMyJetServerSession, 0);
  464. dwError = WZCMapJetError(JetError, "JetEndSession");
  465. *pMyJetServerSession = 0;
  466. }
  467. JetError = JetTerm2(gJetInstance, JET_bitTermComplete);
  468. gJetInstance = 0;
  469. dwError = WZCMapJetError(JetError, "JetTerm/JetTerm2");
  470. return (dwError);
  471. }
  472. DWORD
  473. AddWZCDbLogRecord(
  474. LPWSTR pServerName,
  475. DWORD dwVersion,
  476. PWZC_DB_RECORD pWZCRecord,
  477. LPVOID pvReserved
  478. )
  479. /*++
  480. Routine Description:
  481. This function appends a new record into the table.
  482. Arguments:
  483. pServerName - Pointer to the server name.
  484. pWZCRecord - Pointer to the record to be appended.
  485. Return Value:
  486. Windows Error.
  487. --*/
  488. {
  489. DWORD Error = 0;
  490. BOOL bStartedTransaction = FALSE;
  491. JET_ERR JetError = JET_errSuccess;
  492. SYSTEMTIME stLocalTime;
  493. BOOL bNewRecord = TRUE;
  494. DWORD dwTempKey = 0;
  495. JET_SESID * pMyJetServerSession = NULL;
  496. JET_DBID * pMyJetDatabaseHandle = NULL;
  497. JET_TABLEID * pMyClientTableHandle = NULL;
  498. DWORD LocalError = 0;
  499. //
  500. // Get current time as time stamp for the record.
  501. //
  502. GetLocalTime(&stLocalTime);
  503. SystemTimeToFileTime(&stLocalTime, &(pWZCRecord->timestamp));
  504. AcquireExclusiveLock(gpWZCDbSessionRWLock);
  505. pMyJetServerSession = (JET_SESID *) &(gpAppendSessionCont->SessionID);
  506. pMyJetDatabaseHandle = (JET_DBID *) &(gpAppendSessionCont->DbID);
  507. pMyClientTableHandle = (JET_TABLEID *) &(gpAppendSessionCont->TableID);
  508. if (!(*pMyClientTableHandle)) {
  509. Error = WZCGetTableDataHandle(
  510. pMyJetServerSession,
  511. pMyJetDatabaseHandle,
  512. pMyClientTableHandle
  513. );
  514. BAIL_ON_LOCK_ERROR(Error);
  515. }
  516. //
  517. // Insert a new record or replace a old one.
  518. //
  519. if (gdwCurrentTableSize < MAX_RECORD_NUM) {
  520. bNewRecord = TRUE;
  521. }
  522. else {
  523. bNewRecord = FALSE;
  524. dwTempKey = gdwCurrentHeader;
  525. }
  526. Error = WZCJetBeginTransaction(*pMyJetServerSession);
  527. BAIL_ON_LOCK_ERROR(Error);
  528. bStartedTransaction = TRUE;
  529. //
  530. // Prepare for insertion/replacement.
  531. //
  532. Error = WZCJetPrepareUpdate(
  533. *pMyJetServerSession,
  534. *pMyClientTableHandle,
  535. gLogRecordTable[RECORD_IDX_IDX].ColName,
  536. &dwTempKey,
  537. sizeof(dwTempKey),
  538. bNewRecord
  539. );
  540. BAIL_ON_LOCK_ERROR(Error);
  541. Error = WZCJetSetValue(
  542. *pMyJetServerSession,
  543. *pMyClientTableHandle,
  544. gLogRecordTable[RECORD_ID_IDX].ColHandle,
  545. &(gdwCurrentMaxRecordID),
  546. sizeof(gdwCurrentMaxRecordID)
  547. );
  548. BAIL_ON_LOCK_ERROR(Error);
  549. Error = WZCJetSetValue(
  550. *pMyJetServerSession,
  551. *pMyClientTableHandle,
  552. gLogRecordTable[COMPONENT_ID_IDX].ColHandle,
  553. &(pWZCRecord->componentid),
  554. sizeof(pWZCRecord->componentid)
  555. );
  556. BAIL_ON_LOCK_ERROR(Error);
  557. Error = WZCJetSetValue(
  558. *pMyJetServerSession,
  559. *pMyClientTableHandle,
  560. gLogRecordTable[CATEGORY_IDX].ColHandle,
  561. &(pWZCRecord->category),
  562. sizeof(pWZCRecord->category)
  563. );
  564. BAIL_ON_LOCK_ERROR(Error);
  565. Error = WZCJetSetValue(
  566. *pMyJetServerSession,
  567. *pMyClientTableHandle,
  568. gLogRecordTable[TIMESTAMP_IDX].ColHandle,
  569. &(pWZCRecord->timestamp),
  570. sizeof(pWZCRecord->timestamp)
  571. );
  572. BAIL_ON_LOCK_ERROR(Error);
  573. Error = WZCJetSetValue(
  574. *pMyJetServerSession,
  575. *pMyClientTableHandle,
  576. gLogRecordTable[MESSAGE_IDX].ColHandle,
  577. (pWZCRecord->message).pData,
  578. (pWZCRecord->message).dwDataLen
  579. );
  580. BAIL_ON_LOCK_ERROR(Error);
  581. Error = WZCJetSetValue(
  582. *pMyJetServerSession,
  583. *pMyClientTableHandle,
  584. gLogRecordTable[INTERFACE_MAC_IDX].ColHandle,
  585. (pWZCRecord->localmac).pData,
  586. (pWZCRecord->localmac).dwDataLen
  587. );
  588. BAIL_ON_LOCK_ERROR(Error);
  589. Error = WZCJetSetValue(
  590. *pMyJetServerSession,
  591. *pMyClientTableHandle,
  592. gLogRecordTable[DEST_MAC_IDX].ColHandle,
  593. (pWZCRecord->remotemac).pData,
  594. (pWZCRecord->remotemac).dwDataLen
  595. );
  596. BAIL_ON_LOCK_ERROR(Error);
  597. Error = WZCJetSetValue(
  598. *pMyJetServerSession,
  599. *pMyClientTableHandle,
  600. gLogRecordTable[SSID_IDX].ColHandle,
  601. (pWZCRecord->ssid).pData,
  602. (pWZCRecord->ssid).dwDataLen
  603. );
  604. BAIL_ON_LOCK_ERROR(Error);
  605. Error = WZCJetSetValue(
  606. *pMyJetServerSession,
  607. *pMyClientTableHandle,
  608. gLogRecordTable[CONTEXT_IDX].ColHandle,
  609. (pWZCRecord->context).pData,
  610. (pWZCRecord->context).dwDataLen
  611. );
  612. BAIL_ON_LOCK_ERROR(Error);
  613. JetError = JetUpdate(
  614. *pMyJetServerSession,
  615. *pMyClientTableHandle,
  616. NULL,
  617. 0,
  618. NULL
  619. );
  620. Error = WZCMapJetError(JetError, "AddWZCDbLogRecord: JetUpdate");
  621. BAIL_ON_LOCK_ERROR(Error);
  622. //
  623. // Commit changes.
  624. //
  625. Error = WZCJetCommitTransaction(
  626. *pMyJetServerSession,
  627. *pMyClientTableHandle
  628. );
  629. BAIL_ON_LOCK_ERROR(Error);
  630. if (gdwCurrentTableSize < MAX_RECORD_NUM) {
  631. gdwCurrentTableSize++;
  632. }
  633. else {
  634. gdwCurrentHeader = (gdwCurrentHeader + 1) > MAX_RECORD_NUM ?
  635. 1 : (gdwCurrentHeader + 1);
  636. }
  637. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  638. return (Error);
  639. lock:
  640. //
  641. // If the transaction has been started, then roll back to the
  642. // start point, so that the database does not become inconsistent.
  643. //
  644. if (bStartedTransaction == TRUE) {
  645. LocalError = WZCJetRollBack(*pMyJetServerSession);
  646. }
  647. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  648. return (Error);
  649. }
  650. DWORD
  651. EnumWZCDbLogRecords(
  652. HANDLE hSession,
  653. PWZC_DB_RECORD pTemplateRecord,
  654. PBOOL pbEnumFromStart,
  655. DWORD dwPreferredNumEntries,
  656. PWZC_DB_RECORD * ppWZCRecords,
  657. LPDWORD pdwNumRecords,
  658. LPVOID pvReserved
  659. )
  660. {
  661. DWORD Error = 0;
  662. PSESSION_CONTAINER pSessionCont = NULL;
  663. AcquireSharedLock(gpWZCDbSessionRWLock);
  664. Error = GetSessionContainer(hSession, &pSessionCont);
  665. BAIL_ON_LOCK_ERROR(Error);
  666. if (pTemplateRecord) {
  667. Error = ERROR_NOT_SUPPORTED;
  668. }
  669. else {
  670. Error = IniEnumWZCDbLogRecords(
  671. pSessionCont,
  672. pbEnumFromStart,
  673. dwPreferredNumEntries,
  674. ppWZCRecords,
  675. pdwNumRecords
  676. );
  677. }
  678. BAIL_ON_LOCK_ERROR(Error);
  679. ReleaseSharedLock(gpWZCDbSessionRWLock);
  680. return (Error);
  681. lock:
  682. ReleaseSharedLock(gpWZCDbSessionRWLock);
  683. return (Error);
  684. }
  685. DWORD
  686. IniEnumWZCDbLogRecords(
  687. PSESSION_CONTAINER pSessionCont,
  688. PBOOL pbEnumFromStart,
  689. DWORD dwPreferredNumEntries,
  690. PWZC_DB_RECORD * ppWZCRecords,
  691. LPDWORD pdwNumRecords
  692. )
  693. {
  694. DWORD dwError = 0;
  695. DWORD dwNumToEnum = 0;
  696. PWZC_DB_RECORD pWZCRecords = NULL;
  697. JET_SESID * pMyJetServerSession = NULL;
  698. JET_DBID * pMyJetDatabaseHandle = NULL;
  699. JET_TABLEID * pMyClientTableHandle = NULL;
  700. DWORD i = 0;
  701. PWZC_DB_RECORD pCurWZCRecord = NULL;
  702. JET_ERR JetError = JET_errSuccess;
  703. DWORD dwReqSize = 0;
  704. char cTempBuf[MAX_RAW_DATA_SIZE];
  705. DWORD dwCurIndex = 0;
  706. BOOL bEnumFromStart = FALSE;
  707. if (!dwPreferredNumEntries ||
  708. (dwPreferredNumEntries > MAX_RECORD_ENUM_COUNT)) {
  709. dwNumToEnum = MAX_RECORD_ENUM_COUNT;
  710. }
  711. else {
  712. dwNumToEnum = dwPreferredNumEntries;
  713. }
  714. pWZCRecords = RpcCAlloc(sizeof(WZC_DB_RECORD)*dwNumToEnum);
  715. if (!pWZCRecords) {
  716. dwError = ERROR_OUTOFMEMORY;
  717. BAIL_ON_WIN32_ERROR(dwError);
  718. }
  719. memset(pWZCRecords, 0, sizeof(WZC_DB_RECORD)*dwNumToEnum);
  720. pMyJetServerSession = (JET_SESID *) &(pSessionCont->SessionID);
  721. pMyJetDatabaseHandle = (JET_DBID *) &(pSessionCont->DbID);
  722. pMyClientTableHandle = (JET_TABLEID *) &(pSessionCont->TableID);
  723. if (!(*pMyClientTableHandle)) {
  724. JetError = JetOpenTable(
  725. *pMyJetServerSession,
  726. *pMyJetDatabaseHandle,
  727. LOG_RECORD_TABLE,
  728. NULL,
  729. 0,
  730. 0,
  731. pMyClientTableHandle
  732. );
  733. dwError = WZCMapJetError(JetError, "JetOpenTable");
  734. BAIL_ON_WIN32_ERROR(dwError);
  735. }
  736. bEnumFromStart = *pbEnumFromStart;
  737. if (bEnumFromStart) {
  738. dwError = WZCJetPrepareSearch(
  739. *pMyJetServerSession,
  740. *pMyClientTableHandle,
  741. gLogRecordTable[TIMESTAMP_IDX].ColName,
  742. bEnumFromStart,
  743. NULL,
  744. 0
  745. );
  746. BAIL_ON_WIN32_ERROR(dwError);
  747. bEnumFromStart = FALSE;
  748. }
  749. for (i = 0; i < dwNumToEnum; i++) {
  750. pCurWZCRecord = (pWZCRecords + i);
  751. dwError = WZCJetGetValue(
  752. *pMyJetServerSession,
  753. *pMyClientTableHandle,
  754. gLogRecordTable[RECORD_ID_IDX].ColHandle,
  755. &(pCurWZCRecord->recordid),
  756. sizeof(pCurWZCRecord->recordid),
  757. &dwReqSize
  758. );
  759. BAIL_ON_WIN32_ERROR(dwError);
  760. dwError = WZCJetGetValue(
  761. *pMyJetServerSession,
  762. *pMyClientTableHandle,
  763. gLogRecordTable[COMPONENT_ID_IDX].ColHandle,
  764. &(pCurWZCRecord->componentid),
  765. sizeof(pCurWZCRecord->componentid),
  766. &dwReqSize
  767. );
  768. BAIL_ON_WIN32_ERROR(dwError);
  769. dwError = WZCJetGetValue(
  770. *pMyJetServerSession,
  771. *pMyClientTableHandle,
  772. gLogRecordTable[CATEGORY_IDX].ColHandle,
  773. &(pCurWZCRecord->category),
  774. sizeof(pCurWZCRecord->category),
  775. &dwReqSize
  776. );
  777. BAIL_ON_WIN32_ERROR(dwError);
  778. dwError = WZCJetGetValue(
  779. *pMyJetServerSession,
  780. *pMyClientTableHandle,
  781. gLogRecordTable[TIMESTAMP_IDX].ColHandle,
  782. &(pCurWZCRecord->timestamp),
  783. sizeof(pCurWZCRecord->timestamp),
  784. &dwReqSize
  785. );
  786. BAIL_ON_WIN32_ERROR(dwError);
  787. dwReqSize = 0;
  788. dwError = WZCJetGetValue(
  789. *pMyJetServerSession,
  790. *pMyClientTableHandle,
  791. gLogRecordTable[MESSAGE_IDX].ColHandle,
  792. cTempBuf,
  793. MAX_RAW_DATA_SIZE,
  794. &dwReqSize
  795. );
  796. BAIL_ON_WIN32_ERROR(dwError);
  797. if (dwReqSize > 0) {
  798. (pCurWZCRecord->message).pData = RpcCAlloc(dwReqSize);
  799. if (!((pCurWZCRecord->message).pData)) {
  800. dwError = ERROR_OUTOFMEMORY;
  801. BAIL_ON_WIN32_ERROR(dwError);
  802. }
  803. memcpy((pCurWZCRecord->message).pData, cTempBuf, dwReqSize);
  804. (pCurWZCRecord->message).dwDataLen = dwReqSize;
  805. }
  806. dwReqSize = 0;
  807. dwError = WZCJetGetValue(
  808. *pMyJetServerSession,
  809. *pMyClientTableHandle,
  810. gLogRecordTable[INTERFACE_MAC_IDX].ColHandle,
  811. cTempBuf,
  812. MAX_RAW_DATA_SIZE,
  813. &dwReqSize
  814. );
  815. BAIL_ON_WIN32_ERROR(dwError);
  816. if (dwReqSize > 0) {
  817. (pCurWZCRecord->localmac).pData = RpcCAlloc(dwReqSize);
  818. if (!((pCurWZCRecord->localmac).pData)) {
  819. dwError = ERROR_OUTOFMEMORY;
  820. BAIL_ON_WIN32_ERROR(dwError);
  821. }
  822. memcpy((pCurWZCRecord->localmac).pData, cTempBuf, dwReqSize);
  823. (pCurWZCRecord->localmac).dwDataLen = dwReqSize;
  824. }
  825. dwReqSize = 0;
  826. dwError = WZCJetGetValue(
  827. *pMyJetServerSession,
  828. *pMyClientTableHandle,
  829. gLogRecordTable[DEST_MAC_IDX].ColHandle,
  830. cTempBuf,
  831. MAX_RAW_DATA_SIZE,
  832. &dwReqSize
  833. );
  834. BAIL_ON_WIN32_ERROR(dwError);
  835. if (dwReqSize > 0) {
  836. (pCurWZCRecord->remotemac).pData = RpcCAlloc(dwReqSize);
  837. if (!((pCurWZCRecord->remotemac).pData)) {
  838. dwError = ERROR_OUTOFMEMORY;
  839. BAIL_ON_WIN32_ERROR(dwError);
  840. }
  841. memcpy((pCurWZCRecord->remotemac).pData, cTempBuf, dwReqSize);
  842. (pCurWZCRecord->remotemac).dwDataLen = dwReqSize;
  843. }
  844. dwReqSize = 0;
  845. dwError = WZCJetGetValue(
  846. *pMyJetServerSession,
  847. *pMyClientTableHandle,
  848. gLogRecordTable[SSID_IDX].ColHandle,
  849. cTempBuf,
  850. MAX_RAW_DATA_SIZE,
  851. &dwReqSize
  852. );
  853. BAIL_ON_WIN32_ERROR(dwError);
  854. if (dwReqSize > 0) {
  855. (pCurWZCRecord->ssid).pData = RpcCAlloc(dwReqSize);
  856. if (!((pCurWZCRecord->ssid).pData)) {
  857. dwError = ERROR_OUTOFMEMORY;
  858. BAIL_ON_WIN32_ERROR(dwError);
  859. }
  860. memcpy((pCurWZCRecord->ssid).pData, cTempBuf, dwReqSize);
  861. (pCurWZCRecord->ssid).dwDataLen = dwReqSize;
  862. }
  863. dwReqSize = 0;
  864. dwError = WZCJetGetValue(
  865. *pMyJetServerSession,
  866. *pMyClientTableHandle,
  867. gLogRecordTable[CONTEXT_IDX].ColHandle,
  868. cTempBuf,
  869. MAX_RAW_DATA_SIZE,
  870. &dwReqSize
  871. );
  872. BAIL_ON_WIN32_ERROR(dwError);
  873. if (dwReqSize > 0) {
  874. (pCurWZCRecord->context).pData = RpcCAlloc(dwReqSize);
  875. if (!((pCurWZCRecord->context).pData)) {
  876. dwError = ERROR_OUTOFMEMORY;
  877. BAIL_ON_WIN32_ERROR(dwError);
  878. }
  879. memcpy((pCurWZCRecord->context).pData, cTempBuf, dwReqSize);
  880. (pCurWZCRecord->context).dwDataLen = dwReqSize;
  881. }
  882. JetError = JetMove(
  883. *pMyJetServerSession,
  884. *pMyClientTableHandle,
  885. JET_MoveNext,
  886. 0
  887. );
  888. //
  889. // Don't bail from here as the end of the table (logical or physical)
  890. // is caught in the next call.
  891. //
  892. dwError = WZCJetGetValue(
  893. *pMyJetServerSession,
  894. *pMyClientTableHandle,
  895. gLogRecordTable[RECORD_IDX_IDX].ColHandle,
  896. &dwCurIndex,
  897. sizeof(dwCurIndex),
  898. &dwReqSize
  899. );
  900. if (dwCurIndex == gdwCurrentHeader || dwError != ERROR_SUCCESS) {
  901. dwError = ERROR_NO_MORE_ITEMS;
  902. i++;
  903. break;
  904. }
  905. }
  906. *pbEnumFromStart = bEnumFromStart;
  907. *ppWZCRecords = pWZCRecords;
  908. *pdwNumRecords = i;
  909. return (dwError);
  910. error:
  911. if (pWZCRecords) {
  912. FreeWZCRecords(pWZCRecords, dwNumToEnum);
  913. }
  914. *ppWZCRecords = NULL;
  915. *pdwNumRecords = 0;
  916. return (dwError);
  917. }
  918. VOID
  919. FreeWZCRecords(
  920. PWZC_DB_RECORD pWZCRecords,
  921. DWORD dwNumRecords
  922. )
  923. {
  924. DWORD i = 0;
  925. if (pWZCRecords) {
  926. for (i = 0; i < dwNumRecords; i++) {
  927. if (pWZCRecords[i].message.pData) {
  928. RpcFree(pWZCRecords[i].message.pData);
  929. }
  930. if (pWZCRecords[i].localmac.pData) {
  931. RpcFree(pWZCRecords[i].localmac.pData);
  932. }
  933. if (pWZCRecords[i].remotemac.pData) {
  934. RpcFree(pWZCRecords[i].remotemac.pData);
  935. }
  936. if (pWZCRecords[i].ssid.pData) {
  937. RpcFree(pWZCRecords[i].ssid.pData);
  938. }
  939. if (pWZCRecords[i].context.pData) {
  940. RpcFree(pWZCRecords[i].context.pData);
  941. }
  942. }
  943. RpcFree(pWZCRecords);
  944. }
  945. return;
  946. }
  947. DWORD
  948. FlushWZCDbLog(
  949. HANDLE hSession
  950. )
  951. {
  952. DWORD Error = 0;
  953. PSESSION_CONTAINER pSessionCont = NULL;
  954. AcquireExclusiveLock(gpWZCDbSessionRWLock);
  955. Error = GetSessionContainer(hSession, &pSessionCont);
  956. BAIL_ON_LOCK_ERROR(Error);
  957. Error = IniFlushWZCDbLog();
  958. BAIL_ON_LOCK_ERROR(Error);
  959. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  960. return (Error);
  961. lock:
  962. ReleaseExclusiveLock(gpWZCDbSessionRWLock);
  963. return (Error);
  964. }
  965. DWORD
  966. IniFlushWZCDbLog(
  967. )
  968. {
  969. DWORD dwError = ERROR_SUCCESS;
  970. DWORD JetError = JET_errSuccess;
  971. JET_SESID * pMyJetServerSession = NULL;
  972. JET_DBID * pMyJetDatabaseHandle = NULL;
  973. JET_TABLEID * pMyClientTableHandle = NULL;
  974. pMyJetServerSession = (JET_SESID *) &(gpAppendSessionCont->SessionID);
  975. pMyJetDatabaseHandle = (JET_DBID *) &(gpAppendSessionCont->DbID);
  976. pMyClientTableHandle = (JET_TABLEID *) &(gpAppendSessionCont->TableID);
  977. dwError = CloseAllTableSessions(gpSessionCont);
  978. BAIL_ON_WIN32_ERROR(dwError);
  979. JetError = JetCloseTable(
  980. *pMyJetServerSession,
  981. *pMyClientTableHandle
  982. );
  983. dwError = WZCMapJetError(JetError, "JetCloseTable");
  984. BAIL_ON_WIN32_ERROR(dwError);
  985. *pMyClientTableHandle = 0;
  986. JetError = JetDeleteTable(
  987. *pMyJetServerSession,
  988. *pMyJetDatabaseHandle,
  989. LOG_RECORD_TABLE
  990. );
  991. dwError = WZCMapJetError(JetError, "JetDeleteTable");
  992. BAIL_ON_WIN32_ERROR(dwError);
  993. gdwCurrentHeader = 1;
  994. gdwCurrentTableSize = 0;
  995. gdwCurrentMaxRecordID = 0;
  996. dwError = WZCGetTableDataHandle(
  997. pMyJetServerSession,
  998. pMyJetDatabaseHandle,
  999. pMyClientTableHandle
  1000. );
  1001. BAIL_ON_WIN32_ERROR(dwError);
  1002. dwError = OpenAllTableSessions(gpSessionCont);
  1003. BAIL_ON_WIN32_ERROR(dwError);
  1004. return (dwError);
  1005. error:
  1006. return (dwError);
  1007. }
  1008. DWORD
  1009. CloseAllTableSessions(
  1010. PSESSION_CONTAINER pSessionContList
  1011. )
  1012. {
  1013. DWORD dwError = ERROR_SUCCESS;
  1014. DWORD JetError = JET_errSuccess;
  1015. PSESSION_CONTAINER pSessionCont = NULL;
  1016. pSessionCont = pSessionContList;
  1017. while (pSessionCont) {
  1018. JetError = JetCloseTable(
  1019. pSessionCont->SessionID,
  1020. pSessionCont->TableID
  1021. );
  1022. dwError = WZCMapJetError(JetError, "JetCloseTable");
  1023. BAIL_ON_WIN32_ERROR(dwError);
  1024. pSessionCont->TableID = 0;
  1025. pSessionCont = pSessionCont->pNext;
  1026. }
  1027. error:
  1028. return (dwError);
  1029. }
  1030. DWORD
  1031. OpenAllTableSessions(
  1032. PSESSION_CONTAINER pSessionContList
  1033. )
  1034. {
  1035. DWORD dwError = ERROR_SUCCESS;
  1036. DWORD JetError = JET_errSuccess;
  1037. PSESSION_CONTAINER pSessionCont = NULL;
  1038. pSessionCont = pSessionContList;
  1039. while (pSessionCont) {
  1040. if (pSessionCont->TableID == 0) {
  1041. JetError = JetOpenTable(
  1042. pSessionCont->SessionID,
  1043. (JET_DBID)(pSessionCont->DbID),
  1044. LOG_RECORD_TABLE,
  1045. NULL,
  1046. 0,
  1047. 0,
  1048. &pSessionCont->TableID
  1049. );
  1050. dwError = WZCMapJetError(JetError, "JetOpenTable");
  1051. BAIL_ON_WIN32_ERROR(dwError);
  1052. }
  1053. pSessionCont = pSessionCont->pNext;
  1054. }
  1055. error:
  1056. return (dwError);
  1057. }
  1058. DWORD
  1059. WZCGetTableDataHandle(
  1060. JET_SESID * pMyJetServerSession,
  1061. JET_DBID * pMyJetDatabaseHandle,
  1062. JET_TABLEID * pMyClientTableHandle
  1063. )
  1064. {
  1065. DWORD dwError = ERROR_SUCCESS;
  1066. DWORD JetError = JET_errSuccess;
  1067. //
  1068. // Create a new table. It will be opened in exclusive mode by
  1069. // Jet Engine.
  1070. //
  1071. dwError = WZCCreateTableData(
  1072. *pMyJetServerSession,
  1073. *pMyJetDatabaseHandle,
  1074. pMyClientTableHandle
  1075. );
  1076. if (dwError != JET_errTableDuplicate) {
  1077. BAIL_ON_WIN32_ERROR(dwError);
  1078. //
  1079. // Close the table since it is exclusively locked now.
  1080. //
  1081. JetError = JetCloseTable(
  1082. *pMyJetServerSession,
  1083. *pMyClientTableHandle
  1084. );
  1085. dwError = WZCMapJetError(JetError, "JetCloseTable");
  1086. if (dwError != ERROR_SUCCESS) {
  1087. ASSERT(FALSE);
  1088. }
  1089. BAIL_ON_WIN32_ERROR(dwError);
  1090. *pMyClientTableHandle = 0;
  1091. }
  1092. *pMyClientTableHandle = 0;
  1093. //
  1094. // Reopen the table in non-exclusive mode.
  1095. //
  1096. dwError = WZCOpenTableData(
  1097. *pMyJetServerSession,
  1098. *pMyJetDatabaseHandle,
  1099. pMyClientTableHandle
  1100. );
  1101. BAIL_ON_WIN32_ERROR(dwError);
  1102. error:
  1103. return (dwError);
  1104. }
  1105. DWORD
  1106. IniEnumWZCDbLogRecordsSummary(
  1107. PSESSION_CONTAINER pSessionCont,
  1108. PBOOL pbEnumFromStart,
  1109. DWORD dwPreferredNumEntries,
  1110. PWZC_DB_RECORD * ppWZCRecords,
  1111. LPDWORD pdwNumRecords
  1112. )
  1113. {
  1114. DWORD dwError = 0;
  1115. DWORD dwNumToEnum = 0;
  1116. PWZC_DB_RECORD pWZCRecords = NULL;
  1117. JET_SESID * pMyJetServerSession = NULL;
  1118. JET_DBID * pMyJetDatabaseHandle = NULL;
  1119. JET_TABLEID * pMyClientTableHandle = NULL;
  1120. DWORD i = 0;
  1121. PWZC_DB_RECORD pCurWZCRecord = NULL;
  1122. JET_ERR JetError = JET_errSuccess;
  1123. DWORD dwReqSize = 0;
  1124. char cTempBuf[MAX_RAW_DATA_SIZE];
  1125. DWORD dwCurIndex = 0;
  1126. BOOL bEnumFromStart = FALSE;
  1127. if (!dwPreferredNumEntries ||
  1128. (dwPreferredNumEntries > MAX_RECORD_ENUM_COUNT)) {
  1129. dwNumToEnum = MAX_RECORD_ENUM_COUNT;
  1130. }
  1131. else {
  1132. dwNumToEnum = dwPreferredNumEntries;
  1133. }
  1134. pWZCRecords = RpcCAlloc(sizeof(WZC_DB_RECORD)*dwNumToEnum);
  1135. if (!pWZCRecords) {
  1136. dwError = ERROR_OUTOFMEMORY;
  1137. BAIL_ON_WIN32_ERROR(dwError);
  1138. }
  1139. memset(pWZCRecords, 0, sizeof(WZC_DB_RECORD)*dwNumToEnum);
  1140. pMyJetServerSession = (JET_SESID *) &(pSessionCont->SessionID);
  1141. pMyJetDatabaseHandle = (JET_DBID *) &(pSessionCont->DbID);
  1142. pMyClientTableHandle = (JET_TABLEID *) &(pSessionCont->TableID);
  1143. if (!(*pMyClientTableHandle)) {
  1144. JetError = JetOpenTable(
  1145. *pMyJetServerSession,
  1146. *pMyJetDatabaseHandle,
  1147. LOG_RECORD_TABLE,
  1148. NULL,
  1149. 0,
  1150. 0,
  1151. pMyClientTableHandle
  1152. );
  1153. dwError = WZCMapJetError(JetError, "JetOpenTable");
  1154. BAIL_ON_WIN32_ERROR(dwError);
  1155. }
  1156. bEnumFromStart = *pbEnumFromStart;
  1157. if (bEnumFromStart) {
  1158. dwError = WZCJetPrepareSearch(
  1159. *pMyJetServerSession,
  1160. *pMyClientTableHandle,
  1161. gLogRecordTable[TIMESTAMP_IDX].ColName,
  1162. bEnumFromStart,
  1163. NULL,
  1164. 0
  1165. );
  1166. BAIL_ON_WIN32_ERROR(dwError);
  1167. bEnumFromStart = FALSE;
  1168. }
  1169. for (i = 0; i < dwNumToEnum; i++) {
  1170. pCurWZCRecord = (pWZCRecords + i);
  1171. dwError = WZCJetGetValue(
  1172. *pMyJetServerSession,
  1173. *pMyClientTableHandle,
  1174. gLogRecordTable[RECORD_IDX_IDX].ColHandle,
  1175. &(pCurWZCRecord->recordid),
  1176. sizeof(pCurWZCRecord->recordid),
  1177. &dwReqSize
  1178. );
  1179. BAIL_ON_WIN32_ERROR(dwError);
  1180. dwError = WZCJetGetValue(
  1181. *pMyJetServerSession,
  1182. *pMyClientTableHandle,
  1183. gLogRecordTable[COMPONENT_ID_IDX].ColHandle,
  1184. &(pCurWZCRecord->componentid),
  1185. sizeof(pCurWZCRecord->componentid),
  1186. &dwReqSize
  1187. );
  1188. BAIL_ON_WIN32_ERROR(dwError);
  1189. dwError = WZCJetGetValue(
  1190. *pMyJetServerSession,
  1191. *pMyClientTableHandle,
  1192. gLogRecordTable[CATEGORY_IDX].ColHandle,
  1193. &(pCurWZCRecord->category),
  1194. sizeof(pCurWZCRecord->category),
  1195. &dwReqSize
  1196. );
  1197. BAIL_ON_WIN32_ERROR(dwError);
  1198. dwError = WZCJetGetValue(
  1199. *pMyJetServerSession,
  1200. *pMyClientTableHandle,
  1201. gLogRecordTable[TIMESTAMP_IDX].ColHandle,
  1202. &(pCurWZCRecord->timestamp),
  1203. sizeof(pCurWZCRecord->timestamp),
  1204. &dwReqSize
  1205. );
  1206. BAIL_ON_WIN32_ERROR(dwError);
  1207. dwReqSize = 0;
  1208. dwError = WZCJetGetValue(
  1209. *pMyJetServerSession,
  1210. *pMyClientTableHandle,
  1211. gLogRecordTable[INTERFACE_MAC_IDX].ColHandle,
  1212. cTempBuf,
  1213. MAX_RAW_DATA_SIZE,
  1214. &dwReqSize
  1215. );
  1216. BAIL_ON_WIN32_ERROR(dwError);
  1217. if (dwReqSize > 0) {
  1218. (pCurWZCRecord->localmac).pData = RpcCAlloc(dwReqSize);
  1219. if (!((pCurWZCRecord->localmac).pData)) {
  1220. dwError = ERROR_OUTOFMEMORY;
  1221. BAIL_ON_WIN32_ERROR(dwError);
  1222. }
  1223. memcpy((pCurWZCRecord->localmac).pData, cTempBuf, dwReqSize);
  1224. (pCurWZCRecord->localmac).dwDataLen = dwReqSize;
  1225. }
  1226. dwReqSize = 0;
  1227. dwError = WZCJetGetValue(
  1228. *pMyJetServerSession,
  1229. *pMyClientTableHandle,
  1230. gLogRecordTable[DEST_MAC_IDX].ColHandle,
  1231. cTempBuf,
  1232. MAX_RAW_DATA_SIZE,
  1233. &dwReqSize
  1234. );
  1235. BAIL_ON_WIN32_ERROR(dwError);
  1236. if (dwReqSize > 0) {
  1237. (pCurWZCRecord->remotemac).pData = RpcCAlloc(dwReqSize);
  1238. if (!((pCurWZCRecord->remotemac).pData)) {
  1239. dwError = ERROR_OUTOFMEMORY;
  1240. BAIL_ON_WIN32_ERROR(dwError);
  1241. }
  1242. memcpy((pCurWZCRecord->remotemac).pData, cTempBuf, dwReqSize);
  1243. (pCurWZCRecord->remotemac).dwDataLen = dwReqSize;
  1244. }
  1245. dwReqSize = 0;
  1246. dwError = WZCJetGetValue(
  1247. *pMyJetServerSession,
  1248. *pMyClientTableHandle,
  1249. gLogRecordTable[SSID_IDX].ColHandle,
  1250. cTempBuf,
  1251. MAX_RAW_DATA_SIZE,
  1252. &dwReqSize
  1253. );
  1254. BAIL_ON_WIN32_ERROR(dwError);
  1255. if (dwReqSize > 0) {
  1256. (pCurWZCRecord->ssid).pData = RpcCAlloc(dwReqSize);
  1257. if (!((pCurWZCRecord->ssid).pData)) {
  1258. dwError = ERROR_OUTOFMEMORY;
  1259. BAIL_ON_WIN32_ERROR(dwError);
  1260. }
  1261. memcpy((pCurWZCRecord->ssid).pData, cTempBuf, dwReqSize);
  1262. (pCurWZCRecord->ssid).dwDataLen = dwReqSize;
  1263. }
  1264. dwReqSize = 0;
  1265. dwError = WZCJetGetValue(
  1266. *pMyJetServerSession,
  1267. *pMyClientTableHandle,
  1268. gLogRecordTable[MESSAGE_IDX].ColHandle,
  1269. cTempBuf,
  1270. MAX_RAW_DATA_SIZE,
  1271. &dwReqSize
  1272. );
  1273. BAIL_ON_WIN32_ERROR(dwError);
  1274. if (dwReqSize > 0) {
  1275. //
  1276. // only get (up to) MAX_SUMMARY_MESSAGE_SIZE message data
  1277. //
  1278. dwReqSize = dwReqSize <= MAX_SUMMARY_MESSAGE_SIZE ?
  1279. dwReqSize : MAX_SUMMARY_MESSAGE_SIZE;
  1280. (pCurWZCRecord->message).pData = RpcCAlloc(dwReqSize + 2);
  1281. ZeroMemory((pCurWZCRecord->message).pData, dwReqSize + 2);
  1282. if (!((pCurWZCRecord->message).pData)) {
  1283. dwError = ERROR_OUTOFMEMORY;
  1284. BAIL_ON_WIN32_ERROR(dwError);
  1285. }
  1286. memcpy((pCurWZCRecord->message).pData, cTempBuf, dwReqSize);
  1287. (pCurWZCRecord->message).dwDataLen = dwReqSize + 2;
  1288. }
  1289. //
  1290. // do not get context at all
  1291. //
  1292. (pCurWZCRecord->context).pData = NULL;
  1293. (pCurWZCRecord->context).dwDataLen = 0;
  1294. JetError = JetMove(
  1295. *pMyJetServerSession,
  1296. *pMyClientTableHandle,
  1297. JET_MoveNext,
  1298. 0
  1299. );
  1300. //
  1301. // Don't bail from here as the end of the table (logical or physical)
  1302. // is caught in the next call.
  1303. //
  1304. dwError = WZCJetGetValue(
  1305. *pMyJetServerSession,
  1306. *pMyClientTableHandle,
  1307. gLogRecordTable[RECORD_IDX_IDX].ColHandle,
  1308. &dwCurIndex,
  1309. sizeof(dwCurIndex),
  1310. &dwReqSize
  1311. );
  1312. if (dwCurIndex == gdwCurrentHeader || dwError != ERROR_SUCCESS) {
  1313. JetError = JetMove(
  1314. *pMyJetServerSession,
  1315. *pMyClientTableHandle,
  1316. JET_MoveLast,
  1317. 0
  1318. );
  1319. dwError = WZCMapJetError(JetError, "JetMove");
  1320. if (dwError == ERROR_SUCCESS)
  1321. dwError = ERROR_NO_MORE_ITEMS;
  1322. i++;
  1323. break;
  1324. }
  1325. }
  1326. *pbEnumFromStart = bEnumFromStart;
  1327. *ppWZCRecords = pWZCRecords;
  1328. *pdwNumRecords = i;
  1329. return (dwError);
  1330. error:
  1331. if (pWZCRecords) {
  1332. FreeWZCRecords(pWZCRecords, dwNumToEnum);
  1333. }
  1334. *ppWZCRecords = NULL;
  1335. *pdwNumRecords = 0;
  1336. return (dwError);
  1337. }
  1338. DWORD
  1339. EnumWZCDbLogRecordsSummary(
  1340. HANDLE hSession,
  1341. PWZC_DB_RECORD pTemplateRecord,
  1342. PBOOL pbEnumFromStart,
  1343. DWORD dwPreferredNumEntries,
  1344. PWZC_DB_RECORD * ppWZCRecords,
  1345. LPDWORD pdwNumRecords,
  1346. LPVOID pvReserved
  1347. )
  1348. {
  1349. DWORD Error = 0;
  1350. PSESSION_CONTAINER pSessionCont = NULL;
  1351. AcquireSharedLock(gpWZCDbSessionRWLock);
  1352. Error = GetSessionContainer(hSession, &pSessionCont);
  1353. BAIL_ON_LOCK_ERROR(Error);
  1354. if (pTemplateRecord) {
  1355. Error = ERROR_NOT_SUPPORTED;
  1356. }
  1357. else {
  1358. Error = IniEnumWZCDbLogRecordsSummary(
  1359. pSessionCont,
  1360. pbEnumFromStart,
  1361. dwPreferredNumEntries,
  1362. ppWZCRecords,
  1363. pdwNumRecords
  1364. );
  1365. }
  1366. BAIL_ON_LOCK_ERROR(Error);
  1367. ReleaseSharedLock(gpWZCDbSessionRWLock);
  1368. return (Error);
  1369. lock:
  1370. ReleaseSharedLock(gpWZCDbSessionRWLock);
  1371. return (Error);
  1372. }
  1373. DWORD
  1374. GetWZCDbLogRecord(
  1375. HANDLE hSession,
  1376. PWZC_DB_RECORD pTemplateRecord,
  1377. PWZC_DB_RECORD * ppWZCRecords,
  1378. LPVOID pvReserved
  1379. )
  1380. {
  1381. DWORD Error = 0;
  1382. PSESSION_CONTAINER pSessionCont = NULL;
  1383. SESSION_CONTAINER mySessionCont;
  1384. AcquireSharedLock(gpWZCDbSessionRWLock);
  1385. Error = GetSessionContainer(hSession, &pSessionCont);
  1386. BAIL_ON_LOCK_ERROR(Error);
  1387. ZeroMemory(&mySessionCont, sizeof(SESSION_CONTAINER));
  1388. Error = IniOpenWZCDbLogSession(&mySessionCont);
  1389. BAIL_ON_LOCK_ERROR(Error);
  1390. if (!pTemplateRecord) {
  1391. Error = ERROR_INVALID_HANDLE;
  1392. }
  1393. else {
  1394. Error = IniGetWZCDbLogRecord(
  1395. &mySessionCont,
  1396. pTemplateRecord,
  1397. ppWZCRecords
  1398. );
  1399. }
  1400. BAIL_ON_LOCK_ERROR(Error);
  1401. Error = IniCloseWZCDbLogSession(&mySessionCont);
  1402. BAIL_ON_LOCK_ERROR(Error);
  1403. ReleaseSharedLock(gpWZCDbSessionRWLock);
  1404. return (Error);
  1405. lock:
  1406. ReleaseSharedLock(gpWZCDbSessionRWLock);
  1407. return (Error);
  1408. };
  1409. DWORD
  1410. IniGetWZCDbLogRecord(
  1411. PSESSION_CONTAINER pSessionCont,
  1412. PWZC_DB_RECORD pTemplateRecord,
  1413. PWZC_DB_RECORD * ppWZCRecords
  1414. )
  1415. {
  1416. DWORD dwError = 0;
  1417. PWZC_DB_RECORD pWZCRecords = NULL;
  1418. JET_SESID * pMyJetServerSession = NULL;
  1419. JET_DBID * pMyJetDatabaseHandle = NULL;
  1420. JET_TABLEID * pMyClientTableHandle = NULL;
  1421. PWZC_DB_RECORD pCurWZCRecord = NULL;
  1422. JET_ERR JetError = JET_errSuccess;
  1423. DWORD dwReqSize = 0;
  1424. char cTempBuf[MAX_RAW_DATA_SIZE];
  1425. pWZCRecords = RpcCAlloc(sizeof(WZC_DB_RECORD));
  1426. if (!pWZCRecords) {
  1427. dwError = ERROR_OUTOFMEMORY;
  1428. BAIL_ON_WIN32_ERROR(dwError);
  1429. }
  1430. memset(pWZCRecords, 0, sizeof(WZC_DB_RECORD));
  1431. pMyJetServerSession = (JET_SESID *) &(pSessionCont->SessionID);
  1432. pMyJetDatabaseHandle = (JET_DBID *) &(pSessionCont->DbID);
  1433. pMyClientTableHandle = (JET_TABLEID *) &(pSessionCont->TableID);
  1434. if (!(*pMyClientTableHandle)) {
  1435. JetError = JetOpenTable(
  1436. *pMyJetServerSession,
  1437. *pMyJetDatabaseHandle,
  1438. LOG_RECORD_TABLE,
  1439. NULL,
  1440. 0,
  1441. 0,
  1442. pMyClientTableHandle
  1443. );
  1444. dwError = WZCMapJetError(JetError, "JetOpenTable");
  1445. BAIL_ON_WIN32_ERROR(dwError);
  1446. }
  1447. //
  1448. // seek to the perticular position
  1449. //
  1450. dwError = WZCSeekRecordOnIndexTime(
  1451. *pMyJetServerSession,
  1452. *pMyClientTableHandle,
  1453. pTemplateRecord->recordid,
  1454. pTemplateRecord->timestamp
  1455. );
  1456. if (dwError != ERROR_SUCCESS)
  1457. dwError = ERROR_NO_MORE_ITEMS;
  1458. BAIL_ON_WIN32_ERROR(dwError);
  1459. pCurWZCRecord = pWZCRecords;
  1460. dwError = WZCJetGetValue(
  1461. *pMyJetServerSession,
  1462. *pMyClientTableHandle,
  1463. gLogRecordTable[RECORD_IDX_IDX].ColHandle,
  1464. &(pCurWZCRecord->recordid),
  1465. sizeof(pCurWZCRecord->recordid),
  1466. &dwReqSize
  1467. );
  1468. BAIL_ON_WIN32_ERROR(dwError);
  1469. dwError = WZCJetGetValue(
  1470. *pMyJetServerSession,
  1471. *pMyClientTableHandle,
  1472. gLogRecordTable[COMPONENT_ID_IDX].ColHandle,
  1473. &(pCurWZCRecord->componentid),
  1474. sizeof(pCurWZCRecord->componentid),
  1475. &dwReqSize
  1476. );
  1477. BAIL_ON_WIN32_ERROR(dwError);
  1478. dwError = WZCJetGetValue(
  1479. *pMyJetServerSession,
  1480. *pMyClientTableHandle,
  1481. gLogRecordTable[CATEGORY_IDX].ColHandle,
  1482. &(pCurWZCRecord->category),
  1483. sizeof(pCurWZCRecord->category),
  1484. &dwReqSize
  1485. );
  1486. BAIL_ON_WIN32_ERROR(dwError);
  1487. dwError = WZCJetGetValue(
  1488. *pMyJetServerSession,
  1489. *pMyClientTableHandle,
  1490. gLogRecordTable[TIMESTAMP_IDX].ColHandle,
  1491. &(pCurWZCRecord->timestamp),
  1492. sizeof(pCurWZCRecord->timestamp),
  1493. &dwReqSize
  1494. );
  1495. BAIL_ON_WIN32_ERROR(dwError);
  1496. dwReqSize = 0;
  1497. dwError = WZCJetGetValue(
  1498. *pMyJetServerSession,
  1499. *pMyClientTableHandle,
  1500. gLogRecordTable[INTERFACE_MAC_IDX].ColHandle,
  1501. cTempBuf,
  1502. MAX_RAW_DATA_SIZE,
  1503. &dwReqSize
  1504. );
  1505. BAIL_ON_WIN32_ERROR(dwError);
  1506. if (dwReqSize > 0) {
  1507. (pCurWZCRecord->localmac).pData = RpcCAlloc(dwReqSize);
  1508. if (!((pCurWZCRecord->localmac).pData)) {
  1509. dwError = ERROR_OUTOFMEMORY;
  1510. BAIL_ON_WIN32_ERROR(dwError);
  1511. }
  1512. memcpy((pCurWZCRecord->localmac).pData, cTempBuf, dwReqSize);
  1513. (pCurWZCRecord->localmac).dwDataLen = dwReqSize;
  1514. }
  1515. dwReqSize = 0;
  1516. dwError = WZCJetGetValue(
  1517. *pMyJetServerSession,
  1518. *pMyClientTableHandle,
  1519. gLogRecordTable[DEST_MAC_IDX].ColHandle,
  1520. cTempBuf,
  1521. MAX_RAW_DATA_SIZE,
  1522. &dwReqSize
  1523. );
  1524. BAIL_ON_WIN32_ERROR(dwError);
  1525. if (dwReqSize > 0) {
  1526. (pCurWZCRecord->remotemac).pData = RpcCAlloc(dwReqSize);
  1527. if (!((pCurWZCRecord->remotemac).pData)) {
  1528. dwError = ERROR_OUTOFMEMORY;
  1529. BAIL_ON_WIN32_ERROR(dwError);
  1530. }
  1531. memcpy((pCurWZCRecord->remotemac).pData, cTempBuf, dwReqSize);
  1532. (pCurWZCRecord->remotemac).dwDataLen = dwReqSize;
  1533. }
  1534. dwReqSize = 0;
  1535. dwError = WZCJetGetValue(
  1536. *pMyJetServerSession,
  1537. *pMyClientTableHandle,
  1538. gLogRecordTable[SSID_IDX].ColHandle,
  1539. cTempBuf,
  1540. MAX_RAW_DATA_SIZE,
  1541. &dwReqSize
  1542. );
  1543. BAIL_ON_WIN32_ERROR(dwError);
  1544. if (dwReqSize > 0) {
  1545. (pCurWZCRecord->ssid).pData = RpcCAlloc(dwReqSize);
  1546. if (!((pCurWZCRecord->ssid).pData)) {
  1547. dwError = ERROR_OUTOFMEMORY;
  1548. BAIL_ON_WIN32_ERROR(dwError);
  1549. }
  1550. memcpy((pCurWZCRecord->ssid).pData, cTempBuf, dwReqSize);
  1551. (pCurWZCRecord->ssid).dwDataLen = dwReqSize;
  1552. }
  1553. dwReqSize = 0;
  1554. dwError = WZCJetGetValue(
  1555. *pMyJetServerSession,
  1556. *pMyClientTableHandle,
  1557. gLogRecordTable[MESSAGE_IDX].ColHandle,
  1558. cTempBuf,
  1559. MAX_RAW_DATA_SIZE,
  1560. &dwReqSize
  1561. );
  1562. BAIL_ON_WIN32_ERROR(dwError);
  1563. if (dwReqSize > 0) {
  1564. (pCurWZCRecord->message).pData = RpcCAlloc(dwReqSize);
  1565. ZeroMemory((pCurWZCRecord->message).pData, dwReqSize);
  1566. if (!((pCurWZCRecord->message).pData)) {
  1567. dwError = ERROR_OUTOFMEMORY;
  1568. BAIL_ON_WIN32_ERROR(dwError);
  1569. }
  1570. memcpy((pCurWZCRecord->message).pData, cTempBuf, dwReqSize);
  1571. (pCurWZCRecord->message).dwDataLen = dwReqSize;
  1572. }
  1573. dwReqSize = 0;
  1574. dwError = WZCJetGetValue(
  1575. *pMyJetServerSession,
  1576. *pMyClientTableHandle,
  1577. gLogRecordTable[CONTEXT_IDX].ColHandle,
  1578. cTempBuf,
  1579. MAX_RAW_DATA_SIZE,
  1580. &dwReqSize
  1581. );
  1582. BAIL_ON_WIN32_ERROR(dwError);
  1583. if (dwReqSize > 0) {
  1584. (pCurWZCRecord->context).pData = RpcCAlloc(dwReqSize);
  1585. if (!((pCurWZCRecord->context).pData)) {
  1586. dwError = ERROR_OUTOFMEMORY;
  1587. BAIL_ON_WIN32_ERROR(dwError);
  1588. }
  1589. memcpy((pCurWZCRecord->context).pData, cTempBuf, dwReqSize);
  1590. (pCurWZCRecord->context).dwDataLen = dwReqSize;
  1591. }
  1592. *ppWZCRecords = pWZCRecords;
  1593. return (dwError);
  1594. error:
  1595. if (pWZCRecords) {
  1596. FreeWZCRecords(pWZCRecords, 1);
  1597. }
  1598. *ppWZCRecords = NULL;
  1599. return (dwError);
  1600. }
  1601. DWORD
  1602. WZCSeekRecordOnIndexTime(
  1603. JET_SESID JetServerSession,
  1604. JET_TABLEID JetTableHandle,
  1605. DWORD dwIndex,
  1606. FILETIME ftTimeStamp
  1607. )
  1608. /*++
  1609. Routine Description:
  1610. This function seeks a record based on index and timestamp
  1611. Arguments:
  1612. JetServerSession - Server session id.
  1613. JetTableHandle - Table handle.
  1614. dwIndex - record index
  1615. ftTimeStamp - record timestamp
  1616. Return Value:
  1617. Winerror code.
  1618. --*/
  1619. {
  1620. JET_ERR JetError = JET_errSuccess;
  1621. DWORD Error = 0;
  1622. LONG lErr = 0;
  1623. DWORD dwKeySize = sizeof (dwIndex);
  1624. DWORD dwReqSize = 0;
  1625. FILETIME ftMyTimeStamp;
  1626. JetError = JetSetCurrentIndex(
  1627. JetServerSession,
  1628. JetTableHandle,
  1629. gLogRecordTable[RECORD_IDX_IDX].ColName
  1630. );
  1631. Error = WZCMapJetError(JetError, "JetPrepareSearch: JetSetCurrentIndex");
  1632. if (Error != ERROR_SUCCESS) {
  1633. WZCMapJetError(JetError, gLogRecordTable[RECORD_IDX_IDX].ColName);
  1634. return (Error);
  1635. }
  1636. JetError = JetMove(
  1637. JetServerSession,
  1638. JetTableHandle,
  1639. JET_MoveFirst,
  1640. 0
  1641. );
  1642. Error = WZCMapJetError(JetError, "JetPrepareSearch: JetMove");
  1643. if (Error != ERROR_SUCCESS) {
  1644. WZCMapJetError(JetError, gLogRecordTable[RECORD_IDX_IDX].ColName);
  1645. return (Error);
  1646. }
  1647. JetError = JetMakeKey(
  1648. JetServerSession,
  1649. JetTableHandle,
  1650. &dwIndex,
  1651. dwKeySize,
  1652. JET_bitNewKey
  1653. );
  1654. Error = WZCMapJetError(JetError, "JetPrepareSearch: JetMakeKey");
  1655. if (Error != ERROR_SUCCESS) {
  1656. WZCMapJetError(JetError, gLogRecordTable[RECORD_IDX_IDX].ColName);
  1657. return (Error);
  1658. }
  1659. JetError = JetSeek(
  1660. JetServerSession,
  1661. JetTableHandle,
  1662. JET_bitSeekEQ
  1663. );
  1664. Error = WZCMapJetError(JetError, "JetPrepareSearch: JetMove / JetSeek");
  1665. if (Error == ERROR_SUCCESS) {
  1666. dwReqSize = 0;
  1667. Error = WZCJetGetValue(
  1668. JetServerSession,
  1669. JetTableHandle,
  1670. gLogRecordTable[TIMESTAMP_IDX].ColHandle,
  1671. &ftMyTimeStamp,
  1672. sizeof(ftMyTimeStamp),
  1673. &dwReqSize
  1674. );
  1675. if (Error == ERROR_SUCCESS) {
  1676. lErr = CompareFileTime(
  1677. &ftMyTimeStamp,
  1678. &ftTimeStamp
  1679. );
  1680. if (lErr != 0)
  1681. Error = ERROR_NO_MORE_ITEMS;
  1682. }
  1683. }
  1684. return (Error);
  1685. }