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, 2001, 2002 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);
59 /* Forward referenced subroutines */
61 static void store_inc(LEX *lc, struct res_items *item, int index, int pass);
62 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
63 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
64 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
68 /* We build the current resource here as we are
69 * scanning the resource configuration definition,
70 * then move it to allocated memory when the resource
74 int res_all_size = sizeof(res_all);
77 /* Definition of records permitted within each
78 * resource with the routine to process the record
79 * information. NOTE! quoted names must be in lower case.
84 * name handler value code flags default_value
86 static struct res_items dir_items[] = {
87 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
88 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
89 {"messages", store_res, ITEM(res_dir.messages), R_MSGS, 0, 0},
90 {"dirport", store_pint, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
91 {"diraddress", store_str, ITEM(res_dir.DIRaddr), 0, 0, 0},
92 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
93 {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
94 {"piddirectory", store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
95 {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, ITEM_REQUIRED, 0},
96 {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
97 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
98 {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
99 {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
100 {NULL, NULL, NULL, 0, 0, 0}
104 * Client or File daemon resource
106 * name handler value code flags default_value
109 static struct res_items cli_items[] = {
110 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
111 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
112 {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
113 {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_DEFAULT, 9102},
114 {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
115 {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0},
116 {"fileretention", store_time, ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
117 {"jobretention", store_time, ITEM(res_client.JobRetention), 0, ITEM_DEFAULT, 60*60*24*180},
118 {"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
119 {NULL, NULL, NULL, 0, 0, 0}
122 /* Storage daemon resource
124 * name handler value code flags default_value
126 static struct res_items store_items[] = {
127 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
128 {"description", store_str, ITEM(res_store.hdr.desc), 0, 0, 0},
129 {"sdport", store_pint, ITEM(res_store.SDport), 0, ITEM_DEFAULT, 9103},
130 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
131 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
132 {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
133 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
134 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
135 {"autochanger", store_yesno, ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
136 {NULL, NULL, NULL, 0, 0, 0}
140 * Catalog Resource Directives
142 * name handler value code flags default_value
144 static struct res_items cat_items[] = {
145 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
146 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
147 {"address", store_str, ITEM(res_cat.address), 0, 0, 0},
148 {"dbport", store_pint, ITEM(res_cat.DBport), 0, 0, 0},
149 /* keep this password as store_str for the moment */
150 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
151 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
152 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
153 {NULL, NULL, NULL, 0, 0, 0}
157 * Job Resource Directives
159 * name handler value code flags default_value
161 static struct res_items job_items[] = {
162 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
163 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
164 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
165 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
166 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
167 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
168 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
169 {"level", store_level, ITEM(res_job), 0, 0, 0},
170 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
171 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
172 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
173 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
174 {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0},
175 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
176 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
177 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
178 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
179 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
180 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
181 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
182 {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0},
183 {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0},
184 {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
185 {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
186 {NULL, NULL, NULL, 0, 0, 0}
191 * name handler value code flags default_value
193 static struct res_items fs_items[] = {
194 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
195 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
196 {"include", store_inc, NULL, 0, 0, 0},
197 {"exclude", store_inc, NULL, 1, 0, 0},
198 {NULL, NULL, NULL, 0, 0, 0}
201 /* Schedule -- see run_conf.c */
204 * name handler value code flags default_value
206 static struct res_items sch_items[] = {
207 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
208 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
209 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
210 {NULL, NULL, NULL, 0, 0, 0}
213 /* Group resource -- not implemented
215 * name handler value code flags default_value
217 static struct res_items group_items[] = {
218 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
219 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
220 {NULL, NULL, NULL, 0, 0, 0}
225 * name handler value code flags default_value
227 static struct res_items pool_items[] = {
228 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
229 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
230 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
231 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
232 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
233 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
234 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
235 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT, 1},
236 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
237 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
238 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
239 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
240 {NULL, NULL, NULL, 0, 0, 0}
245 * name handler value code flags default_value
247 static struct res_items counter_items[] = {
248 {"name", store_name, ITEM(res_counter.hdr.name), 0, ITEM_REQUIRED, 0},
249 {"description", store_str, ITEM(res_counter.hdr.desc), 0, 0, 0},
250 {"minimum", store_int, ITEM(res_counter.MinValue), 0, ITEM_DEFAULT, 0},
251 {"maximum", store_pint, ITEM(res_counter.MaxValue), 0, ITEM_DEFAULT, INT32_MAX},
252 {"global", store_yesno, ITEM(res_counter.Global), 0, ITEM_DEFAULT, 0},
253 {"wrapcounter", store_strname, ITEM(res_counter.WrapCounter), 0, 0, 0},
254 {NULL, NULL, NULL, 0, 0, 0}
258 /* Message resource */
259 extern struct res_items msgs_items[];
262 * This is the master resource definition.
263 * It must have one item for each of the resources.
265 * name items rcode res_head
267 struct s_res resources[] = {
268 {"director", dir_items, R_DIRECTOR, NULL},
269 {"client", cli_items, R_CLIENT, NULL},
270 {"job", job_items, R_JOB, NULL},
271 {"storage", store_items, R_STORAGE, NULL},
272 {"catalog", cat_items, R_CATALOG, NULL},
273 {"schedule", sch_items, R_SCHEDULE, NULL},
274 {"fileset", fs_items, R_FILESET, NULL},
275 {"group", group_items, R_GROUP, NULL},
276 {"pool", pool_items, R_POOL, NULL},
277 {"messages", msgs_items, R_MSGS, NULL},
278 {"counter", counter_items, R_COUNTER, NULL},
279 {NULL, NULL, 0, NULL}
283 /* Keywords (RHS) permitted in Job Level records
285 * level_name level job_type
287 struct s_jl joblevels[] = {
288 {"Full", L_FULL, JT_BACKUP},
289 {"Incremental", L_INCREMENTAL, JT_BACKUP},
290 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
291 {"Level", L_LEVEL, JT_BACKUP},
292 {"Since", L_SINCE, JT_BACKUP},
293 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
294 {"Initcatalog", L_VERIFY_INIT, JT_VERIFY},
295 {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG, JT_VERIFY},
296 {"Data", L_VERIFY_DATA, JT_VERIFY},
300 /* Keywords (RHS) permitted in Job type records
304 struct s_jt jobtypes[] = {
305 {"backup", JT_BACKUP},
307 {"verify", JT_VERIFY},
308 {"restore", JT_RESTORE},
313 /* Keywords (RHS) permitted in Backup and Verify records */
314 static struct s_kw BakVerFields[] = {
321 /* Keywords (RHS) permitted in Restore records */
322 static struct s_kw RestoreFields[] = {
325 {"jobid", 'J'}, /* JobId to restore */
326 {"where", 'W'}, /* root of restore */
327 {"replace", 'R'}, /* replacement options */
328 {"bootstrap", 'B'}, /* bootstrap file */
332 /* Options permitted in Restore replace= */
333 static struct s_kw ReplaceOptions[] = {
334 {"always", 'a'}, /* always */
342 /* Define FileSet KeyWord values */
344 #define INC_KW_NONE 0
345 #define INC_KW_COMPRESSION 1
346 #define INC_KW_SIGNATURE 2
347 #define INC_KW_ENCRYPTION 3
348 #define INC_KW_VERIFY 4
349 #define INC_KW_ONEFS 5
350 #define INC_KW_RECURSE 6
351 #define INC_KW_SPARSE 7
352 #define INC_KW_REPLACE 8 /* restore options */
354 /* Include keywords */
355 static struct s_kw FS_option_kw[] = {
356 {"compression", INC_KW_COMPRESSION},
357 {"signature", INC_KW_SIGNATURE},
358 {"encryption", INC_KW_ENCRYPTION},
359 {"verify", INC_KW_VERIFY},
360 {"onefs", INC_KW_ONEFS},
361 {"recurse", INC_KW_RECURSE},
362 {"sparse", INC_KW_SPARSE},
363 {"replace", INC_KW_REPLACE},
367 /* Options for FileSet keywords */
375 /* Options permitted for each keyword and resulting value */
376 static struct s_fs_opt FS_options[] = {
377 {"md5", INC_KW_SIGNATURE, "M"},
378 {"gzip", INC_KW_COMPRESSION, "Z6"},
379 {"gzip1", INC_KW_COMPRESSION, "Z1"},
380 {"gzip2", INC_KW_COMPRESSION, "Z2"},
381 {"gzip3", INC_KW_COMPRESSION, "Z3"},
382 {"gzip4", INC_KW_COMPRESSION, "Z4"},
383 {"gzip5", INC_KW_COMPRESSION, "Z5"},
384 {"gzip6", INC_KW_COMPRESSION, "Z6"},
385 {"gzip7", INC_KW_COMPRESSION, "Z7"},
386 {"gzip8", INC_KW_COMPRESSION, "Z8"},
387 {"gzip9", INC_KW_COMPRESSION, "Z9"},
388 {"blowfish", INC_KW_ENCRYPTION, "B"}, /* ***FIXME*** not implemented */
389 {"3des", INC_KW_ENCRYPTION, "3"}, /* ***FIXME*** not implemented */
390 {"yes", INC_KW_ONEFS, "0"},
391 {"no", INC_KW_ONEFS, "f"},
392 {"yes", INC_KW_RECURSE, "0"},
393 {"no", INC_KW_RECURSE, "h"},
394 {"yes", INC_KW_SPARSE, "s"},
395 {"no", INC_KW_SPARSE, "0"},
396 {"always", INC_KW_REPLACE, "a"},
397 {"ifnewer", INC_KW_REPLACE, "w"},
398 {"never", INC_KW_REPLACE, "n"},
402 char *level_to_str(int level)
405 static char level_no[30];
406 char *str = level_no;
408 sprintf(level_no, "%d", level); /* default if not found */
409 for (i=0; joblevels[i].level_name; i++) {
410 if (level == joblevels[i].level) {
411 str = joblevels[i].level_name;
420 /* Dump contents of resource */
421 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
424 URES *res = (URES *)reshdr;
428 sendit(sock, "No %s resource defined\n", res_to_str(type));
431 if (type < 0) { /* no recursion */
437 char ed1[30], ed2[30];
438 sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%s SDtimeout=%s\n",
439 reshdr->name, res->res_dir.MaxConcurrentJobs,
440 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
441 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
442 if (res->res_dir.query_file) {
443 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
445 if (res->res_dir.messages) {
446 sendit(sock, " --> ");
447 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
451 sendit(sock, "Client: name=%s address=%s FDport=%d\n",
452 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
453 sendit(sock, "JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
454 res->res_client.JobRetention, res->res_client.FileRetention,
455 res->res_client.AutoPrune);
456 if (res->res_client.catalog) {
457 sendit(sock, " --> ");
458 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
462 sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
463 DeviceName=%s MediaType=%s\n",
464 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
465 res->res_store.dev_name, res->res_store.media_type);
468 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
470 res->res_cat.hdr.name, NPRT(res->res_cat.address),
471 res->res_cat.DBport, res->res_cat.db_name, NPRT(res->res_cat.db_user));
474 sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name,
475 res->res_job.JobType, level_to_str(res->res_job.level));
476 if (res->res_job.client) {
477 sendit(sock, " --> ");
478 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
480 if (res->res_job.fileset) {
481 sendit(sock, " --> ");
482 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
484 if (res->res_job.schedule) {
485 sendit(sock, " --> ");
486 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
488 if (res->res_job.RestoreWhere) {
489 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
491 if (res->res_job.RestoreBootstrap) {
492 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
494 if (res->res_job.RunBeforeJob) {
495 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
497 if (res->res_job.RunAfterJob) {
498 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
500 if (res->res_job.WriteBootstrap) {
501 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
503 if (res->res_job.storage) {
504 sendit(sock, " --> ");
505 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
507 if (res->res_job.pool) {
508 sendit(sock, " --> ");
509 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
511 sendit(sock, "!!! No Pool resource\n");
513 if (res->res_job.messages) {
514 sendit(sock, " --> ");
515 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
519 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
520 for (i=0; i<res->res_fs.num_includes; i++)
521 sendit(sock, " Inc: %s\n", res->res_fs.include_array[i]);
522 for (i=0; i<res->res_fs.num_excludes; i++)
523 sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]);
526 if (res->res_sch.run) {
528 RUN *run = res->res_sch.run;
529 char buf[1000], num[10];
530 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
535 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
536 strcpy(buf, " hour=");
537 for (i=0; i<24; i++) {
538 if (bit_is_set(i, run->hour)) {
539 sprintf(num, "%d ", i+1);
545 strcpy(buf, " mday=");
546 for (i=0; i<31; i++) {
547 if (bit_is_set(i, run->mday)) {
548 sprintf(num, "%d ", i+1);
554 strcpy(buf, " month=");
555 for (i=0; i<12; i++) {
556 if (bit_is_set(i, run->month)) {
557 sprintf(num, "%d ", i+1);
563 strcpy(buf, " wday=");
564 for (i=0; i<7; i++) {
565 if (bit_is_set(i, run->wday)) {
566 sprintf(num, "%d ", i+1);
572 sendit(sock, " mins=%d\n", run->minute);
574 sendit(sock, " --> ");
575 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
578 sendit(sock, " --> ");
579 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
582 sendit(sock, " --> ");
583 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
585 /* If another Run record is chained in, go print it */
591 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
595 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
598 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
599 res->res_pool.pool_type);
600 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
601 res->res_pool.use_catalog, res->res_pool.use_volume_once,
602 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
603 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
604 res->res_pool.max_volumes, res->res_pool.AutoPrune,
605 res->res_pool.VolRetention);
606 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
607 NPRT(res->res_pool.label_format));
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\n", type);
620 if (recurse && res->res_dir.hdr.next) {
621 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
626 * Free memory of resource.
627 * NB, we don't need to worry about freeing any references
628 * to other resources as they will be freed when that
629 * resource chain is traversed. Mainly we worry about freeing
630 * allocated strings (names).
632 void free_resource(int type)
637 int rindex = type - r_first;
639 res = (URES *)resources[rindex].res_head;
644 /* common stuff -- free the resource name and description */
645 nres = (RES *)res->res_dir.hdr.next;
646 if (res->res_dir.hdr.name) {
647 free(res->res_dir.hdr.name);
649 if (res->res_dir.hdr.desc) {
650 free(res->res_dir.hdr.desc);
655 if (res->res_dir.working_directory) {
656 free(res->res_dir.working_directory);
658 if (res->res_dir.pid_directory) {
659 free(res->res_dir.pid_directory);
661 if (res->res_dir.subsys_directory) {
662 free(res->res_dir.subsys_directory);
664 if (res->res_dir.password) {
665 free(res->res_dir.password);
667 if (res->res_dir.query_file) {
668 free(res->res_dir.query_file);
670 if (res->res_dir.DIRaddr) {
671 free(res->res_dir.DIRaddr);
675 if (res->res_client.address) {
676 free(res->res_client.address);
678 if (res->res_client.password) {
679 free(res->res_client.password);
683 if (res->res_store.address)
684 free(res->res_store.address);
685 if (res->res_store.password)
686 free(res->res_store.password);
687 if (res->res_store.media_type)
688 free(res->res_store.media_type);
689 if (res->res_store.dev_name)
690 free(res->res_store.dev_name);
693 if (res->res_cat.address)
694 free(res->res_cat.address);
695 if (res->res_cat.db_user)
696 free(res->res_cat.db_user);
697 if (res->res_cat.db_name)
698 free(res->res_cat.db_name);
699 if (res->res_cat.db_password)
700 free(res->res_cat.db_password);
703 if ((num=res->res_fs.num_includes)) {
705 free(res->res_fs.include_array[num]);
706 free(res->res_fs.include_array);
708 if ((num=res->res_fs.num_excludes)) {
710 free(res->res_fs.exclude_array[num]);
711 free(res->res_fs.exclude_array);
715 if (res->res_pool.pool_type) {
716 free(res->res_pool.pool_type);
718 if (res->res_pool.label_format) {
719 free(res->res_pool.label_format);
723 if (res->res_sch.run) {
725 nrun = res->res_sch.run;
734 if (res->res_job.RestoreWhere) {
735 free(res->res_job.RestoreWhere);
737 if (res->res_job.RestoreBootstrap) {
738 free(res->res_job.RestoreBootstrap);
740 if (res->res_job.WriteBootstrap) {
741 free(res->res_job.WriteBootstrap);
743 if (res->res_job.RunBeforeJob) {
744 free(res->res_job.RunBeforeJob);
746 if (res->res_job.RunAfterJob) {
747 free(res->res_job.RunAfterJob);
751 if (res->res_msgs.mail_cmd)
752 free(res->res_msgs.mail_cmd);
753 if (res->res_msgs.operator_cmd)
754 free(res->res_msgs.operator_cmd);
755 free_msgs_res((MSGS *)res); /* free message resource */
761 printf("Unknown resource type %d\n", type);
763 /* Common stuff again -- free the resource, recurse to next one */
767 resources[rindex].res_head = nres;
774 * Save the new resource by chaining it into the head list for
775 * the resource. If this is pass 2, we update any resource
776 * pointers because they may not have been defined until
779 void save_resource(int type, struct res_items *items, int pass)
782 int rindex = type - r_first;
787 * Ensure that all required items are present
789 for (i=0; items[i].name; i++) {
790 if (items[i].flags & ITEM_REQUIRED) {
791 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
792 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
793 items[i].name, resources[rindex]);
796 /* If this triggers, take a look at lib/parse_conf.h */
797 if (i >= MAX_RES_ITEMS) {
798 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
802 /* During pass 2 in each "store" routine, we looked up pointers
803 * to all the resources referrenced in the current resource, now we
804 * must copy their addresses from the static record to the allocated
809 /* Resources not containing a resource */
818 /* Resources containing another resource */
820 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
821 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
823 res->res_dir.messages = res_all.res_dir.messages;
826 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
827 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
829 res->res_job.messages = res_all.res_job.messages;
830 res->res_job.schedule = res_all.res_job.schedule;
831 res->res_job.client = res_all.res_job.client;
832 res->res_job.fileset = res_all.res_job.fileset;
833 res->res_job.storage = res_all.res_job.storage;
834 res->res_job.pool = res_all.res_job.pool;
835 if (res->res_job.JobType == 0) {
836 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
838 if (res->res_job.level != 0) {
840 for (i=0; joblevels[i].level_name; i++) {
841 if (joblevels[i].level == res->res_job.level &&
842 joblevels[i].job_type == res->res_job.JobType) {
848 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
849 res_all.res_dir.hdr.name);
854 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
855 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
857 res->res_client.catalog = res_all.res_client.catalog;
860 /* Schedule is a bit different in that it contains a RUN record
861 * chain which isn't a "named" resource. This chain was linked
862 * in by run_conf.c during pass 2, so here we jam the pointer
863 * into the Schedule resource.
865 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
866 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
868 res->res_sch.run = res_all.res_sch.run;
871 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
875 /* Note, the resource name was already saved during pass 1,
876 * so here, we can just release it.
878 if (res_all.res_dir.hdr.name) {
879 free(res_all.res_dir.hdr.name);
880 res_all.res_dir.hdr.name = NULL;
882 if (res_all.res_dir.hdr.desc) {
883 free(res_all.res_dir.hdr.desc);
884 res_all.res_dir.hdr.desc = NULL;
889 /* The following code is only executed for pass 1 */
892 size = sizeof(DIRRES);
895 size =sizeof(CLIENT);
898 size = sizeof(STORE);
907 size = sizeof(FILESET);
910 size = sizeof(SCHED);
913 size = sizeof(GROUP);
922 printf("Unknown resource type %d\n", type);
929 res = (URES *)malloc(size);
930 memcpy(res, &res_all, size);
931 if (!resources[rindex].res_head) {
932 resources[rindex].res_head = (RES *)res; /* store first entry */
935 /* Add new res to end of chain */
936 for (next=resources[rindex].res_head; next->next; next=next->next)
938 next->next = (RES *)res;
939 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
940 res->res_dir.hdr.name);
946 * Store JobType (backup, verify, restore)
949 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
953 token = lex_get_token(lc, T_NAME);
954 /* Store the type both pass 1 and pass 2 */
955 for (i=0; jobtypes[i].type_name; i++) {
956 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
957 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
963 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
966 set_bit(index, res_all.hdr.item_present);
970 * Store Job Level (Full, Incremental, ...)
973 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
977 token = lex_get_token(lc, T_NAME);
978 /* Store the level pass 2 so that type is defined */
979 for (i=0; joblevels[i].level_name; i++) {
980 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
981 ((JOB *)(item->value))->level = joblevels[i].level;
987 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
990 set_bit(index, res_all.hdr.item_present);
996 * Store backup/verify info for Job record
998 * Note, this code is used for both BACKUP and VERIFY jobs
1000 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1002 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1006 int options = lc->options;
1008 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1011 ((JOB *)(item->value))->JobType = item->code;
1012 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1015 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1017 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1018 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1020 Dmsg1(190, "Got keyword: %s\n", lc->str);
1022 for (i=0; BakVerFields[i].name; i++) {
1023 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1025 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1026 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1028 token = lex_get_token(lc, T_NAME);
1029 Dmsg1(190, "Got value: %s\n", lc->str);
1030 switch (BakVerFields[i].token) {
1032 /* Find Client Resource */
1034 res = GetResWithName(R_CLIENT, lc->str);
1036 scan_err1(lc, "Could not find specified Client Resource: %s",
1039 res_all.res_job.client = (CLIENT *)res;
1043 /* Find FileSet Resource */
1045 res = GetResWithName(R_FILESET, lc->str);
1047 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1050 res_all.res_job.fileset = (FILESET *)res;
1055 for (i=0; joblevels[i].level_name; i++) {
1056 if (joblevels[i].job_type == item->code &&
1057 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1058 ((JOB *)(item->value))->level = joblevels[i].level;
1064 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1069 } /* end if strcmp() */
1072 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1075 lc->options = options; /* reset original options */
1076 set_bit(index, res_all.hdr.item_present);
1080 * Store restore info for Job record
1082 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1085 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1089 int options = lc->options;
1091 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1093 Dmsg0(190, "Enter store_restore()\n");
1095 ((JOB *)(item->value))->JobType = item->code;
1096 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1099 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1100 scan_err1(lc, "expected a name, got: %s", lc->str);
1103 for (i=0; RestoreFields[i].name; i++) {
1104 Dmsg1(190, "Restore kw=%s\n", lc->str);
1105 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1107 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1108 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1110 token = lex_get_token(lc, T_ALL);
1111 Dmsg1(190, "Restore value=%s\n", lc->str);
1112 switch (RestoreFields[i].token) {
1115 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1116 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1119 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1123 /* Find Client Resource */
1125 res = GetResWithName(R_CLIENT, lc->str);
1127 scan_err1(lc, "Could not find specified Client Resource: %s",
1130 res_all.res_job.client = (CLIENT *)res;
1134 /* Find FileSet Resource */
1136 res = GetResWithName(R_FILESET, lc->str);
1138 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1141 res_all.res_job.fileset = (FILESET *)res;
1146 if (token != T_NUMBER) {
1147 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1150 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1151 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1153 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1158 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1159 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1162 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1166 /* Replacement options */
1167 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1168 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1170 /* Fix to scan Replacement options */
1171 for (i=0; ReplaceOptions[i].name; i++) {
1172 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1173 ((JOB *)(item->value))->RestoreOptions = ReplaceOptions[i].token;
1179 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1184 } /* end if strcmp() */
1187 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1190 lc->options = options; /* reset original options */
1191 set_bit(index, res_all.hdr.item_present);
1197 * Scan for Include options (keyword=option) is converted into one or
1198 * two characters. Verifyopts=xxxx is Vxxxx:
1200 static char *scan_include_options(LEX *lc, int keyword)
1203 static char opts[100];
1206 option[0] = 0; /* default option = none */
1207 opts[0] = option[2] = 0; /* terminate options */
1209 token = lex_get_token(lc, T_NAME); /* expect at least one option */
1210 if (keyword == INC_KW_VERIFY) { /* special case */
1211 /* ***FIXME**** ensure these are in permitted set */
1212 strcpy(option, "V"); /* indicate Verify */
1213 strcat(option, lc->str);
1214 strcat(option, ":"); /* terminate it */
1216 for (i=0; FS_options[i].name; i++) {
1217 if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
1218 option[0] = FS_options[i].option[0];
1219 option[1] = FS_options[i].option[1];
1225 scan_err1(lc, "Expected a FileSet option keyword, got: %s", lc->str);
1228 strcat(opts, option);
1230 /* check if more options are specified */
1231 if (lc->ch != ',') {
1232 break; /* no, get out */
1234 token = lex_get_token(lc, T_ALL); /* yes, eat comma */
1241 /* Store FileSet Include/Exclude info */
1242 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
1245 int options = lc->options;
1251 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1253 /* Get include options */
1254 strcpy(inc_opts, "0"); /* set no options */
1255 while ((token=lex_get_token(lc, T_ALL)) != T_BOB) {
1256 keyword = INC_KW_NONE;
1257 for (i=0; FS_option_kw[i].name; i++) {
1258 if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
1259 keyword = FS_option_kw[i].token;
1263 if (keyword == INC_KW_NONE) {
1264 scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1266 /* Option keyword should be following by = <option> */
1267 if ((token=lex_get_token(lc, T_ALL)) != T_EQUALS) {
1268 scan_err1(lc, "expected an = following keyword, got: %s", lc->str);
1270 strcat(inc_opts, scan_include_options(lc, keyword));
1271 if (token == T_BOB) {
1275 strcat(inc_opts, " "); /* add field separator */
1276 inc_opts_len = strlen(inc_opts);
1280 if (!res_all.res_fs.have_MD5) {
1281 MD5Init(&res_all.res_fs.md5c);
1282 res_all.res_fs.have_MD5 = TRUE;
1284 /* Pickup include/exclude names. Note, they are stored as
1286 * where XYZ are the include/exclude options for the FileSet
1287 * a "0 " (zero) indicates no options,
1288 * and fname is the file/directory name given
1290 while ((token = lex_get_token(lc, T_ALL)) != T_EOB) {
1297 case T_UNQUOTED_STRING:
1298 case T_QUOTED_STRING:
1299 fname = (char *) malloc(lc->str_len + inc_opts_len + 1);
1300 strcpy(fname, inc_opts);
1301 strcat(fname, lc->str);
1302 if (res_all.res_fs.have_MD5) {
1303 MD5Update(&res_all.res_fs.md5c, (unsigned char *) fname, inc_opts_len + lc->str_len);
1305 if (item->code == 0) { /* include */
1306 if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
1307 res_all.res_fs.include_size += 10;
1308 if (res_all.res_fs.include_array == NULL) {
1309 res_all.res_fs.include_array = (char **) malloc(sizeof(char *) * res_all.res_fs.include_size);
1311 res_all.res_fs.include_array = (char **) realloc(res_all.res_fs.include_array,
1312 sizeof(char *) * res_all.res_fs.include_size);
1315 res_all.res_fs.include_array[res_all.res_fs.num_includes++] =
1317 } else { /* exclude */
1318 if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
1319 res_all.res_fs.exclude_size += 10;
1320 if (res_all.res_fs.exclude_array == NULL) {
1321 res_all.res_fs.exclude_array = (char **) malloc(sizeof(char *) * res_all.res_fs.exclude_size);
1323 res_all.res_fs.exclude_array = (char **) realloc(res_all.res_fs.exclude_array,
1324 sizeof(char *) * res_all.res_fs.exclude_size);
1327 res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] =
1332 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1335 } else { /* pass 2 */
1336 while (lex_get_token(lc, T_ALL) != T_EOB)
1340 lc->options = options;
1341 set_bit(index, res_all.hdr.item_present);