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