]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/job.c
- Add a kludge to detect bad date/times, which cause a seg fault in
[bacula/bacula] / bacula / src / filed / job.c
index 84f602dc6588efe81dc8d5c0a0764aa00a0c8648..465ab44c428274c4d615c902a1e7cae334d866c0 100644 (file)
@@ -34,7 +34,8 @@ extern CLIENT *me;                  /* our client resource */
                        
 /* 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);
@@ -66,30 +67,32 @@ static void set_options(findFOPTS *fo, const char *opts);
 struct s_cmds {
    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 */
 };
 
@@ -107,6 +110,7 @@ static char runafter[]    = "RunAfterJob %s\n";
 /* 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";
@@ -173,7 +177,7 @@ void *handle_client_request(void *dirp)
    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 */);
 
@@ -183,27 +187,34 @@ void *handle_client_request(void *dirp)
 
       /* 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;
@@ -218,6 +229,7 @@ void *handle_client_request(void *dirp)
    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);
@@ -336,7 +348,7 @@ static int setdebug_cmd(JCR *jcr)
 
    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;   
    }
@@ -352,7 +364,7 @@ static int estimate_cmd(JCR *jcr)
    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;
@@ -376,7 +388,7 @@ static int job_cmd(JCR *jcr)
    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);
@@ -396,7 +408,7 @@ static int runbefore_cmd(JCR *jcr)
 
    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);
@@ -423,7 +435,7 @@ static int runafter_cmd(JCR *jcr)
 
    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);
@@ -434,7 +446,7 @@ static int runafter_cmd(JCR *jcr)
       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);
 }
@@ -1086,7 +1098,7 @@ static int level_cmd(JCR *jcr)
    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) {
@@ -1107,7 +1119,7 @@ static int session_cmd(JCR *jcr)
              &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;
    }
@@ -1128,7 +1140,7 @@ static int storage_cmd(JCR *jcr)
 
    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;
    }
@@ -1379,7 +1391,7 @@ static int restore_cmd(JCR *jcr)
 
    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;
       }
@@ -1579,8 +1591,7 @@ static int send_bootstrap_file(JCR *jcr)
       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);