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