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