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_REQUIRED, 0},
91 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, 0, 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_REQUIRED, 0},
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_REQUIRED, 0},
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 {NULL, NULL, NULL, 0, 0, 0}
138 * Catalog Resource Directives
140 * name handler value code flags default_value
142 static struct res_items cat_items[] = {
143 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
144 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
145 {"address", store_str, ITEM(res_cat.address), 0, 0, 0},
146 {"dbport", store_pint, ITEM(res_cat.DBport), 0, 0, 0},
147 /* keep this password as store_str for the moment */
148 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
149 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
150 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
151 {NULL, NULL, NULL, 0, 0, 0}
155 * Job Resource Directives
157 * name handler value code flags default_value
159 static struct res_items job_items[] = {
160 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
161 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
162 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
163 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
164 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
165 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
166 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
167 {"level", store_level, ITEM(res_job), 0, 0, 0},
168 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
169 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
170 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
171 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
172 {"fileset", store_res, ITEM(res_job.fs), R_FILESET, 0, 0},
173 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
174 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
175 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
176 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
177 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
178 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
179 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
180 {NULL, NULL, NULL, 0, 0, 0}
185 * name handler value code flags default_value
187 static struct res_items fs_items[] = {
188 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
189 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
190 {"include", store_inc, NULL, 0, 0, 0},
191 {"exclude", store_inc, NULL, 1, 0, 0},
192 {NULL, NULL, NULL, 0, 0, 0}
195 /* Schedule -- see run_conf.c */
198 * name handler value code flags default_value
200 static struct res_items sch_items[] = {
201 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
202 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
203 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
204 {NULL, NULL, NULL, 0, 0, 0}
207 /* Group resource -- not implemented
209 * name handler value code flags default_value
211 static struct res_items group_items[] = {
212 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
213 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
214 {NULL, NULL, NULL, 0, 0, 0}
219 * name handler value code flags default_value
221 static struct res_items pool_items[] = {
222 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
223 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
224 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
225 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
226 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
227 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
228 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
229 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, 0, 0},
230 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
231 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
232 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
233 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
234 {NULL, NULL, NULL, 0, 0, 0}
237 /* Message resource */
238 extern struct res_items msgs_items[];
241 * This is the master resource definition.
242 * It must have one item for each of the resources.
244 * name items rcode res_head
246 struct s_res resources[] = {
247 {"director", dir_items, R_DIRECTOR, NULL},
248 {"client", cli_items, R_CLIENT, NULL},
249 {"job", job_items, R_JOB, NULL},
250 {"storage", store_items, R_STORAGE, NULL},
251 {"catalog", cat_items, R_CATALOG, NULL},
252 {"schedule", sch_items, R_SCHEDULE, NULL},
253 {"fileset", fs_items, R_FILESET, NULL},
254 {"group", group_items, R_GROUP, NULL},
255 {"pool", pool_items, R_POOL, NULL},
256 {"messages", msgs_items, R_MSGS, NULL},
257 {NULL, NULL, 0, NULL}
261 /* Keywords (RHS) permitted in Job Level records
263 * level_name level job_type
265 struct s_jl joblevels[] = {
266 {"Full", L_FULL, JT_BACKUP},
267 {"Incremental", L_INCREMENTAL, JT_BACKUP},
268 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
269 {"Level", L_LEVEL, JT_BACKUP},
270 {"Since", L_SINCE, JT_BACKUP},
271 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
272 {"Initcatalog", L_VERIFY_INIT, JT_VERIFY},
273 {"Volume", L_VERIFY_VOLUME, JT_VERIFY},
274 {"Data", L_VERIFY_DATA, JT_VERIFY},
278 /* Keywords (RHS) permitted in Job type records
282 struct s_jt jobtypes[] = {
283 {"backup", JT_BACKUP},
285 {"verify", JT_VERIFY},
286 {"restore", JT_RESTORE},
291 /* Keywords (RHS) permitted in Backup and Verify records */
292 static struct s_kw BakVerFields[] = {
299 /* Keywords (RHS) permitted in Restore records */
300 static struct s_kw RestoreFields[] = {
303 {"jobid", 'J'}, /* JobId to restore */
304 {"where", 'W'}, /* root of restore */
305 {"replace", 'R'}, /* replacement options */
306 {"bootstrap", 'B'}, /* bootstrap file */
310 /* Options permitted in Restore replace= */
311 static struct s_kw ReplaceOptions[] = {
312 {"always", 'A'}, /* always */
320 /* Define FileSet KeyWord values */
323 #define FS_KW_COMPRESSION 1
324 #define FS_KW_SIGNATURE 2
325 #define FS_KW_ENCRYPTION 3
326 #define FS_KW_VERIFY 4
328 /* FileSet keywords */
329 static struct s_kw FS_option_kw[] = {
330 {"compression", FS_KW_COMPRESSION},
331 {"signature", FS_KW_SIGNATURE},
332 {"encryption", FS_KW_ENCRYPTION},
333 {"verify", FS_KW_VERIFY},
337 /* Options for FileSet keywords */
345 /* Options permitted for each keyword and resulting value */
346 static struct s_fs_opt FS_options[] = {
347 {"md5", FS_KW_SIGNATURE, "M"},
348 {"gzip", FS_KW_COMPRESSION, "Z6"},
349 {"gzip1", FS_KW_COMPRESSION, "Z1"},
350 {"gzip2", FS_KW_COMPRESSION, "Z2"},
351 {"gzip3", FS_KW_COMPRESSION, "Z3"},
352 {"gzip4", FS_KW_COMPRESSION, "Z4"},
353 {"gzip5", FS_KW_COMPRESSION, "Z5"},
354 {"gzip6", FS_KW_COMPRESSION, "Z6"},
355 {"gzip7", FS_KW_COMPRESSION, "Z7"},
356 {"gzip8", FS_KW_COMPRESSION, "Z8"},
357 {"gzip9", FS_KW_COMPRESSION, "Z9"},
358 {"blowfish", FS_KW_ENCRYPTION, "B"}, /* ***FIXME*** not implemented */
359 {"3des", FS_KW_ENCRYPTION, "3"}, /* ***FIXME*** not implemented */
363 char *level_to_str(int level)
366 static char level_no[30];
367 char *str = level_no;
369 sprintf(level_no, "%d", level); /* default if not found */
370 for (i=0; joblevels[i].level_name; i++) {
371 if (level == joblevels[i].level) {
372 str = joblevels[i].level_name;
381 /* Dump contents of resource */
382 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
385 URES *res = (URES *)reshdr;
389 sendit(sock, "No %s resource defined\n", res_to_str(type));
392 if (type < 0) { /* no recursion */
398 char ed1[30], ed2[30];
399 sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%s SDtimeout=%s\n",
400 reshdr->name, res->res_dir.MaxConcurrentJobs,
401 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
402 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
403 if (res->res_dir.query_file) {
404 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
406 if (res->res_dir.messages) {
407 sendit(sock, " --> ");
408 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
412 sendit(sock, "Client: name=%s address=%s FDport=%d\n",
413 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
414 sendit(sock, "JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
415 res->res_client.JobRetention, res->res_client.FileRetention,
416 res->res_client.AutoPrune);
417 if (res->res_client.catalog) {
418 sendit(sock, " --> ");
419 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
423 sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
424 DeviceName=%s MediaType=%s\n",
425 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
426 res->res_store.dev_name, res->res_store.media_type);
429 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
431 res->res_cat.hdr.name, NPRT(res->res_cat.address),
432 res->res_cat.DBport, res->res_cat.db_name, NPRT(res->res_cat.db_user));
435 sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name,
436 res->res_job.JobType, level_to_str(res->res_job.level));
437 if (res->res_job.client) {
438 sendit(sock, " --> ");
439 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
441 if (res->res_job.fs) {
442 sendit(sock, " --> ");
443 dump_resource(-R_FILESET, (RES *)res->res_job.fs, sendit, sock);
445 if (res->res_job.schedule) {
446 sendit(sock, " --> ");
447 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
449 if (res->res_job.RestoreWhere) {
450 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
452 if (res->res_job.RestoreBootstrap) {
453 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
455 if (res->res_job.storage) {
456 sendit(sock, " --> ");
457 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
459 if (res->res_job.pool) {
460 sendit(sock, " --> ");
461 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
463 sendit(sock, "!!! No Pool resource\n");
465 if (res->res_job.messages) {
466 sendit(sock, " --> ");
467 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
471 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
472 for (i=0; i<res->res_fs.num_includes; i++)
473 sendit(sock, " Inc: %s\n", res->res_fs.include_array[i]);
474 for (i=0; i<res->res_fs.num_excludes; i++)
475 sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]);
478 if (res->res_sch.run) {
480 RUN *run = res->res_sch.run;
481 char buf[1000], num[10];
482 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
487 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
488 strcpy(buf, " hour=");
489 for (i=0; i<24; i++) {
490 if (bit_is_set(i, run->hour)) {
491 sprintf(num, "%d ", i+1);
497 strcpy(buf, " mday=");
498 for (i=0; i<31; i++) {
499 if (bit_is_set(i, run->mday)) {
500 sprintf(num, "%d ", i+1);
506 strcpy(buf, " month=");
507 for (i=0; i<12; i++) {
508 if (bit_is_set(i, run->month)) {
509 sprintf(num, "%d ", i+1);
515 strcpy(buf, " wday=");
516 for (i=0; i<7; i++) {
517 if (bit_is_set(i, run->wday)) {
518 sprintf(num, "%d ", i+1);
524 sendit(sock, " mins=%d\n", run->minute);
526 sendit(sock, " --> ");
527 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
530 sendit(sock, " --> ");
531 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
534 sendit(sock, " --> ");
535 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
537 /* If another Run record is chained in, go print it */
543 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
547 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
550 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
551 res->res_pool.pool_type);
552 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
553 res->res_pool.use_catalog, res->res_pool.use_volume_once,
554 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
555 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
556 res->res_pool.max_volumes, res->res_pool.AutoPrune,
557 res->res_pool.VolRetention);
558 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
559 NPRT(res->res_pool.label_format));
562 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
563 if (res->res_msgs.mail_cmd)
564 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
565 if (res->res_msgs.operator_cmd)
566 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
569 sendit(sock, "Unknown resource type %d\n", type);
572 if (recurse && res->res_dir.hdr.next) {
573 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
578 * Free memory of resource.
579 * NB, we don't need to worry about freeing any references
580 * to other resources as they will be freed when that
581 * resource chain is traversed. Mainly we worry about freeing
582 * allocated strings (names).
584 void free_resource(int type)
589 int rindex = type - r_first;
591 res = (URES *)resources[rindex].res_head;
596 /* common stuff -- free the resource name and description */
597 nres = (RES *)res->res_dir.hdr.next;
598 if (res->res_dir.hdr.name) {
599 free(res->res_dir.hdr.name);
601 if (res->res_dir.hdr.desc) {
602 free(res->res_dir.hdr.desc);
607 if (res->res_dir.working_directory)
608 free(res->res_dir.working_directory);
609 if (res->res_dir.pid_directory)
610 free(res->res_dir.pid_directory);
611 if (res->res_dir.subsys_directory)
612 free(res->res_dir.subsys_directory);
613 if (res->res_dir.password)
614 free(res->res_dir.password);
615 if (res->res_dir.query_file)
616 free(res->res_dir.query_file);
619 if (res->res_client.address)
620 free(res->res_client.address);
621 if (res->res_client.password)
622 free(res->res_client.password);
625 if (res->res_store.address)
626 free(res->res_store.address);
627 if (res->res_store.password)
628 free(res->res_store.password);
629 if (res->res_store.media_type)
630 free(res->res_store.media_type);
631 if (res->res_store.dev_name)
632 free(res->res_store.dev_name);
635 if (res->res_cat.address)
636 free(res->res_cat.address);
637 if (res->res_cat.db_user)
638 free(res->res_cat.db_user);
639 if (res->res_cat.db_name)
640 free(res->res_cat.db_name);
641 if (res->res_cat.db_password)
642 free(res->res_cat.db_password);
645 if ((num=res->res_fs.num_includes)) {
647 free(res->res_fs.include_array[num]);
648 free(res->res_fs.include_array);
650 if ((num=res->res_fs.num_excludes)) {
652 free(res->res_fs.exclude_array[num]);
653 free(res->res_fs.exclude_array);
657 if (res->res_pool.pool_type) {
658 free(res->res_pool.pool_type);
660 if (res->res_pool.label_format) {
661 free(res->res_pool.label_format);
665 if (res->res_sch.run) {
667 nrun = res->res_sch.run;
676 if (res->res_job.RestoreWhere) {
677 free(res->res_job.RestoreWhere);
679 if (res->res_job.RestoreBootstrap) {
680 free(res->res_job.RestoreBootstrap);
684 if (res->res_msgs.mail_cmd)
685 free(res->res_msgs.mail_cmd);
686 if (res->res_msgs.operator_cmd)
687 free(res->res_msgs.operator_cmd);
688 free_msgs_res((MSGS *)res); /* free message resource */
694 printf("Unknown resource type %d\n", type);
696 /* Common stuff again -- free the resource, recurse to next one */
700 resources[rindex].res_head = nres;
707 * Save the new resource by chaining it into the head list for
708 * the resource. If this is pass 2, we update any resource
709 * pointers because they may not have been defined until
712 void save_resource(int type, struct res_items *items, int pass)
715 int rindex = type - r_first;
720 * Ensure that all required items are present
722 for (i=0; items[i].name; i++) {
723 if (items[i].flags & ITEM_REQUIRED) {
724 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
725 Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
726 items[i].name, resources[rindex]);
729 /* If this triggers, take a look at lib/parse_conf.h */
730 if (i >= MAX_RES_ITEMS) {
731 Emsg1(M_ABORT, 0, "Too many items in %s resource\n", resources[rindex]);
735 /* During pass 2 in each "store" routine, we looked up pointers
736 * to all the resources referrenced in the current resource, now we
737 * must copy their addresses from the static record to the allocated
742 /* Resources not containing a resource */
751 /* Resources containing another resource */
753 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
754 Emsg1(M_ABORT, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
756 res->res_dir.messages = res_all.res_dir.messages;
759 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
760 Emsg1(M_ABORT, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
762 res->res_job.messages = res_all.res_job.messages;
763 res->res_job.schedule = res_all.res_job.schedule;
764 res->res_job.client = res_all.res_job.client;
765 res->res_job.fs = res_all.res_job.fs;
766 res->res_job.storage = res_all.res_job.storage;
767 res->res_job.pool = res_all.res_job.pool;
768 if (res->res_job.JobType == 0) {
769 Emsg1(M_ABORT, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
771 if (res->res_job.level != 0) {
773 for (i=0; joblevels[i].level_name; i++) {
774 if (joblevels[i].level == res->res_job.level &&
775 joblevels[i].job_type == res->res_job.JobType) {
781 Emsg1(M_ABORT, 0, "Inappropriate level specified in Job resource %s\n",
782 res_all.res_dir.hdr.name);
787 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
788 Emsg1(M_ABORT, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
790 res->res_client.catalog = res_all.res_client.catalog;
793 /* Schedule is a bit different in that it contains a RUN record
794 * chain which isn't a "named" resource. This chain was linked
795 * in by run_conf.c during pass 2, so here we jam the pointer
796 * into the Schedule resource.
798 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
799 Emsg1(M_ABORT, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
801 res->res_sch.run = res_all.res_sch.run;
804 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
808 /* Note, the resource name was already saved during pass 1,
809 * so here, we can just release it.
811 if (res_all.res_dir.hdr.name) {
812 free(res_all.res_dir.hdr.name);
813 res_all.res_dir.hdr.name = NULL;
815 if (res_all.res_dir.hdr.desc) {
816 free(res_all.res_dir.hdr.desc);
817 res_all.res_dir.hdr.desc = NULL;
822 /* The following code is only executed for pass 1 */
825 size = sizeof(DIRRES);
828 size =sizeof(CLIENT);
831 size = sizeof(STORE);
840 size = sizeof(FILESET);
843 size = sizeof(SCHED);
846 size = sizeof(GROUP);
855 printf("Unknown resource type %d\n", type);
861 res = (URES *)malloc(size);
862 memcpy(res, &res_all, size);
863 if (!resources[rindex].res_head) {
864 resources[rindex].res_head = (RES *)res; /* store first entry */
867 /* Add new res to end of chain */
868 for (next=resources[rindex].res_head; next->next; next=next->next)
870 next->next = (RES *)res;
871 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
872 res->res_dir.hdr.name);
878 * Store JobType (backup, verify, restore)
881 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
885 token = lex_get_token(lc, T_NAME);
886 /* Store the type both pass 1 and pass 2 */
887 for (i=0; jobtypes[i].type_name; i++) {
888 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
889 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
895 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
898 set_bit(index, res_all.hdr.item_present);
902 * Store Job Level (Full, Incremental, ...)
905 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
909 token = lex_get_token(lc, T_NAME);
910 /* Store the level pass 2 so that type is defined */
911 for (i=0; joblevels[i].level_name; i++) {
912 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
913 ((JOB *)(item->value))->level = joblevels[i].level;
919 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
922 set_bit(index, res_all.hdr.item_present);
928 * Store backup/verify info for Job record
930 * Note, this code is used for both BACKUP and VERIFY jobs
932 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
934 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
938 int options = lc->options;
940 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
943 ((JOB *)(item->value))->JobType = item->code;
944 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
947 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
949 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
950 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
952 Dmsg1(190, "Got keyword: %s\n", lc->str);
954 for (i=0; BakVerFields[i].name; i++) {
955 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
957 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
958 scan_err1(lc, "Expected an equals, got: %s", lc->str);
960 token = lex_get_token(lc, T_NAME);
961 Dmsg1(190, "Got value: %s\n", lc->str);
962 switch (BakVerFields[i].token) {
964 /* Find Client Resource */
966 res = GetResWithName(R_CLIENT, lc->str);
968 scan_err1(lc, "Could not find specified Client Resource: %s",
971 res_all.res_job.client = (CLIENT *)res;
975 /* Find FileSet Resource */
977 res = GetResWithName(R_FILESET, lc->str);
979 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
982 res_all.res_job.fs = (FILESET *)res;
987 for (i=0; joblevels[i].level_name; i++) {
988 if (joblevels[i].job_type == item->code &&
989 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
990 ((JOB *)(item->value))->level = joblevels[i].level;
996 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1001 } /* end if strcmp() */
1004 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1007 lc->options = options; /* reset original options */
1008 set_bit(index, res_all.hdr.item_present);
1012 * Store restore info for Job record
1014 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1017 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1021 int options = lc->options;
1023 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1025 Dmsg0(190, "Enter store_restore()\n");
1027 ((JOB *)(item->value))->JobType = item->code;
1028 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1031 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1032 scan_err1(lc, "expected a name, got: %s", lc->str);
1035 for (i=0; RestoreFields[i].name; i++) {
1036 Dmsg1(190, "Restore kw=%s\n", lc->str);
1037 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1039 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1040 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1042 token = lex_get_token(lc, T_ALL);
1043 Dmsg1(190, "Restore value=%s\n", lc->str);
1044 switch (RestoreFields[i].token) {
1047 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1048 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1051 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1055 /* Find Client Resource */
1057 res = GetResWithName(R_CLIENT, lc->str);
1059 scan_err1(lc, "Could not find specified Client Resource: %s",
1062 res_all.res_job.client = (CLIENT *)res;
1066 /* Find FileSet Resource */
1068 res = GetResWithName(R_FILESET, lc->str);
1070 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1073 res_all.res_job.fs = (FILESET *)res;
1078 if (token != T_NUMBER) {
1079 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1082 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1083 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1085 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1090 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1091 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1094 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1098 /* Replacement options */
1099 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1100 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1102 /* Fix to scan Replacement options */
1103 for (i=0; ReplaceOptions[i].name; i++) {
1104 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1105 ((JOB *)(item->value))->RestoreOptions = ReplaceOptions[i].token;
1111 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1116 } /* end if strcmp() */
1119 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1122 lc->options = options; /* reset original options */
1123 set_bit(index, res_all.hdr.item_present);
1129 * Scan for FileSet options (keyword=option) is converted into one or
1130 * two characters. Verifyopts=xxxx is Vxxxx:
1132 static char *scan_fs_options(LEX *lc, int keyword)
1135 static char opts[100];
1138 option[0] = 0; /* default option = none */
1139 opts[0] = option[2] = 0; /* terminate options */
1141 token = lex_get_token(lc, T_NAME); /* expect at least one option */
1142 if (keyword == FS_KW_VERIFY) { /* special case */
1143 /* ***FIXME**** ensure these are in permitted set */
1144 strcpy(option, "V"); /* indicate Verify */
1145 strcat(option, lc->str);
1146 strcat(option, ":"); /* terminate it */
1148 for (i=0; FS_options[i].name; i++) {
1149 if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
1150 option[0] = FS_options[i].option[0];
1151 option[1] = FS_options[i].option[1];
1157 scan_err1(lc, "Expected a FileSet option keyword, got: %s", lc->str);
1160 strcat(opts, option);
1162 /* check if more options are specified */
1163 if (lc->ch != ',') {
1164 break; /* no, get out */
1166 token = lex_get_token(lc, T_ALL); /* yes, eat comma */
1173 /* Store FileSet Include/Exclude info */
1174 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
1177 int options = lc->options;
1183 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1185 /* Get include options */
1186 strcpy(inc_opts, "0"); /* set no options */
1187 while ((token=lex_get_token(lc, T_ALL)) != T_BOB) {
1188 keyword = FS_KW_NONE;
1189 for (i=0; FS_option_kw[i].name; i++) {
1190 if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
1191 keyword = FS_option_kw[i].token;
1195 if (keyword == FS_KW_NONE) {
1196 scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1198 /* Option keyword should be following by = <option> */
1199 if ((token=lex_get_token(lc, T_ALL)) != T_EQUALS) {
1200 scan_err1(lc, "expected an = following keyword, got: %s", lc->str);
1202 strcat(inc_opts, scan_fs_options(lc, keyword));
1203 if (token == T_BOB) {
1207 strcat(inc_opts, " "); /* add field separator */
1208 inc_opts_len = strlen(inc_opts);
1212 if (!res_all.res_fs.have_MD5) {
1213 MD5Init(&res_all.res_fs.md5c);
1214 res_all.res_fs.have_MD5 = TRUE;
1216 /* Pickup include/exclude names. Note, they are stored as
1218 * where XYZ are the include/exclude options for the FileSet
1219 * a "0 " (zero) indicates no options,
1220 * and fname is the file/directory name given
1222 while ((token = lex_get_token(lc, T_ALL)) != T_EOB) {
1229 case T_UNQUOTED_STRING:
1230 case T_QUOTED_STRING:
1231 fname = (char *) malloc(lc->str_len + inc_opts_len + 1);
1232 strcpy(fname, inc_opts);
1233 strcat(fname, lc->str);
1234 if (res_all.res_fs.have_MD5) {
1235 MD5Update(&res_all.res_fs.md5c, (unsigned char *) fname, inc_opts_len + lc->str_len);
1237 if (item->code == 0) { /* include */
1238 if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
1239 res_all.res_fs.include_size += 10;
1240 if (res_all.res_fs.include_array == NULL) {
1241 res_all.res_fs.include_array = (char **) malloc(sizeof(char *) * res_all.res_fs.include_size);
1243 res_all.res_fs.include_array = (char **) realloc(res_all.res_fs.include_array,
1244 sizeof(char *) * res_all.res_fs.include_size);
1247 res_all.res_fs.include_array[res_all.res_fs.num_includes++] =
1249 } else { /* exclude */
1250 if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
1251 res_all.res_fs.exclude_size += 10;
1252 if (res_all.res_fs.exclude_array == NULL) {
1253 res_all.res_fs.exclude_array = (char **) malloc(sizeof(char *) * res_all.res_fs.exclude_size);
1255 res_all.res_fs.exclude_array = (char **) realloc(res_all.res_fs.exclude_array,
1256 sizeof(char *) * res_all.res_fs.exclude_size);
1259 res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] =
1264 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1267 } else { /* pass 2 */
1268 while (lex_get_token(lc, T_ALL) != T_EOB)
1272 lc->options = options;
1273 set_bit(index, res_all.hdr.item_present);