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