From 180eb560779b272aa2f016d714096a76cdc56719 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 11 Jun 2002 13:20:39 +0000 Subject: [PATCH] Fix space in filename bug -- see kes11Jun02 git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@38 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/bdb_list.c | 3 +- bacula/src/cats/protos.h | 4 +- bacula/src/cats/sql_list.c | 7 +- bacula/src/dird/Makefile.in | 2 +- bacula/src/dird/fd_cmds.c | 116 +++++++++++++++++++--------------- bacula/src/dird/query.sql | 58 +++++++++++++++++ bacula/src/dird/verify.c | 23 +++++-- bacula/src/filed/Makefile.in | 2 +- bacula/src/filed/restore.c | 18 ++++-- bacula/src/lib/message.c | 27 ++++++-- bacula/src/lib/signal.c | 2 +- bacula/src/stored/Makefile.in | 2 +- bacula/src/stored/bextract.c | 21 ++++-- bacula/src/version.h | 4 +- 14 files changed, 203 insertions(+), 86 deletions(-) diff --git a/bacula/src/cats/bdb_list.c b/bacula/src/cats/bdb_list.c index 99a00b214a..06d92923e0 100644 --- a/bacula/src/cats/bdb_list.c +++ b/bacula/src/cats/bdb_list.c @@ -57,7 +57,8 @@ /* * Submit general SQL query */ -int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx) +int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx, + int verbose) { sendit(ctx, "SQL Queries not implemented with internal database.\n"); return 0; diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index cea777bd34..fbaf15b8af 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -81,14 +81,14 @@ void db_list_job_totals(B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx void db_list_files_for_job(B_DB *db, uint32_t jobid, DB_LIST_HANDLER sendit, void *ctx); void db_list_media_records(B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx); void db_list_jobmedia_records(B_DB *mdb, uint32_t JobId, DB_LIST_HANDLER *sendit, void *ctx); -int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx); +int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose); /* update.c */ int db_update_job_start_record(B_DB *db, JOB_DBR *jr); int db_update_job_end_record(B_DB *db, JOB_DBR *jr); int db_update_pool_record(B_DB *db, POOL_DBR *pr); int db_update_media_record(B_DB *db, MEDIA_DBR *mr); -int db_add_MD5_to_file_record(B_DB *mdb, FileId_t FileId, char *MD5); +int db_add_MD5_to_file_record(B_DB *mdb, FileId_t FileId, char *MD5); int db_mark_file_record(B_DB *mdb, FileId_t FileId, int JobId); #endif /* __SQL_PROTOS_H */ diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 305fc92aab..8d88817695 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -51,12 +51,15 @@ extern int QueryDB(char *file, int line, B_DB *db, char *select_cmd); /* * Submit general SQL query */ -int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx) +int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx, + int verbose) { db_lock(mdb); if (sql_query(mdb, query) != 0) { Mmsg(&mdb->errmsg, _("Query failed: %s\n"), sql_strerror(mdb)); - sendit(ctx, mdb->errmsg); + if (verbose) { + sendit(ctx, mdb->errmsg); + } db_unlock(mdb); return 0; } diff --git a/bacula/src/dird/Makefile.in b/bacula/src/dird/Makefile.in index 0bbf313a1d..f0551221be 100644 --- a/bacula/src/dird/Makefile.in +++ b/bacula/src/dird/Makefile.in @@ -66,7 +66,7 @@ all: Makefile bacula-dir bacula-dir: $(SVROBJS) ../lib/libbac.a ../cats/libsql.a $(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ $(SVROBJS) \ - -lsql $(LIBS) $(DLIB) -lbac -lm + -lsql -lbac -lm $(LIBS) $(DLIB) Makefile: $(srcdir)/Makefile.in $(topdir)/config.status cd $(topdir) \ diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 304fb77612..08e4f1147b 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -197,59 +197,71 @@ int get_attributes_and_put_in_catalog(JCR *jcr) * really fatal problems, or the number of errors is too * large. */ - long file_index; - int stream, len; - char *attr, buf[MAXSTRING]; - char Opts[MAXSTRING]; /* either Verify opts or MD5 signature */ - - /* ***FIXME*** check fname length */ - if ((len = sscanf(fd->msg, "%ld %d %s %s", &file_index, &stream, - Opts, jcr->fname)) != 4) { - Jmsg(jcr, M_FATAL, 0, _("fname = check_pool_memory_size(jcr->fname, fd->msglen); + if ((len = sscanf(fd->msg, "%ld %d %s", &file_index, &stream, Opts_MD5)) != 3) { + Jmsg(jcr, M_FATAL, 0, _("msglen, fd->msg); - jcr->JobStatus = JS_ErrorTerminated; - return 0; - } - - if (stream == STREAM_UNIX_ATTRIBUTES) { - jcr->JobFiles++; - len = strlen(fd->msg); /* length before attributes */ - ar.attr = &fd->msg[len+1]; - ar.fname = jcr->fname; - ar.FileIndex = 0; /* used as mark field during compare */ - ar.Stream = stream; - ar.link = NULL; - ar.JobId = jcr->JobId; - ar.ClientId = jcr->ClientId; - ar.PathId = 0; - ar.FilenameId = 0; - - Dmsg2(11, "dirdfname); - Dmsg1(20, "dirddb, &ar)) { - Jmsg1(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db)); - jcr->JobStatus = JS_ErrorTerminated; - /* This probably should not really be fatal *****FIXME****** */ - return 0; - } - jcr->FileIndex = file_index; - jcr->FileId = ar.FileId; - } else if (stream == STREAM_MD5_SIGNATURE) { - if (jcr->FileIndex != (uint32_t)file_index) { - Jmsg0(jcr, M_FATAL, 0, _("Got MD5 but not same block as attributes\n")); - jcr->JobStatus = JS_ErrorTerminated; - return 0; - } - db_escape_string(buf, Opts, strlen(Opts)); - Dmsg2(20, "MD5len=%d MD5=%s\n", strlen(buf), buf); - if (!db_add_MD5_to_file_record(jcr->db, jcr->FileId, buf)) { - Jmsg1(jcr, M_WARNING, 0, "%s", db_strerror(jcr->db)); - } - } - jcr->jr.JobFiles = jcr->JobFiles = file_index; - jcr->jr.LastIndex = file_index; + jcr->JobStatus = JS_ErrorTerminated; + return 0; + } + p = fd->msg; + skip_nonspaces(&p); /* skip FileIndex */ + skip_spaces(&p); + skip_nonspaces(&p); /* skip Stream */ + skip_spaces(&p); + skip_nonspaces(&p); /* skip Opts_MD5 */ + p++; /* skip space */ + fn = jcr->fname; + while (*p != 0) { + *fn++ = *p++; /* copy filename */ + } + *fn = *p++; /* term filename and point to attribs */ + attr = p; + + if (stream == STREAM_UNIX_ATTRIBUTES) { + jcr->JobFiles++; + ar.attr = attr; + ar.fname = jcr->fname; + ar.FileIndex = 0; /* used as mark field during compare */ + ar.Stream = stream; + ar.link = NULL; + ar.JobId = jcr->JobId; + ar.ClientId = jcr->ClientId; + ar.PathId = 0; + ar.FilenameId = 0; + + Dmsg2(11, "dirdfname); + Dmsg1(20, "dirddb, &ar)) { + Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); + jcr->JobStatus = JS_Error; + continue; + } + jcr->FileIndex = file_index; + jcr->FileId = ar.FileId; + } else if (stream == STREAM_MD5_SIGNATURE) { + if (jcr->FileIndex != (uint32_t)file_index) { + Jmsg0(jcr, M_ERROR, 0, _("Got MD5 but not same block as attributes\n")); + jcr->JobStatus = JS_Error; + continue; + } + db_escape_string(MD5, Opts_MD5, strlen(Opts_MD5)); + Dmsg2(20, "MD5len=%d MD5=%s\n", strlen(MD5), MD5); + if (!db_add_MD5_to_file_record(jcr->db, jcr->FileId, MD5)) { + Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); + jcr->JobStatus = JS_Error; + } + } + jcr->jr.JobFiles = jcr->JobFiles = file_index; + jcr->jr.LastIndex = file_index; } if (n < 0) { Jmsg1(jcr, M_FATAL, 0, _("temp.JobTDate + AND Job.ClientId=temp.ClientId + AND Level='I' AND JobStatus='T' + AND JobMedia.JobId=Job.JobId + AND JobMedia.MediaId=Media.MediaId; +SELECT * from temp2; +!DROP TABLE temp; +!DROP TABLE temp2; +# diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index b296611974..475c980004 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -299,26 +299,37 @@ int get_attributes_and_compare_to_catalog(JCR *jcr, int last_full_id) while ((n=bget_msg(fd, 0)) > 0) { long file_index, attr_file_index; int stream; - char *attr, *p; + char *attr, *p, *fn; char Opts_MD5[MAXSTRING]; /* Verify Opts or MD5 signature */ fname = check_pool_memory_size(fname, fd->msglen); jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen); Dmsg1(50, "Atts+MD5=%s\n", fd->msg); - if ((len = sscanf(fd->msg, "%ld %d %100s %s", &file_index, &stream, - Opts_MD5, fname)) != 4) { - Jmsg3(jcr, M_FATAL, 0, _("birdmsg, "%ld %d %100s", &file_index, &stream, + Opts_MD5)) != 3) { + Jmsg3(jcr, M_FATAL, 0, _("birdmsglen, fd->msg); goto bail_out; } + p = fd->msg; + skip_nonspaces(&p); /* skip FileIndex */ + skip_spaces(&p); + skip_nonspaces(&p); /* skip Stream */ + skip_spaces(&p); + skip_nonspaces(&p); /* skip Opts_MD5 */ + p++; /* skip space */ + fn = fname; + while (*p != 0) { + *fn++ = *p++; /* copy filename */ + } + *fn = *p++; /* term filename and point to attribs */ + attr = p; /* * Got attributes stream, decode it */ if (stream == STREAM_UNIX_ATTRIBUTES) { jcr->JobFiles++; attr_file_index = file_index; /* remember attribute file_index */ - len = strlen(fd->msg); - attr = &fd->msg[len+1]; decode_stat(attr, &statf); /* decode file stat packet */ do_MD5 = FALSE; jcr->fn_printed = FALSE; diff --git a/bacula/src/filed/Makefile.in b/bacula/src/filed/Makefile.in index dcc7032603..c6f0eea85a 100755 --- a/bacula/src/filed/Makefile.in +++ b/bacula/src/filed/Makefile.in @@ -66,7 +66,7 @@ win32: $(WIN32OBJS) bacula-fd: $(SVROBJS) ../findlib/libfind.a ../lib/libbac.a @WIN32@ $(CXX) $(LDFLAGS) -L../lib -L../findlib -o $@ $(SVROBJS) \ - $(WIN32LIBS) $(FDLIBS) $(LIBS) $(DLIB) -lfind -lbac -lm + $(WIN32LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS) $(DLIB) Makefile: $(srcdir)/Makefile.in $(topdir)/config.status cd $(topdir) \ diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 43ef5e9c83..3c53741cf6 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -105,7 +105,7 @@ void do_restore(JCR *jcr) /* File Attributes stream */ if (stream == STREAM_UNIX_ATTRIBUTES) { - char *ap, *lp; + char *ap, *lp, *fp; Dmsg1(30, "Stream=Unix Attributes. extract=%d\n", extract); /* If extracting, it was from previous stream, so @@ -143,13 +143,12 @@ void do_restore(JCR *jcr) * Link name (if file linked i.e. FT_LNK) * */ - if (sscanf(sd->msg, "%d %d %s", &record_file_index, &type, fname) != 3) { + if (sscanf(sd->msg, "%d %d", &record_file_index, &type) != 2) { Jmsg(jcr, M_FATAL, 0, _("Error scanning record header: %s\n"), sd->msg); Dmsg0(0, "\nError scanning header\n"); goto bail_out; } - Dmsg3(30, "Got Attr: FilInx=%d type=%d fname=%s\n", record_file_index, - type, fname); + Dmsg2(30, "Got Attr: FilInx=%d type=%d\n", record_file_index, type); if (record_file_index != file_index) { Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"), file_index, record_file_index); @@ -157,10 +156,17 @@ void do_restore(JCR *jcr) goto bail_out; } ap = sd->msg; - /* Skip to attributes */ - while (*ap++ != 0) { + while (*ap++ != ' ') /* skip record file index */ ; + while (*ap++ != ' ') /* skip type */ + ; + /* Save filename and position to attributes */ + fp = fname; + while (*ap != 0) { + *fp++ = *ap++; } + *fp = *ap++; /* terminate filename & point to attribs */ + /* Skip to Link name */ if (type == FT_LNK) { lp = ap; diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index d70adadeae..42953586c7 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -196,7 +196,7 @@ void init_console_msg(char *wd) sprintf(con_fname, "%s/%s.conmsg", wd, my_name); fd = open(con_fname, O_CREAT|O_RDWR|O_BINARY, 0600); if (fd == -1) { - Emsg2(M_ABORT, 0, "Could not open console message file %s: ERR=%s\n", + Emsg2(M_TERM, 0, "Could not open console message file %s: ERR=%s\n", con_fname, strerror(errno)); } if (lseek(fd, 0, SEEK_END) > 0) { @@ -645,7 +645,7 @@ void dispatch_message(void *vjcr, int type, int level, char *msg) Dmsg2(200, "Enter dispatch_msg type=%d msg=%s\n", type, msg); - if (type == M_ABORT) { + if (type == M_ABORT || type == M_TERM) { fprintf(stdout, msg); /* print this here to INSURE that it is printed */ } @@ -755,7 +755,7 @@ void dispatch_message(void *vjcr, int type, int level, char *msg) break; case MD_STDOUT: Dmsg1(200, "STDOUT for following err: %s\n", msg); - if (type != M_ABORT && type != M_FATAL) /* already printed */ + if (type != M_ABORT && type != M_TERM) /* already printed */ fprintf(stdout, msg); break; case MD_STDERR: @@ -829,9 +829,9 @@ e_msg(char *file, int line, int type, int level, char *fmt,...) /* * Check if we have a message destination defined. - * We always report M_ABORT + * We always report M_ABORT and M_TERM */ - if (!daemon_msgs || (type != M_ABORT && + if (!daemon_msgs || ((type != M_ABORT && type != M_TERM) && !bit_is_set(type, daemon_msgs->send_msg))) return; /* no destination */ switch (type) { @@ -839,6 +839,10 @@ e_msg(char *file, int line, int type, int level, char *fmt,...) sprintf(buf, "%s ABORTING due to ERROR in %s:%d\n", my_name, file, line); break; + case M_TERM: + sprintf(buf, "%s TERMINATING due to ERROR in %s:%d\n", + my_name, file, line); + break; case M_FATAL: if (level == -1) /* skip details */ sprintf(buf, "%s: Fatal Error because: ", my_name); @@ -870,6 +874,9 @@ e_msg(char *file, int line, int type, int level, char *fmt,...) char *p = 0; p[0] = 0; /* generate segmentation violation */ } + if (type == M_TERM) { + _exit(1); + } } /* ********************************************************* @@ -908,9 +915,9 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...) buf = rbuf; /* we are the Director */ /* * Check if we have a message destination defined. - * We always report M_ABORT + * We always report M_ABORT and M_TERM */ - if (type != M_ABORT && msgs && !bit_is_set(type, msgs->send_msg)) { + if ((type != M_ABORT && type != M_TERM) && msgs && !bit_is_set(type, msgs->send_msg)) { Dmsg1(200, "No bit set for type %d\n", type); return; /* no destination */ } @@ -918,6 +925,9 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...) case M_ABORT: sprintf(buf, "%s ABORTING due to ERROR\n", my_name); break; + case M_TERM: + sprintf(buf, "%s TERMINATING due to ERROR\n", my_name); + break; case M_FATAL: sprintf(buf, "%s: Job %s Fatal error: ", my_name, job); if (jcr) { @@ -952,6 +962,9 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...) char *p = 0; p[0] = 0; /* generate segmentation violation */ } + if (type == M_TERM) { + _exit(1); + } } /* diff --git a/bacula/src/lib/signal.c b/bacula/src/lib/signal.c index 0b9fe5bc79..deefdb0401 100644 --- a/bacula/src/lib/signal.c +++ b/bacula/src/lib/signal.c @@ -68,7 +68,7 @@ static void signal_handler(int sig) } already_dead = sig; if (sig == SIGTERM) { - Emsg1(M_TERM, -1, "Shutting down Bacula service: %s ...\n", my_name); + Emsg1(M_INFO, -1, "Shutting down Bacula service: %s ...\n", my_name); } else { Emsg2(M_FATAL, -1, "Interrupted by signal %d: %s\n", sig, sig_names[sig]); } diff --git a/bacula/src/stored/Makefile.in b/bacula/src/stored/Makefile.in index 0500e1e6b6..8e479dd01b 100644 --- a/bacula/src/stored/Makefile.in +++ b/bacula/src/stored/Makefile.in @@ -66,7 +66,7 @@ all: Makefile bacula-sd bls bextract bscan btape @echo " " bacula-sd: $(SVROBJS) ../lib/libbac.a - $(CXX) $(LDFLAGS) -L../lib -o $@ $(SVROBJS) $(LIBS) $(DLIB) $(FDLIBS) -lbac -lm + $(CXX) $(LDFLAGS) -L../lib -o $@ $(SVROBJS) $(FDLIBS) -lbac -lm $(LIBS) $(DLIB) #bpool: $(POOLOBJS) ../lib/libbac.a ../cats/libsql.a # $(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ $(POOLOBJS) -lsql $(LIBS) $(DLIB) -lbac -lm diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 17e6dd570a..66834f6f12 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -63,6 +63,7 @@ int main (int argc, char *argv[]) int ch; FILE *fd; char line[1000]; + int got_inc = FALSE; my_name_is(argc, argv, "bextract"); init_msg(NULL, NULL); /* setup message handler */ @@ -104,6 +105,7 @@ int main (int argc, char *argv[]) add_fname_to_include_list(ff, 0, line); } fclose(fd); + got_inc = TRUE; break; case '?': @@ -119,6 +121,9 @@ int main (int argc, char *argv[]) Dmsg0(0, "Wrong number of arguments: \n"); usage(); } + if (!got_inc) { /* If no include file, */ + add_fname_to_include_list(ff, 0, "/"); /* include everything */ + } jcr = new_jcr(sizeof(JCR), my_free_jcr); jcr->VolSessionId = 1; @@ -264,7 +269,7 @@ static void do_extract(char *devname, char *where) /* File Attributes stream */ if (rec.Stream == STREAM_UNIX_ATTRIBUTES) { - char *ap, *lp; + char *ap, *lp, *fp; /* If extracting, it was from previous stream, so * close the output file. @@ -300,14 +305,22 @@ static void do_extract(char *devname, char *where) * Link name (if file linked i.e. FT_LNK) * */ - sscanf(rec.data, "%ld %d %s", &record_file_index, &type, fname); + sscanf(rec.data, "%ld %d", &record_file_index, &type); if (record_file_index != rec.FileIndex) Emsg2(M_ABORT, 0, "Record header file index %ld not equal record index %ld\n", rec.FileIndex, record_file_index); ap = rec.data; - /* Skip to attributes */ - while (*ap++ != 0) + while (*ap++ != ' ') /* skip record file index */ + ; + while (*ap++ != ' ') /* skip type */ ; + /* Save filename and position to attributes */ + fp = fname; + while (*ap != 0) { + *fp++ = *ap++; + } + *fp = *ap++; /* terminate filename & point to attribs */ + /* Skip to Link name */ if (type == FT_LNK) { lp = ap; diff --git a/bacula/src/version.h b/bacula/src/version.h index 8100d79869..05eef0520c 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.21" #define VSTRING "1" -#define DATE "3 June 2002" -#define LSMDATE "03Jun02" +#define DATE "11 June 2002" +#define LSMDATE "11Jun02" /* Debug flags */ #define DEBUG 1 -- 2.39.5