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