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
23 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
25 This program is free software; you can redistribute it and/or
26 modify it under the terms of the GNU General Public License as
27 published by the Free Software Foundation; either version 2 of
28 the License, or (at your option) any later version.
30 This program is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 General Public License for more details.
35 You should have received a copy of the GNU General Public
36 License along with this program; if not, write to the Free
37 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
45 /* Define the first and last resource ID record
46 * types. Note, these should be unique for each
47 * daemon though not a requirement.
49 int r_first = R_FIRST;
51 pthread_mutex_t res_mutex = PTHREAD_MUTEX_INITIALIZER;
53 /* Imported subroutines */
54 extern void store_run(LEX *lc, struct res_items *item, int index, int pass);
57 /* Forward referenced subroutines */
59 static void store_inc(LEX *lc, struct res_items *item, int index, int pass);
60 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
61 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
64 /* We build the current resource here as we are
65 * scanning the resource configuration definition,
66 * then move it to allocated memory when the resource
70 int res_all_size = sizeof(res_all);
73 /* Definition of records permitted within each
74 * resource with the routine to process the record
75 * information. NOTE! quoted names must be in lower case.
80 * name handler value code flags default_value
82 static struct res_items dir_items[] = {
83 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
84 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
85 {"messages", store_res, ITEM(res_dir.messages), R_MSGS, 0, 0},
86 {"dirport", store_pint, ITEM(res_dir.DIRport), 0, ITEM_REQUIRED, 0},
87 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, 0, 0},
88 {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
89 {"piddirectory", store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
90 {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, ITEM_REQUIRED, 0},
91 {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
92 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
93 {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
94 {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
96 {NULL, NULL, NULL, 0, 0, 0}
100 * Client or File daemon resource
102 * name handler value code flags default_value
105 static struct res_items cli_items[] = {
106 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
107 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
108 {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
109 {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_REQUIRED, 0},
110 {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
111 {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0},
112 {"catalogretentionperiod", store_time,
113 ITEM(res_client.cat_ret_period), 0, ITEM_DEFAULT, 60},
114 {"mediaretentionperiod", store_time,
115 ITEM(res_client.media_ret_period), 0, ITEM_DEFAULT, 60},
116 {NULL, NULL, NULL, 0, 0, 0}
119 /* Storage daemon resource
121 * name handler value code flags default_value
123 static struct res_items store_items[] = {
124 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
125 {"description", store_str, ITEM(res_store.hdr.desc), 0, 0, 0},
126 {"sdport", store_pint, ITEM(res_store.SDport), 0, ITEM_REQUIRED, 0},
127 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
128 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
129 {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
130 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
131 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
132 {NULL, NULL, NULL, 0, 0, 0}
136 * Catalog Resource Directives
138 * name handler value code flags default_value
140 static struct res_items cat_items[] = {
141 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
142 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
143 {"address", store_str, ITEM(res_cat.address), 0, 0, 0},
144 {"dbport", store_pint, ITEM(res_cat.DBport), 0, 0, 0},
145 /* keep this password as store_str for the moment */
146 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
147 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
148 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
149 {NULL, NULL, NULL, 0, 0, 0}
153 * Job Resource Directives
155 * name handler value code flags default_value
157 static struct res_items job_items[] = {
158 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
159 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
160 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
161 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
162 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
163 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
164 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
165 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
166 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
167 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
168 {"maxstartdelay", store_time, ITEM(res_job.MaxStartDelay), 0, 0, 0},
169 {NULL, NULL, NULL, 0, 0, 0}
174 * name handler value code flags default_value
176 static struct res_items fs_items[] = {
177 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
178 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
179 {"include", store_inc, NULL, 0, 0, 0},
180 {"exclude", store_inc, NULL, 1, 0, 0},
181 {NULL, NULL, NULL, 0, 0, 0}
184 /* Schedule -- see run_conf.c */
187 * name handler value code flags default_value
189 static struct res_items sch_items[] = {
190 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
191 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
192 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
193 {NULL, NULL, NULL, 0, 0, 0}
196 /* Group resource -- not implemented
198 * name handler value code flags default_value
200 static struct res_items group_items[] = {
201 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
202 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
203 {NULL, NULL, NULL, 0, 0, 0}
208 * name handler value code flags default_value
210 static struct res_items pool_items[] = {
211 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
212 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
213 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
214 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
215 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
216 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
217 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
218 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, 0, 0},
219 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
220 {NULL, NULL, NULL, 0, 0, 0}
223 /* Message resource */
224 extern struct res_items msgs_items[];
227 * This is the master resource definition.
228 * It must have one item for each of the resources.
230 * name items rcode res_head
232 struct s_res resources[] = {
233 {"director", dir_items, R_DIRECTOR, NULL},
234 {"client", cli_items, R_CLIENT, NULL},
235 {"job", job_items, R_JOB, NULL},
236 {"storage", store_items, R_STORAGE, NULL},
237 {"catalog", cat_items, R_CATALOG, NULL},
238 {"schedule", sch_items, R_SCHEDULE, NULL},
239 {"fileset", fs_items, R_FILESET, NULL},
240 {"group", group_items, R_GROUP, NULL},
241 {"pool", pool_items, R_POOL, NULL},
242 {"messages", msgs_items, R_MSGS, NULL},
243 {NULL, NULL, 0, NULL}
247 /* Keywords (RHS) permitted in Job Level records
249 * level_name level level_class
251 struct s_jl joblevels[] = {
252 {"full", L_FULL, JT_BACKUP},
253 {"incremental", L_INCREMENTAL, JT_BACKUP},
254 {"differential", L_DIFFERENTIAL, JT_BACKUP},
255 {"level", L_LEVEL, JT_BACKUP},
256 {"since", L_SINCE, JT_BACKUP},
257 {"catalog", L_VERIFY_CATALOG, JT_VERIFY},
258 {"initcatalog", L_VERIFY_INIT, JT_VERIFY},
259 {"volume", L_VERIFY_VOLUME, JT_VERIFY},
260 {"data", L_VERIFY_DATA, JT_VERIFY},
264 /* Keywords (RHS) permitted in Backup and Verify records */
265 static struct s_kw BakVerFields[] = {
272 /* Keywords (RHS) permitted in Restore records */
273 static struct s_kw RestoreFields[] = {
276 {"jobid", 'J'}, /* JobId to restore */
277 {"where", 'W'}, /* root of restore */
278 {"replace", 'R'}, /* replacement options */
282 /* Options permitted in Restore replace= */
283 static struct s_kw ReplaceOptions[] = {
284 {"always", 'A'}, /* always */
292 /* Define FileSet KeyWord values */
295 #define FS_KW_COMPRESSION 1
296 #define FS_KW_SIGNATURE 2
297 #define FS_KW_ENCRYPTION 3
298 #define FS_KW_VERIFY 4
300 /* FileSet keywords */
301 static struct s_kw FS_option_kw[] = {
302 {"compression", FS_KW_COMPRESSION},
303 {"signature", FS_KW_SIGNATURE},
304 {"encryption", FS_KW_ENCRYPTION},
305 {"verify", FS_KW_VERIFY},
309 /* Options for FileSet keywords */
317 /* Options permitted for each keyword and resulting value */
318 static struct s_fs_opt FS_options[] = {
319 {"md5", FS_KW_SIGNATURE, 'M'},
320 {"gzip", FS_KW_COMPRESSION, 'Z'},
321 {"blowfish", FS_KW_ENCRYPTION, 'B'}, /* ***FIXME*** not implemented */
322 {"3des", FS_KW_ENCRYPTION, '3'}, /* ***FIXME*** not implemented */
326 char *level_to_str(int level)
329 static char level_no[30];
330 char *str = level_no;
332 sprintf(level_no, "%d", level); /* default if not found */
333 for (i=0; joblevels[i].level_name; i++) {
334 if (level == joblevels[i].level) {
335 str = joblevels[i].level_name;
344 /* Dump contents of resource */
345 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
348 URES *res = (URES *)reshdr;
352 sendit(sock, "No %s resource defined\n", res_to_str(type));
355 if (type < 0) { /* no recursion */
361 sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%d SDtimeout=%d\n",
362 reshdr->name, res->res_dir.MaxConcurrentJobs,
363 res->res_dir.FDConnectTimeout,
364 res->res_dir.SDConnectTimeout);
365 if (res->res_dir.query_file) {
366 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
368 if (res->res_dir.messages) {
369 sendit(sock, " --> ");
370 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
374 sendit(sock, "Client: name=%s address=%s FDport=%d\n",
375 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
376 sendit(sock, "CatRetPeriod=%d MediaRetPeriod=%d\n",
377 res->res_client.cat_ret_period, res->res_client.media_ret_period);
378 if (res->res_client.catalog) {
379 sendit(sock, " --> ");
380 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
384 sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
385 DeviceName=%s MediaType=%s\n",
386 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
387 res->res_store.dev_name, res->res_store.media_type);
390 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
392 res->res_cat.hdr.name, res->res_cat.address, res->res_cat.DBport,
393 res->res_cat.db_name, res->res_cat.db_user);
396 sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name,
397 res->res_job.JobType, level_to_str(res->res_job.level));
398 if (res->res_job.client) {
399 sendit(sock, " --> ");
400 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
402 if (res->res_job.fs) {
403 sendit(sock, " --> ");
404 dump_resource(-R_FILESET, (RES *)res->res_job.fs, sendit, sock);
406 if (res->res_job.schedule) {
407 sendit(sock, " --> ");
408 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
410 if (res->res_job.RestoreWhere) {
411 sendit(sock, " --> Where=%s\n", res->res_job.RestoreWhere);
413 if (res->res_job.storage) {
414 sendit(sock, " --> ");
415 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
417 if (res->res_job.pool) {
418 sendit(sock, " --> ");
419 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
421 sendit(sock, "!!! No Pool resource\n");
423 if (res->res_job.messages) {
424 sendit(sock, " --> ");
425 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
429 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
430 for (i=0; i<res->res_fs.num_includes; i++)
431 sendit(sock, " Inc: %s\n", res->res_fs.include_array[i]);
432 for (i=0; i<res->res_fs.num_excludes; i++)
433 sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]);
436 if (res->res_sch.run)
437 sendit(sock, "Schedule: name=%s Level=%s\n", res->res_sch.hdr.name,
438 level_to_str(res->res_sch.run->level));
440 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
443 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
446 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
447 res->res_pool.pool_type);
448 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d\n",
449 res->res_pool.use_catalog, res->res_pool.use_volume_once,
450 res->res_pool.accept_any_volume);
451 sendit(sock, " cat_files=%d max_vols=%d\n",
452 res->res_pool.catalog_files, res->res_pool.max_volumes);
453 sendit(sock, " LabelFormat=%s\n", res->res_pool.label_format?
454 res->res_pool.label_format:"NONE");
457 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
458 if (res->res_msgs.mail_cmd)
459 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
460 if (res->res_msgs.operator_cmd)
461 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
464 sendit(sock, "Unknown resource type %d\n", type);
467 if (recurse && res->res_dir.hdr.next) {
468 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
473 * Free memory of resource.
474 * NB, we don't need to worry about freeing any references
475 * to other resources as they will be freed when that
476 * resource chain is traversed. Mainly we worry about freeing
477 * allocated strings (names).
479 void free_resource(int type)
484 int rindex = type - r_first;
486 res = (URES *)resources[rindex].res_head;
491 /* common stuff -- free the resource name and description */
492 nres = (RES *)res->res_dir.hdr.next;
493 if (res->res_dir.hdr.name) {
494 free(res->res_dir.hdr.name);
496 if (res->res_dir.hdr.desc) {
497 free(res->res_dir.hdr.desc);
502 if (res->res_dir.working_directory)
503 free(res->res_dir.working_directory);
504 if (res->res_dir.pid_directory)
505 free(res->res_dir.pid_directory);
506 if (res->res_dir.subsys_directory)
507 free(res->res_dir.subsys_directory);
508 if (res->res_dir.password)
509 free(res->res_dir.password);
510 if (res->res_dir.query_file)
511 free(res->res_dir.query_file);
514 if (res->res_client.address)
515 free(res->res_client.address);
516 if (res->res_client.password)
517 free(res->res_client.password);
520 if (res->res_store.address)
521 free(res->res_store.address);
522 if (res->res_store.password)
523 free(res->res_store.password);
524 if (res->res_store.media_type)
525 free(res->res_store.media_type);
526 if (res->res_store.dev_name)
527 free(res->res_store.dev_name);
530 if (res->res_cat.address)
531 free(res->res_cat.address);
532 if (res->res_cat.db_user)
533 free(res->res_cat.db_user);
534 if (res->res_cat.db_name)
535 free(res->res_cat.db_name);
536 if (res->res_cat.db_password)
537 free(res->res_cat.db_password);
540 if ((num=res->res_fs.num_includes)) {
542 free(res->res_fs.include_array[num]);
543 free(res->res_fs.include_array);
545 if ((num=res->res_fs.num_excludes)) {
547 free(res->res_fs.exclude_array[num]);
548 free(res->res_fs.exclude_array);
552 if (res->res_pool.pool_type) {
553 free(res->res_pool.pool_type);
555 if (res->res_pool.label_format) {
556 free(res->res_pool.label_format);
560 if (res->res_sch.run) {
562 nrun = res->res_sch.run;
571 if (res->res_job.RestoreWhere) {
572 free(res->res_job.RestoreWhere);
576 if (res->res_msgs.mail_cmd)
577 free(res->res_msgs.mail_cmd);
578 if (res->res_msgs.operator_cmd)
579 free(res->res_msgs.operator_cmd);
585 printf("Unknown resource type %d\n", type);
587 /* Common stuff again -- free the resource, recurse to next one */
589 resources[rindex].res_head = nres;
594 /* Save the new resource by chaining it into the head list for
595 * the resource. If this is pass 2, we update any resource
596 * pointers (currently only in the Job resource).
598 void save_resource(int type, struct res_items *items, int pass)
601 int rindex = type - r_first;
606 * Ensure that all required items are present
608 for (i=0; items[i].name; i++) {
609 if (items[i].flags & ITEM_REQUIRED) {
610 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
611 Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
612 items[i].name, resources[rindex]);
615 /* If this triggers, take a look at lib/parse_conf.h */
616 if (i >= MAX_RES_ITEMS) {
617 Emsg1(M_ABORT, 0, "Too many items in %s resource\n", resources[rindex]);
621 /* During pass 2, we looked up pointers to all the resources
622 * referrenced in the current resource, , now we
623 * must copy their address from the static record to the allocated
628 /* Resources not containing a resource */
638 /* Resources containing another resource */
640 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
641 Emsg1(M_ABORT, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
643 res->res_dir.messages = res_all.res_dir.messages;
646 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
647 Emsg1(M_ABORT, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
649 res->res_job.messages = res_all.res_job.messages;
650 res->res_job.schedule = res_all.res_job.schedule;
651 res->res_job.client = res_all.res_job.client;
652 res->res_job.fs = res_all.res_job.fs;
653 res->res_job.storage = res_all.res_job.storage;
654 res->res_job.pool = res_all.res_job.pool;
657 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
658 Emsg1(M_ABORT, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
660 res->res_client.catalog = res_all.res_client.catalog;
663 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
667 /* Note, the resource name was already saved during pass 1,
668 * so here, we can just release it.
670 if (res_all.res_dir.hdr.name) {
671 free(res_all.res_dir.hdr.name);
672 res_all.res_dir.hdr.name = NULL;
679 size = sizeof(DIRRES);
682 size =sizeof(CLIENT);
685 size = sizeof(STORE);
694 size = sizeof(FILESET);
697 size = sizeof(SCHED);
700 size = sizeof(GROUP);
709 printf("Unknown resource type %d\n", type);
715 res = (URES *) malloc(size);
716 memcpy(res, &res_all, size);
717 res->res_dir.hdr.next = resources[rindex].res_head;
718 resources[rindex].res_head = (RES *)res;
719 Dmsg2(90, "dir_conf: inserting %s res: %s\n", res_to_str(type),
720 res->res_dir.hdr.name);
726 * Store backup/verify info for Job record
728 * Note, this code is used for both BACKUP and VERIFY jobs
730 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
732 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
736 int options = lc->options;
738 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
741 ((JOB *)(item->value))->JobType = item->code;
742 while ((token = lex_get_token(lc)) != T_EOL) {
745 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
746 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
749 Dmsg1(190, "Got keyword: %s\n", lc->str);
751 for (i=0; BakVerFields[i].name; i++) {
752 if (strcmp(lc->str, BakVerFields[i].name) == 0) {
754 if (lex_get_token(lc) != T_EQUALS) {
755 scan_err1(lc, "Expected an equals, got: %s", lc->str);
757 token = lex_get_token(lc);
758 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
759 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
761 Dmsg1(190, "Got value: %s\n", lc->str);
762 switch (BakVerFields[i].token) {
764 /* Find Client Resource */
766 res = GetResWithName(R_CLIENT, lc->str);
768 scan_err1(lc, "Could not find specified Client Resource: %s",
771 res_all.res_job.client = (CLIENT *)res;
775 /* Find FileSet Resource */
777 res = GetResWithName(R_FILESET, lc->str);
779 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
782 res_all.res_job.fs = (FILESET *)res;
788 for (i=0; joblevels[i].level_name; i++) {
789 if (joblevels[i].job_class == item->code &&
790 strcmp(lc->str, joblevels[i].level_name) == 0) {
791 ((JOB *)(item->value))->level = joblevels[i].level;
797 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
802 } /* end if strcmp() */
805 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
809 lc->options = options; /* reset original options */
810 set_bit(index, res_all.hdr.item_present);
814 * Store restore info for Job record
816 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options>
819 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
823 int options = lc->options;
825 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
827 Dmsg0(190, "Enter store_restore()\n");
829 ((JOB *)(item->value))->JobType = item->code;
830 while ((token = lex_get_token(lc)) != T_EOL) {
833 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
834 scan_err1(lc, "Expected a Restore keyword, got: %s", lc->str);
838 for (i=0; RestoreFields[i].name; i++) {
839 Dmsg1(190, "Restore kw=%s\n", lc->str);
840 if (strcmp(lc->str, RestoreFields[i].name) == 0) {
842 if (lex_get_token(lc) != T_EQUALS) {
843 scan_err1(lc, "Expected an equals, got: %s", lc->str);
845 token = lex_get_token(lc);
846 Dmsg1(190, "Restore value=%s\n", lc->str);
847 switch (RestoreFields[i].token) {
849 /* Find Client Resource */
851 res = GetResWithName(R_CLIENT, lc->str);
853 scan_err1(lc, "Could not find specified Client Resource: %s",
856 res_all.res_job.client = (CLIENT *)res;
860 /* Find FileSet Resource */
862 res = GetResWithName(R_FILESET, lc->str);
864 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
867 res_all.res_job.fs = (FILESET *)res;
872 if (token != T_NUMBER) {
873 scan_err1(lc, "expected an integer number, got: %s", lc->str);
876 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
877 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
879 scan_err1(lc, "expected an integer number, got: %s", lc->str);
884 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
885 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
888 res_all.res_job.RestoreWhere = bstrdup(lc->str);
892 /* Replacement options */
893 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
894 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
897 /* Fix to scan Replacement options */
898 for (i=0; ReplaceOptions[i].name; i++) {
899 if (strcmp(lc->str, ReplaceOptions[i].name) == 0) {
900 ((JOB *)(item->value))->RestoreOptions = ReplaceOptions[i].token;
906 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
911 } /* end if strcmp() */
914 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
918 lc->options = options; /* reset original options */
919 set_bit(index, res_all.hdr.item_present);
925 * Scan for FileSet options
927 static char *scan_fs_options(LEX *lc, int keyword)
930 static char opts[100];
933 option[0] = 0; /* default option = none */
934 opts[0] = option[1] = 0; /* terminate options */
936 token = lex_get_token(lc); /* expect at least one option */
937 if (token != T_IDENTIFIER && token != T_STRING && token != T_QUOTED_STRING) {
938 scan_err1(lc, "expected a FileSet option, got: %s", lc->str);
941 if (keyword == FS_KW_VERIFY) { /* special case */
942 /* ***FIXME**** ensure these are in permitted set */
943 strcpy(option, "V"); /* indicate Verify */
944 strcat(option, lc->str);
945 strcat(option, ":"); /* terminate it */
947 for (i=0; FS_options[i].name; i++) {
948 if (strcmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
949 option[0] = FS_options[i].option;
955 scan_err1(lc, "Expected a FileSet option keyword, got: %s", lc->str);
958 strcat(opts, option);
960 /* check if more options are specified */
962 break; /* no, get out */
964 token = lex_get_token(lc); /* yes, eat comma */
971 /* Store FileSet Include/Exclude info */
972 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
975 int options = lc->options;
981 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
983 /* Get include options */
984 strcpy(inc_opts, "0"); /* set no options */
985 while ((token=lex_get_token(lc)) != T_BOB) {
986 if (token != T_STRING) {
987 scan_err1(lc, "expected a FileSet option keyword, got: %s", lc->str);
989 keyword = FS_KW_NONE;
991 for (i=0; FS_option_kw[i].name; i++) {
992 if (strcmp(lc->str, FS_option_kw[i].name) == 0) {
993 keyword = FS_option_kw[i].token;
997 if (keyword == FS_KW_NONE) {
998 scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1001 /* Option keyword should be following by = <option> */
1002 if ((token=lex_get_token(lc)) != T_EQUALS) {
1003 scan_err1(lc, "expected an = following keyword, got: %s", lc->str);
1005 strcat(inc_opts, scan_fs_options(lc, keyword));
1006 if (token == T_BOB) {
1010 strcat(inc_opts, " "); /* add field separator */
1011 inc_opts_len = strlen(inc_opts);
1015 if (!res_all.res_fs.have_MD5) {
1016 MD5Init(&res_all.res_fs.md5c);
1017 res_all.res_fs.have_MD5 = TRUE;
1019 /* Pickup include/exclude names. Note, they are stored as
1021 * where XYZ are the include/exclude options for the FileSet
1022 * a "0 " (zero) indicates no options,
1023 * and fname is the file/directory name given
1025 while ((token = lex_get_token(lc)) != T_EOB) {
1033 case T_QUOTED_STRING:
1034 fname = (char *) malloc(lc->str_len + inc_opts_len + 1);
1035 strcpy(fname, inc_opts);
1036 strcat(fname, lc->str);
1037 if (res_all.res_fs.have_MD5) {
1038 MD5Update(&res_all.res_fs.md5c, (unsigned char *) fname, inc_opts_len + lc->str_len);
1040 if (item->code == 0) { /* include */
1041 if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
1042 res_all.res_fs.include_size += 10;
1043 if (res_all.res_fs.include_array == NULL) {
1044 res_all.res_fs.include_array = (char **) malloc(sizeof(char *) * res_all.res_fs.include_size);
1046 res_all.res_fs.include_array = (char **) realloc(res_all.res_fs.include_array,
1047 sizeof(char *) * res_all.res_fs.include_size);
1050 res_all.res_fs.include_array[res_all.res_fs.num_includes++] =
1052 } else { /* exclude */
1053 if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
1054 res_all.res_fs.exclude_size += 10;
1055 if (res_all.res_fs.exclude_array == NULL) {
1056 res_all.res_fs.exclude_array = (char **) malloc(sizeof(char *) * res_all.res_fs.exclude_size);
1058 res_all.res_fs.exclude_array = (char **) realloc(res_all.res_fs.exclude_array,
1059 sizeof(char *) * res_all.res_fs.exclude_size);
1062 res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] =
1067 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1070 } else { /* pass 2 */
1071 while (lex_get_token(lc) != T_EOB)
1075 lc->options = options;
1076 set_bit(index, res_all.hdr.item_present);