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 struct res_items 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 struct res_items 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 struct res_items 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 struct s_res 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(int type)
152 int rindex = type - r_first;
154 res = (URES *)resources[rindex].res_head;
159 /* common stuff -- free the resource name */
160 nres = (RES *)res->dir_res.hdr.next;
161 if (res->dir_res.hdr.name) {
162 free(res->dir_res.hdr.name);
164 if (res->dir_res.hdr.desc) {
165 free(res->dir_res.hdr.desc);
170 if (res->dir_res.address) {
171 free(res->dir_res.address);
175 if (res->con_res.password) {
176 free(res->con_res.password);
180 if (res->con_font.fontface) {
181 free(res->con_font.fontface);
185 printf("Unknown resource type %d\n", type);
187 /* Common stuff again -- free the resource, recurse to next one */
189 resources[rindex].res_head = nres;
195 /* Save the new resource by chaining it into the head list for
196 * the resource. If this is pass 2, we update any resource
197 * pointers (currently only in the Job resource).
199 void save_resource(int type, struct res_items *items, int pass)
202 int rindex = type - r_first;
207 * Ensure that all required items are present
209 for (i=0; items[i].name; i++) {
210 if (items[i].flags & ITEM_REQUIRED) {
211 if (!bit_is_set(i, res_all.dir_res.hdr.item_present)) {
212 Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
213 items[i].name, resources[rindex]);
218 /* During pass 2, we looked up pointers to all the resources
219 * referrenced in the current resource, , now we
220 * must copy their address from the static record to the allocated
225 /* Resources not containing a resource */
234 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
238 /* Note, the resoure name was already saved during pass 1,
239 * so here, we can just release it.
241 if (res_all.dir_res.hdr.name) {
242 free(res_all.dir_res.hdr.name);
243 res_all.dir_res.hdr.name = NULL;
245 if (res_all.dir_res.hdr.desc) {
246 free(res_all.dir_res.hdr.desc);
247 res_all.dir_res.hdr.desc = NULL;
252 /* The following code is only executed during pass 1 */
255 size = sizeof(DIRRES);
258 size = sizeof(CONFONTRES);
261 size = sizeof(CONRES);
264 printf("Unknown resource type %d\n", type);
270 res = (URES *)malloc(size);
271 memcpy(res, &res_all, size);
272 if (!resources[rindex].res_head) {
273 resources[rindex].res_head = (RES *)res; /* store first entry */
276 /* Add new res to end of chain */
277 for (next=resources[rindex].res_head; next->next; next=next->next) {
278 if (strcmp(next->name, res->dir_res.hdr.name) == 0) {
279 Emsg2(M_ERROR_TERM, 0,
280 _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
281 resources[rindex].name, res->dir_res.hdr.name);
284 next->next = (RES *)res;
285 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
286 res->dir_res.hdr.name);