]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/dird_conf.c
Win32 fixes
[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,                          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    {
565       int i, j, k;
566       sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
567       for (i=0; i<res->res_fs.num_includes; i++) {
568          INCEXE *incexe = res->res_fs.include_items[i];
569          for (j=0; j<incexe->num_opts; j++) {
570             FOPTS *fo = incexe->opts_list[j];
571             sendit(sock, "      O %s\n", fo->opts);
572             for (k=0; k<fo->regex.size(); k++) {
573                sendit(sock, "      R %s\n", fo->regex.get(k));
574             }
575             for (k=0; k<fo->wild.size(); k++) {
576                sendit(sock, "      W %s\n", fo->wild.get(k));
577             }
578             for (k=0; k<fo->base.size(); k++) {
579                sendit(sock, "      B %s\n", fo->base.get(k));
580             }
581             sendit(sock, "      N\n");
582          }
583          for (j=0; j<incexe->name_list.size(); j++) {
584             sendit(sock, "      I %s\n", incexe->name_list.get(j));
585          }
586          if (incexe->name_list.size()) {
587             sendit(sock, "      N\n");
588          }
589       }
590          
591       for (i=0; i<res->res_fs.num_excludes; i++) {
592          INCEXE *incexe = res->res_fs.exclude_items[i];
593          for (j=0; j<incexe->name_list.size(); j++) {
594             sendit(sock, "      E %s\n", incexe->name_list.get(j));
595          }
596          if (incexe->name_list.size()) {
597             sendit(sock, "      N\n");
598          }
599       }
600       break;
601    }
602    case R_SCHEDULE:
603       if (res->res_sch.run) {
604          int i;
605          RUN *run = res->res_sch.run;
606          char buf[1000], num[30];
607          sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
608          if (!run) {
609             break;
610          }
611 next_run:
612          sendit(sock, "  --> Run Level=%s\n", level_to_str(run->level));
613          bstrncpy(buf, "      hour=", sizeof(buf));
614          for (i=0; i<24; i++) {
615             if (bit_is_set(i, run->hour)) {
616                bsnprintf(num, sizeof(num), "%d ", i);
617                bstrncat(buf, num, sizeof(buf));
618             }
619          }
620          bstrncat(buf, "\n", sizeof(buf));
621          sendit(sock, buf);
622          bstrncpy(buf, "      mday=", sizeof(buf));
623          for (i=0; i<31; i++) {
624             if (bit_is_set(i, run->mday)) {
625                bsnprintf(num, sizeof(num), "%d ", i);
626                bstrncat(buf, num, sizeof(buf));
627             }
628          }
629          bstrncat(buf, "\n", sizeof(buf));
630          sendit(sock, buf);
631          bstrncpy(buf, "      month=", sizeof(buf));
632          for (i=0; i<12; i++) {
633             if (bit_is_set(i, run->month)) {
634                bsnprintf(num, sizeof(num), "%d ", i);
635                bstrncat(buf, num, sizeof(buf));
636             }
637          }
638          bstrncat(buf, "\n", sizeof(buf));
639          sendit(sock, buf);
640          bstrncpy(buf, "      wday=", sizeof(buf));
641          for (i=0; i<7; i++) {
642             if (bit_is_set(i, run->wday)) {
643                bsnprintf(num, sizeof(num), "%d ", i);
644                bstrncat(buf, num, sizeof(buf));
645             }
646          }
647          bstrncat(buf, "\n", sizeof(buf));
648          sendit(sock, buf);
649          bstrncpy(buf, "      wom=", sizeof(buf));
650          for (i=0; i<5; i++) {
651             if (bit_is_set(i, run->wom)) {
652                bsnprintf(num, sizeof(num), "%d ", i);
653                bstrncat(buf, num, sizeof(buf));
654             }
655          }
656          bstrncat(buf, "\n", sizeof(buf));
657          sendit(sock, buf);
658          bstrncpy(buf, "      woy=", sizeof(buf));
659          for (i=0; i<54; i++) {
660             if (bit_is_set(i, run->woy)) {
661                bsnprintf(num, sizeof(num), "%d ", i);
662                bstrncat(buf, num, sizeof(buf));
663             }
664          }
665          bstrncat(buf, "\n", sizeof(buf));
666          sendit(sock, buf);
667          sendit(sock, "      mins=%d\n", run->minute);
668          if (run->pool) {
669             sendit(sock, "     --> ");
670             dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
671          }
672          if (run->storage) {
673             sendit(sock, "     --> ");
674             dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
675          }
676          if (run->msgs) {
677             sendit(sock, "     --> ");
678             dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
679          }
680          /* If another Run record is chained in, go print it */
681          if (run->next) {
682             run = run->next;
683             goto next_run;
684          }
685       } else {
686          sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
687       }
688       break;
689    case R_POOL:
690       sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
691               res->res_pool.pool_type);
692       sendit(sock, "      use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
693               res->res_pool.use_catalog, res->res_pool.use_volume_once,
694               res->res_pool.accept_any_volume, res->res_pool.catalog_files);
695       sendit(sock, "      max_vols=%d auto_prune=%d VolRetention=%s\n",
696               res->res_pool.max_volumes, res->res_pool.AutoPrune,
697               edit_utime(res->res_pool.VolRetention, ed1));
698       sendit(sock, "      VolUse=%s recycle=%d LabelFormat=%s\n", 
699               edit_utime(res->res_pool.VolUseDuration, ed1),
700               res->res_pool.Recycle,
701               NPRT(res->res_pool.label_format));
702       sendit(sock, "      CleaningPrefix=%s\n",
703               NPRT(res->res_pool.cleaning_prefix));
704       sendit(sock, "      recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
705               res->res_pool.purge_oldest_volume, 
706               res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
707       break;
708    case R_MSGS:
709       sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
710       if (res->res_msgs.mail_cmd) 
711          sendit(sock, "      mailcmd=%s\n", res->res_msgs.mail_cmd);
712       if (res->res_msgs.operator_cmd) 
713          sendit(sock, "      opcmd=%s\n", res->res_msgs.operator_cmd);
714       break;
715    default:
716       sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
717       break;
718    }
719    if (recurse && res->res_dir.hdr.next) {
720       dump_resource(type, res->res_dir.hdr.next, sendit, sock);
721    }
722 }
723
724 /*
725  * Free all the members of an INCEXE structure
726  */
727 static void free_incexe(INCEXE *incexe)
728 {
729    incexe->name_list.destroy();
730    for (int i=0; i<incexe->num_opts; i++) {
731       FOPTS *fopt = incexe->opts_list[i];
732       fopt->regex.destroy();
733       fopt->wild.destroy();
734       fopt->base.destroy();
735       free(fopt);
736    }
737    if (incexe->opts_list) {
738       free(incexe->opts_list);
739    }
740    free(incexe);
741 }
742
743 /* 
744  * Free memory of resource -- called when daemon terminates.
745  * NB, we don't need to worry about freeing any references
746  * to other resources as they will be freed when that 
747  * resource chain is traversed.  Mainly we worry about freeing
748  * allocated strings (names).
749  */
750 void free_resource(RES *sres, int type)
751 {
752    int num;
753    RES *nres;                         /* next resource if linked */
754    URES *res = (URES *)sres;
755
756    if (res == NULL)
757       return;
758
759    /* common stuff -- free the resource name and description */
760    nres = (RES *)res->res_dir.hdr.next;
761    if (res->res_dir.hdr.name) {
762       free(res->res_dir.hdr.name);
763    }
764    if (res->res_dir.hdr.desc) {
765       free(res->res_dir.hdr.desc);
766    }
767
768    switch (type) {
769    case R_DIRECTOR:
770       if (res->res_dir.working_directory) {
771          free(res->res_dir.working_directory);
772       }
773       if (res->res_dir.pid_directory) {
774          free(res->res_dir.pid_directory);
775       }
776       if (res->res_dir.subsys_directory) {
777          free(res->res_dir.subsys_directory);
778       }
779       if (res->res_dir.password) {
780          free(res->res_dir.password);
781       }
782       if (res->res_dir.query_file) {
783          free(res->res_dir.query_file);
784       }
785       if (res->res_dir.DIRaddr) {
786          free(res->res_dir.DIRaddr);
787       }
788       break;
789    case R_COUNTER:
790        break;
791    case R_CONSOLE:
792       if (res->res_con.password) {
793          free(res->res_con.password);
794       }
795       for (int i=0; i<Num_ACL; i++) {
796          if (res->res_con.ACL_lists[i]) {
797             delete res->res_con.ACL_lists[i];
798             res->res_con.ACL_lists[i] = NULL;
799          }
800       }
801       break;
802    case R_CLIENT:
803       if (res->res_client.address) {
804          free(res->res_client.address);
805       }
806       if (res->res_client.password) {
807          free(res->res_client.password);
808       }
809       break;
810    case R_STORAGE:
811       if (res->res_store.address) {
812          free(res->res_store.address);
813       }
814       if (res->res_store.password) {
815          free(res->res_store.password);
816       }
817       if (res->res_store.media_type) {
818          free(res->res_store.media_type);
819       }
820       if (res->res_store.dev_name) {
821          free(res->res_store.dev_name);
822       }
823       break;
824    case R_CATALOG:
825       if (res->res_cat.db_address) {
826          free(res->res_cat.db_address);
827       }
828       if (res->res_cat.db_socket) {
829          free(res->res_cat.db_socket);
830       }
831       if (res->res_cat.db_user) {
832          free(res->res_cat.db_user);
833       }
834       if (res->res_cat.db_name) {
835          free(res->res_cat.db_name);
836       }
837       if (res->res_cat.db_password) {
838          free(res->res_cat.db_password);
839       }
840       break;
841    case R_FILESET:
842       if ((num=res->res_fs.num_includes)) {
843          while (--num >= 0) {   
844             free_incexe(res->res_fs.include_items[num]);
845          }
846          free(res->res_fs.include_items);
847       }
848       res->res_fs.num_includes = 0;
849       if ((num=res->res_fs.num_excludes)) {
850          while (--num >= 0) {   
851             free_incexe(res->res_fs.exclude_items[num]);
852          }
853          free(res->res_fs.exclude_items);
854       }
855       res->res_fs.num_excludes = 0;
856       break;
857    case R_POOL:
858       if (res->res_pool.pool_type) {
859          free(res->res_pool.pool_type);
860       }
861       if (res->res_pool.label_format) {
862          free(res->res_pool.label_format);
863       }
864       if (res->res_pool.cleaning_prefix) {
865          free(res->res_pool.cleaning_prefix);
866       }
867       break;
868    case R_SCHEDULE:
869       if (res->res_sch.run) {
870          RUN *nrun, *next;
871          nrun = res->res_sch.run;
872          while (nrun) {
873             next = nrun->next;
874             free(nrun);
875             nrun = next;
876          }
877       }
878       break;
879    case R_JOB:
880    case R_JOBDEFS:
881       if (res->res_job.RestoreWhere) {
882          free(res->res_job.RestoreWhere);
883       }
884       if (res->res_job.RestoreBootstrap) {
885          free(res->res_job.RestoreBootstrap);
886       }
887       if (res->res_job.WriteBootstrap) {
888          free(res->res_job.WriteBootstrap);
889       }
890       if (res->res_job.RunBeforeJob) {
891          free(res->res_job.RunBeforeJob);
892       }
893       if (res->res_job.RunAfterJob) {
894          free(res->res_job.RunAfterJob);
895       }
896       if (res->res_job.RunAfterFailedJob) {
897          free(res->res_job.RunAfterFailedJob);
898       }
899       if (res->res_job.ClientRunBeforeJob) {
900          free(res->res_job.ClientRunBeforeJob);
901       }
902       if (res->res_job.ClientRunAfterJob) {
903          free(res->res_job.ClientRunAfterJob);
904       }
905       break;
906    case R_MSGS:
907       if (res->res_msgs.mail_cmd) {
908          free(res->res_msgs.mail_cmd);
909       }
910       if (res->res_msgs.operator_cmd) {
911          free(res->res_msgs.operator_cmd);
912       }
913       free_msgs_res((MSGS *)res);  /* free message resource */
914       res = NULL;
915       break;
916    default:
917       printf("Unknown resource type %d in free_resource.\n", type);
918    }
919    /* Common stuff again -- free the resource, recurse to next one */
920    if (res) {
921       free(res);
922    }
923    if (nres) {
924       free_resource(nres, type);
925    }
926 }
927
928 /*
929  * Save the new resource by chaining it into the head list for
930  * the resource. If this is pass 2, we update any resource
931  * pointers because they may not have been defined until 
932  * later in pass 1.
933  */
934 void save_resource(int type, RES_ITEM *items, int pass)
935 {
936    URES *res;
937    int rindex = type - r_first;
938    int i, size;
939    int error = 0;
940    
941    /* Check Job requirements after applying JobDefs */
942    if (type != R_JOB && type != R_JOBDEFS) {
943       /* 
944        * Ensure that all required items are present
945        */
946       for (i=0; items[i].name; i++) {
947          if (items[i].flags & ITEM_REQUIRED) {
948                if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {  
949                   Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
950                     items[i].name, resources[rindex]);
951                 }
952          }
953          /* If this triggers, take a look at lib/parse_conf.h */
954          if (i >= MAX_RES_ITEMS) {
955             Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
956          }
957       }
958    }
959
960    /*
961     * During pass 2 in each "store" routine, we looked up pointers 
962     * to all the resources referrenced in the current resource, now we
963     * must copy their addresses from the static record to the allocated
964     * record.
965     */
966    if (pass == 2) {
967       switch (type) {
968       /* Resources not containing a resource */
969       case R_CONSOLE:
970       case R_CATALOG:
971       case R_STORAGE:
972       case R_POOL:
973       case R_MSGS:
974       case R_FILESET:
975          break;
976
977       /* Resources containing another resource */
978       case R_DIRECTOR:
979          if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
980             Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
981          }
982          res->res_dir.messages = res_all.res_dir.messages;
983          break;
984       case R_JOB:
985       case R_JOBDEFS:
986          if ((res = (URES *)GetResWithName(type, res_all.res_dir.hdr.name)) == NULL) {
987             Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", 
988                   res_all.res_dir.hdr.name);
989          }
990          res->res_job.messages   = res_all.res_job.messages;
991          res->res_job.schedule   = res_all.res_job.schedule;
992          res->res_job.client     = res_all.res_job.client;
993          res->res_job.fileset    = res_all.res_job.fileset;
994          res->res_job.storage    = res_all.res_job.storage;
995          res->res_job.pool       = res_all.res_job.pool;
996          res->res_job.full_pool  = res_all.res_job.full_pool;
997          res->res_job.inc_pool   = res_all.res_job.inc_pool;
998          res->res_job.dif_pool   = res_all.res_job.dif_pool;
999          res->res_job.verify_job = res_all.res_job.verify_job;
1000          res->res_job.jobdefs    = res_all.res_job.jobdefs;
1001          break;
1002       case R_COUNTER:
1003          if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
1004             Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
1005          }
1006          res->res_counter.Catalog = res_all.res_counter.Catalog;
1007          res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
1008          break;
1009
1010       case R_CLIENT:
1011          if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
1012             Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
1013          }
1014          res->res_client.catalog = res_all.res_client.catalog;
1015          break;
1016       case R_SCHEDULE:
1017          /*
1018           * Schedule is a bit different in that it contains a RUN record
1019           * chain which isn't a "named" resource. This chain was linked
1020           * in by run_conf.c during pass 2, so here we jam the pointer 
1021           * into the Schedule resource.                         
1022           */
1023          if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
1024             Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
1025          }
1026          res->res_sch.run = res_all.res_sch.run;
1027          break;
1028       default:
1029          Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
1030          error = 1;
1031          break;
1032       }
1033       /* Note, the resource name was already saved during pass 1,
1034        * so here, we can just release it.
1035        */
1036       if (res_all.res_dir.hdr.name) {
1037          free(res_all.res_dir.hdr.name);
1038          res_all.res_dir.hdr.name = NULL;
1039       }
1040       if (res_all.res_dir.hdr.desc) {
1041          free(res_all.res_dir.hdr.desc);
1042          res_all.res_dir.hdr.desc = NULL;
1043       }
1044       return;
1045    }
1046
1047    /*
1048     * The following code is only executed during pass 1   
1049     */
1050    switch (type) {
1051    case R_DIRECTOR:
1052       size = sizeof(DIRRES);
1053       break;
1054    case R_CONSOLE:
1055       size = sizeof(CONRES);
1056       break;
1057    case R_CLIENT:
1058       size =sizeof(CLIENT);
1059       break;
1060    case R_STORAGE:
1061       size = sizeof(STORE); 
1062       break;
1063    case R_CATALOG:
1064       size = sizeof(CAT);
1065       break;
1066    case R_JOB:
1067    case R_JOBDEFS:
1068       size = sizeof(JOB);
1069       break;
1070    case R_FILESET:
1071       size = sizeof(FILESET);
1072       break;
1073    case R_SCHEDULE:
1074       size = sizeof(SCHED);
1075       break;
1076    case R_POOL:
1077       size = sizeof(POOL);
1078       break;
1079    case R_MSGS:
1080       size = sizeof(MSGS);
1081       break;
1082    case R_COUNTER:
1083       size = sizeof(COUNTER);
1084       break;
1085    default:
1086       printf("Unknown resource type %d in save_resrouce.\n", type);
1087       error = 1;
1088       size = 1;
1089       break;
1090    }
1091    /* Common */
1092    if (!error) {
1093       res = (URES *)malloc(size);
1094       memcpy(res, &res_all, size);
1095       if (!resources[rindex].res_head) {
1096          resources[rindex].res_head = (RES *)res; /* store first entry */
1097          Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1098                res->res_dir.hdr.name, rindex);
1099       } else {
1100          RES *next;
1101          /* Add new res to end of chain */
1102          for (next=resources[rindex].res_head; next->next; next=next->next) {
1103             if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
1104                Emsg2(M_ERROR_TERM, 0,
1105                   _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
1106                   resources[rindex].name, res->res_dir.hdr.name);
1107             }
1108          }
1109          next->next = (RES *)res;
1110          Dmsg4(200, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type),
1111                res->res_dir.hdr.name, rindex, pass);
1112       }
1113    }
1114 }
1115
1116 /* 
1117  * Store JobType (backup, verify, restore)
1118  *
1119  */
1120 void store_jobtype(LEX *lc, RES_ITEM *item, int index, int pass)
1121 {
1122    int token, i;   
1123
1124    token = lex_get_token(lc, T_NAME);
1125    /* Store the type both pass 1 and pass 2 */
1126    for (i=0; jobtypes[i].type_name; i++) {
1127       if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1128          *(int *)(item->value) = jobtypes[i].job_type;
1129          i = 0;
1130          break;
1131       }
1132    }
1133    if (i != 0) {
1134       scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1135    }
1136    scan_to_eol(lc);
1137    set_bit(index, res_all.hdr.item_present);
1138 }
1139
1140 /* 
1141  * Store Job Level (Full, Incremental, ...)
1142  *
1143  */
1144 void store_level(LEX *lc, RES_ITEM *item, int index, int pass)
1145 {
1146    int token, i;
1147
1148    token = lex_get_token(lc, T_NAME);
1149    /* Store the level pass 2 so that type is defined */
1150    for (i=0; joblevels[i].level_name; i++) {
1151       if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1152          *(int *)(item->value) = joblevels[i].level;
1153          i = 0;
1154          break;
1155       }
1156    }
1157    if (i != 0) {
1158       scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1159    }
1160    scan_to_eol(lc);
1161    set_bit(index, res_all.hdr.item_present);
1162 }
1163
1164 void store_replace(LEX *lc, RES_ITEM *item, int index, int pass)
1165 {
1166    int token, i;
1167    token = lex_get_token(lc, T_NAME);
1168    /* Scan Replacement options */
1169    for (i=0; ReplaceOptions[i].name; i++) {
1170       if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1171          *(int *)(item->value) = ReplaceOptions[i].token;
1172          i = 0;
1173          break;
1174       }
1175    }
1176    if (i != 0) {
1177       scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1178    }
1179    scan_to_eol(lc);
1180    set_bit(index, res_all.hdr.item_present);
1181 }
1182
1183 /* 
1184  * Store ACL (access control list)
1185  *
1186  */
1187 void store_acl(LEX *lc, RES_ITEM *item, int index, int pass)
1188 {
1189    int token;
1190
1191    for (;;) {
1192       token = lex_get_token(lc, T_NAME);
1193       if (pass == 1) {
1194          if (((alist **)item->value)[item->code] == NULL) {   
1195             ((alist **)item->value)[item->code] = new alist(10, owned_by_alist);
1196 //          Dmsg1(400, "Defined new ACL alist at %d\n", item->code);
1197          }
1198          ((alist **)item->value)[item->code]->append(bstrdup(lc->str));
1199 //       Dmsg2(400, "Appended to %d %s\n", item->code, lc->str);
1200       }
1201       token = lex_get_token(lc, T_ALL);
1202       if (token == T_COMMA) {
1203          continue;                    /* get another ACL */
1204       }
1205       break;
1206    }
1207    set_bit(index, res_all.hdr.item_present);
1208 }
1209
1210
1211 #ifdef old_deprecated_code
1212 /* 
1213  * Store backup/verify info for Job record 
1214  *
1215  * Note, this code is used for both BACKUP and VERIFY jobs
1216  *
1217  *    Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1218  */
1219 static void store_backup(LEX *lc, RES_ITEM *item, int index, int pass)
1220 {
1221    int token, i;
1222    RES *res;
1223    int options = lc->options;
1224
1225    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1226
1227    
1228    ((JOB *)(item->value))->JobType = item->code;
1229    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1230       bool found = false;
1231
1232       Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1233       
1234       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1235          scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1236       }
1237       Dmsg1(190, "Got keyword: %s\n", lc->str);
1238       for (i=0; BakVerFields[i].name; i++) {
1239          if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1240             found = true;
1241             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1242                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1243             }
1244             token = lex_get_token(lc, T_NAME);
1245             Dmsg1(190, "Got value: %s\n", lc->str);
1246             switch (BakVerFields[i].token) {
1247             case 'C':
1248                /* Find Client Resource */
1249                if (pass == 2) {
1250                   res = GetResWithName(R_CLIENT, lc->str);
1251                   if (res == NULL) {
1252                      scan_err1(lc, "Could not find specified Client Resource: %s",
1253                                 lc->str);
1254                   }
1255                   res_all.res_job.client = (CLIENT *)res;
1256                }
1257                break;
1258             case 'F':
1259                /* Find FileSet Resource */
1260                if (pass == 2) {
1261                   res = GetResWithName(R_FILESET, lc->str);
1262                   if (res == NULL) {
1263                      scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1264                                  lc->str);
1265                   }
1266                   res_all.res_job.fileset = (FILESET *)res;
1267                }
1268                break;
1269             case 'L':
1270                /* Get level */
1271                for (i=0; joblevels[i].level_name; i++) {
1272                   if (joblevels[i].job_type == item->code && 
1273                        strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1274                      ((JOB *)(item->value))->level = joblevels[i].level;
1275                      i = 0;
1276                      break;
1277                   }
1278                }
1279                if (i != 0) {
1280                   scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1281                }
1282                break;
1283             } /* end switch */
1284             break;
1285          } /* end if strcmp() */
1286       } /* end for */
1287       if (!found) {
1288          scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1289       }
1290    } /* end while */
1291    lc->options = options;             /* reset original options */
1292    set_bit(index, res_all.hdr.item_present);
1293 }
1294
1295 /* 
1296  * Store restore info for Job record 
1297  *
1298  *    Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1299  *
1300  */
1301 static void store_restore(LEX *lc, RES_ITEM *item, int index, int pass)
1302 {
1303    int token, i;
1304    RES *res;
1305    int options = lc->options;
1306
1307    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1308
1309    Dmsg0(190, "Enter store_restore()\n");
1310    
1311    ((JOB *)(item->value))->JobType = item->code;
1312    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1313       bool found = false;
1314
1315       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1316          scan_err1(lc, "expected a name, got: %s", lc->str);
1317       }
1318       for (i=0; RestoreFields[i].name; i++) {
1319          Dmsg1(190, "Restore kw=%s\n", lc->str);
1320          if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1321             found = true;
1322             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1323                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1324             }
1325             token = lex_get_token(lc, T_ALL);
1326             Dmsg1(190, "Restore value=%s\n", lc->str);
1327             switch (RestoreFields[i].token) {
1328             case 'B':
1329                /* Bootstrap */
1330                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1331                   scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1332                }
1333                if (pass == 1) {
1334                   res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1335                }
1336                break;
1337             case 'C':
1338                /* Find Client Resource */
1339                if (pass == 2) {
1340                   res = GetResWithName(R_CLIENT, lc->str);
1341                   if (res == NULL) {
1342                      scan_err1(lc, "Could not find specified Client Resource: %s",
1343                                 lc->str);
1344                   }
1345                   res_all.res_job.client = (CLIENT *)res;
1346                }
1347                break;
1348             case 'F':
1349                /* Find FileSet Resource */
1350                if (pass == 2) {
1351                   res = GetResWithName(R_FILESET, lc->str);
1352                   if (res == NULL) {
1353                      scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1354                                  lc->str);
1355                   }
1356                   res_all.res_job.fileset = (FILESET *)res;
1357                }
1358                break;
1359             case 'J':
1360                /* JobId */
1361                if (token != T_NUMBER) {
1362                   scan_err1(lc, "expected an integer number, got: %s", lc->str);
1363                }
1364                errno = 0;
1365                res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1366                Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1367                if (errno != 0) {
1368                   scan_err1(lc, "expected an integer number, got: %s", lc->str);
1369                }
1370                break;
1371             case 'W':
1372                /* Where */
1373                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1374                   scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1375                }
1376                if (pass == 1) {
1377                   res_all.res_job.RestoreWhere = bstrdup(lc->str);
1378                }
1379                break;
1380             case 'R':
1381                /* Replacement options */
1382                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1383                   scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1384                }
1385                /* Fix to scan Replacement options */
1386                for (i=0; ReplaceOptions[i].name; i++) {
1387                   if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1388                       ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1389                      i = 0;
1390                      break;
1391                   }
1392                }
1393                if (i != 0) {
1394                   scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1395                }
1396                break;
1397             } /* end switch */
1398             break;
1399          } /* end if strcmp() */
1400       } /* end for */
1401       if (!found) {
1402          scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1403       }
1404    } /* end while */
1405    lc->options = options;             /* reset original options */
1406    set_bit(index, res_all.hdr.item_present);
1407 }
1408 #endif