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.

573 lines
13 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: db.h
  7. //
  8. // Contents: Cert Server Database interface implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include "resource.h" // main symbols
  12. typedef struct _DBSEEKDATA
  13. {
  14. DWORD SeekFlags; // CST_*
  15. JET_GRBIT grbitSeekRange; // JetSeek flags if CST_SEEKINDEXRANGE
  16. // this is where to seek to retrieve
  17. // end-of-range key
  18. JET_GRBIT grbitInitial; // JetMove or JetSeek flags: set initial cursor
  19. // Where to set the cursor initially
  20. JET_GRBIT grbitRange; // JetSetIndexRange flags if CST_SEEKINDEXRANGE
  21. // other flags to be ingested while setting
  22. // range (bitRange UpperLimit, Inclusive)
  23. } DBSEEKDATA;
  24. // _Create() CreateFlags:
  25. #define CF_DATABASE 0x00000001
  26. #define CF_MISSINGTABLES 0x00000002
  27. #define CF_MISSINGCOLUMNS 0x00000004
  28. #define CF_MISSINGINDEXES 0x00000008
  29. #ifdef DBG_CERTSRV
  30. #define CSASSERTTHREAD(pcs) \
  31. { \
  32. DWORD dwThreadId = GetCurrentThreadId(); \
  33. if ((pcs)->dwThreadId != dwThreadId) \
  34. { \
  35. DBGPRINT((DBG_SS_CERTDB, "Session tid=%d, Current tid=%d\n", (pcs)->dwThreadId, dwThreadId)); \
  36. } \
  37. CSASSERT((pcs)->dwThreadId == dwThreadId); \
  38. }
  39. #endif
  40. HRESULT
  41. InitGlobalWriterState(VOID);
  42. HRESULT
  43. UnInitGlobalWriterState(VOID);
  44. VOID
  45. DBFreeParms();
  46. HRESULT
  47. DBInitParms(
  48. IN DWORD cSession,
  49. IN BOOL fCircularLogging,
  50. OPTIONAL IN WCHAR const *pwszEventSource,
  51. OPTIONAL IN WCHAR const *pwszLogDir,
  52. OPTIONAL IN WCHAR const *pwszSystemDir,
  53. OPTIONAL IN WCHAR const *pwszTempDir,
  54. OUT JET_INSTANCE *pInstance);
  55. #if DBG_CERTSRV
  56. VOID
  57. dbgcat(
  58. IN OUT WCHAR *pwszBuf,
  59. IN WCHAR const *pwszAdd);
  60. WCHAR const *
  61. wszSeekgrbit(
  62. JET_GRBIT grbit);
  63. WCHAR const *
  64. wszMovecrow(
  65. IN LONG cRow);
  66. WCHAR const *
  67. wszSetIndexRangegrbit(
  68. JET_GRBIT grbit);
  69. WCHAR const *
  70. wszMakeKeygrbit(
  71. JET_GRBIT grbit);
  72. WCHAR const *
  73. wszCSFFlags(
  74. IN LONG Flags);
  75. WCHAR const *
  76. wszCSTFlags(
  77. IN LONG Flags);
  78. WCHAR const *
  79. wszSeekOperator(
  80. IN LONG SeekOperator);
  81. WCHAR const *
  82. wszSortOperator(
  83. IN LONG SortOrder);
  84. VOID
  85. dbDumpValue(
  86. IN DWORD dwSubSystemId,
  87. OPTIONAL IN DBTABLE const *pdt,
  88. IN BYTE const *pbValue,
  89. IN DWORD cbValue);
  90. VOID
  91. dbDumpColumn(
  92. IN DWORD dwSubSystemId,
  93. IN DBTABLE const *pdt,
  94. IN BYTE const *pbValue,
  95. IN DWORD cbValue);
  96. #endif // DBG_CERTSRV
  97. class CCertDB:
  98. public ICertDB,
  99. //public ISupportErrorInfoImpl<&IID_ICertDB>,
  100. public CComObjectRoot,
  101. public CComCoClass<CCertDB, &CLSID_CCertDB>
  102. {
  103. public:
  104. CCertDB();
  105. ~CCertDB();
  106. BEGIN_COM_MAP(CCertDB)
  107. COM_INTERFACE_ENTRY(ICertDB)
  108. //COM_INTERFACE_ENTRY(ISupportErrorInfo)
  109. END_COM_MAP()
  110. DECLARE_NOT_AGGREGATABLE(CCertDB)
  111. // Remove the comment from the line above if you don't want your object to
  112. // support aggregation. The default is to support it
  113. DECLARE_REGISTRY(
  114. CCertDB,
  115. wszCLASS_CERTDB TEXT(".1"),
  116. wszCLASS_CERTDB,
  117. IDS_CERTDB_DESC,
  118. THREADFLAGS_BOTH)
  119. // ICertDB
  120. public:
  121. STDMETHOD(Open)(
  122. /* [in] */ DWORD Flags,
  123. /* [in] */ DWORD cSession,
  124. /* [in] */ WCHAR const *pwszEventSource,
  125. /* [in] */ WCHAR const *pwszDBFile,
  126. /* [in] */ WCHAR const *pwszLogDir,
  127. /* [in] */ WCHAR const *pwszSystemDir,
  128. /* [in] */ WCHAR const *pwszTempDir);
  129. STDMETHOD(ShutDown)(
  130. /* [in] */ DWORD dwFlags);
  131. STDMETHOD(OpenRow)(
  132. /* [in] */ DWORD dwFlags,
  133. /* [in] */ DWORD RowId,
  134. /* [in] */ WCHAR const *pwszSerialNumberOrCertHash, // OPTIONAL
  135. /* [out] */ ICertDBRow **pprow);
  136. STDMETHOD(OpenView)(
  137. /* [in] */ DWORD ccvr,
  138. /* [in] */ CERTVIEWRESTRICTION const *acvr,
  139. /* [in] */ DWORD ccolOut,
  140. /* [in] */ DWORD const *acolOut,
  141. /* [in] */ DWORD const dwFlags,
  142. /* [out] */ IEnumCERTDBRESULTROW **ppenum);
  143. STDMETHOD(EnumCertDBColumn)(
  144. /* [in] */ DWORD dwTable,
  145. /* [out] */ IEnumCERTDBCOLUMN **ppenum);
  146. STDMETHOD(OpenBackup)(
  147. /* [in] */ LONG grbitJet,
  148. /* [out] */ ICertDBBackup **ppBackup);
  149. STDMETHOD(GetDefaultColumnSet)(
  150. /* [in] */ DWORD iColumnSetDefault,
  151. /* [in] */ DWORD cColumnIds,
  152. /* [out] */ DWORD *pcColumnIds,
  153. /* [out, ref] */ DWORD *pColumnIds);
  154. // CCertDB
  155. HRESULT BeginTransaction(
  156. IN CERTSESSION *pcs,
  157. IN BOOL fPrepareUpdate);
  158. HRESULT CommitTransaction(
  159. IN CERTSESSION *pcs,
  160. IN BOOL fCommit);
  161. HRESULT ReleaseSession(
  162. IN CERTSESSION *pcs);
  163. HRESULT BackupBegin(
  164. IN LONG grbitJet);
  165. HRESULT BackupGetDBFileList(
  166. IN OUT DWORD *pcwcList,
  167. OUT WCHAR *pwszzList); // OPTIONAL
  168. HRESULT BackupGetLogFileList(
  169. IN OUT DWORD *pcwcList,
  170. OUT WCHAR *pwszzList); // OPTIONAL
  171. HRESULT BackupOpenFile(
  172. IN WCHAR const *pwszFile,
  173. OUT JET_HANDLE *phFileDB,
  174. OPTIONAL OUT ULARGE_INTEGER *pliSize);
  175. HRESULT BackupReadFile(
  176. IN JET_HANDLE hFileDB,
  177. OUT BYTE *pb,
  178. IN DWORD cb,
  179. OUT DWORD *pcb);
  180. HRESULT BackupCloseFile(
  181. IN JET_HANDLE hFileDB);
  182. HRESULT BackupTruncateLog();
  183. HRESULT BackupEnd();
  184. HRESULT SetProperty(
  185. IN CERTSESSION *pcs,
  186. IN DBTABLE const *pdt,
  187. IN DWORD cbProp,
  188. IN BYTE const *pbProp); // OPTIONAL
  189. HRESULT GetProperty(
  190. IN CERTSESSION *pcs,
  191. IN DBTABLE const *pdt,
  192. IN OUT DWORD *pcbProp,
  193. OUT BYTE *pbProp); // OPTIONAL
  194. HRESULT SetAttribute(
  195. IN CERTSESSION *pcs,
  196. IN WCHAR const *pwszAttributeName,
  197. IN DWORD cbValue,
  198. IN BYTE const *pbValue); // OPTIONAL
  199. HRESULT GetAttribute(
  200. IN CERTSESSION *pcs,
  201. IN WCHAR const *pwszAttributeName,
  202. IN OUT DWORD *pcbValue,
  203. OUT BYTE *pbValue); // OPTIONAL
  204. HRESULT SetExtension(
  205. IN CERTSESSION *pcs,
  206. IN WCHAR const *pwszExtensionName,
  207. IN DWORD dwExtFlags,
  208. IN DWORD cbValue,
  209. IN BYTE const *pbValue); // OPTIONAL
  210. HRESULT GetExtension(
  211. IN CERTSESSION *pcs,
  212. IN WCHAR const *pwszExtensionName,
  213. OUT DWORD *pdwExtFlags,
  214. IN OUT DWORD *pcbValue,
  215. OUT BYTE *pbValue); // OPTIONAL
  216. HRESULT CopyRequestNames(
  217. IN CERTSESSION *pcs);
  218. HRESULT GetColumnType(
  219. IN LONG ColumnIndex,
  220. OUT DWORD *pType);
  221. HRESULT EnumCertDBColumnNext(
  222. IN DWORD dwTable,
  223. IN ULONG ielt,
  224. IN ULONG celt,
  225. OUT CERTDBCOLUMN *rgelt,
  226. OUT ULONG *pielt,
  227. OUT ULONG *pceltFetched);
  228. HRESULT EnumCertDBResultRowNext(
  229. IN CERTSESSION *pcs,
  230. IN DWORD ccvr,
  231. IN CERTVIEWRESTRICTION const *acvr,
  232. IN DWORD ccolOut,
  233. IN DWORD const *acolOut,
  234. IN LONG cskip,
  235. IN ULONG celt,
  236. OUT CERTDBRESULTROW *rgelt,
  237. OUT ULONG *pceltFetched,
  238. OUT LONG *pcskipped);
  239. HRESULT ReleaseResultRow(
  240. IN ULONG celt,
  241. IN OUT CERTDBRESULTROW *rgelt);
  242. HRESULT EnumerateSetup(
  243. IN CERTSESSION *pcs,
  244. IN OUT DWORD *pFlags,
  245. OUT JET_TABLEID *ptableid);
  246. HRESULT EnumerateNext(
  247. IN CERTSESSION *pcs,
  248. IN OUT DWORD *pFlags,
  249. IN JET_TABLEID tableid,
  250. IN LONG cskip,
  251. IN ULONG celt,
  252. OUT CERTDBNAME *rgelt,
  253. OUT ULONG *pceltFetched);
  254. HRESULT EnumerateClose(
  255. IN CERTSESSION *pcs,
  256. IN JET_TABLEID tableid);
  257. HRESULT OpenTables(
  258. IN CERTSESSION *pcs,
  259. OPTIONAL IN CERTVIEWRESTRICTION const *pcvr);
  260. HRESULT CloseTables(
  261. IN CERTSESSION *pcs);
  262. HRESULT Delete(
  263. IN CERTSESSION *pcs);
  264. HRESULT CloseTable(
  265. IN CERTSESSION *pcs,
  266. IN JET_TABLEID tableid);
  267. HRESULT MapPropId(
  268. IN WCHAR const *pwszPropName,
  269. IN DWORD dwFlags,
  270. OUT DBTABLE *pdtOut);
  271. HRESULT TestShutDownState();
  272. #if DBG_CERTSRV
  273. VOID DumpRestriction(
  274. IN DWORD dwSubSystemId,
  275. IN LONG i,
  276. IN CERTVIEWRESTRICTION const *pcvr);
  277. #endif // DBG_CERTSRV
  278. private:
  279. HRESULT _AllocateSession(
  280. OUT CERTSESSION **ppcs);
  281. HRESULT _BackupGetFileList(
  282. IN BOOL fDBFiles,
  283. IN OUT DWORD *pcwcList,
  284. OPTIONAL OUT WCHAR *pwszzList);
  285. HRESULT _CreateTable(
  286. IN DWORD CreateFlags, // CF_*
  287. IN CERTSESSION *pcs,
  288. IN DBCREATETABLE const *pct);
  289. HRESULT _Create(
  290. IN DWORD CreateFlags, // CF_*
  291. IN CHAR const *pszDatBaseName);
  292. HRESULT _CreateIndex(
  293. IN CERTSESSION *pcs,
  294. IN JET_TABLEID tableid,
  295. IN CHAR const *pszIndexName,
  296. IN CHAR const *pchKey,
  297. IN DWORD cbKey,
  298. IN DWORD flags);
  299. HRESULT _AddColumn(
  300. IN CERTSESSION *pcs,
  301. IN JET_TABLEID tableid,
  302. IN DBTABLE const *pdt);
  303. HRESULT _BuildColumnIds(
  304. IN CERTSESSION *pcs,
  305. IN CHAR const *pszTableName,
  306. IN DBTABLE *pdt);
  307. HRESULT _ConvertOldColumnData(
  308. IN CERTSESSION *pcs,
  309. IN CHAR const *pszTableName,
  310. IN DBAUXDATA const *pdbaux,
  311. IN DBTABLE *pdt);
  312. HRESULT _ConvertColumnData(
  313. IN CERTSESSION *pcs,
  314. IN JET_TABLEID tableid,
  315. IN DWORD RowId,
  316. IN DBTABLE const *pdt,
  317. IN DBAUXDATA const *pdbaux,
  318. IN OUT BYTE **ppbBuf,
  319. IN OUT DWORD *pcbBuf);
  320. HRESULT _AddKeyLengthColumn(
  321. IN CERTSESSION *pcs,
  322. IN JET_TABLEID tableid,
  323. IN DWORD RowId,
  324. IN DBTABLE const *pdtPublicKey,
  325. IN DBTABLE const *pdtPublicKeyAlgorithm,
  326. IN DBTABLE const *pdtPublicKeyParameters,
  327. IN DBTABLE const *pdtPublicKeyLength,
  328. IN DBAUXDATA const *pdbaux,
  329. IN OUT BYTE **ppbBuf,
  330. IN OUT DWORD *pcbBuf);
  331. HRESULT _AddCallerName(
  332. IN CERTSESSION *pcs,
  333. IN JET_TABLEID tableid,
  334. IN DWORD RowId,
  335. IN DBTABLE const *pdtCallerName,
  336. IN DBTABLE const *pdtRequesterName,
  337. IN DBAUXDATA const *pdbaux,
  338. IN OUT BYTE **ppbBuf,
  339. IN OUT DWORD *pcbBuf);
  340. HRESULT _SetColumn(
  341. IN JET_SESID SesId,
  342. IN JET_TABLEID tableid,
  343. IN JET_COLUMNID columnid,
  344. IN DWORD cbProp,
  345. IN BYTE const *pbProp); // OPTIONAL
  346. HRESULT _OpenTableRow(
  347. IN CERTSESSION *pcs,
  348. IN DBAUXDATA const *pdbaux,
  349. OPTIONAL IN CERTVIEWRESTRICTION const *pcvr,
  350. OUT CERTSESSIONTABLE *pTable,
  351. OUT DWORD *pdwRowIdMismatch);
  352. HRESULT _UpdateTable(
  353. IN CERTSESSION *pcs,
  354. IN JET_TABLEID tableid);
  355. HRESULT _OpenTable(
  356. IN CERTSESSION *pcs,
  357. IN DBAUXDATA const *pdbaux,
  358. IN CERTVIEWRESTRICTION const *pcvr,
  359. IN OUT CERTSESSIONTABLE *pTable);
  360. HRESULT _SetIndirect(
  361. IN CERTSESSION *pcs,
  362. IN OUT CERTSESSIONTABLE *pTable,
  363. IN WCHAR const *pwszName,
  364. IN DWORD const *pdwExtFlags, // OPTIONAL
  365. IN DWORD cbValue,
  366. IN BYTE const *pbValue); // OPTIONAL
  367. HRESULT _GetIndirect(
  368. IN CERTSESSION *pcs,
  369. IN OUT CERTSESSIONTABLE *pTable,
  370. IN WCHAR const *pwszName,
  371. OUT DWORD *pdwExtFlags, // OPTIONAL
  372. IN OUT DWORD *pcbValue,
  373. OUT BYTE *pbValue); // OPTIONAL
  374. DBTABLE const *_MapTable(
  375. IN WCHAR const *pwszPropName,
  376. IN DBTABLE const *pdt);
  377. HRESULT _MapPropIdIndex(
  378. IN DWORD ColumnIndex,
  379. OUT DBTABLE const **ppdt,
  380. OPTIONAL OUT DWORD *pType);
  381. HRESULT _RetrieveColumnBuffer(
  382. IN CERTSESSION *pcs,
  383. IN JET_TABLEID tableid,
  384. IN JET_COLUMNID columnid,
  385. IN JET_COLTYP coltyp,
  386. IN OUT DWORD *pcbProp,
  387. IN OUT BYTE **ppbBuf,
  388. IN OUT DWORD *pcbBuf);
  389. HRESULT _RetrieveColumn(
  390. IN CERTSESSION *pcs,
  391. IN JET_TABLEID tableid,
  392. IN JET_COLUMNID columnid,
  393. IN JET_COLTYP coltyp,
  394. IN OUT DWORD *pcbData,
  395. OUT BYTE *pbData);
  396. HRESULT _CompareColumnValue(
  397. IN CERTSESSION *pcs,
  398. IN CERTVIEWRESTRICTION const *pcvr);
  399. HRESULT _EnumerateMove(
  400. IN CERTSESSION *pcs,
  401. IN OUT DWORD *pFlags,
  402. IN DBAUXDATA const *pdbaux,
  403. IN JET_TABLEID tableid,
  404. IN LONG cskip);
  405. HRESULT _MakeSeekKey(
  406. IN CERTSESSION *pcs,
  407. IN JET_TABLEID tableid,
  408. IN DBTABLE const *pdt,
  409. IN BYTE const *pbValue,
  410. IN DWORD cbValue);
  411. HRESULT _SeekTable(
  412. IN CERTSESSION *pcs,
  413. IN JET_TABLEID tableid,
  414. IN CERTVIEWRESTRICTION const *pcvr,
  415. IN DBTABLE const *pdt,
  416. IN DWORD dwPosition,
  417. OUT DWORD *pTableFlags
  418. DBGPARM(IN DBAUXDATA const *pdbaux));
  419. HRESULT _MoveTable(
  420. IN CERTSESSION *pcs,
  421. IN DWORD ccvr,
  422. IN CERTVIEWRESTRICTION const *acvr,
  423. IN LONG cskip,
  424. OUT LONG *pcskipped);
  425. HRESULT _GetResultRow(
  426. IN CERTSESSION *pcs,
  427. IN DWORD ccvr,
  428. IN CERTVIEWRESTRICTION const *acvr,
  429. IN LONG cskip,
  430. IN DWORD ccolOut,
  431. IN DWORD const *acolOut,
  432. OUT CERTDBRESULTROW *pelt,
  433. OUT LONG *pcskipped);
  434. HRESULT _JetSeekFromRestriction(
  435. IN CERTVIEWRESTRICTION const *pcvr,
  436. IN DWORD dwPosition,
  437. OUT DBSEEKDATA *pSeekData);
  438. HRESULT _DupString(
  439. OPTIONAL IN WCHAR const *pwszPrefix,
  440. IN WCHAR const *pwszIn,
  441. OUT WCHAR **ppwszOut);
  442. HRESULT _Rollback(
  443. IN CERTSESSION *pcs);
  444. #if DBG_CERTSRV
  445. HRESULT _DumpRowId(
  446. IN CHAR const *psz,
  447. IN CERTSESSION *pcs,
  448. IN JET_TABLEID tableid);
  449. HRESULT _DumpColumn(
  450. IN CHAR const *psz,
  451. IN CERTSESSION *pcs,
  452. IN JET_TABLEID tableid,
  453. IN DBTABLE const *pdt);
  454. #endif // DBG_CERTSRV
  455. BOOL m_fDBOpen;
  456. BOOL m_fDBReadOnly;
  457. BOOL m_fDBRestart;
  458. BOOL m_fFoundOldColumns;
  459. BOOL m_fAddedNewColumns;
  460. JET_INSTANCE m_Instance;
  461. CERTSESSION *m_aSession;
  462. DWORD m_cSession;
  463. DWORD m_cbPage;
  464. CRITICAL_SECTION m_critsecSession;
  465. CRITICAL_SECTION m_critsecAutoIncTables;
  466. BOOL m_cCritSec;
  467. BOOL m_fPendingShutDown;
  468. };