2 * Main configuration file parser for Bacula Directors,
3 * some parts may be split into separate files such as
4 * the schedule configuration (sch_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;
53 pthread_mutex_t res_mutex = PTHREAD_MUTEX_INITIALIZER;
55 /* Imported subroutines */
56 extern void store_run(LEX *lc, struct res_items *item, int index, int pass);
57 extern void store_finc(LEX *lc, struct res_items *item, int index, int pass);
58 extern void store_inc(LEX *lc, struct res_items *item, int index, int pass);
61 /* Forward referenced subroutines */
63 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
64 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
66 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
67 static void store_replace(LEX *lc, struct res_items *item, int index, int pass);
70 /* We build the current resource here as we are
71 * scanning the resource configuration definition,
72 * then move it to allocated memory when the resource
76 int res_all_size = sizeof(res_all);
79 /* Definition of records permitted within each
80 * resource with the routine to process the record
81 * information. NOTE! quoted names must be in lower case.
86 * name handler value code flags default_value
88 static struct res_items dir_items[] = {
89 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
90 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
91 {"messages", store_res, ITEM(res_dir.messages), R_MSGS, 0, 0},
92 {"dirport", store_pint, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
93 {"diraddress", store_str, ITEM(res_dir.DIRaddr), 0, 0, 0},
94 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
95 {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
96 {"piddirectory",store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
97 {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, 0, 0},
98 {"requiressl", store_yesno, ITEM(res_dir.require_ssl), 1, ITEM_DEFAULT, 0},
99 {"enablessl", store_yesno, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
100 {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
101 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
102 {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
103 {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
104 {NULL, NULL, NULL, 0, 0, 0}
110 * name handler value code flags default_value
112 static struct res_items con_items[] = {
113 {"name", store_name, ITEM(res_con.hdr.name), 0, ITEM_REQUIRED, 0},
114 {"description", store_str, ITEM(res_con.hdr.desc), 0, 0, 0},
115 {"enablessl", store_yesno, ITEM(res_con.enable_ssl), 1, ITEM_DEFAULT, 0},
116 {"password", store_password, ITEM(res_con.password), 0, ITEM_REQUIRED, 0},
117 {NULL, NULL, NULL, 0, 0, 0}
122 * Client or File daemon resource
124 * name handler value code flags default_value
127 static struct res_items cli_items[] = {
128 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
129 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
130 {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
131 {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_DEFAULT, 9102},
132 {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
133 {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0},
134 {"fileretention", store_time, ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
135 {"jobretention", store_time, ITEM(res_client.JobRetention), 0, ITEM_DEFAULT, 60*60*24*180},
136 {"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
137 {"enablessl", store_yesno, ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
138 {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
139 {NULL, NULL, NULL, 0, 0, 0}
142 /* Storage daemon resource
144 * name handler value code flags default_value
146 static struct res_items store_items[] = {
147 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
148 {"description", store_str, ITEM(res_store.hdr.desc), 0, 0, 0},
149 {"sdport", store_pint, ITEM(res_store.SDport), 0, ITEM_DEFAULT, 9103},
150 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
151 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
152 {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
153 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
154 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
155 {"autochanger", store_yesno, ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
156 {"enablessl", store_yesno, ITEM(res_store.enable_ssl), 1, ITEM_DEFAULT, 0},
157 {"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
158 {NULL, NULL, NULL, 0, 0, 0}
162 * Catalog Resource Directives
164 * name handler value code flags default_value
166 static struct res_items cat_items[] = {
167 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
168 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
169 {"address", store_str, ITEM(res_cat.db_address), 0, 0, 0},
170 {"dbaddress", store_str, ITEM(res_cat.db_address), 0, 0, 0},
171 {"dbport", store_pint, ITEM(res_cat.db_port), 0, 0, 0},
172 /* keep this password as store_str for the moment */
173 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
174 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
175 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
176 {"dbsocket", store_str, ITEM(res_cat.db_socket), 0, 0, 0},
177 {NULL, NULL, NULL, 0, 0, 0}
181 * Job Resource Directives
183 * name handler value code flags default_value
185 static struct res_items job_items[] = {
186 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
187 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
188 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
189 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
190 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
191 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
192 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
193 {"level", store_level, ITEM(res_job), 0, 0, 0},
194 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
195 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
196 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
197 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
198 {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0},
199 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
200 {"replace", store_replace, ITEM(res_job.replace), REPLACE_ALWAYS, ITEM_DEFAULT, 0},
201 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
202 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
203 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
204 {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
205 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
206 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
207 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
208 {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0},
209 {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0},
210 {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
211 {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
212 {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
213 {NULL, NULL, NULL, 0, 0, 0}
218 * name handler value code flags default_value
220 static struct res_items fs_items[] = {
221 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
222 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
223 {"include", store_inc, NULL, 0, 0, 0},
224 {"finclude", store_finc, NULL, 0, ITEM_NO_EQUALS, 0},
225 {"exclude", store_inc, NULL, 1, 0, 0},
226 {"fexclude", store_finc, NULL, 1, ITEM_NO_EQUALS, 0},
227 {NULL, NULL, NULL, 0, 0, 0}
230 /* Schedule -- see run_conf.c */
233 * name handler value code flags default_value
235 static struct res_items sch_items[] = {
236 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
237 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
238 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
239 {NULL, NULL, NULL, 0, 0, 0}
242 /* Group resource -- not implemented
244 * name handler value code flags default_value
246 static struct res_items group_items[] = {
247 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
248 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
249 {NULL, NULL, NULL, 0, 0, 0}
254 * name handler value code flags default_value
256 static struct res_items pool_items[] = {
257 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
258 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
259 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
260 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
261 {"cleaningprefix", store_strname, ITEM(res_pool.cleaning_prefix), 0, 0, 0},
262 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
263 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
264 {"recycleoldestvolume", store_yesno, ITEM(res_pool.recycle_oldest_volume), 1, 0, 0},
265 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
266 {"maximumvolumejobs", store_pint, ITEM(res_pool.MaxVolJobs), 0, 0, 0},
267 {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles), 0, 0, 0},
268 {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes), 0, 0, 0},
269 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT, 1},
270 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
271 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
272 {"volumeuseduration", store_time, ITEM(res_pool.VolUseDuration),0, 0, 0},
273 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
274 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
275 {NULL, NULL, NULL, 0, 0, 0}
280 * name handler value code flags default_value
282 static struct res_items counter_items[] = {
283 {"name", store_name, ITEM(res_counter.hdr.name), 0, ITEM_REQUIRED, 0},
284 {"description", store_str, ITEM(res_counter.hdr.desc), 0, 0, 0},
285 {"minimum", store_int, ITEM(res_counter.MinValue), 0, ITEM_DEFAULT, 0},
286 {"maximum", store_pint, ITEM(res_counter.MaxValue), 0, ITEM_DEFAULT, INT32_MAX},
287 {"global", store_yesno, ITEM(res_counter.Global), 0, ITEM_DEFAULT, 0},
288 {"wrapcounter", store_strname, ITEM(res_counter.WrapCounter), 0, 0, 0},
289 {NULL, NULL, NULL, 0, 0, 0}
293 /* Message resource */
294 extern struct res_items msgs_items[];
297 * This is the master resource definition.
298 * It must have one item for each of the resources.
300 * name items rcode res_head
302 struct s_res resources[] = {
303 {"director", dir_items, R_DIRECTOR, NULL},
304 {"console", con_items, R_CONSOLE, NULL},
305 {"client", cli_items, R_CLIENT, NULL},
306 {"job", job_items, R_JOB, NULL},
307 {"storage", store_items, R_STORAGE, NULL},
308 {"catalog", cat_items, R_CATALOG, NULL},
309 {"schedule", sch_items, R_SCHEDULE, NULL},
310 {"fileset", fs_items, R_FILESET, NULL},
311 {"group", group_items, R_GROUP, NULL},
312 {"pool", pool_items, R_POOL, NULL},
313 {"messages", msgs_items, R_MSGS, NULL},
314 {"counter", counter_items, R_COUNTER, NULL},
315 {NULL, NULL, 0, NULL}
319 /* Keywords (RHS) permitted in Job Level records
321 * level_name level job_type
323 struct s_jl joblevels[] = {
324 {"Full", L_FULL, JT_BACKUP},
325 {"Incremental", L_INCREMENTAL, JT_BACKUP},
326 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
327 {"Since", L_SINCE, JT_BACKUP},
328 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
329 {"Initcatalog", L_VERIFY_INIT, JT_VERIFY},
330 {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG, JT_VERIFY},
331 {"Data", L_VERIFY_DATA, JT_VERIFY},
335 /* Keywords (RHS) permitted in Job type records
339 struct s_jt jobtypes[] = {
340 {"backup", JT_BACKUP},
342 {"verify", JT_VERIFY},
343 {"restore", JT_RESTORE},
348 /* Keywords (RHS) permitted in Backup and Verify records */
349 static struct s_kw BakVerFields[] = {
356 /* Keywords (RHS) permitted in Restore records */
357 static struct s_kw RestoreFields[] = {
360 {"jobid", 'J'}, /* JobId to restore */
361 {"where", 'W'}, /* root of restore */
362 {"replace", 'R'}, /* replacement options */
363 {"bootstrap", 'B'}, /* bootstrap file */
367 /* Options permitted in Restore replace= */
368 struct s_kw ReplaceOptions[] = {
369 {"always", REPLACE_ALWAYS},
370 {"ifnewer", REPLACE_IFNEWER},
371 {"ifolder", REPLACE_IFOLDER},
372 {"never", REPLACE_NEVER},
376 char *level_to_str(int level)
379 static char level_no[30];
380 char *str = level_no;
382 sprintf(level_no, "%d", level); /* default if not found */
383 for (i=0; joblevels[i].level_name; i++) {
384 if (level == joblevels[i].level) {
385 str = joblevels[i].level_name;
392 /* Dump contents of resource */
393 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
395 URES *res = (URES *)reshdr;
399 sendit(sock, "No %s resource defined\n", res_to_str(type));
402 if (type < 0) { /* no recursion */
408 char ed1[30], ed2[30];
409 sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n",
410 reshdr->name, res->res_dir.MaxConcurrentJobs,
411 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
412 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
413 if (res->res_dir.query_file) {
414 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
416 if (res->res_dir.messages) {
417 sendit(sock, " --> ");
418 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
422 sendit(sock, "Console name=%s SSL=%d\n",
423 res->res_con.hdr.name, res->res_con.enable_ssl);
426 sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
427 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
428 res->res_client.MaxConcurrentJobs);
429 sendit(sock, " JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
430 res->res_client.JobRetention, res->res_client.FileRetention,
431 res->res_client.AutoPrune);
432 if (res->res_client.catalog) {
433 sendit(sock, " --> ");
434 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
438 sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
439 DeviceName=%s MediaType=%s\n",
440 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
441 res->res_store.MaxConcurrentJobs,
442 res->res_store.dev_name, res->res_store.media_type);
445 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
447 res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
448 res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
451 sendit(sock, "Job: name=%s JobType=%d level=%s MaxJobs=%u\n",
452 res->res_job.hdr.name, res->res_job.JobType,
453 level_to_str(res->res_job.level), res->res_job.MaxConcurrentJobs);
454 if (res->res_job.client) {
455 sendit(sock, " --> ");
456 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
458 if (res->res_job.fileset) {
459 sendit(sock, " --> ");
460 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
462 if (res->res_job.schedule) {
463 sendit(sock, " --> ");
464 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
466 if (res->res_job.RestoreWhere) {
467 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
469 if (res->res_job.RestoreBootstrap) {
470 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
472 if (res->res_job.RunBeforeJob) {
473 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
475 if (res->res_job.RunAfterJob) {
476 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
478 if (res->res_job.WriteBootstrap) {
479 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
481 if (res->res_job.storage) {
482 sendit(sock, " --> ");
483 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
485 if (res->res_job.pool) {
486 sendit(sock, " --> ");
487 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
489 sendit(sock, "!!! No Pool resource\n");
491 if (res->res_job.messages) {
492 sendit(sock, " --> ");
493 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
497 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
498 for (int i=0; i<res->res_fs.num_includes; i++) {
499 INCEXE *incexe = res->res_fs.include_items[i];
500 for (int j=0; j<incexe->num_names; j++) {
501 sendit(sock, " Inc: %s\n", incexe->name_list[j]);
504 for (int i=0; i<res->res_fs.num_excludes; i++) {
505 INCEXE *incexe = res->res_fs.exclude_items[i];
506 for (int j=0; j<incexe->num_names; j++) {
507 sendit(sock, " Exc: %s\n", incexe->name_list[j]);
512 if (res->res_sch.run) {
514 RUN *run = res->res_sch.run;
515 char buf[1000], num[10];
516 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
521 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
522 strcpy(buf, " hour=");
523 for (i=0; i<24; i++) {
524 if (bit_is_set(i, run->hour)) {
525 sprintf(num, "%d ", i);
531 strcpy(buf, " mday=");
532 for (i=0; i<31; i++) {
533 if (bit_is_set(i, run->mday)) {
534 sprintf(num, "%d ", i+1);
540 strcpy(buf, " month=");
541 for (i=0; i<12; i++) {
542 if (bit_is_set(i, run->month)) {
543 sprintf(num, "%d ", i+1);
549 strcpy(buf, " wday=");
550 for (i=0; i<7; i++) {
551 if (bit_is_set(i, run->wday)) {
552 sprintf(num, "%d ", i+1);
558 strcpy(buf, " wpos=");
559 for (i=0; i<5; i++) {
560 if (bit_is_set(i, run->wpos)) {
561 sprintf(num, "%d ", i+1);
567 sendit(sock, " mins=%d\n", run->minute);
569 sendit(sock, " --> ");
570 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
573 sendit(sock, " --> ");
574 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
577 sendit(sock, " --> ");
578 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
580 /* If another Run record is chained in, go print it */
586 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
590 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
593 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
594 res->res_pool.pool_type);
595 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
596 res->res_pool.use_catalog, res->res_pool.use_volume_once,
597 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
598 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
599 res->res_pool.max_volumes, res->res_pool.AutoPrune,
600 res->res_pool.VolRetention);
601 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
602 NPRT(res->res_pool.label_format));
603 sendit(sock, " CleaningPrefix=%s\n",
604 NPRT(res->res_pool.cleaning_prefix));
605 sendit(sock, " recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
606 res->res_pool.recycle_oldest_volume,
607 res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
610 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
611 if (res->res_msgs.mail_cmd)
612 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
613 if (res->res_msgs.operator_cmd)
614 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
617 sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
620 if (recurse && res->res_dir.hdr.next) {
621 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
626 * Free all the members of an INCEXE structure
628 static void free_incexe(INCEXE *incexe)
630 for (int i=0; i<incexe->num_names; i++) {
631 free(incexe->name_list[i]);
633 if (incexe->name_list) {
634 free(incexe->name_list);
636 for (int i=0; i<incexe->num_opts; i++) {
637 FOPTS *fopt = incexe->opts_list[i];
641 for (int j=0; j<fopt->num_base; j++) {
642 free(fopt->base_list[j]);
644 if (fopt->base_list) {
645 free(fopt->base_list);
649 if (incexe->opts_list) {
650 free(incexe->opts_list);
656 * Free memory of resource.
657 * NB, we don't need to worry about freeing any references
658 * to other resources as they will be freed when that
659 * resource chain is traversed. Mainly we worry about freeing
660 * allocated strings (names).
662 void free_resource(int type)
667 int rindex = type - r_first;
669 res = (URES *)resources[rindex].res_head;
674 /* common stuff -- free the resource name and description */
675 nres = (RES *)res->res_dir.hdr.next;
676 if (res->res_dir.hdr.name) {
677 free(res->res_dir.hdr.name);
679 if (res->res_dir.hdr.desc) {
680 free(res->res_dir.hdr.desc);
685 if (res->res_dir.working_directory) {
686 free(res->res_dir.working_directory);
688 if (res->res_dir.pid_directory) {
689 free(res->res_dir.pid_directory);
691 if (res->res_dir.subsys_directory) {
692 free(res->res_dir.subsys_directory);
694 if (res->res_dir.password) {
695 free(res->res_dir.password);
697 if (res->res_dir.query_file) {
698 free(res->res_dir.query_file);
700 if (res->res_dir.DIRaddr) {
701 free(res->res_dir.DIRaddr);
705 if (res->res_con.password) {
706 free(res->res_con.password);
710 if (res->res_client.address) {
711 free(res->res_client.address);
713 if (res->res_client.password) {
714 free(res->res_client.password);
718 if (res->res_store.address) {
719 free(res->res_store.address);
721 if (res->res_store.password) {
722 free(res->res_store.password);
724 if (res->res_store.media_type) {
725 free(res->res_store.media_type);
727 if (res->res_store.dev_name) {
728 free(res->res_store.dev_name);
732 if (res->res_cat.db_address) {
733 free(res->res_cat.db_address);
735 if (res->res_cat.db_socket) {
736 free(res->res_cat.db_socket);
738 if (res->res_cat.db_user) {
739 free(res->res_cat.db_user);
741 if (res->res_cat.db_name) {
742 free(res->res_cat.db_name);
744 if (res->res_cat.db_password) {
745 free(res->res_cat.db_password);
749 if ((num=res->res_fs.num_includes)) {
751 free_incexe(res->res_fs.include_items[num]);
753 free(res->res_fs.include_items);
755 res->res_fs.num_includes = 0;
756 if ((num=res->res_fs.num_excludes)) {
758 free_incexe(res->res_fs.exclude_items[num]);
760 free(res->res_fs.exclude_items);
762 res->res_fs.num_excludes = 0;
765 if (res->res_pool.pool_type) {
766 free(res->res_pool.pool_type);
768 if (res->res_pool.label_format) {
769 free(res->res_pool.label_format);
771 if (res->res_pool.cleaning_prefix) {
772 free(res->res_pool.cleaning_prefix);
776 if (res->res_sch.run) {
778 nrun = res->res_sch.run;
787 if (res->res_job.RestoreWhere) {
788 free(res->res_job.RestoreWhere);
790 if (res->res_job.RestoreBootstrap) {
791 free(res->res_job.RestoreBootstrap);
793 if (res->res_job.WriteBootstrap) {
794 free(res->res_job.WriteBootstrap);
796 if (res->res_job.RunBeforeJob) {
797 free(res->res_job.RunBeforeJob);
799 if (res->res_job.RunAfterJob) {
800 free(res->res_job.RunAfterJob);
804 if (res->res_msgs.mail_cmd)
805 free(res->res_msgs.mail_cmd);
806 if (res->res_msgs.operator_cmd)
807 free(res->res_msgs.operator_cmd);
808 free_msgs_res((MSGS *)res); /* free message resource */
814 printf("Unknown resource type %d in free_resource.\n", type);
816 /* Common stuff again -- free the resource, recurse to next one */
820 resources[rindex].res_head = nres;
827 * Save the new resource by chaining it into the head list for
828 * the resource. If this is pass 2, we update any resource
829 * pointers because they may not have been defined until
832 void save_resource(int type, struct res_items *items, int pass)
835 int rindex = type - r_first;
840 * Ensure that all required items are present
842 for (i=0; items[i].name; i++) {
843 if (items[i].flags & ITEM_REQUIRED) {
844 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
845 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
846 items[i].name, resources[rindex]);
849 /* If this triggers, take a look at lib/parse_conf.h */
850 if (i >= MAX_RES_ITEMS) {
851 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
855 /* During pass 2 in each "store" routine, we looked up pointers
856 * to all the resources referrenced in the current resource, now we
857 * must copy their addresses from the static record to the allocated
862 /* Resources not containing a resource */
872 /* Resources containing another resource */
874 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
875 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
877 res->res_dir.messages = res_all.res_dir.messages;
880 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
881 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
883 res->res_job.messages = res_all.res_job.messages;
884 res->res_job.schedule = res_all.res_job.schedule;
885 res->res_job.client = res_all.res_job.client;
886 res->res_job.fileset = res_all.res_job.fileset;
887 res->res_job.storage = res_all.res_job.storage;
888 res->res_job.pool = res_all.res_job.pool;
889 if (res->res_job.JobType == 0) {
890 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
892 if (res->res_job.level != 0) {
894 for (i=0; joblevels[i].level_name; i++) {
895 if (joblevels[i].level == res->res_job.level &&
896 joblevels[i].job_type == res->res_job.JobType) {
902 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
903 res_all.res_dir.hdr.name);
908 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
909 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
911 res->res_client.catalog = res_all.res_client.catalog;
914 /* Schedule is a bit different in that it contains a RUN record
915 * chain which isn't a "named" resource. This chain was linked
916 * in by run_conf.c during pass 2, so here we jam the pointer
917 * into the Schedule resource.
919 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
920 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
922 res->res_sch.run = res_all.res_sch.run;
925 Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
929 /* Note, the resource name was already saved during pass 1,
930 * so here, we can just release it.
932 if (res_all.res_dir.hdr.name) {
933 free(res_all.res_dir.hdr.name);
934 res_all.res_dir.hdr.name = NULL;
936 if (res_all.res_dir.hdr.desc) {
937 free(res_all.res_dir.hdr.desc);
938 res_all.res_dir.hdr.desc = NULL;
943 /* The following code is only executed for pass 1 */
946 size = sizeof(DIRRES);
949 size = sizeof(CONRES);
952 size =sizeof(CLIENT);
955 size = sizeof(STORE);
964 size = sizeof(FILESET);
967 size = sizeof(SCHED);
970 size = sizeof(GROUP);
979 size = sizeof(COUNTER);
982 printf("Unknown resource type %d in save_resrouce.\n", type);
989 res = (URES *)malloc(size);
990 memcpy(res, &res_all, size);
991 if (!resources[rindex].res_head) {
992 resources[rindex].res_head = (RES *)res; /* store first entry */
993 Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
994 res->res_dir.hdr.name, rindex);
997 /* Add new res to end of chain */
998 for (next=resources[rindex].res_head; next->next; next=next->next)
1000 next->next = (RES *)res;
1001 Dmsg3(200, "Inserting %s res: %s index=%d\n", res_to_str(type),
1002 res->res_dir.hdr.name, rindex);
1008 * Store JobType (backup, verify, restore)
1011 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1015 token = lex_get_token(lc, T_NAME);
1016 /* Store the type both pass 1 and pass 2 */
1017 for (i=0; jobtypes[i].type_name; i++) {
1018 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1019 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1025 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1028 set_bit(index, res_all.hdr.item_present);
1032 * Store Job Level (Full, Incremental, ...)
1035 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1039 token = lex_get_token(lc, T_NAME);
1040 /* Store the level pass 2 so that type is defined */
1041 for (i=0; joblevels[i].level_name; i++) {
1042 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1043 ((JOB *)(item->value))->level = joblevels[i].level;
1049 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1052 set_bit(index, res_all.hdr.item_present);
1055 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1058 token = lex_get_token(lc, T_NAME);
1059 /* Scan Replacement options */
1060 for (i=0; ReplaceOptions[i].name; i++) {
1061 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1062 *(int *)(item->value) = ReplaceOptions[i].token;
1068 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1071 set_bit(index, res_all.hdr.item_present);
1075 * Store backup/verify info for Job record
1077 * Note, this code is used for both BACKUP and VERIFY jobs
1079 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1081 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1085 int options = lc->options;
1087 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1090 ((JOB *)(item->value))->JobType = item->code;
1091 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1094 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1096 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1097 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1099 Dmsg1(190, "Got keyword: %s\n", lc->str);
1101 for (i=0; BakVerFields[i].name; i++) {
1102 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1104 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1105 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1107 token = lex_get_token(lc, T_NAME);
1108 Dmsg1(190, "Got value: %s\n", lc->str);
1109 switch (BakVerFields[i].token) {
1111 /* Find Client Resource */
1113 res = GetResWithName(R_CLIENT, lc->str);
1115 scan_err1(lc, "Could not find specified Client Resource: %s",
1118 res_all.res_job.client = (CLIENT *)res;
1122 /* Find FileSet Resource */
1124 res = GetResWithName(R_FILESET, lc->str);
1126 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1129 res_all.res_job.fileset = (FILESET *)res;
1134 for (i=0; joblevels[i].level_name; i++) {
1135 if (joblevels[i].job_type == item->code &&
1136 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1137 ((JOB *)(item->value))->level = joblevels[i].level;
1143 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1148 } /* end if strcmp() */
1151 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1154 lc->options = options; /* reset original options */
1155 set_bit(index, res_all.hdr.item_present);
1159 * Store restore info for Job record
1161 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1164 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1168 int options = lc->options;
1170 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1172 Dmsg0(190, "Enter store_restore()\n");
1174 ((JOB *)(item->value))->JobType = item->code;
1175 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1178 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1179 scan_err1(lc, "expected a name, got: %s", lc->str);
1182 for (i=0; RestoreFields[i].name; i++) {
1183 Dmsg1(190, "Restore kw=%s\n", lc->str);
1184 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1186 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1187 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1189 token = lex_get_token(lc, T_ALL);
1190 Dmsg1(190, "Restore value=%s\n", lc->str);
1191 switch (RestoreFields[i].token) {
1194 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1195 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1198 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1202 /* Find Client Resource */
1204 res = GetResWithName(R_CLIENT, lc->str);
1206 scan_err1(lc, "Could not find specified Client Resource: %s",
1209 res_all.res_job.client = (CLIENT *)res;
1213 /* Find FileSet Resource */
1215 res = GetResWithName(R_FILESET, lc->str);
1217 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1220 res_all.res_job.fileset = (FILESET *)res;
1225 if (token != T_NUMBER) {
1226 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1229 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1230 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1232 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1237 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1238 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1241 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1245 /* Replacement options */
1246 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1247 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1249 /* Fix to scan Replacement options */
1250 for (i=0; ReplaceOptions[i].name; i++) {
1251 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1252 ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1258 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1263 } /* end if strcmp() */
1266 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1269 lc->options = options; /* reset original options */
1270 set_bit(index, res_all.hdr.item_present);