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