]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/dird_conf.c
Implement new Include/Exclude + fix segfaults in variable expansion + print warning...
[bacula/bacula] / bacula / src / dird / dird_conf.c
1 /*
2  *   Main configuration file parser for Bacula Directors,
3  *    some parts may be split into separate files such as
4  *    the schedule configuration (run_config.c).
5  *
6  *   Note, the configuration file parser consists of three parts
7  *
8  *   1. The generic lexical scanner in lib/lex.c and lib/lex.h
9  *
10  *   2. The generic config  scanner in lib/parse_config.c and 
11  *      lib/parse_config.h.
12  *      These files contain the parser code, some utility
13  *      routines, and the common store routines (name, int,
14  *      string).
15  *
16  *   3. The daemon specific file, which contains the Resource
17  *      definitions as well as any specific store routines
18  *      for the resource records.
19  *
20  *     Kern Sibbald, January MM
21  *
22  *     Version $Id$
23  */
24 /*
25    Copyright (C) 2000-2003 Kern Sibbald and John Walker
26
27    This program is free software; you can redistribute it and/or
28    modify it under the terms of the GNU General Public License as
29    published by the Free Software Foundation; either version 2 of
30    the License, or (at your option) any later version.
31
32    This program is distributed in the hope that it will be useful,
33    but WITHOUT ANY WARRANTY; without even the implied warranty of
34    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35    General Public License for more details.
36
37    You should have received a copy of the GNU General Public
38    License along with this program; if not, write to the Free
39    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
40    MA 02111-1307, USA.
41
42  */
43
44 #include "bacula.h"
45 #include "dird.h"
46
47 /* Define the first and last resource ID record
48  * types. Note, these should be unique for each
49  * daemon though not a requirement.
50  */
51 int r_first = R_FIRST;
52 int r_last  = R_LAST;
53
54 pthread_mutex_t res_mutex =  PTHREAD_MUTEX_INITIALIZER;
55
56 /* Imported subroutines */
57 extern void store_run(LEX *lc, struct res_items *item, int index, int pass);
58 extern void store_finc(LEX *lc, struct res_items *item, int index, int pass);
59 extern void store_inc(LEX *lc, struct res_items *item, int index, int pass);
60
61
62 /* Forward referenced subroutines */
63
64 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
66 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
67 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
68 static void store_replace(LEX *lc, struct res_items *item, int index, int pass);
69
70
71 /* We build the current resource here as we are
72  * scanning the resource configuration definition,
73  * then move it to allocated memory when the resource
74  * scan is complete.
75  */
76 URES res_all;
77 int  res_all_size = sizeof(res_all);
78
79
80 /* Definition of records permitted within each
81  * resource with the routine to process the record 
82  * information.  NOTE! quoted names must be in lower case.
83  */ 
84 /* 
85  *    Director Resource
86  *
87  *   name          handler     value                 code flags    default_value
88  */
89 static struct res_items dir_items[] = {
90    {"name",        store_name,     ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
91    {"description", store_str,      ITEM(res_dir.hdr.desc), 0, 0, 0},
92    {"messages",    store_res,      ITEM(res_dir.messages), R_MSGS, 0, 0},
93    {"dirport",     store_pint,     ITEM(res_dir.DIRport),  0, ITEM_DEFAULT, 9101},
94    {"diraddress",  store_str,      ITEM(res_dir.DIRaddr),  0, 0, 0},
95    {"queryfile",   store_dir,      ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
96    {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
97    {"piddirectory",store_dir,     ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
98    {"subsysdirectory", store_dir,  ITEM(res_dir.subsys_directory), 0, 0, 0},
99    {"requiressl",  store_yesno,    ITEM(res_dir.require_ssl), 1, ITEM_DEFAULT, 0},
100    {"enablessl",   store_yesno,    ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
101    {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
102    {"password",    store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
103    {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
104    {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
105    {NULL, NULL, NULL, 0, 0, 0}
106 };
107
108 /* 
109  *    Console Resource
110  *
111  *   name          handler     value                 code flags    default_value
112  */
113 static struct res_items con_items[] = {
114    {"name",        store_name,     ITEM(res_con.hdr.name), 0, ITEM_REQUIRED, 0},
115    {"description", store_str,      ITEM(res_con.hdr.desc), 0, 0, 0},
116    {"enablessl",   store_yesno,    ITEM(res_con.enable_ssl), 1, ITEM_DEFAULT, 0},
117    {"password",    store_password, ITEM(res_con.password), 0, ITEM_REQUIRED, 0},
118    {NULL, NULL, NULL, 0, 0, 0}
119 };
120
121
122 /* 
123  *    Client or File daemon resource
124  *
125  *   name          handler     value                 code flags    default_value
126  */
127
128 static struct res_items cli_items[] = {
129    {"name",     store_name,       ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
130    {"description", store_str,     ITEM(res_client.hdr.desc), 0, 0, 0},
131    {"address",  store_str,        ITEM(res_client.address),  0, ITEM_REQUIRED, 0},
132    {"fdport",   store_pint,       ITEM(res_client.FDport),   0, ITEM_DEFAULT, 9102},
133    {"password", store_password,   ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
134    {"catalog",  store_res,        ITEM(res_client.catalog),  R_CATALOG, 0, 0},
135    {"fileretention", store_time,  ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
136    {"jobretention",  store_time,  ITEM(res_client.JobRetention),  0, ITEM_DEFAULT, 60*60*24*180},
137    {"autoprune", store_yesno,     ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
138    {"enablessl", store_yesno,     ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
139    {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
140    {NULL, NULL, NULL, 0, 0, 0} 
141 };
142
143 /* Storage daemon resource
144  *
145  *   name          handler     value                 code flags    default_value
146  */
147 static struct res_items store_items[] = {
148    {"name",      store_name,     ITEM(res_store.hdr.name),   0, ITEM_REQUIRED, 0},
149    {"description", store_str,    ITEM(res_store.hdr.desc),   0, 0, 0},
150    {"sdport",    store_pint,     ITEM(res_store.SDport),     0, ITEM_DEFAULT, 9103},
151    {"sddport",   store_pint,     ITEM(res_store.SDDport),    0, 0, 0}, /* deprecated */
152    {"address",   store_str,      ITEM(res_store.address),    0, ITEM_REQUIRED, 0},
153    {"password",  store_password, ITEM(res_store.password),   0, ITEM_REQUIRED, 0},
154    {"device",    store_strname,  ITEM(res_store.dev_name),   0, ITEM_REQUIRED, 0},
155    {"mediatype", store_strname,  ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
156    {"autochanger", store_yesno,  ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
157    {"enablessl", store_yesno,    ITEM(res_store.enable_ssl),  1, ITEM_DEFAULT, 0},
158    {"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
159    {NULL, NULL, NULL, 0, 0, 0} 
160 };
161
162 /* 
163  *    Catalog Resource Directives
164  *
165  *   name          handler     value                 code flags    default_value
166  */
167 static struct res_items cat_items[] = {
168    {"name",     store_name,     ITEM(res_cat.hdr.name),    0, ITEM_REQUIRED, 0},
169    {"description", store_str,   ITEM(res_cat.hdr.desc),    0, 0, 0},
170    {"address",  store_str,      ITEM(res_cat.db_address),  0, 0, 0},
171    {"dbaddress", store_str,     ITEM(res_cat.db_address),  0, 0, 0},
172    {"dbport",   store_pint,     ITEM(res_cat.db_port),      0, 0, 0},
173    /* keep this password as store_str for the moment */
174    {"password", store_str,      ITEM(res_cat.db_password), 0, 0, 0},
175    {"user",     store_str,      ITEM(res_cat.db_user),     0, 0, 0},
176    {"dbname",   store_str,      ITEM(res_cat.db_name),     0, ITEM_REQUIRED, 0},
177    {"dbsocket", store_str,      ITEM(res_cat.db_socket),   0, 0, 0}, 
178    {NULL, NULL, NULL, 0, 0, 0} 
179 };
180
181 /* 
182  *    Job Resource Directives
183  *
184  *   name          handler     value                 code flags    default_value
185  */
186 static struct res_items job_items[] = {
187    {"name",     store_name,    ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
188    {"description", store_str,  ITEM(res_job.hdr.desc), 0, 0, 0},
189    {"backup",   store_backup,  ITEM(res_job),          JT_BACKUP, 0, 0},
190    {"verify",   store_backup,  ITEM(res_job),          JT_VERIFY, 0, 0},
191    {"restore",  store_restore, ITEM(res_job),          JT_RESTORE, 0, 0},
192    {"schedule", store_res,     ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
193    {"type",     store_jobtype, ITEM(res_job),          0, 0, 0},
194    {"level",    store_level,   ITEM(res_job),          0, 0, 0},
195    {"messages", store_res,     ITEM(res_job.messages), R_MSGS, 0, 0},
196    {"storage",  store_res,     ITEM(res_job.storage),  R_STORAGE, 0, 0},
197    {"pool",     store_res,     ITEM(res_job.pool),     R_POOL, 0, 0},
198    {"client",   store_res,     ITEM(res_job.client),   R_CLIENT, 0, 0},
199    {"fileset",  store_res,     ITEM(res_job.fileset),  R_FILESET, 0, 0},
200    {"where",    store_dir,     ITEM(res_job.RestoreWhere), 0, 0, 0},
201    {"replace",  store_replace, ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS},
202    {"bootstrap",store_dir,     ITEM(res_job.RestoreBootstrap), 0, 0, 0},
203    {"maxruntime", store_time,  ITEM(res_job.MaxRunTime), 0, 0, 0},
204    {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
205    {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
206    {"prunejobs",   store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
207    {"prunefiles",  store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
208    {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
209    {"runbeforejob", store_str,  ITEM(res_job.RunBeforeJob), 0, 0, 0},
210    {"runafterjob",  store_str,  ITEM(res_job.RunAfterJob),  0, 0, 0},
211    {"clientrunbeforejob", store_str,  ITEM(res_job.ClientRunBeforeJob), 0, 0, 0},
212    {"clientrunafterjob",  store_str,  ITEM(res_job.ClientRunAfterJob),  0, 0, 0},
213    {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
214    {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
215    {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
216    {"rescheduleonerror", store_yesno, ITEM(res_job.RescheduleOnError), 1, ITEM_DEFAULT, 0},
217    {"rescheduleinterval", store_time, ITEM(res_job.RescheduleInterval), 0, ITEM_DEFAULT, 60 * 30},
218    {"rescheduletimes", store_pint, ITEM(res_job.RescheduleTimes), 0, 0, 0},
219    {"priority",   store_pint, ITEM(res_job.Priority), 0, ITEM_DEFAULT, 10},
220    {NULL, NULL, NULL, 0, 0, 0} 
221 };
222
223 /* FileSet resource
224  *
225  *   name          handler     value                 code flags    default_value
226  */
227 static struct res_items fs_items[] = {
228    {"name",        store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
229    {"description", store_str,  ITEM(res_fs.hdr.desc), 0, 0, 0},
230    {"include",     store_inc,  NULL,                  0, ITEM_NO_EQUALS, 0},
231    {"exclude",     store_inc,  NULL,                  1, ITEM_NO_EQUALS, 0},
232    {NULL,          NULL,       NULL,                  0, 0, 0} 
233 };
234
235 /* Schedule -- see run_conf.c */
236 /* Schedule
237  *
238  *   name          handler     value                 code flags    default_value
239  */
240 static struct res_items sch_items[] = {
241    {"name",     store_name,  ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
242    {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
243    {"run",      store_run,   ITEM(res_sch.run),      0, 0, 0},
244    {NULL, NULL, NULL, 0, 0, 0} 
245 };
246
247 /* Group resource -- not implemented
248  *
249  *   name          handler     value                 code flags    default_value
250  */
251 static struct res_items group_items[] = {
252    {"name",        store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
253    {"description", store_str,  ITEM(res_group.hdr.desc), 0, 0, 0},
254    {NULL, NULL, NULL, 0, 0, 0} 
255 };
256
257 /* Pool resource
258  *
259  *   name             handler     value                        code flags default_value
260  */
261 static struct res_items pool_items[] = {
262    {"name",            store_name,    ITEM(res_pool.hdr.name),      0, ITEM_REQUIRED, 0},
263    {"description",     store_str,     ITEM(res_pool.hdr.desc),      0, 0,     0},
264    {"pooltype",        store_strname, ITEM(res_pool.pool_type),     0, ITEM_REQUIRED, 0},
265    {"labelformat",     store_strname, ITEM(res_pool.label_format),  0, 0,     0},
266    {"cleaningprefix",  store_strname, ITEM(res_pool.cleaning_prefix),  0, 0,     0},
267    {"usecatalog",      store_yesno, ITEM(res_pool.use_catalog),     1, ITEM_DEFAULT,  1},
268    {"usevolumeonce",   store_yesno, ITEM(res_pool.use_volume_once), 1, 0,        0},
269    {"purgeoldestvolume", store_yesno, ITEM(res_pool.purge_oldest_volume), 1, 0, 0},
270    {"recycleoldestvolume", store_yesno, ITEM(res_pool.recycle_oldest_volume), 1, 0, 0},
271    {"recyclecurrentvolume", store_yesno, ITEM(res_pool.recycle_current_volume), 1, 0, 0},
272    {"maximumvolumes",  store_pint,  ITEM(res_pool.max_volumes),     0, 0,        0},
273    {"maximumvolumejobs", store_pint,  ITEM(res_pool.MaxVolJobs),    0, 0,       0},
274    {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles),   0, 0,       0},
275    {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes),   0, 0,       0},
276    {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT,     1},
277    {"catalogfiles",    store_yesno, ITEM(res_pool.catalog_files),   1, ITEM_DEFAULT,  1},
278    {"volumeretention", store_time,  ITEM(res_pool.VolRetention),    0, ITEM_DEFAULT, 60*60*24*365},
279    {"volumeuseduration", store_time,  ITEM(res_pool.VolUseDuration),0, 0, 0},
280    {"autoprune",       store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
281    {"recycle",         store_yesno, ITEM(res_pool.Recycle),     1, ITEM_DEFAULT, 1},
282    {NULL, NULL, NULL, 0, 0, 0} 
283 };
284
285 /* 
286  * Counter Resource
287  *   name             handler     value                        code flags default_value
288  */
289 static struct res_items counter_items[] = {
290    {"name",            store_name,    ITEM(res_counter.hdr.name),        0, ITEM_REQUIRED, 0},
291    {"description",     store_str,     ITEM(res_counter.hdr.desc),        0, 0,     0},
292    {"minimum",         store_int,     ITEM(res_counter.MinValue),        0, ITEM_DEFAULT, 0},
293    {"maximum",         store_pint,    ITEM(res_counter.MaxValue),        0, ITEM_DEFAULT, INT32_MAX},
294    {"wrapcounter",     store_res,     ITEM(res_counter.WrapCounter),     R_COUNTER, 0, 0},
295    {"catalog",         store_res,     ITEM(res_counter.Catalog),         R_CATALOG, 0, 0},
296    {NULL, NULL, NULL, 0, 0, 0} 
297 };
298
299
300 /* Message resource */
301 extern struct res_items msgs_items[];
302
303 /* 
304  * This is the master resource definition.  
305  * It must have one item for each of the resources.
306  *
307  *  name             items        rcode        res_head
308  */
309 struct s_res resources[] = {
310    {"director",      dir_items,   R_DIRECTOR,  NULL},
311    {"console",       con_items,   R_CONSOLE,   NULL},
312    {"client",        cli_items,   R_CLIENT,    NULL},
313    {"job",           job_items,   R_JOB,       NULL},
314    {"storage",       store_items, R_STORAGE,   NULL},
315    {"catalog",       cat_items,   R_CATALOG,   NULL},
316    {"schedule",      sch_items,   R_SCHEDULE,  NULL},
317    {"fileset",       fs_items,    R_FILESET,   NULL},
318    {"group",         group_items, R_GROUP,     NULL},
319    {"pool",          pool_items,  R_POOL,      NULL},
320    {"messages",      msgs_items,  R_MSGS,      NULL},
321    {"counter",       counter_items, R_COUNTER, NULL},
322    {NULL,            NULL,        0,           NULL}
323 };
324
325
326 /* Keywords (RHS) permitted in Job Level records   
327  *
328  *   level_name      level              job_type
329  */
330 struct s_jl joblevels[] = {
331    {"Full",          L_FULL,            JT_BACKUP},
332    {"Base",          L_BASE,            JT_BACKUP},
333    {"Incremental",   L_INCREMENTAL,     JT_BACKUP},
334    {"Differential",  L_DIFFERENTIAL,    JT_BACKUP},
335    {"Since",         L_SINCE,           JT_BACKUP},
336    {"Catalog",       L_VERIFY_CATALOG,  JT_VERIFY},
337    {"InitCatalog",   L_VERIFY_INIT,     JT_VERIFY},
338    {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG,   JT_VERIFY},
339    {"Data",          L_VERIFY_DATA,     JT_VERIFY},
340    {NULL,            0}
341 };
342
343 /* Keywords (RHS) permitted in Job type records   
344  *
345  *   type_name       job_type
346  */
347 struct s_jt jobtypes[] = {
348    {"backup",        JT_BACKUP},
349    {"admin",         JT_ADMIN},
350    {"verify",        JT_VERIFY},
351    {"restore",       JT_RESTORE},
352    {NULL,            0}
353 };
354
355
356 /* Keywords (RHS) permitted in Backup and Verify records */
357 static struct s_kw BakVerFields[] = {
358    {"client",        'C'},
359    {"fileset",       'F'},
360    {"level",         'L'}, 
361    {NULL,            0}
362 };
363
364 /* Keywords (RHS) permitted in Restore records */
365 static struct s_kw RestoreFields[] = {
366    {"client",        'C'},
367    {"fileset",       'F'},
368    {"jobid",         'J'},            /* JobId to restore */
369    {"where",         'W'},            /* root of restore */
370    {"replace",       'R'},            /* replacement options */
371    {"bootstrap",     'B'},            /* bootstrap file */
372    {NULL,              0}
373 };
374
375 /* Options permitted in Restore replace= */
376 struct s_kw ReplaceOptions[] = {
377    {"always",         REPLACE_ALWAYS},
378    {"ifnewer",        REPLACE_IFNEWER},
379    {"ifolder",        REPLACE_IFOLDER},
380    {"never",          REPLACE_NEVER},
381    {NULL,               0}
382 };
383
384 char *level_to_str(int level)
385 {
386    int i;
387    static char level_no[30];
388    char *str = level_no;
389
390    sprintf(level_no, "%d", level);    /* default if not found */
391    for (i=0; joblevels[i].level_name; i++) {
392       if (level == joblevels[i].level) {
393          str = joblevels[i].level_name;
394          break;
395       }
396    }
397    return str;
398 }
399
400 /* Dump contents of resource */
401 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
402 {
403    URES *res = (URES *)reshdr;
404    int recurse = 1;
405    char ed1[30], ed2[30];
406
407    if (res == NULL) {
408       sendit(sock, "No %s resource defined\n", res_to_str(type));
409       return;
410    }
411    if (type < 0) {                    /* no recursion */
412       type = - type;
413       recurse = 0;
414    }
415    switch (type) {
416    case R_DIRECTOR:
417       sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n", 
418          reshdr->name, res->res_dir.MaxConcurrentJobs, 
419          edit_uint64(res->res_dir.FDConnectTimeout, ed1),
420          edit_uint64(res->res_dir.SDConnectTimeout, ed2));
421       if (res->res_dir.query_file) {
422          sendit(sock, "   query_file=%s\n", res->res_dir.query_file);
423       }
424       if (res->res_dir.messages) {
425          sendit(sock, "  --> ");
426          dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
427       }
428       break;
429    case R_CONSOLE:
430       sendit(sock, "Console: name=%s SSL=%d\n", 
431          res->res_con.hdr.name, res->res_con.enable_ssl);
432       break;
433    case R_COUNTER:
434       if (res->res_counter.WrapCounter) {
435          sendit(sock, "Counter: name=%s min=%d max=%d wrapcntr=%s\n",
436             res->res_counter.hdr.name, res->res_counter.MinValue, 
437             res->res_counter.MaxValue, res->res_counter.WrapCounter->hdr.name);
438       } else {
439          sendit(sock, "Counter: name=%s min=%d max=%d\n",
440             res->res_counter.hdr.name, res->res_counter.MinValue, 
441             res->res_counter.MaxValue);
442       }
443       if (res->res_counter.Catalog) {
444          sendit(sock, "  --> ");
445          dump_resource(-R_CATALOG, (RES *)res->res_counter.Catalog, sendit, sock);
446       }
447       break;
448
449    case R_CLIENT:
450       sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
451          res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
452          res->res_client.MaxConcurrentJobs);
453       sendit(sock, "      JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
454          res->res_client.JobRetention, res->res_client.FileRetention,
455          res->res_client.AutoPrune);
456       if (res->res_client.catalog) {
457          sendit(sock, "  --> ");
458          dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
459       }
460       break;
461    case R_STORAGE:
462       sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
463       DeviceName=%s MediaType=%s\n",
464          res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
465          res->res_store.MaxConcurrentJobs,
466          res->res_store.dev_name, res->res_store.media_type);
467       break;
468    case R_CATALOG:
469       sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
470       db_user=%s\n",
471          res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
472          res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
473       break;
474    case R_JOB:
475       sendit(sock, "Job: name=%s JobType=%d level=%s Priority=%d MaxJobs=%u\n", 
476          res->res_job.hdr.name, res->res_job.JobType, 
477          level_to_str(res->res_job.level), res->res_job.Priority,
478          res->res_job.MaxConcurrentJobs);
479       sendit(sock, "     Resched=%d Times=%d Interval=%s\n",
480           res->res_job.RescheduleOnError, res->res_job.RescheduleTimes,
481           edit_uint64_with_commas(res->res_job.RescheduleInterval, ed1));
482       if (res->res_job.client) {
483          sendit(sock, "  --> ");
484          dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
485       }
486       if (res->res_job.fileset) {
487          sendit(sock, "  --> ");
488          dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
489       }
490       if (res->res_job.schedule) {
491          sendit(sock, "  --> ");
492          dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
493       }
494       if (res->res_job.RestoreWhere) {
495          sendit(sock, "  --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
496       }
497       if (res->res_job.RestoreBootstrap) {
498          sendit(sock, "  --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
499       }
500       if (res->res_job.RunBeforeJob) {
501          sendit(sock, "  --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
502       }
503       if (res->res_job.RunAfterJob) {
504          sendit(sock, "  --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
505       }
506       if (res->res_job.WriteBootstrap) {
507          sendit(sock, "  --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
508       }
509       if (res->res_job.storage) {
510          sendit(sock, "  --> ");
511          dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
512       }
513       if (res->res_job.pool) {
514          sendit(sock, "  --> ");
515          dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
516       } else {
517          sendit(sock, "!!! No Pool resource\n");
518       }
519       if (res->res_job.messages) {
520          sendit(sock, "  --> ");
521          dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
522       }
523       break;
524    case R_FILESET:
525       sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
526       for (int i=0; i<res->res_fs.num_includes; i++) {
527          INCEXE *incexe = res->res_fs.include_items[i];
528          for (int j=0; j<incexe->name_list.size(); j++) {
529             sendit(sock, "      Inc: %s\n", incexe->name_list.get(j));
530          }
531       }
532       for (int i=0; i<res->res_fs.num_excludes; i++) {
533          INCEXE *incexe = res->res_fs.exclude_items[i];
534          for (int j=0; j<incexe->name_list.size(); j++) {
535             sendit(sock, "      Exc: %s\n", incexe->name_list.get(j));
536          }
537       }
538       break;
539    case R_SCHEDULE:
540       if (res->res_sch.run) {
541          int i;
542          RUN *run = res->res_sch.run;
543          char buf[1000], num[10];
544          sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
545          if (!run) {
546             break;
547          }
548 next_run:
549          sendit(sock, "  --> Run Level=%s\n", level_to_str(run->level));
550          strcpy(buf, "      hour=");
551          for (i=0; i<24; i++) {
552             if (bit_is_set(i, run->hour)) {
553                sprintf(num, "%d ", i);
554                strcat(buf, num);
555             }
556          }
557          strcat(buf, "\n");
558          sendit(sock, buf);
559          strcpy(buf, "      mday=");
560          for (i=0; i<31; i++) {
561             if (bit_is_set(i, run->mday)) {
562                sprintf(num, "%d ", i+1);
563                strcat(buf, num);
564             }
565          }
566          strcat(buf, "\n");
567          sendit(sock, buf);
568          strcpy(buf, "      month=");
569          for (i=0; i<12; i++) {
570             if (bit_is_set(i, run->month)) {
571                sprintf(num, "%d ", i+1);
572                strcat(buf, num);
573             }
574          }
575          strcat(buf, "\n");
576          sendit(sock, buf);
577          strcpy(buf, "      wday=");
578          for (i=0; i<7; i++) {
579             if (bit_is_set(i, run->wday)) {
580                sprintf(num, "%d ", i+1);
581                strcat(buf, num);
582             }
583          }
584          strcat(buf, "\n");
585          sendit(sock, buf);
586          strcpy(buf, "      wpos=");
587          for (i=0; i<5; i++) {
588             if (bit_is_set(i, run->wpos)) {
589                sprintf(num, "%d ", i+1);
590                strcat(buf, num);
591             }
592          }
593          strcat(buf, "\n");
594          sendit(sock, buf);
595          sendit(sock, "      mins=%d\n", run->minute);
596          if (run->pool) {
597             sendit(sock, "     --> ");
598             dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
599          }
600          if (run->storage) {
601             sendit(sock, "     --> ");
602             dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
603          }
604          if (run->msgs) {
605             sendit(sock, "     --> ");
606             dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
607          }
608          /* If another Run record is chained in, go print it */
609          if (run->next) {
610             run = run->next;
611             goto next_run;
612          }
613       } else {
614          sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
615       }
616       break;
617    case R_GROUP:
618       sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
619       break;
620    case R_POOL:
621       sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
622               res->res_pool.pool_type);
623       sendit(sock, "      use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
624               res->res_pool.use_catalog, res->res_pool.use_volume_once,
625               res->res_pool.accept_any_volume, res->res_pool.catalog_files);
626       sendit(sock, "      max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
627               res->res_pool.max_volumes, res->res_pool.AutoPrune,
628               res->res_pool.VolRetention);
629       sendit(sock, "      recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
630               NPRT(res->res_pool.label_format));
631       sendit(sock, "      CleaningPrefix=%s\n",
632               NPRT(res->res_pool.cleaning_prefix));
633       sendit(sock, "      recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
634               res->res_pool.purge_oldest_volume, 
635               res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
636       break;
637    case R_MSGS:
638       sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
639       if (res->res_msgs.mail_cmd) 
640          sendit(sock, "      mailcmd=%s\n", res->res_msgs.mail_cmd);
641       if (res->res_msgs.operator_cmd) 
642          sendit(sock, "      opcmd=%s\n", res->res_msgs.operator_cmd);
643       break;
644    default:
645       sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
646       break;
647    }
648    if (recurse && res->res_dir.hdr.next) {
649       dump_resource(type, res->res_dir.hdr.next, sendit, sock);
650    }
651 }
652
653 /*
654  * Free all the members of an INCEXE structure
655  */
656 static void free_incexe(INCEXE *incexe)
657 {
658    incexe->name_list.destroy();
659    for (int i=0; i<incexe->num_opts; i++) {
660       FOPTS *fopt = incexe->opts_list[i];
661       fopt->match.destroy();
662       fopt->base_list.destroy();
663       free(fopt);
664    }
665    if (incexe->opts_list) {
666       free(incexe->opts_list);
667    }
668    free(incexe);
669 }
670
671 /* 
672  * Free memory of resource.  
673  * NB, we don't need to worry about freeing any references
674  * to other resources as they will be freed when that 
675  * resource chain is traversed.  Mainly we worry about freeing
676  * allocated strings (names).
677  */
678 void free_resource(int type)
679 {
680    int num;
681    URES *res;
682    RES *nres;
683    int rindex = type - r_first;
684
685    res = (URES *)resources[rindex].res_head;
686
687    if (res == NULL)
688       return;
689
690    /* common stuff -- free the resource name and description */
691    nres = (RES *)res->res_dir.hdr.next;
692    if (res->res_dir.hdr.name) {
693       free(res->res_dir.hdr.name);
694    }
695    if (res->res_dir.hdr.desc) {
696       free(res->res_dir.hdr.desc);
697    }
698
699    switch (type) {
700    case R_DIRECTOR:
701       if (res->res_dir.working_directory) {
702          free(res->res_dir.working_directory);
703       }
704       if (res->res_dir.pid_directory) {
705          free(res->res_dir.pid_directory);
706       }
707       if (res->res_dir.subsys_directory) {
708          free(res->res_dir.subsys_directory);
709       }
710       if (res->res_dir.password) {
711          free(res->res_dir.password);
712       }
713       if (res->res_dir.query_file) {
714          free(res->res_dir.query_file);
715       }
716       if (res->res_dir.DIRaddr) {
717          free(res->res_dir.DIRaddr);
718       }
719       break;
720    case R_COUNTER:
721        break;
722    case R_CONSOLE:
723       if (res->res_con.password) {
724          free(res->res_con.password);
725       }
726       break;
727    case R_CLIENT:
728       if (res->res_client.address) {
729          free(res->res_client.address);
730       }
731       if (res->res_client.password) {
732          free(res->res_client.password);
733       }
734       break;
735    case R_STORAGE:
736       if (res->res_store.address) {
737          free(res->res_store.address);
738       }
739       if (res->res_store.password) {
740          free(res->res_store.password);
741       }
742       if (res->res_store.media_type) {
743          free(res->res_store.media_type);
744       }
745       if (res->res_store.dev_name) {
746          free(res->res_store.dev_name);
747       }
748       break;
749    case R_CATALOG:
750       if (res->res_cat.db_address) {
751          free(res->res_cat.db_address);
752       }
753       if (res->res_cat.db_socket) {
754          free(res->res_cat.db_socket);
755       }
756       if (res->res_cat.db_user) {
757          free(res->res_cat.db_user);
758       }
759       if (res->res_cat.db_name) {
760          free(res->res_cat.db_name);
761       }
762       if (res->res_cat.db_password) {
763          free(res->res_cat.db_password);
764       }
765       break;
766    case R_FILESET:
767       if ((num=res->res_fs.num_includes)) {
768          while (--num >= 0) {   
769             free_incexe(res->res_fs.include_items[num]);
770          }
771          free(res->res_fs.include_items);
772       }
773       res->res_fs.num_includes = 0;
774       if ((num=res->res_fs.num_excludes)) {
775          while (--num >= 0) {   
776             free_incexe(res->res_fs.exclude_items[num]);
777          }
778          free(res->res_fs.exclude_items);
779       }
780       res->res_fs.num_excludes = 0;
781       break;
782    case R_POOL:
783       if (res->res_pool.pool_type) {
784          free(res->res_pool.pool_type);
785       }
786       if (res->res_pool.label_format) {
787          free(res->res_pool.label_format);
788       }
789       if (res->res_pool.cleaning_prefix) {
790          free(res->res_pool.cleaning_prefix);
791       }
792       break;
793    case R_SCHEDULE:
794       if (res->res_sch.run) {
795          RUN *nrun, *next;
796          nrun = res->res_sch.run;
797          while (nrun) {
798             next = nrun->next;
799             free(nrun);
800             nrun = next;
801          }
802       }
803       break;
804    case R_JOB:
805       if (res->res_job.RestoreWhere) {
806          free(res->res_job.RestoreWhere);
807       }
808       if (res->res_job.RestoreBootstrap) {
809          free(res->res_job.RestoreBootstrap);
810       }
811       if (res->res_job.WriteBootstrap) {
812          free(res->res_job.WriteBootstrap);
813       }
814       if (res->res_job.RunBeforeJob) {
815          free(res->res_job.RunBeforeJob);
816       }
817       if (res->res_job.RunAfterJob) {
818          free(res->res_job.RunAfterJob);
819       }
820       if (res->res_job.ClientRunBeforeJob) {
821          free(res->res_job.ClientRunBeforeJob);
822       }
823       if (res->res_job.ClientRunAfterJob) {
824          free(res->res_job.ClientRunAfterJob);
825       }
826       break;
827    case R_MSGS:
828       if (res->res_msgs.mail_cmd) {
829          free(res->res_msgs.mail_cmd);
830       }
831       if (res->res_msgs.operator_cmd) {
832          free(res->res_msgs.operator_cmd);
833       }
834       free_msgs_res((MSGS *)res);  /* free message resource */
835       res = NULL;
836       break;
837    case R_GROUP:
838       break;
839    default:
840       printf("Unknown resource type %d in free_resource.\n", type);
841    }
842    /* Common stuff again -- free the resource, recurse to next one */
843    if (res) {
844       free(res);
845    }
846    resources[rindex].res_head = nres;
847    if (nres) {
848       free_resource(type);
849    }
850 }
851
852 /*
853  * Save the new resource by chaining it into the head list for
854  * the resource. If this is pass 2, we update any resource
855  * pointers because they may not have been defined until 
856  * later in pass 1.
857  */
858 void save_resource(int type, struct res_items *items, int pass)
859 {
860    URES *res;
861    int rindex = type - r_first;
862    int i, size;
863    int error = 0;
864    
865    /* 
866     * Ensure that all required items are present
867     */
868    for (i=0; items[i].name; i++) {
869       if (items[i].flags & ITEM_REQUIRED) {
870             if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {  
871                Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
872                  items[i].name, resources[rindex]);
873              }
874       }
875       /* If this triggers, take a look at lib/parse_conf.h */
876       if (i >= MAX_RES_ITEMS) {
877          Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
878       }
879    }
880
881    /* During pass 2 in each "store" routine, we looked up pointers 
882     * to all the resources referrenced in the current resource, now we
883     * must copy their addresses from the static record to the allocated
884     * record.
885     */
886    if (pass == 2) {
887       switch (type) {
888       /* Resources not containing a resource */
889       case R_CONSOLE:
890       case R_CATALOG:
891       case R_STORAGE:
892       case R_GROUP:
893       case R_POOL:
894       case R_MSGS:
895       case R_FILESET:
896          break;
897
898       /* Resources containing another resource */
899       case R_DIRECTOR:
900          if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
901             Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
902          }
903          res->res_dir.messages = res_all.res_dir.messages;
904          break;
905       case R_JOB:
906          if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
907             Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
908          }
909          res->res_job.messages = res_all.res_job.messages;
910          res->res_job.schedule = res_all.res_job.schedule;
911          res->res_job.client   = res_all.res_job.client;
912          res->res_job.fileset  = res_all.res_job.fileset;
913          res->res_job.storage  = res_all.res_job.storage;
914          res->res_job.pool     = res_all.res_job.pool;
915          if (res->res_job.JobType == 0) {
916             Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
917          }
918          if (res->res_job.level != 0) {
919             int i;
920             for (i=0; joblevels[i].level_name; i++) {
921                if (joblevels[i].level == res->res_job.level &&
922                    joblevels[i].job_type == res->res_job.JobType) {
923                   i = 0;
924                   break;
925                }
926             }
927             if (i != 0) {
928                Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n", 
929                   res_all.res_dir.hdr.name);
930             }
931          }
932          break;
933       case R_COUNTER:
934          if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
935             Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
936          }
937          res->res_counter.Catalog = res_all.res_counter.Catalog;
938          res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
939          break;
940
941       case R_CLIENT:
942          if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
943             Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
944          }
945          res->res_client.catalog = res_all.res_client.catalog;
946          break;
947       case R_SCHEDULE:
948          /* Schedule is a bit different in that it contains a RUN record
949           * chain which isn't a "named" resource. This chain was linked
950           * in by run_conf.c during pass 2, so here we jam the pointer 
951           * into the Schedule resource.                         
952           */
953          if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
954             Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
955          }
956          res->res_sch.run = res_all.res_sch.run;
957          break;
958       default:
959          Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
960          error = 1;
961          break;
962       }
963       /* Note, the resource name was already saved during pass 1,
964        * so here, we can just release it.
965        */
966       if (res_all.res_dir.hdr.name) {
967          free(res_all.res_dir.hdr.name);
968          res_all.res_dir.hdr.name = NULL;
969       }
970       if (res_all.res_dir.hdr.desc) {
971          free(res_all.res_dir.hdr.desc);
972          res_all.res_dir.hdr.desc = NULL;
973       }
974       return;
975    }
976
977    /* The following code is only executed for pass 1 */
978    switch (type) {
979    case R_DIRECTOR:
980       size = sizeof(DIRRES);
981       break;
982    case R_CONSOLE:
983       size = sizeof(CONRES);
984       break;
985    case R_CLIENT:
986       size =sizeof(CLIENT);
987       break;
988    case R_STORAGE:
989       size = sizeof(STORE); 
990       break;
991    case R_CATALOG:
992       size = sizeof(CAT);
993       break;
994    case R_JOB:
995       size = sizeof(JOB);
996       break;
997    case R_FILESET:
998       size = sizeof(FILESET);
999       break;
1000    case R_SCHEDULE:
1001       size = sizeof(SCHED);
1002       break;
1003    case R_GROUP:
1004       size = sizeof(GROUP);
1005       break;
1006    case R_POOL:
1007       size = sizeof(POOL);
1008       break;
1009    case R_MSGS:
1010       size = sizeof(MSGS);
1011       break;
1012    case R_COUNTER:
1013       size = sizeof(COUNTER);
1014       break;
1015    default:
1016       printf("Unknown resource type %d in save_resrouce.\n", type);
1017       error = 1;
1018       size = 1;
1019       break;
1020    }
1021    /* Common */
1022    if (!error) {
1023       res = (URES *)malloc(size);
1024       memcpy(res, &res_all, size);
1025       if (!resources[rindex].res_head) {
1026          resources[rindex].res_head = (RES *)res; /* store first entry */
1027          Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1028                res->res_dir.hdr.name, rindex);
1029       } else {
1030          RES *next;
1031          /* Add new res to end of chain */
1032          for (next=resources[rindex].res_head; next->next; next=next->next)
1033             { }
1034          next->next = (RES *)res;
1035          Dmsg3(200, "Inserting %s res: %s index=%d\n", res_to_str(type),
1036                res->res_dir.hdr.name, rindex);
1037       }
1038    }
1039 }
1040
1041 /* 
1042  * Store JobType (backup, verify, restore)
1043  *
1044  */
1045 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1046 {
1047    int token, i;   
1048
1049    token = lex_get_token(lc, T_NAME);
1050    /* Store the type both pass 1 and pass 2 */
1051    for (i=0; jobtypes[i].type_name; i++) {
1052       if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1053          ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1054          i = 0;
1055          break;
1056       }
1057    }
1058    if (i != 0) {
1059       scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1060    }
1061    scan_to_eol(lc);
1062    set_bit(index, res_all.hdr.item_present);
1063 }
1064
1065 /* 
1066  * Store Job Level (Full, Incremental, ...)
1067  *
1068  */
1069 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1070 {
1071    int token, i;
1072
1073    token = lex_get_token(lc, T_NAME);
1074    /* Store the level pass 2 so that type is defined */
1075    for (i=0; joblevels[i].level_name; i++) {
1076       if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1077          ((JOB *)(item->value))->level = joblevels[i].level;
1078          i = 0;
1079          break;
1080       }
1081    }
1082    if (i != 0) {
1083       scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1084    }
1085    scan_to_eol(lc);
1086    set_bit(index, res_all.hdr.item_present);
1087 }
1088
1089 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1090 {
1091    int token, i;
1092    token = lex_get_token(lc, T_NAME);
1093    /* Scan Replacement options */
1094    for (i=0; ReplaceOptions[i].name; i++) {
1095       if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1096          *(int *)(item->value) = ReplaceOptions[i].token;
1097          i = 0;
1098          break;
1099       }
1100    }
1101    if (i != 0) {
1102       scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1103    }
1104    scan_to_eol(lc);
1105    set_bit(index, res_all.hdr.item_present);
1106 }
1107
1108 /* 
1109  * Store backup/verify info for Job record 
1110  *
1111  * Note, this code is used for both BACKUP and VERIFY jobs
1112  *
1113  *    Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1114  */
1115 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1116 {
1117    int token, i;
1118    RES *res;
1119    int options = lc->options;
1120
1121    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1122
1123    
1124    ((JOB *)(item->value))->JobType = item->code;
1125    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1126       bool found = false;
1127
1128       Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1129       
1130       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1131          scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1132       }
1133       Dmsg1(190, "Got keyword: %s\n", lc->str);
1134       for (i=0; BakVerFields[i].name; i++) {
1135          if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1136             found = true;
1137             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1138                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1139             }
1140             token = lex_get_token(lc, T_NAME);
1141             Dmsg1(190, "Got value: %s\n", lc->str);
1142             switch (BakVerFields[i].token) {
1143             case 'C':
1144                /* Find Client Resource */
1145                if (pass == 2) {
1146                   res = GetResWithName(R_CLIENT, lc->str);
1147                   if (res == NULL) {
1148                      scan_err1(lc, "Could not find specified Client Resource: %s",
1149                                 lc->str);
1150                   }
1151                   res_all.res_job.client = (CLIENT *)res;
1152                }
1153                break;
1154             case 'F':
1155                /* Find FileSet Resource */
1156                if (pass == 2) {
1157                   res = GetResWithName(R_FILESET, lc->str);
1158                   if (res == NULL) {
1159                      scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1160                                  lc->str);
1161                   }
1162                   res_all.res_job.fileset = (FILESET *)res;
1163                }
1164                break;
1165             case 'L':
1166                /* Get level */
1167                for (i=0; joblevels[i].level_name; i++) {
1168                   if (joblevels[i].job_type == item->code && 
1169                        strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1170                      ((JOB *)(item->value))->level = joblevels[i].level;
1171                      i = 0;
1172                      break;
1173                   }
1174                }
1175                if (i != 0) {
1176                   scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1177                }
1178                break;
1179             } /* end switch */
1180             break;
1181          } /* end if strcmp() */
1182       } /* end for */
1183       if (!found) {
1184          scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1185       }
1186    } /* end while */
1187    lc->options = options;             /* reset original options */
1188    set_bit(index, res_all.hdr.item_present);
1189 }
1190
1191 /* 
1192  * Store restore info for Job record 
1193  *
1194  *    Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1195  *
1196  */
1197 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1198 {
1199    int token, i;
1200    RES *res;
1201    int options = lc->options;
1202
1203    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1204
1205    Dmsg0(190, "Enter store_restore()\n");
1206    
1207    ((JOB *)(item->value))->JobType = item->code;
1208    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1209       bool found = false;
1210
1211       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1212          scan_err1(lc, "expected a name, got: %s", lc->str);
1213       }
1214       for (i=0; RestoreFields[i].name; i++) {
1215          Dmsg1(190, "Restore kw=%s\n", lc->str);
1216          if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1217             found = true;
1218             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1219                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1220             }
1221             token = lex_get_token(lc, T_ALL);
1222             Dmsg1(190, "Restore value=%s\n", lc->str);
1223             switch (RestoreFields[i].token) {
1224             case 'B':
1225                /* Bootstrap */
1226                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1227                   scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1228                }
1229                if (pass == 1) {
1230                   res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1231                }
1232                break;
1233             case 'C':
1234                /* Find Client Resource */
1235                if (pass == 2) {
1236                   res = GetResWithName(R_CLIENT, lc->str);
1237                   if (res == NULL) {
1238                      scan_err1(lc, "Could not find specified Client Resource: %s",
1239                                 lc->str);
1240                   }
1241                   res_all.res_job.client = (CLIENT *)res;
1242                }
1243                break;
1244             case 'F':
1245                /* Find FileSet Resource */
1246                if (pass == 2) {
1247                   res = GetResWithName(R_FILESET, lc->str);
1248                   if (res == NULL) {
1249                      scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1250                                  lc->str);
1251                   }
1252                   res_all.res_job.fileset = (FILESET *)res;
1253                }
1254                break;
1255             case 'J':
1256                /* JobId */
1257                if (token != T_NUMBER) {
1258                   scan_err1(lc, "expected an integer number, got: %s", lc->str);
1259                }
1260                errno = 0;
1261                res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1262                Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1263                if (errno != 0) {
1264                   scan_err1(lc, "expected an integer number, got: %s", lc->str);
1265                }
1266                break;
1267             case 'W':
1268                /* Where */
1269                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1270                   scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1271                }
1272                if (pass == 1) {
1273                   res_all.res_job.RestoreWhere = bstrdup(lc->str);
1274                }
1275                break;
1276             case 'R':
1277                /* Replacement options */
1278                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1279                   scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1280                }
1281                /* Fix to scan Replacement options */
1282                for (i=0; ReplaceOptions[i].name; i++) {
1283                   if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1284                       ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1285                      i = 0;
1286                      break;
1287                   }
1288                }
1289                if (i != 0) {
1290                   scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1291                }
1292                break;
1293             } /* end switch */
1294             break;
1295          } /* end if strcmp() */
1296       } /* end for */
1297       if (!found) {
1298          scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1299       }
1300    } /* end while */
1301    lc->options = options;             /* reset original options */
1302    set_bit(index, res_all.hdr.item_present);
1303 }