]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_dotcmds.c
Fix bug #1268 Full Max Run Time cancels jobs (when Max Run Time = 0).
[bacula/bacula] / bacula / src / dird / ua_dotcmds.c
index 3bdd67d6c0f0ffb048576bb3932219f45c44601e..462d8ed27a3dbafceb513990983a9b6a2e1f8183 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2002-2009 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.
@@ -69,26 +69,26 @@ static bool sql_cmd(UAContext *ua, const char *cmd);
 static bool dot_quit_cmd(UAContext *ua, const char *cmd);
 static bool dot_help_cmd(UAContext *ua, const char *cmd);
 
-struct cmdstruct { const char *key; bool (*func)(UAContext *ua, const char *cmd); const char *help; };
-static struct cmdstruct commands[] = {
- { NT_(".api"),        api_cmd,        NULL},
- { NT_(".backups"),    backupscmd,     NULL},
- { NT_(".clients"),    clientscmd,     NULL},
- { NT_(".defaults"),   defaultscmd,    NULL},
- { NT_(".die"),        diecmd,         NULL},
- { NT_(".exit"),       dot_quit_cmd,   NULL},
- { NT_(".filesets"),   filesetscmd,    NULL},
- { NT_(".help"),       dot_help_cmd,   NULL},
- { NT_(".jobs"),       jobscmd,        NULL},
- { NT_(".levels"),     levelscmd,      NULL},
- { NT_(".messages"),   getmsgscmd,     NULL},
- { NT_(".msgs"),       msgscmd,        NULL},
- { NT_(".pools"),      poolscmd,       NULL},
- { NT_(".quit"),       dot_quit_cmd,   NULL},
- { NT_(".sql"),        sql_cmd,        NULL},
- { NT_(".status"),     dot_status_cmd, NULL},
- { NT_(".storage"),    storagecmd,     NULL},
- { NT_(".types"),      typescmd,       NULL
+struct cmdstruct { const char *key; bool (*func)(UAContext *ua, const char *cmd); const char *help;const bool use_in_rs;};
+static struct cmdstruct commands[] = { /* help */  /* can be used in runscript */
+ { NT_(".api"),        api_cmd,          NULL,       false},
+ { NT_(".backups"),    backupscmd,       NULL,       false},
+ { NT_(".clients"),    clientscmd,       NULL,       true},
+ { NT_(".defaults"),   defaultscmd,      NULL,       false},
+ { NT_(".die"),        diecmd,           NULL,       false},
+ { NT_(".exit"),       dot_quit_cmd,     NULL,       false},
+ { NT_(".filesets"),   filesetscmd,      NULL,       false},
+ { NT_(".help"),       dot_help_cmd,     NULL,       false},
+ { NT_(".jobs"),       jobscmd,          NULL,       true},
+ { NT_(".levels"),     levelscmd,        NULL,       false},
+ { NT_(".messages"),   getmsgscmd,       NULL,       false},
+ { NT_(".msgs"),       msgscmd,          NULL,       false},
+ { NT_(".pools"),      poolscmd,         NULL,       true},
+ { NT_(".quit"),       dot_quit_cmd,     NULL,       false},
+ { NT_(".sql"),        sql_cmd,          NULL,       false},
+ { NT_(".status"),     dot_status_cmd,   NULL,       false},
+ { NT_(".storage"),    storagecmd,       NULL,       true},
+ { NT_(".types"),      typescmd,         NULL,       false
              };
 #define comsize ((int)(sizeof(commands)/sizeof(struct cmdstruct)))
 
@@ -116,6 +116,11 @@ bool do_a_dot_command(UAContext *ua)
    }
    for (i=0; i<comsize; i++) {     /* search for command */
       if (strncasecmp(ua->argk[0],  _(commands[i].key), len) == 0) {
+         /* Check if this command is authorized in RunScript */
+         if (ua->runscript && !commands[i].use_in_rs) {
+            ua->error_msg(_("Can't use %s command in a runscript"), ua->argk[0]);
+            break;
+         }
          bool gui = ua->gui;
          /* Check if command permitted, but "quit" is always OK */
          if (strcmp(ua->argk[0], NT_(".quit")) != 0 &&
@@ -126,6 +131,7 @@ bool do_a_dot_command(UAContext *ua)
          ua->gui = true;
          if (ua->api) user->signal(BNET_CMD_BEGIN);
          ok = (*commands[i].func)(ua, ua->cmd);   /* go execute command */
+         if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
          ua->gui = gui;
          found = true;
          break;
@@ -136,7 +142,6 @@ bool do_a_dot_command(UAContext *ua)
       ua->error_msg("%s", user->msg);
       ok = false;
    }
-   if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
    return ok;
 }
 
@@ -463,6 +468,10 @@ static int sql_handler(void *ctx, int num_field, char **row)
    UAContext *ua = (UAContext *)ctx;
    POOL_MEM rows(PM_MESSAGE);
 
+   /* Check for nonsense */
+   if (num_field == 0 || row == NULL || row[0] == NULL) {
+      return 0;                       /* nothing returned */
+   }
    for (int i=0; num_field--; i++) {
       if (i == 0) {
          pm_strcpy(rows, NPRT(row[0]));