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