/* Imported functions */
extern int status_cmd(JCR *jcr);
-
+extern int qstatus_cmd(JCR *jcr);
+
/* Forward referenced functions */
static int backup_cmd(JCR *jcr);
static int bootstrap_cmd(JCR *jcr);
/* Exported functions */
struct s_cmds {
- char *cmd;
+ const char *cmd;
int (*func)(JCR *);
+ int monitoraccess; /* specify if monitors have access to this function */
};
/*
* The following are the recognized commands from the Director.
*/
static struct s_cmds cmds[] = {
- {"backup", backup_cmd},
- {"cancel", cancel_cmd},
- {"setdebug=", setdebug_cmd},
- {"estimate", estimate_cmd},
- {"exclude", exclude_cmd},
- {"Hello", hello_cmd},
- {"include", include_cmd},
- {"fileset", fileset_cmd},
- {"JobId=", job_cmd},
- {"level = ", level_cmd},
- {"restore", restore_cmd},
- {"session", session_cmd},
- {"status", status_cmd},
- {"storage ", storage_cmd},
- {"verify", verify_cmd},
- {"bootstrap", bootstrap_cmd},
- {"RunBeforeJob", runbefore_cmd},
- {"RunAfterJob", runafter_cmd},
+ {"backup", backup_cmd, 0},
+ {"cancel", cancel_cmd, 0},
+ {"setdebug=", setdebug_cmd, 0},
+ {"estimate", estimate_cmd, 0},
+ {"exclude", exclude_cmd, 0},
+ {"Hello", hello_cmd, 1},
+ {"include", include_cmd, 0},
+ {"fileset", fileset_cmd, 0},
+ {"JobId=", job_cmd, 0},
+ {"level = ", level_cmd, 0},
+ {"restore", restore_cmd, 0},
+ {"session", session_cmd, 0},
+ {"status", status_cmd, 1},
+ {".status", qstatus_cmd, 1},
+ {"storage ", storage_cmd, 0},
+ {"verify", verify_cmd, 0},
+ {"bootstrap", bootstrap_cmd, 0},
+ {"RunBeforeJob", runbefore_cmd, 0},
+ {"RunAfterJob", runafter_cmd, 0},
{NULL, NULL} /* list terminator */
};
/* Responses sent to Director */
static char errmsg[] = "2999 Invalid command\n";
static char no_auth[] = "2998 No Authorization\n";
+static char illegal_cmd[] = "2997 Illegal command for a Director with Monitor directive enabled\n";
static char OKinc[] = "2000 OK include\n";
static char OKest[] = "2000 OK estimate files=%u bytes=%s\n";
static char OKexc[] = "2000 OK exclude\n";
jcr->last_fname = get_pool_memory(PM_FNAME);
jcr->last_fname[0] = 0;
jcr->client_name = get_memory(strlen(my_name) + 1);
- pm_strcpy(&jcr->client_name, my_name);
+ pm_strcpy(jcr->client_name, my_name);
dir->jcr = jcr;
enable_backup_privileges(NULL, 1 /* ignore_errors */);
/* Read command */
if (bnet_recv(dir) < 0) {
- break; /* connection terminated */
+ break; /* connection terminated */
}
dir->msg[dir->msglen] = 0;
Dmsg1(100, "<dird: %s", dir->msg);
found = false;
for (i=0; cmds[i].cmd; i++) {
if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
+ found = true; /* indicate command found */
if (!jcr->authenticated && cmds[i].func != hello_cmd) {
bnet_fsend(dir, no_auth);
+ bnet_sig(dir, BNET_EOD);
+ break;
+ }
+ if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
+ Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
+ bnet_fsend(dir, illegal_cmd);
+ bnet_sig(dir, BNET_EOD);
break;
}
- found = true; /* indicate command found */
Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
- if (!cmds[i].func(jcr)) { /* do command */
- quit = true; /* error or fully terminated, get out */
+ if (!cmds[i].func(jcr)) { /* do command */
+ quit = true; /* error or fully terminated, get out */
Dmsg0(20, "Quit command loop due to command error or Job done.\n");
}
break;
}
}
- if (!found) { /* command not found */
+ if (!found) { /* command not found */
bnet_fsend(dir, errmsg);
quit = true;
break;
if (jcr->RunAfterJob && !job_canceled(jcr)) {
run_cmd(jcr, jcr->RunAfterJob, "ClientRunAfterJob");
}
+ dequeue_messages(jcr); /* send any queued messages */
/* Inform Director that we are done */
bnet_sig(dir, BNET_TERMINATE);
FF_PKT *ff = (FF_PKT *)jcr->ff;
findFILESET *fileset = ff->fileset;
if (fileset) {
- int i, j;
+ int i, j, k;
/* Delete FileSet Include lists */
for (i=0; i<fileset->include_list.size(); i++) {
findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
for (j=0; j<incexe->opts_list.size(); j++) {
findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+ for (k=0; k<fo->regex.size(); k++) {
+ regfree((regex_t *)fo->regex.get(k));
+ }
fo->regex.destroy();
fo->wild.destroy();
fo->base.destroy();
+ if (fo->reader) {
+ free(fo->reader);
+ }
+ if (fo->writer) {
+ free(fo->writer);
+ }
}
incexe->opts_list.destroy();
incexe->name_list.destroy();
return 0;
}
Dmsg0(120, "OK Authenticate\n");
- jcr->authenticated = TRUE;
+ jcr->authenticated = true;
return 1;
}
Dmsg1(110, "setdebug_cmd: %s", dir->msg);
if (sscanf(dir->msg, "setdebug=%d trace=%d", &level, &trace_flag) != 2 || level < 0) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
bnet_fsend(dir, "2991 Bad setdebug command: %s\n", jcr->errmsg);
return 0;
}
char ed2[50];
if (sscanf(dir->msg, estimatecmd, &jcr->listing) != 1) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_FATAL, 0, _("Bad estimate command: %s"), jcr->errmsg);
bnet_fsend(dir, "2992 Bad estimate command.\n");
return 0;
if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
&jcr->VolSessionId, &jcr->VolSessionTime,
sd_auth_key) != 5) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg);
bnet_fsend(dir, BADjob);
free_pool_memory(sd_auth_key);
Dmsg1(100, "runbefore_cmd: %s", dir->msg);
if (sscanf(dir->msg, runbefore, cmd) != 1) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad RunBeforeJob command: %s\n"), jcr->errmsg);
bnet_fsend(dir, "2905 Bad RunBeforeJob command.\n");
free_memory(cmd);
Dmsg1(100, "runafter_cmd: %s", dir->msg);
if (sscanf(dir->msg, runafter, msg) != 1) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad RunAfter command: %s\n"), jcr->errmsg);
bnet_fsend(dir, "2905 Bad RunAfterJob command.\n");
free_memory(msg);
free_pool_memory(jcr->RunAfterJob);
}
jcr->RunAfterJob = get_pool_memory(PM_FNAME);
- pm_strcpy(&jcr->RunAfterJob, msg);
+ pm_strcpy(jcr->RunAfterJob, msg);
free_pool_memory(msg);
return bnet_fsend(dir, OKRunAfter);
}
case '<':
p++; /* skip over < */
if ((ffd = fopen(p, "r")) == NULL) {
+ berrno be;
Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
- list==INC_LIST?"included":"excluded", p, strerror(errno));
+ list==INC_LIST?"included":"excluded", p, be.strerror());
return;
}
/* Copy File options */
case '<':
p++; /* skip over < */
if ((ffd = fopen(p, "r")) == NULL) {
+ berrno be;
Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
- p, strerror(errno));
+ p, be.strerror());
return;
}
while (fgets(buf, sizeof(buf), ffd)) {
break;
case 'R':
current_opts = start_options(ff);
- current_opts->regex.append(bstrdup(item));
+ regex_t *preg;
+ int rc;
+ char prbuf[500];
+ preg = (regex_t *)malloc(sizeof(regex_t));
+ rc = regcomp(preg, item, REG_EXTENDED);
+ if (rc != 0) {
+ regerror(rc, preg, prbuf, sizeof(prbuf));
+ regfree(preg);
+ free(preg);
+ Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
+ state = state_error;
+ break;
+ }
+ current_opts->regex.append(preg);
state = state_options;
break;
case 'B':
set_options(current_opts, item);
state = state_options;
break;
+ case 'D':
+ current_opts = start_options(ff);
+ current_opts->reader = bstrdup(item);
+ state = state_options;
+ break;
+ case 'T':
+ current_opts = start_options(ff);
+ current_opts->writer = bstrdup(item);
+ state = state_options;
+ break;
default:
Jmsg(jcr, M_FATAL, 0, "Invalid FileSet command: %s\n", item);
state = state_error;
for (k=0; k<fo->base.size(); k++) {
Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
}
+ if (fo->reader) {
+ Dmsg1(400, "D %s\n", fo->reader);
+ }
+ if (fo->writer) {
+ Dmsg1(400, "T %s\n", fo->writer);
+ }
}
for (j=0; j<incexe->name_list.size(); j++) {
Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
unlink(jcr->RestoreBootstrap);
free_pool_memory(jcr->RestoreBootstrap);
}
- Mmsg(&fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
+ Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
jcr->Job);
Dmsg1(400, "bootstrap=%s\n", fname);
jcr->RestoreBootstrap = fname;
bs = fopen(fname, "a+"); /* create file */
if (!bs) {
+ berrno be;
/*
* Suck up what he is sending to us so that he will then
* read our error message.
{ }
Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
- jcr->RestoreBootstrap, strerror(errno));
+ jcr->RestoreBootstrap, be.strerror());
free_pool_memory(jcr->RestoreBootstrap);
jcr->RestoreBootstrap = NULL;
set_jcr_job_status(jcr, JS_ErrorTerminated);
Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
jcr->incremental = 1; /* set incremental or decremental backup */
- jcr->mtime = since_time; /* set since time */
+ jcr->mtime = (time_t)since_time; /* set since time */
} else {
Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level);
free_memory(level);
return bnet_fsend(dir, OKlevel);
bail_out:
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad level command: %s\n"), jcr->errmsg);
free_memory(level);
if (buf) {
&jcr->VolSessionId, &jcr->VolSessionTime,
&jcr->StartFile, &jcr->EndFile,
&jcr->StartBlock, &jcr->EndBlock) != 7) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", jcr->errmsg);
return 0;
}
Dmsg1(100, "StorageCmd: %s", dir->msg);
if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), jcr->errmsg);
return 0;
}
Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
/* Open command communications with Storage daemon */
/* Try to connect for 1 hour at 10 second intervals */
- sd = bnet_connect(jcr, 10, me->SDConnectTimeout, _("Storage daemon"),
+ sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
jcr->stored_addr, NULL, stored_port, 1);
- Dmsg0(110, "Connection OK to SD.\n");
if (sd == NULL) {
Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
jcr->stored_addr, stored_port);
jcr->stored_addr, stored_port);
return 0;
}
+ Dmsg0(110, "Connection OK to SD.\n");
jcr->store_bsock = sd;
if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
- pm_strcpy(&jcr->errmsg, dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
return 0;
}
FILE *bs;
char buf[2000];
BSOCK *sd = jcr->store_bsock;
- char *bootstrap = "bootstrap\n";
+ const char *bootstrap = "bootstrap\n";
int stat = 0;
Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
}
bs = fopen(jcr->RestoreBootstrap, "r");
if (!bs) {
+ berrno be;
Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
- jcr->RestoreBootstrap, strerror(errno));
+ jcr->RestoreBootstrap, be.strerror());
set_jcr_job_status(jcr, JS_ErrorTerminated);
goto bail_out;
}
- pm_strcpy(&sd->msg, bootstrap);
- sd->msglen = strlen(sd->msg);
+ sd->msglen = pm_strcpy(sd->msg, bootstrap);
bnet_send(sd);
while (fgets(buf, sizeof(buf), bs)) {
- sd->msglen = Mmsg(&sd->msg, "%s", buf);
+ sd->msglen = Mmsg(sd->msg, "%s", buf);
bnet_send(sd);
}
bnet_sig(sd, BNET_EOD);