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