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