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