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