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