2 * Main configuration file parser for Bacula User Agent
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, September MM
26 Copyright (C) 2000, 2001 Kern Sibbald and John Walker
28 This program is free software; you can redistribute it and/or
29 modify it under the terms of the GNU General Public License
30 as published by the Free Software Foundation; either version 2
31 of the License, or (at your option) any later version.
33 This program is distributed in the hope that it will be useful,
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 GNU General Public License for more details.
38 You should have received a copy of the GNU General Public License
39 along with this program; if not, write to the Free Software
40 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
44 #include "console_conf.h"
46 /* Define the first and last resource ID record
47 * types. Note, these should be unique for each
48 * daemon though not a requirement.
50 int r_first = R_FIRST;
53 /* Forward referenced subroutines */
56 /* We build the current resource here as we are
57 * scanning the resource configuration definition,
58 * then move it to allocated memory when the resource
62 int res_all_size = sizeof(res_all);
64 /* Definition of records permitted within each
65 * resource with the routine to process the record
68 static RES_ITEM dir_items[] = {
69 {"name", store_name, ITEM(dir_res.hdr.name), 0, ITEM_REQUIRED, 0},
70 {"description", store_str, ITEM(dir_res.hdr.desc), 0, 0, 0},
71 {"dirport", store_int, ITEM(dir_res.DIRport), 0, ITEM_DEFAULT, 9101},
72 {"address", store_str, ITEM(dir_res.address), 0, ITEM_REQUIRED, 0},
73 {"password", store_password, ITEM(dir_res.password), 0, 0, 0},
74 {"enablessl", store_yesno, ITEM(dir_res.enable_ssl), 1, ITEM_DEFAULT, 0},
75 {NULL, NULL, NULL, 0, 0, 0}
78 static RES_ITEM con_items[] = {
79 {"name", store_name, ITEM(con_res.hdr.name), 0, ITEM_REQUIRED, 0},
80 {"description", store_str, ITEM(con_res.hdr.desc), 0, 0, 0},
81 {"password", store_password, ITEM(con_res.password), 0, ITEM_REQUIRED, 0},
82 {"requiressl", store_yesno, ITEM(con_res.require_ssl), 1, ITEM_DEFAULT, 0},
83 {NULL, NULL, NULL, 0, 0, 0}
86 static RES_ITEM con_font_items[] = {
87 {"name", store_name, ITEM(con_font.hdr.name), 0, ITEM_REQUIRED, 0},
88 {"description", store_str, ITEM(con_font.hdr.desc), 0, 0, 0},
89 {"font", store_str, ITEM(con_font.fontface), 0, 0, 0},
90 {"requiressl", store_yesno, ITEM(con_font.require_ssl), 1, ITEM_DEFAULT, 0},
91 {NULL, NULL, NULL, 0, 0, 0}
96 * This is the master resource definition.
97 * It must have one item for each of the resources.
99 RES_TABLE resources[] = {
100 {"director", dir_items, R_DIRECTOR, NULL},
101 {"console", con_items, R_CONSOLE, NULL},
102 {"consolefont", con_font_items, R_CONSOLE_FONT, NULL},
103 {NULL, NULL, 0, NULL}
107 /* Dump contents of resource */
108 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
110 URES *res = (URES *)reshdr;
114 printf("No record for %d %s\n", type, res_to_str(type));
117 if (type < 0) { /* no recursion */
123 printf("Director: name=%s address=%s DIRport=%d\n", reshdr->name,
124 res->dir_res.address, res->dir_res.DIRport);
127 printf("Console: name=%s\n", reshdr->name);
130 printf("ConsoleFont: name=%s font face=%s\n",
131 reshdr->name, NPRT(res->con_font.fontface));
134 printf("Unknown resource type %d\n", type);
136 if (recurse && res->dir_res.hdr.next) {
137 dump_resource(type, res->dir_res.hdr.next, sendit, sock);
142 * Free memory of resource.
143 * NB, we don't need to worry about freeing any references
144 * to other resources as they will be freed when that
145 * resource chain is traversed. Mainly we worry about freeing
146 * allocated strings (names).
148 void free_resource(RES *sres, int type)
151 URES *res = (URES *)sres;
156 /* common stuff -- free the resource name */
157 nres = (RES *)res->dir_res.hdr.next;
158 if (res->dir_res.hdr.name) {
159 free(res->dir_res.hdr.name);
161 if (res->dir_res.hdr.desc) {
162 free(res->dir_res.hdr.desc);
167 if (res->dir_res.address) {
168 free(res->dir_res.address);
172 if (res->con_res.password) {
173 free(res->con_res.password);
177 if (res->con_font.fontface) {
178 free(res->con_font.fontface);
182 printf("Unknown resource type %d\n", type);
184 /* Common stuff again -- free the resource, recurse to next one */
187 free_resource(nres, type);
191 /* Save the new resource by chaining it into the head list for
192 * the resource. If this is pass 2, we update any resource
193 * pointers (currently only in the Job resource).
195 void save_resource(int type, RES_ITEM *items, int pass)
198 int rindex = type - r_first;
203 * Ensure that all required items are present
205 for (i=0; items[i].name; i++) {
206 if (items[i].flags & ITEM_REQUIRED) {
207 if (!bit_is_set(i, res_all.dir_res.hdr.item_present)) {
208 Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
209 items[i].name, resources[rindex]);
214 /* During pass 2, we looked up pointers to all the resources
215 * referrenced in the current resource, , now we
216 * must copy their address from the static record to the allocated
221 /* Resources not containing a resource */
230 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
234 /* Note, the resoure name was already saved during pass 1,
235 * so here, we can just release it.
237 if (res_all.dir_res.hdr.name) {
238 free(res_all.dir_res.hdr.name);
239 res_all.dir_res.hdr.name = NULL;
241 if (res_all.dir_res.hdr.desc) {
242 free(res_all.dir_res.hdr.desc);
243 res_all.dir_res.hdr.desc = NULL;
248 /* The following code is only executed during pass 1 */
251 size = sizeof(DIRRES);
254 size = sizeof(CONFONTRES);
257 size = sizeof(CONRES);
260 printf("Unknown resource type %d\n", type);
266 res = (URES *)malloc(size);
267 memcpy(res, &res_all, size);
268 if (!resources[rindex].res_head) {
269 resources[rindex].res_head = (RES *)res; /* store first entry */
272 /* Add new res to end of chain */
273 for (next=resources[rindex].res_head; next->next; next=next->next) {
274 if (strcmp(next->name, res->dir_res.hdr.name) == 0) {
275 Emsg2(M_ERROR_TERM, 0,
276 _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
277 resources[rindex].name, res->dir_res.hdr.name);
280 next->next = (RES *)res;
281 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
282 res->dir_res.hdr.name);