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.

474 lines
11 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: backup.h
  7. //
  8. // Contents: backupsource Table
  9. //
  10. // History:
  11. //
  12. //---------------------------------------------------------------------------
  13. #ifndef __BACKUP_SOURCE_H__
  14. #define __BACKUP_SOURCE_H__
  15. #include "tlsdb.h"
  16. //
  17. // re-direct define using what's in tlsdef.h just for backward compatibility
  18. //
  19. #define BACKUPSOURCE_PROCESS_LSSETUPID 0x00000001
  20. #define BACKUPSOURCE_PROCESS_SERVERNAME (BACKUPSOURCE_PROCESS_LSSETUPID << 1)
  21. #define BACKUPSOURCE_PROCESS_DOMAINSID (BACKUPSOURCE_PROCESS_LSSETUPID << 2)
  22. #define BACKUPSOURCE_PROCESS_FILENAME (BACKUPSOURCE_PROCESS_LSSETUPID << 3)
  23. #define BACKUPSOURCE_PROCESS_BACKUPTIME (BACKUPSOURCE_PROCESS_LSSETUPID << 4)
  24. #define BACKUPSOURCE_PROCESS_RESTORETIME (BACKUPSOURCE_PROCESS_LSSETUPID << 5)
  25. //
  26. // Licensed KeyPack Table
  27. //
  28. #define BACKUPSOURCE_TABLE_NAME _TEXT("BackupSource")
  29. #define BACKUPSOURCE_COLUMN_LSERVERNAME _TEXT("ServerName")
  30. #define BACKUPSOURCE_COLUMN_LSSETUPID _TEXT("TLSSetupId")
  31. #define BACKUPSOURCE_COLUMN_DOMAINSID _TEXT("TLSDomainSetupId")
  32. #define BACKUPSOURCE_COLUMN_DBFILENAME _TEXT("DbFileName")
  33. #define BACKUPSOURCE_COLUMN_LASTBACKUPTIME _TEXT("LastBackupTime")
  34. #define BACKUPSOURCE_COLUMN_LASTRESTORETIME _TEXT("LastRestoreTime")
  35. typedef struct __BackSourceRecord {
  36. TCHAR szInstallId[MAX_JETBLUE_TEXT_LENGTH+1];
  37. TCHAR szTlsServerName[MAX_JETBLUE_TEXT_LENGTH+1];
  38. PSID pbDomainSid;
  39. DWORD cbDomainSid;
  40. TCHAR szFileName[MAX_PATH+1];
  41. FILETIME ftLastBackupTime; // last backup time
  42. FILETIME ftLastRestoreTime; // last restore time
  43. __BackSourceRecord() : pbDomainSid(NULL), cbDomainSid(0) {}
  44. ~__BackSourceRecord()
  45. {
  46. if(pbDomainSid != NULL)
  47. {
  48. FreeMemory(pbDomainSid);
  49. }
  50. }
  51. __BackSourceRecord(
  52. const __BackSourceRecord& v
  53. )
  54. /*++
  55. ++*/
  56. {
  57. *this = v;
  58. }
  59. __BackSourceRecord&
  60. operator=(const __BackSourceRecord& v)
  61. {
  62. BOOL bSuccess;
  63. if(this == &v)
  64. return *this;
  65. _tcscpy(szInstallId, v.szInstallId);
  66. _tcscpy(szTlsServerName, v.szTlsServerName);
  67. _tcscpy(szFileName, v.szFileName);
  68. ftLastBackupTime = v.ftLastBackupTime;
  69. ftLastRestoreTime = v.ftLastRestoreTime;
  70. bSuccess = TLSDBCopySid(
  71. v.pbDomainSid,
  72. v.cbDomainSid,
  73. &pbDomainSid,
  74. &cbDomainSid
  75. );
  76. JB_ASSERT(bSuccess == TRUE);
  77. return *this;
  78. }
  79. } BACKUPSOURCERECORD, *LPBACKUPSOURCERECORD, *PBACKUPSOURCERECORD;
  80. //
  81. //
  82. // Index structure for backupsource Table
  83. //
  84. //
  85. ////////////////////////////////////////////////////////////////
  86. //
  87. // Index on szInstallId
  88. //
  89. ////////////////////////////////////////////////////////////////
  90. // KeyPack_KeyPackId_idx
  91. //
  92. #define BACKUPSOURCE_INDEX_LSERVERNAME_INDEXNAME \
  93. BACKUPSOURCE_TABLE_NAME SEPERATOR BACKUPSOURCE_COLUMN_LSERVERNAME SEPERATOR INDEXNAME
  94. //
  95. // Primary Index on KeyPack ID "+KeyPackId\0"
  96. //
  97. #define BACKUPSOURCE_INDEX_LSERVERNAME_INDEXKEY \
  98. INDEX_SORT_ASCENDING BACKUPSOURCE_COLUMN_LSERVERNAME INDEX_END_COLNAME
  99. typedef struct __BackupSourceIdxOnServerName : public JBKeyBase {
  100. TCHAR szTlsServerName[MAX_JETBLUE_TEXT_LENGTH+1];
  101. static LPCTSTR pszIndexName;
  102. static LPCTSTR pszIndexKey;
  103. //--------------------------------------------------------
  104. __BackupSourceIdxOnServerName(
  105. const BACKUPSOURCERECORD& v
  106. ) :
  107. JBKeyBase()
  108. /*++
  109. ++*/
  110. {
  111. *this = v;
  112. }
  113. //--------------------------------------------------------
  114. __BackupSourceIdxOnServerName(
  115. const BACKUPSOURCERECORD* v=NULL
  116. ) :
  117. JBKeyBase()
  118. /*++
  119. ++*/
  120. {
  121. if(v)
  122. {
  123. *this = *v;
  124. }
  125. }
  126. //--------------------------------------------------------
  127. __BackupSourceIdxOnServerName&
  128. operator=(const BACKUPSOURCERECORD& v)
  129. {
  130. _tcscpy(szTlsServerName, v.szTlsServerName);
  131. SetEmptyValue(FALSE);
  132. return *this;
  133. }
  134. //--------------------------------------------------------
  135. LPCTSTR
  136. GetIndexName()
  137. {
  138. return pszIndexName;
  139. }
  140. //--------------------------------------------------------
  141. LPCTSTR
  142. GetIndexKey()
  143. {
  144. return pszIndexKey;
  145. }
  146. //--------------------------------------------------------
  147. DWORD
  148. GetNumKeyComponents()
  149. {
  150. return 1;
  151. }
  152. //--------------------------------------------------------
  153. BOOL
  154. GetSearchKey(
  155. DWORD dwComponentIndex,
  156. PVOID* pbData,
  157. unsigned long* cbData,
  158. JET_GRBIT* grbit,
  159. DWORD dwSearchParm
  160. )
  161. /*++
  162. ++*/
  163. {
  164. if(dwComponentIndex >= GetNumKeyComponents())
  165. {
  166. JB_ASSERT(FALSE);
  167. return FALSE;
  168. }
  169. *pbData = szTlsServerName;
  170. *cbData = _tcslen(szTlsServerName) * sizeof(TCHAR);
  171. *grbit = JET_bitNewKey;
  172. return TRUE;
  173. }
  174. } TLSBckSrcIdxServerName;
  175. ////////////////////////////////////////////////////////////////
  176. //
  177. // Index on EntryLastModifyTime
  178. //
  179. //
  180. ////////////////////////////////////////////////////////////////
  181. //
  182. // Index name
  183. //
  184. #define BACKUPSOURCE_INDEX_LSSETUPID_INDEXNAME \
  185. BACKUPSOURCE_TABLE_NAME SEPERATOR BACKUPSOURCE_COLUMN_LSSETUPID SEPERATOR INDEXNAME
  186. //
  187. // Index key
  188. //
  189. #define BACKUPSOURCE_INDEX_LSSETUPID_INDEXKEY \
  190. INDEX_SORT_ASCENDING BACKUPSOURCE_COLUMN_LSSETUPID INDEX_END_COLNAME
  191. typedef struct __BackupSourceIdxOnSetupId : public JBKeyBase {
  192. static LPCTSTR pszIndexName;
  193. static LPCTSTR pszIndexKey;
  194. TCHAR szInstallId[MAX_JETBLUE_TEXT_LENGTH+1];
  195. //--------------------------------------------------------
  196. __BackupSourceIdxOnSetupId(
  197. const BACKUPSOURCERECORD& v
  198. ) :
  199. JBKeyBase()
  200. /*++
  201. ++*/
  202. {
  203. *this = v;
  204. }
  205. //--------------------------------------------------------
  206. __BackupSourceIdxOnSetupId(
  207. const BACKUPSOURCERECORD* v=NULL
  208. ) :
  209. JBKeyBase()
  210. /*++
  211. ++*/
  212. {
  213. if(v)
  214. {
  215. *this = *v;
  216. }
  217. }
  218. //--------------------------------------------------------
  219. __BackupSourceIdxOnSetupId&
  220. operator=(const BACKUPSOURCERECORD& v)
  221. {
  222. _tcscpy(szInstallId, v.szInstallId);
  223. SetEmptyValue(FALSE);
  224. return *this;
  225. }
  226. //--------------------------------------------------------
  227. LPCTSTR
  228. GetIndexName()
  229. {
  230. return pszIndexName;
  231. }
  232. //--------------------------------------------------------
  233. LPCTSTR
  234. GetIndexKey()
  235. {
  236. return pszIndexName;
  237. }
  238. //--------------------------------------------------------
  239. DWORD
  240. GetNumKeyComponents()
  241. {
  242. return 1;
  243. }
  244. //--------------------------------------------------------
  245. BOOL
  246. GetSearchKey(
  247. DWORD dwComponentIndex,
  248. PVOID* pbData,
  249. unsigned long* cbData,
  250. JET_GRBIT* grbit,
  251. DWORD dwSearchParm
  252. )
  253. /*++
  254. ++*/
  255. {
  256. if(dwComponentIndex >= GetNumKeyComponents())
  257. {
  258. JB_ASSERT(FALSE);
  259. return FALSE;
  260. }
  261. *pbData = szInstallId;
  262. *cbData = _tcslen(szInstallId)*sizeof(TCHAR);
  263. *grbit = JET_bitNewKey;
  264. return TRUE;
  265. }
  266. } TLSBckSrcIdxSetupId;
  267. // -----------------------------------------------------------
  268. //
  269. // LicensedPackStatus Table
  270. //
  271. // -----------------------------------------------------------
  272. class BackupSourceTable : public TLSTable<BACKUPSOURCERECORD> {
  273. private:
  274. static LPCTSTR pszTableName;
  275. BOOL
  276. ProcessSingleColumn(
  277. BOOL bFetch,
  278. TLSColumnBase& column,
  279. DWORD offset,
  280. PVOID pbData,
  281. DWORD cbData,
  282. PDWORD pcbDataReturn,
  283. LPCTSTR szColumnName
  284. );
  285. BOOL
  286. ProcessRecord(
  287. BACKUPSOURCERECORD* v,
  288. BOOL bFetch, // TRUE - fetch, FALSE insert
  289. DWORD dwParam,
  290. BOOL bUpdate
  291. );
  292. public:
  293. TLSColumnText szInstallId;
  294. TLSColumnText szTlsServerName;
  295. TLSColumnBinary pbDomainSid;
  296. TLSColumnText szFileName;
  297. TLSColumnFileTime ftLastBackupTime;
  298. TLSColumnFileTime ftLastRestoreTime;
  299. //-----------------------------------------------------
  300. virtual LPCTSTR
  301. GetTableName()
  302. {
  303. return pszTableName;
  304. }
  305. //-----------------------------------------------------
  306. BackupSourceTable(JBDatabase& database) : TLSTable<BACKUPSOURCERECORD>(database)
  307. /*
  308. */
  309. {
  310. }
  311. //-----------------------------------------------------
  312. virtual BOOL
  313. ResolveToTableColumn();
  314. //-----------------------------------------------------
  315. virtual BOOL
  316. FetchRecord(
  317. BACKUPSOURCERECORD& v,
  318. DWORD dwParam=PROCESS_ALL_COLUMNS
  319. )
  320. /*
  321. */
  322. {
  323. if(IsValid() == FALSE)
  324. {
  325. DebugOutput(
  326. _TEXT("Table %s is not valid...\n"),
  327. GetTableName()
  328. );
  329. JB_ASSERT(FALSE);
  330. SetLastJetError(JET_errInvalidParameter);
  331. return FALSE;
  332. }
  333. //CCriticalSectionLocker Lock(GetTableLock());
  334. return ProcessRecord(&v, TRUE, dwParam, FALSE);
  335. }
  336. //-----------------------------------------------------
  337. virtual BOOL
  338. InsertRecord(
  339. BACKUPSOURCERECORD& v,
  340. DWORD dwParam=PROCESS_ALL_COLUMNS
  341. )
  342. /*
  343. */
  344. {
  345. if(IsValid() == FALSE)
  346. {
  347. DebugOutput(
  348. _TEXT("Table %s is not valid...\n"),
  349. GetTableName()
  350. );
  351. JB_ASSERT(FALSE);
  352. SetLastJetError(JET_errInvalidParameter);
  353. return FALSE;
  354. }
  355. //CCriticalSectionLocker Lock(GetTableLock());
  356. return ProcessRecord(&v, FALSE, dwParam, FALSE);
  357. }
  358. //-----------------------------------------------------
  359. virtual BOOL
  360. UpdateRecord(
  361. BACKUPSOURCERECORD& v,
  362. DWORD dwParam=PROCESS_ALL_COLUMNS
  363. )
  364. /*
  365. */
  366. {
  367. if(IsValid() == FALSE)
  368. {
  369. DebugOutput(
  370. _TEXT("Table %s is not valid...\n"),
  371. GetTableName()
  372. );
  373. JB_ASSERT(FALSE);
  374. SetLastJetError(JET_errInvalidParameter);
  375. return FALSE;
  376. }
  377. //CCriticalSectionLocker Lock(GetTableLock());
  378. return ProcessRecord(&v, FALSE, dwParam, TRUE);
  379. }
  380. //-------------------------------------------------------
  381. virtual BOOL
  382. Initialize()
  383. {
  384. return TRUE;
  385. }
  386. //-------------------------------------------------------
  387. virtual JBKeyBase*
  388. EnumerationIndex(
  389. IN BOOL bMatchAll,
  390. IN DWORD dwParam,
  391. IN BACKUPSOURCERECORD* kp,
  392. IN OUT BOOL* bCompareKey
  393. );
  394. virtual BOOL
  395. EqualValue(
  396. BACKUPSOURCERECORD& s1,
  397. BACKUPSOURCERECORD& s2,
  398. BOOL bMatchAll,
  399. DWORD dwParam
  400. );
  401. };
  402. #endif