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 */
345 #define FS_KW_COMPRESSION 1
346 #define FS_KW_SIGNATURE 2
347 #define FS_KW_ENCRYPTION 3
348 #define FS_KW_VERIFY 4
349 #define FS_KW_ONEFS 5
350 #define FS_KW_RECURSE 6
351 #define FS_KW_SPARSE 7
353 /* FileSet keywords */
354 static struct s_kw FS_option_kw[] = {
355 {"compression", FS_KW_COMPRESSION},
356 {"signature", FS_KW_SIGNATURE},
357 {"encryption", FS_KW_ENCRYPTION},
358 {"verify", FS_KW_VERIFY},
359 {"onefs", FS_KW_ONEFS},
360 {"recurse", FS_KW_RECURSE},
361 {"sparse", FS_KW_SPARSE},
365 /* Options for FileSet keywords */
373 /* Options permitted for each keyword and resulting value */
374 static struct s_fs_opt FS_options[] = {
375 {"md5", FS_KW_SIGNATURE, "M"},
376 {"gzip", FS_KW_COMPRESSION, "Z6"},
377 {"gzip1", FS_KW_COMPRESSION, "Z1"},
378 {"gzip2", FS_KW_COMPRESSION, "Z2"},
379 {"gzip3", FS_KW_COMPRESSION, "Z3"},
380 {"gzip4", FS_KW_COMPRESSION, "Z4"},
381 {"gzip5", FS_KW_COMPRESSION, "Z5"},
382 {"gzip6", FS_KW_COMPRESSION, "Z6"},
383 {"gzip7", FS_KW_COMPRESSION, "Z7"},
384 {"gzip8", FS_KW_COMPRESSION, "Z8"},
385 {"gzip9", FS_KW_COMPRESSION, "Z9"},
386 {"blowfish", FS_KW_ENCRYPTION, "B"}, /* ***FIXME*** not implemented */
387 {"3des", FS_KW_ENCRYPTION, "3"}, /* ***FIXME*** not implemented */
388 {"yes", FS_KW_ONEFS, "0"},
389 {"no", FS_KW_ONEFS, "f"},
390 {"yes", FS_KW_RECURSE, "0"},
391 {"no", FS_KW_RECURSE, "h"},
392 {"yes", FS_KW_SPARSE, "s"},
393 {"no", FS_KW_SPARSE, "0"},
397 char *level_to_str(int level)
400 static char level_no[30];
401 char *str = level_no;
403 sprintf(level_no, "%d", level); /* default if not found */
404 for (i=0; joblevels[i].level_name; i++) {
405 if (level == joblevels[i].level) {
406 str = joblevels[i].level_name;
415 /* Dump contents of resource */
416 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
419 URES *res = (URES *)reshdr;
423 sendit(sock, "No %s resource defined\n", res_to_str(type));
426 if (type < 0) { /* no recursion */
432 char ed1[30], ed2[30];
433 sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%s SDtimeout=%s\n",
434 reshdr->name, res->res_dir.MaxConcurrentJobs,
435 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
436 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
437 if (res->res_dir.query_file) {
438 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
440 if (res->res_dir.messages) {
441 sendit(sock, " --> ");
442 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
446 sendit(sock, "Client: name=%s address=%s FDport=%d\n",
447 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
448 sendit(sock, "JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
449 res->res_client.JobRetention, res->res_client.FileRetention,
450 res->res_client.AutoPrune);
451 if (res->res_client.catalog) {
452 sendit(sock, " --> ");
453 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
457 sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
458 DeviceName=%s MediaType=%s\n",
459 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
460 res->res_store.dev_name, res->res_store.media_type);
463 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
465 res->res_cat.hdr.name, NPRT(res->res_cat.address),
466 res->res_cat.DBport, res->res_cat.db_name, NPRT(res->res_cat.db_user));
469 sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name,
470 res->res_job.JobType, level_to_str(res->res_job.level));
471 if (res->res_job.client) {
472 sendit(sock, " --> ");
473 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
475 if (res->res_job.fileset) {
476 sendit(sock, " --> ");
477 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
479 if (res->res_job.schedule) {
480 sendit(sock, " --> ");
481 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
483 if (res->res_job.RestoreWhere) {
484 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
486 if (res->res_job.RestoreBootstrap) {
487 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
489 if (res->res_job.RunBeforeJob) {
490 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
492 if (res->res_job.RunAfterJob) {
493 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
495 if (res->res_job.WriteBootstrap) {
496 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
498 if (res->res_job.storage) {
499 sendit(sock, " --> ");
500 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
502 if (res->res_job.pool) {
503 sendit(sock, " --> ");
504 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
506 sendit(sock, "!!! No Pool resource\n");
508 if (res->res_job.messages) {
509 sendit(sock, " --> ");
510 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
514 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
515 for (i=0; i<res->res_fs.num_includes; i++)
516 sendit(sock, " Inc: %s\n", res->res_fs.include_array[i]);
517 for (i=0; i<res->res_fs.num_excludes; i++)
518 sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]);
521 if (res->res_sch.run) {
523 RUN *run = res->res_sch.run;
524 char buf[1000], num[10];
525 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
530 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
531 strcpy(buf, " hour=");
532 for (i=0; i<24; i++) {
533 if (bit_is_set(i, run->hour)) {
534 sprintf(num, "%d ", i+1);
540 strcpy(buf, " mday=");
541 for (i=0; i<31; i++) {
542 if (bit_is_set(i, run->mday)) {
543 sprintf(num, "%d ", i+1);
549 strcpy(buf, " month=");
550 for (i=0; i<12; i++) {
551 if (bit_is_set(i, run->month)) {
552 sprintf(num, "%d ", i+1);
558 strcpy(buf, " wday=");
559 for (i=0; i<7; i++) {
560 if (bit_is_set(i, run->wday)) {
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));
605 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
606 if (res->res_msgs.mail_cmd)
607 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
608 if (res->res_msgs.operator_cmd)
609 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
612 sendit(sock, "Unknown resource type %d\n", type);
615 if (recurse && res->res_dir.hdr.next) {
616 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
621 * Free memory of resource.
622 * NB, we don't need to worry about freeing any references
623 * to other resources as they will be freed when that
624 * resource chain is traversed. Mainly we worry about freeing
625 * allocated strings (names).
627 void free_resource(int type)
632 int rindex = type - r_first;
634 res = (URES *)resources[rindex].res_head;
639 /* common stuff -- free the resource name and description */
640 nres = (RES *)res->res_dir.hdr.next;
641 if (res->res_dir.hdr.name) {
642 free(res->res_dir.hdr.name);
644 if (res->res_dir.hdr.desc) {
645 free(res->res_dir.hdr.desc);
650 if (res->res_dir.working_directory) {
651 free(res->res_dir.working_directory);
653 if (res->res_dir.pid_directory) {
654 free(res->res_dir.pid_directory);
656 if (res->res_dir.subsys_directory) {
657 free(res->res_dir.subsys_directory);
659 if (res->res_dir.password) {
660 free(res->res_dir.password);
662 if (res->res_dir.query_file) {
663 free(res->res_dir.query_file);
665 if (res->res_dir.DIRaddr) {
666 free(res->res_dir.DIRaddr);
670 if (res->res_client.address) {
671 free(res->res_client.address);
673 if (res->res_client.password) {
674 free(res->res_client.password);
678 if (res->res_store.address)
679 free(res->res_store.address);
680 if (res->res_store.password)
681 free(res->res_store.password);
682 if (res->res_store.media_type)
683 free(res->res_store.media_type);
684 if (res->res_store.dev_name)
685 free(res->res_store.dev_name);
688 if (res->res_cat.address)
689 free(res->res_cat.address);
690 if (res->res_cat.db_user)
691 free(res->res_cat.db_user);
692 if (res->res_cat.db_name)
693 free(res->res_cat.db_name);
694 if (res->res_cat.db_password)
695 free(res->res_cat.db_password);
698 if ((num=res->res_fs.num_includes)) {
700 free(res->res_fs.include_array[num]);
701 free(res->res_fs.include_array);
703 if ((num=res->res_fs.num_excludes)) {
705 free(res->res_fs.exclude_array[num]);
706 free(res->res_fs.exclude_array);
710 if (res->res_pool.pool_type) {
711 free(res->res_pool.pool_type);
713 if (res->res_pool.label_format) {
714 free(res->res_pool.label_format);
718 if (res->res_sch.run) {
720 nrun = res->res_sch.run;
729 if (res->res_job.RestoreWhere) {
730 free(res->res_job.RestoreWhere);
732 if (res->res_job.RestoreBootstrap) {
733 free(res->res_job.RestoreBootstrap);
735 if (res->res_job.WriteBootstrap) {
736 free(res->res_job.WriteBootstrap);
738 if (res->res_job.RunBeforeJob) {
739 free(res->res_job.RunBeforeJob);
741 if (res->res_job.RunAfterJob) {
742 free(res->res_job.RunAfterJob);
746 if (res->res_msgs.mail_cmd)
747 free(res->res_msgs.mail_cmd);
748 if (res->res_msgs.operator_cmd)
749 free(res->res_msgs.operator_cmd);
750 free_msgs_res((MSGS *)res); /* free message resource */
756 printf("Unknown resource type %d\n", type);
758 /* Common stuff again -- free the resource, recurse to next one */
762 resources[rindex].res_head = nres;
769 * Save the new resource by chaining it into the head list for
770 * the resource. If this is pass 2, we update any resource
771 * pointers because they may not have been defined until
774 void save_resource(int type, struct res_items *items, int pass)
777 int rindex = type - r_first;
782 * Ensure that all required items are present
784 for (i=0; items[i].name; i++) {
785 if (items[i].flags & ITEM_REQUIRED) {
786 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
787 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
788 items[i].name, resources[rindex]);
791 /* If this triggers, take a look at lib/parse_conf.h */
792 if (i >= MAX_RES_ITEMS) {
793 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
797 /* During pass 2 in each "store" routine, we looked up pointers
798 * to all the resources referrenced in the current resource, now we
799 * must copy their addresses from the static record to the allocated
804 /* Resources not containing a resource */
813 /* Resources containing another resource */
815 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
816 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
818 res->res_dir.messages = res_all.res_dir.messages;
821 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
822 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
824 res->res_job.messages = res_all.res_job.messages;
825 res->res_job.schedule = res_all.res_job.schedule;
826 res->res_job.client = res_all.res_job.client;
827 res->res_job.fileset = res_all.res_job.fileset;
828 res->res_job.storage = res_all.res_job.storage;
829 res->res_job.pool = res_all.res_job.pool;
830 if (res->res_job.JobType == 0) {
831 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
833 if (res->res_job.level != 0) {
835 for (i=0; joblevels[i].level_name; i++) {
836 if (joblevels[i].level == res->res_job.level &&
837 joblevels[i].job_type == res->res_job.JobType) {
843 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
844 res_all.res_dir.hdr.name);
849 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
850 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
852 res->res_client.catalog = res_all.res_client.catalog;
855 /* Schedule is a bit different in that it contains a RUN record
856 * chain which isn't a "named" resource. This chain was linked
857 * in by run_conf.c during pass 2, so here we jam the pointer
858 * into the Schedule resource.
860 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
861 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
863 res->res_sch.run = res_all.res_sch.run;
866 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
870 /* Note, the resource name was already saved during pass 1,
871 * so here, we can just release it.
873 if (res_all.res_dir.hdr.name) {
874 free(res_all.res_dir.hdr.name);
875 res_all.res_dir.hdr.name = NULL;
877 if (res_all.res_dir.hdr.desc) {
878 free(res_all.res_dir.hdr.desc);
879 res_all.res_dir.hdr.desc = NULL;
884 /* The following code is only executed for pass 1 */
887 size = sizeof(DIRRES);
890 size =sizeof(CLIENT);
893 size = sizeof(STORE);
902 size = sizeof(FILESET);
905 size = sizeof(SCHED);
908 size = sizeof(GROUP);
917 printf("Unknown resource type %d\n", type);
924 res = (URES *)malloc(size);
925 memcpy(res, &res_all, size);
926 if (!resources[rindex].res_head) {
927 resources[rindex].res_head = (RES *)res; /* store first entry */
930 /* Add new res to end of chain */
931 for (next=resources[rindex].res_head; next->next; next=next->next)
933 next->next = (RES *)res;
934 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
935 res->res_dir.hdr.name);
941 * Store JobType (backup, verify, restore)
944 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
948 token = lex_get_token(lc, T_NAME);
949 /* Store the type both pass 1 and pass 2 */
950 for (i=0; jobtypes[i].type_name; i++) {
951 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
952 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
958 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
961 set_bit(index, res_all.hdr.item_present);
965 * Store Job Level (Full, Incremental, ...)
968 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
972 token = lex_get_token(lc, T_NAME);
973 /* Store the level pass 2 so that type is defined */
974 for (i=0; joblevels[i].level_name; i++) {
975 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
976 ((JOB *)(item->value))->level = joblevels[i].level;
982 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
985 set_bit(index, res_all.hdr.item_present);
991 * Store backup/verify info for Job record
993 * Note, this code is used for both BACKUP and VERIFY jobs
995 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
997 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1001 int options = lc->options;
1003 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1006 ((JOB *)(item->value))->JobType = item->code;
1007 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1010 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1012 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1013 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1015 Dmsg1(190, "Got keyword: %s\n", lc->str);
1017 for (i=0; BakVerFields[i].name; i++) {
1018 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1020 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1021 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1023 token = lex_get_token(lc, T_NAME);
1024 Dmsg1(190, "Got value: %s\n", lc->str);
1025 switch (BakVerFields[i].token) {
1027 /* Find Client Resource */
1029 res = GetResWithName(R_CLIENT, lc->str);
1031 scan_err1(lc, "Could not find specified Client Resource: %s",
1034 res_all.res_job.client = (CLIENT *)res;
1038 /* Find FileSet Resource */
1040 res = GetResWithName(R_FILESET, lc->str);
1042 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1045 res_all.res_job.fileset = (FILESET *)res;
1050 for (i=0; joblevels[i].level_name; i++) {
1051 if (joblevels[i].job_type == item->code &&
1052 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1053 ((JOB *)(item->value))->level = joblevels[i].level;
1059 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1064 } /* end if strcmp() */
1067 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1070 lc->options = options; /* reset original options */
1071 set_bit(index, res_all.hdr.item_present);
1075 * Store restore info for Job record
1077 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1080 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1084 int options = lc->options;
1086 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1088 Dmsg0(190, "Enter store_restore()\n");
1090 ((JOB *)(item->value))->JobType = item->code;
1091 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1094 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1095 scan_err1(lc, "expected a name, got: %s", lc->str);
1098 for (i=0; RestoreFields[i].name; i++) {
1099 Dmsg1(190, "Restore kw=%s\n", lc->str);
1100 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1102 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1103 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1105 token = lex_get_token(lc, T_ALL);
1106 Dmsg1(190, "Restore value=%s\n", lc->str);
1107 switch (RestoreFields[i].token) {
1110 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1111 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1114 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1118 /* Find Client Resource */
1120 res = GetResWithName(R_CLIENT, lc->str);
1122 scan_err1(lc, "Could not find specified Client Resource: %s",
1125 res_all.res_job.client = (CLIENT *)res;
1129 /* Find FileSet Resource */
1131 res = GetResWithName(R_FILESET, lc->str);
1133 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1136 res_all.res_job.fileset = (FILESET *)res;
1141 if (token != T_NUMBER) {
1142 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1145 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1146 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1148 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1153 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1154 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1157 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1161 /* Replacement options */
1162 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1163 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1165 /* Fix to scan Replacement options */
1166 for (i=0; ReplaceOptions[i].name; i++) {
1167 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1168 ((JOB *)(item->value))->RestoreOptions = ReplaceOptions[i].token;
1174 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1179 } /* end if strcmp() */
1182 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1185 lc->options = options; /* reset original options */
1186 set_bit(index, res_all.hdr.item_present);
1192 * Scan for FileSet options (keyword=option) is converted into one or
1193 * two characters. Verifyopts=xxxx is Vxxxx:
1195 static char *scan_fs_options(LEX *lc, int keyword)
1198 static char opts[100];
1201 option[0] = 0; /* default option = none */
1202 opts[0] = option[2] = 0; /* terminate options */
1204 token = lex_get_token(lc, T_NAME); /* expect at least one option */
1205 if (keyword == FS_KW_VERIFY) { /* special case */
1206 /* ***FIXME**** ensure these are in permitted set */
1207 strcpy(option, "V"); /* indicate Verify */
1208 strcat(option, lc->str);
1209 strcat(option, ":"); /* terminate it */
1211 for (i=0; FS_options[i].name; i++) {
1212 if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
1213 option[0] = FS_options[i].option[0];
1214 option[1] = FS_options[i].option[1];
1220 scan_err1(lc, "Expected a FileSet option keyword, got: %s", lc->str);
1223 strcat(opts, option);
1225 /* check if more options are specified */
1226 if (lc->ch != ',') {
1227 break; /* no, get out */
1229 token = lex_get_token(lc, T_ALL); /* yes, eat comma */
1236 /* Store FileSet Include/Exclude info */
1237 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
1240 int options = lc->options;
1246 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1248 /* Get include options */
1249 strcpy(inc_opts, "0"); /* set no options */
1250 while ((token=lex_get_token(lc, T_ALL)) != T_BOB) {
1251 keyword = FS_KW_NONE;
1252 for (i=0; FS_option_kw[i].name; i++) {
1253 if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
1254 keyword = FS_option_kw[i].token;
1258 if (keyword == FS_KW_NONE) {
1259 scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1261 /* Option keyword should be following by = <option> */
1262 if ((token=lex_get_token(lc, T_ALL)) != T_EQUALS) {
1263 scan_err1(lc, "expected an = following keyword, got: %s", lc->str);
1265 strcat(inc_opts, scan_fs_options(lc, keyword));
1266 if (token == T_BOB) {
1270 strcat(inc_opts, " "); /* add field separator */
1271 inc_opts_len = strlen(inc_opts);
1275 if (!res_all.res_fs.have_MD5) {
1276 MD5Init(&res_all.res_fs.md5c);
1277 res_all.res_fs.have_MD5 = TRUE;
1279 /* Pickup include/exclude names. Note, they are stored as
1281 * where XYZ are the include/exclude options for the FileSet
1282 * a "0 " (zero) indicates no options,
1283 * and fname is the file/directory name given
1285 while ((token = lex_get_token(lc, T_ALL)) != T_EOB) {
1292 case T_UNQUOTED_STRING:
1293 case T_QUOTED_STRING:
1294 fname = (char *) malloc(lc->str_len + inc_opts_len + 1);
1295 strcpy(fname, inc_opts);
1296 strcat(fname, lc->str);
1297 if (res_all.res_fs.have_MD5) {
1298 MD5Update(&res_all.res_fs.md5c, (unsigned char *) fname, inc_opts_len + lc->str_len);
1300 if (item->code == 0) { /* include */
1301 if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
1302 res_all.res_fs.include_size += 10;
1303 if (res_all.res_fs.include_array == NULL) {
1304 res_all.res_fs.include_array = (char **) malloc(sizeof(char *) * res_all.res_fs.include_size);
1306 res_all.res_fs.include_array = (char **) realloc(res_all.res_fs.include_array,
1307 sizeof(char *) * res_all.res_fs.include_size);
1310 res_all.res_fs.include_array[res_all.res_fs.num_includes++] =
1312 } else { /* exclude */
1313 if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
1314 res_all.res_fs.exclude_size += 10;
1315 if (res_all.res_fs.exclude_array == NULL) {
1316 res_all.res_fs.exclude_array = (char **) malloc(sizeof(char *) * res_all.res_fs.exclude_size);
1318 res_all.res_fs.exclude_array = (char **) realloc(res_all.res_fs.exclude_array,
1319 sizeof(char *) * res_all.res_fs.exclude_size);
1322 res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] =
1327 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1330 } else { /* pass 2 */
1331 while (lex_get_token(lc, T_ALL) != T_EOB)
1335 lc->options = options;
1336 set_bit(index, res_all.hdr.item_present);