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, 0, 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, 0, 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, 0, 0},
155 {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
156 {"sdpassword", store_password, ITEM(res_store.password), 0, 0, 0},
157 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
158 {"sddevicename", store_strname, ITEM(res_store.dev_name), 0, 0, 0},
159 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
160 {"autochanger", store_yesno, ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
161 {"enablessl", store_yesno, ITEM(res_store.enable_ssl), 1, ITEM_DEFAULT, 0},
162 {"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
163 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
164 {NULL, NULL, NULL, 0, 0, 0}
168 * Catalog Resource Directives
170 * name handler value code flags default_value
172 static struct res_items cat_items[] = {
173 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
174 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
175 {"address", store_str, ITEM(res_cat.db_address), 0, 0, 0},
176 {"dbaddress", store_str, ITEM(res_cat.db_address), 0, 0, 0},
177 {"dbport", store_pint, ITEM(res_cat.db_port), 0, 0, 0},
178 /* keep this password as store_str for the moment */
179 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
180 {"dbpassword", store_str, ITEM(res_cat.db_password), 0, 0, 0},
181 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
182 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
183 {"dbsocket", store_str, ITEM(res_cat.db_socket), 0, 0, 0},
184 {NULL, NULL, NULL, 0, 0, 0}
188 * Job Resource Directives
190 * name handler value code flags default_value
192 static struct res_items job_items[] = {
193 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
194 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
195 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
196 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
197 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
198 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
199 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
200 {"level", store_level, ITEM(res_job), 0, 0, 0},
201 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
202 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
203 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
204 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
205 {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0},
206 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
207 {"replace", store_replace, ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS},
208 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
209 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
210 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
211 {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
212 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
213 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
214 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
215 {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0},
216 {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0},
217 {"clientrunbeforejob", store_str, ITEM(res_job.ClientRunBeforeJob), 0, 0, 0},
218 {"clientrunafterjob", store_str, ITEM(res_job.ClientRunAfterJob), 0, 0, 0},
219 {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
220 {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
221 {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
222 {"rescheduleonerror", store_yesno, ITEM(res_job.RescheduleOnError), 1, ITEM_DEFAULT, 0},
223 {"rescheduleinterval", store_time, ITEM(res_job.RescheduleInterval), 0, ITEM_DEFAULT, 60 * 30},
224 {"rescheduletimes", store_pint, ITEM(res_job.RescheduleTimes), 0, 0, 0},
225 {"priority", store_pint, ITEM(res_job.Priority), 0, ITEM_DEFAULT, 10},
226 {NULL, NULL, NULL, 0, 0, 0}
231 * name handler value code flags default_value
233 static struct res_items fs_items[] = {
234 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
235 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
236 {"include", store_inc, NULL, 0, ITEM_NO_EQUALS, 0},
237 {"exclude", store_inc, NULL, 1, ITEM_NO_EQUALS, 0},
238 {NULL, NULL, NULL, 0, 0, 0}
241 /* Schedule -- see run_conf.c */
244 * name handler value code flags default_value
246 static struct res_items sch_items[] = {
247 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
248 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
249 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
250 {NULL, NULL, NULL, 0, 0, 0}
253 /* Group resource -- not implemented
255 * name handler value code flags default_value
257 static struct res_items group_items[] = {
258 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
259 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
260 {NULL, NULL, NULL, 0, 0, 0}
265 * name handler value code flags default_value
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}
293 * name handler value code flags default_value
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}
306 /* Message resource */
307 extern struct res_items msgs_items[];
310 * This is the master resource definition.
311 * It must have one item for each of the resources.
313 * name items rcode res_head
315 struct s_res resources[] = {
316 {"director", dir_items, R_DIRECTOR, NULL},
317 {"console", con_items, R_CONSOLE, NULL},
318 {"client", cli_items, R_CLIENT, NULL},
319 {"job", job_items, R_JOB, NULL},
320 {"storage", store_items, R_STORAGE, NULL},
321 {"catalog", cat_items, R_CATALOG, NULL},
322 {"schedule", sch_items, R_SCHEDULE, NULL},
323 {"fileset", fs_items, R_FILESET, NULL},
324 {"group", group_items, R_GROUP, NULL},
325 {"pool", pool_items, R_POOL, NULL},
326 {"messages", msgs_items, R_MSGS, NULL},
327 {"counter", counter_items, R_COUNTER, NULL},
328 {NULL, NULL, 0, NULL}
332 /* Keywords (RHS) permitted in Job Level records
334 * level_name level job_type
336 struct s_jl joblevels[] = {
337 {"Full", L_FULL, JT_BACKUP},
338 {"Base", L_BASE, JT_BACKUP},
339 {"Incremental", L_INCREMENTAL, JT_BACKUP},
340 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
341 {"Since", L_SINCE, JT_BACKUP},
342 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
343 {"InitCatalog", L_VERIFY_INIT, JT_VERIFY},
344 {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG, JT_VERIFY},
345 {"Data", L_VERIFY_DATA, JT_VERIFY},
349 /* Keywords (RHS) permitted in Job type records
353 struct s_jt jobtypes[] = {
354 {"backup", JT_BACKUP},
356 {"verify", JT_VERIFY},
357 {"restore", JT_RESTORE},
362 /* Keywords (RHS) permitted in Backup and Verify records */
363 static struct s_kw BakVerFields[] = {
370 /* Keywords (RHS) permitted in Restore records */
371 static struct s_kw RestoreFields[] = {
374 {"jobid", 'J'}, /* JobId to restore */
375 {"where", 'W'}, /* root of restore */
376 {"replace", 'R'}, /* replacement options */
377 {"bootstrap", 'B'}, /* bootstrap file */
381 /* Options permitted in Restore replace= */
382 struct s_kw ReplaceOptions[] = {
383 {"always", REPLACE_ALWAYS},
384 {"ifnewer", REPLACE_IFNEWER},
385 {"ifolder", REPLACE_IFOLDER},
386 {"never", REPLACE_NEVER},
390 char *level_to_str(int level)
393 static char level_no[30];
394 char *str = level_no;
396 sprintf(level_no, "%d", level); /* default if not found */
397 for (i=0; joblevels[i].level_name; i++) {
398 if (level == joblevels[i].level) {
399 str = joblevels[i].level_name;
406 /* Dump contents of resource */
407 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
409 URES *res = (URES *)reshdr;
411 char ed1[30], ed2[30];
414 sendit(sock, "No %s resource defined\n", res_to_str(type));
417 if (type < 0) { /* no recursion */
423 sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n",
424 reshdr->name, res->res_dir.MaxConcurrentJobs,
425 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
426 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
427 if (res->res_dir.query_file) {
428 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
430 if (res->res_dir.messages) {
431 sendit(sock, " --> ");
432 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
436 sendit(sock, "Console: name=%s SSL=%d\n",
437 res->res_con.hdr.name, res->res_con.enable_ssl);
440 if (res->res_counter.WrapCounter) {
441 sendit(sock, "Counter: name=%s min=%d max=%d cur=%d wrapcntr=%s\n",
442 res->res_counter.hdr.name, res->res_counter.MinValue,
443 res->res_counter.MaxValue, res->res_counter.CurrentValue,
444 res->res_counter.WrapCounter->hdr.name);
446 sendit(sock, "Counter: name=%s min=%d max=%d\n",
447 res->res_counter.hdr.name, res->res_counter.MinValue,
448 res->res_counter.MaxValue);
450 if (res->res_counter.Catalog) {
451 sendit(sock, " --> ");
452 dump_resource(-R_CATALOG, (RES *)res->res_counter.Catalog, sendit, sock);
457 sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
458 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
459 res->res_client.MaxConcurrentJobs);
460 sendit(sock, " JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
461 res->res_client.JobRetention, res->res_client.FileRetention,
462 res->res_client.AutoPrune);
463 if (res->res_client.catalog) {
464 sendit(sock, " --> ");
465 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
469 sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
470 DeviceName=%s MediaType=%s\n",
471 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
472 res->res_store.MaxConcurrentJobs,
473 res->res_store.dev_name, res->res_store.media_type);
476 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
478 res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
479 res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
482 sendit(sock, "Job: name=%s JobType=%d level=%s Priority=%d MaxJobs=%u\n",
483 res->res_job.hdr.name, res->res_job.JobType,
484 level_to_str(res->res_job.level), res->res_job.Priority,
485 res->res_job.MaxConcurrentJobs);
486 sendit(sock, " Resched=%d Times=%d Interval=%s\n",
487 res->res_job.RescheduleOnError, res->res_job.RescheduleTimes,
488 edit_uint64_with_commas(res->res_job.RescheduleInterval, ed1));
489 if (res->res_job.client) {
490 sendit(sock, " --> ");
491 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
493 if (res->res_job.fileset) {
494 sendit(sock, " --> ");
495 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
497 if (res->res_job.schedule) {
498 sendit(sock, " --> ");
499 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
501 if (res->res_job.RestoreWhere) {
502 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
504 if (res->res_job.RestoreBootstrap) {
505 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
507 if (res->res_job.RunBeforeJob) {
508 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
510 if (res->res_job.RunAfterJob) {
511 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
513 if (res->res_job.WriteBootstrap) {
514 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
516 if (res->res_job.storage) {
517 sendit(sock, " --> ");
518 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
520 if (res->res_job.pool) {
521 sendit(sock, " --> ");
522 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
524 sendit(sock, "!!! No Pool resource\n");
526 if (res->res_job.messages) {
527 sendit(sock, " --> ");
528 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
532 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
533 for (int i=0; i<res->res_fs.num_includes; i++) {
534 INCEXE *incexe = res->res_fs.include_items[i];
535 for (int j=0; j<incexe->name_list.size(); j++) {
536 sendit(sock, " Inc: %s\n", incexe->name_list.get(j));
539 for (int i=0; i<res->res_fs.num_excludes; i++) {
540 INCEXE *incexe = res->res_fs.exclude_items[i];
541 for (int j=0; j<incexe->name_list.size(); j++) {
542 sendit(sock, " Exc: %s\n", incexe->name_list.get(j));
547 if (res->res_sch.run) {
549 RUN *run = res->res_sch.run;
550 char buf[1000], num[10];
551 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
556 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
557 strcpy(buf, " hour=");
558 for (i=0; i<24; i++) {
559 if (bit_is_set(i, run->hour)) {
560 sprintf(num, "%d ", i);
566 strcpy(buf, " mday=");
567 for (i=0; i<31; i++) {
568 if (bit_is_set(i, run->mday)) {
569 sprintf(num, "%d ", i+1);
575 strcpy(buf, " month=");
576 for (i=0; i<12; i++) {
577 if (bit_is_set(i, run->month)) {
578 sprintf(num, "%d ", i+1);
584 strcpy(buf, " wday=");
585 for (i=0; i<7; i++) {
586 if (bit_is_set(i, run->wday)) {
587 sprintf(num, "%d ", i+1);
593 strcpy(buf, " wpos=");
594 for (i=0; i<5; i++) {
595 if (bit_is_set(i, run->wpos)) {
596 sprintf(num, "%d ", i+1);
602 sendit(sock, " mins=%d\n", run->minute);
604 sendit(sock, " --> ");
605 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
608 sendit(sock, " --> ");
609 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
612 sendit(sock, " --> ");
613 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
615 /* If another Run record is chained in, go print it */
621 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
625 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
628 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
629 res->res_pool.pool_type);
630 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
631 res->res_pool.use_catalog, res->res_pool.use_volume_once,
632 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
633 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
634 res->res_pool.max_volumes, res->res_pool.AutoPrune,
635 res->res_pool.VolRetention);
636 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
637 NPRT(res->res_pool.label_format));
638 sendit(sock, " CleaningPrefix=%s\n",
639 NPRT(res->res_pool.cleaning_prefix));
640 sendit(sock, " recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
641 res->res_pool.purge_oldest_volume,
642 res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
645 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
646 if (res->res_msgs.mail_cmd)
647 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
648 if (res->res_msgs.operator_cmd)
649 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
652 sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
655 if (recurse && res->res_dir.hdr.next) {
656 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
661 * Free all the members of an INCEXE structure
663 static void free_incexe(INCEXE *incexe)
665 incexe->name_list.destroy();
666 for (int i=0; i<incexe->num_opts; i++) {
667 FOPTS *fopt = incexe->opts_list[i];
668 fopt->match.destroy();
669 fopt->base_list.destroy();
672 if (incexe->opts_list) {
673 free(incexe->opts_list);
679 * Free memory of resource.
680 * NB, we don't need to worry about freeing any references
681 * to other resources as they will be freed when that
682 * resource chain is traversed. Mainly we worry about freeing
683 * allocated strings (names).
685 void free_resource(int type)
690 int rindex = type - r_first;
692 res = (URES *)resources[rindex].res_head;
697 /* common stuff -- free the resource name and description */
698 nres = (RES *)res->res_dir.hdr.next;
699 if (res->res_dir.hdr.name) {
700 free(res->res_dir.hdr.name);
702 if (res->res_dir.hdr.desc) {
703 free(res->res_dir.hdr.desc);
708 if (res->res_dir.working_directory) {
709 free(res->res_dir.working_directory);
711 if (res->res_dir.pid_directory) {
712 free(res->res_dir.pid_directory);
714 if (res->res_dir.subsys_directory) {
715 free(res->res_dir.subsys_directory);
717 if (res->res_dir.password) {
718 free(res->res_dir.password);
720 if (res->res_dir.query_file) {
721 free(res->res_dir.query_file);
723 if (res->res_dir.DIRaddr) {
724 free(res->res_dir.DIRaddr);
730 if (res->res_con.password) {
731 free(res->res_con.password);
735 if (res->res_client.address) {
736 free(res->res_client.address);
738 if (res->res_client.password) {
739 free(res->res_client.password);
743 if (res->res_store.address) {
744 free(res->res_store.address);
746 if (res->res_store.password) {
747 free(res->res_store.password);
749 if (res->res_store.media_type) {
750 free(res->res_store.media_type);
752 if (res->res_store.dev_name) {
753 free(res->res_store.dev_name);
757 if (res->res_cat.db_address) {
758 free(res->res_cat.db_address);
760 if (res->res_cat.db_socket) {
761 free(res->res_cat.db_socket);
763 if (res->res_cat.db_user) {
764 free(res->res_cat.db_user);
766 if (res->res_cat.db_name) {
767 free(res->res_cat.db_name);
769 if (res->res_cat.db_password) {
770 free(res->res_cat.db_password);
774 if ((num=res->res_fs.num_includes)) {
776 free_incexe(res->res_fs.include_items[num]);
778 free(res->res_fs.include_items);
780 res->res_fs.num_includes = 0;
781 if ((num=res->res_fs.num_excludes)) {
783 free_incexe(res->res_fs.exclude_items[num]);
785 free(res->res_fs.exclude_items);
787 res->res_fs.num_excludes = 0;
790 if (res->res_pool.pool_type) {
791 free(res->res_pool.pool_type);
793 if (res->res_pool.label_format) {
794 free(res->res_pool.label_format);
796 if (res->res_pool.cleaning_prefix) {
797 free(res->res_pool.cleaning_prefix);
801 if (res->res_sch.run) {
803 nrun = res->res_sch.run;
812 if (res->res_job.RestoreWhere) {
813 free(res->res_job.RestoreWhere);
815 if (res->res_job.RestoreBootstrap) {
816 free(res->res_job.RestoreBootstrap);
818 if (res->res_job.WriteBootstrap) {
819 free(res->res_job.WriteBootstrap);
821 if (res->res_job.RunBeforeJob) {
822 free(res->res_job.RunBeforeJob);
824 if (res->res_job.RunAfterJob) {
825 free(res->res_job.RunAfterJob);
827 if (res->res_job.ClientRunBeforeJob) {
828 free(res->res_job.ClientRunBeforeJob);
830 if (res->res_job.ClientRunAfterJob) {
831 free(res->res_job.ClientRunAfterJob);
835 if (res->res_msgs.mail_cmd) {
836 free(res->res_msgs.mail_cmd);
838 if (res->res_msgs.operator_cmd) {
839 free(res->res_msgs.operator_cmd);
841 free_msgs_res((MSGS *)res); /* free message resource */
847 printf("Unknown resource type %d in free_resource.\n", type);
849 /* Common stuff again -- free the resource, recurse to next one */
853 resources[rindex].res_head = nres;
860 * Save the new resource by chaining it into the head list for
861 * the resource. If this is pass 2, we update any resource
862 * pointers because they may not have been defined until
865 void save_resource(int type, struct res_items *items, int pass)
868 int rindex = type - r_first;
873 * Ensure that all required items are present
875 for (i=0; items[i].name; i++) {
876 if (items[i].flags & ITEM_REQUIRED) {
877 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
878 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
879 items[i].name, resources[rindex]);
882 /* If this triggers, take a look at lib/parse_conf.h */
883 if (i >= MAX_RES_ITEMS) {
884 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
888 /* During pass 2 in each "store" routine, we looked up pointers
889 * to all the resources referrenced in the current resource, now we
890 * must copy their addresses from the static record to the allocated
895 /* Resources not containing a resource */
905 /* Resources containing another resource */
907 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
908 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
910 res->res_dir.messages = res_all.res_dir.messages;
913 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
914 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
916 res->res_job.messages = res_all.res_job.messages;
917 res->res_job.schedule = res_all.res_job.schedule;
918 res->res_job.client = res_all.res_job.client;
919 res->res_job.fileset = res_all.res_job.fileset;
920 res->res_job.storage = res_all.res_job.storage;
921 res->res_job.pool = res_all.res_job.pool;
922 if (res->res_job.JobType == 0) {
923 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
925 if (res->res_job.level != 0) {
927 for (i=0; joblevels[i].level_name; i++) {
928 if (joblevels[i].level == res->res_job.level &&
929 joblevels[i].job_type == res->res_job.JobType) {
935 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
936 res_all.res_dir.hdr.name);
941 if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
942 Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
944 res->res_counter.Catalog = res_all.res_counter.Catalog;
945 res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
949 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
950 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
952 res->res_client.catalog = res_all.res_client.catalog;
955 /* Schedule is a bit different in that it contains a RUN record
956 * chain which isn't a "named" resource. This chain was linked
957 * in by run_conf.c during pass 2, so here we jam the pointer
958 * into the Schedule resource.
960 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
961 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
963 res->res_sch.run = res_all.res_sch.run;
966 Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
970 /* Note, the resource name was already saved during pass 1,
971 * so here, we can just release it.
973 if (res_all.res_dir.hdr.name) {
974 free(res_all.res_dir.hdr.name);
975 res_all.res_dir.hdr.name = NULL;
977 if (res_all.res_dir.hdr.desc) {
978 free(res_all.res_dir.hdr.desc);
979 res_all.res_dir.hdr.desc = NULL;
984 /* The following code is only executed for pass 1 */
987 size = sizeof(DIRRES);
990 size = sizeof(CONRES);
993 size =sizeof(CLIENT);
996 size = sizeof(STORE);
1005 size = sizeof(FILESET);
1008 size = sizeof(SCHED);
1011 size = sizeof(GROUP);
1014 size = sizeof(POOL);
1017 size = sizeof(MSGS);
1020 size = sizeof(COUNTER);
1023 printf("Unknown resource type %d in save_resrouce.\n", type);
1030 res = (URES *)malloc(size);
1031 memcpy(res, &res_all, size);
1032 if (!resources[rindex].res_head) {
1033 resources[rindex].res_head = (RES *)res; /* store first entry */
1034 Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1035 res->res_dir.hdr.name, rindex);
1038 /* Add new res to end of chain */
1039 for (next=resources[rindex].res_head; next->next; next=next->next)
1041 next->next = (RES *)res;
1042 Dmsg3(200, "Inserting %s res: %s index=%d\n", res_to_str(type),
1043 res->res_dir.hdr.name, rindex);
1049 * Store JobType (backup, verify, restore)
1052 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1056 token = lex_get_token(lc, T_NAME);
1057 /* Store the type both pass 1 and pass 2 */
1058 for (i=0; jobtypes[i].type_name; i++) {
1059 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1060 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1066 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1069 set_bit(index, res_all.hdr.item_present);
1073 * Store Job Level (Full, Incremental, ...)
1076 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1080 token = lex_get_token(lc, T_NAME);
1081 /* Store the level pass 2 so that type is defined */
1082 for (i=0; joblevels[i].level_name; i++) {
1083 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1084 ((JOB *)(item->value))->level = joblevels[i].level;
1090 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1093 set_bit(index, res_all.hdr.item_present);
1096 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1099 token = lex_get_token(lc, T_NAME);
1100 /* Scan Replacement options */
1101 for (i=0; ReplaceOptions[i].name; i++) {
1102 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1103 *(int *)(item->value) = ReplaceOptions[i].token;
1109 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1112 set_bit(index, res_all.hdr.item_present);
1116 * Store backup/verify info for Job record
1118 * Note, this code is used for both BACKUP and VERIFY jobs
1120 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1122 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1126 int options = lc->options;
1128 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1131 ((JOB *)(item->value))->JobType = item->code;
1132 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1135 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1137 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1138 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1140 Dmsg1(190, "Got keyword: %s\n", lc->str);
1141 for (i=0; BakVerFields[i].name; i++) {
1142 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1144 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1145 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1147 token = lex_get_token(lc, T_NAME);
1148 Dmsg1(190, "Got value: %s\n", lc->str);
1149 switch (BakVerFields[i].token) {
1151 /* Find Client Resource */
1153 res = GetResWithName(R_CLIENT, lc->str);
1155 scan_err1(lc, "Could not find specified Client Resource: %s",
1158 res_all.res_job.client = (CLIENT *)res;
1162 /* Find FileSet Resource */
1164 res = GetResWithName(R_FILESET, lc->str);
1166 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1169 res_all.res_job.fileset = (FILESET *)res;
1174 for (i=0; joblevels[i].level_name; i++) {
1175 if (joblevels[i].job_type == item->code &&
1176 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1177 ((JOB *)(item->value))->level = joblevels[i].level;
1183 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1188 } /* end if strcmp() */
1191 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1194 lc->options = options; /* reset original options */
1195 set_bit(index, res_all.hdr.item_present);
1199 * Store restore info for Job record
1201 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1204 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1208 int options = lc->options;
1210 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1212 Dmsg0(190, "Enter store_restore()\n");
1214 ((JOB *)(item->value))->JobType = item->code;
1215 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1218 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1219 scan_err1(lc, "expected a name, got: %s", lc->str);
1221 for (i=0; RestoreFields[i].name; i++) {
1222 Dmsg1(190, "Restore kw=%s\n", lc->str);
1223 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1225 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1226 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1228 token = lex_get_token(lc, T_ALL);
1229 Dmsg1(190, "Restore value=%s\n", lc->str);
1230 switch (RestoreFields[i].token) {
1233 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1234 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1237 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1241 /* Find Client Resource */
1243 res = GetResWithName(R_CLIENT, lc->str);
1245 scan_err1(lc, "Could not find specified Client Resource: %s",
1248 res_all.res_job.client = (CLIENT *)res;
1252 /* Find FileSet Resource */
1254 res = GetResWithName(R_FILESET, lc->str);
1256 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1259 res_all.res_job.fileset = (FILESET *)res;
1264 if (token != T_NUMBER) {
1265 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1268 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1269 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1271 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1276 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1277 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1280 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1284 /* Replacement options */
1285 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1286 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1288 /* Fix to scan Replacement options */
1289 for (i=0; ReplaceOptions[i].name; i++) {
1290 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1291 ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1297 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1302 } /* end if strcmp() */
1305 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1308 lc->options = options; /* reset original options */
1309 set_bit(index, res_all.hdr.item_present);