X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Fua_input.c;h=d9e24f664158d02247b49abb3bca9de1e1e168ec;hb=3cd7f14201e385fe8025a58a07dd151bb27c13e3;hp=7aa673016045b70da17eb45b5c0d2cc0633af224;hpb=5483b82f16f28424ca126db50f7bf71e53023e3e;p=bacula%2Fbacula diff --git a/bacula/src/dird/ua_input.c b/bacula/src/dird/ua_input.c index 7aa6730160..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,10 +49,14 @@ 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 */ } - ua->cmd = (char *) check_pool_memory_size(ua->cmd, sock->msglen+1); + 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); strip_trailing_junk(ua->cmd); if (strcmp(ua->cmd, ".messages") == 0) { @@ -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++; - } - p++; /* skip terminating quote */ - for ( ; *p && *p != ' '; ) { - *q++ = *p++; + continue; } - *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,12 +140,12 @@ char *next_arg(char **s) void parse_command_args(UAContext *ua) { - BSOCK *sock = ua->UA_sock; - char *p, *n; - int i; + char *p, *q, *n; + int i, len; - ua->args = (char *) check_pool_memory_size(ua->args, sock->msglen+1); - bstrncpy(ua->args, sock->msg, sock->msglen+1); + len = strlen(ua->cmd) + 1; + ua->args = check_pool_memory_size(ua->args, len); + bstrncpy(ua->args, ua->cmd, len); strip_trailing_junk(ua->args); ua->argc = 0; p = ua->args; @@ -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 */ }