* Version $Id$
*/
/*
- Copyright (C) 2001-2005 Kern Sibbald
+ Bacula® - The Network Backup Solution
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as ammended with additional clauses defined in the
- file LICENSE in the main source directory.
+ Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
- */
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
#include "bacula.h"
#include "stored.h"
static int create_fileset_record(B_DB *db, FILESET_DBR *fsr);
static int create_jobmedia_record(B_DB *db, JCR *jcr);
static JCR *create_jcr(JOB_DBR *jr, DEV_RECORD *rec, uint32_t JobId);
-static int update_SIG_record(B_DB *db, char *SIGbuf, DEV_RECORD *rec, int type);
-
-
-/* Global variables */
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
-int win32_client = 1;
-#else
-int win32_client = 0;
-#endif
+static int update_digest_record(B_DB *db, char *digest, DEV_RECORD *rec, int type);
/* Local variables */
static void usage()
{
fprintf(stderr, _(
-"Copyright (C) 2001-2005 Kern Sibbald.\n"
-"\nVersion: " VERSION " (" BDATE ")\n\n"
+PROG_COPYRIGHT
+"\nVersion: %s (%s)\n\n"
"Usage: bscan [ options ] <bacula-archive>\n"
" -b bootstrap specify a bootstrap file\n"
" -c <file> specify configuration file\n"
" -v verbose\n"
" -V <Volumes> specify Volume names (separated by |)\n"
" -w <dir> specify working directory (default from conf file)\n"
-" -? print this message\n\n"));
+" -? print this message\n\n"), 2001, VERSION, BDATE);
exit(1);
}
struct stat stat_buf;
char *VolumeName = NULL;
+ setlocale(LC_ALL, "");
+ bindtextdomain("bacula", LOCALEDIR);
+ textdomain("bacula");
+ init_stack_dump();
+
my_name_is(argc, argv, "bscan");
init_msg(NULL, NULL);
+ OSDependentInit();
while ((ch = getopt(argc, argv, "b:c:d:h:mn:pP:rsSu:vV:w:?")) != -1) {
switch (ch) {
if (!bjcr) {
exit(1);
}
- dev = bjcr->dcr->dev;
+ dev = bjcr->read_dcr->dev;
if (showProgress) {
char ed1[50];
struct stat sb;
- fstat(dev->fd, &sb);
+ fstat(dev->fd(), &sb);
currentVolumeSize = sb.st_size;
Pmsg1(000, _("First Volume Size = %sn"),
edit_uint64(currentVolumeSize, ed1));
}
do_scan();
- printf("Records %sadded or updated in the catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
- update_db?"":"would have been ",
- num_media, num_pools, num_jobs, num_files);
+ if (update_db) {
+ printf("Records added or updated in the catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
+ num_media, num_pools, num_jobs, num_files);
+ }
+ else {
+ printf("Records would have been added or updated in the catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
+ num_media, num_pools, num_jobs, num_files);
+ }
free_jcr(bjcr);
- term_dev(dev);
+ dev->term();
return 0;
}
// mdcr->EndBlock = (uint32_t)dcr->file_addr;
// mdcr->EndFile = (uint32_t)(dcr->file_addr >> 32);
}
+ mjcr->read_dcr->VolLastIndex = dcr->VolLastIndex;
if (!create_jobmedia_record(db, mjcr)) {
Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"),
dev->VolCatInfo.VolCatName, mjcr->Job);
if (showProgress) {
char ed1[50];
struct stat sb;
- fstat(dev->fd, &sb);
+ fstat(dev->fd(), &sb);
currentVolumeSize = sb.st_size;
Pmsg1(000, _("First Volume Size = %sn"),
edit_uint64(currentVolumeSize, ed1));
/* Detach bscan's jcr as we are not a real Job on the tape */
- read_records(bjcr->dcr, record_cb, bscan_mount_next_read_volume);
+ read_records(bjcr->read_dcr, record_cb, bscan_mount_next_read_volume);
+ if (update_db) {
+ db_write_batch_file_records(bjcr); /* used by bulk batch file insert */
+ }
free_attr(attr);
}
DEVICE *dev = dcr->dev;
JCR *bjcr = dcr->jcr;
DEV_BLOCK *block = dcr->block;
+ char digest[BASE64_SIZE(CRYPTO_DIGEST_MAX_SIZE)];
if (rec->data_len > 0) {
mr.VolBytes += rec->data_len + WRITE_RECHDR_LENGTH; /* Accumulate Volume bytes */
- if (showProgress) {
+ if (showProgress && currentVolumeSize > 0) {
int pct = (mr.VolBytes * 100) / currentVolumeSize;
if (pct != last_pct) {
- fprintf(stdout, "done: %d%%\n", pct);
+ fprintf(stdout, _("done: %d%%\n"), pct);
fflush(stdout);
last_pct = pct;
}
/* Check Media Info */
memset(&mr, 0, sizeof(mr));
- bstrncpy(mr.VolumeName, dev->VolHdr.VolName, sizeof(mr.VolumeName));
+ bstrncpy(mr.VolumeName, dev->VolHdr.VolumeName, sizeof(mr.VolumeName));
mr.PoolId = pr.PoolId;
num_media++;
if (db_get_media_record(bjcr, db, &mr)) {
/* process label, if Job record exists don't update db */
mjcr = create_job_record(db, &jr, &label, rec);
- dcr = mjcr->dcr;
+ dcr = mjcr->read_dcr;
update_db = save_update_db;
jr.PoolId = pr.PoolId;
+#ifdef xxx
/* Set start positions into JCR */
if (dev->is_tape()) {
/*
dcr->StartBlock = (uint32_t)dev->file_addr;
dcr->StartFile = (uint32_t)(dev->file_addr >> 32);
}
+#endif
mjcr->start_time = jr.StartTime;
mjcr->JobLevel = jr.JobLevel;
mjcr->JobStatus = JS_Terminated;
/* Create JobMedia record */
+ mjcr->read_dcr->VolLastIndex = dcr->VolLastIndex;
create_jobmedia_record(db, mjcr);
- dev->attached_dcrs->remove(mjcr->dcr);
+ detach_dcr_from_dev(mjcr->read_dcr);
free_jcr(mjcr);
break;
if (!db_update_job_end_record(bjcr, db, &jr)) {
Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
}
- mjcr->dcr = NULL;
+ mjcr->read_dcr = NULL;
free_jcr(mjcr);
}
}
}
return true;
}
- dcr = mjcr->dcr;
+ dcr = mjcr->read_dcr;
if (dcr->VolFirstIndex == 0) {
dcr->VolFirstIndex = block->FirstIndex;
}
case STREAM_WIN32_DATA:
case STREAM_FILE_DATA:
case STREAM_SPARSE_DATA:
+ case STREAM_ENCRYPTED_FILE_DATA:
+ case STREAM_ENCRYPTED_WIN32_DATA:
+ case STREAM_ENCRYPTED_MACOS_FORK_DATA:
+ /*
+ * For encrypted stream, this is an approximation.
+ * The data must be decrypted to know the correct length.
+ */
mjcr->JobBytes += rec->data_len;
if (rec->Stream == STREAM_SPARSE_DATA) {
mjcr->JobBytes -= sizeof(uint64_t);
break;
case STREAM_GZIP_DATA:
- mjcr->JobBytes += rec->data_len; /* No correct, we should expand it */
- free_jcr(mjcr); /* done using JCR */
+ case STREAM_ENCRYPTED_FILE_GZIP_DATA:
+ case STREAM_ENCRYPTED_WIN32_GZIP_DATA:
+ /* No correct, we should (decrypt and) expand it
+ done using JCR
+ */
+ mjcr->JobBytes += rec->data_len;
+ free_jcr(mjcr);
break;
case STREAM_SPARSE_GZIP_DATA:
free_jcr(mjcr); /* done using JCR */
break;
- case STREAM_MD5_SIGNATURE:
- char MD5buf[50];
- bin_to_base64(MD5buf, (char *)rec->data, 16); /* encode 16 bytes */
+ case STREAM_MD5_DIGEST:
+ bin_to_base64(digest, sizeof(digest), (char *)rec->data, CRYPTO_DIGEST_MD5_SIZE, true);
+ if (verbose > 1) {
+ Pmsg1(000, _("Got MD5 record: %s\n"), digest);
+ }
+ update_digest_record(db, digest, rec, CRYPTO_DIGEST_MD5);
+ break;
+
+ case STREAM_SHA1_DIGEST:
+ bin_to_base64(digest, sizeof(digest), (char *)rec->data, CRYPTO_DIGEST_SHA1_SIZE, true);
+ if (verbose > 1) {
+ Pmsg1(000, _("Got SHA1 record: %s\n"), digest);
+ }
+ update_digest_record(db, digest, rec, CRYPTO_DIGEST_SHA1);
+ break;
+
+ case STREAM_SHA256_DIGEST:
+ bin_to_base64(digest, sizeof(digest), (char *)rec->data, CRYPTO_DIGEST_SHA256_SIZE, true);
+ if (verbose > 1) {
+ Pmsg1(000, _("Got SHA256 record: %s\n"), digest);
+ }
+ update_digest_record(db, digest, rec, CRYPTO_DIGEST_SHA256);
+ break;
+
+ case STREAM_SHA512_DIGEST:
+ bin_to_base64(digest, sizeof(digest), (char *)rec->data, CRYPTO_DIGEST_SHA512_SIZE, true);
if (verbose > 1) {
- Pmsg1(000, _("Got MD5 record: %s\n"), MD5buf);
+ Pmsg1(000, _("Got SHA512 record: %s\n"), digest);
}
- update_SIG_record(db, MD5buf, rec, MD5_SIG);
+ update_digest_record(db, digest, rec, CRYPTO_DIGEST_SHA512);
break;
- case STREAM_SHA1_SIGNATURE:
- char SIGbuf[50];
- bin_to_base64(SIGbuf, (char *)rec->data, 20); /* encode 20 bytes */
+ case STREAM_ENCRYPTED_SESSION_DATA:
+ // TODO landonf: Investigate crypto support in bscan
if (verbose > 1) {
- Pmsg1(000, _("Got SHA1 record: %s\n"), SIGbuf);
+ Pmsg0(000, _("Got signed digest record\n"));
}
- update_SIG_record(db, SIGbuf, rec, SHA1_SIG);
break;
+ case STREAM_SIGNED_DIGEST:
+ // TODO landonf: Investigate crypto support in bscan
+ if (verbose > 1) {
+ Pmsg0(000, _("Got signed digest record\n"));
+ }
+ break;
case STREAM_PROGRAM_NAMES:
if (verbose) {
Pmsg0(000, _("Got Prog Data Stream record.\n"));
}
break;
+
+ case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL: /* Standard ACL attributes on UNIX */
+ case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL: /* Default ACL attributes on UNIX */
+ /* Ignore Unix attributes */
+ break;
+
default:
- Pmsg2(0, _("Unknown stream type!!! stream=%d data=%s\n"), rec->Stream, rec->data);
+ Pmsg2(0, _("Unknown stream type!!! stream=%d len=%i\n"), rec->Stream, rec->data_len);
break;
}
return true;
*/
static void bscan_free_jcr(JCR *jcr)
{
- Dmsg0(200, "Start dird free_jcr\n");
+ Dmsg0(200, "Start bscan free_jcr\n");
if (jcr->file_bsock) {
Dmsg0(200, "Close File bsock\n");
free_dcr(jcr->dcr);
jcr->dcr = NULL;
}
- Dmsg0(200, "End dird free_jcr\n");
+ if (jcr->read_dcr) {
+ free_dcr(jcr->read_dcr);
+ jcr->read_dcr = NULL;
+ }
+ Dmsg0(200, "End bscan free_jcr\n");
}
/*
char *fname, char *lname, int type,
char *ap, DEV_RECORD *rec)
{
- DCR *dcr = mjcr->dcr;
+ DCR *dcr = mjcr->read_dcr;
ar.fname = fname;
ar.link = lname;
ar.ClientId = mjcr->ClientId;
/* We mark Vols as Archive to keep them from being re-written */
bstrncpy(mr->VolStatus, "Archive", sizeof(mr->VolStatus));
mr->VolRetention = 365 * 3600 * 24; /* 1 year */
+ mr->Enabled = 1;
if (vl->VerNum >= 11) {
mr->FirstWritten = btime_to_utime(vl->write_btime);
mr->LabelDate = btime_to_utime(vl->label_btime);
return 0;
}
if (verbose) {
- Pmsg2(000, _("Updated Job termination record for JobId=%u TermStat=%c\n"), jr->JobId,
- jr->JobStatus);
+ Pmsg3(000, _("Updated Job termination record for JobId=%u Level=%s TermStat=%c\n"),
+ jr->JobId, job_level_to_str(mjcr->JobLevel), jr->JobStatus);
}
if (verbose > 1) {
const char *term_msg;
static int create_jobmedia_record(B_DB *db, JCR *mjcr)
{
JOBMEDIA_DBR jmr;
- DCR *dcr = mjcr->dcr;
+ DCR *dcr = mjcr->read_dcr;
if (dev->is_tape()) {
dcr->EndBlock = dev->EndBlock;
jmr.JobId = mjcr->JobId;
jmr.MediaId = mr.MediaId;
jmr.FirstIndex = dcr->VolFirstIndex;
- jmr.LastIndex = dcr->FileIndex;
+ jmr.LastIndex = dcr->VolLastIndex;
jmr.StartFile = dcr->StartFile;
jmr.EndFile = dcr->EndFile;
jmr.StartBlock = dcr->StartBlock;
/*
* Simulate the database call that updates the MD5/SHA1 record
*/
-static int update_SIG_record(B_DB *db, char *SIGbuf, DEV_RECORD *rec, int type)
+static int update_digest_record(B_DB *db, char *digest, DEV_RECORD *rec, int type)
{
JCR *mjcr;
return 1;
}
- if (!db_add_SIG_to_file_record(bjcr, db, mjcr->FileId, SIGbuf, type)) {
+ if (!db_add_digest_to_file_record(bjcr, db, mjcr->FileId, digest, type)) {
Pmsg1(0, _("Could not add MD5/SHA1 to File record. ERR=%s\n"), db_strerror(db));
free_jcr(mjcr);
return 0;
jobjcr->VolSessionId = rec->VolSessionId;
jobjcr->VolSessionTime = rec->VolSessionTime;
jobjcr->ClientId = jr->ClientId;
- new_dcr(jobjcr, dev);
+ jobjcr->read_dcr = new_dcr(jobjcr, dev);
+
return jobjcr;
}
/* Dummies to replace askdir.c */
-bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { return 1;}
bool dir_find_next_appendable_volume(DCR *dcr) { return 1;}
bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; }
bool dir_create_jobmedia_record(DCR *dcr) { return 1; }
DEVICE *dev = dcr->dev;
Dmsg0(20, "Enter dir_ask_sysop_to_mount_volume\n");
/* Close device so user can use autochanger if desired */
- if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
- offline_dev(dev);
- }
- force_close_dev(dev);
- fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
+ fprintf(stderr, _("Mount Volume \"%s\" on device %s and press return when ready: "),
dcr->VolumeName, dev->print_name());
+ dev->close();
getchar();
return true;
}
+
+bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing)
+{
+ Dmsg0(100, "Fake dir_get_volume_info\n");
+ bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
+ dcr->VolCatInfo.VolCatParts = find_num_dvd_parts(dcr);
+ Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts);
+ return 1;
+}