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).
6 * Note, the configuration file parser consists of three parts
8 * 1. The generic lexical scanner in lib/lex.c and lib/lex.h
10 * 2. The generic config scanner in lib/parse_config.c and
12 * These files contain the parser code, some utility
13 * routines, and the common store routines (name, int,
16 * 3. The daemon specific file, which contains the Resource
17 * definitions as well as any specific store routines
18 * for the resource records.
20 * Kern Sibbald, January MM
25 Copyright (C) 2000-2003 Kern Sibbald and John Walker
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.
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.
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,
47 /* Define the first and last resource ID record
48 * types. Note, these should be unique for each
49 * daemon though not a requirement.
51 int r_first = R_FIRST;
54 pthread_mutex_t res_mutex = PTHREAD_MUTEX_INITIALIZER;
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);
62 /* Forward referenced subroutines */
64 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
66 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
67 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
68 static void store_replace(LEX *lc, struct res_items *item, int index, int pass);
71 /* We build the current resource here as we are
72 * scanning the resource configuration definition,
73 * then move it to allocated memory when the resource
77 int res_all_size = sizeof(res_all);
80 /* Definition of records permitted within each
81 * resource with the routine to process the record
82 * information. NOTE! quoted names must be in lower case.
87 * name handler value code flags default_value
89 static struct res_items dir_items[] = {
90 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
91 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
92 {"messages", store_res, ITEM(res_dir.messages), R_MSGS, 0, 0},
93 {"dirport", store_pint, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
94 {"diraddress", store_str, ITEM(res_dir.DIRaddr), 0, 0, 0},
95 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
96 {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
97 {"piddirectory",store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
98 {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, 0, 0},
99 {"requiressl", store_yesno, ITEM(res_dir.require_ssl), 1, ITEM_DEFAULT, 0},
100 {"enablessl", store_yesno, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
101 {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
102 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
103 {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
104 {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
105 {NULL, NULL, NULL, 0, 0, 0}
111 * name handler value code flags default_value
113 static struct res_items con_items[] = {
114 {"name", store_name, ITEM(res_con.hdr.name), 0, ITEM_REQUIRED, 0},
115 {"description", store_str, ITEM(res_con.hdr.desc), 0, 0, 0},
116 {"enablessl", store_yesno, ITEM(res_con.enable_ssl), 1, ITEM_DEFAULT, 0},
117 {"password", store_password, ITEM(res_con.password), 0, ITEM_REQUIRED, 0},
118 {NULL, NULL, NULL, 0, 0, 0}
123 * Client or File daemon resource
125 * name handler value code flags default_value
128 static struct res_items cli_items[] = {
129 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
130 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
131 {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
132 {"fdaddress", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
133 {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_DEFAULT, 9102},
134 {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
135 {"fdpassword", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
136 {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0},
137 {"fileretention", store_time, ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
138 {"jobretention", store_time, ITEM(res_client.JobRetention), 0, ITEM_DEFAULT, 60*60*24*180},
139 {"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
140 {"enablessl", store_yesno, ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
141 {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
142 {NULL, NULL, NULL, 0, 0, 0}
145 /* Storage daemon resource
147 * name handler value code flags default_value
149 static struct res_items store_items[] = {
150 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
151 {"description", store_str, ITEM(res_store.hdr.desc), 0, 0, 0},
152 {"sdport", store_pint, ITEM(res_store.SDport), 0, ITEM_DEFAULT, 9103},
153 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
154 {"sdaddress", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
155 {"sdpassword", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
156 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
157 {"sddevicename", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
158 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
159 {"autochanger", store_yesno, ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
160 {"enablessl", store_yesno, ITEM(res_store.enable_ssl), 1, ITEM_DEFAULT, 0},
161 {"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
162 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
163 {NULL, NULL, NULL, 0, 0, 0}
167 * Catalog Resource Directives
169 * name handler value code flags default_value
171 static struct res_items cat_items[] = {
172 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
173 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
174 {"address", store_str, ITEM(res_cat.db_address), 0, 0, 0},
175 {"dbaddress", store_str, ITEM(res_cat.db_address), 0, 0, 0},
176 {"dbport", store_pint, ITEM(res_cat.db_port), 0, 0, 0},
177 /* keep this password as store_str for the moment */
178 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
179 {"dbpassword", store_str, ITEM(res_cat.db_password), 0, 0, 0},
180 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
181 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
182 {"dbsocket", store_str, ITEM(res_cat.db_socket), 0, 0, 0},
183 {NULL, NULL, NULL, 0, 0, 0}
187 * Job Resource Directives
189 * name handler value code flags default_value
191 static struct res_items job_items[] = {
192 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
193 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
194 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
195 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
196 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
197 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
198 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
199 {"level", store_level, ITEM(res_job), 0, 0, 0},
200 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
201 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
202 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
203 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
204 {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0},
205 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
206 {"replace", store_replace, ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS},
207 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
208 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
209 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
210 {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
211 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
212 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
213 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
214 {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0},
215 {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0},
216 {"clientrunbeforejob", store_str, ITEM(res_job.ClientRunBeforeJob), 0, 0, 0},
217 {"clientrunafterjob", store_str, ITEM(res_job.ClientRunAfterJob), 0, 0, 0},
218 {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
219 {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
220 {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
221 {"rescheduleonerror", store_yesno, ITEM(res_job.RescheduleOnError), 1, ITEM_DEFAULT, 0},
222 {"rescheduleinterval", store_time, ITEM(res_job.RescheduleInterval), 0, ITEM_DEFAULT, 60 * 30},
223 {"rescheduletimes", store_pint, ITEM(res_job.RescheduleTimes), 0, 0, 0},
224 {"priority", store_pint, ITEM(res_job.Priority), 0, ITEM_DEFAULT, 10},
225 {NULL, NULL, NULL, 0, 0, 0}
230 * name handler value code flags default_value
232 static struct res_items fs_items[] = {
233 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
234 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
235 {"include", store_inc, NULL, 0, ITEM_NO_EQUALS, 0},
236 {"exclude", store_inc, NULL, 1, ITEM_NO_EQUALS, 0},
237 {NULL, NULL, NULL, 0, 0, 0}
240 /* Schedule -- see run_conf.c */
243 * name handler value code flags default_value
245 static struct res_items sch_items[] = {
246 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
247 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
248 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
249 {NULL, NULL, NULL, 0, 0, 0}
252 /* Group resource -- not implemented
254 * name handler value code flags default_value
256 static struct res_items group_items[] = {
257 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
258 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
259 {NULL, NULL, NULL, 0, 0, 0}
264 * name handler value code flags default_value
266 static struct res_items pool_items[] = {
267 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
268 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
269 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
270 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
271 {"cleaningprefix", store_strname, ITEM(res_pool.cleaning_prefix), 0, 0, 0},
272 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
273 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
274 {"purgeoldestvolume", store_yesno, ITEM(res_pool.purge_oldest_volume), 1, 0, 0},
275 {"recycleoldestvolume", store_yesno, ITEM(res_pool.recycle_oldest_volume), 1, 0, 0},
276 {"recyclecurrentvolume", store_yesno, ITEM(res_pool.recycle_current_volume), 1, 0, 0},
277 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
278 {"maximumvolumejobs", store_pint, ITEM(res_pool.MaxVolJobs), 0, 0, 0},
279 {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles), 0, 0, 0},
280 {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes), 0, 0, 0},
281 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT, 1},
282 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
283 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
284 {"volumeuseduration", store_time, ITEM(res_pool.VolUseDuration),0, 0, 0},
285 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
286 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
287 {NULL, NULL, NULL, 0, 0, 0}
292 * name handler value code flags default_value
294 static struct res_items counter_items[] = {
295 {"name", store_name, ITEM(res_counter.hdr.name), 0, ITEM_REQUIRED, 0},
296 {"description", store_str, ITEM(res_counter.hdr.desc), 0, 0, 0},
297 {"minimum", store_int, ITEM(res_counter.MinValue), 0, ITEM_DEFAULT, 0},
298 {"maximum", store_pint, ITEM(res_counter.MaxValue), 0, ITEM_DEFAULT, INT32_MAX},
299 {"wrapcounter", store_res, ITEM(res_counter.WrapCounter), R_COUNTER, 0, 0},
300 {"catalog", store_res, ITEM(res_counter.Catalog), R_CATALOG, 0, 0},
301 {NULL, NULL, NULL, 0, 0, 0}
305 /* Message resource */
306 extern struct res_items msgs_items[];
309 * This is the master resource definition.
310 * It must have one item for each of the resources.
312 * name items rcode res_head
314 struct s_res resources[] = {
315 {"director", dir_items, R_DIRECTOR, NULL},
316 {"console", con_items, R_CONSOLE, NULL},
317 {"client", cli_items, R_CLIENT, NULL},
318 {"job", job_items, R_JOB, NULL},
319 {"storage", store_items, R_STORAGE, NULL},
320 {"catalog", cat_items, R_CATALOG, NULL},
321 {"schedule", sch_items, R_SCHEDULE, NULL},
322 {"fileset", fs_items, R_FILESET, NULL},
323 {"group", group_items, R_GROUP, NULL},
324 {"pool", pool_items, R_POOL, NULL},
325 {"messages", msgs_items, R_MSGS, NULL},
326 {"counter", counter_items, R_COUNTER, NULL},
327 {NULL, NULL, 0, NULL}
331 /* Keywords (RHS) permitted in Job Level records
333 * level_name level job_type
335 struct s_jl joblevels[] = {
336 {"Full", L_FULL, JT_BACKUP},
337 {"Base", L_BASE, JT_BACKUP},
338 {"Incremental", L_INCREMENTAL, JT_BACKUP},
339 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
340 {"Since", L_SINCE, JT_BACKUP},
341 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
342 {"InitCatalog", L_VERIFY_INIT, JT_VERIFY},
343 {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG, JT_VERIFY},
344 {"Data", L_VERIFY_DATA, JT_VERIFY},
348 /* Keywords (RHS) permitted in Job type records
352 struct s_jt jobtypes[] = {
353 {"backup", JT_BACKUP},
355 {"verify", JT_VERIFY},
356 {"restore", JT_RESTORE},
361 /* Keywords (RHS) permitted in Backup and Verify records */
362 static struct s_kw BakVerFields[] = {
369 /* Keywords (RHS) permitted in Restore records */
370 static struct s_kw RestoreFields[] = {
373 {"jobid", 'J'}, /* JobId to restore */
374 {"where", 'W'}, /* root of restore */
375 {"replace", 'R'}, /* replacement options */
376 {"bootstrap", 'B'}, /* bootstrap file */
380 /* Options permitted in Restore replace= */
381 struct s_kw ReplaceOptions[] = {
382 {"always", REPLACE_ALWAYS},
383 {"ifnewer", REPLACE_IFNEWER},
384 {"ifolder", REPLACE_IFOLDER},
385 {"never", REPLACE_NEVER},
389 char *level_to_str(int level)
392 static char level_no[30];
393 char *str = level_no;
395 sprintf(level_no, "%d", level); /* default if not found */
396 for (i=0; joblevels[i].level_name; i++) {
397 if (level == joblevels[i].level) {
398 str = joblevels[i].level_name;
405 /* Dump contents of resource */
406 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
408 URES *res = (URES *)reshdr;
410 char ed1[30], ed2[30];
413 sendit(sock, "No %s resource defined\n", res_to_str(type));
416 if (type < 0) { /* no recursion */
422 sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n",
423 reshdr->name, res->res_dir.MaxConcurrentJobs,
424 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
425 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
426 if (res->res_dir.query_file) {
427 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
429 if (res->res_dir.messages) {
430 sendit(sock, " --> ");
431 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
435 sendit(sock, "Console: name=%s SSL=%d\n",
436 res->res_con.hdr.name, res->res_con.enable_ssl);
439 if (res->res_counter.WrapCounter) {
440 sendit(sock, "Counter: name=%s min=%d max=%d cur=%d wrapcntr=%s\n",
441 res->res_counter.hdr.name, res->res_counter.MinValue,
442 res->res_counter.MaxValue, res->res_counter.CurrentValue,
443 res->res_counter.WrapCounter->hdr.name);
445 sendit(sock, "Counter: name=%s min=%d max=%d\n",
446 res->res_counter.hdr.name, res->res_counter.MinValue,
447 res->res_counter.MaxValue);
449 if (res->res_counter.Catalog) {
450 sendit(sock, " --> ");
451 dump_resource(-R_CATALOG, (RES *)res->res_counter.Catalog, sendit, sock);
456 sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
457 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
458 res->res_client.MaxConcurrentJobs);
459 sendit(sock, " JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
460 res->res_client.JobRetention, res->res_client.FileRetention,
461 res->res_client.AutoPrune);
462 if (res->res_client.catalog) {
463 sendit(sock, " --> ");
464 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
468 sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
469 DeviceName=%s MediaType=%s\n",
470 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
471 res->res_store.MaxConcurrentJobs,
472 res->res_store.dev_name, res->res_store.media_type);
475 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
477 res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
478 res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
481 sendit(sock, "Job: name=%s JobType=%d level=%s Priority=%d MaxJobs=%u\n",
482 res->res_job.hdr.name, res->res_job.JobType,
483 level_to_str(res->res_job.level), res->res_job.Priority,
484 res->res_job.MaxConcurrentJobs);
485 sendit(sock, " Resched=%d Times=%d Interval=%s\n",
486 res->res_job.RescheduleOnError, res->res_job.RescheduleTimes,
487 edit_uint64_with_commas(res->res_job.RescheduleInterval, ed1));
488 if (res->res_job.client) {
489 sendit(sock, " --> ");
490 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
492 if (res->res_job.fileset) {
493 sendit(sock, " --> ");
494 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
496 if (res->res_job.schedule) {
497 sendit(sock, " --> ");
498 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
500 if (res->res_job.RestoreWhere) {
501 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
503 if (res->res_job.RestoreBootstrap) {
504 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
506 if (res->res_job.RunBeforeJob) {
507 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
509 if (res->res_job.RunAfterJob) {
510 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
512 if (res->res_job.WriteBootstrap) {
513 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
515 if (res->res_job.storage) {
516 sendit(sock, " --> ");
517 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
519 if (res->res_job.pool) {
520 sendit(sock, " --> ");
521 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
523 sendit(sock, "!!! No Pool resource\n");
525 if (res->res_job.messages) {
526 sendit(sock, " --> ");
527 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
531 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
532 for (int i=0; i<res->res_fs.num_includes; i++) {
533 INCEXE *incexe = res->res_fs.include_items[i];
534 for (int j=0; j<incexe->name_list.size(); j++) {
535 sendit(sock, " Inc: %s\n", incexe->name_list.get(j));
538 for (int i=0; i<res->res_fs.num_excludes; i++) {
539 INCEXE *incexe = res->res_fs.exclude_items[i];
540 for (int j=0; j<incexe->name_list.size(); j++) {
541 sendit(sock, " Exc: %s\n", incexe->name_list.get(j));
546 if (res->res_sch.run) {
548 RUN *run = res->res_sch.run;
549 char buf[1000], num[10];
550 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
555 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
556 strcpy(buf, " hour=");
557 for (i=0; i<24; i++) {
558 if (bit_is_set(i, run->hour)) {
559 sprintf(num, "%d ", i);
565 strcpy(buf, " mday=");
566 for (i=0; i<31; i++) {
567 if (bit_is_set(i, run->mday)) {
568 sprintf(num, "%d ", i+1);
574 strcpy(buf, " month=");
575 for (i=0; i<12; i++) {
576 if (bit_is_set(i, run->month)) {
577 sprintf(num, "%d ", i+1);
583 strcpy(buf, " wday=");
584 for (i=0; i<7; i++) {
585 if (bit_is_set(i, run->wday)) {
586 sprintf(num, "%d ", i+1);
592 strcpy(buf, " wpos=");
593 for (i=0; i<5; i++) {
594 if (bit_is_set(i, run->wpos)) {
595 sprintf(num, "%d ", i+1);
601 sendit(sock, " mins=%d\n", run->minute);
603 sendit(sock, " --> ");
604 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
607 sendit(sock, " --> ");
608 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
611 sendit(sock, " --> ");
612 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
614 /* If another Run record is chained in, go print it */
620 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
624 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
627 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
628 res->res_pool.pool_type);
629 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
630 res->res_pool.use_catalog, res->res_pool.use_volume_once,
631 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
632 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
633 res->res_pool.max_volumes, res->res_pool.AutoPrune,
634 res->res_pool.VolRetention);
635 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
636 NPRT(res->res_pool.label_format));
637 sendit(sock, " CleaningPrefix=%s\n",
638 NPRT(res->res_pool.cleaning_prefix));
639 sendit(sock, " recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
640 res->res_pool.purge_oldest_volume,
641 res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
644 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
645 if (res->res_msgs.mail_cmd)
646 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
647 if (res->res_msgs.operator_cmd)
648 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
651 sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
654 if (recurse && res->res_dir.hdr.next) {
655 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
660 * Free all the members of an INCEXE structure
662 static void free_incexe(INCEXE *incexe)
664 incexe->name_list.destroy();
665 for (int i=0; i<incexe->num_opts; i++) {
666 FOPTS *fopt = incexe->opts_list[i];
667 fopt->match.destroy();
668 fopt->base_list.destroy();
671 if (incexe->opts_list) {
672 free(incexe->opts_list);
678 * Free memory of resource.
679 * NB, we don't need to worry about freeing any references
680 * to other resources as they will be freed when that
681 * resource chain is traversed. Mainly we worry about freeing
682 * allocated strings (names).
684 void free_resource(int type)
689 int rindex = type - r_first;
691 res = (URES *)resources[rindex].res_head;
696 /* common stuff -- free the resource name and description */
697 nres = (RES *)res->res_dir.hdr.next;
698 if (res->res_dir.hdr.name) {
699 free(res->res_dir.hdr.name);
701 if (res->res_dir.hdr.desc) {
702 free(res->res_dir.hdr.desc);
707 if (res->res_dir.working_directory) {
708 free(res->res_dir.working_directory);
710 if (res->res_dir.pid_directory) {
711 free(res->res_dir.pid_directory);
713 if (res->res_dir.subsys_directory) {
714 free(res->res_dir.subsys_directory);
716 if (res->res_dir.password) {
717 free(res->res_dir.password);
719 if (res->res_dir.query_file) {
720 free(res->res_dir.query_file);
722 if (res->res_dir.DIRaddr) {
723 free(res->res_dir.DIRaddr);
729 if (res->res_con.password) {
730 free(res->res_con.password);
734 if (res->res_client.address) {
735 free(res->res_client.address);
737 if (res->res_client.password) {
738 free(res->res_client.password);
742 if (res->res_store.address) {
743 free(res->res_store.address);
745 if (res->res_store.password) {
746 free(res->res_store.password);
748 if (res->res_store.media_type) {
749 free(res->res_store.media_type);
751 if (res->res_store.dev_name) {
752 free(res->res_store.dev_name);
756 if (res->res_cat.db_address) {
757 free(res->res_cat.db_address);
759 if (res->res_cat.db_socket) {
760 free(res->res_cat.db_socket);
762 if (res->res_cat.db_user) {
763 free(res->res_cat.db_user);
765 if (res->res_cat.db_name) {
766 free(res->res_cat.db_name);
768 if (res->res_cat.db_password) {
769 free(res->res_cat.db_password);
773 if ((num=res->res_fs.num_includes)) {
775 free_incexe(res->res_fs.include_items[num]);
777 free(res->res_fs.include_items);
779 res->res_fs.num_includes = 0;
780 if ((num=res->res_fs.num_excludes)) {
782 free_incexe(res->res_fs.exclude_items[num]);
784 free(res->res_fs.exclude_items);
786 res->res_fs.num_excludes = 0;
789 if (res->res_pool.pool_type) {
790 free(res->res_pool.pool_type);
792 if (res->res_pool.label_format) {
793 free(res->res_pool.label_format);
795 if (res->res_pool.cleaning_prefix) {
796 free(res->res_pool.cleaning_prefix);
800 if (res->res_sch.run) {
802 nrun = res->res_sch.run;
811 if (res->res_job.RestoreWhere) {
812 free(res->res_job.RestoreWhere);
814 if (res->res_job.RestoreBootstrap) {
815 free(res->res_job.RestoreBootstrap);
817 if (res->res_job.WriteBootstrap) {
818 free(res->res_job.WriteBootstrap);
820 if (res->res_job.RunBeforeJob) {
821 free(res->res_job.RunBeforeJob);
823 if (res->res_job.RunAfterJob) {
824 free(res->res_job.RunAfterJob);
826 if (res->res_job.ClientRunBeforeJob) {
827 free(res->res_job.ClientRunBeforeJob);
829 if (res->res_job.ClientRunAfterJob) {
830 free(res->res_job.ClientRunAfterJob);
834 if (res->res_msgs.mail_cmd) {
835 free(res->res_msgs.mail_cmd);
837 if (res->res_msgs.operator_cmd) {
838 free(res->res_msgs.operator_cmd);
840 free_msgs_res((MSGS *)res); /* free message resource */
846 printf("Unknown resource type %d in free_resource.\n", type);
848 /* Common stuff again -- free the resource, recurse to next one */
852 resources[rindex].res_head = nres;
859 * Save the new resource by chaining it into the head list for
860 * the resource. If this is pass 2, we update any resource
861 * pointers because they may not have been defined until
864 void save_resource(int type, struct res_items *items, int pass)
867 int rindex = type - r_first;
872 * Ensure that all required items are present
874 for (i=0; items[i].name; i++) {
875 if (items[i].flags & ITEM_REQUIRED) {
876 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
877 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
878 items[i].name, resources[rindex]);
881 /* If this triggers, take a look at lib/parse_conf.h */
882 if (i >= MAX_RES_ITEMS) {
883 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
887 /* During pass 2 in each "store" routine, we looked up pointers
888 * to all the resources referrenced in the current resource, now we
889 * must copy their addresses from the static record to the allocated
894 /* Resources not containing a resource */
904 /* Resources containing another resource */
906 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
907 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
909 res->res_dir.messages = res_all.res_dir.messages;
912 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
913 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
915 res->res_job.messages = res_all.res_job.messages;
916 res->res_job.schedule = res_all.res_job.schedule;
917 res->res_job.client = res_all.res_job.client;
918 res->res_job.fileset = res_all.res_job.fileset;
919 res->res_job.storage = res_all.res_job.storage;
920 res->res_job.pool = res_all.res_job.pool;
921 if (res->res_job.JobType == 0) {
922 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
924 if (res->res_job.level != 0) {
926 for (i=0; joblevels[i].level_name; i++) {
927 if (joblevels[i].level == res->res_job.level &&
928 joblevels[i].job_type == res->res_job.JobType) {
934 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
935 res_all.res_dir.hdr.name);
940 if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
941 Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
943 res->res_counter.Catalog = res_all.res_counter.Catalog;
944 res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
948 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
949 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
951 res->res_client.catalog = res_all.res_client.catalog;
954 /* Schedule is a bit different in that it contains a RUN record
955 * chain which isn't a "named" resource. This chain was linked
956 * in by run_conf.c during pass 2, so here we jam the pointer
957 * into the Schedule resource.
959 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
960 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
962 res->res_sch.run = res_all.res_sch.run;
965 Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
969 /* Note, the resource name was already saved during pass 1,
970 * so here, we can just release it.
972 if (res_all.res_dir.hdr.name) {
973 free(res_all.res_dir.hdr.name);
974 res_all.res_dir.hdr.name = NULL;
976 if (res_all.res_dir.hdr.desc) {
977 free(res_all.res_dir.hdr.desc);
978 res_all.res_dir.hdr.desc = NULL;
983 /* The following code is only executed for pass 1 */
986 size = sizeof(DIRRES);
989 size = sizeof(CONRES);
992 size =sizeof(CLIENT);
995 size = sizeof(STORE);
1004 size = sizeof(FILESET);
1007 size = sizeof(SCHED);
1010 size = sizeof(GROUP);
1013 size = sizeof(POOL);
1016 size = sizeof(MSGS);
1019 size = sizeof(COUNTER);
1022 printf("Unknown resource type %d in save_resrouce.\n", type);
1029 res = (URES *)malloc(size);
1030 memcpy(res, &res_all, size);
1031 if (!resources[rindex].res_head) {
1032 resources[rindex].res_head = (RES *)res; /* store first entry */
1033 Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1034 res->res_dir.hdr.name, rindex);
1037 /* Add new res to end of chain */
1038 for (next=resources[rindex].res_head; next->next; next=next->next)
1040 next->next = (RES *)res;
1041 Dmsg3(200, "Inserting %s res: %s index=%d\n", res_to_str(type),
1042 res->res_dir.hdr.name, rindex);
1048 * Store JobType (backup, verify, restore)
1051 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1055 token = lex_get_token(lc, T_NAME);
1056 /* Store the type both pass 1 and pass 2 */
1057 for (i=0; jobtypes[i].type_name; i++) {
1058 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1059 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1065 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1068 set_bit(index, res_all.hdr.item_present);
1072 * Store Job Level (Full, Incremental, ...)
1075 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1079 token = lex_get_token(lc, T_NAME);
1080 /* Store the level pass 2 so that type is defined */
1081 for (i=0; joblevels[i].level_name; i++) {
1082 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1083 ((JOB *)(item->value))->level = joblevels[i].level;
1089 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1092 set_bit(index, res_all.hdr.item_present);
1095 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1098 token = lex_get_token(lc, T_NAME);
1099 /* Scan Replacement options */
1100 for (i=0; ReplaceOptions[i].name; i++) {
1101 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1102 *(int *)(item->value) = ReplaceOptions[i].token;
1108 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1111 set_bit(index, res_all.hdr.item_present);
1115 * Store backup/verify info for Job record
1117 * Note, this code is used for both BACKUP and VERIFY jobs
1119 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1121 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1125 int options = lc->options;
1127 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1130 ((JOB *)(item->value))->JobType = item->code;
1131 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1134 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1136 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1137 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1139 Dmsg1(190, "Got keyword: %s\n", lc->str);
1140 for (i=0; BakVerFields[i].name; i++) {
1141 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1143 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1144 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1146 token = lex_get_token(lc, T_NAME);
1147 Dmsg1(190, "Got value: %s\n", lc->str);
1148 switch (BakVerFields[i].token) {
1150 /* Find Client Resource */
1152 res = GetResWithName(R_CLIENT, lc->str);
1154 scan_err1(lc, "Could not find specified Client Resource: %s",
1157 res_all.res_job.client = (CLIENT *)res;
1161 /* Find FileSet Resource */
1163 res = GetResWithName(R_FILESET, lc->str);
1165 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1168 res_all.res_job.fileset = (FILESET *)res;
1173 for (i=0; joblevels[i].level_name; i++) {
1174 if (joblevels[i].job_type == item->code &&
1175 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1176 ((JOB *)(item->value))->level = joblevels[i].level;
1182 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1187 } /* end if strcmp() */
1190 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1193 lc->options = options; /* reset original options */
1194 set_bit(index, res_all.hdr.item_present);
1198 * Store restore info for Job record
1200 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1203 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1207 int options = lc->options;
1209 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1211 Dmsg0(190, "Enter store_restore()\n");
1213 ((JOB *)(item->value))->JobType = item->code;
1214 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1217 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1218 scan_err1(lc, "expected a name, got: %s", lc->str);
1220 for (i=0; RestoreFields[i].name; i++) {
1221 Dmsg1(190, "Restore kw=%s\n", lc->str);
1222 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1224 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1225 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1227 token = lex_get_token(lc, T_ALL);
1228 Dmsg1(190, "Restore value=%s\n", lc->str);
1229 switch (RestoreFields[i].token) {
1232 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1233 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1236 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1240 /* Find Client Resource */
1242 res = GetResWithName(R_CLIENT, lc->str);
1244 scan_err1(lc, "Could not find specified Client Resource: %s",
1247 res_all.res_job.client = (CLIENT *)res;
1251 /* Find FileSet Resource */
1253 res = GetResWithName(R_FILESET, lc->str);
1255 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1258 res_all.res_job.fileset = (FILESET *)res;
1263 if (token != T_NUMBER) {
1264 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1267 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1268 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1270 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1275 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1276 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1279 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1283 /* Replacement options */
1284 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1285 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1287 /* Fix to scan Replacement options */
1288 for (i=0; ReplaceOptions[i].name; i++) {
1289 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1290 ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1296 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1301 } /* end if strcmp() */
1304 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1307 lc->options = options; /* reset original options */
1308 set_bit(index, res_all.hdr.item_present);