]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/dird_conf.c
Implement cleaning prefix
[bacula/bacula] / bacula / src / dird / dird_conf.c
1 /*
2  *   Main configuration file parser for Bacula Directors,
3  *    some parts may be split into separate files such as
4  *    the schedule configuration (sch_config.c).
5  *
6  *   Note, the configuration file parser consists of three parts
7  *
8  *   1. The generic lexical scanner in lib/lex.c and lib/lex.h
9  *
10  *   2. The generic config  scanner in lib/parse_config.c and 
11  *      lib/parse_config.h.
12  *      These files contain the parser code, some utility
13  *      routines, and the common store routines (name, int,
14  *      string).
15  *
16  *   3. The daemon specific file, which contains the Resource
17  *      definitions as well as any specific store routines
18  *      for the resource records.
19  *
20  *     Kern Sibbald, January MM
21  *
22  *     Version $Id$
23  */
24 /*
25    Copyright (C) 2000-2003 Kern Sibbald and John Walker
26
27    This program is free software; you can redistribute it and/or
28    modify it under the terms of the GNU General Public License as
29    published by the Free Software Foundation; either version 2 of
30    the License, or (at your option) any later version.
31
32    This program is distributed in the hope that it will be useful,
33    but WITHOUT ANY WARRANTY; without even the implied warranty of
34    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35    General Public License for more details.
36
37    You should have received a copy of the GNU General Public
38    License along with this program; if not, write to the Free
39    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
40    MA 02111-1307, USA.
41
42  */
43
44 #include "bacula.h"
45 #include "dird.h"
46
47 /* Define the first and last resource ID record
48  * types. Note, these should be unique for each
49  * daemon though not a requirement.
50  */
51 int r_first = R_FIRST;
52 int r_last  = R_LAST;
53 pthread_mutex_t res_mutex =  PTHREAD_MUTEX_INITIALIZER;
54
55 /* Imported subroutines */
56 extern void store_run(LEX *lc, struct res_items *item, int index, int pass);
57 extern void store_finc(LEX *lc, struct res_items *item, int index, int pass);
58 extern void store_inc(LEX *lc, struct res_items *item, int index, int pass);
59
60
61 /* Forward referenced subroutines */
62
63 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
64 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
66 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
67 static void store_replace(LEX *lc, struct res_items *item, int index, int pass);
68
69
70 /* We build the current resource here as we are
71  * scanning the resource configuration definition,
72  * then move it to allocated memory when the resource
73  * scan is complete.
74  */
75 URES res_all;
76 int  res_all_size = sizeof(res_all);
77
78
79 /* Definition of records permitted within each
80  * resource with the routine to process the record 
81  * information.  NOTE! quoted names must be in lower case.
82  */ 
83 /* 
84  *    Director Resource
85  *
86  *   name          handler     value                 code flags    default_value
87  */
88 static struct res_items dir_items[] = {
89    {"name",        store_name,     ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
90    {"description", store_str,      ITEM(res_dir.hdr.desc), 0, 0, 0},
91    {"messages",    store_res,      ITEM(res_dir.messages), R_MSGS, 0, 0},
92    {"dirport",     store_pint,     ITEM(res_dir.DIRport),  0, ITEM_DEFAULT, 9101},
93    {"diraddress",  store_str,      ITEM(res_dir.DIRaddr),  0, 0, 0},
94    {"queryfile",   store_dir,      ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
95    {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
96    {"piddirectory", store_dir,     ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
97    {"subsysdirectory", store_dir,  ITEM(res_dir.subsys_directory), 0, ITEM_REQUIRED, 0},
98    {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
99    {"password",    store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
100    {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
101    {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
102    {NULL, NULL, NULL, 0, 0, 0}
103 };
104
105 /* 
106  *    Client or File daemon resource
107  *
108  *   name          handler     value                 code flags    default_value
109  */
110
111 static struct res_items cli_items[] = {
112    {"name",     store_name,       ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
113    {"description", store_str,     ITEM(res_client.hdr.desc), 0, 0, 0},
114    {"address",  store_str,        ITEM(res_client.address),  0, ITEM_REQUIRED, 0},
115    {"fdport",   store_pint,       ITEM(res_client.FDport),   0, ITEM_DEFAULT, 9102},
116    {"password", store_password,   ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
117    {"catalog",  store_res,        ITEM(res_client.catalog),  R_CATALOG, 0, 0},
118    {"fileretention", store_time,  ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
119    {"jobretention",  store_time,  ITEM(res_client.JobRetention),  0, ITEM_DEFAULT, 60*60*24*180},
120    {"autoprune", store_yesno,     ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
121    {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
122    {NULL, NULL, NULL, 0, 0, 0} 
123 };
124
125 /* Storage daemon resource
126  *
127  *   name          handler     value                 code flags    default_value
128  */
129 static struct res_items store_items[] = {
130    {"name",      store_name,     ITEM(res_store.hdr.name),   0, ITEM_REQUIRED, 0},
131    {"description", store_str,    ITEM(res_store.hdr.desc),   0, 0, 0},
132    {"sdport",    store_pint,     ITEM(res_store.SDport),     0, ITEM_DEFAULT, 9103},
133    {"sddport",   store_pint,     ITEM(res_store.SDDport),    0, 0, 0}, /* deprecated */
134    {"address",   store_str,      ITEM(res_store.address),    0, ITEM_REQUIRED, 0},
135    {"password",  store_password, ITEM(res_store.password),   0, ITEM_REQUIRED, 0},
136    {"device",    store_strname,  ITEM(res_store.dev_name),   0, ITEM_REQUIRED, 0},
137    {"mediatype", store_strname,  ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
138    {"autochanger", store_yesno,  ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
139    {"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
140    {NULL, NULL, NULL, 0, 0, 0} 
141 };
142
143 /* 
144  *    Catalog Resource Directives
145  *
146  *   name          handler     value                 code flags    default_value
147  */
148 static struct res_items cat_items[] = {
149    {"name",     store_name,     ITEM(res_cat.hdr.name),    0, ITEM_REQUIRED, 0},
150    {"description", store_str,   ITEM(res_cat.hdr.desc),    0, 0, 0},
151    {"address",  store_str,      ITEM(res_cat.db_address),  0, 0, 0},
152    {"dbaddress", store_str,     ITEM(res_cat.db_address),  0, 0, 0},
153    {"dbport",   store_pint,     ITEM(res_cat.db_port),      0, 0, 0},
154    /* keep this password as store_str for the moment */
155    {"password", store_str,      ITEM(res_cat.db_password), 0, 0, 0},
156    {"user",     store_str,      ITEM(res_cat.db_user),     0, 0, 0},
157    {"dbname",   store_str,      ITEM(res_cat.db_name),     0, ITEM_REQUIRED, 0},
158    {"dbsocket", store_str,      ITEM(res_cat.db_socket),   0, 0, 0}, 
159    {NULL, NULL, NULL, 0, 0, 0} 
160 };
161
162 /* 
163  *    Job Resource Directives
164  *
165  *   name          handler     value                 code flags    default_value
166  */
167 static struct res_items job_items[] = {
168    {"name",     store_name,    ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
169    {"description", store_str,  ITEM(res_job.hdr.desc), 0, 0, 0},
170    {"backup",   store_backup,  ITEM(res_job),          JT_BACKUP, 0, 0},
171    {"verify",   store_backup,  ITEM(res_job),          JT_VERIFY, 0, 0},
172    {"restore",  store_restore, ITEM(res_job),          JT_RESTORE, 0, 0},
173    {"schedule", store_res,     ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
174    {"type",     store_jobtype, ITEM(res_job),          0, 0, 0},
175    {"level",    store_level,   ITEM(res_job),          0, 0, 0},
176    {"messages", store_res,     ITEM(res_job.messages), R_MSGS, 0, 0},
177    {"storage",  store_res,     ITEM(res_job.storage),  R_STORAGE, 0, 0},
178    {"pool",     store_res,     ITEM(res_job.pool),     R_POOL, 0, 0},
179    {"client",   store_res,     ITEM(res_job.client),   R_CLIENT, 0, 0},
180    {"fileset",  store_res,     ITEM(res_job.fileset),  R_FILESET, 0, 0},
181    {"where",    store_dir,     ITEM(res_job.RestoreWhere), 0, 0, 0},
182    {"replace",  store_replace, ITEM(res_job.replace), REPLACE_ALWAYS, ITEM_DEFAULT, 0},
183    {"bootstrap",store_dir,     ITEM(res_job.RestoreBootstrap), 0, 0, 0},
184    {"maxruntime", store_time,  ITEM(res_job.MaxRunTime), 0, 0, 0},
185    {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
186    {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
187    {"prunejobs",   store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
188    {"prunefiles",  store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
189    {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
190    {"runbeforejob", store_str,  ITEM(res_job.RunBeforeJob), 0, 0, 0},
191    {"runafterjob",  store_str,  ITEM(res_job.RunAfterJob),  0, 0, 0},
192    {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
193    {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
194    {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
195    {NULL, NULL, NULL, 0, 0, 0} 
196 };
197
198 /* FileSet resource
199  *
200  *   name          handler     value                 code flags    default_value
201  */
202 static struct res_items fs_items[] = {
203    {"name",        store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
204    {"description", store_str,  ITEM(res_fs.hdr.desc), 0, 0, 0},
205    {"include",     store_inc,  NULL,                  0, 0, 0},
206    {"finclude",    store_finc, NULL,                  0, ITEM_NO_EQUALS, 0},
207    {"exclude",     store_inc,  NULL,                  1, 0, 0},
208    {"fexclude",    store_finc, NULL,                  1, ITEM_NO_EQUALS, 0},
209    {NULL,          NULL,       NULL,                  0, 0, 0} 
210 };
211
212 /* Schedule -- see run_conf.c */
213 /* Schedule
214  *
215  *   name          handler     value                 code flags    default_value
216  */
217 static struct res_items sch_items[] = {
218    {"name",     store_name,  ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
219    {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
220    {"run",      store_run,   ITEM(res_sch.run),      0, 0, 0},
221    {NULL, NULL, NULL, 0, 0, 0} 
222 };
223
224 /* Group resource -- not implemented
225  *
226  *   name          handler     value                 code flags    default_value
227  */
228 static struct res_items group_items[] = {
229    {"name",        store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
230    {"description", store_str,  ITEM(res_group.hdr.desc), 0, 0, 0},
231    {NULL, NULL, NULL, 0, 0, 0} 
232 };
233
234 /* Pool resource
235  *
236  *   name             handler     value                        code flags default_value
237  */
238 static struct res_items pool_items[] = {
239    {"name",            store_name,    ITEM(res_pool.hdr.name),      0, ITEM_REQUIRED, 0},
240    {"description",     store_str,     ITEM(res_pool.hdr.desc),      0, 0,     0},
241    {"pooltype",        store_strname, ITEM(res_pool.pool_type),     0, ITEM_REQUIRED, 0},
242    {"labelformat",     store_strname, ITEM(res_pool.label_format),  0, 0,     0},
243    {"cleaningprefix",  store_strname, ITEM(res_pool.cleaning_prefix),  0, 0,     0},
244    {"usecatalog",      store_yesno, ITEM(res_pool.use_catalog),     1, ITEM_DEFAULT,  1},
245    {"usevolumeonce",   store_yesno, ITEM(res_pool.use_volume_once), 1, 0,        0},
246    {"recycleoldestvolume", store_yesno, ITEM(res_pool.recycle_oldest_volume), 1, 0, 0},
247    {"maximumvolumes",  store_pint,  ITEM(res_pool.max_volumes),     0, 0,        0},
248    {"maximumvolumejobs", store_pint,  ITEM(res_pool.MaxVolJobs),    0, 0,       0},
249    {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles),   0, 0,       0},
250    {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes),   0, 0,       0},
251    {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT,     1},
252    {"catalogfiles",    store_yesno, ITEM(res_pool.catalog_files),   1, ITEM_DEFAULT,  1},
253    {"volumeretention", store_time,  ITEM(res_pool.VolRetention),    0, ITEM_DEFAULT, 60*60*24*365},
254    {"volumeuseduration", store_time,  ITEM(res_pool.VolUseDuration),0, 0, 0},
255    {"autoprune",       store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
256    {"recycle",         store_yesno, ITEM(res_pool.Recycle),     1, ITEM_DEFAULT, 1},
257    {NULL, NULL, NULL, 0, 0, 0} 
258 };
259
260 /* 
261  * Counter Resource
262  *   name             handler     value                        code flags default_value
263  */
264 static struct res_items counter_items[] = {
265    {"name",            store_name,    ITEM(res_counter.hdr.name),        0, ITEM_REQUIRED, 0},
266    {"description",     store_str,     ITEM(res_counter.hdr.desc),        0, 0,     0},
267    {"minimum",         store_int,     ITEM(res_counter.MinValue),        0, ITEM_DEFAULT, 0},
268    {"maximum",         store_pint,    ITEM(res_counter.MaxValue),        0, ITEM_DEFAULT, INT32_MAX},
269    {"global",          store_yesno,   ITEM(res_counter.Global),          0, ITEM_DEFAULT, 0},
270    {"wrapcounter",     store_strname, ITEM(res_counter.WrapCounter),     0, 0, 0},
271    {NULL, NULL, NULL, 0, 0, 0} 
272 };
273
274
275 /* Message resource */
276 extern struct res_items msgs_items[];
277
278 /* 
279  * This is the master resource definition.  
280  * It must have one item for each of the resources.
281  *
282  *  name             items        rcode        res_head
283  */
284 struct s_res resources[] = {
285    {"director",      dir_items,   R_DIRECTOR,  NULL},
286    {"client",        cli_items,   R_CLIENT,    NULL},
287    {"job",           job_items,   R_JOB,       NULL},
288    {"storage",       store_items, R_STORAGE,   NULL},
289    {"catalog",       cat_items,   R_CATALOG,   NULL},
290    {"schedule",      sch_items,   R_SCHEDULE,  NULL},
291    {"fileset",       fs_items,    R_FILESET,   NULL},
292    {"group",         group_items, R_GROUP,     NULL},
293    {"pool",          pool_items,  R_POOL,      NULL},
294    {"messages",      msgs_items,  R_MSGS,      NULL},
295    {"counter",       counter_items, R_COUNTER, NULL},
296    {NULL,            NULL,        0,           NULL}
297 };
298
299
300 /* Keywords (RHS) permitted in Job Level records   
301  *
302  *   level_name      level              job_type
303  */
304 struct s_jl joblevels[] = {
305    {"Full",          L_FULL,            JT_BACKUP},
306    {"Incremental",   L_INCREMENTAL,     JT_BACKUP},
307    {"Differential",  L_DIFFERENTIAL,    JT_BACKUP},
308    {"Since",         L_SINCE,           JT_BACKUP},
309    {"Catalog",       L_VERIFY_CATALOG,  JT_VERIFY},
310    {"Initcatalog",   L_VERIFY_INIT,     JT_VERIFY},
311    {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG,   JT_VERIFY},
312    {"Data",          L_VERIFY_DATA,     JT_VERIFY},
313    {NULL,            0}
314 };
315
316 /* Keywords (RHS) permitted in Job type records   
317  *
318  *   type_name       job_type
319  */
320 struct s_jt jobtypes[] = {
321    {"backup",        JT_BACKUP},
322    {"admin",         JT_ADMIN},
323    {"verify",        JT_VERIFY},
324    {"restore",       JT_RESTORE},
325    {NULL,            0}
326 };
327
328
329 /* Keywords (RHS) permitted in Backup and Verify records */
330 static struct s_kw BakVerFields[] = {
331    {"client",        'C'},
332    {"fileset",       'F'},
333    {"level",         'L'}, 
334    {NULL,            0}
335 };
336
337 /* Keywords (RHS) permitted in Restore records */
338 static struct s_kw RestoreFields[] = {
339    {"client",        'C'},
340    {"fileset",       'F'},
341    {"jobid",         'J'},            /* JobId to restore */
342    {"where",         'W'},            /* root of restore */
343    {"replace",       'R'},            /* replacement options */
344    {"bootstrap",     'B'},            /* bootstrap file */
345    {NULL,              0}
346 };
347
348 /* Options permitted in Restore replace= */
349 struct s_kw ReplaceOptions[] = {
350    {"always",         REPLACE_ALWAYS},
351    {"ifnewer",        REPLACE_IFNEWER},
352    {"ifolder",        REPLACE_IFOLDER},
353    {"never",          REPLACE_NEVER},
354    {NULL,               0}
355 };
356
357 char *level_to_str(int level)
358 {
359    int i;
360    static char level_no[30];
361    char *str = level_no;
362
363    sprintf(level_no, "%d", level);    /* default if not found */
364    for (i=0; joblevels[i].level_name; i++) {
365       if (level == joblevels[i].level) {
366          str = joblevels[i].level_name;
367          break;
368       }
369    }
370    return str;
371 }
372
373 /* Dump contents of resource */
374 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
375 {
376    URES *res = (URES *)reshdr;
377    int recurse = 1;
378
379    if (res == NULL) {
380       sendit(sock, "No %s resource defined\n", res_to_str(type));
381       return;
382    }
383    if (type < 0) {                    /* no recursion */
384       type = - type;
385       recurse = 0;
386    }
387    switch (type) {
388       case R_DIRECTOR:
389          char ed1[30], ed2[30];
390          sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n", 
391             reshdr->name, res->res_dir.MaxConcurrentJobs, 
392             edit_uint64(res->res_dir.FDConnectTimeout, ed1),
393             edit_uint64(res->res_dir.SDConnectTimeout, ed2));
394          if (res->res_dir.query_file) {
395             sendit(sock, "   query_file=%s\n", res->res_dir.query_file);
396          }
397          if (res->res_dir.messages) {
398             sendit(sock, "  --> ");
399             dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
400          }
401          break;
402       case R_CLIENT:
403          sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
404             res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
405             res->res_client.MaxConcurrentJobs);
406          sendit(sock, "      JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
407             res->res_client.JobRetention, res->res_client.FileRetention,
408             res->res_client.AutoPrune);
409          if (res->res_client.catalog) {
410             sendit(sock, "  --> ");
411             dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
412          }
413          break;
414       case R_STORAGE:
415          sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
416          DeviceName=%s MediaType=%s\n",
417             res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
418             res->res_store.MaxConcurrentJobs,
419             res->res_store.dev_name, res->res_store.media_type);
420          break;
421       case R_CATALOG:
422          sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
423          db_user=%s\n",
424             res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
425             res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
426          break;
427       case R_JOB:
428          sendit(sock, "Job: name=%s JobType=%d level=%s MaxJobs=%u\n", 
429             res->res_job.hdr.name, res->res_job.JobType, 
430             level_to_str(res->res_job.level), res->res_job.MaxConcurrentJobs);
431          if (res->res_job.client) {
432             sendit(sock, "  --> ");
433             dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
434          }
435          if (res->res_job.fileset) {
436             sendit(sock, "  --> ");
437             dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
438          }
439          if (res->res_job.schedule) {
440             sendit(sock, "  --> ");
441             dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
442          }
443          if (res->res_job.RestoreWhere) {
444             sendit(sock, "  --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
445          }
446          if (res->res_job.RestoreBootstrap) {
447             sendit(sock, "  --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
448          }
449          if (res->res_job.RunBeforeJob) {
450             sendit(sock, "  --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
451          }
452          if (res->res_job.RunAfterJob) {
453             sendit(sock, "  --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
454          }
455          if (res->res_job.WriteBootstrap) {
456             sendit(sock, "  --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
457          }
458          if (res->res_job.storage) {
459             sendit(sock, "  --> ");
460             dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
461          }
462          if (res->res_job.pool) {
463             sendit(sock, "  --> ");
464             dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
465          } else {
466             sendit(sock, "!!! No Pool resource\n");
467          }
468          if (res->res_job.messages) {
469             sendit(sock, "  --> ");
470             dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
471          }
472          break;
473       case R_FILESET:
474          sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
475          for (int i=0; i<res->res_fs.num_includes; i++) {
476             INCEXE *incexe = res->res_fs.include_items[i];
477             for (int j=0; j<incexe->num_names; j++) {
478                sendit(sock, "      Inc: %s\n", incexe->name_list[j]);
479             }
480          }
481          for (int i=0; i<res->res_fs.num_excludes; i++) {
482             INCEXE *incexe = res->res_fs.exclude_items[i];
483             for (int j=0; j<incexe->num_names; j++) {
484                sendit(sock, "      Exc: %s\n", incexe->name_list[j]);
485             }
486          }
487          break;
488       case R_SCHEDULE:
489          if (res->res_sch.run) {
490             int i;
491             RUN *run = res->res_sch.run;
492             char buf[1000], num[10];
493             sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
494             if (!run) {
495                break;
496             }
497 next_run:
498             sendit(sock, "  --> Run Level=%s\n", level_to_str(run->level));
499             strcpy(buf, "      hour=");
500             for (i=0; i<24; i++) {
501                if (bit_is_set(i, run->hour)) {
502                   sprintf(num, "%d ", i);
503                   strcat(buf, num);
504                }
505             }
506             strcat(buf, "\n");
507             sendit(sock, buf);
508             strcpy(buf, "      mday=");
509             for (i=0; i<31; i++) {
510                if (bit_is_set(i, run->mday)) {
511                   sprintf(num, "%d ", i+1);
512                   strcat(buf, num);
513                }
514             }
515             strcat(buf, "\n");
516             sendit(sock, buf);
517             strcpy(buf, "      month=");
518             for (i=0; i<12; i++) {
519                if (bit_is_set(i, run->month)) {
520                   sprintf(num, "%d ", i+1);
521                   strcat(buf, num);
522                }
523             }
524             strcat(buf, "\n");
525             sendit(sock, buf);
526             strcpy(buf, "      wday=");
527             for (i=0; i<7; i++) {
528                if (bit_is_set(i, run->wday)) {
529                   sprintf(num, "%d ", i+1);
530                   strcat(buf, num);
531                }
532             }
533             strcat(buf, "\n");
534             sendit(sock, buf);
535             strcpy(buf, "      wpos=");
536             for (i=0; i<5; i++) {
537                if (bit_is_set(i, run->wpos)) {
538                   sprintf(num, "%d ", i+1);
539                   strcat(buf, num);
540                }
541             }
542             strcat(buf, "\n");
543             sendit(sock, buf);
544             sendit(sock, "      mins=%d\n", run->minute);
545             if (run->pool) {
546                sendit(sock, "     --> ");
547                dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
548             }
549             if (run->storage) {
550                sendit(sock, "     --> ");
551                dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
552             }
553             if (run->msgs) {
554                sendit(sock, "     --> ");
555                dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
556             }
557             /* If another Run record is chained in, go print it */
558             if (run->next) {
559                run = run->next;
560                goto next_run;
561             }
562          } else {
563             sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
564          }
565          break;
566       case R_GROUP:
567          sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
568          break;
569       case R_POOL:
570          sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
571                  res->res_pool.pool_type);
572          sendit(sock, "      use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
573                  res->res_pool.use_catalog, res->res_pool.use_volume_once,
574                  res->res_pool.accept_any_volume, res->res_pool.catalog_files);
575          sendit(sock, "      max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
576                  res->res_pool.max_volumes, res->res_pool.AutoPrune,
577                  res->res_pool.VolRetention);
578          sendit(sock, "      recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
579                  NPRT(res->res_pool.label_format));
580          sendit(sock, "      CleaningPrefix=%s\n",
581                  NPRT(res->res_pool.cleaning_prefix));
582          sendit(sock, "      recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
583                  res->res_pool.recycle_oldest_volume, 
584                  res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
585          break;
586       case R_MSGS:
587          sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
588          if (res->res_msgs.mail_cmd) 
589             sendit(sock, "      mailcmd=%s\n", res->res_msgs.mail_cmd);
590          if (res->res_msgs.operator_cmd) 
591             sendit(sock, "      opcmd=%s\n", res->res_msgs.operator_cmd);
592          break;
593       default:
594          sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
595          break;
596    }
597    if (recurse && res->res_dir.hdr.next) {
598       dump_resource(type, res->res_dir.hdr.next, sendit, sock);
599    }
600 }
601
602 /*
603  * Free all the members of an INCEXE structure
604  */
605 static void free_incexe(INCEXE *incexe)
606 {
607    for (int i=0; i<incexe->num_names; i++) {
608       free(incexe->name_list[i]);
609    }
610    if (incexe->name_list) {
611       free(incexe->name_list);
612    }
613    for (int i=0; i<incexe->num_opts; i++) {
614       FOPTS *fopt = incexe->opts_list[i];
615       if (fopt->match) {
616          free(fopt->match);
617       }
618       for (int j=0; j<fopt->num_base; j++) {
619          free(fopt->base_list[j]);
620       }
621       if (fopt->base_list) {
622          free(fopt->base_list);
623       }
624       free(fopt);
625    }
626    if (incexe->opts_list) {
627       free(incexe->opts_list);
628    }
629    free(incexe);
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          }
693          if (res->res_store.password) {
694             free(res->res_store.password);
695          }
696          if (res->res_store.media_type) {
697             free(res->res_store.media_type);
698          }
699          if (res->res_store.dev_name) {
700             free(res->res_store.dev_name);
701          }
702          break;
703       case R_CATALOG:
704          if (res->res_cat.db_address) {
705             free(res->res_cat.db_address);
706          }
707          if (res->res_cat.db_socket) {
708             free(res->res_cat.db_socket);
709          }
710          if (res->res_cat.db_user) {
711             free(res->res_cat.db_user);
712          }
713          if (res->res_cat.db_name) {
714             free(res->res_cat.db_name);
715          }
716          if (res->res_cat.db_password) {
717             free(res->res_cat.db_password);
718          }
719          break;
720       case R_FILESET:
721          if ((num=res->res_fs.num_includes)) {
722             while (--num >= 0) {   
723                free_incexe(res->res_fs.include_items[num]);
724             }
725             free(res->res_fs.include_items);
726          }
727          res->res_fs.num_includes = 0;
728          if ((num=res->res_fs.num_excludes)) {
729             while (--num >= 0) {   
730                free_incexe(res->res_fs.exclude_items[num]);
731             }
732             free(res->res_fs.exclude_items);
733          }
734          res->res_fs.num_excludes = 0;
735          break;
736       case R_POOL:
737          if (res->res_pool.pool_type) {
738             free(res->res_pool.pool_type);
739          }
740          if (res->res_pool.label_format) {
741             free(res->res_pool.label_format);
742          }
743          if (res->res_pool.cleaning_prefix) {
744             free(res->res_pool.cleaning_prefix);
745          }
746          break;
747       case R_SCHEDULE:
748          if (res->res_sch.run) {
749             RUN *nrun, *next;
750             nrun = res->res_sch.run;
751             while (nrun) {
752                next = nrun->next;
753                free(nrun);
754                nrun = next;
755             }
756          }
757          break;
758       case R_JOB:
759          if (res->res_job.RestoreWhere) {
760             free(res->res_job.RestoreWhere);
761          }
762          if (res->res_job.RestoreBootstrap) {
763             free(res->res_job.RestoreBootstrap);
764          }
765          if (res->res_job.WriteBootstrap) {
766             free(res->res_job.WriteBootstrap);
767          }
768          if (res->res_job.RunBeforeJob) {
769             free(res->res_job.RunBeforeJob);
770          }
771          if (res->res_job.RunAfterJob) {
772             free(res->res_job.RunAfterJob);
773          }
774          break;
775       case R_MSGS:
776          if (res->res_msgs.mail_cmd)
777             free(res->res_msgs.mail_cmd);
778          if (res->res_msgs.operator_cmd)
779             free(res->res_msgs.operator_cmd);
780          free_msgs_res((MSGS *)res);  /* free message resource */
781          res = NULL;
782          break;
783       case R_GROUP:
784          break;
785       default:
786          printf("Unknown resource type %d in free_resource.\n", type);
787    }
788    /* Common stuff again -- free the resource, recurse to next one */
789    if (res) {
790       free(res);
791    }
792    resources[rindex].res_head = nres;
793    if (nres) {
794       free_resource(type);
795    }
796 }
797
798 /*
799  * Save the new resource by chaining it into the head list for
800  * the resource. If this is pass 2, we update any resource
801  * pointers because they may not have been defined until 
802  * later in pass 1.
803  */
804 void save_resource(int type, struct res_items *items, int pass)
805 {
806    URES *res;
807    int rindex = type - r_first;
808    int i, size;
809    int error = 0;
810    
811    /* 
812     * Ensure that all required items are present
813     */
814    for (i=0; items[i].name; i++) {
815       if (items[i].flags & ITEM_REQUIRED) {
816             if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {  
817                Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
818                  items[i].name, resources[rindex]);
819              }
820       }
821       /* If this triggers, take a look at lib/parse_conf.h */
822       if (i >= MAX_RES_ITEMS) {
823          Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
824       }
825    }
826
827    /* During pass 2 in each "store" routine, we looked up pointers 
828     * to all the resources referrenced in the current resource, now we
829     * must copy their addresses from the static record to the allocated
830     * record.
831     */
832    if (pass == 2) {
833       switch (type) {
834          /* Resources not containing a resource */
835          case R_CATALOG:
836          case R_STORAGE:
837          case R_GROUP:
838          case R_POOL:
839          case R_MSGS:
840          case R_FILESET:
841             break;
842
843          /* Resources containing another resource */
844          case R_DIRECTOR:
845             if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
846                Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
847             }
848             res->res_dir.messages = res_all.res_dir.messages;
849             break;
850          case R_JOB:
851             if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
852                Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
853             }
854             res->res_job.messages = res_all.res_job.messages;
855             res->res_job.schedule = res_all.res_job.schedule;
856             res->res_job.client   = res_all.res_job.client;
857             res->res_job.fileset  = res_all.res_job.fileset;
858             res->res_job.storage  = res_all.res_job.storage;
859             res->res_job.pool     = res_all.res_job.pool;
860             if (res->res_job.JobType == 0) {
861                Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
862             }
863             if (res->res_job.level != 0) {
864                int i;
865                for (i=0; joblevels[i].level_name; i++) {
866                   if (joblevels[i].level == res->res_job.level &&
867                       joblevels[i].job_type == res->res_job.JobType) {
868                      i = 0;
869                      break;
870                   }
871                }
872                if (i != 0) {
873                   Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n", 
874                      res_all.res_dir.hdr.name);
875                }
876             }
877             break;
878          case R_CLIENT:
879             if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
880                Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
881             }
882             res->res_client.catalog = res_all.res_client.catalog;
883             break;
884          case R_SCHEDULE:
885             /* Schedule is a bit different in that it contains a RUN record
886              * chain which isn't a "named" resource. This chain was linked
887              * in by run_conf.c during pass 2, so here we jam the pointer 
888              * into the Schedule resource.                         
889              */
890             if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
891                Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
892             }
893             res->res_sch.run = res_all.res_sch.run;
894             break;
895          default:
896             Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
897             error = 1;
898             break;
899       }
900       /* Note, the resource name was already saved during pass 1,
901        * so here, we can just release it.
902        */
903       if (res_all.res_dir.hdr.name) {
904          free(res_all.res_dir.hdr.name);
905          res_all.res_dir.hdr.name = NULL;
906       }
907       if (res_all.res_dir.hdr.desc) {
908          free(res_all.res_dir.hdr.desc);
909          res_all.res_dir.hdr.desc = NULL;
910       }
911       return;
912    }
913
914    /* The following code is only executed for pass 1 */
915    switch (type) {
916       case R_DIRECTOR:
917          size = sizeof(DIRRES);
918          break;
919       case R_CLIENT:
920          size =sizeof(CLIENT);
921          break;
922       case R_STORAGE:
923          size = sizeof(STORE); 
924          break;
925       case R_CATALOG:
926          size = sizeof(CAT);
927          break;
928       case R_JOB:
929          size = sizeof(JOB);
930          break;
931       case R_FILESET:
932          size = sizeof(FILESET);
933          break;
934       case R_SCHEDULE:
935          size = sizeof(SCHED);
936          break;
937       case R_GROUP:
938          size = sizeof(GROUP);
939          break;
940       case R_POOL:
941          size = sizeof(POOL);
942          break;
943       case R_MSGS:
944          size = sizeof(MSGS);
945          break;
946       case R_COUNTER:
947          size = sizeof(COUNTER);
948          break;
949       default:
950          printf("Unknown resource type %d in save_resrouce.\n", type);
951          error = 1;
952          size = 1;
953          break;
954    }
955    /* Common */
956    if (!error) {
957       res = (URES *)malloc(size);
958       memcpy(res, &res_all, size);
959       if (!resources[rindex].res_head) {
960          resources[rindex].res_head = (RES *)res; /* store first entry */
961          Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
962                res->res_dir.hdr.name, rindex);
963       } else {
964          RES *next;
965          /* Add new res to end of chain */
966          for (next=resources[rindex].res_head; next->next; next=next->next)
967             { }
968          next->next = (RES *)res;
969          Dmsg3(200, "Inserting %s res: %s index=%d\n", res_to_str(type),
970                res->res_dir.hdr.name, rindex);
971       }
972    }
973 }
974
975 /* 
976  * Store JobType (backup, verify, restore)
977  *
978  */
979 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
980 {
981    int token, i;   
982
983    token = lex_get_token(lc, T_NAME);
984    /* Store the type both pass 1 and pass 2 */
985    for (i=0; jobtypes[i].type_name; i++) {
986       if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
987          ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
988          i = 0;
989          break;
990       }
991    }
992    if (i != 0) {
993       scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
994    }
995    scan_to_eol(lc);
996    set_bit(index, res_all.hdr.item_present);
997 }
998
999 /* 
1000  * Store Job Level (Full, Incremental, ...)
1001  *
1002  */
1003 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1004 {
1005    int token, i;
1006
1007    token = lex_get_token(lc, T_NAME);
1008    /* Store the level pass 2 so that type is defined */
1009    for (i=0; joblevels[i].level_name; i++) {
1010       if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1011          ((JOB *)(item->value))->level = joblevels[i].level;
1012          i = 0;
1013          break;
1014       }
1015    }
1016    if (i != 0) {
1017       scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1018    }
1019    scan_to_eol(lc);
1020    set_bit(index, res_all.hdr.item_present);
1021 }
1022
1023 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1024 {
1025    int token, i;
1026    token = lex_get_token(lc, T_NAME);
1027    /* Scan Replacement options */
1028    for (i=0; ReplaceOptions[i].name; i++) {
1029       if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1030          *(int *)(item->value) = ReplaceOptions[i].token;
1031          i = 0;
1032          break;
1033       }
1034    }
1035    if (i != 0) {
1036       scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1037    }
1038    scan_to_eol(lc);
1039    set_bit(index, res_all.hdr.item_present);
1040 }
1041
1042 /* 
1043  * Store backup/verify info for Job record 
1044  *
1045  * Note, this code is used for both BACKUP and VERIFY jobs
1046  *
1047  *    Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1048  */
1049 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1050 {
1051    int token, i;
1052    RES *res;
1053    int options = lc->options;
1054
1055    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1056
1057    
1058    ((JOB *)(item->value))->JobType = item->code;
1059    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1060       int found;
1061
1062       Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1063       
1064       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1065          scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1066       }
1067       Dmsg1(190, "Got keyword: %s\n", lc->str);
1068       found = FALSE;
1069       for (i=0; BakVerFields[i].name; i++) {
1070          if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1071             found = TRUE;
1072             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1073                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1074             }
1075             token = lex_get_token(lc, T_NAME);
1076             Dmsg1(190, "Got value: %s\n", lc->str);
1077             switch (BakVerFields[i].token) {
1078                case 'C':
1079                   /* Find Client Resource */
1080                   if (pass == 2) {
1081                      res = GetResWithName(R_CLIENT, lc->str);
1082                      if (res == NULL) {
1083                         scan_err1(lc, "Could not find specified Client Resource: %s",
1084                                    lc->str);
1085                      }
1086                      res_all.res_job.client = (CLIENT *)res;
1087                   }
1088                   break;
1089                case 'F':
1090                   /* Find FileSet Resource */
1091                   if (pass == 2) {
1092                      res = GetResWithName(R_FILESET, lc->str);
1093                      if (res == NULL) {
1094                         scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1095                                     lc->str);
1096                      }
1097                      res_all.res_job.fileset = (FILESET *)res;
1098                   }
1099                   break;
1100                case 'L':
1101                   /* Get level */
1102                   for (i=0; joblevels[i].level_name; i++) {
1103                      if (joblevels[i].job_type == item->code && 
1104                           strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1105                         ((JOB *)(item->value))->level = joblevels[i].level;
1106                         i = 0;
1107                         break;
1108                      }
1109                   }
1110                   if (i != 0) {
1111                      scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1112                   }
1113                   break;
1114             } /* end switch */
1115             break;
1116          } /* end if strcmp() */
1117       } /* end for */
1118       if (!found) {
1119          scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1120       }
1121    } /* end while */
1122    lc->options = options;             /* reset original options */
1123    set_bit(index, res_all.hdr.item_present);
1124 }
1125
1126 /* 
1127  * Store restore info for Job record 
1128  *
1129  *    Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1130  *
1131  */
1132 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1133 {
1134    int token, i;
1135    RES *res;
1136    int options = lc->options;
1137
1138    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1139
1140    Dmsg0(190, "Enter store_restore()\n");
1141    
1142    ((JOB *)(item->value))->JobType = item->code;
1143    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1144       int found; 
1145
1146       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1147          scan_err1(lc, "expected a name, got: %s", lc->str);
1148       }
1149       found = FALSE;
1150       for (i=0; RestoreFields[i].name; i++) {
1151          Dmsg1(190, "Restore kw=%s\n", lc->str);
1152          if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1153             found = TRUE;
1154             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1155                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1156             }
1157             token = lex_get_token(lc, T_ALL);
1158             Dmsg1(190, "Restore value=%s\n", lc->str);
1159             switch (RestoreFields[i].token) {
1160                case 'B':
1161                   /* Bootstrap */
1162                   if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1163                      scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1164                   }
1165                   if (pass == 1) {
1166                      res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1167                   }
1168                   break;
1169                case 'C':
1170                   /* Find Client Resource */
1171                   if (pass == 2) {
1172                      res = GetResWithName(R_CLIENT, lc->str);
1173                      if (res == NULL) {
1174                         scan_err1(lc, "Could not find specified Client Resource: %s",
1175                                    lc->str);
1176                      }
1177                      res_all.res_job.client = (CLIENT *)res;
1178                   }
1179                   break;
1180                case 'F':
1181                   /* Find FileSet Resource */
1182                   if (pass == 2) {
1183                      res = GetResWithName(R_FILESET, lc->str);
1184                      if (res == NULL) {
1185                         scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1186                                     lc->str);
1187                      }
1188                      res_all.res_job.fileset = (FILESET *)res;
1189                   }
1190                   break;
1191                case 'J':
1192                   /* JobId */
1193                   if (token != T_NUMBER) {
1194                      scan_err1(lc, "expected an integer number, got: %s", lc->str);
1195                   }
1196                   errno = 0;
1197                   res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1198                   Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1199                   if (errno != 0) {
1200                      scan_err1(lc, "expected an integer number, got: %s", lc->str);
1201                   }
1202                   break;
1203                case 'W':
1204                   /* Where */
1205                   if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1206                      scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1207                   }
1208                   if (pass == 1) {
1209                      res_all.res_job.RestoreWhere = bstrdup(lc->str);
1210                   }
1211                   break;
1212                case 'R':
1213                   /* Replacement options */
1214                   if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1215                      scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1216                   }
1217                   /* Fix to scan Replacement options */
1218                   for (i=0; ReplaceOptions[i].name; i++) {
1219                      if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1220                          ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1221                         i = 0;
1222                         break;
1223                      }
1224                   }
1225                   if (i != 0) {
1226                      scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1227                   }
1228                   break;
1229             } /* end switch */
1230             break;
1231          } /* end if strcmp() */
1232       } /* end for */
1233       if (!found) {
1234          scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1235       }
1236    } /* end while */
1237    lc->options = options;             /* reset original options */
1238    set_bit(index, res_all.hdr.item_present);
1239 }