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 * NOTE!!! keep it in the same order as the R_codes
314 * or eliminate all resources[rindex].name
316 * name items rcode res_head
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 {"group", group_items, R_GROUP, NULL},
327 {"pool", pool_items, R_POOL, NULL},
328 {"messages", msgs_items, R_MSGS, NULL},
329 {"counter", counter_items, R_COUNTER, NULL},
330 {"console", con_items, R_CONSOLE, NULL},
331 {NULL, NULL, 0, NULL}
335 /* Keywords (RHS) permitted in Job Level records
337 * level_name level job_type
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 {"Data", L_VERIFY_DATA, JT_VERIFY},
352 /* Keywords (RHS) permitted in Job type records
356 struct s_jt jobtypes[] = {
357 {"backup", JT_BACKUP},
359 {"verify", JT_VERIFY},
360 {"restore", JT_RESTORE},
365 /* Keywords (RHS) permitted in Backup and Verify records */
366 static struct s_kw BakVerFields[] = {
373 /* Keywords (RHS) permitted in Restore records */
374 static struct s_kw RestoreFields[] = {
377 {"jobid", 'J'}, /* JobId to restore */
378 {"where", 'W'}, /* root of restore */
379 {"replace", 'R'}, /* replacement options */
380 {"bootstrap", 'B'}, /* bootstrap file */
384 /* Options permitted in Restore replace= */
385 struct s_kw ReplaceOptions[] = {
386 {"always", REPLACE_ALWAYS},
387 {"ifnewer", REPLACE_IFNEWER},
388 {"ifolder", REPLACE_IFOLDER},
389 {"never", REPLACE_NEVER},
393 char *level_to_str(int level)
396 static char level_no[30];
397 char *str = level_no;
399 sprintf(level_no, "%d", level); /* default if not found */
400 for (i=0; joblevels[i].level_name; i++) {
401 if (level == joblevels[i].level) {
402 str = joblevels[i].level_name;
409 /* Dump contents of resource */
410 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
412 URES *res = (URES *)reshdr;
414 char ed1[100], ed2[100];
417 sendit(sock, "No %s resource defined\n", res_to_str(type));
420 if (type < 0) { /* no recursion */
426 sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n",
427 reshdr->name, res->res_dir.MaxConcurrentJobs,
428 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
429 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
430 if (res->res_dir.query_file) {
431 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
433 if (res->res_dir.messages) {
434 sendit(sock, " --> ");
435 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
439 sendit(sock, "Console: name=%s SSL=%d\n",
440 res->res_con.hdr.name, res->res_con.enable_ssl);
443 if (res->res_counter.WrapCounter) {
444 sendit(sock, "Counter: name=%s min=%d max=%d cur=%d wrapcntr=%s\n",
445 res->res_counter.hdr.name, res->res_counter.MinValue,
446 res->res_counter.MaxValue, res->res_counter.CurrentValue,
447 res->res_counter.WrapCounter->hdr.name);
449 sendit(sock, "Counter: name=%s min=%d max=%d\n",
450 res->res_counter.hdr.name, res->res_counter.MinValue,
451 res->res_counter.MaxValue);
453 if (res->res_counter.Catalog) {
454 sendit(sock, " --> ");
455 dump_resource(-R_CATALOG, (RES *)res->res_counter.Catalog, sendit, sock);
460 sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
461 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
462 res->res_client.MaxConcurrentJobs);
463 sendit(sock, " JobRetention=%s FileRetention=%s AutoPrune=%d\n",
464 edit_utime(res->res_client.JobRetention, ed1),
465 edit_utime(res->res_client.FileRetention, ed2),
466 res->res_client.AutoPrune);
467 if (res->res_client.catalog) {
468 sendit(sock, " --> ");
469 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
473 sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
474 DeviceName=%s MediaType=%s\n",
475 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
476 res->res_store.MaxConcurrentJobs,
477 res->res_store.dev_name, res->res_store.media_type);
480 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
482 res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
483 res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
486 sendit(sock, "Job: name=%s JobType=%d level=%s Priority=%d MaxJobs=%u\n",
487 res->res_job.hdr.name, res->res_job.JobType,
488 level_to_str(res->res_job.level), res->res_job.Priority,
489 res->res_job.MaxConcurrentJobs);
490 sendit(sock, " Resched=%d Times=%d Interval=%s\n",
491 res->res_job.RescheduleOnError, res->res_job.RescheduleTimes,
492 edit_uint64_with_commas(res->res_job.RescheduleInterval, ed1));
493 if (res->res_job.client) {
494 sendit(sock, " --> ");
495 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
497 if (res->res_job.fileset) {
498 sendit(sock, " --> ");
499 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
501 if (res->res_job.schedule) {
502 sendit(sock, " --> ");
503 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
505 if (res->res_job.RestoreWhere) {
506 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
508 if (res->res_job.RestoreBootstrap) {
509 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
511 if (res->res_job.RunBeforeJob) {
512 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
514 if (res->res_job.RunAfterJob) {
515 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
517 if (res->res_job.WriteBootstrap) {
518 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
520 if (res->res_job.storage) {
521 sendit(sock, " --> ");
522 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
524 if (res->res_job.pool) {
525 sendit(sock, " --> ");
526 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
528 sendit(sock, "!!! No Pool resource\n");
530 if (res->res_job.messages) {
531 sendit(sock, " --> ");
532 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
536 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
537 for (int i=0; i<res->res_fs.num_includes; i++) {
538 INCEXE *incexe = res->res_fs.include_items[i];
539 for (int j=0; j<incexe->name_list.size(); j++) {
540 sendit(sock, " Inc: %s\n", incexe->name_list.get(j));
543 for (int i=0; i<res->res_fs.num_excludes; i++) {
544 INCEXE *incexe = res->res_fs.exclude_items[i];
545 for (int j=0; j<incexe->name_list.size(); j++) {
546 sendit(sock, " Exc: %s\n", incexe->name_list.get(j));
551 if (res->res_sch.run) {
553 RUN *run = res->res_sch.run;
554 char buf[1000], num[10];
555 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
560 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
561 bstrncpy(buf, " hour=", sizeof(buf));
562 for (i=0; i<24; i++) {
563 if (bit_is_set(i, run->hour)) {
564 sprintf(num, "%d ", i);
565 bstrncat(buf, num, sizeof(buf));
570 strcpy(buf, " mday=");
571 for (i=0; i<31; i++) {
572 if (bit_is_set(i, run->mday)) {
573 sprintf(num, "%d ", i+1);
579 strcpy(buf, " month=");
580 for (i=0; i<12; i++) {
581 if (bit_is_set(i, run->month)) {
582 sprintf(num, "%d ", i+1);
588 strcpy(buf, " wday=");
589 for (i=0; i<7; i++) {
590 if (bit_is_set(i, run->wday)) {
591 sprintf(num, "%d ", i+1);
597 strcpy(buf, " wpos=");
598 for (i=0; i<5; i++) {
599 if (bit_is_set(i, run->wpos)) {
600 sprintf(num, "%d ", i+1);
606 sendit(sock, " mins=%d\n", run->minute);
608 sendit(sock, " --> ");
609 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
612 sendit(sock, " --> ");
613 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
616 sendit(sock, " --> ");
617 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
619 /* If another Run record is chained in, go print it */
625 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
629 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
632 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
633 res->res_pool.pool_type);
634 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
635 res->res_pool.use_catalog, res->res_pool.use_volume_once,
636 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
637 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%s\n",
638 res->res_pool.max_volumes, res->res_pool.AutoPrune,
639 edit_utime(res->res_pool.VolRetention, ed1));
640 sendit(sock, " VolUse=%s recycle=%d LabelFormat=%s\n",
641 edit_utime(res->res_pool.VolUseDuration, ed1),
642 res->res_pool.Recycle,
643 NPRT(res->res_pool.label_format));
644 sendit(sock, " CleaningPrefix=%s\n",
645 NPRT(res->res_pool.cleaning_prefix));
646 sendit(sock, " recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
647 res->res_pool.purge_oldest_volume,
648 res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
651 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
652 if (res->res_msgs.mail_cmd)
653 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
654 if (res->res_msgs.operator_cmd)
655 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
658 sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
661 if (recurse && res->res_dir.hdr.next) {
662 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
667 * Free all the members of an INCEXE structure
669 static void free_incexe(INCEXE *incexe)
671 incexe->name_list.destroy();
672 for (int i=0; i<incexe->num_opts; i++) {
673 FOPTS *fopt = incexe->opts_list[i];
674 fopt->match.destroy();
675 fopt->base_list.destroy();
678 if (incexe->opts_list) {
679 free(incexe->opts_list);
685 * Free memory of resource.
686 * NB, we don't need to worry about freeing any references
687 * to other resources as they will be freed when that
688 * resource chain is traversed. Mainly we worry about freeing
689 * allocated strings (names).
691 void free_resource(int type)
696 int rindex = type - r_first;
698 res = (URES *)resources[rindex].res_head;
703 /* common stuff -- free the resource name and description */
704 nres = (RES *)res->res_dir.hdr.next;
705 if (res->res_dir.hdr.name) {
706 free(res->res_dir.hdr.name);
708 if (res->res_dir.hdr.desc) {
709 free(res->res_dir.hdr.desc);
714 if (res->res_dir.working_directory) {
715 free(res->res_dir.working_directory);
717 if (res->res_dir.pid_directory) {
718 free(res->res_dir.pid_directory);
720 if (res->res_dir.subsys_directory) {
721 free(res->res_dir.subsys_directory);
723 if (res->res_dir.password) {
724 free(res->res_dir.password);
726 if (res->res_dir.query_file) {
727 free(res->res_dir.query_file);
729 if (res->res_dir.DIRaddr) {
730 free(res->res_dir.DIRaddr);
736 if (res->res_con.password) {
737 free(res->res_con.password);
741 if (res->res_client.address) {
742 free(res->res_client.address);
744 if (res->res_client.password) {
745 free(res->res_client.password);
749 if (res->res_store.address) {
750 free(res->res_store.address);
752 if (res->res_store.password) {
753 free(res->res_store.password);
755 if (res->res_store.media_type) {
756 free(res->res_store.media_type);
758 if (res->res_store.dev_name) {
759 free(res->res_store.dev_name);
763 if (res->res_cat.db_address) {
764 free(res->res_cat.db_address);
766 if (res->res_cat.db_socket) {
767 free(res->res_cat.db_socket);
769 if (res->res_cat.db_user) {
770 free(res->res_cat.db_user);
772 if (res->res_cat.db_name) {
773 free(res->res_cat.db_name);
775 if (res->res_cat.db_password) {
776 free(res->res_cat.db_password);
780 if ((num=res->res_fs.num_includes)) {
782 free_incexe(res->res_fs.include_items[num]);
784 free(res->res_fs.include_items);
786 res->res_fs.num_includes = 0;
787 if ((num=res->res_fs.num_excludes)) {
789 free_incexe(res->res_fs.exclude_items[num]);
791 free(res->res_fs.exclude_items);
793 res->res_fs.num_excludes = 0;
796 if (res->res_pool.pool_type) {
797 free(res->res_pool.pool_type);
799 if (res->res_pool.label_format) {
800 free(res->res_pool.label_format);
802 if (res->res_pool.cleaning_prefix) {
803 free(res->res_pool.cleaning_prefix);
807 if (res->res_sch.run) {
809 nrun = res->res_sch.run;
818 if (res->res_job.RestoreWhere) {
819 free(res->res_job.RestoreWhere);
821 if (res->res_job.RestoreBootstrap) {
822 free(res->res_job.RestoreBootstrap);
824 if (res->res_job.WriteBootstrap) {
825 free(res->res_job.WriteBootstrap);
827 if (res->res_job.RunBeforeJob) {
828 free(res->res_job.RunBeforeJob);
830 if (res->res_job.RunAfterJob) {
831 free(res->res_job.RunAfterJob);
833 if (res->res_job.ClientRunBeforeJob) {
834 free(res->res_job.ClientRunBeforeJob);
836 if (res->res_job.ClientRunAfterJob) {
837 free(res->res_job.ClientRunAfterJob);
841 if (res->res_msgs.mail_cmd) {
842 free(res->res_msgs.mail_cmd);
844 if (res->res_msgs.operator_cmd) {
845 free(res->res_msgs.operator_cmd);
847 free_msgs_res((MSGS *)res); /* free message resource */
853 printf("Unknown resource type %d in free_resource.\n", type);
855 /* Common stuff again -- free the resource, recurse to next one */
859 resources[rindex].res_head = nres;
866 * Save the new resource by chaining it into the head list for
867 * the resource. If this is pass 2, we update any resource
868 * pointers because they may not have been defined until
871 void save_resource(int type, struct res_items *items, int pass)
874 int rindex = type - r_first;
879 * Ensure that all required items are present
881 for (i=0; items[i].name; i++) {
882 if (items[i].flags & ITEM_REQUIRED) {
883 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
884 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
885 items[i].name, resources[rindex]);
888 /* If this triggers, take a look at lib/parse_conf.h */
889 if (i >= MAX_RES_ITEMS) {
890 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
894 /* During pass 2 in each "store" routine, we looked up pointers
895 * to all the resources referrenced in the current resource, now we
896 * must copy their addresses from the static record to the allocated
901 /* Resources not containing a resource */
911 /* Resources containing another resource */
913 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
914 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
916 res->res_dir.messages = res_all.res_dir.messages;
919 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
920 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
922 res->res_job.messages = res_all.res_job.messages;
923 res->res_job.schedule = res_all.res_job.schedule;
924 res->res_job.client = res_all.res_job.client;
925 res->res_job.fileset = res_all.res_job.fileset;
926 res->res_job.storage = res_all.res_job.storage;
927 res->res_job.pool = res_all.res_job.pool;
928 if (res->res_job.JobType == 0) {
929 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
931 if (res->res_job.level != 0) {
933 for (i=0; joblevels[i].level_name; i++) {
934 if (joblevels[i].level == res->res_job.level &&
935 joblevels[i].job_type == res->res_job.JobType) {
941 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
942 res_all.res_dir.hdr.name);
947 if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
948 Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
950 res->res_counter.Catalog = res_all.res_counter.Catalog;
951 res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
955 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
956 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
958 res->res_client.catalog = res_all.res_client.catalog;
961 /* Schedule is a bit different in that it contains a RUN record
962 * chain which isn't a "named" resource. This chain was linked
963 * in by run_conf.c during pass 2, so here we jam the pointer
964 * into the Schedule resource.
966 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
967 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
969 res->res_sch.run = res_all.res_sch.run;
972 Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
976 /* Note, the resource name was already saved during pass 1,
977 * so here, we can just release it.
979 if (res_all.res_dir.hdr.name) {
980 free(res_all.res_dir.hdr.name);
981 res_all.res_dir.hdr.name = NULL;
983 if (res_all.res_dir.hdr.desc) {
984 free(res_all.res_dir.hdr.desc);
985 res_all.res_dir.hdr.desc = NULL;
991 * The following code is only executed during pass 1
995 size = sizeof(DIRRES);
998 size = sizeof(CONRES);
1001 size =sizeof(CLIENT);
1004 size = sizeof(STORE);
1013 size = sizeof(FILESET);
1016 size = sizeof(SCHED);
1019 size = sizeof(GROUP);
1022 size = sizeof(POOL);
1025 size = sizeof(MSGS);
1028 size = sizeof(COUNTER);
1031 printf("Unknown resource type %d in save_resrouce.\n", type);
1038 res = (URES *)malloc(size);
1039 memcpy(res, &res_all, size);
1040 if (!resources[rindex].res_head) {
1041 resources[rindex].res_head = (RES *)res; /* store first entry */
1042 Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1043 res->res_dir.hdr.name, rindex);
1046 /* Add new res to end of chain */
1047 for (next=resources[rindex].res_head; next->next; next=next->next) {
1048 if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
1049 Emsg2(M_ERROR_TERM, 0,
1050 _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
1051 resources[rindex].name, res->res_dir.hdr.name);
1054 next->next = (RES *)res;
1055 Dmsg4(200, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type),
1056 res->res_dir.hdr.name, rindex, pass);
1062 * Store JobType (backup, verify, restore)
1065 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1069 token = lex_get_token(lc, T_NAME);
1070 /* Store the type both pass 1 and pass 2 */
1071 for (i=0; jobtypes[i].type_name; i++) {
1072 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1073 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1079 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1082 set_bit(index, res_all.hdr.item_present);
1086 * Store Job Level (Full, Incremental, ...)
1089 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1093 token = lex_get_token(lc, T_NAME);
1094 /* Store the level pass 2 so that type is defined */
1095 for (i=0; joblevels[i].level_name; i++) {
1096 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1097 ((JOB *)(item->value))->level = joblevels[i].level;
1103 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1106 set_bit(index, res_all.hdr.item_present);
1109 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1112 token = lex_get_token(lc, T_NAME);
1113 /* Scan Replacement options */
1114 for (i=0; ReplaceOptions[i].name; i++) {
1115 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1116 *(int *)(item->value) = ReplaceOptions[i].token;
1122 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1125 set_bit(index, res_all.hdr.item_present);
1129 * Store backup/verify info for Job record
1131 * Note, this code is used for both BACKUP and VERIFY jobs
1133 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1135 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1139 int options = lc->options;
1141 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1144 ((JOB *)(item->value))->JobType = item->code;
1145 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1148 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1150 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1151 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1153 Dmsg1(190, "Got keyword: %s\n", lc->str);
1154 for (i=0; BakVerFields[i].name; i++) {
1155 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1157 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1158 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1160 token = lex_get_token(lc, T_NAME);
1161 Dmsg1(190, "Got value: %s\n", lc->str);
1162 switch (BakVerFields[i].token) {
1164 /* Find Client Resource */
1166 res = GetResWithName(R_CLIENT, lc->str);
1168 scan_err1(lc, "Could not find specified Client Resource: %s",
1171 res_all.res_job.client = (CLIENT *)res;
1175 /* Find FileSet Resource */
1177 res = GetResWithName(R_FILESET, lc->str);
1179 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1182 res_all.res_job.fileset = (FILESET *)res;
1187 for (i=0; joblevels[i].level_name; i++) {
1188 if (joblevels[i].job_type == item->code &&
1189 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1190 ((JOB *)(item->value))->level = joblevels[i].level;
1196 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1201 } /* end if strcmp() */
1204 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1207 lc->options = options; /* reset original options */
1208 set_bit(index, res_all.hdr.item_present);
1212 * Store restore info for Job record
1214 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1217 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1221 int options = lc->options;
1223 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1225 Dmsg0(190, "Enter store_restore()\n");
1227 ((JOB *)(item->value))->JobType = item->code;
1228 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1231 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1232 scan_err1(lc, "expected a name, got: %s", lc->str);
1234 for (i=0; RestoreFields[i].name; i++) {
1235 Dmsg1(190, "Restore kw=%s\n", lc->str);
1236 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1238 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1239 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1241 token = lex_get_token(lc, T_ALL);
1242 Dmsg1(190, "Restore value=%s\n", lc->str);
1243 switch (RestoreFields[i].token) {
1246 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1247 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1250 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1254 /* Find Client Resource */
1256 res = GetResWithName(R_CLIENT, lc->str);
1258 scan_err1(lc, "Could not find specified Client Resource: %s",
1261 res_all.res_job.client = (CLIENT *)res;
1265 /* Find FileSet Resource */
1267 res = GetResWithName(R_FILESET, lc->str);
1269 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1272 res_all.res_job.fileset = (FILESET *)res;
1277 if (token != T_NUMBER) {
1278 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1281 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1282 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1284 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1289 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1290 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1293 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1297 /* Replacement options */
1298 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1299 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1301 /* Fix to scan Replacement options */
1302 for (i=0; ReplaceOptions[i].name; i++) {
1303 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1304 ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1310 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1315 } /* end if strcmp() */
1318 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1321 lc->options = options; /* reset original options */
1322 set_bit(index, res_all.hdr.item_present);