3 * Bacula Director -- User Agent Commands
4 * These are "dot" commands, i.e. commands preceded
5 * by a period. These commands are meant to be used
6 * by a program, so there is no prompting, and the
7 * returned results are (supposed to be) predictable.
9 * Kern Sibbald, April MMII
15 Copyright (C) 2002 Kern Sibbald and John Walker
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation; either version 2 of
20 the License, or (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public
28 License along with this program; if not, write to the Free
29 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
37 /* Imported variables */
40 extern struct s_res resources[];
41 extern char my_name[];
43 /* Imported functions */
44 extern int qmessagescmd(UAContext *ua, char *cmd);
45 extern int quit_cmd(UAContext *ua, char *cmd);
47 /* Forward referenced functions */
48 static int diecmd(UAContext *ua, char *cmd);
49 static int jobscmd(UAContext *ua, char *cmd);
50 static int filesetscmd(UAContext *ua, char *cmd);
51 static int clientscmd(UAContext *ua, char *cmd);
52 static int msgscmd(UAContext *ua, char *cmd);
53 static int poolscmd(UAContext *ua, char *cmd);
54 static int storagecmd(UAContext *ua, char *cmd);
55 static int defaultscmd(UAContext *ua, char *cmd);
56 static int typescmd(UAContext *ua, char *cmd);
57 static int levelscmd(UAContext *ua, char *cmd);
59 struct cmdstruct { char *key; int (*func)(UAContext *ua, char *cmd); char *help; };
60 static struct cmdstruct commands[] = {
61 { N_(".die"), diecmd, NULL},
62 { N_(".jobs"), jobscmd, NULL},
63 { N_(".filesets"), filesetscmd, NULL},
64 { N_(".clients"), clientscmd, NULL},
65 { N_(".msgs"), msgscmd, NULL},
66 { N_(".pools"), poolscmd, NULL},
67 { N_(".types"), typescmd, NULL},
68 { N_(".levels"), levelscmd, NULL},
69 { N_(".storage"), storagecmd, NULL},
70 { N_(".defaults"), defaultscmd, NULL},
71 { N_(".messages"), qmessagescmd, NULL},
72 { N_(".quit"), quit_cmd, NULL},
73 { N_(".exit"), quit_cmd, NULL}
75 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
78 * Execute a command from the UA
80 int do_a_dot_command(UAContext *ua, char *cmd)
89 Dmsg1(200, "Dot command: %s\n", ua->UA_sock->msg);
94 len = strlen(ua->argk[0]);
98 for (i=0; i<comsize; i++) { /* search for command */
99 if (strncasecmp(ua->argk[0], _(commands[i].key), len) == 0) {
100 stat = (*commands[i].func)(ua, cmd); /* go execute command */
106 strcat(ua->UA_sock->msg, _(": is an illegal command\n"));
107 ua->UA_sock->msglen = strlen(ua->UA_sock->msg);
108 bnet_send(ua->UA_sock);
114 * Create segmentation fault
116 static int diecmd(UAContext *ua, char *cmd)
121 bsendmsg(ua, "The Director will segment fault.\n");
122 a = jcr->JobId; /* ref NULL pointer */
123 jcr->JobId = 1000; /* another ref NULL pointer */
127 static int jobscmd(UAContext *ua, char *cmd)
131 while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) {
132 bsendmsg(ua, "%s\n", job->hdr.name);
138 static int filesetscmd(UAContext *ua, char *cmd)
142 while ( (fs = (FILESET *)GetNextRes(R_FILESET, (RES *)fs)) ) {
143 bsendmsg(ua, "%s\n", fs->hdr.name);
149 static int clientscmd(UAContext *ua, char *cmd)
151 CLIENT *client = NULL;
153 while ( (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)) ) {
154 bsendmsg(ua, "%s\n", client->hdr.name);
160 static int msgscmd(UAContext *ua, char *cmd)
164 while ( (msgs = (MSGS *)GetNextRes(R_MSGS, (RES *)msgs)) ) {
165 bsendmsg(ua, "%s\n", msgs->hdr.name);
171 static int poolscmd(UAContext *ua, char *cmd)
175 while ( (pool = (POOL *)GetNextRes(R_POOL, (RES *)pool)) ) {
176 bsendmsg(ua, "%s\n", pool->hdr.name);
182 static int storagecmd(UAContext *ua, char *cmd)
186 while ( (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)) ) {
187 bsendmsg(ua, "%s\n", store->hdr.name);
194 static int typescmd(UAContext *ua, char *cmd)
196 bsendmsg(ua, "Backup\n");
197 bsendmsg(ua, "Restore\n");
198 bsendmsg(ua, "Admin\n");
199 bsendmsg(ua, "Verify\n");
203 static int levelscmd(UAContext *ua, char *cmd)
205 bsendmsg(ua, "Incremental\n");
206 bsendmsg(ua, "Full\n");
207 bsendmsg(ua, "Differential\n");
208 bsendmsg(ua, "Catalog\n");
209 bsendmsg(ua, "InitCatalog\n");
210 bsendmsg(ua, "VolumeToCatalog\n");
217 * Return default values for a job
219 static int defaultscmd(UAContext *ua, char *cmd)
222 if (ua->argc == 2 && strcmp(ua->argk[1], "job") == 0) {
223 job = (JOB *)GetResWithName(R_JOB, ua->argv[1]);
225 bsendmsg(ua, "job=%s", job->hdr.name);
226 bsendmsg(ua, "pool=%s", job->pool->hdr.name);
227 bsendmsg(ua, "messages=%s", job->messages->hdr.name);
228 bsendmsg(ua, "client=%s", job->client->hdr.name);
229 bsendmsg(ua, "storage=%s", job->storage->hdr.name);
230 bsendmsg(ua, "where=%s", job->RestoreWhere?job->RestoreWhere:"");
231 bsendmsg(ua, "level=%s", level_to_str(job->level));
232 bsendmsg(ua, "type=%s", job_type_to_str(job->JobType));
233 bsendmsg(ua, "fileset=%s", job->fileset->hdr.name);