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-2003 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_match(LEX *lc, struct res_items *item, int index, int pass);
63 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
64 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
66 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
67 static void store_replace(LEX *lc, struct res_items *item, int index, int pass);
68 static void store_opts(LEX *lc, struct res_items *item, int index, int pass);
71 /* We build the current resource here as we are
72 * scanning the resource configuration definition,
73 * then move it to allocated memory when the resource
77 int res_all_size = sizeof(res_all);
80 /* Definition of records permitted within each
81 * resource with the routine to process the record
82 * information. NOTE! quoted names must be in lower case.
87 * name handler value code flags default_value
89 static struct res_items dir_items[] = {
90 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
91 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
92 {"messages", store_res, ITEM(res_dir.messages), R_MSGS, 0, 0},
93 {"dirport", store_pint, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
94 {"diraddress", store_str, ITEM(res_dir.DIRaddr), 0, 0, 0},
95 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
96 {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
97 {"piddirectory", store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
98 {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, ITEM_REQUIRED, 0},
99 {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
100 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
101 {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
102 {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
103 {NULL, NULL, NULL, 0, 0, 0}
107 * Client or File daemon resource
109 * name handler value code flags default_value
112 static struct res_items cli_items[] = {
113 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
114 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
115 {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
116 {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_DEFAULT, 9102},
117 {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
118 {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0},
119 {"fileretention", store_time, ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
120 {"jobretention", store_time, ITEM(res_client.JobRetention), 0, ITEM_DEFAULT, 60*60*24*180},
121 {"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
122 {NULL, NULL, NULL, 0, 0, 0}
125 /* Storage daemon resource
127 * name handler value code flags default_value
129 static struct res_items store_items[] = {
130 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
131 {"description", store_str, ITEM(res_store.hdr.desc), 0, 0, 0},
132 {"sdport", store_pint, ITEM(res_store.SDport), 0, ITEM_DEFAULT, 9103},
133 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
134 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
135 {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
136 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
137 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
138 {"autochanger", store_yesno, ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
139 {NULL, NULL, NULL, 0, 0, 0}
143 * Catalog Resource Directives
145 * name handler value code flags default_value
147 static struct res_items cat_items[] = {
148 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
149 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
150 {"address", store_str, ITEM(res_cat.db_address), 0, 0, 0},
151 {"dbaddress", store_str, ITEM(res_cat.db_address), 0, 0, 0},
152 {"dbport", store_pint, ITEM(res_cat.db_port), 0, 0, 0},
153 /* keep this password as store_str for the moment */
154 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
155 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
156 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
157 {"dbsocket", store_str, ITEM(res_cat.db_socket), 0, 0, 0},
158 {NULL, NULL, NULL, 0, 0, 0}
162 * Job Resource Directives
164 * name handler value code flags default_value
166 static struct res_items job_items[] = {
167 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
168 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
169 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
170 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
171 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
172 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
173 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
174 {"level", store_level, ITEM(res_job), 0, 0, 0},
175 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
176 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
177 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
178 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
179 {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0},
180 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
181 {"replace", store_replace, ITEM(res_job.replace), REPLACE_ALWAYS, ITEM_DEFAULT, 0},
182 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
183 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
184 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
185 {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
186 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
187 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
188 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
189 {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0},
190 {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0},
191 {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
192 {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
193 {NULL, NULL, NULL, 0, 0, 0}
198 * name handler value code flags default_value
200 static struct res_items fs_items[] = {
201 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
202 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
203 {"include", store_inc, NULL, 0, 0, 0},
204 {"exclude", store_inc, NULL, 1, 0, 0},
205 {NULL, NULL, NULL, 0, 0, 0}
208 /* Schedule -- see run_conf.c */
211 * name handler value code flags default_value
213 static struct res_items sch_items[] = {
214 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
215 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
216 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
217 {NULL, NULL, NULL, 0, 0, 0}
220 /* Group resource -- not implemented
222 * name handler value code flags default_value
224 static struct res_items group_items[] = {
225 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
226 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
227 {NULL, NULL, NULL, 0, 0, 0}
232 * name handler value code flags default_value
234 static struct res_items pool_items[] = {
235 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
236 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
237 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
238 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
239 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
240 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
241 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
242 {"maximumvolumejobs", store_pint, ITEM(res_pool.MaxVolJobs), 0, 0, 0},
243 {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles), 0, 0, 0},
244 {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes), 0, 0, 0},
245 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT, 1},
246 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
247 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
248 {"volumeuseduration", store_time, ITEM(res_pool.VolUseDuration),0, 0, 0},
249 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
250 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
251 {NULL, NULL, NULL, 0, 0, 0}
256 * name handler value code flags default_value
258 static struct res_items counter_items[] = {
259 {"name", store_name, ITEM(res_counter.hdr.name), 0, ITEM_REQUIRED, 0},
260 {"description", store_str, ITEM(res_counter.hdr.desc), 0, 0, 0},
261 {"minimum", store_int, ITEM(res_counter.MinValue), 0, ITEM_DEFAULT, 0},
262 {"maximum", store_pint, ITEM(res_counter.MaxValue), 0, ITEM_DEFAULT, INT32_MAX},
263 {"global", store_yesno, ITEM(res_counter.Global), 0, ITEM_DEFAULT, 0},
264 {"wrapcounter", store_strname, ITEM(res_counter.WrapCounter), 0, 0, 0},
265 {NULL, NULL, NULL, 0, 0, 0}
270 * FileOptions Resource
271 * name handler value code flags default_value
273 static struct res_items fo_items[] = {
274 {"name", store_name, ITEM(res_fopts.hdr.name), 0, ITEM_REQUIRED, 0},
275 {"description", store_str, ITEM(res_fopts.hdr.desc), 0, 0, 0},
276 {"compression", store_opts, ITEM(res_fopts.opts), 0, 0, 0},
277 {"signature", store_opts, ITEM(res_fopts.opts), 0, 0, 0},
278 {"verify", store_opts, ITEM(res_fopts.opts), 0, 0, 0},
279 {"onefs", store_opts, ITEM(res_fopts.opts), 0, 0, 0},
280 {"recurse", store_opts, ITEM(res_fopts.opts), 0, 0, 0},
281 {"sparse", store_opts, ITEM(res_fopts.opts), 0, 0, 0},
282 {"readfifo", store_opts, ITEM(res_fopts.opts), 0, 0, 0},
283 {"replace", store_replace, ITEM(res_fopts.replace), 0, 0, 0},
284 {"match", store_match, ITEM(res_fopts.match), 0, 0, 0},
285 {NULL, NULL, NULL, 0, 0, 0}
290 /* Message resource */
291 extern struct res_items msgs_items[];
294 * This is the master resource definition.
295 * It must have one item for each of the resources.
297 * name items rcode res_head
299 struct s_res resources[] = {
300 {"director", dir_items, R_DIRECTOR, NULL},
301 {"client", cli_items, R_CLIENT, NULL},
302 {"job", job_items, R_JOB, NULL},
303 {"storage", store_items, R_STORAGE, NULL},
304 {"catalog", cat_items, R_CATALOG, NULL},
305 {"schedule", sch_items, R_SCHEDULE, NULL},
306 {"fileset", fs_items, R_FILESET, NULL},
307 {"group", group_items, R_GROUP, NULL},
308 {"pool", pool_items, R_POOL, NULL},
309 {"messages", msgs_items, R_MSGS, NULL},
310 {"counter", counter_items, R_COUNTER, NULL},
311 {"fileoptions", fo_items, R_FILEOPTIONS, NULL},
312 {NULL, NULL, 0, NULL}
316 /* Keywords (RHS) permitted in Job Level records
318 * level_name level job_type
320 struct s_jl joblevels[] = {
321 {"Full", L_FULL, JT_BACKUP},
322 {"Incremental", L_INCREMENTAL, JT_BACKUP},
323 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
324 {"Since", L_SINCE, JT_BACKUP},
325 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
326 {"Initcatalog", L_VERIFY_INIT, JT_VERIFY},
327 {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG, JT_VERIFY},
328 {"Data", L_VERIFY_DATA, JT_VERIFY},
332 /* Keywords (RHS) permitted in Job type records
336 struct s_jt jobtypes[] = {
337 {"backup", JT_BACKUP},
339 {"verify", JT_VERIFY},
340 {"restore", JT_RESTORE},
345 /* Keywords (RHS) permitted in Backup and Verify records */
346 static struct s_kw BakVerFields[] = {
353 /* Keywords (RHS) permitted in Restore records */
354 static struct s_kw RestoreFields[] = {
357 {"jobid", 'J'}, /* JobId to restore */
358 {"where", 'W'}, /* root of restore */
359 {"replace", 'R'}, /* replacement options */
360 {"bootstrap", 'B'}, /* bootstrap file */
364 /* Options permitted in Restore replace= */
365 struct s_kw ReplaceOptions[] = {
366 {"always", REPLACE_ALWAYS},
367 {"ifnewer", REPLACE_IFNEWER},
368 {"ifolder", REPLACE_IFOLDER},
369 {"never", REPLACE_NEVER},
375 /* Define FileSet KeyWord values */
377 #define INC_KW_NONE 0
378 #define INC_KW_COMPRESSION 1
379 #define INC_KW_SIGNATURE 2
380 #define INC_KW_ENCRYPTION 3
381 #define INC_KW_VERIFY 4
382 #define INC_KW_ONEFS 5
383 #define INC_KW_RECURSE 6
384 #define INC_KW_SPARSE 7
385 #define INC_KW_REPLACE 8 /* restore options */
386 #define INC_KW_READFIFO 9 /* Causes fifo data to be read */
387 #define INC_KW_FILEOPTIONS 10 /* file options */
389 /* Include keywords -- these are keywords that can appear
390 * in the options lists of an include ( Include = compression= ...)
392 static struct s_kw FS_option_kw[] = {
393 {"compression", INC_KW_COMPRESSION},
394 {"signature", INC_KW_SIGNATURE},
395 {"encryption", INC_KW_ENCRYPTION},
396 {"verify", INC_KW_VERIFY},
397 {"onefs", INC_KW_ONEFS},
398 {"recurse", INC_KW_RECURSE},
399 {"sparse", INC_KW_SPARSE},
400 {"replace", INC_KW_REPLACE},
401 {"readfifo", INC_KW_READFIFO},
402 {"fileoptions", INC_KW_FILEOPTIONS},
406 /* Options for FileSet keywords */
414 /* Options permitted for each keyword and resulting value */
415 static struct s_fs_opt FS_options[] = {
416 {"md5", INC_KW_SIGNATURE, "M"},
417 {"sha1", INC_KW_SIGNATURE, "S"},
418 {"gzip", INC_KW_COMPRESSION, "Z6"},
419 {"gzip1", INC_KW_COMPRESSION, "Z1"},
420 {"gzip2", INC_KW_COMPRESSION, "Z2"},
421 {"gzip3", INC_KW_COMPRESSION, "Z3"},
422 {"gzip4", INC_KW_COMPRESSION, "Z4"},
423 {"gzip5", INC_KW_COMPRESSION, "Z5"},
424 {"gzip6", INC_KW_COMPRESSION, "Z6"},
425 {"gzip7", INC_KW_COMPRESSION, "Z7"},
426 {"gzip8", INC_KW_COMPRESSION, "Z8"},
427 {"gzip9", INC_KW_COMPRESSION, "Z9"},
428 {"blowfish", INC_KW_ENCRYPTION, "B"}, /* ***FIXME*** not implemented */
429 {"3des", INC_KW_ENCRYPTION, "3"}, /* ***FIXME*** not implemented */
430 {"yes", INC_KW_ONEFS, "0"},
431 {"no", INC_KW_ONEFS, "f"},
432 {"yes", INC_KW_RECURSE, "0"},
433 {"no", INC_KW_RECURSE, "h"},
434 {"yes", INC_KW_SPARSE, "s"},
435 {"no", INC_KW_SPARSE, "0"},
436 {"always", INC_KW_REPLACE, "a"},
437 {"ifnewer", INC_KW_REPLACE, "w"},
438 {"never", INC_KW_REPLACE, "n"},
439 {"yes", INC_KW_READFIFO, "r"},
440 {"no", INC_KW_READFIFO, "0"},
444 char *level_to_str(int level)
447 static char level_no[30];
448 char *str = level_no;
450 sprintf(level_no, "%d", level); /* default if not found */
451 for (i=0; joblevels[i].level_name; i++) {
452 if (level == joblevels[i].level) {
453 str = joblevels[i].level_name;
462 /* Dump contents of resource */
463 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
465 URES *res = (URES *)reshdr;
469 sendit(sock, "No %s resource defined\n", res_to_str(type));
472 if (type < 0) { /* no recursion */
478 char ed1[30], ed2[30];
479 sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%s SDtimeout=%s\n",
480 reshdr->name, res->res_dir.MaxConcurrentJobs,
481 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
482 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
483 if (res->res_dir.query_file) {
484 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
486 if (res->res_dir.messages) {
487 sendit(sock, " --> ");
488 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
492 sendit(sock, "Client: name=%s address=%s FDport=%d\n",
493 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
494 sendit(sock, " JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
495 res->res_client.JobRetention, res->res_client.FileRetention,
496 res->res_client.AutoPrune);
497 if (res->res_client.catalog) {
498 sendit(sock, " --> ");
499 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
503 sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
504 DeviceName=%s MediaType=%s\n",
505 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
506 res->res_store.dev_name, res->res_store.media_type);
509 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
511 res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
512 res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
515 sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name,
516 res->res_job.JobType, level_to_str(res->res_job.level));
517 if (res->res_job.client) {
518 sendit(sock, " --> ");
519 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
521 if (res->res_job.fileset) {
522 sendit(sock, " --> ");
523 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
525 if (res->res_job.schedule) {
526 sendit(sock, " --> ");
527 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
529 if (res->res_job.RestoreWhere) {
530 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
532 if (res->res_job.RestoreBootstrap) {
533 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
535 if (res->res_job.RunBeforeJob) {
536 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
538 if (res->res_job.RunAfterJob) {
539 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
541 if (res->res_job.WriteBootstrap) {
542 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
544 if (res->res_job.storage) {
545 sendit(sock, " --> ");
546 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
548 if (res->res_job.pool) {
549 sendit(sock, " --> ");
550 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
552 sendit(sock, "!!! No Pool resource\n");
554 if (res->res_job.messages) {
555 sendit(sock, " --> ");
556 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
560 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
561 for (int i=0; i<res->res_fs.num_includes; i++) {
562 INCEXE *incexe = res->res_fs.include_items[i];
563 for (int j=0; j<incexe->num_names; j++) {
564 sendit(sock, " Inc: %s\n", incexe->name_list[j]);
567 for (int i=0; i<res->res_fs.num_excludes; i++) {
568 INCEXE *incexe = res->res_fs.exclude_items[i];
569 for (int j=0; j<incexe->num_names; j++) {
570 sendit(sock, " Exc: %s\n", incexe->name_list[j]);
575 if (res->res_sch.run) {
577 RUN *run = res->res_sch.run;
578 char buf[1000], num[10];
579 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
584 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
585 strcpy(buf, " hour=");
586 for (i=0; i<24; i++) {
587 if (bit_is_set(i, run->hour)) {
588 sprintf(num, "%d ", i);
594 strcpy(buf, " mday=");
595 for (i=0; i<31; i++) {
596 if (bit_is_set(i, run->mday)) {
597 sprintf(num, "%d ", i+1);
603 strcpy(buf, " month=");
604 for (i=0; i<12; i++) {
605 if (bit_is_set(i, run->month)) {
606 sprintf(num, "%d ", i+1);
612 strcpy(buf, " wday=");
613 for (i=0; i<7; i++) {
614 if (bit_is_set(i, run->wday)) {
615 sprintf(num, "%d ", i+1);
621 strcpy(buf, " wpos=");
622 for (i=0; i<5; i++) {
623 if (bit_is_set(i, run->wpos)) {
624 sprintf(num, "%d ", i+1);
630 sendit(sock, " mins=%d\n", run->minute);
632 sendit(sock, " --> ");
633 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
636 sendit(sock, " --> ");
637 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
640 sendit(sock, " --> ");
641 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
643 /* If another Run record is chained in, go print it */
649 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
653 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
656 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
657 res->res_pool.pool_type);
658 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
659 res->res_pool.use_catalog, res->res_pool.use_volume_once,
660 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
661 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
662 res->res_pool.max_volumes, res->res_pool.AutoPrune,
663 res->res_pool.VolRetention);
664 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
665 NPRT(res->res_pool.label_format));
668 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
669 if (res->res_msgs.mail_cmd)
670 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
671 if (res->res_msgs.operator_cmd)
672 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
675 sendit(sock, "FileOptions: name=%s\n", res->res_msgs.hdr.name);
676 sendit(sock, " opts=%s replace=%c\n", res->res_fopts.opts,
677 res->res_fopts.replace);
678 for (int i=0; i < res->res_fopts.num_match; i++) {
679 sendit(sock, " match=%s\n", res->res_fopts.match[i]);
683 sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
686 if (recurse && res->res_dir.hdr.next) {
687 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
692 * Free memory of resource.
693 * NB, we don't need to worry about freeing any references
694 * to other resources as they will be freed when that
695 * resource chain is traversed. Mainly we worry about freeing
696 * allocated strings (names).
698 void free_resource(int type)
703 int rindex = type - r_first;
705 res = (URES *)resources[rindex].res_head;
710 /* common stuff -- free the resource name and description */
711 nres = (RES *)res->res_dir.hdr.next;
712 if (res->res_dir.hdr.name) {
713 free(res->res_dir.hdr.name);
715 if (res->res_dir.hdr.desc) {
716 free(res->res_dir.hdr.desc);
721 if (res->res_dir.working_directory) {
722 free(res->res_dir.working_directory);
724 if (res->res_dir.pid_directory) {
725 free(res->res_dir.pid_directory);
727 if (res->res_dir.subsys_directory) {
728 free(res->res_dir.subsys_directory);
730 if (res->res_dir.password) {
731 free(res->res_dir.password);
733 if (res->res_dir.query_file) {
734 free(res->res_dir.query_file);
736 if (res->res_dir.DIRaddr) {
737 free(res->res_dir.DIRaddr);
741 if (res->res_client.address) {
742 free(res->res_client.address);
744 if (res->res_client.password) {
745 free(res->res_client.password);
749 if (res->res_store.address) {
750 free(res->res_store.address);
752 if (res->res_store.password) {
753 free(res->res_store.password);
755 if (res->res_store.media_type) {
756 free(res->res_store.media_type);
758 if (res->res_store.dev_name) {
759 free(res->res_store.dev_name);
763 if (res->res_cat.db_address) {
764 free(res->res_cat.db_address);
766 if (res->res_cat.db_socket) {
767 free(res->res_cat.db_socket);
769 if (res->res_cat.db_user) {
770 free(res->res_cat.db_user);
772 if (res->res_cat.db_name) {
773 free(res->res_cat.db_name);
775 if (res->res_cat.db_password) {
776 free(res->res_cat.db_password);
780 if ((num=res->res_fs.num_includes)) {
782 INCEXE *incexe = res->res_fs.include_items[num];
783 for (int i=0; i<incexe->num_names; i++) {
784 free(incexe->name_list[i]);
786 if (incexe->name_list) {
787 free(incexe->name_list);
791 free(res->res_fs.include_items);
793 res->res_fs.num_includes = 0;
794 if ((num=res->res_fs.num_excludes)) {
796 INCEXE *incexe = res->res_fs.exclude_items[num];
797 for (int i=0; i<incexe->num_names; i++) {
798 free(incexe->name_list[i]);
800 if (incexe->name_list) {
801 free(incexe->name_list);
805 free(res->res_fs.exclude_items);
807 res->res_fs.num_excludes = 0;
810 if (res->res_pool.pool_type) {
811 free(res->res_pool.pool_type);
813 if (res->res_pool.label_format) {
814 free(res->res_pool.label_format);
818 if (res->res_sch.run) {
820 nrun = res->res_sch.run;
829 if (res->res_job.RestoreWhere) {
830 free(res->res_job.RestoreWhere);
832 if (res->res_job.RestoreBootstrap) {
833 free(res->res_job.RestoreBootstrap);
835 if (res->res_job.WriteBootstrap) {
836 free(res->res_job.WriteBootstrap);
838 if (res->res_job.RunBeforeJob) {
839 free(res->res_job.RunBeforeJob);
841 if (res->res_job.RunAfterJob) {
842 free(res->res_job.RunAfterJob);
846 if (res->res_msgs.mail_cmd)
847 free(res->res_msgs.mail_cmd);
848 if (res->res_msgs.operator_cmd)
849 free(res->res_msgs.operator_cmd);
850 free_msgs_res((MSGS *)res); /* free message resource */
854 if (res->res_fopts.num_match) {
855 for (int i=0; i < res->res_fopts.num_match; i++) {
856 free(res->res_fopts.match[i]);
858 free((char *)res->res_fopts.match);
864 printf("Unknown resource type %d in free_resource.\n", type);
866 /* Common stuff again -- free the resource, recurse to next one */
870 resources[rindex].res_head = nres;
877 * Save the new resource by chaining it into the head list for
878 * the resource. If this is pass 2, we update any resource
879 * pointers because they may not have been defined until
882 void save_resource(int type, struct res_items *items, int pass)
885 int rindex = type - r_first;
890 * Ensure that all required items are present
892 for (i=0; items[i].name; i++) {
893 if (items[i].flags & ITEM_REQUIRED) {
894 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
895 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
896 items[i].name, resources[rindex]);
899 /* If this triggers, take a look at lib/parse_conf.h */
900 if (i >= MAX_RES_ITEMS) {
901 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
905 /* During pass 2 in each "store" routine, we looked up pointers
906 * to all the resources referrenced in the current resource, now we
907 * must copy their addresses from the static record to the allocated
912 /* Resources not containing a resource */
921 /* Special case for FileSet, all allocations are done
922 * only in pass 2, so here we must copy the whole structure.
923 * This is done so that we can have forward references to
924 * FileOptions resources within the fileset
928 if ((res = (URES *)GetResWithName(R_FILESET, res_all.res_dir.hdr.name)) == NULL) {
929 Emsg1(M_ERROR_TERM, 0, "Cannot find FileSet resource %s\n", res_all.res_dir.hdr.name);
931 memcpy(&res_save, &res_all, sizeof(RES));
932 memcpy(&res_all, res, sizeof(RES));
933 memcpy(res, &res_all, sizeof(FILESET));
934 memcpy(&res_all, &res_save, sizeof(RES));
937 /* Resources containing another resource */
939 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
940 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
942 res->res_dir.messages = res_all.res_dir.messages;
945 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
946 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
948 res->res_job.messages = res_all.res_job.messages;
949 res->res_job.schedule = res_all.res_job.schedule;
950 res->res_job.client = res_all.res_job.client;
951 res->res_job.fileset = res_all.res_job.fileset;
952 res->res_job.storage = res_all.res_job.storage;
953 res->res_job.pool = res_all.res_job.pool;
954 if (res->res_job.JobType == 0) {
955 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
957 if (res->res_job.level != 0) {
959 for (i=0; joblevels[i].level_name; i++) {
960 if (joblevels[i].level == res->res_job.level &&
961 joblevels[i].job_type == res->res_job.JobType) {
967 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
968 res_all.res_dir.hdr.name);
973 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
974 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
976 res->res_client.catalog = res_all.res_client.catalog;
979 /* Schedule is a bit different in that it contains a RUN record
980 * chain which isn't a "named" resource. This chain was linked
981 * in by run_conf.c during pass 2, so here we jam the pointer
982 * into the Schedule resource.
984 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
985 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
987 res->res_sch.run = res_all.res_sch.run;
990 Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
994 /* Note, the resource name was already saved during pass 1,
995 * so here, we can just release it.
997 if (res_all.res_dir.hdr.name) {
998 free(res_all.res_dir.hdr.name);
999 res_all.res_dir.hdr.name = NULL;
1001 if (res_all.res_dir.hdr.desc) {
1002 free(res_all.res_dir.hdr.desc);
1003 res_all.res_dir.hdr.desc = NULL;
1008 /* The following code is only executed for pass 1 */
1011 size = sizeof(DIRRES);
1014 size =sizeof(CLIENT);
1017 size = sizeof(STORE);
1026 size = sizeof(FILESET);
1029 size = sizeof(SCHED);
1032 size = sizeof(GROUP);
1035 size = sizeof(POOL);
1038 size = sizeof(MSGS);
1041 size = sizeof(COUNTER);
1044 size = sizeof(FILEOPTIONS);
1047 printf("Unknown resource type %d in save_resrouce.\n", type);
1054 res = (URES *)malloc(size);
1055 memcpy(res, &res_all, size);
1056 if (!resources[rindex].res_head) {
1057 resources[rindex].res_head = (RES *)res; /* store first entry */
1058 Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1059 res->res_dir.hdr.name, rindex);
1062 /* Add new res to end of chain */
1063 for (next=resources[rindex].res_head; next->next; next=next->next)
1065 next->next = (RES *)res;
1066 Dmsg3(200, "Inserting %s res: %s index=%d\n", res_to_str(type),
1067 res->res_dir.hdr.name, rindex);
1073 * Store JobType (backup, verify, restore)
1076 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1080 token = lex_get_token(lc, T_NAME);
1081 /* Store the type both pass 1 and pass 2 */
1082 for (i=0; jobtypes[i].type_name; i++) {
1083 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1084 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1090 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1093 set_bit(index, res_all.hdr.item_present);
1097 * Store Job Level (Full, Incremental, ...)
1100 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1104 token = lex_get_token(lc, T_NAME);
1105 /* Store the level pass 2 so that type is defined */
1106 for (i=0; joblevels[i].level_name; i++) {
1107 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1108 ((JOB *)(item->value))->level = joblevels[i].level;
1114 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1117 set_bit(index, res_all.hdr.item_present);
1120 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1123 token = lex_get_token(lc, T_NAME);
1124 /* Scan Replacement options */
1125 for (i=0; ReplaceOptions[i].name; i++) {
1126 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1127 *(int *)(item->value) = ReplaceOptions[i].token;
1133 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1136 set_bit(index, res_all.hdr.item_present);
1140 * Store backup/verify info for Job record
1142 * Note, this code is used for both BACKUP and VERIFY jobs
1144 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1146 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1150 int options = lc->options;
1152 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1155 ((JOB *)(item->value))->JobType = item->code;
1156 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1159 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1161 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1162 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1164 Dmsg1(190, "Got keyword: %s\n", lc->str);
1166 for (i=0; BakVerFields[i].name; i++) {
1167 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1169 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1170 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1172 token = lex_get_token(lc, T_NAME);
1173 Dmsg1(190, "Got value: %s\n", lc->str);
1174 switch (BakVerFields[i].token) {
1176 /* Find Client Resource */
1178 res = GetResWithName(R_CLIENT, lc->str);
1180 scan_err1(lc, "Could not find specified Client Resource: %s",
1183 res_all.res_job.client = (CLIENT *)res;
1187 /* Find FileSet Resource */
1189 res = GetResWithName(R_FILESET, lc->str);
1191 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1194 res_all.res_job.fileset = (FILESET *)res;
1199 for (i=0; joblevels[i].level_name; i++) {
1200 if (joblevels[i].job_type == item->code &&
1201 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1202 ((JOB *)(item->value))->level = joblevels[i].level;
1208 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1213 } /* end if strcmp() */
1216 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1219 lc->options = options; /* reset original options */
1220 set_bit(index, res_all.hdr.item_present);
1224 * Store restore info for Job record
1226 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1229 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1233 int options = lc->options;
1235 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1237 Dmsg0(190, "Enter store_restore()\n");
1239 ((JOB *)(item->value))->JobType = item->code;
1240 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1243 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1244 scan_err1(lc, "expected a name, got: %s", lc->str);
1247 for (i=0; RestoreFields[i].name; i++) {
1248 Dmsg1(190, "Restore kw=%s\n", lc->str);
1249 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1251 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1252 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1254 token = lex_get_token(lc, T_ALL);
1255 Dmsg1(190, "Restore value=%s\n", lc->str);
1256 switch (RestoreFields[i].token) {
1259 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1260 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1263 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1267 /* Find Client Resource */
1269 res = GetResWithName(R_CLIENT, lc->str);
1271 scan_err1(lc, "Could not find specified Client Resource: %s",
1274 res_all.res_job.client = (CLIENT *)res;
1278 /* Find FileSet Resource */
1280 res = GetResWithName(R_FILESET, lc->str);
1282 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1285 res_all.res_job.fileset = (FILESET *)res;
1290 if (token != T_NUMBER) {
1291 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1294 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1295 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1297 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1302 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1303 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1306 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1310 /* Replacement options */
1311 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1312 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1314 /* Fix to scan Replacement options */
1315 for (i=0; ReplaceOptions[i].name; i++) {
1316 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1317 ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1323 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1328 } /* end if strcmp() */
1331 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1334 lc->options = options; /* reset original options */
1335 set_bit(index, res_all.hdr.item_present);
1341 * Scan for Include options (keyword=option) is converted into one or
1342 * two characters. Verifyopts=xxxx is Vxxxx:
1344 static void scan_include_options(LEX *lc, int keyword, char *opts, int optlen)
1349 option[0] = 0; /* default option = none */
1350 option[2] = 0; /* terminate options */
1351 token = lex_get_token(lc, T_NAME); /* expect at least one option */
1352 if (keyword == INC_KW_VERIFY) { /* special case */
1353 /* ***FIXME**** ensure these are in permitted set */
1354 bstrncat(opts, "V", optlen); /* indicate Verify */
1355 bstrncat(opts, lc->str, optlen);
1356 bstrncat(opts, ":", optlen); /* terminate it */
1358 /* Standard keyword -- these are now deprecated and should be specified
1359 * in the FileOptions resource
1362 for (i=0; FS_options[i].name; i++) {
1363 if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
1364 /* NOTE! maximum 2 letters here or increase option[3] */
1365 option[0] = FS_options[i].option[0];
1366 option[1] = FS_options[i].option[1];
1372 scan_err1(lc, "Expected a FileSet option keyword, got:%s:", lc->str);
1373 } else { /* add option */
1374 bstrncat(opts, option, optlen);
1375 Dmsg3(200, "Catopts=%s option=%s optlen=%d\n", opts, option,optlen);
1379 /* If option terminated by comma, eat it */
1380 if (lc->ch == ',') {
1381 token = lex_get_token(lc, T_ALL); /* yes, eat comma */
1385 /* Store FileSet Include/Exclude info */
1386 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
1389 int options = lc->options;
1395 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1397 /* Get include options */
1399 while ((token=lex_get_token(lc, T_ALL)) != T_BOB) {
1400 keyword = INC_KW_NONE;
1401 for (i=0; FS_option_kw[i].name; i++) {
1402 if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
1403 keyword = FS_option_kw[i].token;
1407 if (keyword == INC_KW_NONE) {
1408 scan_err1(lc, _("Expected a FileSet keyword, got: %s"), lc->str);
1410 /* Option keyword should be following by = <option> */
1411 if ((token=lex_get_token(lc, T_ALL)) != T_EQUALS) {
1412 scan_err1(lc, _("expected an = following keyword, got: %s"), lc->str);
1414 if (keyword == INC_KW_FILEOPTIONS) {
1415 token = lex_get_token(lc, T_NAME);
1417 res = GetResWithName(R_FILEOPTIONS, lc->str);
1419 scan_err1(lc, _("Could not find specified FileOptions Resource: %s"), lc->str);
1423 scan_include_options(lc, keyword, inc_opts, sizeof(inc_opts));
1425 if (token == T_BOB) {
1430 strcat(inc_opts, "0"); /* set no options */
1432 inc_opts_len = strlen(inc_opts);
1436 if (!res_all.res_fs.have_MD5) {
1437 MD5Init(&res_all.res_fs.md5c);
1438 res_all.res_fs.have_MD5 = TRUE;
1440 /* Create incexe structure */
1441 Dmsg0(200, "Create INCEXE structure\n");
1442 incexe = (INCEXE *)malloc(sizeof(INCEXE));
1443 memset(incexe, 0, sizeof(INCEXE));
1444 bstrncpy(incexe->opts, inc_opts, sizeof(incexe->opts));
1445 incexe->fileopts = (struct s_res_fopts *)res;
1446 Dmsg1(200, "incexe opts=%s\n", incexe->opts);
1447 if (item->code == 0) { /* include */
1448 if (res_all.res_fs.num_includes == 0) {
1449 res_all.res_fs.include_items = (INCEXE **)malloc(sizeof(INCEXE *));
1451 res_all.res_fs.include_items = (INCEXE **)realloc(res_all.res_fs.include_items,
1452 sizeof(INCEXE *) * res_all.res_fs.num_includes + 1);
1454 res_all.res_fs.include_items[res_all.res_fs.num_includes++] = incexe;
1455 Dmsg1(200, "num_includes=%d\n", res_all.res_fs.num_includes);
1456 } else { /* exclude */
1457 if (res_all.res_fs.num_excludes == 0) {
1458 res_all.res_fs.exclude_items = (INCEXE **)malloc(sizeof(INCEXE *));
1460 res_all.res_fs.exclude_items = (INCEXE **)realloc(res_all.res_fs.exclude_items,
1461 sizeof(INCEXE *) * res_all.res_fs.num_excludes + 1);
1463 res_all.res_fs.exclude_items[res_all.res_fs.num_excludes++] = incexe;
1464 Dmsg1(200, "num_excludes=%d\n", res_all.res_fs.num_excludes);
1467 /* Pickup include/exclude names. They are stored in INCEXE
1468 * structures which contains the options and the name.
1470 while ((token = lex_get_token(lc, T_ALL)) != T_EOB) {
1477 case T_UNQUOTED_STRING:
1478 case T_QUOTED_STRING:
1479 if (res_all.res_fs.have_MD5) {
1480 MD5Update(&res_all.res_fs.md5c, (unsigned char *)lc->str, lc->str_len);
1482 if (incexe->num_names == incexe->max_names) {
1483 incexe->max_names += 10;
1484 if (incexe->name_list == NULL) {
1485 incexe->name_list = (char **)malloc(sizeof(char *) * incexe->max_names);
1487 incexe->name_list = (char **)realloc(incexe->name_list,
1488 sizeof(char *) * incexe->max_names);
1491 incexe->name_list[incexe->num_names++] = bstrdup(lc->str);
1492 Dmsg1(200, "Add to name_list %s\n", incexe->name_list[incexe->num_names -1]);
1495 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1498 /* Note, MD5Final is done in backup.c */
1499 } else { /* pass 1 */
1500 while (lex_get_token(lc, T_ALL) != T_EOB)
1504 lc->options = options;
1505 set_bit(index, res_all.hdr.item_present);
1508 /* Store FileOptions Match info */
1509 static void store_match(LEX *lc, struct res_items *item, int index, int pass)
1515 /* Pickup Match string
1517 token = lex_get_token(lc, T_ALL);
1520 case T_UNQUOTED_STRING:
1521 case T_QUOTED_STRING:
1522 match = (char *)malloc(lc->str_len + 1);
1523 strcpy(match, lc->str);
1524 res_all.res_fopts.num_match++;
1525 if (res_all.res_fopts.match == NULL) {
1526 res_all.res_fopts.match = (char **)malloc(sizeof(char *) * res_all.res_fopts.num_match);
1528 res_all.res_fopts.match = (char **)realloc(res_all.res_fopts.match,
1529 sizeof(char *) * res_all.res_fopts.num_match);
1531 res_all.res_fopts.match[res_all.res_fopts.num_match-1] = match;
1534 scan_err1(lc, "Expected a filename, got: %s", lc->str);
1536 } else { /* pass 2 */
1537 lex_get_token(lc, T_ALL);
1540 set_bit(index, res_all.hdr.item_present);
1543 static void store_opts(LEX *lc, struct res_items *item, int index, int pass)
1550 keyword = INC_KW_NONE;
1551 for (i=0; FS_option_kw[i].name; i++) {
1552 if (strcasecmp(item->name, FS_option_kw[i].name) == 0) {
1553 keyword = FS_option_kw[i].token;
1557 if (keyword == INC_KW_NONE) {
1558 scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1560 Dmsg2(200, "keyword=%d %s\n", keyword, FS_option_kw[keyword].name);
1561 scan_include_options(lc, keyword, inc_opts, sizeof(inc_opts));
1563 bstrncat((char *)item->value, inc_opts, MAX_FO_OPTS);
1566 set_bit(index, res_all.hdr.item_present);