]> git.sur5r.net Git - bacula/bacula/commitdiff
Check some user inputs in purge and restore commands
authorEric Bollengier <eric@eb.homelinux.org>
Mon, 7 Feb 2011 18:04:47 +0000 (19:04 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:40:02 +0000 (14:40 +0200)
bacula/src/dird/ua.h
bacula/src/dird/ua_purge.c
bacula/src/dird/ua_restore.c
bacula/src/dird/ua_server.c

index b8f01b94be0bfceb24f4410b9b147d8df66464f9..bd116985f5d40b37261283ae3dfa360c8b6085e7 100644 (file)
@@ -46,6 +46,7 @@ public:
    CONRES *cons;                      /* console resource */
    POOLMEM *cmd;                      /* return command/name buffer */
    POOLMEM *args;                     /* command line arguments */
+   POOLMEM *err;                      /* store error message */
    char *argk[MAX_CMD_ARGS];          /* argument keywords */
    char *argv[MAX_CMD_ARGS];          /* argument values */
    int argc;                          /* number of arguments */
index b17825713d663f3688af3add614dc3969e9677be..34856df34eebe6daecb358f735461843f7b3a3b5 100644 (file)
@@ -652,16 +652,19 @@ static int action_on_purge_cmd(UAContext *ua, const char *cmd)
       if (strcasecmp(ua->argk[i], NT_("allpools")) == 0) {
          allpools = true;
             
-      } else if (strcasecmp(ua->argk[i], NT_("volume")) == 0 && ua->argv[i]) {
+      } else if (strcasecmp(ua->argk[i], NT_("volume")) == 0 
+                 && is_name_valid(ua->argv[i], NULL)) {
          bstrncpy(mr.VolumeName, ua->argv[i], sizeof(mr.VolumeName));
 
-      } else if (strcasecmp(ua->argk[i], NT_("devicetype")) == 0 && ua->argv[i]) {
+      } else if (strcasecmp(ua->argk[i], NT_("devicetype")) == 0 
+                 && ua->argv[i]) {
          bstrncpy(mr.MediaType, ua->argv[i], sizeof(mr.MediaType));
          
       } else if (strcasecmp(ua->argk[i], NT_("drive")) == 0 && ua->argv[i]) {
          drive = atoi(ua->argv[i]);
 
-      } else if (strcasecmp(ua->argk[i], NT_("action")) == 0 && ua->argv[i]) {
+      } else if (strcasecmp(ua->argk[i], NT_("action")) == 0 
+                 && is_name_valid(ua->argv[i], NULL)) {
          action=ua->argv[i];
       }
    }
index 49176f92fd281b2a7226ffa1cf3cdecf911df322..2802cc5a8a7d0dff72dd354911a9b7237f3d772e 100644 (file)
@@ -371,7 +371,8 @@ static int get_client_name(UAContext *ua, RESTORE_CTX *rx)
          i = find_arg_with_value(ua, NT_("backupclient"));
       }
       if (i >= 0) {
-         if (!has_value(ua, i)) {
+         if (!is_name_valid(ua->argv[i], &ua->err)) {
+            ua->error_msg("%s argument: %s", ua->argk[i], ua->err);
             return 0;
          }
          bstrncpy(rx->ClientName, ua->argv[i], sizeof(rx->ClientName));
@@ -397,7 +398,8 @@ static int get_restore_client_name(UAContext *ua, RESTORE_CTX &rx)
    /* try command line argument */
    int i = find_arg_with_value(ua, NT_("restoreclient"));
    if (i >= 0) {
-      if (!has_value(ua, i)) {
+      if (!is_name_valid(ua->argv[i], &ua->err)) {
+         ua->error_msg("%s argument: %s", ua->argk[i], ua->err);
          return 0;
       }
       bstrncpy(rx.RestoreClientName, ua->argv[i], sizeof(rx.RestoreClientName));
@@ -1276,14 +1278,18 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
     */
    memset(&fsr, 0, sizeof(fsr));
    i = find_arg_with_value(ua, "FileSet");
-   if (i >= 0) {
+
+   if (i >= 0 && is_name_valid(ua->argv[i], &ua->err)) {
       bstrncpy(fsr.FileSet, ua->argv[i], sizeof(fsr.FileSet));
       if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
          ua->error_msg(_("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet,
             db_strerror(ua->db));
          i = -1;
       }
+   } else if (i >= 0) {         /* name is invalid */
+      ua->error_msg(_("FileSet argument: %s\n"), ua->err);
    }
+
    if (i < 0) {                       /* fileset not found */
       edit_int64(cr.ClientId, ed1);
       Mmsg(rx->query, uar_sel_fileset, ed1, ed1);
index a7580f244a19438049e9549ff83f70b45b65c796..71b729249f4ae2eb01d0314ea6bddc3515106fdb 100644 (file)
@@ -195,6 +195,7 @@ UAContext *new_ua_context(JCR *jcr)
    ua->db = jcr->db;
    ua->cmd = get_pool_memory(PM_FNAME);
    ua->args = get_pool_memory(PM_FNAME);
+   ua->err = get_pool_memory(PM_FNAME);
    ua->verbose = true;
    ua->automount = true;
    return ua;
@@ -208,10 +209,12 @@ void free_ua_context(UAContext *ua)
    if (ua->args) {
       free_pool_memory(ua->args);
    }
+   if (ua->err) {
+      free_pool_memory(ua->err);
+   }
    if (ua->prompt) {
       free(ua->prompt);
    }
-
    if (ua->UA_sock) {
       bnet_close(ua->UA_sock);
       ua->UA_sock = NULL;