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