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 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
92 {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
93 {"piddirectory", store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
94 {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, ITEM_REQUIRED, 0},
95 {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
96 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
97 {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
98 {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
99 {NULL, NULL, NULL, 0, 0, 0}
103 * Client or File daemon resource
105 * name handler value code flags default_value
108 static struct res_items cli_items[] = {
109 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
110 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
111 {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
112 {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_DEFAULT, 9102},
113 {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
114 {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0},
115 {"fileretention", store_time, ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
116 {"jobretention", store_time, ITEM(res_client.JobRetention), 0, ITEM_DEFAULT, 60*60*24*180},
117 {"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
118 {NULL, NULL, NULL, 0, 0, 0}
121 /* Storage daemon resource
123 * name handler value code flags default_value
125 static struct res_items store_items[] = {
126 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
127 {"description", store_str, ITEM(res_store.hdr.desc), 0, 0, 0},
128 {"sdport", store_pint, ITEM(res_store.SDport), 0, ITEM_DEFAULT, 9103},
129 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
130 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
131 {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
132 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
133 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
134 {"autochanger", store_yesno, ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
135 {NULL, NULL, NULL, 0, 0, 0}
139 * Catalog Resource Directives
141 * name handler value code flags default_value
143 static struct res_items cat_items[] = {
144 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
145 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
146 {"address", store_str, ITEM(res_cat.address), 0, 0, 0},
147 {"dbport", store_pint, ITEM(res_cat.DBport), 0, 0, 0},
148 /* keep this password as store_str for the moment */
149 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
150 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
151 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
152 {NULL, NULL, NULL, 0, 0, 0}
156 * Job Resource Directives
158 * name handler value code flags default_value
160 static struct res_items job_items[] = {
161 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
162 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
163 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
164 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
165 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
166 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
167 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
168 {"level", store_level, ITEM(res_job), 0, 0, 0},
169 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
170 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
171 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
172 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
173 {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0},
174 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
175 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
176 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
177 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
178 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
179 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
180 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
181 {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0},
182 {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0},
183 {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
184 {NULL, NULL, NULL, 0, 0, 0}
189 * name handler value code flags default_value
191 static struct res_items fs_items[] = {
192 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
193 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
194 {"include", store_inc, NULL, 0, 0, 0},
195 {"exclude", store_inc, NULL, 1, 0, 0},
196 {NULL, NULL, NULL, 0, 0, 0}
199 /* Schedule -- see run_conf.c */
202 * name handler value code flags default_value
204 static struct res_items sch_items[] = {
205 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
206 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
207 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
208 {NULL, NULL, NULL, 0, 0, 0}
211 /* Group resource -- not implemented
213 * name handler value code flags default_value
215 static struct res_items group_items[] = {
216 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
217 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
218 {NULL, NULL, NULL, 0, 0, 0}
223 * name handler value code flags default_value
225 static struct res_items pool_items[] = {
226 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
227 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
228 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
229 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
230 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
231 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
232 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
233 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, 0, 0},
234 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
235 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
236 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
237 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
238 {NULL, NULL, NULL, 0, 0, 0}
243 * name handler value code flags default_value
245 static struct res_items counter_items[] = {
246 {"name", store_name, ITEM(res_counter.hdr.name), 0, ITEM_REQUIRED, 0},
247 {"description", store_str, ITEM(res_counter.hdr.desc), 0, 0, 0},
248 {"minimum", store_int, ITEM(res_counter.MinValue), 0, ITEM_DEFAULT, 0},
249 {"maximum", store_pint, ITEM(res_counter.MaxValue), 0, ITEM_DEFAULT, INT32_MAX},
250 {"global", store_yesno, ITEM(res_counter.Global), 0, ITEM_DEFAULT, 0},
251 {"wrapcounter", store_strname, ITEM(res_counter.WrapCounter), 0, 0, 0},
252 {NULL, NULL, NULL, 0, 0, 0}
256 /* Message resource */
257 extern struct res_items msgs_items[];
260 * This is the master resource definition.
261 * It must have one item for each of the resources.
263 * name items rcode res_head
265 struct s_res resources[] = {
266 {"director", dir_items, R_DIRECTOR, NULL},
267 {"client", cli_items, R_CLIENT, NULL},
268 {"job", job_items, R_JOB, NULL},
269 {"storage", store_items, R_STORAGE, NULL},
270 {"catalog", cat_items, R_CATALOG, NULL},
271 {"schedule", sch_items, R_SCHEDULE, NULL},
272 {"fileset", fs_items, R_FILESET, NULL},
273 {"group", group_items, R_GROUP, NULL},
274 {"pool", pool_items, R_POOL, NULL},
275 {"messages", msgs_items, R_MSGS, NULL},
276 {"counter", counter_items, R_COUNTER, NULL},
277 {NULL, NULL, 0, NULL}
281 /* Keywords (RHS) permitted in Job Level records
283 * level_name level job_type
285 struct s_jl joblevels[] = {
286 {"Full", L_FULL, JT_BACKUP},
287 {"Incremental", L_INCREMENTAL, JT_BACKUP},
288 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
289 {"Level", L_LEVEL, JT_BACKUP},
290 {"Since", L_SINCE, JT_BACKUP},
291 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
292 {"Initcatalog", L_VERIFY_INIT, JT_VERIFY},
293 {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG, JT_VERIFY},
294 {"Data", L_VERIFY_DATA, JT_VERIFY},
298 /* Keywords (RHS) permitted in Job type records
302 struct s_jt jobtypes[] = {
303 {"backup", JT_BACKUP},
305 {"verify", JT_VERIFY},
306 {"restore", JT_RESTORE},
311 /* Keywords (RHS) permitted in Backup and Verify records */
312 static struct s_kw BakVerFields[] = {
319 /* Keywords (RHS) permitted in Restore records */
320 static struct s_kw RestoreFields[] = {
323 {"jobid", 'J'}, /* JobId to restore */
324 {"where", 'W'}, /* root of restore */
325 {"replace", 'R'}, /* replacement options */
326 {"bootstrap", 'B'}, /* bootstrap file */
330 /* Options permitted in Restore replace= */
331 static struct s_kw ReplaceOptions[] = {
332 {"always", 'A'}, /* always */
340 /* Define FileSet KeyWord values */
343 #define FS_KW_COMPRESSION 1
344 #define FS_KW_SIGNATURE 2
345 #define FS_KW_ENCRYPTION 3
346 #define FS_KW_VERIFY 4
347 #define FS_KW_ONEFS 5
348 #define FS_KW_RECURSE 6
350 /* FileSet keywords */
351 static struct s_kw FS_option_kw[] = {
352 {"compression", FS_KW_COMPRESSION},
353 {"signature", FS_KW_SIGNATURE},
354 {"encryption", FS_KW_ENCRYPTION},
355 {"verify", FS_KW_VERIFY},
356 {"onefs", FS_KW_ONEFS},
357 {"recurse", FS_KW_RECURSE},
361 /* Options for FileSet keywords */
369 /* Options permitted for each keyword and resulting value */
370 static struct s_fs_opt FS_options[] = {
371 {"md5", FS_KW_SIGNATURE, "M"},
372 {"gzip", FS_KW_COMPRESSION, "Z6"},
373 {"gzip1", FS_KW_COMPRESSION, "Z1"},
374 {"gzip2", FS_KW_COMPRESSION, "Z2"},
375 {"gzip3", FS_KW_COMPRESSION, "Z3"},
376 {"gzip4", FS_KW_COMPRESSION, "Z4"},
377 {"gzip5", FS_KW_COMPRESSION, "Z5"},
378 {"gzip6", FS_KW_COMPRESSION, "Z6"},
379 {"gzip7", FS_KW_COMPRESSION, "Z7"},
380 {"gzip8", FS_KW_COMPRESSION, "Z8"},
381 {"gzip9", FS_KW_COMPRESSION, "Z9"},
382 {"blowfish", FS_KW_ENCRYPTION, "B"}, /* ***FIXME*** not implemented */
383 {"3des", FS_KW_ENCRYPTION, "3"}, /* ***FIXME*** not implemented */
384 {"yes", FS_KW_ONEFS, "0"},
385 {"no", FS_KW_ONEFS, "f"},
386 {"yes", FS_KW_RECURSE, "0"},
387 {"no", FS_KW_RECURSE, "h"},
391 char *level_to_str(int level)
394 static char level_no[30];
395 char *str = level_no;
397 sprintf(level_no, "%d", level); /* default if not found */
398 for (i=0; joblevels[i].level_name; i++) {
399 if (level == joblevels[i].level) {
400 str = joblevels[i].level_name;
409 /* Dump contents of resource */
410 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
413 URES *res = (URES *)reshdr;
417 sendit(sock, "No %s resource defined\n", res_to_str(type));
420 if (type < 0) { /* no recursion */
426 char ed1[30], ed2[30];
427 sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%s SDtimeout=%s\n",
428 reshdr->name, res->res_dir.MaxConcurrentJobs,
429 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
430 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
431 if (res->res_dir.query_file) {
432 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
434 if (res->res_dir.messages) {
435 sendit(sock, " --> ");
436 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
440 sendit(sock, "Client: name=%s address=%s FDport=%d\n",
441 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
442 sendit(sock, "JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
443 res->res_client.JobRetention, res->res_client.FileRetention,
444 res->res_client.AutoPrune);
445 if (res->res_client.catalog) {
446 sendit(sock, " --> ");
447 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
451 sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
452 DeviceName=%s MediaType=%s\n",
453 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
454 res->res_store.dev_name, res->res_store.media_type);
457 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
459 res->res_cat.hdr.name, NPRT(res->res_cat.address),
460 res->res_cat.DBport, res->res_cat.db_name, NPRT(res->res_cat.db_user));
463 sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name,
464 res->res_job.JobType, level_to_str(res->res_job.level));
465 if (res->res_job.client) {
466 sendit(sock, " --> ");
467 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
469 if (res->res_job.fileset) {
470 sendit(sock, " --> ");
471 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
473 if (res->res_job.schedule) {
474 sendit(sock, " --> ");
475 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
477 if (res->res_job.RestoreWhere) {
478 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
480 if (res->res_job.RestoreBootstrap) {
481 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
483 if (res->res_job.RunBeforeJob) {
484 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
486 if (res->res_job.RunAfterJob) {
487 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
489 if (res->res_job.storage) {
490 sendit(sock, " --> ");
491 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
493 if (res->res_job.pool) {
494 sendit(sock, " --> ");
495 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
497 sendit(sock, "!!! No Pool resource\n");
499 if (res->res_job.messages) {
500 sendit(sock, " --> ");
501 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
505 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
506 for (i=0; i<res->res_fs.num_includes; i++)
507 sendit(sock, " Inc: %s\n", res->res_fs.include_array[i]);
508 for (i=0; i<res->res_fs.num_excludes; i++)
509 sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]);
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+1);
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 sendit(sock, " mins=%d\n", run->minute);
560 sendit(sock, " --> ");
561 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
564 sendit(sock, " --> ");
565 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
568 sendit(sock, " --> ");
569 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
571 /* If another Run record is chained in, go print it */
577 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
581 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
584 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
585 res->res_pool.pool_type);
586 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
587 res->res_pool.use_catalog, res->res_pool.use_volume_once,
588 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
589 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
590 res->res_pool.max_volumes, res->res_pool.AutoPrune,
591 res->res_pool.VolRetention);
592 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
593 NPRT(res->res_pool.label_format));
596 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
597 if (res->res_msgs.mail_cmd)
598 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
599 if (res->res_msgs.operator_cmd)
600 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
603 sendit(sock, "Unknown resource type %d\n", type);
606 if (recurse && res->res_dir.hdr.next) {
607 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
612 * Free memory of resource.
613 * NB, we don't need to worry about freeing any references
614 * to other resources as they will be freed when that
615 * resource chain is traversed. Mainly we worry about freeing
616 * allocated strings (names).
618 void free_resource(int type)
623 int rindex = type - r_first;
625 res = (URES *)resources[rindex].res_head;
630 /* common stuff -- free the resource name and description */
631 nres = (RES *)res->res_dir.hdr.next;
632 if (res->res_dir.hdr.name) {
633 free(res->res_dir.hdr.name);
635 if (res->res_dir.hdr.desc) {
636 free(res->res_dir.hdr.desc);
641 if (res->res_dir.working_directory)
642 free(res->res_dir.working_directory);
643 if (res->res_dir.pid_directory)
644 free(res->res_dir.pid_directory);
645 if (res->res_dir.subsys_directory)
646 free(res->res_dir.subsys_directory);
647 if (res->res_dir.password)
648 free(res->res_dir.password);
649 if (res->res_dir.query_file)
650 free(res->res_dir.query_file);
653 if (res->res_client.address)
654 free(res->res_client.address);
655 if (res->res_client.password)
656 free(res->res_client.password);
659 if (res->res_store.address)
660 free(res->res_store.address);
661 if (res->res_store.password)
662 free(res->res_store.password);
663 if (res->res_store.media_type)
664 free(res->res_store.media_type);
665 if (res->res_store.dev_name)
666 free(res->res_store.dev_name);
669 if (res->res_cat.address)
670 free(res->res_cat.address);
671 if (res->res_cat.db_user)
672 free(res->res_cat.db_user);
673 if (res->res_cat.db_name)
674 free(res->res_cat.db_name);
675 if (res->res_cat.db_password)
676 free(res->res_cat.db_password);
679 if ((num=res->res_fs.num_includes)) {
681 free(res->res_fs.include_array[num]);
682 free(res->res_fs.include_array);
684 if ((num=res->res_fs.num_excludes)) {
686 free(res->res_fs.exclude_array[num]);
687 free(res->res_fs.exclude_array);
691 if (res->res_pool.pool_type) {
692 free(res->res_pool.pool_type);
694 if (res->res_pool.label_format) {
695 free(res->res_pool.label_format);
699 if (res->res_sch.run) {
701 nrun = res->res_sch.run;
710 if (res->res_job.RestoreWhere) {
711 free(res->res_job.RestoreWhere);
713 if (res->res_job.RestoreBootstrap) {
714 free(res->res_job.RestoreBootstrap);
716 if (res->res_job.RunBeforeJob) {
717 free(res->res_job.RunBeforeJob);
719 if (res->res_job.RunAfterJob) {
720 free(res->res_job.RunAfterJob);
724 if (res->res_msgs.mail_cmd)
725 free(res->res_msgs.mail_cmd);
726 if (res->res_msgs.operator_cmd)
727 free(res->res_msgs.operator_cmd);
728 free_msgs_res((MSGS *)res); /* free message resource */
734 printf("Unknown resource type %d\n", type);
736 /* Common stuff again -- free the resource, recurse to next one */
740 resources[rindex].res_head = nres;
747 * Save the new resource by chaining it into the head list for
748 * the resource. If this is pass 2, we update any resource
749 * pointers because they may not have been defined until
752 void save_resource(int type, struct res_items *items, int pass)
755 int rindex = type - r_first;
760 * Ensure that all required items are present
762 for (i=0; items[i].name; i++) {
763 if (items[i].flags & ITEM_REQUIRED) {
764 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
765 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
766 items[i].name, resources[rindex]);
769 /* If this triggers, take a look at lib/parse_conf.h */
770 if (i >= MAX_RES_ITEMS) {
771 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
775 /* During pass 2 in each "store" routine, we looked up pointers
776 * to all the resources referrenced in the current resource, now we
777 * must copy their addresses from the static record to the allocated
782 /* Resources not containing a resource */
791 /* Resources containing another resource */
793 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
794 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
796 res->res_dir.messages = res_all.res_dir.messages;
799 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
800 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
802 res->res_job.messages = res_all.res_job.messages;
803 res->res_job.schedule = res_all.res_job.schedule;
804 res->res_job.client = res_all.res_job.client;
805 res->res_job.fileset = res_all.res_job.fileset;
806 res->res_job.storage = res_all.res_job.storage;
807 res->res_job.pool = res_all.res_job.pool;
808 if (res->res_job.JobType == 0) {
809 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
811 if (res->res_job.level != 0) {
813 for (i=0; joblevels[i].level_name; i++) {
814 if (joblevels[i].level == res->res_job.level &&
815 joblevels[i].job_type == res->res_job.JobType) {
821 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
822 res_all.res_dir.hdr.name);
827 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
828 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
830 res->res_client.catalog = res_all.res_client.catalog;
833 /* Schedule is a bit different in that it contains a RUN record
834 * chain which isn't a "named" resource. This chain was linked
835 * in by run_conf.c during pass 2, so here we jam the pointer
836 * into the Schedule resource.
838 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
839 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
841 res->res_sch.run = res_all.res_sch.run;
844 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
848 /* Note, the resource name was already saved during pass 1,
849 * so here, we can just release it.
851 if (res_all.res_dir.hdr.name) {
852 free(res_all.res_dir.hdr.name);
853 res_all.res_dir.hdr.name = NULL;
855 if (res_all.res_dir.hdr.desc) {
856 free(res_all.res_dir.hdr.desc);
857 res_all.res_dir.hdr.desc = NULL;
862 /* The following code is only executed for pass 1 */
865 size = sizeof(DIRRES);
868 size =sizeof(CLIENT);
871 size = sizeof(STORE);
880 size = sizeof(FILESET);
883 size = sizeof(SCHED);
886 size = sizeof(GROUP);
895 printf("Unknown resource type %d\n", type);
902 res = (URES *)malloc(size);
903 memcpy(res, &res_all, size);
904 if (!resources[rindex].res_head) {
905 resources[rindex].res_head = (RES *)res; /* store first entry */
908 /* Add new res to end of chain */
909 for (next=resources[rindex].res_head; next->next; next=next->next)
911 next->next = (RES *)res;
912 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
913 res->res_dir.hdr.name);
919 * Store JobType (backup, verify, restore)
922 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
926 token = lex_get_token(lc, T_NAME);
927 /* Store the type both pass 1 and pass 2 */
928 for (i=0; jobtypes[i].type_name; i++) {
929 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
930 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
936 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
939 set_bit(index, res_all.hdr.item_present);
943 * Store Job Level (Full, Incremental, ...)
946 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
950 token = lex_get_token(lc, T_NAME);
951 /* Store the level pass 2 so that type is defined */
952 for (i=0; joblevels[i].level_name; i++) {
953 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
954 ((JOB *)(item->value))->level = joblevels[i].level;
960 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
963 set_bit(index, res_all.hdr.item_present);
969 * Store backup/verify info for Job record
971 * Note, this code is used for both BACKUP and VERIFY jobs
973 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
975 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
979 int options = lc->options;
981 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
984 ((JOB *)(item->value))->JobType = item->code;
985 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
988 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
990 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
991 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
993 Dmsg1(190, "Got keyword: %s\n", lc->str);
995 for (i=0; BakVerFields[i].name; i++) {
996 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
998 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
999 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1001 token = lex_get_token(lc, T_NAME);
1002 Dmsg1(190, "Got value: %s\n", lc->str);
1003 switch (BakVerFields[i].token) {
1005 /* Find Client Resource */
1007 res = GetResWithName(R_CLIENT, lc->str);
1009 scan_err1(lc, "Could not find specified Client Resource: %s",
1012 res_all.res_job.client = (CLIENT *)res;
1016 /* Find FileSet Resource */
1018 res = GetResWithName(R_FILESET, lc->str);
1020 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1023 res_all.res_job.fileset = (FILESET *)res;
1028 for (i=0; joblevels[i].level_name; i++) {
1029 if (joblevels[i].job_type == item->code &&
1030 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1031 ((JOB *)(item->value))->level = joblevels[i].level;
1037 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1042 } /* end if strcmp() */
1045 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1048 lc->options = options; /* reset original options */
1049 set_bit(index, res_all.hdr.item_present);
1053 * Store restore info for Job record
1055 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1058 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1062 int options = lc->options;
1064 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1066 Dmsg0(190, "Enter store_restore()\n");
1068 ((JOB *)(item->value))->JobType = item->code;
1069 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1072 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1073 scan_err1(lc, "expected a name, got: %s", lc->str);
1076 for (i=0; RestoreFields[i].name; i++) {
1077 Dmsg1(190, "Restore kw=%s\n", lc->str);
1078 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1080 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1081 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1083 token = lex_get_token(lc, T_ALL);
1084 Dmsg1(190, "Restore value=%s\n", lc->str);
1085 switch (RestoreFields[i].token) {
1088 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1089 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1092 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1096 /* Find Client Resource */
1098 res = GetResWithName(R_CLIENT, lc->str);
1100 scan_err1(lc, "Could not find specified Client Resource: %s",
1103 res_all.res_job.client = (CLIENT *)res;
1107 /* Find FileSet Resource */
1109 res = GetResWithName(R_FILESET, lc->str);
1111 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1114 res_all.res_job.fileset = (FILESET *)res;
1119 if (token != T_NUMBER) {
1120 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1123 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1124 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1126 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1131 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1132 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1135 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1139 /* Replacement options */
1140 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1141 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1143 /* Fix to scan Replacement options */
1144 for (i=0; ReplaceOptions[i].name; i++) {
1145 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1146 ((JOB *)(item->value))->RestoreOptions = ReplaceOptions[i].token;
1152 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1157 } /* end if strcmp() */
1160 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1163 lc->options = options; /* reset original options */
1164 set_bit(index, res_all.hdr.item_present);
1170 * Scan for FileSet options (keyword=option) is converted into one or
1171 * two characters. Verifyopts=xxxx is Vxxxx:
1173 static char *scan_fs_options(LEX *lc, int keyword)
1176 static char opts[100];
1179 option[0] = 0; /* default option = none */
1180 opts[0] = option[2] = 0; /* terminate options */
1182 token = lex_get_token(lc, T_NAME); /* expect at least one option */
1183 if (keyword == FS_KW_VERIFY) { /* special case */
1184 /* ***FIXME**** ensure these are in permitted set */
1185 strcpy(option, "V"); /* indicate Verify */
1186 strcat(option, lc->str);
1187 strcat(option, ":"); /* terminate it */
1189 for (i=0; FS_options[i].name; i++) {
1190 if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
1191 option[0] = FS_options[i].option[0];
1192 option[1] = FS_options[i].option[1];
1198 scan_err1(lc, "Expected a FileSet option keyword, got: %s", lc->str);
1201 strcat(opts, option);
1203 /* check if more options are specified */
1204 if (lc->ch != ',') {
1205 break; /* no, get out */
1207 token = lex_get_token(lc, T_ALL); /* yes, eat comma */
1214 /* Store FileSet Include/Exclude info */
1215 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
1218 int options = lc->options;
1224 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1226 /* Get include options */
1227 strcpy(inc_opts, "0"); /* set no options */
1228 while ((token=lex_get_token(lc, T_ALL)) != T_BOB) {
1229 keyword = FS_KW_NONE;
1230 for (i=0; FS_option_kw[i].name; i++) {
1231 if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
1232 keyword = FS_option_kw[i].token;
1236 if (keyword == FS_KW_NONE) {
1237 scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1239 /* Option keyword should be following by = <option> */
1240 if ((token=lex_get_token(lc, T_ALL)) != T_EQUALS) {
1241 scan_err1(lc, "expected an = following keyword, got: %s", lc->str);
1243 strcat(inc_opts, scan_fs_options(lc, keyword));
1244 if (token == T_BOB) {
1248 strcat(inc_opts, " "); /* add field separator */
1249 inc_opts_len = strlen(inc_opts);
1253 if (!res_all.res_fs.have_MD5) {
1254 MD5Init(&res_all.res_fs.md5c);
1255 res_all.res_fs.have_MD5 = TRUE;
1257 /* Pickup include/exclude names. Note, they are stored as
1259 * where XYZ are the include/exclude options for the FileSet
1260 * a "0 " (zero) indicates no options,
1261 * and fname is the file/directory name given
1263 while ((token = lex_get_token(lc, T_ALL)) != T_EOB) {
1270 case T_UNQUOTED_STRING:
1271 case T_QUOTED_STRING:
1272 fname = (char *) malloc(lc->str_len + inc_opts_len + 1);
1273 strcpy(fname, inc_opts);
1274 strcat(fname, lc->str);
1275 if (res_all.res_fs.have_MD5) {
1276 MD5Update(&res_all.res_fs.md5c, (unsigned char *) fname, inc_opts_len + lc->str_len);
1278 if (item->code == 0) { /* include */
1279 if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
1280 res_all.res_fs.include_size += 10;
1281 if (res_all.res_fs.include_array == NULL) {
1282 res_all.res_fs.include_array = (char **) malloc(sizeof(char *) * res_all.res_fs.include_size);
1284 res_all.res_fs.include_array = (char **) realloc(res_all.res_fs.include_array,
1285 sizeof(char *) * res_all.res_fs.include_size);
1288 res_all.res_fs.include_array[res_all.res_fs.num_includes++] =
1290 } else { /* exclude */
1291 if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
1292 res_all.res_fs.exclude_size += 10;
1293 if (res_all.res_fs.exclude_array == NULL) {
1294 res_all.res_fs.exclude_array = (char **) malloc(sizeof(char *) * res_all.res_fs.exclude_size);
1296 res_all.res_fs.exclude_array = (char **) realloc(res_all.res_fs.exclude_array,
1297 sizeof(char *) * res_all.res_fs.exclude_size);
1300 res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] =
1305 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1308 } else { /* pass 2 */
1309 while (lex_get_token(lc, T_ALL) != T_EOB)
1313 lc->options = options;
1314 set_bit(index, res_all.hdr.item_present);