2 * Configuration file parser for Bacula Storage daemon
4 * Kern Sibbald, March MM
10 Copyright (C) 2000, 2001, 2002 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 pthread_mutex_t res_mutex = PTHREAD_MUTEX_INITIALIZER;
41 /* Forward referenced subroutines */
43 /* We build the current resource here statically,
44 * then move it to dynamic memory */
46 int res_all_size = sizeof(res_all);
48 /* Definition of records permitted within each
49 * resource with the routine to process the record
53 /* Globals for the Storage daemon. */
54 static struct res_items store_items[] = {
55 {"name", store_name, ITEM(res_store.hdr.name), 0, ITEM_REQUIRED, 0},
56 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
57 {"address", store_str, ITEM(res_store.address), 0, ITEM_REQUIRED, 0},
58 {"messages", store_res, ITEM(res_store.messages), 0, R_MSGS, 0},
59 {"sdport", store_int, ITEM(res_store.SDport), 0, ITEM_REQUIRED, 0},
60 {"sddport", store_int, ITEM(res_store.SDDport), 0, 0, 0}, /* depricated */
61 {"workingdirectory", store_dir, ITEM(res_store.working_directory), 0, ITEM_REQUIRED, 0},
62 {"piddirectory", store_dir, ITEM(res_store.pid_directory), 0, ITEM_REQUIRED, 0},
63 {"subsysdirectory", store_dir, ITEM(res_store.subsys_directory), 0, ITEM_REQUIRED, 0},
64 {"maximumconcurrentjobs", store_int, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 1},
65 {NULL, NULL, 0, 0, 0, 0}
69 /* Directors that can speak to the Storage daemon */
70 static struct res_items dir_items[] = {
71 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
72 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
73 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
74 {"address", store_str, ITEM(res_dir.address), 0, 0, 0},
75 {NULL, NULL, 0, 0, 0, 0}
78 /* Device definition */
79 static struct res_items dev_items[] = {
80 {"name", store_name, ITEM(res_dev.hdr.name), 0, ITEM_REQUIRED, 0},
81 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
82 {"mediatype", store_strname,ITEM(res_dev.media_type), 0, ITEM_REQUIRED, 0},
83 {"archivedevice", store_strname,ITEM(res_dev.device_name), 0, ITEM_REQUIRED, 0},
84 {"hardwareendoffile", store_yesno, ITEM(res_dev.cap_bits), CAP_EOF, ITEM_DEFAULT, 1},
85 {"hardwareendofmedium", store_yesno, ITEM(res_dev.cap_bits), CAP_EOM, ITEM_DEFAULT, 1},
86 {"backwardspacerecord", store_yesno, ITEM(res_dev.cap_bits), CAP_BSR, ITEM_DEFAULT, 1},
87 {"backwardspacefile", store_yesno, ITEM(res_dev.cap_bits), CAP_BSF, ITEM_DEFAULT, 1},
88 {"forwardspacerecord", store_yesno, ITEM(res_dev.cap_bits), CAP_FSR, ITEM_DEFAULT, 1},
89 {"forwardspacefile", store_yesno, ITEM(res_dev.cap_bits), CAP_FSF, ITEM_DEFAULT, 1},
90 {"removablemedia", store_yesno, ITEM(res_dev.cap_bits), CAP_REM, ITEM_DEFAULT, 1},
91 {"randomaccess", store_yesno, ITEM(res_dev.cap_bits), CAP_RACCESS, 0, 0},
92 {"automaticmount", store_yesno, ITEM(res_dev.cap_bits), CAP_AUTOMOUNT, ITEM_DEFAULT, 0},
93 {"labelmedia", store_yesno, ITEM(res_dev.cap_bits), CAP_LABEL, ITEM_DEFAULT, 0},
94 {"mountanonymousvolumes", store_yesno, ITEM(res_dev.cap_bits), CAP_ANONVOLS, ITEM_DEFAULT, 0},
95 {"alwaysopen", store_yesno, ITEM(res_dev.cap_bits), CAP_ALWAYSOPEN, ITEM_DEFAULT, 1},
96 {"maximumrewindwait", store_pint, ITEM(res_dev.max_rewind_wait), 0, ITEM_DEFAULT, 5 * 60},
97 {"minimumblocksize", store_pint, ITEM(res_dev.min_block_size), 0, 0, 0},
98 {"maximumblocksize", store_pint, ITEM(res_dev.max_block_size), 0, 0, 0},
99 {"maximumvolumejobs", store_pint, ITEM(res_dev.max_volume_jobs), 0, 0, 0},
100 {"maximumvolumefiles", store_int64, ITEM(res_dev.max_volume_files), 0, 0, 0},
101 {"maximumvolumesize", store_size, ITEM(res_dev.max_volume_size), 0, 0, 0},
102 {"maximumfilesize", store_size, ITEM(res_dev.max_file_size), 0, 0, 0},
103 {"volumecapacity", store_size, ITEM(res_dev.volume_capacity), 0, 0, 0},
104 {NULL, NULL, 0, 0, 0, 0}
107 /* Message resource */
108 extern struct res_items msgs_items[];
111 /* This is the master resource definition */
112 struct s_res resources[] = {
113 {"director", dir_items, R_DIRECTOR, NULL},
114 {"storage", store_items, R_STORAGE, NULL},
115 {"device", dev_items, R_DEVICE, NULL},
116 {"messages", msgs_items, R_MSGS, NULL},
117 {NULL, NULL, 0, NULL}
122 /* Dump contents of resource */
123 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
125 URES *res = (URES *)reshdr;
129 sendit(sock, _("Warning: no %s resource (%d) defined.\n"), res_to_str(type), type);
132 sendit(sock, "dump_resource type=%d\n", type);
133 if (type < 0) { /* no recursion */
139 sendit(sock, "Director: name=%s\n", res->res_dir.hdr.name);
142 sendit(sock, "Storage: name=%s address=%s SDport=%d SDDport=%d\n",
143 res->res_store.hdr.name, res->res_store.address,
144 res->res_store.SDport, res->res_store.SDDport);
147 sendit(sock, "Device: name=%s MediaType=%s Device=%s\n",
148 res->res_dev.hdr.name,
149 res->res_dev.media_type, res->res_dev.device_name);
150 sendit(sock, " rew_wait=%d min_bs=%d max_bs=%d\n",
151 res->res_dev.max_rewind_wait, res->res_dev.min_block_size,
152 res->res_dev.max_block_size);
153 sendit(sock, " max_jobs=%d max_files=%" lld " max_size=%" lld "\n",
154 res->res_dev.max_volume_jobs, res->res_dev.max_volume_files,
155 res->res_dev.max_volume_size);
156 sendit(sock, " max_file_size=%" lld " capacity=%" lld "\n",
157 res->res_dev.max_file_size, res->res_dev.volume_capacity);
159 if (res->res_dev.cap_bits & CAP_EOF) {
160 strcat(buf, "CAP_EOF ");
162 if (res->res_dev.cap_bits & CAP_BSR) {
163 strcat(buf, "CAP_BSR ");
165 if (res->res_dev.cap_bits & CAP_BSF) {
166 strcat(buf, "CAP_BSF ");
168 if (res->res_dev.cap_bits & CAP_FSR) {
169 strcat(buf, "CAP_FSR ");
171 if (res->res_dev.cap_bits & CAP_FSF) {
172 strcat(buf, "CAP_FSF ");
174 if (res->res_dev.cap_bits & CAP_EOM) {
175 strcat(buf, "CAP_EOM ");
177 if (res->res_dev.cap_bits & CAP_REM) {
178 strcat(buf, "CAP_REM ");
180 if (res->res_dev.cap_bits & CAP_RACCESS) {
181 strcat(buf, "CAP_RACCESS ");
183 if (res->res_dev.cap_bits & CAP_AUTOMOUNT) {
184 strcat(buf, "CAP_AUTOMOUNT ");
186 if (res->res_dev.cap_bits & CAP_LABEL) {
187 strcat(buf, "CAP_LABEL ");
189 if (res->res_dev.cap_bits & CAP_ANONVOLS) {
190 strcat(buf, "CAP_ANONVOLS ");
192 if (res->res_dev.cap_bits & CAP_ALWAYSOPEN) {
193 strcat(buf, "CAP_ALWAYSOPEN ");
199 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
200 if (res->res_msgs.mail_cmd)
201 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
202 if (res->res_msgs.operator_cmd)
203 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
206 sendit(sock, _("Warning: unknown resource type %d\n"), type);
209 if (recurse && res->res_dir.hdr.next)
210 dump_resource(type, (RES *)res->res_dir.hdr.next, sendit, sock);
214 * Free memory of resource.
215 * NB, we don't need to worry about freeing any references
216 * to other resources as they will be freed when that
217 * resource chain is traversed. Mainly we worry about freeing
218 * allocated strings (names).
220 void free_resource(int type)
224 int rindex = type - r_first;
225 res = (URES *)resources[rindex].res_head;
230 /* common stuff -- free the resource name */
231 nres = (URES *)res->res_dir.hdr.next;
232 if (res->res_dir.hdr.name)
233 free(res->res_dir.hdr.name);
237 if (res->res_dir.password)
238 free(res->res_dir.password);
239 if (res->res_dir.address)
240 free(res->res_dir.address);
243 if (res->res_store.address)
244 free(res->res_store.address);
245 if (res->res_store.working_directory)
246 free(res->res_store.working_directory);
247 if (res->res_store.pid_directory)
248 free(res->res_store.pid_directory);
249 if (res->res_store.subsys_directory)
250 free(res->res_store.subsys_directory);
253 if (res->res_dev.media_type)
254 free(res->res_dev.media_type);
255 if (res->res_dev.device_name)
256 free(res->res_dev.device_name);
259 if (res->res_msgs.mail_cmd)
260 free(res->res_msgs.mail_cmd);
261 if (res->res_msgs.operator_cmd)
262 free(res->res_msgs.operator_cmd);
263 free_msgs_res((MSGS *)res); /* free message resource */
267 Dmsg1(0, "Unknown resource type %d\n", type);
270 /* Common stuff again -- free the resource, recurse to next one */
274 resources[rindex].res_head = (RES *)nres;
280 /* Save the new resource by chaining it into the head list for
281 * the resource. If this is pass 2, we update any resource
282 * pointers (currently only in the Job resource).
284 void save_resource(int type, struct res_items *items, int pass)
287 int rindex = type - r_first;
292 * Ensure that all required items are present
294 for (i=0; items[i].name; i++) {
295 if (items[i].flags & ITEM_REQUIRED) {
296 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
297 Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
298 items[i].name, resources[rindex]);
301 /* If this triggers, take a look at lib/parse_conf.h */
302 if (i >= MAX_RES_ITEMS) {
303 Emsg1(M_ABORT, 0, _("Too many items in %s resource\n"), resources[rindex]);
307 /* During pass 2, we looked up pointers to all the resources
308 * referrenced in the current resource, , now we
309 * must copy their address from the static record to the allocated
314 /* Resources not containing a resource */
320 /* Resources containing a resource */
322 if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) {
323 Emsg1(M_ABORT, 0, "Cannot find Storage resource %s\n", res_all.res_dir.hdr.name);
325 res->res_store.messages = res_all.res_store.messages;
328 printf("Unknown resource type %d\n", type);
334 if (res_all.res_dir.hdr.name) {
335 free(res_all.res_dir.hdr.name);
336 res_all.res_dir.hdr.name = NULL;
338 if (res_all.res_dir.hdr.desc) {
339 free(res_all.res_dir.hdr.desc);
340 res_all.res_dir.hdr.desc = NULL;
345 /* The following code is only executed on pass 1 */
348 size = sizeof(DIRRES);
351 size = sizeof(STORES);
354 size = sizeof(DEVRES);
360 printf("Unknown resource type %d\n", type);
366 res = (URES *) malloc(size);
367 memcpy(res, &res_all, size);
368 res->res_dir.hdr.next = resources[rindex].res_head;
369 resources[rindex].res_head = (RES *)res;