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.

544 lines
13 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: backup.cpp
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "backup.h"
  13. LPCTSTR __BackupSourceIdxOnServerName::pszIndexName = BACKUPSOURCE_INDEX_LSERVERNAME_INDEXNAME;
  14. LPCTSTR __BackupSourceIdxOnServerName::pszIndexKey = BACKUPSOURCE_INDEX_LSERVERNAME_INDEXKEY;
  15. LPCTSTR __BackupSourceIdxOnSetupId::pszIndexName = BACKUPSOURCE_INDEX_LSSETUPID_INDEXNAME;
  16. LPCTSTR __BackupSourceIdxOnSetupId::pszIndexKey = BACKUPSOURCE_INDEX_LSSETUPID_INDEXKEY;
  17. LPCTSTR BackupSourceTable::pszTableName = BACKUPSOURCE_TABLE_NAME;
  18. //----------------------------------------------------
  19. CCriticalSection BackupSourceTable::g_TableLock;
  20. //----------------------------------------------------
  21. TLSJBIndex
  22. BackupSourceTable::g_TableIndex[] =
  23. {
  24. {
  25. BACKUPSOURCE_INDEX_LSERVERNAME_INDEXNAME,
  26. BACKUPSOURCE_INDEX_LSERVERNAME_INDEXKEY,
  27. -1,
  28. JET_bitIndexIgnoreNull,
  29. TLSTABLE_INDEX_DEFAULT_DENSITY
  30. },
  31. {
  32. BACKUPSOURCE_INDEX_LSSETUPID_INDEXNAME,
  33. BACKUPSOURCE_INDEX_LSSETUPID_INDEXKEY,
  34. -1,
  35. JET_bitIndexIgnoreNull,
  36. TLSTABLE_INDEX_DEFAULT_DENSITY
  37. }
  38. };
  39. int
  40. BackupSourceTable::g_NumTableIndex = sizeof(BackupSourceTable::g_TableIndex) / sizeof(BackupSourceTable::g_TableIndex[0]);
  41. TLSJBColumn
  42. BackupSourceTable::g_Columns[] =
  43. {
  44. {
  45. BACKUPSOURCE_COLUMN_LSERVERNAME,
  46. JB_COLTYPE_TEXT,
  47. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  48. 0,
  49. JBSTRING_NULL,
  50. _tcslen(JBSTRING_NULL),
  51. TLS_JETBLUE_COLUMN_CODE_PAGE,
  52. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  53. TLS_JETBLUE_COLUMN_LANGID
  54. },
  55. {
  56. BACKUPSOURCE_COLUMN_LSSETUPID,
  57. JB_COLTYPE_TEXT,
  58. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  59. 0,
  60. JBSTRING_NULL,
  61. _tcslen(JBSTRING_NULL),
  62. TLS_JETBLUE_COLUMN_CODE_PAGE,
  63. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  64. TLS_JETBLUE_COLUMN_LANGID
  65. },
  66. {
  67. BACKUPSOURCE_COLUMN_DOMAINSID,
  68. JET_coltypLongBinary,
  69. TLSTABLE_MAX_BINARY_LENGTH,
  70. 0,
  71. NULL,
  72. 0,
  73. TLS_JETBLUE_COLUMN_CODE_PAGE,
  74. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  75. TLS_JETBLUE_COLUMN_LANGID
  76. },
  77. {
  78. BACKUPSOURCE_COLUMN_DBFILENAME,
  79. JB_COLTYPE_TEXT,
  80. (MAX_PATH + 1)*sizeof(TCHAR),
  81. 0,
  82. NULL,
  83. 0,
  84. TLS_JETBLUE_COLUMN_CODE_PAGE,
  85. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  86. TLS_JETBLUE_COLUMN_LANGID
  87. },
  88. {
  89. BACKUPSOURCE_COLUMN_LASTBACKUPTIME,
  90. JET_coltypBinary,
  91. sizeof(FILETIME),
  92. JET_bitColumnNotNULL,
  93. NULL,
  94. 0,
  95. TLS_JETBLUE_COLUMN_CODE_PAGE,
  96. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  97. TLS_JETBLUE_COLUMN_LANGID
  98. },
  99. {
  100. BACKUPSOURCE_COLUMN_LASTRESTORETIME,
  101. JET_coltypBinary,
  102. sizeof(FILETIME),
  103. JET_bitColumnNotNULL,
  104. NULL,
  105. 0,
  106. TLS_JETBLUE_COLUMN_CODE_PAGE,
  107. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  108. TLS_JETBLUE_COLUMN_LANGID
  109. }
  110. };
  111. int
  112. BackupSourceTable::g_NumColumns=sizeof(BackupSourceTable::g_Columns) / sizeof(BackupSourceTable::g_Columns[0]);
  113. //-------------------------------------------------------------
  114. JBKeyBase*
  115. BackupSourceTable::EnumerationIndex(
  116. BOOL bMatchAll,
  117. DWORD dwSearchParam,
  118. BACKUPSOURCERECORD* pRecord,
  119. BOOL* bCompareKey
  120. )
  121. /*
  122. */
  123. {
  124. JBKeyBase* index;
  125. if(dwSearchParam & BACKUPSOURCE_PROCESS_LSSETUPID)
  126. {
  127. index = new TLSBckSrcIdxSetupId(pRecord);
  128. }
  129. else
  130. {
  131. index = new TLSBckSrcIdxServerName(pRecord);
  132. }
  133. *bCompareKey = bMatchAll;
  134. return index;
  135. }
  136. //------------------------------------------------------------
  137. BOOL
  138. BackupSourceTable::EqualValue(
  139. BACKUPSOURCERECORD& s1,
  140. BACKUPSOURCERECORD& s2,
  141. BOOL bMatchAll,
  142. DWORD dwParam
  143. )
  144. /*
  145. */
  146. {
  147. BOOL bRetCode = TRUE;
  148. if(dwParam & BACKUPSOURCE_PROCESS_LSSETUPID)
  149. {
  150. bRetCode = (_tcscmp(s1.szInstallId, s2.szInstallId) == 0);
  151. if(bRetCode != bMatchAll)
  152. goto cleanup;
  153. }
  154. if(dwParam & BACKUPSOURCE_PROCESS_SERVERNAME)
  155. {
  156. bRetCode = (_tcsicmp(s1.szTlsServerName, s2.szTlsServerName) == 0);
  157. if(bRetCode != bMatchAll)
  158. goto cleanup;
  159. }
  160. //if(dwParam & BACKUPSOURCE_PROCESS_DOMAINSID)
  161. //{
  162. // bRetCode = EqualSid(s1.pbDomainSid, s2.pbDomainSid);
  163. // if(bRetCode != bMatchAll)
  164. // goto cleanup;
  165. //}
  166. if(dwParam & BACKUPSOURCE_PROCESS_FILENAME)
  167. {
  168. bRetCode = (_tcsicmp(s1.szFileName, s2.szFileName) == 0);
  169. if(bRetCode != bMatchAll)
  170. goto cleanup;
  171. }
  172. if(dwParam & BACKUPSOURCE_PROCESS_BACKUPTIME)
  173. {
  174. bRetCode = (CompareFileTime(&s1.ftLastBackupTime, &s2.ftLastBackupTime) == 0);
  175. if(bRetCode != bMatchAll)
  176. goto cleanup;
  177. }
  178. if(dwParam & BACKUPSOURCE_PROCESS_RESTORETIME)
  179. {
  180. bRetCode = (CompareFileTime(&s1.ftLastRestoreTime, &s2.ftLastRestoreTime) == 0);
  181. }
  182. cleanup:
  183. return bRetCode;
  184. }
  185. //----------------------------------------------------
  186. BOOL
  187. BackupSourceTable::ResolveToTableColumn()
  188. /*
  189. */
  190. {
  191. m_JetErr = szInstallId.AttachToTable(
  192. *this,
  193. BACKUPSOURCE_COLUMN_LSSETUPID
  194. );
  195. if(IsSuccess() == FALSE)
  196. {
  197. DebugOutput(
  198. _TEXT("Can't find column %s in table %s\n"),
  199. BACKUPSOURCE_COLUMN_LSSETUPID,
  200. GetTableName()
  201. );
  202. goto cleanup;
  203. }
  204. m_JetErr = szTlsServerName.AttachToTable(
  205. *this,
  206. BACKUPSOURCE_COLUMN_LSERVERNAME
  207. );
  208. if(IsSuccess() == FALSE)
  209. {
  210. DebugOutput(
  211. _TEXT("Can't find column %s in table %s\n"),
  212. BACKUPSOURCE_COLUMN_LSERVERNAME,
  213. GetTableName()
  214. );
  215. goto cleanup;
  216. }
  217. m_JetErr = pbDomainSid.AttachToTable(
  218. *this,
  219. BACKUPSOURCE_COLUMN_DOMAINSID
  220. );
  221. if(IsSuccess() == FALSE)
  222. {
  223. DebugOutput(
  224. _TEXT("Can't find column %s in table %s\n"),
  225. BACKUPSOURCE_COLUMN_DOMAINSID,
  226. GetTableName()
  227. );
  228. goto cleanup;
  229. }
  230. m_JetErr = szFileName.AttachToTable(
  231. *this,
  232. BACKUPSOURCE_COLUMN_DBFILENAME
  233. );
  234. if(IsSuccess() == FALSE)
  235. {
  236. DebugOutput(
  237. _TEXT("Can't find column %s in table %s\n"),
  238. BACKUPSOURCE_PROCESS_FILENAME,
  239. GetTableName()
  240. );
  241. goto cleanup;
  242. }
  243. m_JetErr = ftLastBackupTime.AttachToTable(
  244. *this,
  245. BACKUPSOURCE_COLUMN_LASTBACKUPTIME
  246. );
  247. if(IsSuccess() == FALSE)
  248. {
  249. DebugOutput(
  250. _TEXT("Can't find column %s in table %s\n"),
  251. BACKUPSOURCE_COLUMN_LASTBACKUPTIME,
  252. GetTableName()
  253. );
  254. goto cleanup;
  255. }
  256. m_JetErr = ftLastRestoreTime.AttachToTable(
  257. *this,
  258. BACKUPSOURCE_COLUMN_LASTRESTORETIME
  259. );
  260. if(IsSuccess() == FALSE)
  261. {
  262. DebugOutput(
  263. _TEXT("Can't find column %s in table %s\n"),
  264. BACKUPSOURCE_COLUMN_LASTRESTORETIME,
  265. GetTableName()
  266. );
  267. }
  268. cleanup:
  269. return IsSuccess();
  270. }
  271. //----------------------------------------------------
  272. CLASS_PRIVATE BOOL
  273. BackupSourceTable::ProcessSingleColumn(
  274. IN BOOL bFetch,
  275. IN TLSColumnBase& column,
  276. IN DWORD offset,
  277. IN PVOID pbData,
  278. IN DWORD cbData,
  279. IN PDWORD pcbDataReturn,
  280. IN LPCTSTR szColumnName
  281. )
  282. /*
  283. Abstract:
  284. Fetch/Insert/Update a particular column.
  285. Parameter:
  286. bFetch - TRUE if fetch, FALSE if update/insert.
  287. column - Intended column for operation, reference pointer to TLSColumn
  288. szColumnName - name of the column, for debugging print purpose only
  289. Returns:
  290. TRUE if successful, FALSE otherwise.
  291. */
  292. {
  293. if(bFetch)
  294. {
  295. m_JetErr = column.FetchColumnValue(
  296. pbData,
  297. cbData,
  298. offset,
  299. pcbDataReturn
  300. );
  301. }
  302. else
  303. {
  304. m_JetErr = column.InsertColumnValue(
  305. pbData,
  306. cbData,
  307. offset
  308. );
  309. }
  310. REPORTPROCESSFAILED(
  311. bFetch,
  312. GetTableName(),
  313. szColumnName,
  314. m_JetErr
  315. );
  316. return IsSuccess();
  317. }
  318. //---------------------------------------------------------
  319. CLASS_PRIVATE BOOL
  320. BackupSourceTable::ProcessRecord(
  321. BACKUPSOURCERECORD* bkRecord,
  322. BOOL bFetch,
  323. DWORD dwParam,
  324. BOOL bUpdate
  325. )
  326. /*
  327. */
  328. {
  329. DWORD dwSize;
  330. if(bFetch == FALSE)
  331. {
  332. BeginUpdate(bUpdate);
  333. }
  334. else
  335. {
  336. SetLastJetError(JET_errSuccess);
  337. }
  338. if(IsSuccess() == FALSE)
  339. goto cleanup;
  340. if(dwParam & BACKUPSOURCE_PROCESS_LSSETUPID)
  341. {
  342. ProcessSingleColumn(
  343. bFetch,
  344. szInstallId,
  345. 0,
  346. bkRecord->szInstallId,
  347. sizeof(bkRecord->szInstallId),
  348. &dwSize,
  349. BACKUPSOURCE_COLUMN_LSSETUPID
  350. );
  351. }
  352. if(IsSuccess() == FALSE)
  353. goto cleanup;
  354. if(dwParam & BACKUPSOURCE_PROCESS_SERVERNAME)
  355. {
  356. ProcessSingleColumn(
  357. bFetch,
  358. szTlsServerName,
  359. 0,
  360. bkRecord->szTlsServerName,
  361. sizeof(bkRecord->szTlsServerName),
  362. &dwSize,
  363. BACKUPSOURCE_COLUMN_LSERVERNAME
  364. );
  365. }
  366. if(IsSuccess() == FALSE)
  367. goto cleanup;
  368. #if 0
  369. // no more domain SID
  370. if(dwParam & BACKUPSOURCE_PROCESS_DOMAINSID)
  371. {
  372. if(bFetch == TRUE)
  373. {
  374. DWORD size=0;
  375. m_JetErr = pbDomainSid.FetchColumnValue(
  376. NULL,
  377. 0,
  378. 0,
  379. &size
  380. );
  381. if(bkRecord->cbDomainSid < size || bkRecord->pbDomainSid == NULL)
  382. {
  383. FreeMemory(bkRecord->pbDomainSid);
  384. bkRecord->pbDomainSid = (PSID)AllocateMemory(bkRecord->cbDomainSid = size);
  385. if(bkRecord->pbDomainSid == NULL)
  386. {
  387. SetLastJetError(JET_errOutOfMemory);
  388. goto cleanup;
  389. }
  390. }
  391. m_JetErr = pbDomainSid.FetchColumnValue(
  392. bkRecord->pbDomainSid,
  393. bkRecord->cbDomainSid,
  394. 0,
  395. &bkRecord->cbDomainSid
  396. );
  397. }
  398. else
  399. {
  400. ProcessSingleColumn(
  401. bFetch,
  402. pbDomainSid,
  403. 0,
  404. bkRecord->pbDomainSid,
  405. bkRecord->cbDomainSid,
  406. &dwSize,
  407. BACKUPSOURCE_COLUMN_DOMAINSID
  408. );
  409. }
  410. }
  411. if(IsSuccess() == FALSE)
  412. goto cleanup;
  413. #endif
  414. if(dwParam & BACKUPSOURCE_PROCESS_FILENAME)
  415. {
  416. ProcessSingleColumn(
  417. bFetch,
  418. szFileName,
  419. 0,
  420. bkRecord->szFileName,
  421. sizeof(bkRecord->szFileName),
  422. &dwSize,
  423. BACKUPSOURCE_COLUMN_DBFILENAME
  424. );
  425. }
  426. if(IsSuccess() == FALSE)
  427. goto cleanup;
  428. if(dwParam & BACKUPSOURCE_PROCESS_BACKUPTIME)
  429. {
  430. ProcessSingleColumn(
  431. bFetch,
  432. ftLastBackupTime,
  433. 0,
  434. &(bkRecord->ftLastBackupTime),
  435. sizeof(bkRecord->ftLastBackupTime),
  436. &dwSize,
  437. BACKUPSOURCE_COLUMN_LASTBACKUPTIME
  438. );
  439. }
  440. if(IsSuccess() == FALSE)
  441. goto cleanup;
  442. if(dwParam & BACKUPSOURCE_PROCESS_RESTORETIME)
  443. {
  444. ProcessSingleColumn(
  445. bFetch,
  446. ftLastRestoreTime,
  447. 0,
  448. &(bkRecord->ftLastRestoreTime),
  449. sizeof(bkRecord->ftLastRestoreTime),
  450. &dwSize,
  451. BACKUPSOURCE_COLUMN_LASTRESTORETIME
  452. );
  453. }
  454. cleanup:
  455. //
  456. // For inserting/updating record
  457. if(bFetch == FALSE)
  458. {
  459. JET_ERR jetErr;
  460. jetErr = GetLastJetError();
  461. EndUpdate(IsSuccess() == FALSE);
  462. if(jetErr != JET_errSuccess && IsSuccess() == FALSE)
  463. SetLastJetError(jetErr);
  464. }
  465. return IsSuccess();
  466. }