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