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;
52 static RES *sres_head[R_LAST - R_FIRST];
53 RES **res_head = sres_head;
55 /* Forward referenced subroutines */
58 /* We build the current resource here as we are
59 * scanning the resource configuration definition,
60 * then move it to allocated memory when the resource
64 int res_all_size = sizeof(res_all);
66 /* Definition of records permitted within each
67 * resource with the routine to process the record
70 static RES_ITEM dir_items[] = {
71 {"name", store_name, ITEM(dir_res.hdr.name), 0, ITEM_REQUIRED, 0},
72 {"description", store_str, ITEM(dir_res.hdr.desc), 0, 0, 0},
73 {"dirport", store_int, ITEM(dir_res.DIRport), 0, ITEM_DEFAULT, 9101},
74 {"address", store_str, ITEM(dir_res.address), 0, ITEM_REQUIRED, 0},
75 {"password", store_password, ITEM(dir_res.password), 0, 0, 0},
76 {"enablessl", store_yesno, ITEM(dir_res.enable_ssl), 1, ITEM_DEFAULT, 0},
77 {NULL, NULL, NULL, 0, 0, 0}
80 static RES_ITEM con_items[] = {
81 {"name", store_name, ITEM(con_res.hdr.name), 0, ITEM_REQUIRED, 0},
82 {"description", store_str, ITEM(con_res.hdr.desc), 0, 0, 0},
83 {"password", store_password, ITEM(con_res.password), 0, ITEM_REQUIRED, 0},
84 {"requiressl", store_yesno, ITEM(con_res.require_ssl), 1, ITEM_DEFAULT, 0},
85 {NULL, NULL, NULL, 0, 0, 0}
88 static RES_ITEM con_font_items[] = {
89 {"name", store_name, ITEM(con_font.hdr.name), 0, ITEM_REQUIRED, 0},
90 {"description", store_str, ITEM(con_font.hdr.desc), 0, 0, 0},
91 {"font", store_str, ITEM(con_font.fontface), 0, 0, 0},
92 {"requiressl", store_yesno, ITEM(con_font.require_ssl), 1, ITEM_DEFAULT, 0},
93 {NULL, NULL, NULL, 0, 0, 0}
98 * This is the master resource definition.
99 * It must have one item for each of the resources.
101 RES_TABLE resources[] = {
102 {"director", dir_items, R_DIRECTOR},
103 {"console", con_items, R_CONSOLE},
104 {"consolefont", con_font_items, R_CONSOLE_FONT},
109 /* Dump contents of resource */
110 void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock)
112 URES *res = (URES *)reshdr;
116 printf("No record for %d %s\n", type, res_to_str(type));
119 if (type < 0) { /* no recursion */
125 printf("Director: name=%s address=%s DIRport=%d\n", reshdr->name,
126 res->dir_res.address, res->dir_res.DIRport);
129 printf("Console: name=%s\n", reshdr->name);
132 printf("ConsoleFont: name=%s font face=%s\n",
133 reshdr->name, NPRT(res->con_font.fontface));
136 printf("Unknown resource type %d\n", type);
138 if (recurse && res->dir_res.hdr.next) {
139 dump_resource(type, res->dir_res.hdr.next, sendit, sock);
144 * Free memory of resource.
145 * NB, we don't need to worry about freeing any references
146 * to other resources as they will be freed when that
147 * resource chain is traversed. Mainly we worry about freeing
148 * allocated strings (names).
150 void free_resource(RES *sres, int type)
153 URES *res = (URES *)sres;
158 /* common stuff -- free the resource name */
159 nres = (RES *)res->dir_res.hdr.next;
160 if (res->dir_res.hdr.name) {
161 free(res->dir_res.hdr.name);
163 if (res->dir_res.hdr.desc) {
164 free(res->dir_res.hdr.desc);
169 if (res->dir_res.address) {
170 free(res->dir_res.address);
174 if (res->con_res.password) {
175 free(res->con_res.password);
179 if (res->con_font.fontface) {
180 free(res->con_font.fontface);
184 printf("Unknown resource type %d\n", type);
186 /* Common stuff again -- free the resource, recurse to next one */
189 free_resource(nres, type);
193 /* Save the new resource by chaining it into the head list for
194 * the resource. If this is pass 2, we update any resource
195 * pointers (currently only in the Job resource).
197 void save_resource(int type, RES_ITEM *items, int pass)
200 int rindex = type - r_first;
205 * Ensure that all required items are present
207 for (i=0; items[i].name; i++) {
208 if (items[i].flags & ITEM_REQUIRED) {
209 if (!bit_is_set(i, res_all.dir_res.hdr.item_present)) {
210 Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
211 items[i].name, resources[rindex]);
216 /* During pass 2, we looked up pointers to all the resources
217 * referrenced in the current resource, , now we
218 * must copy their address from the static record to the allocated
223 /* Resources not containing a resource */
232 Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
236 /* Note, the resoure name was already saved during pass 1,
237 * so here, we can just release it.
239 if (res_all.dir_res.hdr.name) {
240 free(res_all.dir_res.hdr.name);
241 res_all.dir_res.hdr.name = NULL;
243 if (res_all.dir_res.hdr.desc) {
244 free(res_all.dir_res.hdr.desc);
245 res_all.dir_res.hdr.desc = NULL;
250 /* The following code is only executed during pass 1 */
253 size = sizeof(DIRRES);
256 size = sizeof(CONFONTRES);
259 size = sizeof(CONRES);
262 printf("Unknown resource type %d\n", type);
268 res = (URES *)malloc(size);
269 memcpy(res, &res_all, size);
270 if (!res_head[rindex]) {
271 res_head[rindex] = (RES *)res; /* store first entry */
274 /* Add new res to end of chain */
275 for (next=res_head[rindex]; next->next; next=next->next) {
276 if (strcmp(next->name, res->dir_res.hdr.name) == 0) {
277 Emsg2(M_ERROR_TERM, 0,
278 _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
279 resources[rindex].name, res->dir_res.hdr.name);
282 next->next = (RES *)res;
283 Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
284 res->dir_res.hdr.name);