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