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