2 Bacula® - The Network Backup Solution
4 Copyright (C) 2001-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
30 * Bacula Director -- User Agent Input and scanning code
32 * Kern Sibbald, October MMI
41 /* Imported variables */
44 /* Exported functions */
47 * If subprompt is set, we send a BNET_SUB_PROMPT signal otherwise
48 * send a BNET_TEXT_INPUT signal.
50 int get_cmd(UAContext *ua, const char *prompt, bool subprompt)
52 BSOCK *sock = ua->UA_sock;
56 if (!sock || ua->batch) { /* No UA or batch mode */
60 sock->signal(BNET_TEXT_INPUT);
62 sock->fsend("%s", prompt);
64 sock->signal(BNET_SUB_PROMPT);
68 if (stat == BNET_SIGNAL) {
69 continue; /* ignore signals */
71 if (is_bnet_stop(sock)) {
72 return 0; /* error or terminate */
74 pm_strcpy(ua->cmd, sock->msg);
75 strip_trailing_junk(ua->cmd);
76 if (strcmp(ua->cmd, ".messages") == 0) {
77 qmessagescmd(ua, ua->cmd);
79 /* Lone dot => break */
80 if (ua->cmd[0] == '.' && ua->cmd[1] == 0) {
89 * Get a positive integer
90 * Returns: false if failure
91 * true if success => value in ua->pint32_val
93 bool get_pint(UAContext *ua, const char *prompt)
100 if (!get_cmd(ua, prompt)) {
103 /* Kludge for slots blank line => 0 */
104 if (ua->cmd[0] == 0 && strncmp(prompt, _("Enter slot"), strlen(_("Enter slot"))) == 0) {
107 if (!is_a_number(ua->cmd)) {
108 ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd);
112 dval = strtod(ua->cmd, NULL);
113 if (errno != 0 || dval < 0) {
114 ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd);
117 ua->pint32_val = (uint32_t)dval;
118 ua->int64_val = (int64_t)dval;
124 * Test a yes or no response
125 * Returns: false if failure
126 * true if success => ret == 1 for yes
129 bool is_yesno(char *val, int *ret)
132 if ((strcasecmp(val, _("yes")) == 0) ||
133 (strcasecmp(val, NT_("yes")) == 0))
136 } else if ((strcasecmp(val, _("no")) == 0) ||
137 (strcasecmp(val, NT_("no")) == 0))
148 * Gets a yes or no response
149 * Returns: false if failure
150 * true if success => ua->pint32_val == 1 for yes
151 * ua->pint32_val == 0 for no
153 bool get_yesno(UAContext *ua, const char *prompt)
159 if (ua->api) ua->UA_sock->signal(BNET_YESNO);
160 if (!get_cmd(ua, prompt)) {
163 len = strlen(ua->cmd);
164 if (len < 1 || len > 3) {
167 if (is_yesno(ua->cmd, &ret)) {
168 ua->pint32_val = ret;
171 ua->warning_msg(_("Invalid response. You must answer yes or no.\n"));
176 * Gets an Enabled value => 0, 1, 2, yes, no, archived
177 * Returns: 0, 1, 2 if OK
180 int get_enabled(UAContext *ua, const char *val)
184 if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "true") == 0) {
186 } else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "false") == 0) {
188 } else if (strcasecmp(val, "archived") == 0) {
193 if (Enabled < 0 || Enabled > 2) {
194 ua->error_msg(_("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n"));
200 void parse_ua_args(UAContext *ua)
202 parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);
206 * Check if the comment has legal characters
207 * If ua is non-NULL send the message
209 bool is_comment_legal(UAContext *ua, const char *name)
213 const char *forbid = "'<>&\\\"";
215 /* Restrict the characters permitted in the comment */
216 for (p=name; *p; p++) {
217 if (!strchr(forbid, (int)(*p))) {
221 ua->error_msg(_("Illegal character \"%c\" in a comment.\n"), *p);
226 if (len >= MAX_NAME_LENGTH) {
228 ua->error_msg(_("Comment too long.\n"));
234 ua->error_msg(_("Comment must be at least one character long.\n"));