X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Fua_input.c;h=d9e24f664158d02247b49abb3bca9de1e1e168ec;hb=3cd7f14201e385fe8025a58a07dd151bb27c13e3;hp=9a9382d3d03b542823d2703861faedec876f3f06;hpb=efc8794eb0ab2a15ff618bf3f8a8b5369271a5f5;p=bacula%2Fbacula diff --git a/bacula/src/dird/ua_input.c b/bacula/src/dird/ua_input.c index 9a9382d3d0..d9e24f6641 100644 --- a/bacula/src/dird/ua_input.c +++ b/bacula/src/dird/ua_input.c @@ -40,6 +40,7 @@ int get_cmd(UAContext *ua, char *prompt) { BSOCK *sock = ua->UA_sock; + int stat; ua->cmd[0] = 0; if (!sock) { /* No UA */ @@ -48,8 +49,12 @@ int get_cmd(UAContext *ua, char *prompt) bnet_fsend(sock, "%s", prompt); bnet_sig(sock, BNET_PROMPT); /* request more input */ for ( ;; ) { - if (bnet_recv(sock) < 0) { - return 0; + stat = bnet_recv(sock); + if (stat == BNET_SIGNAL) { + continue; /* ignore signals */ + } + if (is_bnet_stop(sock)) { + return 0; /* error or terminate */ } ua->cmd = check_pool_memory_size(ua->cmd, sock->msglen+1); bstrncpy(ua->cmd, sock->msg, sock->msglen+1); @@ -74,36 +79,40 @@ int get_cmd(UAContext *ua, char *prompt) char *next_arg(char **s) { char *p, *q, *n; + int in_quote = 0; - Dmsg1(400, "Next arg=%s\n", *s); /* skip past spaces to next arg */ for (p=*s; *p && *p == ' '; ) { p++; } - /* Determine start of argument */ - if (*p == '"') { - Dmsg0(400, "Start with quote.\n"); - for (n = q = ++p; *p && *p != '"'; ) { - if (*p == '\\') { - p++; + Dmsg1(400, "Next arg=%s\n", p); + for (n = q = p; *p ; ) { + if (*p == '\\') { + p++; + if (*p) { + *q++ = *p++; + } else { + *q++ = *p; } - *q++ = *p++; + continue; } - p++; /* skip terminating quote */ - for ( ; *p && *p != ' '; ) { - *q++ = *p++; - } - *q = 0; - } else { - /* Scan argment and terminate it */ - n = p; - for ( ; *p && *p != ' '; ) { + if (*p == '"') { /* start or end of quote */ + if (in_quote) { + p++; /* skip quote */ + in_quote = 0; + continue; + } + in_quote = 1; p++; + continue; } - if (*p == ' ') { - *p++ = 0; + if (!in_quote && *p == ' ') { /* end of field */ + p++; + break; } + *q++ = *p++; } + *q = 0; *s = p; Dmsg2(400, "End arg=%s next=%s\n", n, p); return n; @@ -131,7 +140,7 @@ char *next_arg(char **s) void parse_command_args(UAContext *ua) { - char *p, *n; + char *p, *q, *n; int i, len; len = strlen(ua->cmd) + 1; @@ -154,6 +163,17 @@ void parse_command_args(UAContext *ua) p = strchr(ua->argk[i], '='); if (p) { *p++ = 0; /* terminate keyword and point to value */ + /* Unquote quoted values */ + if (*p == '"') { + for (n = q = ++p; *p && *p != '"'; ) { + if (*p == '\\') { + p++; + } + *q++ = *p++; + } + *q = 0; /* terminate string */ + p = n; /* point to string */ + } if (strlen(p) > MAX_NAME_LENGTH-1) { p[MAX_NAME_LENGTH-1] = 0; /* truncate to max len */ }