From c11f9314622fb39b11aa4a51600b925c3d7ece97 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 7 Feb 2011 19:04:47 +0100 Subject: [PATCH] Check some user inputs in purge and restore commands --- bacula/src/dird/ua.h | 1 + bacula/src/dird/ua_purge.c | 9 ++++++--- bacula/src/dird/ua_restore.c | 12 +++++++++--- bacula/src/dird/ua_server.c | 5 ++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/bacula/src/dird/ua.h b/bacula/src/dird/ua.h index b8f01b94be..bd116985f5 100644 --- a/bacula/src/dird/ua.h +++ b/bacula/src/dird/ua.h @@ -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 */ diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index b17825713d..34856df34e 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -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]; } } diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 49176f92fd..2802cc5a8a 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -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); diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index a7580f244a..71b729249f 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -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; -- 2.39.5