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