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