2 * Configuration file parser for Bacula Storage daemon
4 * Kern Sibbald, March MM
10 Copyright (C) 2000-2004 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 extern int debug_level;
35 /* First and last resource ids */
36 int r_first = R_FIRST;
38 static RES *sres_head[R_LAST - R_FIRST + 1];
39 RES **res_head = sres_head;
42 /* Forward referenced subroutines */
44 /* We build the current resource here statically,
45 * then move it to dynamic memory */
47 int res_all_size = sizeof(res_all);
49 /* Definition of records permitted within each
50 * resource with the routine to process the record
54 /* Globals for the Storage daemon. */
55 static RES_ITEM store_items[] = {
56 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
57 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
58 {"sdaddress", store_addresses_address, ITEM(res_store.sdaddrs), 0, ITEM_DEFAULT, 9103},
59 {"sdaddresses", store_addresses, ITEM(res_store.sdaddrs), 0, ITEM_DEFAULT, 9103},
60 {"messages", store_res, ITEM(res_store.messages), 0, R_MSGS, 0},
61 {"sdport", store_addresses_port, ITEM(res_store.sdaddrs), 0, ITEM_DEFAULT, 9103},
62 {"workingdirectory", store_dir, ITEM(res_store.working_directory), 0, ITEM_REQUIRED, 0},
63 {"piddirectory", store_dir, ITEM(res_store.pid_directory), 0, ITEM_REQUIRED, 0},
64 {"subsysdirectory", store_dir, ITEM(res_store.subsys_directory), 0, 0, 0},
65 {"requiressl", store_yesno,ITEM(res_store.require_ssl), 1, ITEM_DEFAULT, 0},
66 {"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 10},
67 {"heartbeatinterval", store_time, ITEM(res_store.heartbeat_interval), 0, ITEM_DEFAULT, 0},
68 {NULL, NULL, 0, 0, 0, 0}
72 /* Directors that can speak to the Storage daemon */
73 static RES_ITEM dir_items[] = {
74 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
75 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
76 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
77 {"enablessl", store_yesno, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
78 {"monitor", store_yesno, ITEM(res_dir.monitor), 1, ITEM_DEFAULT, 0},
79 {NULL, NULL, 0, 0, 0, 0}
82 /* Device definition */
83 static RES_ITEM dev_items[] = {
84 {"name", store_name, ITEM(res_dev.hdr.name), 0, ITEM_REQUIRED, 0},
85 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
86 {"mediatype", store_strname,ITEM(res_dev.media_type), 0, ITEM_REQUIRED, 0},
87 {"archivedevice", store_strname,ITEM(res_dev.device_name), 0, ITEM_REQUIRED, 0},
88 {"hardwareendoffile", store_yesno, ITEM(res_dev.cap_bits), CAP_EOF, ITEM_DEFAULT, 1},
89 {"hardwareendofmedium", store_yesno, ITEM(res_dev.cap_bits), CAP_EOM, ITEM_DEFAULT, 1},
90 {"backwardspacerecord", store_yesno, ITEM(res_dev.cap_bits), CAP_BSR, ITEM_DEFAULT, 1},
91 {"backwardspacefile", store_yesno, ITEM(res_dev.cap_bits), CAP_BSF, ITEM_DEFAULT, 1},
92 {"bsfateom", store_yesno, ITEM(res_dev.cap_bits), CAP_BSFATEOM, ITEM_DEFAULT, 0},
93 {"twoeof", store_yesno, ITEM(res_dev.cap_bits), CAP_TWOEOF, ITEM_DEFAULT, 0},
94 {"forwardspacerecord", store_yesno, ITEM(res_dev.cap_bits), CAP_FSR, ITEM_DEFAULT, 1},
95 {"forwardspacefile", store_yesno, ITEM(res_dev.cap_bits), CAP_FSF, ITEM_DEFAULT, 1},
96 {"fastforwardspacefile", store_yesno, ITEM(res_dev.cap_bits), CAP_FASTFSF, ITEM_DEFAULT, 1},
97 {"removablemedia", store_yesno, ITEM(res_dev.cap_bits), CAP_REM, ITEM_DEFAULT, 1},
98 {"randomaccess", store_yesno, ITEM(res_dev.cap_bits), CAP_RACCESS, 0, 0},
99 {"automaticmount", store_yesno, ITEM(res_dev.cap_bits), CAP_AUTOMOUNT, ITEM_DEFAULT, 0},
100 {"labelmedia", store_yesno, ITEM(res_dev.cap_bits), CAP_LABEL, ITEM_DEFAULT, 0},
101 {"alwaysopen", store_yesno, ITEM(res_dev.cap_bits), CAP_ALWAYSOPEN, ITEM_DEFAULT, 1},
102 {"autochanger", store_yesno, ITEM(res_dev.cap_bits), CAP_AUTOCHANGER, ITEM_DEFAULT, 0},
103 {"closeonpoll", store_yesno, ITEM(res_dev.cap_bits), CAP_CLOSEONPOLL, ITEM_DEFAULT, 0},
104 {"blockpositioning", store_yesno, ITEM(res_dev.cap_bits), CAP_POSITIONBLOCKS, ITEM_DEFAULT, 1},
105 {"usemtiocget", store_yesno, ITEM(res_dev.cap_bits), CAP_MTIOCGET, ITEM_DEFAULT, 1},
106 {"changerdevice", store_strname,ITEM(res_dev.changer_name), 0, 0, 0},
107 {"changercommand", store_strname,ITEM(res_dev.changer_command), 0, 0, 0},
108 {"alertcommand", store_strname,ITEM(res_dev.alert_command), 0, 0, 0},
109 {"maximumchangerwait", store_pint, ITEM(res_dev.max_changer_wait), 0, ITEM_DEFAULT, 5 * 60},
110 {"maximumopenwait", store_pint, ITEM(res_dev.max_open_wait), 0, ITEM_DEFAULT, 5 * 60},
111 {"maximumopenvolumes", store_pint, ITEM(res_dev.max_open_vols), 0, ITEM_DEFAULT, 1},
112 {"maximumnetworkbuffersize", store_pint, ITEM(res_dev.max_network_buffer_size), 0, 0, 0},
113 {"volumepollinterval", store_time, ITEM(res_dev.vol_poll_interval), 0, 0, 0},
114 {"offlineonunmount", store_yesno, ITEM(res_dev.cap_bits), CAP_OFFLINEUNMOUNT, ITEM_DEFAULT, 0},
115 {"maximumrewindwait", store_pint, ITEM(res_dev.max_rewind_wait), 0, ITEM_DEFAULT, 5 * 60},
116 {"minimumblocksize", store_pint, ITEM(res_dev.min_block_size), 0, 0, 0},
117 {"maximumblocksize", store_pint, ITEM(res_dev.max_block_size), 0, 0, 0},
118 {"maximumvolumesize", store_size, ITEM(res_dev.max_volume_size), 0, 0, 0},
119 {"maximumfilesize", store_size, ITEM(res_dev.max_file_size), 0, ITEM_DEFAULT, 1000000000},
120 {"volumecapacity", store_size, ITEM(res_dev.volume_capacity), 0, 0, 0},
121 {"spooldirectory", store_dir, ITEM(res_dev.spool_directory), 0, 0, 0},
122 {"maximumspoolsize", store_size, ITEM(res_dev.max_spool_size), 0, 0, 0},
123 {"maximumjobspoolsize", store_size, ITEM(res_dev.max_job_spool_size), 0, 0, 0},
124 {"driveindex", store_pint, ITEM(res_dev.drive_index), 0, 0, 0},
125 {NULL, NULL, 0, 0, 0, 0}
128 // {"mountanonymousvolumes", store_yesno, ITEM(res_dev.cap_bits), CAP_ANONVOLS, ITEM_DEFAULT, 0},
131 /* Message resource */
132 extern RES_ITEM msgs_items[];
135 /* This is the master resource definition */
136 RES_TABLE resources[] = {
137 {"director", dir_items, R_DIRECTOR},
138 {"storage", store_items, R_STORAGE},
139 {"device", dev_items, R_DEVICE},
140 {"messages", msgs_items, R_MSGS},
147 /* Dump contents of resource */
148 void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock)
150 URES *res = (URES *)reshdr;
155 sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), res_to_str(type), type);
158 sendit(sock, "dump_resource type=%d\n", type);
159 if (type < 0) { /* no recursion */
165 sendit(sock, "Director: name=%s\n", res->res_dir.hdr.name);
168 sendit(sock, "Storage: name=%s SDaddr=%s SDport=%d SDDport=%d HB=%s\n",
169 res->res_store.hdr.name,
170 NPRT(get_first_address(res->res_store.sdaddrs, buf, sizeof(buf))),
171 get_first_port_host_order(res->res_store.sdaddrs),
172 get_first_port_host_order(res->res_store.sddaddrs),
173 edit_utime(res->res_store.heartbeat_interval, buf, sizeof(buf)));
174 foreach_dlist(p, res->res_store.sdaddrs) {
175 sendit(sock, " SDaddr=%s SDport=%d\n",
176 p->get_address(buf, sizeof(buf)), p->get_port_host_order());
178 foreach_dlist(p, res->res_store.sddaddrs) {
179 sendit(sock, " SDDaddr=%s SDDport=%d\n",
180 p->get_address(buf, sizeof(buf)), p->get_port_host_order());
184 sendit(sock, "Device: name=%s MediaType=%s Device=%s\n",
185 res->res_dev.hdr.name,
186 res->res_dev.media_type, res->res_dev.device_name);
187 sendit(sock, " rew_wait=%d min_bs=%d max_bs=%d\n",
188 res->res_dev.max_rewind_wait, res->res_dev.min_block_size,
189 res->res_dev.max_block_size);
190 sendit(sock, " max_jobs=%d max_files=%" lld " max_size=%" lld "\n",
191 res->res_dev.max_volume_jobs, res->res_dev.max_volume_files,
192 res->res_dev.max_volume_size);
193 sendit(sock, " max_file_size=%" lld " capacity=%" lld "\n",
194 res->res_dev.max_file_size, res->res_dev.volume_capacity);
195 sendit(sock, " spool_directory=%s\n", NPRT(res->res_dev.spool_directory));
196 sendit(sock, " max_spool_size=%" lld " max_job_spool_size=%" lld "\n",
197 res->res_dev.max_spool_size, res->res_dev.max_job_spool_size);
199 if (res->res_dev.cap_bits & CAP_EOF) {
200 bstrncat(buf, "CAP_EOF ", sizeof(buf));
202 if (res->res_dev.cap_bits & CAP_BSR) {
203 bstrncat(buf, "CAP_BSR ", sizeof(buf));
205 if (res->res_dev.cap_bits & CAP_BSF) {
206 bstrncat(buf, "CAP_BSF ", sizeof(buf));
208 if (res->res_dev.cap_bits & CAP_FSR) {
209 bstrncat(buf, "CAP_FSR ", sizeof(buf));
211 if (res->res_dev.cap_bits & CAP_FSF) {
212 bstrncat(buf, "CAP_FSF ", sizeof(buf));
214 if (res->res_dev.cap_bits & CAP_EOM) {
215 bstrncat(buf, "CAP_EOM ", sizeof(buf));
217 if (res->res_dev.cap_bits & CAP_REM) {
218 bstrncat(buf, "CAP_REM ", sizeof(buf));
220 if (res->res_dev.cap_bits & CAP_RACCESS) {
221 bstrncat(buf, "CAP_RACCESS ", sizeof(buf));
223 if (res->res_dev.cap_bits & CAP_AUTOMOUNT) {
224 bstrncat(buf, "CAP_AUTOMOUNT ", sizeof(buf));
226 if (res->res_dev.cap_bits & CAP_LABEL) {
227 bstrncat(buf, "CAP_LABEL ", sizeof(buf));
229 if (res->res_dev.cap_bits & CAP_ANONVOLS) {
230 bstrncat(buf, "CAP_ANONVOLS ", sizeof(buf));
232 if (res->res_dev.cap_bits & CAP_ALWAYSOPEN) {
233 bstrncat(buf, "CAP_ALWAYSOPEN ", sizeof(buf));
235 bstrncat(buf, "\n", sizeof(buf));
239 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
240 if (res->res_msgs.mail_cmd)
241 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
242 if (res->res_msgs.operator_cmd)
243 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
246 sendit(sock, _("Warning: unknown resource type %d\n"), type);
249 if (recurse && res->res_dir.hdr.next)
250 dump_resource(type, (RES *)res->res_dir.hdr.next, sendit, sock);
254 * Free memory of resource.
255 * NB, we don't need to worry about freeing any references
256 * to other resources as they will be freed when that
257 * resource chain is traversed. Mainly we worry about freeing
258 * allocated strings (names).
260 void free_resource(RES *sres, int type)
263 URES *res = (URES *)sres;
268 /* common stuff -- free the resource name */
269 nres = (RES *)res->res_dir.hdr.next;
270 if (res->res_dir.hdr.name) {
271 free(res->res_dir.hdr.name);
273 if (res->res_dir.hdr.desc) {
274 free(res->res_dir.hdr.desc);
280 if (res->res_dir.password) {
281 free(res->res_dir.password);
283 if (res->res_dir.address) {
284 free(res->res_dir.address);
288 if (res->res_store.sdaddrs) {
289 free_addresses(res->res_store.sdaddrs);
291 if (res->res_store.sddaddrs) {
292 free_addresses(res->res_store.sddaddrs);
294 if (res->res_store.working_directory) {
295 free(res->res_store.working_directory);
297 if (res->res_store.pid_directory) {
298 free(res->res_store.pid_directory);
300 if (res->res_store.subsys_directory) {
301 free(res->res_store.subsys_directory);
305 if (res->res_dev.media_type) {
306 free(res->res_dev.media_type);
308 if (res->res_dev.device_name) {
309 free(res->res_dev.device_name);
311 if (res->res_dev.changer_name) {
312 free(res->res_dev.changer_name);
314 if (res->res_dev.changer_command) {
315 free(res->res_dev.changer_command);
317 if (res->res_dev.alert_command) {
318 free(res->res_dev.alert_command);
320 if (res->res_dev.spool_directory) {
321 free(res->res_dev.spool_directory);
325 if (res->res_msgs.mail_cmd) {
326 free(res->res_msgs.mail_cmd);
328 if (res->res_msgs.operator_cmd) {
329 free(res->res_msgs.operator_cmd);
331 free_msgs_res((MSGS *)res); /* free message resource */
335 Dmsg1(0, "Unknown resource type %d\n", type);
338 /* Common stuff again -- free the resource, recurse to next one */
343 free_resource(nres, type);
347 /* Save the new resource by chaining it into the head list for
348 * the resource. If this is pass 2, we update any resource
349 * pointers (currently only in the Job resource).
351 void save_resource(int type, RES_ITEM *items, int pass)
354 int rindex = type - r_first;
359 * Ensure that all required items are present
361 for (i=0; items[i].name; i++) {
362 if (items[i].flags & ITEM_REQUIRED) {
363 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
364 Emsg2(M_ERROR_TERM, 0, _("\"%s\" item is required in \"%s\" resource, but not found.\n"),
365 items[i].name, resources[rindex]);
368 /* If this triggers, take a look at lib/parse_conf.h */
369 if (i >= MAX_RES_ITEMS) {
370 Emsg1(M_ERROR_TERM, 0, _("Too many items in \"%s\" resource\n"), resources[rindex]);
374 /* During pass 2, we looked up pointers to all the resources
375 * referrenced in the current resource, , now we
376 * must copy their address from the static record to the allocated
381 /* Resources not containing a resource */
387 /* Resources containing a resource */
389 if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) {
390 Emsg1(M_ERROR_TERM, 0, "Cannot find Storage resource \"%s\"\n", res_all.res_dir.hdr.name);
392 res->res_store.messages = res_all.res_store.messages;
395 printf("Unknown resource type %d\n", type);
401 if (res_all.res_dir.hdr.name) {
402 free(res_all.res_dir.hdr.name);
403 res_all.res_dir.hdr.name = NULL;
405 if (res_all.res_dir.hdr.desc) {
406 free(res_all.res_dir.hdr.desc);
407 res_all.res_dir.hdr.desc = NULL;
412 /* The following code is only executed on pass 1 */
415 size = sizeof(DIRRES);
418 size = sizeof(STORES);
421 size = sizeof(DEVRES);
427 printf("Unknown resource type %d\n", type);
434 res = (URES *)malloc(size);
435 memcpy(res, &res_all, size);
436 if (!res_head[rindex]) {
437 res_head[rindex] = (RES *)res; /* store first entry */
440 /* Add new res to end of chain */
441 for (next=res_head[rindex]; next->next; next=next->next) {
442 if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
443 Emsg2(M_ERROR_TERM, 0,
444 _("Attempt to define second \"%s\" resource named \"%s\" is not permitted.\n"),
445 resources[rindex].name, res->res_dir.hdr.name);
448 next->next = (RES *)res;
449 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
450 res->res_dir.hdr.name);