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