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