From 0951a40eb853fdeba338887b66d94a7a89995109 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 1 Feb 2008 12:31:31 +0000 Subject: [PATCH] First cut plugin directives. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6355 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird_conf.c | 14 +++ bacula/src/dird/dird_conf.h | 4 +- bacula/src/dird/fd_cmds.c | 201 ++++++++++++++++++++---------------- bacula/src/dird/inc_conf.c | 60 +++++++++++ bacula/src/filed/job.c | 40 +++++-- bacula/src/findlib/find.h | 1 + bacula/technotes-2.3 | 2 + 7 files changed, 225 insertions(+), 97 deletions(-) diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 0b36d6d34a..9817cc9038 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -745,6 +745,9 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm for (k=0; kdrivetype.size(); k++) { sendit(sock, " XD %s\n", fo->drivetype.get(k)); } + if (fo->plugin) { + sendit(sock, " G %s\n", fo->plugin); + } if (fo->reader) { sendit(sock, " D %s\n", fo->reader); } @@ -759,6 +762,13 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm if (incexe->name_list.size()) { sendit(sock, " N\n"); } + for (j=0; jplugin_list.size(); j++) { + sendit(sock, " P %s\n", incexe->plugin_list.get(j)); + } + if (incexe->plugin_list.size()) { + sendit(sock, " N\n"); + } + } for (i=0; ires_fs.num_excludes; i++) { @@ -936,6 +946,7 @@ next_run: static void free_incexe(INCEXE *incexe) { incexe->name_list.destroy(); + incexe->plugin_list.destroy(); for (int i=0; inum_opts; i++) { FOPTS *fopt = incexe->opts_list[i]; fopt->regex.destroy(); @@ -948,6 +959,9 @@ static void free_incexe(INCEXE *incexe) fopt->base.destroy(); fopt->fstype.destroy(); fopt->drivetype.destroy(); + if (fopt->plugin) { + free(fopt->plugin); + } if (fopt->reader) { free(fopt->reader); } diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index dffce56428..250b4abd81 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -442,6 +442,7 @@ struct FOPTS { alist drivetype; /* drive type limitation */ char *reader; /* reader program */ char *writer; /* writer program */ + char *plugin; /* plugin program */ }; @@ -451,6 +452,7 @@ struct INCEXE { FOPTS **opts_list; /* options list */ int num_opts; /* number of options items */ alist name_list; /* filename list -- holds char * */ + alist plugin_list; /* filename list for plugins */ }; /* diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 7479a73056..6c032fb54f 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -62,6 +62,7 @@ static char OKRunScript[] = "2000 OK RunScript\n"; static char OKRunBeforeNow[] = "2000 OK RunBeforeNow\n"; /* Forward referenced functions */ +static bool send_list_item(JCR *jcr, const char *code, char *item, BSOCK *fd); /* External functions */ extern DIRRES *director; @@ -216,7 +217,7 @@ static void send_since_time(JCR *jcr) char ed1[50]; stime = str_to_utime(jcr->stime); - bnet_fsend(fd, levelcmd, NT_("since_utime "), edit_uint64(stime, ed1), 0); + fd->fsend(levelcmd, NT_("since_utime "), edit_uint64(stime, ed1), 0); while (bget_dirmsg(fd) >= 0) { /* allow him to poll us to sync clocks */ Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg); } @@ -235,19 +236,19 @@ bool send_level_command(JCR *jcr) */ switch (jcr->JobLevel) { case L_BASE: - bnet_fsend(fd, levelcmd, "base", " ", 0); + fd->fsend(levelcmd, "base", " ", 0); break; /* L_NONE is the console, sending something off to the FD */ case L_NONE: case L_FULL: - bnet_fsend(fd, levelcmd, "full", " ", 0); + fd->fsend(levelcmd, "full", " ", 0); break; case L_DIFFERENTIAL: - bnet_fsend(fd, levelcmd, "differential", " ", 0); + fd->fsend(levelcmd, "differential", " ", 0); send_since_time(jcr); break; case L_INCREMENTAL: - bnet_fsend(fd, levelcmd, "incremental", " ", 0); + fd->fsend(levelcmd, "incremental", " ", 0); send_since_time(jcr); break; case L_SINCE: @@ -280,24 +281,20 @@ static bool send_fileset(JCR *jcr) num = fileset->num_excludes; } for (int i=0; iinclude_items[i]; - bnet_fsend(fd, "I\n"); + fd->fsend("I\n"); } else { ie = fileset->exclude_items[i]; - bnet_fsend(fd, "E\n"); + fd->fsend("E\n"); } for (j=0; jnum_opts; j++) { FOPTS *fo = ie->opts_list[j]; - bnet_fsend(fd, "O %s\n", fo->opts); + fd->fsend("O %s\n", fo->opts); bool enhanced_wild = false; for (k=0; fo->opts[k]!='\0'; k++) { @@ -308,110 +305,61 @@ static bool send_fileset(JCR *jcr) } for (k=0; kregex.size(); k++) { - bnet_fsend(fd, "R %s\n", fo->regex.get(k)); + fd->fsend("R %s\n", fo->regex.get(k)); } for (k=0; kregexdir.size(); k++) { - bnet_fsend(fd, "RD %s\n", fo->regexdir.get(k)); + fd->fsend("RD %s\n", fo->regexdir.get(k)); } for (k=0; kregexfile.size(); k++) { - bnet_fsend(fd, "RF %s\n", fo->regexfile.get(k)); + fd->fsend("RF %s\n", fo->regexfile.get(k)); } for (k=0; kwild.size(); k++) { - bnet_fsend(fd, "W %s\n", fo->wild.get(k)); + fd->fsend("W %s\n", fo->wild.get(k)); } for (k=0; kwilddir.size(); k++) { - bnet_fsend(fd, "WD %s\n", fo->wilddir.get(k)); + fd->fsend("WD %s\n", fo->wilddir.get(k)); } for (k=0; kwildfile.size(); k++) { - bnet_fsend(fd, "WF %s\n", fo->wildfile.get(k)); + fd->fsend("WF %s\n", fo->wildfile.get(k)); } for (k=0; kwildbase.size(); k++) { - bnet_fsend(fd, "W%c %s\n", enhanced_wild ? 'B' : 'F', fo->wildbase.get(k)); + fd->fsend("W%c %s\n", enhanced_wild ? 'B' : 'F', fo->wildbase.get(k)); } for (k=0; kbase.size(); k++) { - bnet_fsend(fd, "B %s\n", fo->base.get(k)); + fd->fsend("B %s\n", fo->base.get(k)); } for (k=0; kfstype.size(); k++) { - bnet_fsend(fd, "X %s\n", fo->fstype.get(k)); + fd->fsend("X %s\n", fo->fstype.get(k)); } for (k=0; kdrivetype.size(); k++) { - bnet_fsend(fd, "XD %s\n", fo->drivetype.get(k)); + fd->fsend("XD %s\n", fo->drivetype.get(k)); + } + if (fo->plugin) { + fd->fsend("G %s\n", fo->plugin); } if (fo->reader) { - bnet_fsend(fd, "D %s\n", fo->reader); + fd->fsend("D %s\n", fo->reader); } if (fo->writer) { - bnet_fsend(fd, "T %s\n", fo->writer); + fd->fsend("T %s\n", fo->writer); } - bnet_fsend(fd, "N\n"); + fd->fsend("N\n"); } for (j=0; jname_list.size(); j++) { - p = (char *)ie->name_list.get(j); - switch (*p) { - case '|': - p++; /* skip over the | */ - fd->msg = edit_job_codes(jcr, fd->msg, p, ""); - bpipe = open_bpipe(fd->msg, 0, "r"); - if (!bpipe) { - berrno be; - Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"), - p, be.bstrerror()); - goto bail_out; - } - bstrncpy(buf, "F ", sizeof(buf)); - Dmsg1(500, "Opts=%s\n", buf); - optlen = strlen(buf); - while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) { - fd->msglen = Mmsg(fd->msg, "%s", buf); - Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg); - if (!bnet_send(fd)) { - Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); - goto bail_out; - } - } - if ((stat=close_bpipe(bpipe)) != 0) { - berrno be; - Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. ERR=%s\n"), - p, be.bstrerror(stat)); - goto bail_out; - } - break; - case '<': - p++; /* skip over < */ - if ((ffd = fopen(p, "rb")) == NULL) { - berrno be; - Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"), - p, be.bstrerror()); - goto bail_out; - } - bstrncpy(buf, "F ", sizeof(buf)); - Dmsg1(500, "Opts=%s\n", buf); - optlen = strlen(buf); - while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) { - fd->msglen = Mmsg(fd->msg, "%s", buf); - if (!bnet_send(fd)) { - Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); - goto bail_out; - } - } - fclose(ffd); - break; - case '\\': - p++; /* skip over \ */ - /* Note, fall through wanted */ - default: - pm_strcpy(fd->msg, "F "); - fd->msglen = pm_strcat(fd->msg, p); - Dmsg1(500, "Inc/Exc name=%s\n", fd->msg); - if (!bnet_send(fd)) { - Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); - goto bail_out; - } - break; + item = (char *)ie->name_list.get(j); + if (!send_list_item(jcr, "F ", item, fd)) { + goto bail_out; } } - bnet_fsend(fd, "N\n"); + fd->fsend("N\n"); + for (j=0; jplugin_list.size(); j++) { + item = (char *)ie->plugin_list.get(j); + if (!send_list_item(jcr, "P ", item, fd)) { + goto bail_out; + } + } + fd->fsend("N\n"); } if (!include) { /* If we just did excludes */ break; /* all done */ @@ -419,7 +367,7 @@ static bool send_fileset(JCR *jcr) include = false; /* Now do excludes */ } - bnet_sig(fd, BNET_EOD); /* end of data */ + fd->signal(BNET_EOD); /* end of data */ if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) { goto bail_out; } @@ -431,6 +379,79 @@ bail_out: } +static bool send_list_item(JCR *jcr, const char *code, char *item, BSOCK *fd) +{ + BPIPE *bpipe; + FILE *ffd; + char buf[2000]; + int optlen, stat; + char *p = item; + + switch (*p) { + case '|': + p++; /* skip over the | */ + fd->msg = edit_job_codes(jcr, fd->msg, p, ""); + bpipe = open_bpipe(fd->msg, 0, "r"); + if (!bpipe) { + berrno be; + Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"), + p, be.bstrerror()); + return false; + } + bstrncpy(buf, code, sizeof(buf)); + Dmsg1(500, "code=%s\n", buf); + optlen = strlen(buf); + while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) { + fd->msglen = Mmsg(fd->msg, "%s", buf); + Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg); + if (!bnet_send(fd)) { + Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); + return false; + } + } + if ((stat=close_bpipe(bpipe)) != 0) { + berrno be; + Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. ERR=%s\n"), + p, be.bstrerror(stat)); + return false; + } + break; + case '<': + p++; /* skip over < */ + if ((ffd = fopen(p, "rb")) == NULL) { + berrno be; + Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"), + p, be.bstrerror()); + return false; + } + bstrncpy(buf, code, sizeof(buf)); + Dmsg1(500, "code=%s\n", buf); + optlen = strlen(buf); + while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) { + fd->msglen = Mmsg(fd->msg, "%s", buf); + if (!bnet_send(fd)) { + Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); + return false; + } + } + fclose(ffd); + break; + case '\\': + p++; /* skip over \ */ + /* Note, fall through wanted */ + default: + pm_strcpy(fd->msg, code); + fd->msglen = pm_strcat(fd->msg, p); + Dmsg1(500, "Inc/Exc name=%s\n", fd->msg); + if (!fd->send()) { + Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); + return false; + } + break; + } + return true; +} + /* * Send include list to File daemon diff --git a/bacula/src/dird/inc_conf.c b/bacula/src/dird/inc_conf.c index dcf757622c..50fd28e777 100644 --- a/bacula/src/dird/inc_conf.c +++ b/bacula/src/dird/inc_conf.c @@ -53,8 +53,10 @@ static void store_fstype(LEX *lc, RES_ITEM *item, int index, int pass); static void store_drivetype(LEX *lc, RES_ITEM *item, int index, int pass); static void store_opts(LEX *lc, RES_ITEM *item, int index, int pass); static void store_fname(LEX *lc, RES_ITEM *item, int index, int pass); +static void store_plugin_name(LEX *lc, RES_ITEM *item, int index, int pass); static void options_res(LEX *lc, RES_ITEM *item, int index, int pass); static void store_base(LEX *lc, RES_ITEM *item, int index, int pass); +static void store_plugin(LEX *lc, RES_ITEM *item, int index, int pass); static void store_reader(LEX *lc, RES_ITEM *item, int index, int pass); static void store_writer(LEX *lc, RES_ITEM *item, int index, int pass); static void setup_current_opts(void); @@ -83,6 +85,7 @@ static INCEXE res_incexe; */ static RES_ITEM newinc_items[] = { {"file", store_fname, {0}, 0, 0, 0}, + {"plugin", store_plugin_name, {0}, 0, 0, 0}, {"options", options_res, {0}, 0, 0, 0}, {NULL, NULL, {0}, 0, 0, 0} }; @@ -112,6 +115,7 @@ static RES_ITEM options_items[] = { {"wildfile", store_wild, {0}, 2, 0, 0}, {"exclude", store_opts, {0}, 0, 0, 0}, {"aclsupport", store_opts, {0}, 0, 0, 0}, + {"plugin", store_plugin, {0}, 0, 0, 0}, {"reader", store_reader, {0}, 0, 0, 0}, {"writer", store_writer, {0}, 0, 0, 0}, {"ignorecase", store_opts, {0}, 0, 0, 0}, @@ -470,6 +474,22 @@ static void store_base(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); } +/* Store reader info */ +static void store_plugin(LEX *lc, RES_ITEM *item, int index, int pass) +{ + int token; + + token = lex_get_token(lc, T_NAME); + if (pass == 1) { + /* + * Pickup plugin command + */ + res_incexe.current_opts->plugin = bstrdup(lc->str); + } + scan_to_eol(lc); +} + + /* Store reader info */ static void store_reader(LEX *lc, RES_ITEM *item, int index, int pass) { @@ -632,6 +652,46 @@ static void store_fname(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); } +/* + * Store Filename info. Note, for minor efficiency reasons, we + * always increase the name buffer by 10 items because we expect + * to add more entries. + */ +static void store_plugin_name(LEX *lc, RES_ITEM *item, int index, int pass) +{ + int token; + INCEXE *incexe; + + token = lex_get_token(lc, T_SKIP_EOL); + if (pass == 1) { + /* Pickup Filename string + */ + switch (token) { + case T_IDENTIFIER: + case T_UNQUOTED_STRING: + if (strchr(lc->str, '\\')) { + scan_err1(lc, _("Backslash found. Use forward slashes or quote the string.: %s\n"), lc->str); + /* NOT REACHED */ + } + case T_QUOTED_STRING: + if (res_all.res_fs.have_MD5) { + MD5Update(&res_all.res_fs.md5c, (unsigned char *)lc->str, lc->str_len); + } + incexe = &res_incexe; + if (incexe->plugin_list.size() == 0) { + incexe->plugin_list.init(10, true); + } + incexe->plugin_list.append(bstrdup(lc->str)); + Dmsg1(900, "Add to plugin_list %s\n", lc->str); + break; + default: + scan_err1(lc, _("Expected a filename, got: %s"), lc->str); + } + } + scan_to_eol(lc); +} + + /* * Come here when Options seen in Include/Exclude diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index ef74a313c5..106bff14a8 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -322,6 +322,7 @@ void *handle_client_request(void *dirp) } incexe->opts_list.destroy(); incexe->name_list.destroy(); + incexe->plugin_list.destroy(); } fileset->include_list.destroy(); @@ -343,6 +344,7 @@ void *handle_client_request(void *dirp) } incexe->opts_list.destroy(); incexe->name_list.destroy(); + incexe->plugin_list.destroy(); } fileset->exclude_list.destroy(); free(fileset); @@ -631,7 +633,8 @@ static findFOPTS *start_options(FF_PKT *ff) * Add fname to include/exclude fileset list. First check for * | and < and if necessary perform command. */ -static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset) +static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset, + bool is_file) { char *p; BPIPE *bpipe; @@ -659,7 +662,11 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese free_pool_memory(fn); while (fgets(buf, sizeof(buf), bpipe->rfd)) { strip_trailing_junk(buf); - fileset->incexe->name_list.append(new_dlistString(buf)); + if (is_file) { + fileset->incexe->name_list.append(new_dlistString(buf)); + } else { + fileset->incexe->plugin_list.append(new_dlistString(buf)); + } } if ((stat=close_bpipe(bpipe)) != 0) { berrno be; @@ -680,12 +687,20 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese while (fgets(buf, sizeof(buf), ffd)) { strip_trailing_junk(buf); Dmsg1(100, "%s\n", buf); - fileset->incexe->name_list.append(new_dlistString(buf)); + if (is_file) { + fileset->incexe->name_list.append(new_dlistString(buf)); + } else { + fileset->incexe->plugin_list.append(new_dlistString(buf)); + } } fclose(ffd); break; default: - fileset->incexe->name_list.append(new_dlistString(fname)); + if (is_file) { + fileset->incexe->name_list.append(new_dlistString(fname)); + } else { + fileset->incexe->plugin_list.append(new_dlistString(fname)); + } break; } } @@ -736,6 +751,7 @@ static void add_fileset(JCR *jcr, const char *item) memset(fileset->incexe, 0, sizeof(findINCEXE)); fileset->incexe->opts_list.init(1, true); fileset->incexe->name_list.init(); /* for dlist; was 1,true for alist */ + fileset->incexe->plugin_list.init(); fileset->include_list.append(fileset->incexe); break; case 'E': @@ -744,15 +760,21 @@ static void add_fileset(JCR *jcr, const char *item) memset(fileset->incexe, 0, sizeof(findINCEXE)); fileset->incexe->opts_list.init(1, true); fileset->incexe->name_list.init(); + fileset->incexe->plugin_list.init(); fileset->exclude_list.append(fileset->incexe); break; case 'N': state = state_none; break; case 'F': - /* File item to either include/include list */ + /* File item to include or exclude list */ + state = state_include; + add_file_to_fileset(jcr, item, fileset, true); + break; + case 'P': + /* Plugin item to include list */ state = state_include; - add_file_to_fileset(jcr, item, fileset); + add_file_to_fileset(jcr, item, fileset, false); break; case 'R': current_opts = start_options(ff); @@ -892,6 +914,9 @@ static bool term_fileset(JCR *jcr) foreach_dlist(node, &incexe->name_list) { Dmsg1(400, "F %s\n", node->c_str()); } + foreach_dlist(node, &incexe->plugin_list) { + Dmsg1(400, "P %s\n", node->c_str()); + } } for (i=0; iexclude_list.size(); i++) { findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i); @@ -933,6 +958,9 @@ static bool term_fileset(JCR *jcr) foreach_dlist(node, incexe->name_list) { Dmsg1(400, "F %s\n", node->c_str()); } + foreach_dlist(node, &incexe->plugin_list) { + Dmsg1(400, "P %s\n", node->c_str()); + } } #endif return ff->fileset->state != state_error; diff --git a/bacula/src/findlib/find.h b/bacula/src/findlib/find.h index b646d16834..3dd02c0841 100644 --- a/bacula/src/findlib/find.h +++ b/bacula/src/findlib/find.h @@ -165,6 +165,7 @@ struct findINCEXE { findFOPTS *current_opts; /* points to current options structure */ alist opts_list; /* options list */ dlist name_list; /* filename list -- holds dlistString */ + dlist plugin_list; /* plugin list -- holds dlistString */ }; /* diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index b21eb75d89..68631766e6 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,8 @@ Technical notes on version 2.3 General: +01Feb08 +kes First cut plugin directives. 30Jan08 kes Apply patch from bug #1049 to prevent stripping the path on a symlink. -- 2.39.5