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 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
174 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
175 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
176 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
177 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
178 {NULL, NULL, NULL, 0, 0, 0}
183 * name handler value code flags default_value
185 static struct res_items fs_items[] = {
186 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
187 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
188 {"include", store_inc, NULL, 0, 0, 0},
189 {"exclude", store_inc, NULL, 1, 0, 0},
190 {NULL, NULL, NULL, 0, 0, 0}
193 /* Schedule -- see run_conf.c */
196 * name handler value code flags default_value
198 static struct res_items sch_items[] = {
199 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
200 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
201 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
202 {NULL, NULL, NULL, 0, 0, 0}
205 /* Group resource -- not implemented
207 * name handler value code flags default_value
209 static struct res_items group_items[] = {
210 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
211 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
212 {NULL, NULL, NULL, 0, 0, 0}
217 * name handler value code flags default_value
219 static struct res_items pool_items[] = {
220 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
221 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
222 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
223 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
224 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
225 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
226 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
227 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, 0, 0},
228 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
229 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
230 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
231 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
232 {NULL, NULL, NULL, 0, 0, 0}
235 /* Message resource */
236 extern struct res_items msgs_items[];
239 * This is the master resource definition.
240 * It must have one item for each of the resources.
242 * name items rcode res_head
244 struct s_res resources[] = {
245 {"director", dir_items, R_DIRECTOR, NULL},
246 {"client", cli_items, R_CLIENT, NULL},
247 {"job", job_items, R_JOB, NULL},
248 {"storage", store_items, R_STORAGE, NULL},
249 {"catalog", cat_items, R_CATALOG, NULL},
250 {"schedule", sch_items, R_SCHEDULE, NULL},
251 {"fileset", fs_items, R_FILESET, NULL},
252 {"group", group_items, R_GROUP, NULL},
253 {"pool", pool_items, R_POOL, NULL},
254 {"messages", msgs_items, R_MSGS, NULL},
255 {NULL, NULL, 0, NULL}
259 /* Keywords (RHS) permitted in Job Level records
261 * level_name level job_type
263 struct s_jl joblevels[] = {
264 {"Full", L_FULL, JT_BACKUP},
265 {"Incremental", L_INCREMENTAL, JT_BACKUP},
266 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
267 {"Level", L_LEVEL, JT_BACKUP},
268 {"Since", L_SINCE, JT_BACKUP},
269 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
270 {"Initcatalog", L_VERIFY_INIT, JT_VERIFY},
271 {"Volume", L_VERIFY_VOLUME, JT_VERIFY},
272 {"Data", L_VERIFY_DATA, JT_VERIFY},
276 /* Keywords (RHS) permitted in Job type records
280 struct s_jt jobtypes[] = {
281 {"backup", JT_BACKUP},
283 {"verify", JT_VERIFY},
284 {"restore", JT_RESTORE},
289 /* Keywords (RHS) permitted in Backup and Verify records */
290 static struct s_kw BakVerFields[] = {
297 /* Keywords (RHS) permitted in Restore records */
298 static struct s_kw RestoreFields[] = {
301 {"jobid", 'J'}, /* JobId to restore */
302 {"where", 'W'}, /* root of restore */
303 {"replace", 'R'}, /* replacement options */
307 /* Options permitted in Restore replace= */
308 static struct s_kw ReplaceOptions[] = {
309 {"always", 'A'}, /* always */
317 /* Define FileSet KeyWord values */
320 #define FS_KW_COMPRESSION 1
321 #define FS_KW_SIGNATURE 2
322 #define FS_KW_ENCRYPTION 3
323 #define FS_KW_VERIFY 4
325 /* FileSet keywords */
326 static struct s_kw FS_option_kw[] = {
327 {"compression", FS_KW_COMPRESSION},
328 {"signature", FS_KW_SIGNATURE},
329 {"encryption", FS_KW_ENCRYPTION},
330 {"verify", FS_KW_VERIFY},
334 /* Options for FileSet keywords */
342 /* Options permitted for each keyword and resulting value */
343 static struct s_fs_opt FS_options[] = {
344 {"md5", FS_KW_SIGNATURE, 'M'},
345 {"gzip", FS_KW_COMPRESSION, 'Z'},
346 {"blowfish", FS_KW_ENCRYPTION, 'B'}, /* ***FIXME*** not implemented */
347 {"3des", FS_KW_ENCRYPTION, '3'}, /* ***FIXME*** not implemented */
351 char *level_to_str(int level)
354 static char level_no[30];
355 char *str = level_no;
357 sprintf(level_no, "%d", level); /* default if not found */
358 for (i=0; joblevels[i].level_name; i++) {
359 if (level == joblevels[i].level) {
360 str = joblevels[i].level_name;
369 /* Dump contents of resource */
370 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
373 URES *res = (URES *)reshdr;
377 sendit(sock, "No %s resource defined\n", res_to_str(type));
380 if (type < 0) { /* no recursion */
386 char ed1[30], ed2[30];
387 sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%s SDtimeout=%s\n",
388 reshdr->name, res->res_dir.MaxConcurrentJobs,
389 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
390 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
391 if (res->res_dir.query_file) {
392 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
394 if (res->res_dir.messages) {
395 sendit(sock, " --> ");
396 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
400 sendit(sock, "Client: name=%s address=%s FDport=%d\n",
401 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
402 sendit(sock, "JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
403 res->res_client.JobRetention, res->res_client.FileRetention,
404 res->res_client.AutoPrune);
405 if (res->res_client.catalog) {
406 sendit(sock, " --> ");
407 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
411 sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
412 DeviceName=%s MediaType=%s\n",
413 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
414 res->res_store.dev_name, res->res_store.media_type);
417 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
419 res->res_cat.hdr.name, res->res_cat.address, res->res_cat.DBport,
420 res->res_cat.db_name, res->res_cat.db_user);
423 sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name,
424 res->res_job.JobType, level_to_str(res->res_job.level));
425 if (res->res_job.client) {
426 sendit(sock, " --> ");
427 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
429 if (res->res_job.fs) {
430 sendit(sock, " --> ");
431 dump_resource(-R_FILESET, (RES *)res->res_job.fs, sendit, sock);
433 if (res->res_job.schedule) {
434 sendit(sock, " --> ");
435 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
437 if (res->res_job.RestoreWhere) {
438 sendit(sock, " --> Where=%s\n", res->res_job.RestoreWhere);
440 if (res->res_job.storage) {
441 sendit(sock, " --> ");
442 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
444 if (res->res_job.pool) {
445 sendit(sock, " --> ");
446 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
448 sendit(sock, "!!! No Pool resource\n");
450 if (res->res_job.messages) {
451 sendit(sock, " --> ");
452 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
456 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
457 for (i=0; i<res->res_fs.num_includes; i++)
458 sendit(sock, " Inc: %s\n", res->res_fs.include_array[i]);
459 for (i=0; i<res->res_fs.num_excludes; i++)
460 sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]);
463 if (res->res_sch.run) {
465 RUN *run = res->res_sch.run;
466 char buf[1000], num[10];
467 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
472 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
473 strcpy(buf, " hour=");
474 for (i=0; i<24; i++) {
475 if (bit_is_set(i, run->hour)) {
476 sprintf(num, "%d ", i+1);
482 strcpy(buf, " mday=");
483 for (i=0; i<31; i++) {
484 if (bit_is_set(i, run->mday)) {
485 sprintf(num, "%d ", i+1);
491 strcpy(buf, " month=");
492 for (i=0; i<12; i++) {
493 if (bit_is_set(i, run->month)) {
494 sprintf(num, "%d ", i+1);
500 strcpy(buf, " wday=");
501 for (i=0; i<7; i++) {
502 if (bit_is_set(i, run->wday)) {
503 sprintf(num, "%d ", i+1);
509 sendit(sock, " mins=%d\n", run->minute);
511 sendit(sock, " --> ");
512 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
515 sendit(sock, " --> ");
516 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
519 sendit(sock, " --> ");
520 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
522 /* If another Run record is chained in, go print it */
528 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
532 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
535 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
536 res->res_pool.pool_type);
537 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
538 res->res_pool.use_catalog, res->res_pool.use_volume_once,
539 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
540 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
541 res->res_pool.max_volumes, res->res_pool.AutoPrune,
542 res->res_pool.VolRetention);
543 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
544 res->res_pool.label_format?res->res_pool.label_format:"*None*");
547 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
548 if (res->res_msgs.mail_cmd)
549 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
550 if (res->res_msgs.operator_cmd)
551 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
554 sendit(sock, "Unknown resource type %d\n", type);
557 if (recurse && res->res_dir.hdr.next) {
558 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
563 * Free memory of resource.
564 * NB, we don't need to worry about freeing any references
565 * to other resources as they will be freed when that
566 * resource chain is traversed. Mainly we worry about freeing
567 * allocated strings (names).
569 void free_resource(int type)
574 int rindex = type - r_first;
576 res = (URES *)resources[rindex].res_head;
581 /* common stuff -- free the resource name and description */
582 nres = (RES *)res->res_dir.hdr.next;
583 if (res->res_dir.hdr.name) {
584 free(res->res_dir.hdr.name);
586 if (res->res_dir.hdr.desc) {
587 free(res->res_dir.hdr.desc);
592 if (res->res_dir.working_directory)
593 free(res->res_dir.working_directory);
594 if (res->res_dir.pid_directory)
595 free(res->res_dir.pid_directory);
596 if (res->res_dir.subsys_directory)
597 free(res->res_dir.subsys_directory);
598 if (res->res_dir.password)
599 free(res->res_dir.password);
600 if (res->res_dir.query_file)
601 free(res->res_dir.query_file);
604 if (res->res_client.address)
605 free(res->res_client.address);
606 if (res->res_client.password)
607 free(res->res_client.password);
610 if (res->res_store.address)
611 free(res->res_store.address);
612 if (res->res_store.password)
613 free(res->res_store.password);
614 if (res->res_store.media_type)
615 free(res->res_store.media_type);
616 if (res->res_store.dev_name)
617 free(res->res_store.dev_name);
620 if (res->res_cat.address)
621 free(res->res_cat.address);
622 if (res->res_cat.db_user)
623 free(res->res_cat.db_user);
624 if (res->res_cat.db_name)
625 free(res->res_cat.db_name);
626 if (res->res_cat.db_password)
627 free(res->res_cat.db_password);
630 if ((num=res->res_fs.num_includes)) {
632 free(res->res_fs.include_array[num]);
633 free(res->res_fs.include_array);
635 if ((num=res->res_fs.num_excludes)) {
637 free(res->res_fs.exclude_array[num]);
638 free(res->res_fs.exclude_array);
642 if (res->res_pool.pool_type) {
643 free(res->res_pool.pool_type);
645 if (res->res_pool.label_format) {
646 free(res->res_pool.label_format);
650 if (res->res_sch.run) {
652 nrun = res->res_sch.run;
661 if (res->res_job.RestoreWhere) {
662 free(res->res_job.RestoreWhere);
666 if (res->res_msgs.mail_cmd)
667 free(res->res_msgs.mail_cmd);
668 if (res->res_msgs.operator_cmd)
669 free(res->res_msgs.operator_cmd);
670 free_msgs_res((MSGS *)res); /* free message resource */
676 printf("Unknown resource type %d\n", type);
678 /* Common stuff again -- free the resource, recurse to next one */
682 resources[rindex].res_head = nres;
689 * Save the new resource by chaining it into the head list for
690 * the resource. If this is pass 2, we update any resource
691 * pointers because they may not have been defined until
694 void save_resource(int type, struct res_items *items, int pass)
697 int rindex = type - r_first;
702 * Ensure that all required items are present
704 for (i=0; items[i].name; i++) {
705 if (items[i].flags & ITEM_REQUIRED) {
706 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
707 Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
708 items[i].name, resources[rindex]);
711 /* If this triggers, take a look at lib/parse_conf.h */
712 if (i >= MAX_RES_ITEMS) {
713 Emsg1(M_ABORT, 0, "Too many items in %s resource\n", resources[rindex]);
717 /* During pass 2 in each "store" routine, we looked up pointers
718 * to all the resources referrenced in the current resource, now we
719 * must copy their addresses from the static record to the allocated
724 /* Resources not containing a resource */
733 /* Resources containing another resource */
735 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
736 Emsg1(M_ABORT, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
738 res->res_dir.messages = res_all.res_dir.messages;
741 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
742 Emsg1(M_ABORT, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
744 res->res_job.messages = res_all.res_job.messages;
745 res->res_job.schedule = res_all.res_job.schedule;
746 res->res_job.client = res_all.res_job.client;
747 res->res_job.fs = res_all.res_job.fs;
748 res->res_job.storage = res_all.res_job.storage;
749 res->res_job.pool = res_all.res_job.pool;
750 if (res->res_job.JobType == 0) {
751 Emsg1(M_ABORT, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
753 if (res->res_job.level != 0) {
755 for (i=0; joblevels[i].level_name; i++) {
756 if (joblevels[i].level == res->res_job.level &&
757 joblevels[i].job_type == res->res_job.JobType) {
763 Emsg1(M_ABORT, 0, "Inappropriate level specified in Job resource %s\n",
764 res_all.res_dir.hdr.name);
769 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
770 Emsg1(M_ABORT, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
772 res->res_client.catalog = res_all.res_client.catalog;
775 /* Schedule is a bit different in that it contains a RUN record
776 * chain which isn't a "named" resource. This chain was linked
777 * in by run_conf.c during pass 2, so here we jam the pointer
778 * into the Schedule resource.
780 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
781 Emsg1(M_ABORT, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
783 res->res_sch.run = res_all.res_sch.run;
786 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
790 /* Note, the resource name was already saved during pass 1,
791 * so here, we can just release it.
793 if (res_all.res_dir.hdr.name) {
794 free(res_all.res_dir.hdr.name);
795 res_all.res_dir.hdr.name = NULL;
797 if (res_all.res_dir.hdr.desc) {
798 free(res_all.res_dir.hdr.desc);
799 res_all.res_dir.hdr.desc = NULL;
804 /* The following code is only executed for pass 1 */
807 size = sizeof(DIRRES);
810 size =sizeof(CLIENT);
813 size = sizeof(STORE);
822 size = sizeof(FILESET);
825 size = sizeof(SCHED);
828 size = sizeof(GROUP);
837 printf("Unknown resource type %d\n", type);
843 res = (URES *)malloc(size);
844 memcpy(res, &res_all, size);
845 res->res_dir.hdr.next = resources[rindex].res_head;
846 resources[rindex].res_head = (RES *)res;
847 Dmsg2(90, "dir_conf: inserting %s res: %s\n", res_to_str(type),
848 res->res_dir.hdr.name);
854 * Store JobType (backup, verify, restore)
857 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
861 token = lex_get_token(lc);
862 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
863 scan_err1(lc, "expected an identifier or string, got: %s", lc->str);
865 /* Store the type both pass 1 and pass 2 */
866 for (i=0; jobtypes[i].type_name; i++) {
867 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
868 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
874 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
878 set_bit(index, res_all.hdr.item_present);
882 * Store Job Level (Full, Incremental, ...)
885 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
889 token = lex_get_token(lc);
890 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
891 scan_err1(lc, "expected an identifier or string, got: %s", lc->str);
893 /* Store the level pass 2 so that type is defined */
894 for (i=0; joblevels[i].level_name; i++) {
895 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
896 ((JOB *)(item->value))->level = joblevels[i].level;
902 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
906 set_bit(index, res_all.hdr.item_present);
912 * Store backup/verify info for Job record
914 * Note, this code is used for both BACKUP and VERIFY jobs
916 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
918 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
922 int options = lc->options;
924 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
927 ((JOB *)(item->value))->JobType = item->code;
928 while ((token = lex_get_token(lc)) != T_EOL) {
931 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
932 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
934 Dmsg1(190, "Got keyword: %s\n", lc->str);
936 for (i=0; BakVerFields[i].name; i++) {
937 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
939 if (lex_get_token(lc) != T_EQUALS) {
940 scan_err1(lc, "Expected an equals, got: %s", lc->str);
942 token = lex_get_token(lc);
943 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
944 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
946 Dmsg1(190, "Got value: %s\n", lc->str);
947 switch (BakVerFields[i].token) {
949 /* Find Client Resource */
951 res = GetResWithName(R_CLIENT, lc->str);
953 scan_err1(lc, "Could not find specified Client Resource: %s",
956 res_all.res_job.client = (CLIENT *)res;
960 /* Find FileSet Resource */
962 res = GetResWithName(R_FILESET, lc->str);
964 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
967 res_all.res_job.fs = (FILESET *)res;
972 for (i=0; joblevels[i].level_name; i++) {
973 if (joblevels[i].job_type == item->code &&
974 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
975 ((JOB *)(item->value))->level = joblevels[i].level;
981 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
986 } /* end if strcmp() */
989 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
993 lc->options = options; /* reset original options */
994 set_bit(index, res_all.hdr.item_present);
998 * Store restore info for Job record
1000 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options>
1003 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1007 int options = lc->options;
1009 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1011 Dmsg0(190, "Enter store_restore()\n");
1013 ((JOB *)(item->value))->JobType = item->code;
1014 while ((token = lex_get_token(lc)) != T_EOL) {
1017 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
1018 scan_err1(lc, "Expected a Restore keyword, got: %s", lc->str);
1021 for (i=0; RestoreFields[i].name; i++) {
1022 Dmsg1(190, "Restore kw=%s\n", lc->str);
1023 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1025 if (lex_get_token(lc) != T_EQUALS) {
1026 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1028 token = lex_get_token(lc);
1029 Dmsg1(190, "Restore value=%s\n", lc->str);
1030 switch (RestoreFields[i].token) {
1032 /* Find Client Resource */
1034 res = GetResWithName(R_CLIENT, lc->str);
1036 scan_err1(lc, "Could not find specified Client Resource: %s",
1039 res_all.res_job.client = (CLIENT *)res;
1043 /* Find FileSet Resource */
1045 res = GetResWithName(R_FILESET, lc->str);
1047 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1050 res_all.res_job.fs = (FILESET *)res;
1055 if (token != T_NUMBER) {
1056 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1059 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1060 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1062 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1067 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
1068 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1071 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1075 /* Replacement options */
1076 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
1077 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1079 /* Fix to scan Replacement options */
1080 for (i=0; ReplaceOptions[i].name; i++) {
1081 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1082 ((JOB *)(item->value))->RestoreOptions = ReplaceOptions[i].token;
1088 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1093 } /* end if strcmp() */
1096 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1100 lc->options = options; /* reset original options */
1101 set_bit(index, res_all.hdr.item_present);
1107 * Scan for FileSet options
1109 static char *scan_fs_options(LEX *lc, int keyword)
1112 static char opts[100];
1115 option[0] = 0; /* default option = none */
1116 opts[0] = option[1] = 0; /* terminate options */
1118 token = lex_get_token(lc); /* expect at least one option */
1119 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
1120 scan_err1(lc, "expected a FileSet option, got: %s", lc->str);
1122 if (keyword == FS_KW_VERIFY) { /* special case */
1123 /* ***FIXME**** ensure these are in permitted set */
1124 strcpy(option, "V"); /* indicate Verify */
1125 strcat(option, lc->str);
1126 strcat(option, ":"); /* terminate it */
1128 for (i=0; FS_options[i].name; i++) {
1129 if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
1130 option[0] = FS_options[i].option;
1136 scan_err1(lc, "Expected a FileSet option keyword, got: %s", lc->str);
1139 strcat(opts, option);
1141 /* check if more options are specified */
1142 if (lc->ch != ',') {
1143 break; /* no, get out */
1145 token = lex_get_token(lc); /* yes, eat comma */
1152 /* Store FileSet Include/Exclude info */
1153 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
1156 int options = lc->options;
1162 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1164 /* Get include options */
1165 strcpy(inc_opts, "0"); /* set no options */
1166 while ((token=lex_get_token(lc)) != T_BOB) {
1167 if (token != T_STRING) {
1168 scan_err1(lc, "expected a FileSet option keyword, got: %s", lc->str);
1170 keyword = FS_KW_NONE;
1171 for (i=0; FS_option_kw[i].name; i++) {
1172 if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
1173 keyword = FS_option_kw[i].token;
1177 if (keyword == FS_KW_NONE) {
1178 scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1181 /* Option keyword should be following by = <option> */
1182 if ((token=lex_get_token(lc)) != T_EQUALS) {
1183 scan_err1(lc, "expected an = following keyword, got: %s", lc->str);
1185 strcat(inc_opts, scan_fs_options(lc, keyword));
1186 if (token == T_BOB) {
1190 strcat(inc_opts, " "); /* add field separator */
1191 inc_opts_len = strlen(inc_opts);
1195 if (!res_all.res_fs.have_MD5) {
1196 MD5Init(&res_all.res_fs.md5c);
1197 res_all.res_fs.have_MD5 = TRUE;
1199 /* Pickup include/exclude names. Note, they are stored as
1201 * where XYZ are the include/exclude options for the FileSet
1202 * a "0 " (zero) indicates no options,
1203 * and fname is the file/directory name given
1205 while ((token = lex_get_token(lc)) != T_EOB) {
1213 case T_QUOTED_STRING:
1214 fname = (char *) malloc(lc->str_len + inc_opts_len + 1);
1215 strcpy(fname, inc_opts);
1216 strcat(fname, lc->str);
1217 if (res_all.res_fs.have_MD5) {
1218 MD5Update(&res_all.res_fs.md5c, (unsigned char *) fname, inc_opts_len + lc->str_len);
1220 if (item->code == 0) { /* include */
1221 if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
1222 res_all.res_fs.include_size += 10;
1223 if (res_all.res_fs.include_array == NULL) {
1224 res_all.res_fs.include_array = (char **) malloc(sizeof(char *) * res_all.res_fs.include_size);
1226 res_all.res_fs.include_array = (char **) realloc(res_all.res_fs.include_array,
1227 sizeof(char *) * res_all.res_fs.include_size);
1230 res_all.res_fs.include_array[res_all.res_fs.num_includes++] =
1232 } else { /* exclude */
1233 if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
1234 res_all.res_fs.exclude_size += 10;
1235 if (res_all.res_fs.exclude_array == NULL) {
1236 res_all.res_fs.exclude_array = (char **) malloc(sizeof(char *) * res_all.res_fs.exclude_size);
1238 res_all.res_fs.exclude_array = (char **) realloc(res_all.res_fs.exclude_array,
1239 sizeof(char *) * res_all.res_fs.exclude_size);
1242 res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] =
1247 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1250 } else { /* pass 2 */
1251 while (lex_get_token(lc) != T_EOB)
1255 lc->options = options;
1256 set_bit(index, res_all.hdr.item_present);