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