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