xref: /minix3/crypto/external/bsd/heimdal/dist/lib/krb5/verify_krb5_conf.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: verify_krb5_conf.c,v 1.1.1.2 2014/04/24 12:45:51 pettai Exp $	*/
2ebfedea0SLionel Sambuc 
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc  * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
5ebfedea0SLionel Sambuc  * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc  * All rights reserved.
7ebfedea0SLionel Sambuc  *
8ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
9ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
10ebfedea0SLionel Sambuc  * are met:
11ebfedea0SLionel Sambuc  *
12ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
13ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
14ebfedea0SLionel Sambuc  *
15ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
16ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
17ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
18ebfedea0SLionel Sambuc  *
19ebfedea0SLionel Sambuc  * 3. Neither the name of the Institute nor the names of its contributors
20ebfedea0SLionel Sambuc  *    may be used to endorse or promote products derived from this software
21ebfedea0SLionel Sambuc  *    without specific prior written permission.
22ebfedea0SLionel Sambuc  *
23ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33ebfedea0SLionel Sambuc  * SUCH DAMAGE.
34ebfedea0SLionel Sambuc  */
35ebfedea0SLionel Sambuc 
36ebfedea0SLionel Sambuc #include "krb5_locl.h"
37ebfedea0SLionel Sambuc #include <krb5/getarg.h>
38ebfedea0SLionel Sambuc #include <krb5/parse_bytes.h>
39ebfedea0SLionel Sambuc #include <err.h>
40ebfedea0SLionel Sambuc 
41ebfedea0SLionel Sambuc /* verify krb5.conf */
42ebfedea0SLionel Sambuc 
43ebfedea0SLionel Sambuc static int dumpconfig_flag = 0;
44ebfedea0SLionel Sambuc static int version_flag = 0;
45ebfedea0SLionel Sambuc static int help_flag	= 0;
46ebfedea0SLionel Sambuc static int warn_mit_syntax_flag = 0;
47ebfedea0SLionel Sambuc 
48ebfedea0SLionel Sambuc static struct getargs args[] = {
49ebfedea0SLionel Sambuc     {"dumpconfig", 0,      arg_flag,       &dumpconfig_flag,
50ebfedea0SLionel Sambuc      "show the parsed config files", NULL },
51ebfedea0SLionel Sambuc     {"warn-mit-syntax", 0, arg_flag,       &warn_mit_syntax_flag,
52ebfedea0SLionel Sambuc      "show the parsed config files", NULL },
53ebfedea0SLionel Sambuc     {"version",	0,	arg_flag,	&version_flag,
54ebfedea0SLionel Sambuc      "print version", NULL },
55ebfedea0SLionel Sambuc     {"help",	0,	arg_flag,	&help_flag,
56ebfedea0SLionel Sambuc      NULL, NULL }
57ebfedea0SLionel Sambuc };
58ebfedea0SLionel Sambuc 
59ebfedea0SLionel Sambuc static void
usage(int ret)60ebfedea0SLionel Sambuc usage (int ret)
61ebfedea0SLionel Sambuc {
62ebfedea0SLionel Sambuc     arg_printusage (args,
63ebfedea0SLionel Sambuc 		    sizeof(args)/sizeof(*args),
64ebfedea0SLionel Sambuc 		    NULL,
65ebfedea0SLionel Sambuc 		    "[config-file]");
66ebfedea0SLionel Sambuc     exit (ret);
67ebfedea0SLionel Sambuc }
68ebfedea0SLionel Sambuc 
69ebfedea0SLionel Sambuc static int
check_bytes(krb5_context context,const char * path,char * data)70ebfedea0SLionel Sambuc check_bytes(krb5_context context, const char *path, char *data)
71ebfedea0SLionel Sambuc {
72ebfedea0SLionel Sambuc     if(parse_bytes(data, NULL) == -1) {
73ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: failed to parse \"%s\" as size", path, data);
74ebfedea0SLionel Sambuc 	return 1;
75ebfedea0SLionel Sambuc     }
76ebfedea0SLionel Sambuc     return 0;
77ebfedea0SLionel Sambuc }
78ebfedea0SLionel Sambuc 
79ebfedea0SLionel Sambuc static int
check_time(krb5_context context,const char * path,char * data)80ebfedea0SLionel Sambuc check_time(krb5_context context, const char *path, char *data)
81ebfedea0SLionel Sambuc {
82ebfedea0SLionel Sambuc     if(parse_time(data, NULL) == -1) {
83ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: failed to parse \"%s\" as time", path, data);
84ebfedea0SLionel Sambuc 	return 1;
85ebfedea0SLionel Sambuc     }
86ebfedea0SLionel Sambuc     return 0;
87ebfedea0SLionel Sambuc }
88ebfedea0SLionel Sambuc 
89ebfedea0SLionel Sambuc static int
check_numeric(krb5_context context,const char * path,char * data)90ebfedea0SLionel Sambuc check_numeric(krb5_context context, const char *path, char *data)
91ebfedea0SLionel Sambuc {
92ebfedea0SLionel Sambuc     long v;
93ebfedea0SLionel Sambuc     char *end;
94ebfedea0SLionel Sambuc     v = strtol(data, &end, 0);
95ebfedea0SLionel Sambuc 
96ebfedea0SLionel Sambuc     if ((v == LONG_MIN || v == LONG_MAX) && errno != 0) {
97ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: over/under flow for \"%s\"",
98ebfedea0SLionel Sambuc 		   path, data);
99ebfedea0SLionel Sambuc 	return 1;
100ebfedea0SLionel Sambuc     }
101ebfedea0SLionel Sambuc     if(*end != '\0') {
102ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: failed to parse \"%s\" as a number",
103ebfedea0SLionel Sambuc 		   path, data);
104ebfedea0SLionel Sambuc 	return 1;
105ebfedea0SLionel Sambuc     }
106ebfedea0SLionel Sambuc     return 0;
107ebfedea0SLionel Sambuc }
108ebfedea0SLionel Sambuc 
109ebfedea0SLionel Sambuc static int
check_boolean(krb5_context context,const char * path,char * data)110ebfedea0SLionel Sambuc check_boolean(krb5_context context, const char *path, char *data)
111ebfedea0SLionel Sambuc {
112ebfedea0SLionel Sambuc     long int v;
113ebfedea0SLionel Sambuc     char *end;
114ebfedea0SLionel Sambuc     if(strcasecmp(data, "yes") == 0 ||
115ebfedea0SLionel Sambuc        strcasecmp(data, "true") == 0 ||
116ebfedea0SLionel Sambuc        strcasecmp(data, "no") == 0 ||
117ebfedea0SLionel Sambuc        strcasecmp(data, "false") == 0)
118ebfedea0SLionel Sambuc 	return 0;
119ebfedea0SLionel Sambuc     v = strtol(data, &end, 0);
120ebfedea0SLionel Sambuc     if(*end != '\0') {
121ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: failed to parse \"%s\" as a boolean",
122ebfedea0SLionel Sambuc 		   path, data);
123ebfedea0SLionel Sambuc 	return 1;
124ebfedea0SLionel Sambuc     }
125ebfedea0SLionel Sambuc     if(v != 0 && v != 1)
126ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: numeric value \"%s\" is treated as \"true\"",
127ebfedea0SLionel Sambuc 		   path, data);
128ebfedea0SLionel Sambuc     return 0;
129ebfedea0SLionel Sambuc }
130ebfedea0SLionel Sambuc 
131ebfedea0SLionel Sambuc static int
check_524(krb5_context context,const char * path,char * data)132ebfedea0SLionel Sambuc check_524(krb5_context context, const char *path, char *data)
133ebfedea0SLionel Sambuc {
134ebfedea0SLionel Sambuc     if(strcasecmp(data, "yes") == 0 ||
135ebfedea0SLionel Sambuc        strcasecmp(data, "no") == 0 ||
136ebfedea0SLionel Sambuc        strcasecmp(data, "2b") == 0 ||
137ebfedea0SLionel Sambuc        strcasecmp(data, "local") == 0)
138ebfedea0SLionel Sambuc 	return 0;
139ebfedea0SLionel Sambuc 
140ebfedea0SLionel Sambuc     krb5_warnx(context, "%s: didn't contain a valid option `%s'",
141ebfedea0SLionel Sambuc 	       path, data);
142ebfedea0SLionel Sambuc     return 1;
143ebfedea0SLionel Sambuc }
144ebfedea0SLionel Sambuc 
145ebfedea0SLionel Sambuc static int
check_host(krb5_context context,const char * path,char * data)146ebfedea0SLionel Sambuc check_host(krb5_context context, const char *path, char *data)
147ebfedea0SLionel Sambuc {
148ebfedea0SLionel Sambuc     int ret;
149ebfedea0SLionel Sambuc     char hostname[128];
150ebfedea0SLionel Sambuc     const char *p = data;
151ebfedea0SLionel Sambuc     struct addrinfo hints;
152ebfedea0SLionel Sambuc     char service[32];
153ebfedea0SLionel Sambuc     int defport;
154ebfedea0SLionel Sambuc     struct addrinfo *ai;
155ebfedea0SLionel Sambuc 
156ebfedea0SLionel Sambuc     hints.ai_flags = 0;
157ebfedea0SLionel Sambuc     hints.ai_family = PF_UNSPEC;
158ebfedea0SLionel Sambuc     hints.ai_socktype = 0;
159ebfedea0SLionel Sambuc     hints.ai_protocol = 0;
160ebfedea0SLionel Sambuc 
161ebfedea0SLionel Sambuc     hints.ai_addrlen = 0;
162ebfedea0SLionel Sambuc     hints.ai_canonname = NULL;
163ebfedea0SLionel Sambuc     hints.ai_addr = NULL;
164ebfedea0SLionel Sambuc     hints.ai_next = NULL;
165ebfedea0SLionel Sambuc 
166ebfedea0SLionel Sambuc     /* XXX data could be a list of hosts that this code can't handle */
167ebfedea0SLionel Sambuc     /* XXX copied from krbhst.c */
168ebfedea0SLionel Sambuc     if(strncmp(p, "http://", 7) == 0){
169ebfedea0SLionel Sambuc         p += 7;
170ebfedea0SLionel Sambuc 	hints.ai_socktype = SOCK_STREAM;
171ebfedea0SLionel Sambuc 	strlcpy(service, "http", sizeof(service));
172ebfedea0SLionel Sambuc 	defport = 80;
173ebfedea0SLionel Sambuc     } else if(strncmp(p, "http/", 5) == 0) {
174ebfedea0SLionel Sambuc         p += 5;
175ebfedea0SLionel Sambuc 	hints.ai_socktype = SOCK_STREAM;
176ebfedea0SLionel Sambuc 	strlcpy(service, "http", sizeof(service));
177ebfedea0SLionel Sambuc 	defport = 80;
178ebfedea0SLionel Sambuc     }else if(strncmp(p, "tcp/", 4) == 0){
179ebfedea0SLionel Sambuc         p += 4;
180ebfedea0SLionel Sambuc 	hints.ai_socktype = SOCK_STREAM;
181ebfedea0SLionel Sambuc 	strlcpy(service, "kerberos", sizeof(service));
182ebfedea0SLionel Sambuc 	defport = 88;
183ebfedea0SLionel Sambuc     } else if(strncmp(p, "udp/", 4) == 0) {
184ebfedea0SLionel Sambuc         p += 4;
185ebfedea0SLionel Sambuc 	hints.ai_socktype = SOCK_DGRAM;
186ebfedea0SLionel Sambuc 	strlcpy(service, "kerberos", sizeof(service));
187ebfedea0SLionel Sambuc 	defport = 88;
188ebfedea0SLionel Sambuc     } else {
189ebfedea0SLionel Sambuc 	hints.ai_socktype = SOCK_DGRAM;
190ebfedea0SLionel Sambuc 	strlcpy(service, "kerberos", sizeof(service));
191ebfedea0SLionel Sambuc 	defport = 88;
192ebfedea0SLionel Sambuc     }
193ebfedea0SLionel Sambuc     if(strsep_copy(&p, ":", hostname, sizeof(hostname)) < 0) {
194ebfedea0SLionel Sambuc 	return 1;
195ebfedea0SLionel Sambuc     }
196ebfedea0SLionel Sambuc     hostname[strcspn(hostname, "/")] = '\0';
197ebfedea0SLionel Sambuc     if(p != NULL) {
198ebfedea0SLionel Sambuc 	char *end;
199ebfedea0SLionel Sambuc 	int tmp = strtol(p, &end, 0);
200ebfedea0SLionel Sambuc 	if(end == p) {
201ebfedea0SLionel Sambuc 	    krb5_warnx(context, "%s: failed to parse port number in %s",
202ebfedea0SLionel Sambuc 		       path, data);
203ebfedea0SLionel Sambuc 	    return 1;
204ebfedea0SLionel Sambuc 	}
205ebfedea0SLionel Sambuc 	defport = tmp;
206ebfedea0SLionel Sambuc 	snprintf(service, sizeof(service), "%u", defport);
207ebfedea0SLionel Sambuc     }
208ebfedea0SLionel Sambuc     ret = getaddrinfo(hostname, service, &hints, &ai);
209ebfedea0SLionel Sambuc     if(ret == EAI_SERVICE && !isdigit((unsigned char)service[0])) {
210ebfedea0SLionel Sambuc 	snprintf(service, sizeof(service), "%u", defport);
211ebfedea0SLionel Sambuc 	ret = getaddrinfo(hostname, service, &hints, &ai);
212ebfedea0SLionel Sambuc     }
213ebfedea0SLionel Sambuc     if(ret != 0) {
214ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: %s (%s)", path, gai_strerror(ret), hostname);
215ebfedea0SLionel Sambuc 	return 1;
216ebfedea0SLionel Sambuc     }
217ebfedea0SLionel Sambuc     return 0;
218ebfedea0SLionel Sambuc }
219ebfedea0SLionel Sambuc 
220ebfedea0SLionel Sambuc static int
mit_entry(krb5_context context,const char * path,char * data)221ebfedea0SLionel Sambuc mit_entry(krb5_context context, const char *path, char *data)
222ebfedea0SLionel Sambuc {
223ebfedea0SLionel Sambuc     if (warn_mit_syntax_flag)
224ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s is only used by MIT Kerberos", path);
225ebfedea0SLionel Sambuc     return 0;
226ebfedea0SLionel Sambuc }
227ebfedea0SLionel Sambuc 
228ebfedea0SLionel Sambuc struct s2i {
229ebfedea0SLionel Sambuc     const char *s;
230ebfedea0SLionel Sambuc     int val;
231ebfedea0SLionel Sambuc };
232ebfedea0SLionel Sambuc 
233ebfedea0SLionel Sambuc #define L(X) { #X, LOG_ ## X }
234ebfedea0SLionel Sambuc 
235ebfedea0SLionel Sambuc static struct s2i syslogvals[] = {
236ebfedea0SLionel Sambuc     /* severity */
237ebfedea0SLionel Sambuc     L(EMERG),
238ebfedea0SLionel Sambuc     L(ALERT),
239ebfedea0SLionel Sambuc     L(CRIT),
240ebfedea0SLionel Sambuc     L(ERR),
241ebfedea0SLionel Sambuc     L(WARNING),
242ebfedea0SLionel Sambuc     L(NOTICE),
243ebfedea0SLionel Sambuc     L(INFO),
244ebfedea0SLionel Sambuc     L(DEBUG),
245ebfedea0SLionel Sambuc     /* facility */
246ebfedea0SLionel Sambuc     L(AUTH),
247ebfedea0SLionel Sambuc #ifdef LOG_AUTHPRIV
248ebfedea0SLionel Sambuc     L(AUTHPRIV),
249ebfedea0SLionel Sambuc #endif
250ebfedea0SLionel Sambuc #ifdef LOG_CRON
251ebfedea0SLionel Sambuc     L(CRON),
252ebfedea0SLionel Sambuc #endif
253ebfedea0SLionel Sambuc     L(DAEMON),
254ebfedea0SLionel Sambuc #ifdef LOG_FTP
255ebfedea0SLionel Sambuc     L(FTP),
256ebfedea0SLionel Sambuc #endif
257ebfedea0SLionel Sambuc     L(KERN),
258ebfedea0SLionel Sambuc     L(LPR),
259ebfedea0SLionel Sambuc     L(MAIL),
260ebfedea0SLionel Sambuc #ifdef LOG_NEWS
261ebfedea0SLionel Sambuc     L(NEWS),
262ebfedea0SLionel Sambuc #endif
263ebfedea0SLionel Sambuc     L(SYSLOG),
264ebfedea0SLionel Sambuc     L(USER),
265ebfedea0SLionel Sambuc #ifdef LOG_UUCP
266ebfedea0SLionel Sambuc     L(UUCP),
267ebfedea0SLionel Sambuc #endif
268ebfedea0SLionel Sambuc     L(LOCAL0),
269ebfedea0SLionel Sambuc     L(LOCAL1),
270ebfedea0SLionel Sambuc     L(LOCAL2),
271ebfedea0SLionel Sambuc     L(LOCAL3),
272ebfedea0SLionel Sambuc     L(LOCAL4),
273ebfedea0SLionel Sambuc     L(LOCAL5),
274ebfedea0SLionel Sambuc     L(LOCAL6),
275ebfedea0SLionel Sambuc     L(LOCAL7),
276ebfedea0SLionel Sambuc     { NULL, -1 }
277ebfedea0SLionel Sambuc };
278ebfedea0SLionel Sambuc 
279ebfedea0SLionel Sambuc static int
find_value(const char * s,struct s2i * table)280ebfedea0SLionel Sambuc find_value(const char *s, struct s2i *table)
281ebfedea0SLionel Sambuc {
282ebfedea0SLionel Sambuc     while(table->s && strcasecmp(table->s, s))
283ebfedea0SLionel Sambuc 	table++;
284ebfedea0SLionel Sambuc     return table->val;
285ebfedea0SLionel Sambuc }
286ebfedea0SLionel Sambuc 
287ebfedea0SLionel Sambuc static int
check_log(krb5_context context,const char * path,char * data)288ebfedea0SLionel Sambuc check_log(krb5_context context, const char *path, char *data)
289ebfedea0SLionel Sambuc {
290ebfedea0SLionel Sambuc     /* XXX sync with log.c */
291ebfedea0SLionel Sambuc     int min = 0, max = -1, n;
292ebfedea0SLionel Sambuc     char c;
293ebfedea0SLionel Sambuc     const char *p = data;
294ebfedea0SLionel Sambuc 
295ebfedea0SLionel Sambuc     n = sscanf(p, "%d%c%d/", &min, &c, &max);
296ebfedea0SLionel Sambuc     if(n == 2){
297ebfedea0SLionel Sambuc 	if(c == '/') {
298ebfedea0SLionel Sambuc 	    if(min < 0){
299ebfedea0SLionel Sambuc 		max = -min;
300ebfedea0SLionel Sambuc 		min = 0;
301ebfedea0SLionel Sambuc 	    }else{
302ebfedea0SLionel Sambuc 		max = min;
303ebfedea0SLionel Sambuc 	    }
304ebfedea0SLionel Sambuc 	}
305ebfedea0SLionel Sambuc     }
306ebfedea0SLionel Sambuc     if(n){
307ebfedea0SLionel Sambuc 	p = strchr(p, '/');
308ebfedea0SLionel Sambuc 	if(p == NULL) {
309ebfedea0SLionel Sambuc 	    krb5_warnx(context, "%s: failed to parse \"%s\"", path, data);
310ebfedea0SLionel Sambuc 	    return 1;
311ebfedea0SLionel Sambuc 	}
312ebfedea0SLionel Sambuc 	p++;
313ebfedea0SLionel Sambuc     }
314ebfedea0SLionel Sambuc     if(strcmp(p, "STDERR") == 0 ||
315ebfedea0SLionel Sambuc        strcmp(p, "CONSOLE") == 0 ||
316ebfedea0SLionel Sambuc        (strncmp(p, "FILE", 4) == 0 && (p[4] == ':' || p[4] == '=')) ||
317ebfedea0SLionel Sambuc        (strncmp(p, "DEVICE", 6) == 0 && p[6] == '='))
318ebfedea0SLionel Sambuc 	return 0;
319ebfedea0SLionel Sambuc     if(strncmp(p, "SYSLOG", 6) == 0){
320ebfedea0SLionel Sambuc 	int ret = 0;
321ebfedea0SLionel Sambuc 	char severity[128] = "";
322ebfedea0SLionel Sambuc 	char facility[128] = "";
323ebfedea0SLionel Sambuc 	p += 6;
324ebfedea0SLionel Sambuc 	if(*p != '\0')
325ebfedea0SLionel Sambuc 	    p++;
326ebfedea0SLionel Sambuc 	if(strsep_copy(&p, ":", severity, sizeof(severity)) != -1)
327ebfedea0SLionel Sambuc 	    strsep_copy(&p, ":", facility, sizeof(facility));
328ebfedea0SLionel Sambuc 	if(*severity == '\0')
329ebfedea0SLionel Sambuc 	    strlcpy(severity, "ERR", sizeof(severity));
330ebfedea0SLionel Sambuc  	if(*facility == '\0')
331ebfedea0SLionel Sambuc 	    strlcpy(facility, "AUTH", sizeof(facility));
332ebfedea0SLionel Sambuc 	if(find_value(severity, syslogvals) == -1) {
333ebfedea0SLionel Sambuc 	    krb5_warnx(context, "%s: unknown syslog facility \"%s\"",
334ebfedea0SLionel Sambuc 		       path, facility);
335ebfedea0SLionel Sambuc 	    ret++;
336ebfedea0SLionel Sambuc 	}
337ebfedea0SLionel Sambuc 	if(find_value(severity, syslogvals) == -1) {
338ebfedea0SLionel Sambuc 	    krb5_warnx(context, "%s: unknown syslog severity \"%s\"",
339ebfedea0SLionel Sambuc 		       path, severity);
340ebfedea0SLionel Sambuc 	    ret++;
341ebfedea0SLionel Sambuc 	}
342ebfedea0SLionel Sambuc 	return ret;
343ebfedea0SLionel Sambuc     }else{
344ebfedea0SLionel Sambuc 	krb5_warnx(context, "%s: unknown log type: \"%s\"", path, data);
345ebfedea0SLionel Sambuc 	return 1;
346ebfedea0SLionel Sambuc     }
347ebfedea0SLionel Sambuc }
348ebfedea0SLionel Sambuc 
349ebfedea0SLionel Sambuc typedef int (*check_func_t)(krb5_context, const char*, char*);
350ebfedea0SLionel Sambuc struct entry {
351ebfedea0SLionel Sambuc     const char *name;
352ebfedea0SLionel Sambuc     int type;
353ebfedea0SLionel Sambuc     void *check_data;
354ebfedea0SLionel Sambuc     int deprecated;
355ebfedea0SLionel Sambuc };
356ebfedea0SLionel Sambuc 
357ebfedea0SLionel Sambuc struct entry all_strings[] = {
358ebfedea0SLionel Sambuc     { "", krb5_config_string, NULL },
359ebfedea0SLionel Sambuc     { NULL }
360ebfedea0SLionel Sambuc };
361ebfedea0SLionel Sambuc 
362ebfedea0SLionel Sambuc struct entry all_boolean[] = {
363ebfedea0SLionel Sambuc     { "", krb5_config_string, check_boolean },
364ebfedea0SLionel Sambuc     { NULL }
365ebfedea0SLionel Sambuc };
366ebfedea0SLionel Sambuc 
367ebfedea0SLionel Sambuc 
368ebfedea0SLionel Sambuc struct entry v4_name_convert_entries[] = {
369ebfedea0SLionel Sambuc     { "host", krb5_config_list, all_strings },
370ebfedea0SLionel Sambuc     { "plain", krb5_config_list, all_strings },
371ebfedea0SLionel Sambuc     { NULL }
372ebfedea0SLionel Sambuc };
373ebfedea0SLionel Sambuc 
374ebfedea0SLionel Sambuc struct entry libdefaults_entries[] = {
375ebfedea0SLionel Sambuc     { "accept_null_addresses", krb5_config_string, check_boolean },
376ebfedea0SLionel Sambuc     { "allow_weak_crypto", krb5_config_string, check_boolean },
377ebfedea0SLionel Sambuc     { "capath", krb5_config_list, all_strings, 1 },
378ebfedea0SLionel Sambuc     { "check_pac", krb5_config_string, check_boolean },
379ebfedea0SLionel Sambuc     { "clockskew", krb5_config_string, check_time },
380ebfedea0SLionel Sambuc     { "date_format", krb5_config_string, NULL },
381ebfedea0SLionel Sambuc     { "default_cc_name", krb5_config_string, NULL },
382ebfedea0SLionel Sambuc     { "default_etypes", krb5_config_string, NULL },
383ebfedea0SLionel Sambuc     { "default_etypes_des", krb5_config_string, NULL },
384ebfedea0SLionel Sambuc     { "default_keytab_modify_name", krb5_config_string, NULL },
385ebfedea0SLionel Sambuc     { "default_keytab_name", krb5_config_string, NULL },
386ebfedea0SLionel Sambuc     { "default_realm", krb5_config_string, NULL },
387ebfedea0SLionel Sambuc     { "dns_canonize_hostname", krb5_config_string, check_boolean },
388ebfedea0SLionel Sambuc     { "dns_proxy", krb5_config_string, NULL },
389ebfedea0SLionel Sambuc     { "dns_lookup_kdc", krb5_config_string, check_boolean },
390ebfedea0SLionel Sambuc     { "dns_lookup_realm", krb5_config_string, check_boolean },
391ebfedea0SLionel Sambuc     { "dns_lookup_realm_labels", krb5_config_string, NULL },
392ebfedea0SLionel Sambuc     { "egd_socket", krb5_config_string, NULL },
393ebfedea0SLionel Sambuc     { "encrypt", krb5_config_string, check_boolean },
394ebfedea0SLionel Sambuc     { "extra_addresses", krb5_config_string, NULL },
395ebfedea0SLionel Sambuc     { "fcache_version", krb5_config_string, check_numeric },
396ebfedea0SLionel Sambuc     { "fcc-mit-ticketflags", krb5_config_string, check_boolean },
397ebfedea0SLionel Sambuc     { "forward", krb5_config_string, check_boolean },
398ebfedea0SLionel Sambuc     { "forwardable", krb5_config_string, check_boolean },
399ebfedea0SLionel Sambuc     { "http_proxy", krb5_config_string, check_host /* XXX */ },
400ebfedea0SLionel Sambuc     { "ignore_addresses", krb5_config_string, NULL },
401ebfedea0SLionel Sambuc     { "kdc_timeout", krb5_config_string, check_time },
402ebfedea0SLionel Sambuc     { "kdc_timesync", krb5_config_string, check_boolean },
403ebfedea0SLionel Sambuc     { "log_utc", krb5_config_string, check_boolean },
404ebfedea0SLionel Sambuc     { "maxretries", krb5_config_string, check_numeric },
405ebfedea0SLionel Sambuc     { "scan_interfaces", krb5_config_string, check_boolean },
406ebfedea0SLionel Sambuc     { "srv_lookup", krb5_config_string, check_boolean },
407ebfedea0SLionel Sambuc     { "srv_try_txt", krb5_config_string, check_boolean },
408ebfedea0SLionel Sambuc     { "ticket_lifetime", krb5_config_string, check_time },
409ebfedea0SLionel Sambuc     { "time_format", krb5_config_string, NULL },
410ebfedea0SLionel Sambuc     { "transited_realms_reject", krb5_config_string, NULL },
411ebfedea0SLionel Sambuc     { "no-addresses", krb5_config_string, check_boolean },
412ebfedea0SLionel Sambuc     { "v4_instance_resolve", krb5_config_string, check_boolean },
413ebfedea0SLionel Sambuc     { "v4_name_convert", krb5_config_list, v4_name_convert_entries },
414ebfedea0SLionel Sambuc     { "verify_ap_req_nofail", krb5_config_string, check_boolean },
415ebfedea0SLionel Sambuc     { "max_retries", krb5_config_string, check_time },
416ebfedea0SLionel Sambuc     { "renew_lifetime", krb5_config_string, check_time },
417ebfedea0SLionel Sambuc     { "proxiable", krb5_config_string, check_boolean },
418ebfedea0SLionel Sambuc     { "warn_pwexpire", krb5_config_string, check_time },
419ebfedea0SLionel Sambuc     /* MIT stuff */
420ebfedea0SLionel Sambuc     { "permitted_enctypes", krb5_config_string, mit_entry },
421ebfedea0SLionel Sambuc     { "default_tgs_enctypes", krb5_config_string, mit_entry },
422ebfedea0SLionel Sambuc     { "default_tkt_enctypes", krb5_config_string, mit_entry },
423ebfedea0SLionel Sambuc     { NULL }
424ebfedea0SLionel Sambuc };
425ebfedea0SLionel Sambuc 
426ebfedea0SLionel Sambuc struct entry appdefaults_entries[] = {
427ebfedea0SLionel Sambuc     { "afslog", krb5_config_string, check_boolean },
428ebfedea0SLionel Sambuc     { "afs-use-524", krb5_config_string, check_524 },
429ebfedea0SLionel Sambuc     { "encrypt", krb5_config_string, check_boolean },
430ebfedea0SLionel Sambuc     { "forward", krb5_config_string, check_boolean },
431ebfedea0SLionel Sambuc     { "forwardable", krb5_config_string, check_boolean },
432ebfedea0SLionel Sambuc     { "proxiable", krb5_config_string, check_boolean },
433ebfedea0SLionel Sambuc     { "ticket_lifetime", krb5_config_string, check_time },
434ebfedea0SLionel Sambuc     { "renew_lifetime", krb5_config_string, check_time },
435ebfedea0SLionel Sambuc     { "no-addresses", krb5_config_string, check_boolean },
436ebfedea0SLionel Sambuc     { "krb4_get_tickets", krb5_config_string, check_boolean },
437ebfedea0SLionel Sambuc     { "pkinit_anchors", krb5_config_string, NULL },
438ebfedea0SLionel Sambuc     { "pkinit_win2k", krb5_config_string, NULL },
439ebfedea0SLionel Sambuc     { "pkinit_win2k_require_binding", krb5_config_string, NULL },
440ebfedea0SLionel Sambuc     { "pkinit_require_eku", krb5_config_string, NULL },
441ebfedea0SLionel Sambuc     { "pkinit_require_krbtgt_otherName", krb5_config_string, NULL },
442ebfedea0SLionel Sambuc     { "pkinit_require_hostname_match", krb5_config_string, NULL },
443ebfedea0SLionel Sambuc #if 0
444ebfedea0SLionel Sambuc     { "anonymous", krb5_config_string, check_boolean },
445ebfedea0SLionel Sambuc #endif
446ebfedea0SLionel Sambuc     { "", krb5_config_list, appdefaults_entries },
447ebfedea0SLionel Sambuc     { NULL }
448ebfedea0SLionel Sambuc };
449ebfedea0SLionel Sambuc 
450ebfedea0SLionel Sambuc struct entry realms_entries[] = {
451ebfedea0SLionel Sambuc     { "forwardable", krb5_config_string, check_boolean },
452ebfedea0SLionel Sambuc     { "proxiable", krb5_config_string, check_boolean },
453ebfedea0SLionel Sambuc     { "ticket_lifetime", krb5_config_string, check_time },
454ebfedea0SLionel Sambuc     { "renew_lifetime", krb5_config_string, check_time },
455ebfedea0SLionel Sambuc     { "warn_pwexpire", krb5_config_string, check_time },
456ebfedea0SLionel Sambuc     { "kdc", krb5_config_string, check_host },
457ebfedea0SLionel Sambuc     { "admin_server", krb5_config_string, check_host },
458ebfedea0SLionel Sambuc     { "kpasswd_server", krb5_config_string, check_host },
459ebfedea0SLionel Sambuc     { "krb524_server", krb5_config_string, check_host },
460ebfedea0SLionel Sambuc     { "v4_name_convert", krb5_config_list, v4_name_convert_entries },
461ebfedea0SLionel Sambuc     { "v4_instance_convert", krb5_config_list, all_strings },
462ebfedea0SLionel Sambuc     { "v4_domains", krb5_config_string, NULL },
463ebfedea0SLionel Sambuc     { "default_domain", krb5_config_string, NULL },
464ebfedea0SLionel Sambuc     { "win2k_pkinit", krb5_config_string, NULL },
465ebfedea0SLionel Sambuc     /* MIT stuff */
466ebfedea0SLionel Sambuc     { "admin_keytab", krb5_config_string, mit_entry },
467ebfedea0SLionel Sambuc     { "acl_file", krb5_config_string, mit_entry },
468ebfedea0SLionel Sambuc     { "dict_file", krb5_config_string, mit_entry },
469ebfedea0SLionel Sambuc     { "kadmind_port", krb5_config_string, mit_entry },
470ebfedea0SLionel Sambuc     { "kpasswd_port", krb5_config_string, mit_entry },
471ebfedea0SLionel Sambuc     { "master_key_name", krb5_config_string, mit_entry },
472ebfedea0SLionel Sambuc     { "master_key_type", krb5_config_string, mit_entry },
473ebfedea0SLionel Sambuc     { "key_stash_file", krb5_config_string, mit_entry },
474ebfedea0SLionel Sambuc     { "max_life", krb5_config_string, mit_entry },
475ebfedea0SLionel Sambuc     { "max_renewable_life", krb5_config_string, mit_entry },
476ebfedea0SLionel Sambuc     { "default_principal_expiration", krb5_config_string, mit_entry },
477ebfedea0SLionel Sambuc     { "default_principal_flags", krb5_config_string, mit_entry },
478ebfedea0SLionel Sambuc     { "supported_enctypes", krb5_config_string, mit_entry },
479ebfedea0SLionel Sambuc     { "database_name", krb5_config_string, mit_entry },
480ebfedea0SLionel Sambuc     { NULL }
481ebfedea0SLionel Sambuc };
482ebfedea0SLionel Sambuc 
483ebfedea0SLionel Sambuc struct entry realms_foobar[] = {
484ebfedea0SLionel Sambuc     { "", krb5_config_list, realms_entries },
485ebfedea0SLionel Sambuc     { NULL }
486ebfedea0SLionel Sambuc };
487ebfedea0SLionel Sambuc 
488ebfedea0SLionel Sambuc 
489ebfedea0SLionel Sambuc struct entry kdc_database_entries[] = {
490ebfedea0SLionel Sambuc     { "realm", krb5_config_string, NULL },
491ebfedea0SLionel Sambuc     { "dbname", krb5_config_string, NULL },
492ebfedea0SLionel Sambuc     { "mkey_file", krb5_config_string, NULL },
493ebfedea0SLionel Sambuc     { "acl_file", krb5_config_string, NULL },
494ebfedea0SLionel Sambuc     { "log_file", krb5_config_string, NULL },
495ebfedea0SLionel Sambuc     { NULL }
496ebfedea0SLionel Sambuc };
497ebfedea0SLionel Sambuc 
498ebfedea0SLionel Sambuc struct entry kdc_entries[] = {
499ebfedea0SLionel Sambuc     { "database", krb5_config_list, kdc_database_entries },
500ebfedea0SLionel Sambuc     { "key-file", krb5_config_string, NULL },
501ebfedea0SLionel Sambuc     { "logging", krb5_config_string, check_log },
502ebfedea0SLionel Sambuc     { "max-request", krb5_config_string, check_bytes },
503ebfedea0SLionel Sambuc     { "require-preauth", krb5_config_string, check_boolean },
504ebfedea0SLionel Sambuc     { "ports", krb5_config_string, NULL },
505ebfedea0SLionel Sambuc     { "addresses", krb5_config_string, NULL },
506ebfedea0SLionel Sambuc     { "enable-kerberos4", krb5_config_string, check_boolean },
507ebfedea0SLionel Sambuc     { "enable-524", krb5_config_string, check_boolean },
508ebfedea0SLionel Sambuc     { "enable-http", krb5_config_string, check_boolean },
509ebfedea0SLionel Sambuc     { "check-ticket-addresses", krb5_config_string, check_boolean },
510ebfedea0SLionel Sambuc     { "allow-null-ticket-addresses", krb5_config_string, check_boolean },
511ebfedea0SLionel Sambuc     { "allow-anonymous", krb5_config_string, check_boolean },
512ebfedea0SLionel Sambuc     { "v4_realm", krb5_config_string, NULL },
513*0a6a1f1dSLionel Sambuc     { "enable-kaserver", krb5_config_string, check_boolean, 1 },
514ebfedea0SLionel Sambuc     { "encode_as_rep_as_tgs_rep", krb5_config_string, check_boolean },
515ebfedea0SLionel Sambuc     { "kdc_warn_pwexpire", krb5_config_string, check_time },
516ebfedea0SLionel Sambuc     { "use_2b", krb5_config_list, NULL },
517ebfedea0SLionel Sambuc     { "enable-pkinit", krb5_config_string, check_boolean },
518ebfedea0SLionel Sambuc     { "pkinit_identity", krb5_config_string, NULL },
519ebfedea0SLionel Sambuc     { "pkinit_anchors", krb5_config_string, NULL },
520ebfedea0SLionel Sambuc     { "pkinit_pool", krb5_config_string, NULL },
521ebfedea0SLionel Sambuc     { "pkinit_revoke", krb5_config_string, NULL },
522ebfedea0SLionel Sambuc     { "pkinit_kdc_ocsp", krb5_config_string, NULL },
523ebfedea0SLionel Sambuc     { "pkinit_principal_in_certificate", krb5_config_string, NULL },
524ebfedea0SLionel Sambuc     { "pkinit_dh_min_bits", krb5_config_string, NULL },
525ebfedea0SLionel Sambuc     { "pkinit_allow_proxy_certificate", krb5_config_string, NULL },
526ebfedea0SLionel Sambuc     { "hdb-ldap-create-base", krb5_config_string, NULL },
527ebfedea0SLionel Sambuc     { "v4-realm", krb5_config_string, NULL },
528ebfedea0SLionel Sambuc     { NULL }
529ebfedea0SLionel Sambuc };
530ebfedea0SLionel Sambuc 
531ebfedea0SLionel Sambuc struct entry kadmin_entries[] = {
532ebfedea0SLionel Sambuc     { "password_lifetime", krb5_config_string, check_time },
533ebfedea0SLionel Sambuc     { "default_keys", krb5_config_string, NULL },
534ebfedea0SLionel Sambuc     { "use_v4_salt", krb5_config_string, NULL },
535ebfedea0SLionel Sambuc     { "require-preauth", krb5_config_string, check_boolean },
536ebfedea0SLionel Sambuc     { NULL }
537ebfedea0SLionel Sambuc };
538ebfedea0SLionel Sambuc struct entry log_strings[] = {
539ebfedea0SLionel Sambuc     { "", krb5_config_string, check_log },
540ebfedea0SLionel Sambuc     { NULL }
541ebfedea0SLionel Sambuc };
542ebfedea0SLionel Sambuc 
543ebfedea0SLionel Sambuc 
544ebfedea0SLionel Sambuc /* MIT stuff */
545ebfedea0SLionel Sambuc struct entry kdcdefaults_entries[] = {
546ebfedea0SLionel Sambuc     { "kdc_ports", krb5_config_string, mit_entry },
547ebfedea0SLionel Sambuc     { "v4_mode", krb5_config_string, mit_entry },
548ebfedea0SLionel Sambuc     { NULL }
549ebfedea0SLionel Sambuc };
550ebfedea0SLionel Sambuc 
551ebfedea0SLionel Sambuc struct entry capaths_entries[] = {
552ebfedea0SLionel Sambuc     { "", krb5_config_list, all_strings },
553ebfedea0SLionel Sambuc     { NULL }
554ebfedea0SLionel Sambuc };
555ebfedea0SLionel Sambuc 
556ebfedea0SLionel Sambuc struct entry password_quality_entries[] = {
557ebfedea0SLionel Sambuc     { "policies", krb5_config_string, NULL },
558ebfedea0SLionel Sambuc     { "external_program", krb5_config_string, NULL },
559ebfedea0SLionel Sambuc     { "min_classes", krb5_config_string, check_numeric },
560ebfedea0SLionel Sambuc     { "min_length", krb5_config_string, check_numeric },
561ebfedea0SLionel Sambuc     { "", krb5_config_list, all_strings },
562ebfedea0SLionel Sambuc     { NULL }
563ebfedea0SLionel Sambuc };
564ebfedea0SLionel Sambuc 
565ebfedea0SLionel Sambuc struct entry toplevel_sections[] = {
566ebfedea0SLionel Sambuc     { "libdefaults" , krb5_config_list, libdefaults_entries },
567ebfedea0SLionel Sambuc     { "realms", krb5_config_list, realms_foobar },
568ebfedea0SLionel Sambuc     { "domain_realm", krb5_config_list, all_strings },
569ebfedea0SLionel Sambuc     { "logging", krb5_config_list, log_strings },
570ebfedea0SLionel Sambuc     { "kdc", krb5_config_list, kdc_entries },
571ebfedea0SLionel Sambuc     { "kadmin", krb5_config_list, kadmin_entries },
572ebfedea0SLionel Sambuc     { "appdefaults", krb5_config_list, appdefaults_entries },
573ebfedea0SLionel Sambuc     { "gssapi", krb5_config_list, NULL },
574ebfedea0SLionel Sambuc     { "capaths", krb5_config_list, capaths_entries },
575ebfedea0SLionel Sambuc     { "password_quality", krb5_config_list, password_quality_entries },
576ebfedea0SLionel Sambuc     /* MIT stuff */
577ebfedea0SLionel Sambuc     { "kdcdefaults", krb5_config_list, kdcdefaults_entries },
578ebfedea0SLionel Sambuc     { NULL }
579ebfedea0SLionel Sambuc };
580ebfedea0SLionel Sambuc 
581ebfedea0SLionel Sambuc 
582ebfedea0SLionel Sambuc static int
check_section(krb5_context context,const char * path,krb5_config_section * cf,struct entry * entries)583ebfedea0SLionel Sambuc check_section(krb5_context context, const char *path, krb5_config_section *cf,
584ebfedea0SLionel Sambuc 	      struct entry *entries)
585ebfedea0SLionel Sambuc {
586ebfedea0SLionel Sambuc     int error = 0;
587ebfedea0SLionel Sambuc     krb5_config_section *p;
588ebfedea0SLionel Sambuc     struct entry *e;
589ebfedea0SLionel Sambuc 
590ebfedea0SLionel Sambuc     char *local;
591ebfedea0SLionel Sambuc 
592ebfedea0SLionel Sambuc     for(p = cf; p != NULL; p = p->next) {
593ebfedea0SLionel Sambuc 	local = NULL;
594ebfedea0SLionel Sambuc 	if (asprintf(&local, "%s/%s", path, p->name) < 0 || local == NULL)
595ebfedea0SLionel Sambuc 	    errx(1, "out of memory");
596ebfedea0SLionel Sambuc 	for(e = entries; e->name != NULL; e++) {
597ebfedea0SLionel Sambuc 	    if(*e->name == '\0' || strcmp(e->name, p->name) == 0) {
598ebfedea0SLionel Sambuc 		if(e->type != p->type) {
599ebfedea0SLionel Sambuc 		    krb5_warnx(context, "%s: unknown or wrong type", local);
600ebfedea0SLionel Sambuc 		    error |= 1;
601ebfedea0SLionel Sambuc 		} else if(p->type == krb5_config_string && e->check_data != NULL) {
602ebfedea0SLionel Sambuc 		    error |= (*(check_func_t)e->check_data)(context, local, p->u.string);
603ebfedea0SLionel Sambuc 		} else if(p->type == krb5_config_list && e->check_data != NULL) {
604ebfedea0SLionel Sambuc 		    error |= check_section(context, local, p->u.list, e->check_data);
605ebfedea0SLionel Sambuc 		}
606ebfedea0SLionel Sambuc 		if(e->deprecated) {
607ebfedea0SLionel Sambuc 		    krb5_warnx(context, "%s: is a deprecated entry", local);
608ebfedea0SLionel Sambuc 		    error |= 1;
609ebfedea0SLionel Sambuc 		}
610ebfedea0SLionel Sambuc 		break;
611ebfedea0SLionel Sambuc 	    }
612ebfedea0SLionel Sambuc 	}
613ebfedea0SLionel Sambuc 	if(e->name == NULL) {
614ebfedea0SLionel Sambuc 	    krb5_warnx(context, "%s: unknown entry", local);
615ebfedea0SLionel Sambuc 	    error |= 1;
616ebfedea0SLionel Sambuc 	}
617ebfedea0SLionel Sambuc 	free(local);
618ebfedea0SLionel Sambuc     }
619ebfedea0SLionel Sambuc     return error;
620ebfedea0SLionel Sambuc }
621ebfedea0SLionel Sambuc 
622ebfedea0SLionel Sambuc 
623ebfedea0SLionel Sambuc static void
dumpconfig(int level,krb5_config_section * top)624ebfedea0SLionel Sambuc dumpconfig(int level, krb5_config_section *top)
625ebfedea0SLionel Sambuc {
626ebfedea0SLionel Sambuc     krb5_config_section *x;
627ebfedea0SLionel Sambuc     for(x = top; x; x = x->next) {
628ebfedea0SLionel Sambuc 	switch(x->type) {
629ebfedea0SLionel Sambuc 	case krb5_config_list:
630ebfedea0SLionel Sambuc 	    if(level == 0) {
631ebfedea0SLionel Sambuc 		printf("[%s]\n", x->name);
632ebfedea0SLionel Sambuc 	    } else {
633ebfedea0SLionel Sambuc 		printf("%*s%s = {\n", 4 * level, " ", x->name);
634ebfedea0SLionel Sambuc 	    }
635ebfedea0SLionel Sambuc 	    dumpconfig(level + 1, x->u.list);
636ebfedea0SLionel Sambuc 	    if(level > 0)
637ebfedea0SLionel Sambuc 		printf("%*s}\n", 4 * level, " ");
638ebfedea0SLionel Sambuc 	    break;
639ebfedea0SLionel Sambuc 	case krb5_config_string:
640ebfedea0SLionel Sambuc 	    printf("%*s%s = %s\n", 4 * level, " ", x->name, x->u.string);
641ebfedea0SLionel Sambuc 	    break;
642ebfedea0SLionel Sambuc 	}
643ebfedea0SLionel Sambuc     }
644ebfedea0SLionel Sambuc }
645ebfedea0SLionel Sambuc 
646ebfedea0SLionel Sambuc int
main(int argc,char ** argv)647ebfedea0SLionel Sambuc main(int argc, char **argv)
648ebfedea0SLionel Sambuc {
649ebfedea0SLionel Sambuc     krb5_context context;
650ebfedea0SLionel Sambuc     krb5_error_code ret;
651ebfedea0SLionel Sambuc     krb5_config_section *tmp_cf;
652ebfedea0SLionel Sambuc     int optidx = 0;
653ebfedea0SLionel Sambuc 
654ebfedea0SLionel Sambuc     setprogname (argv[0]);
655ebfedea0SLionel Sambuc 
656ebfedea0SLionel Sambuc     ret = krb5_init_context(&context);
657ebfedea0SLionel Sambuc     if (ret == KRB5_CONFIG_BADFORMAT)
658ebfedea0SLionel Sambuc 	errx (1, "krb5_init_context failed to parse configuration file");
659ebfedea0SLionel Sambuc     else if (ret)
660ebfedea0SLionel Sambuc 	errx (1, "krb5_init_context failed with %d", ret);
661ebfedea0SLionel Sambuc 
662ebfedea0SLionel Sambuc     if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
663ebfedea0SLionel Sambuc 	usage(1);
664ebfedea0SLionel Sambuc 
665ebfedea0SLionel Sambuc     if (help_flag)
666ebfedea0SLionel Sambuc 	usage (0);
667ebfedea0SLionel Sambuc 
668ebfedea0SLionel Sambuc     if(version_flag){
669ebfedea0SLionel Sambuc 	print_version(NULL);
670ebfedea0SLionel Sambuc 	exit(0);
671ebfedea0SLionel Sambuc     }
672ebfedea0SLionel Sambuc 
673ebfedea0SLionel Sambuc     argc -= optidx;
674ebfedea0SLionel Sambuc     argv += optidx;
675ebfedea0SLionel Sambuc 
676ebfedea0SLionel Sambuc     tmp_cf = NULL;
677ebfedea0SLionel Sambuc     if(argc == 0)
678ebfedea0SLionel Sambuc 	krb5_get_default_config_files(&argv);
679ebfedea0SLionel Sambuc 
680ebfedea0SLionel Sambuc     while(*argv) {
681ebfedea0SLionel Sambuc 	ret = krb5_config_parse_file_multi(context, *argv, &tmp_cf);
682ebfedea0SLionel Sambuc 	if (ret != 0)
683ebfedea0SLionel Sambuc 	    krb5_warn (context, ret, "krb5_config_parse_file");
684ebfedea0SLionel Sambuc 	argv++;
685ebfedea0SLionel Sambuc     }
686ebfedea0SLionel Sambuc 
687ebfedea0SLionel Sambuc     if(dumpconfig_flag)
688ebfedea0SLionel Sambuc 	dumpconfig(0, tmp_cf);
689ebfedea0SLionel Sambuc 
690ebfedea0SLionel Sambuc     return check_section(context, "", tmp_cf, toplevel_sections);
691ebfedea0SLionel Sambuc }
692