* Version $Id$
*/
/*
- Copyright (C) 2001-2005 Kern Sibbald
+ Copyright (C) 2001-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
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., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
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 int num_files = 0;
#define CONFIG_FILE "bacula-sd.conf"
-char *configfile;
+char *configfile = NULL;
STORES *me = NULL; /* our Global resource */
bool forge_on = false; /* proceed inspite of I/O errors */
pthread_mutex_t device_release_mutex = PTHREAD_MUTEX_INITIALIZER;
static void usage()
{
fprintf(stderr, _(
-"Copyright (C) 2001-2005 Kern Sibbald.\n"
-"\nVersion: " VERSION " (" BDATE ")\n\n"
+"Copyright (C) 2001-%s Kern Sibbald.\n"
+"\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"), BYEAR, VERSION, BDATE);
exit(1);
}
struct stat stat_buf;
char *VolumeName = NULL;
+ setlocale(LC_ALL, "");
+ bindtextdomain("bacula", LOCALEDIR);
+ textdomain("bacula");
+
my_name_is(argc, argv, "bscan");
init_msg(NULL, NULL);
if (!bjcr) {
exit(1);
}
- dev = bjcr->dcr->dev;
+ dev = bjcr->read_dcr->dev;
if (showProgress) {
char ed1[50];
struct stat sb;
}
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);
/* 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);
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);
+ dev->attached_dcrs->remove(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;
}
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);
break;
*/
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;
}
bool dir_send_job_status(JCR *jcr) {return 1;}
int generate_job_event(JCR *jcr, const char *event) { return 1; }
-
bool dir_ask_sysop_to_mount_volume(DCR *dcr)
{
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: ",
+ dev->close();
+ fprintf(stderr, _("Mount Volume \"%s\" on device %s and press return when ready: "),
dcr->VolumeName, dev->print_name());
getchar();
return true;