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