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);
57 extern void store_finc(LEX *lc, struct res_items *item, int index, int pass);
58 extern void store_inc(LEX *lc, struct res_items *item, int index, int pass);
61 /* Forward referenced subroutines */
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);
70 /* We build the current resource here as we are
71 * scanning the resource configuration definition,
72 * then move it to allocated memory when the resource
76 int res_all_size = sizeof(res_all);
79 /* Definition of records permitted within each
80 * resource with the routine to process the record
81 * information. NOTE! quoted names must be in lower case.
86 * name handler value code flags default_value
88 static struct res_items dir_items[] = {
89 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
90 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
91 {"messages", store_res, ITEM(res_dir.messages), R_MSGS, 0, 0},
92 {"dirport", store_pint, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
93 {"diraddress", store_str, ITEM(res_dir.DIRaddr), 0, 0, 0},
94 {"queryfile", store_dir, ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
95 {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
96 {"piddirectory",store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
97 {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, 0, 0},
98 {"requiressl", store_yesno, ITEM(res_dir.require_ssl), 1, ITEM_DEFAULT, 0},
99 {"enablessl", store_yesno, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
100 {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
101 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
102 {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
103 {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
104 {NULL, NULL, NULL, 0, 0, 0}
110 * name handler value code flags default_value
112 static struct res_items con_items[] = {
113 {"name", store_name, ITEM(res_con.hdr.name), 0, ITEM_REQUIRED, 0},
114 {"description", store_str, ITEM(res_con.hdr.desc), 0, 0, 0},
115 {"enablessl", store_yesno, ITEM(res_con.enable_ssl), 1, ITEM_DEFAULT, 0},
116 {"password", store_password, ITEM(res_con.password), 0, ITEM_REQUIRED, 0},
117 {NULL, NULL, NULL, 0, 0, 0}
122 * Client or File daemon resource
124 * name handler value code flags default_value
127 static struct res_items cli_items[] = {
128 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
129 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
130 {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
131 {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_DEFAULT, 9102},
132 {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
133 {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0},
134 {"fileretention", store_time, ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
135 {"jobretention", store_time, ITEM(res_client.JobRetention), 0, ITEM_DEFAULT, 60*60*24*180},
136 {"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
137 {"enablessl", store_yesno, ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
138 {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
139 {NULL, NULL, NULL, 0, 0, 0}
142 /* Storage daemon resource
144 * name handler value code flags default_value
146 static struct res_items store_items[] = {
147 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
148 {"description", store_str, ITEM(res_store.hdr.desc), 0, 0, 0},
149 {"sdport", store_pint, ITEM(res_store.SDport), 0, ITEM_DEFAULT, 9103},
150 {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
151 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
152 {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
153 {"device", store_strname, ITEM(res_store.dev_name), 0, ITEM_REQUIRED, 0},
154 {"mediatype", store_strname, ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
155 {"autochanger", store_yesno, ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
156 {"enablessl", store_yesno, ITEM(res_store.enable_ssl), 1, ITEM_DEFAULT, 0},
157 {"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
158 {NULL, NULL, NULL, 0, 0, 0}
162 * Catalog Resource Directives
164 * name handler value code flags default_value
166 static struct res_items cat_items[] = {
167 {"name", store_name, ITEM(res_cat.hdr.name), 0, ITEM_REQUIRED, 0},
168 {"description", store_str, ITEM(res_cat.hdr.desc), 0, 0, 0},
169 {"address", store_str, ITEM(res_cat.db_address), 0, 0, 0},
170 {"dbaddress", store_str, ITEM(res_cat.db_address), 0, 0, 0},
171 {"dbport", store_pint, ITEM(res_cat.db_port), 0, 0, 0},
172 /* keep this password as store_str for the moment */
173 {"password", store_str, ITEM(res_cat.db_password), 0, 0, 0},
174 {"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
175 {"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
176 {"dbsocket", store_str, ITEM(res_cat.db_socket), 0, 0, 0},
177 {NULL, NULL, NULL, 0, 0, 0}
181 * Job Resource Directives
183 * name handler value code flags default_value
185 static struct res_items job_items[] = {
186 {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
187 {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0},
188 {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0},
189 {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0},
190 {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0},
191 {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
192 {"type", store_jobtype, ITEM(res_job), 0, 0, 0},
193 {"level", store_level, ITEM(res_job), 0, 0, 0},
194 {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0},
195 {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0},
196 {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0},
197 {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0},
198 {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0},
199 {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0},
200 {"replace", store_replace, ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS},
201 {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0},
202 {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0},
203 {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
204 {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
205 {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
206 {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
207 {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
208 {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0},
209 {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0},
210 {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
211 {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
212 {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
213 {"rescheduleonerror", store_yesno, ITEM(res_job.RescheduleOnError), 1, ITEM_DEFAULT, 0},
214 {"rescheduleinterval", store_time, ITEM(res_job.RescheduleInterval), 0, ITEM_DEFAULT, 60 * 30},
215 {"rescheduletimes", store_pint, ITEM(res_job.RescheduleTimes), 0, 0, 0},
216 {NULL, NULL, NULL, 0, 0, 0}
221 * name handler value code flags default_value
223 static struct res_items fs_items[] = {
224 {"name", store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
225 {"description", store_str, ITEM(res_fs.hdr.desc), 0, 0, 0},
226 {"include", store_inc, NULL, 0, 0, 0},
227 {"finclude", store_finc, NULL, 0, ITEM_NO_EQUALS, 0},
228 {"exclude", store_inc, NULL, 1, 0, 0},
229 {"fexclude", store_finc, NULL, 1, ITEM_NO_EQUALS, 0},
230 {NULL, NULL, NULL, 0, 0, 0}
233 /* Schedule -- see run_conf.c */
236 * name handler value code flags default_value
238 static struct res_items sch_items[] = {
239 {"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
240 {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
241 {"run", store_run, ITEM(res_sch.run), 0, 0, 0},
242 {NULL, NULL, NULL, 0, 0, 0}
245 /* Group resource -- not implemented
247 * name handler value code flags default_value
249 static struct res_items group_items[] = {
250 {"name", store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
251 {"description", store_str, ITEM(res_group.hdr.desc), 0, 0, 0},
252 {NULL, NULL, NULL, 0, 0, 0}
257 * name handler value code flags default_value
259 static struct res_items pool_items[] = {
260 {"name", store_name, ITEM(res_pool.hdr.name), 0, ITEM_REQUIRED, 0},
261 {"description", store_str, ITEM(res_pool.hdr.desc), 0, 0, 0},
262 {"pooltype", store_strname, ITEM(res_pool.pool_type), 0, ITEM_REQUIRED, 0},
263 {"labelformat", store_strname, ITEM(res_pool.label_format), 0, 0, 0},
264 {"cleaningprefix", store_strname, ITEM(res_pool.cleaning_prefix), 0, 0, 0},
265 {"usecatalog", store_yesno, ITEM(res_pool.use_catalog), 1, ITEM_DEFAULT, 1},
266 {"usevolumeonce", store_yesno, ITEM(res_pool.use_volume_once), 1, 0, 0},
267 {"recycleoldestvolume", store_yesno, ITEM(res_pool.recycle_oldest_volume), 1, 0, 0},
268 {"maximumvolumes", store_pint, ITEM(res_pool.max_volumes), 0, 0, 0},
269 {"maximumvolumejobs", store_pint, ITEM(res_pool.MaxVolJobs), 0, 0, 0},
270 {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles), 0, 0, 0},
271 {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes), 0, 0, 0},
272 {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT, 1},
273 {"catalogfiles", store_yesno, ITEM(res_pool.catalog_files), 1, ITEM_DEFAULT, 1},
274 {"volumeretention", store_time, ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
275 {"volumeuseduration", store_time, ITEM(res_pool.VolUseDuration),0, 0, 0},
276 {"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
277 {"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
278 {NULL, NULL, NULL, 0, 0, 0}
283 * name handler value code flags default_value
285 static struct res_items counter_items[] = {
286 {"name", store_name, ITEM(res_counter.hdr.name), 0, ITEM_REQUIRED, 0},
287 {"description", store_str, ITEM(res_counter.hdr.desc), 0, 0, 0},
288 {"minimum", store_int, ITEM(res_counter.MinValue), 0, ITEM_DEFAULT, 0},
289 {"maximum", store_pint, ITEM(res_counter.MaxValue), 0, ITEM_DEFAULT, INT32_MAX},
290 {"wrapcounter", store_res, ITEM(res_counter.WrapCounter), R_COUNTER, 0, 0},
291 {"catalog", store_res, ITEM(res_counter.Catalog), R_CATALOG, 0, 0},
292 {NULL, NULL, NULL, 0, 0, 0}
296 /* Message resource */
297 extern struct res_items msgs_items[];
300 * This is the master resource definition.
301 * It must have one item for each of the resources.
303 * name items rcode res_head
305 struct s_res resources[] = {
306 {"director", dir_items, R_DIRECTOR, NULL},
307 {"console", con_items, R_CONSOLE, NULL},
308 {"client", cli_items, R_CLIENT, NULL},
309 {"job", job_items, R_JOB, NULL},
310 {"storage", store_items, R_STORAGE, NULL},
311 {"catalog", cat_items, R_CATALOG, NULL},
312 {"schedule", sch_items, R_SCHEDULE, NULL},
313 {"fileset", fs_items, R_FILESET, NULL},
314 {"group", group_items, R_GROUP, NULL},
315 {"pool", pool_items, R_POOL, NULL},
316 {"messages", msgs_items, R_MSGS, NULL},
317 {"counter", counter_items, R_COUNTER, NULL},
318 {NULL, NULL, 0, NULL}
322 /* Keywords (RHS) permitted in Job Level records
324 * level_name level job_type
326 struct s_jl joblevels[] = {
327 {"Full", L_FULL, JT_BACKUP},
328 {"Base", L_BASE, JT_BACKUP},
329 {"Incremental", L_INCREMENTAL, JT_BACKUP},
330 {"Differential", L_DIFFERENTIAL, JT_BACKUP},
331 {"Since", L_SINCE, JT_BACKUP},
332 {"Catalog", L_VERIFY_CATALOG, JT_VERIFY},
333 {"Initcatalog", L_VERIFY_INIT, JT_VERIFY},
334 {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG, JT_VERIFY},
335 {"Data", L_VERIFY_DATA, JT_VERIFY},
339 /* Keywords (RHS) permitted in Job type records
343 struct s_jt jobtypes[] = {
344 {"backup", JT_BACKUP},
346 {"verify", JT_VERIFY},
347 {"restore", JT_RESTORE},
352 /* Keywords (RHS) permitted in Backup and Verify records */
353 static struct s_kw BakVerFields[] = {
360 /* Keywords (RHS) permitted in Restore records */
361 static struct s_kw RestoreFields[] = {
364 {"jobid", 'J'}, /* JobId to restore */
365 {"where", 'W'}, /* root of restore */
366 {"replace", 'R'}, /* replacement options */
367 {"bootstrap", 'B'}, /* bootstrap file */
371 /* Options permitted in Restore replace= */
372 struct s_kw ReplaceOptions[] = {
373 {"always", REPLACE_ALWAYS},
374 {"ifnewer", REPLACE_IFNEWER},
375 {"ifolder", REPLACE_IFOLDER},
376 {"never", REPLACE_NEVER},
380 char *level_to_str(int level)
383 static char level_no[30];
384 char *str = level_no;
386 sprintf(level_no, "%d", level); /* default if not found */
387 for (i=0; joblevels[i].level_name; i++) {
388 if (level == joblevels[i].level) {
389 str = joblevels[i].level_name;
396 /* Dump contents of resource */
397 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
399 URES *res = (URES *)reshdr;
401 char ed1[30], ed2[30];
404 sendit(sock, "No %s resource defined\n", res_to_str(type));
407 if (type < 0) { /* no recursion */
413 sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n",
414 reshdr->name, res->res_dir.MaxConcurrentJobs,
415 edit_uint64(res->res_dir.FDConnectTimeout, ed1),
416 edit_uint64(res->res_dir.SDConnectTimeout, ed2));
417 if (res->res_dir.query_file) {
418 sendit(sock, " query_file=%s\n", res->res_dir.query_file);
420 if (res->res_dir.messages) {
421 sendit(sock, " --> ");
422 dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
426 sendit(sock, "Console: name=%s SSL=%d\n",
427 res->res_con.hdr.name, res->res_con.enable_ssl);
430 sendit(sock, "Counter: name=%s min=%d max=%d\n",
431 res->res_counter.hdr.name, res->res_counter.MinValue,
432 res->res_counter.MaxValue);
433 if (res->res_counter.Catalog) {
434 sendit(sock, " --> ");
435 dump_resource(-R_CATALOG, (RES *)res->res_counter.Catalog, sendit, sock);
437 if (res->res_counter.WrapCounter) {
438 sendit(sock, " --> ");
439 dump_resource(-R_COUNTER, (RES *)res->res_counter.WrapCounter, sendit, sock);
446 sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
447 res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
448 res->res_client.MaxConcurrentJobs);
449 sendit(sock, " JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
450 res->res_client.JobRetention, res->res_client.FileRetention,
451 res->res_client.AutoPrune);
452 if (res->res_client.catalog) {
453 sendit(sock, " --> ");
454 dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
458 sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
459 DeviceName=%s MediaType=%s\n",
460 res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
461 res->res_store.MaxConcurrentJobs,
462 res->res_store.dev_name, res->res_store.media_type);
465 sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
467 res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
468 res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
471 sendit(sock, "Job: name=%s JobType=%d level=%s MaxJobs=%u\n",
472 res->res_job.hdr.name, res->res_job.JobType,
473 level_to_str(res->res_job.level), res->res_job.MaxConcurrentJobs);
474 sendit(sock, " Resched=%d Times=%d Interval=%s\n",
475 res->res_job.RescheduleOnError, res->res_job.RescheduleTimes,
476 edit_uint64_with_commas(res->res_job.RescheduleInterval, ed1));
477 if (res->res_job.client) {
478 sendit(sock, " --> ");
479 dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
481 if (res->res_job.fileset) {
482 sendit(sock, " --> ");
483 dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
485 if (res->res_job.schedule) {
486 sendit(sock, " --> ");
487 dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
489 if (res->res_job.RestoreWhere) {
490 sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
492 if (res->res_job.RestoreBootstrap) {
493 sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
495 if (res->res_job.RunBeforeJob) {
496 sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
498 if (res->res_job.RunAfterJob) {
499 sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
501 if (res->res_job.WriteBootstrap) {
502 sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
504 if (res->res_job.storage) {
505 sendit(sock, " --> ");
506 dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
508 if (res->res_job.pool) {
509 sendit(sock, " --> ");
510 dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
512 sendit(sock, "!!! No Pool resource\n");
514 if (res->res_job.messages) {
515 sendit(sock, " --> ");
516 dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
520 sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
521 for (int i=0; i<res->res_fs.num_includes; i++) {
522 INCEXE *incexe = res->res_fs.include_items[i];
523 for (int j=0; j<incexe->num_names; j++) {
524 sendit(sock, " Inc: %s\n", incexe->name_list[j]);
527 for (int i=0; i<res->res_fs.num_excludes; i++) {
528 INCEXE *incexe = res->res_fs.exclude_items[i];
529 for (int j=0; j<incexe->num_names; j++) {
530 sendit(sock, " Exc: %s\n", incexe->name_list[j]);
535 if (res->res_sch.run) {
537 RUN *run = res->res_sch.run;
538 char buf[1000], num[10];
539 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
544 sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
545 strcpy(buf, " hour=");
546 for (i=0; i<24; i++) {
547 if (bit_is_set(i, run->hour)) {
548 sprintf(num, "%d ", i);
554 strcpy(buf, " mday=");
555 for (i=0; i<31; i++) {
556 if (bit_is_set(i, run->mday)) {
557 sprintf(num, "%d ", i+1);
563 strcpy(buf, " month=");
564 for (i=0; i<12; i++) {
565 if (bit_is_set(i, run->month)) {
566 sprintf(num, "%d ", i+1);
572 strcpy(buf, " wday=");
573 for (i=0; i<7; i++) {
574 if (bit_is_set(i, run->wday)) {
575 sprintf(num, "%d ", i+1);
581 strcpy(buf, " wpos=");
582 for (i=0; i<5; i++) {
583 if (bit_is_set(i, run->wpos)) {
584 sprintf(num, "%d ", i+1);
590 sendit(sock, " mins=%d\n", run->minute);
592 sendit(sock, " --> ");
593 dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
596 sendit(sock, " --> ");
597 dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
600 sendit(sock, " --> ");
601 dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
603 /* If another Run record is chained in, go print it */
609 sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
613 sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
616 sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
617 res->res_pool.pool_type);
618 sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
619 res->res_pool.use_catalog, res->res_pool.use_volume_once,
620 res->res_pool.accept_any_volume, res->res_pool.catalog_files);
621 sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
622 res->res_pool.max_volumes, res->res_pool.AutoPrune,
623 res->res_pool.VolRetention);
624 sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
625 NPRT(res->res_pool.label_format));
626 sendit(sock, " CleaningPrefix=%s\n",
627 NPRT(res->res_pool.cleaning_prefix));
628 sendit(sock, " recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
629 res->res_pool.recycle_oldest_volume,
630 res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
633 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
634 if (res->res_msgs.mail_cmd)
635 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
636 if (res->res_msgs.operator_cmd)
637 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
640 sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
643 if (recurse && res->res_dir.hdr.next) {
644 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
649 * Free all the members of an INCEXE structure
651 static void free_incexe(INCEXE *incexe)
653 for (int i=0; i<incexe->num_names; i++) {
654 free(incexe->name_list[i]);
656 if (incexe->name_list) {
657 free(incexe->name_list);
659 for (int i=0; i<incexe->num_opts; i++) {
660 FOPTS *fopt = incexe->opts_list[i];
664 for (int j=0; j<fopt->num_base; j++) {
665 free(fopt->base_list[j]);
667 if (fopt->base_list) {
668 free(fopt->base_list);
672 if (incexe->opts_list) {
673 free(incexe->opts_list);
679 * Free memory of resource.
680 * NB, we don't need to worry about freeing any references
681 * to other resources as they will be freed when that
682 * resource chain is traversed. Mainly we worry about freeing
683 * allocated strings (names).
685 void free_resource(int type)
690 int rindex = type - r_first;
692 res = (URES *)resources[rindex].res_head;
697 /* common stuff -- free the resource name and description */
698 nres = (RES *)res->res_dir.hdr.next;
699 if (res->res_dir.hdr.name) {
700 free(res->res_dir.hdr.name);
702 if (res->res_dir.hdr.desc) {
703 free(res->res_dir.hdr.desc);
708 if (res->res_dir.working_directory) {
709 free(res->res_dir.working_directory);
711 if (res->res_dir.pid_directory) {
712 free(res->res_dir.pid_directory);
714 if (res->res_dir.subsys_directory) {
715 free(res->res_dir.subsys_directory);
717 if (res->res_dir.password) {
718 free(res->res_dir.password);
720 if (res->res_dir.query_file) {
721 free(res->res_dir.query_file);
723 if (res->res_dir.DIRaddr) {
724 free(res->res_dir.DIRaddr);
730 if (res->res_con.password) {
731 free(res->res_con.password);
735 if (res->res_client.address) {
736 free(res->res_client.address);
738 if (res->res_client.password) {
739 free(res->res_client.password);
743 if (res->res_store.address) {
744 free(res->res_store.address);
746 if (res->res_store.password) {
747 free(res->res_store.password);
749 if (res->res_store.media_type) {
750 free(res->res_store.media_type);
752 if (res->res_store.dev_name) {
753 free(res->res_store.dev_name);
757 if (res->res_cat.db_address) {
758 free(res->res_cat.db_address);
760 if (res->res_cat.db_socket) {
761 free(res->res_cat.db_socket);
763 if (res->res_cat.db_user) {
764 free(res->res_cat.db_user);
766 if (res->res_cat.db_name) {
767 free(res->res_cat.db_name);
769 if (res->res_cat.db_password) {
770 free(res->res_cat.db_password);
774 if ((num=res->res_fs.num_includes)) {
776 free_incexe(res->res_fs.include_items[num]);
778 free(res->res_fs.include_items);
780 res->res_fs.num_includes = 0;
781 if ((num=res->res_fs.num_excludes)) {
783 free_incexe(res->res_fs.exclude_items[num]);
785 free(res->res_fs.exclude_items);
787 res->res_fs.num_excludes = 0;
790 if (res->res_pool.pool_type) {
791 free(res->res_pool.pool_type);
793 if (res->res_pool.label_format) {
794 free(res->res_pool.label_format);
796 if (res->res_pool.cleaning_prefix) {
797 free(res->res_pool.cleaning_prefix);
801 if (res->res_sch.run) {
803 nrun = res->res_sch.run;
812 if (res->res_job.RestoreWhere) {
813 free(res->res_job.RestoreWhere);
815 if (res->res_job.RestoreBootstrap) {
816 free(res->res_job.RestoreBootstrap);
818 if (res->res_job.WriteBootstrap) {
819 free(res->res_job.WriteBootstrap);
821 if (res->res_job.RunBeforeJob) {
822 free(res->res_job.RunBeforeJob);
824 if (res->res_job.RunAfterJob) {
825 free(res->res_job.RunAfterJob);
829 if (res->res_msgs.mail_cmd)
830 free(res->res_msgs.mail_cmd);
831 if (res->res_msgs.operator_cmd)
832 free(res->res_msgs.operator_cmd);
833 free_msgs_res((MSGS *)res); /* free message resource */
839 printf("Unknown resource type %d in free_resource.\n", type);
841 /* Common stuff again -- free the resource, recurse to next one */
845 resources[rindex].res_head = nres;
852 * Save the new resource by chaining it into the head list for
853 * the resource. If this is pass 2, we update any resource
854 * pointers because they may not have been defined until
857 void save_resource(int type, struct res_items *items, int pass)
860 int rindex = type - r_first;
865 * Ensure that all required items are present
867 for (i=0; items[i].name; i++) {
868 if (items[i].flags & ITEM_REQUIRED) {
869 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
870 Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
871 items[i].name, resources[rindex]);
874 /* If this triggers, take a look at lib/parse_conf.h */
875 if (i >= MAX_RES_ITEMS) {
876 Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
880 /* During pass 2 in each "store" routine, we looked up pointers
881 * to all the resources referrenced in the current resource, now we
882 * must copy their addresses from the static record to the allocated
887 /* Resources not containing a resource */
897 /* Resources containing another resource */
899 if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
900 Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
902 res->res_dir.messages = res_all.res_dir.messages;
905 if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
906 Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
908 res->res_job.messages = res_all.res_job.messages;
909 res->res_job.schedule = res_all.res_job.schedule;
910 res->res_job.client = res_all.res_job.client;
911 res->res_job.fileset = res_all.res_job.fileset;
912 res->res_job.storage = res_all.res_job.storage;
913 res->res_job.pool = res_all.res_job.pool;
914 if (res->res_job.JobType == 0) {
915 Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
917 if (res->res_job.level != 0) {
919 for (i=0; joblevels[i].level_name; i++) {
920 if (joblevels[i].level == res->res_job.level &&
921 joblevels[i].job_type == res->res_job.JobType) {
927 Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n",
928 res_all.res_dir.hdr.name);
933 if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
934 Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
936 res->res_counter.Catalog = res_all.res_counter.Catalog;
937 res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
941 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
942 Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
944 res->res_client.catalog = res_all.res_client.catalog;
947 /* Schedule is a bit different in that it contains a RUN record
948 * chain which isn't a "named" resource. This chain was linked
949 * in by run_conf.c during pass 2, so here we jam the pointer
950 * into the Schedule resource.
952 if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
953 Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
955 res->res_sch.run = res_all.res_sch.run;
958 Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
962 /* Note, the resource name was already saved during pass 1,
963 * so here, we can just release it.
965 if (res_all.res_dir.hdr.name) {
966 free(res_all.res_dir.hdr.name);
967 res_all.res_dir.hdr.name = NULL;
969 if (res_all.res_dir.hdr.desc) {
970 free(res_all.res_dir.hdr.desc);
971 res_all.res_dir.hdr.desc = NULL;
976 /* The following code is only executed for pass 1 */
979 size = sizeof(DIRRES);
982 size = sizeof(CONRES);
985 size =sizeof(CLIENT);
988 size = sizeof(STORE);
997 size = sizeof(FILESET);
1000 size = sizeof(SCHED);
1003 size = sizeof(GROUP);
1006 size = sizeof(POOL);
1009 size = sizeof(MSGS);
1012 size = sizeof(COUNTER);
1015 printf("Unknown resource type %d in save_resrouce.\n", type);
1022 res = (URES *)malloc(size);
1023 memcpy(res, &res_all, size);
1024 if (!resources[rindex].res_head) {
1025 resources[rindex].res_head = (RES *)res; /* store first entry */
1026 Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1027 res->res_dir.hdr.name, rindex);
1030 /* Add new res to end of chain */
1031 for (next=resources[rindex].res_head; next->next; next=next->next)
1033 next->next = (RES *)res;
1034 Dmsg3(200, "Inserting %s res: %s index=%d\n", res_to_str(type),
1035 res->res_dir.hdr.name, rindex);
1041 * Store JobType (backup, verify, restore)
1044 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1048 token = lex_get_token(lc, T_NAME);
1049 /* Store the type both pass 1 and pass 2 */
1050 for (i=0; jobtypes[i].type_name; i++) {
1051 if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1052 ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1058 scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1061 set_bit(index, res_all.hdr.item_present);
1065 * Store Job Level (Full, Incremental, ...)
1068 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1072 token = lex_get_token(lc, T_NAME);
1073 /* Store the level pass 2 so that type is defined */
1074 for (i=0; joblevels[i].level_name; i++) {
1075 if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1076 ((JOB *)(item->value))->level = joblevels[i].level;
1082 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1085 set_bit(index, res_all.hdr.item_present);
1088 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1091 token = lex_get_token(lc, T_NAME);
1092 /* Scan Replacement options */
1093 for (i=0; ReplaceOptions[i].name; i++) {
1094 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1095 *(int *)(item->value) = ReplaceOptions[i].token;
1101 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1104 set_bit(index, res_all.hdr.item_present);
1108 * Store backup/verify info for Job record
1110 * Note, this code is used for both BACKUP and VERIFY jobs
1112 * Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1114 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1118 int options = lc->options;
1120 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1123 ((JOB *)(item->value))->JobType = item->code;
1124 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1127 Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1129 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1130 scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1132 Dmsg1(190, "Got keyword: %s\n", lc->str);
1134 for (i=0; BakVerFields[i].name; i++) {
1135 if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1137 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1138 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1140 token = lex_get_token(lc, T_NAME);
1141 Dmsg1(190, "Got value: %s\n", lc->str);
1142 switch (BakVerFields[i].token) {
1144 /* Find Client Resource */
1146 res = GetResWithName(R_CLIENT, lc->str);
1148 scan_err1(lc, "Could not find specified Client Resource: %s",
1151 res_all.res_job.client = (CLIENT *)res;
1155 /* Find FileSet Resource */
1157 res = GetResWithName(R_FILESET, lc->str);
1159 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1162 res_all.res_job.fileset = (FILESET *)res;
1167 for (i=0; joblevels[i].level_name; i++) {
1168 if (joblevels[i].job_type == item->code &&
1169 strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1170 ((JOB *)(item->value))->level = joblevels[i].level;
1176 scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1181 } /* end if strcmp() */
1184 scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1187 lc->options = options; /* reset original options */
1188 set_bit(index, res_all.hdr.item_present);
1192 * Store restore info for Job record
1194 * Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1197 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1201 int options = lc->options;
1203 lc->options |= LOPT_NO_IDENT; /* make spaces significant */
1205 Dmsg0(190, "Enter store_restore()\n");
1207 ((JOB *)(item->value))->JobType = item->code;
1208 while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1211 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1212 scan_err1(lc, "expected a name, got: %s", lc->str);
1215 for (i=0; RestoreFields[i].name; i++) {
1216 Dmsg1(190, "Restore kw=%s\n", lc->str);
1217 if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1219 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1220 scan_err1(lc, "Expected an equals, got: %s", lc->str);
1222 token = lex_get_token(lc, T_ALL);
1223 Dmsg1(190, "Restore value=%s\n", lc->str);
1224 switch (RestoreFields[i].token) {
1227 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1228 scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1231 res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1235 /* Find Client Resource */
1237 res = GetResWithName(R_CLIENT, lc->str);
1239 scan_err1(lc, "Could not find specified Client Resource: %s",
1242 res_all.res_job.client = (CLIENT *)res;
1246 /* Find FileSet Resource */
1248 res = GetResWithName(R_FILESET, lc->str);
1250 scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1253 res_all.res_job.fileset = (FILESET *)res;
1258 if (token != T_NUMBER) {
1259 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1262 res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1263 Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1265 scan_err1(lc, "expected an integer number, got: %s", lc->str);
1270 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1271 scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1274 res_all.res_job.RestoreWhere = bstrdup(lc->str);
1278 /* Replacement options */
1279 if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1280 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1282 /* Fix to scan Replacement options */
1283 for (i=0; ReplaceOptions[i].name; i++) {
1284 if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1285 ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1291 scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1296 } /* end if strcmp() */
1299 scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1302 lc->options = options; /* reset original options */
1303 set_bit(index, res_all.hdr.item_present);