2 * Main configuration file parser for Bacula File Daemon (Client)
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, September MM
25 Copyright (C) 2000, 2001, 2002 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,
48 /* Define the first and last resource ID record
49 * types. Note, these should be unique for each
50 * daemon though not a requirement.
52 int r_first = R_FIRST;
54 static RES *sres_head[R_LAST - R_FIRST + 1];
55 RES **res_head = sres_head;
58 /* Forward referenced subroutines */
61 /* We build the current resource here as we are
62 * scanning the resource configuration definition,
63 * then move it to allocated memory when the resource
66 #if defined(HAVE_WIN32) && !defined(HAVE_CYGWIN)
67 extern "C" { // work around visual compiler mangling variables
69 int res_all_size = sizeof(res_all);
73 int res_all_size = sizeof(res_all);
76 /* Definition of records permitted within each
77 * resource with the routine to process the record
81 /* Client or File daemon "Global" resources */
82 static RES_ITEM cli_items[] = {
83 {"name", store_name, ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
84 {"description", store_str, ITEM(res_client.hdr.desc), 0, 0, 0},
85 {"fdport", store_addresses_port, ITEM(res_client.FDaddrs), 0, ITEM_DEFAULT, 9102},
86 {"fdaddress", store_addresses_address, ITEM(res_client.FDaddrs), 0, ITEM_DEFAULT, 9102},
87 {"fdaddresses", store_addresses, ITEM(res_client.FDaddrs), 0, ITEM_DEFAULT, 9102},
89 {"workingdirectory", store_dir, ITEM(res_client.working_directory), 0, ITEM_REQUIRED, 0},
90 {"piddirectory", store_dir, ITEM(res_client.pid_directory), 0, ITEM_REQUIRED, 0},
91 {"subsysdirectory", store_dir, ITEM(res_client.subsys_directory), 0, 0, 0},
92 {"scriptsdirectory", store_dir, ITEM(res_client.scripts_directory), 0, 0, 0},
93 {"requiressl", store_yesno, ITEM(res_client.require_ssl), 1, ITEM_DEFAULT, 0},
94 {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 10},
95 {"messages", store_res, ITEM(res_client.messages), R_MSGS, 0, 0},
96 {"heartbeatinterval", store_time, ITEM(res_client.heartbeat_interval), 0, ITEM_DEFAULT, 0},
97 {"sdconnecttimeout", store_time,ITEM(res_client.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
98 {"maximumnetworkbuffersize", store_pint, ITEM(res_client.max_network_buffer_size), 0, 0, 0},
99 {NULL, NULL, NULL, 0, 0, 0}
102 /* Directors that can use our services */
103 static RES_ITEM dir_items[] = {
104 {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
105 {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
106 {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
107 {"address", store_str, ITEM(res_dir.address), 0, 0, 0},
108 {"enablessl", store_yesno, ITEM(res_dir.enable_ssl),1, ITEM_DEFAULT, 0},
109 {"monitor", store_yesno, ITEM(res_dir.monitor), 1, ITEM_DEFAULT, 0},
110 {NULL, NULL, NULL, 0, 0, 0}
113 /* Message resource */
114 extern RES_ITEM msgs_items[];
117 * This is the master resource definition.
118 * It must have one item for each of the resources.
120 RES_TABLE resources[] = {
121 {"director", dir_items, R_DIRECTOR},
122 {"filedaemon", cli_items, R_CLIENT},
123 {"client", cli_items, R_CLIENT}, /* alias for filedaemon */
124 {"messages", msgs_items, R_MSGS},
129 /* Dump contents of resource */
130 void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock)
132 URES *res = (URES *)reshdr;
136 sendit(sock, "No record for %d %s\n", type, res_to_str(type));
139 if (type < 0) { /* no recursion */
145 sendit(sock, "Director: name=%s password=%s\n", reshdr->name,
146 res->res_dir.password);
149 sendit(sock, "Client: name=%s FDport=%d\n", reshdr->name,
150 get_first_port_host_order(res->res_client.FDaddrs));
153 sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
154 if (res->res_msgs.mail_cmd)
155 sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
156 if (res->res_msgs.operator_cmd)
157 sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
160 sendit(sock, "Unknown resource type %d\n", type);
162 if (recurse && res->res_dir.hdr.next)
163 dump_resource(type, res->res_dir.hdr.next, sendit, sock);
167 * Free memory of resource.
168 * NB, we don't need to worry about freeing any references
169 * to other resources as they will be freed when that
170 * resource chain is traversed. Mainly we worry about freeing
171 * allocated strings (names).
173 void free_resource(RES *sres, int type)
176 URES *res = (URES *)sres;
182 /* common stuff -- free the resource name */
183 nres = (RES *)res->res_dir.hdr.next;
184 if (res->res_dir.hdr.name) {
185 free(res->res_dir.hdr.name);
187 if (res->res_dir.hdr.desc) {
188 free(res->res_dir.hdr.desc);
192 if (res->res_dir.password) {
193 free(res->res_dir.password);
195 if (res->res_dir.address) {
196 free(res->res_dir.address);
200 if (res->res_client.working_directory) {
201 free(res->res_client.working_directory);
203 if (res->res_client.pid_directory) {
204 free(res->res_client.pid_directory);
206 if (res->res_client.subsys_directory) {
207 free(res->res_client.subsys_directory);
209 if (res->res_client.scripts_directory) {
210 free(res->res_client.scripts_directory);
212 if (res->res_client.FDaddrs) {
213 free_addresses(res->res_client.FDaddrs);
217 if (res->res_msgs.mail_cmd)
218 free(res->res_msgs.mail_cmd);
219 if (res->res_msgs.operator_cmd)
220 free(res->res_msgs.operator_cmd);
221 free_msgs_res((MSGS *)res); /* free message resource */
225 printf("Unknown resource type %d\n", type);
227 /* Common stuff again -- free the resource, recurse to next one */
232 free_resource(nres, type);
236 /* Save the new resource by chaining it into the head list for
237 * the resource. If this is pass 2, we update any resource
238 * pointers (currently only in the Job resource).
240 void save_resource(int type, RES_ITEM *items, int pass)
243 int rindex = type - r_first;
248 * Ensure that all required items are present
250 for (i=0; items[i].name; i++) {
251 if (items[i].flags & ITEM_REQUIRED) {
252 if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
253 Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
254 items[i].name, resources[rindex]);
259 /* During pass 2, we looked up pointers to all the resources
260 * referrenced in the current resource, , now we
261 * must copy their address from the static record to the allocated
266 /* Resources not containing a resource */
271 /* Resources containing another resource */
273 if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_dir.hdr.name)) == NULL) {
274 Emsg1(M_ABORT, 0, "Cannot find Client resource %s\n", res_all.res_dir.hdr.name);
276 res->res_client.messages = res_all.res_client.messages;
279 Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
283 /* Note, the resoure name was already saved during pass 1,
284 * so here, we can just release it.
286 if (res_all.res_dir.hdr.name) {
287 free(res_all.res_dir.hdr.name);
288 res_all.res_dir.hdr.name = NULL;
290 if (res_all.res_dir.hdr.desc) {
291 free(res_all.res_dir.hdr.desc);
292 res_all.res_dir.hdr.desc = NULL;
297 /* The following code is only executed on pass 1 */
300 size = sizeof(DIRRES);
303 size = sizeof(CLIENT);
309 printf(_("Unknown resource type %d\n"), type);
316 res = (URES *)malloc(size);
317 memcpy(res, &res_all, size);
318 if (!res_head[rindex]) {
319 res_head[rindex] = (RES *)res; /* store first entry */
322 /* Add new res to end of chain */
323 for (next=res_head[rindex]; next->next; next=next->next) {
324 if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
325 Emsg2(M_ERROR_TERM, 0,
326 _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
327 resources[rindex].name, res->res_dir.hdr.name);
330 next->next = (RES *)res;
331 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
332 res->res_dir.hdr.name);