2 Bacula® - The Network Backup Solution
4 Copyright (C) 2001-2010 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
40 /* Imported variables */
43 /* Exported functions */
46 * If subprompt is set, we send a BNET_SUB_PROMPT signal otherwise
47 * send a BNET_TEXT_INPUT signal.
49 int get_cmd(UAContext *ua, const char *prompt, bool subprompt)
51 BSOCK *sock = ua->UA_sock;
55 if (!sock || ua->batch) { /* No UA or batch mode */
58 if (!subprompt && ua->api) {
59 sock->signal(BNET_TEXT_INPUT);
61 sock->fsend("%s", prompt);
62 if (!ua->api || subprompt) {
63 sock->signal(BNET_SUB_PROMPT);
67 if (stat == BNET_SIGNAL) {
68 continue; /* ignore signals */
70 if (is_bnet_stop(sock)) {
71 return 0; /* error or terminate */
73 pm_strcpy(ua->cmd, sock->msg);
74 strip_trailing_junk(ua->cmd);
75 if (strcmp(ua->cmd, ".messages") == 0) {
76 qmessagescmd(ua, ua->cmd);
78 /* Lone dot => break */
79 if (ua->cmd[0] == '.' && ua->cmd[1] == 0) {
88 * Get a positive integer
89 * Returns: false if failure
90 * true if success => value in ua->pint32_val
92 bool get_pint(UAContext *ua, const char *prompt)
99 if (!get_cmd(ua, prompt)) {
102 /* Kludge for slots blank line => 0 */
103 if (ua->cmd[0] == 0 && strncmp(prompt, _("Enter slot"), strlen(_("Enter slot"))) == 0) {
106 if (!is_a_number(ua->cmd)) {
107 ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd);
111 dval = strtod(ua->cmd, NULL);
112 if (errno != 0 || dval < 0) {
113 ua->warning_msg(_("Expected a positive integer, got: %s\n"), ua->cmd);
116 ua->pint32_val = (uint32_t)dval;
117 ua->int64_val = (int64_t)dval;
123 * Test a yes or no response
124 * Returns: false if failure
125 * true if success => ret == 1 for yes
128 bool is_yesno(char *val, int *ret)
131 if ((strcasecmp(val, _("yes")) == 0) ||
132 (strcasecmp(val, NT_("yes")) == 0))
135 } else if ((strcasecmp(val, _("no")) == 0) ||
136 (strcasecmp(val, NT_("no")) == 0))
147 * Gets a yes or no response
148 * Returns: false if failure
149 * true if success => ua->pint32_val == 1 for yes
150 * ua->pint32_val == 0 for no
152 bool get_yesno(UAContext *ua, const char *prompt)
158 if (ua->api) ua->UA_sock->signal(BNET_YESNO);
159 if (!get_cmd(ua, prompt)) {
162 len = strlen(ua->cmd);
163 if (len < 1 || len > 3) {
166 if (is_yesno(ua->cmd, &ret)) {
167 ua->pint32_val = ret;
170 ua->warning_msg(_("Invalid response. You must answer yes or no.\n"));
175 * Gets an Enabled value => 0, 1, 2, yes, no, archived
176 * Returns: 0, 1, 2 if OK
179 int get_enabled(UAContext *ua, const char *val)
183 if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "true") == 0) {
185 } else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "false") == 0) {
187 } else if (strcasecmp(val, "archived") == 0) {
192 if (Enabled < 0 || Enabled > 2) {
193 ua->error_msg(_("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n"));
199 void parse_ua_args(UAContext *ua)
201 parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);
205 * Check if the comment has legal characters
206 * If ua is non-NULL send the message
208 bool is_comment_legal(UAContext *ua, const char *name)
212 const char *forbid = "'<>&\\\"";
214 /* Restrict the characters permitted in the comment */
215 for (p=name; *p; p++) {
216 if (!strchr(forbid, (int)(*p))) {
220 ua->error_msg(_("Illegal character \"%c\" in a comment.\n"), *p);
225 if (len >= MAX_NAME_LENGTH) {
227 ua->error_msg(_("Comment too long.\n"));
233 ua->error_msg(_("Comment must be at least one character long.\n"));