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