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