1b528cefcSMark Murray /*
2ae771770SStanislav Sedov * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
3b528cefcSMark Murray * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray * All rights reserved.
5b528cefcSMark Murray *
6b528cefcSMark Murray * Redistribution and use in source and binary forms, with or without
7b528cefcSMark Murray * modification, are permitted provided that the following conditions
8b528cefcSMark Murray * are met:
9b528cefcSMark Murray *
10b528cefcSMark Murray * 1. Redistributions of source code must retain the above copyright
11b528cefcSMark Murray * notice, this list of conditions and the following disclaimer.
12b528cefcSMark Murray *
13b528cefcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright
14b528cefcSMark Murray * notice, this list of conditions and the following disclaimer in the
15b528cefcSMark Murray * documentation and/or other materials provided with the distribution.
16b528cefcSMark Murray *
17b528cefcSMark Murray * 3. Neither the name of the Institute nor the names of its contributors
18b528cefcSMark Murray * may be used to endorse or promote products derived from this software
19b528cefcSMark Murray * without specific prior written permission.
20b528cefcSMark Murray *
21b528cefcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22b528cefcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23b528cefcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24b528cefcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25b528cefcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26b528cefcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27b528cefcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28b528cefcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29b528cefcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30b528cefcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31b528cefcSMark Murray * SUCH DAMAGE.
32b528cefcSMark Murray */
33b528cefcSMark Murray
34b528cefcSMark Murray #include "krb5_locl.h"
35b528cefcSMark Murray #include <getarg.h>
364137ff4cSJacques Vidrine #include <parse_bytes.h>
374137ff4cSJacques Vidrine #include <err.h>
38b528cefcSMark Murray
39b528cefcSMark Murray /* verify krb5.conf */
40b528cefcSMark Murray
418373020dSJacques Vidrine static int dumpconfig_flag = 0;
42b528cefcSMark Murray static int version_flag = 0;
43b528cefcSMark Murray static int help_flag = 0;
44c19800e8SDoug Rabson static int warn_mit_syntax_flag = 0;
45b528cefcSMark Murray
46b528cefcSMark Murray static struct getargs args[] = {
478373020dSJacques Vidrine {"dumpconfig", 0, arg_flag, &dumpconfig_flag,
488373020dSJacques Vidrine "show the parsed config files", NULL },
49c19800e8SDoug Rabson {"warn-mit-syntax", 0, arg_flag, &warn_mit_syntax_flag,
50c19800e8SDoug Rabson "show the parsed config files", NULL },
51b528cefcSMark Murray {"version", 0, arg_flag, &version_flag,
52b528cefcSMark Murray "print version", NULL },
53b528cefcSMark Murray {"help", 0, arg_flag, &help_flag,
54b528cefcSMark Murray NULL, NULL }
55b528cefcSMark Murray };
56b528cefcSMark Murray
57b528cefcSMark Murray static void
usage(int ret)58b528cefcSMark Murray usage (int ret)
59b528cefcSMark Murray {
60b528cefcSMark Murray arg_printusage (args,
61b528cefcSMark Murray sizeof(args)/sizeof(*args),
62b528cefcSMark Murray NULL,
63b528cefcSMark Murray "[config-file]");
64b528cefcSMark Murray exit (ret);
65b528cefcSMark Murray }
66b528cefcSMark Murray
674137ff4cSJacques Vidrine static int
check_bytes(krb5_context context,const char * path,char * data)684137ff4cSJacques Vidrine check_bytes(krb5_context context, const char *path, char *data)
694137ff4cSJacques Vidrine {
704137ff4cSJacques Vidrine if(parse_bytes(data, NULL) == -1) {
714137ff4cSJacques Vidrine krb5_warnx(context, "%s: failed to parse \"%s\" as size", path, data);
724137ff4cSJacques Vidrine return 1;
734137ff4cSJacques Vidrine }
744137ff4cSJacques Vidrine return 0;
754137ff4cSJacques Vidrine }
764137ff4cSJacques Vidrine
774137ff4cSJacques Vidrine static int
check_time(krb5_context context,const char * path,char * data)784137ff4cSJacques Vidrine check_time(krb5_context context, const char *path, char *data)
794137ff4cSJacques Vidrine {
804137ff4cSJacques Vidrine if(parse_time(data, NULL) == -1) {
814137ff4cSJacques Vidrine krb5_warnx(context, "%s: failed to parse \"%s\" as time", path, data);
824137ff4cSJacques Vidrine return 1;
834137ff4cSJacques Vidrine }
844137ff4cSJacques Vidrine return 0;
854137ff4cSJacques Vidrine }
864137ff4cSJacques Vidrine
874137ff4cSJacques Vidrine static int
check_numeric(krb5_context context,const char * path,char * data)884137ff4cSJacques Vidrine check_numeric(krb5_context context, const char *path, char *data)
894137ff4cSJacques Vidrine {
90ae771770SStanislav Sedov long v;
914137ff4cSJacques Vidrine char *end;
924137ff4cSJacques Vidrine v = strtol(data, &end, 0);
93ae771770SStanislav Sedov
94ae771770SStanislav Sedov if ((v == LONG_MIN || v == LONG_MAX) && errno != 0) {
95ae771770SStanislav Sedov krb5_warnx(context, "%s: over/under flow for \"%s\"",
96ae771770SStanislav Sedov path, data);
97ae771770SStanislav Sedov return 1;
98ae771770SStanislav Sedov }
994137ff4cSJacques Vidrine if(*end != '\0') {
1004137ff4cSJacques Vidrine krb5_warnx(context, "%s: failed to parse \"%s\" as a number",
1014137ff4cSJacques Vidrine path, data);
1024137ff4cSJacques Vidrine return 1;
1034137ff4cSJacques Vidrine }
1044137ff4cSJacques Vidrine return 0;
1054137ff4cSJacques Vidrine }
1064137ff4cSJacques Vidrine
1074137ff4cSJacques Vidrine static int
check_boolean(krb5_context context,const char * path,char * data)1084137ff4cSJacques Vidrine check_boolean(krb5_context context, const char *path, char *data)
1094137ff4cSJacques Vidrine {
1104137ff4cSJacques Vidrine long int v;
1114137ff4cSJacques Vidrine char *end;
1124137ff4cSJacques Vidrine if(strcasecmp(data, "yes") == 0 ||
1134137ff4cSJacques Vidrine strcasecmp(data, "true") == 0 ||
1144137ff4cSJacques Vidrine strcasecmp(data, "no") == 0 ||
1154137ff4cSJacques Vidrine strcasecmp(data, "false") == 0)
1164137ff4cSJacques Vidrine return 0;
1174137ff4cSJacques Vidrine v = strtol(data, &end, 0);
1184137ff4cSJacques Vidrine if(*end != '\0') {
1194137ff4cSJacques Vidrine krb5_warnx(context, "%s: failed to parse \"%s\" as a boolean",
1204137ff4cSJacques Vidrine path, data);
1214137ff4cSJacques Vidrine return 1;
1224137ff4cSJacques Vidrine }
1238373020dSJacques Vidrine if(v != 0 && v != 1)
1248373020dSJacques Vidrine krb5_warnx(context, "%s: numeric value \"%s\" is treated as \"true\"",
1258373020dSJacques Vidrine path, data);
1264137ff4cSJacques Vidrine return 0;
1274137ff4cSJacques Vidrine }
1284137ff4cSJacques Vidrine
1294137ff4cSJacques Vidrine static int
check_524(krb5_context context,const char * path,char * data)130bbd80c28SJacques Vidrine check_524(krb5_context context, const char *path, char *data)
131bbd80c28SJacques Vidrine {
132bbd80c28SJacques Vidrine if(strcasecmp(data, "yes") == 0 ||
133bbd80c28SJacques Vidrine strcasecmp(data, "no") == 0 ||
134bbd80c28SJacques Vidrine strcasecmp(data, "2b") == 0 ||
135bbd80c28SJacques Vidrine strcasecmp(data, "local") == 0)
136bbd80c28SJacques Vidrine return 0;
137bbd80c28SJacques Vidrine
138bbd80c28SJacques Vidrine krb5_warnx(context, "%s: didn't contain a valid option `%s'",
139bbd80c28SJacques Vidrine path, data);
140bbd80c28SJacques Vidrine return 1;
141bbd80c28SJacques Vidrine }
142bbd80c28SJacques Vidrine
143bbd80c28SJacques Vidrine static int
check_host(krb5_context context,const char * path,char * data)1444137ff4cSJacques Vidrine check_host(krb5_context context, const char *path, char *data)
1454137ff4cSJacques Vidrine {
1464137ff4cSJacques Vidrine int ret;
1474137ff4cSJacques Vidrine char hostname[128];
1484137ff4cSJacques Vidrine const char *p = data;
149c19800e8SDoug Rabson struct addrinfo hints;
150c19800e8SDoug Rabson char service[32];
151c19800e8SDoug Rabson int defport;
1524137ff4cSJacques Vidrine struct addrinfo *ai;
153c19800e8SDoug Rabson
154c19800e8SDoug Rabson hints.ai_flags = 0;
155c19800e8SDoug Rabson hints.ai_family = PF_UNSPEC;
156c19800e8SDoug Rabson hints.ai_socktype = 0;
157c19800e8SDoug Rabson hints.ai_protocol = 0;
158c19800e8SDoug Rabson
159c19800e8SDoug Rabson hints.ai_addrlen = 0;
160c19800e8SDoug Rabson hints.ai_canonname = NULL;
161c19800e8SDoug Rabson hints.ai_addr = NULL;
162c19800e8SDoug Rabson hints.ai_next = NULL;
163c19800e8SDoug Rabson
1644137ff4cSJacques Vidrine /* XXX data could be a list of hosts that this code can't handle */
1654137ff4cSJacques Vidrine /* XXX copied from krbhst.c */
1664137ff4cSJacques Vidrine if(strncmp(p, "http://", 7) == 0){
1674137ff4cSJacques Vidrine p += 7;
168c19800e8SDoug Rabson hints.ai_socktype = SOCK_STREAM;
169c19800e8SDoug Rabson strlcpy(service, "http", sizeof(service));
170c19800e8SDoug Rabson defport = 80;
1714137ff4cSJacques Vidrine } else if(strncmp(p, "http/", 5) == 0) {
1724137ff4cSJacques Vidrine p += 5;
173c19800e8SDoug Rabson hints.ai_socktype = SOCK_STREAM;
174c19800e8SDoug Rabson strlcpy(service, "http", sizeof(service));
175c19800e8SDoug Rabson defport = 80;
1764137ff4cSJacques Vidrine }else if(strncmp(p, "tcp/", 4) == 0){
1774137ff4cSJacques Vidrine p += 4;
178c19800e8SDoug Rabson hints.ai_socktype = SOCK_STREAM;
179c19800e8SDoug Rabson strlcpy(service, "kerberos", sizeof(service));
180c19800e8SDoug Rabson defport = 88;
1814137ff4cSJacques Vidrine } else if(strncmp(p, "udp/", 4) == 0) {
1824137ff4cSJacques Vidrine p += 4;
183c19800e8SDoug Rabson hints.ai_socktype = SOCK_DGRAM;
184c19800e8SDoug Rabson strlcpy(service, "kerberos", sizeof(service));
185c19800e8SDoug Rabson defport = 88;
186c19800e8SDoug Rabson } else {
187c19800e8SDoug Rabson hints.ai_socktype = SOCK_DGRAM;
188c19800e8SDoug Rabson strlcpy(service, "kerberos", sizeof(service));
189c19800e8SDoug Rabson defport = 88;
1904137ff4cSJacques Vidrine }
1914137ff4cSJacques Vidrine if(strsep_copy(&p, ":", hostname, sizeof(hostname)) < 0) {
1924137ff4cSJacques Vidrine return 1;
1934137ff4cSJacques Vidrine }
1944137ff4cSJacques Vidrine hostname[strcspn(hostname, "/")] = '\0';
195c19800e8SDoug Rabson if(p != NULL) {
196c19800e8SDoug Rabson char *end;
197c19800e8SDoug Rabson int tmp = strtol(p, &end, 0);
198c19800e8SDoug Rabson if(end == p) {
199c19800e8SDoug Rabson krb5_warnx(context, "%s: failed to parse port number in %s",
200c19800e8SDoug Rabson path, data);
201c19800e8SDoug Rabson return 1;
202c19800e8SDoug Rabson }
203c19800e8SDoug Rabson defport = tmp;
204c19800e8SDoug Rabson snprintf(service, sizeof(service), "%u", defport);
205c19800e8SDoug Rabson }
206c19800e8SDoug Rabson ret = getaddrinfo(hostname, service, &hints, &ai);
207c19800e8SDoug Rabson if(ret == EAI_SERVICE && !isdigit((unsigned char)service[0])) {
208c19800e8SDoug Rabson snprintf(service, sizeof(service), "%u", defport);
209c19800e8SDoug Rabson ret = getaddrinfo(hostname, service, &hints, &ai);
210c19800e8SDoug Rabson }
2114137ff4cSJacques Vidrine if(ret != 0) {
2124137ff4cSJacques Vidrine krb5_warnx(context, "%s: %s (%s)", path, gai_strerror(ret), hostname);
2134137ff4cSJacques Vidrine return 1;
2144137ff4cSJacques Vidrine }
2154137ff4cSJacques Vidrine return 0;
2164137ff4cSJacques Vidrine }
2174137ff4cSJacques Vidrine
2188373020dSJacques Vidrine static int
mit_entry(krb5_context context,const char * path,char * data)2198373020dSJacques Vidrine mit_entry(krb5_context context, const char *path, char *data)
2208373020dSJacques Vidrine {
221c19800e8SDoug Rabson if (warn_mit_syntax_flag)
2228373020dSJacques Vidrine krb5_warnx(context, "%s is only used by MIT Kerberos", path);
2238373020dSJacques Vidrine return 0;
2248373020dSJacques Vidrine }
2258373020dSJacques Vidrine
2268373020dSJacques Vidrine struct s2i {
227c19800e8SDoug Rabson const char *s;
2288373020dSJacques Vidrine int val;
2298373020dSJacques Vidrine };
2308373020dSJacques Vidrine
2318373020dSJacques Vidrine #define L(X) { #X, LOG_ ## X }
2328373020dSJacques Vidrine
2338373020dSJacques Vidrine static struct s2i syslogvals[] = {
234bbd80c28SJacques Vidrine /* severity */
2358373020dSJacques Vidrine L(EMERG),
2368373020dSJacques Vidrine L(ALERT),
2378373020dSJacques Vidrine L(CRIT),
2388373020dSJacques Vidrine L(ERR),
2398373020dSJacques Vidrine L(WARNING),
2408373020dSJacques Vidrine L(NOTICE),
2418373020dSJacques Vidrine L(INFO),
2428373020dSJacques Vidrine L(DEBUG),
243bbd80c28SJacques Vidrine /* facility */
2448373020dSJacques Vidrine L(AUTH),
2458373020dSJacques Vidrine #ifdef LOG_AUTHPRIV
2468373020dSJacques Vidrine L(AUTHPRIV),
2478373020dSJacques Vidrine #endif
2488373020dSJacques Vidrine #ifdef LOG_CRON
2498373020dSJacques Vidrine L(CRON),
2508373020dSJacques Vidrine #endif
2518373020dSJacques Vidrine L(DAEMON),
2528373020dSJacques Vidrine #ifdef LOG_FTP
2538373020dSJacques Vidrine L(FTP),
2548373020dSJacques Vidrine #endif
2558373020dSJacques Vidrine L(KERN),
2568373020dSJacques Vidrine L(LPR),
2578373020dSJacques Vidrine L(MAIL),
2588373020dSJacques Vidrine #ifdef LOG_NEWS
2598373020dSJacques Vidrine L(NEWS),
2608373020dSJacques Vidrine #endif
2618373020dSJacques Vidrine L(SYSLOG),
2628373020dSJacques Vidrine L(USER),
2638373020dSJacques Vidrine #ifdef LOG_UUCP
2648373020dSJacques Vidrine L(UUCP),
2658373020dSJacques Vidrine #endif
2668373020dSJacques Vidrine L(LOCAL0),
2678373020dSJacques Vidrine L(LOCAL1),
2688373020dSJacques Vidrine L(LOCAL2),
2698373020dSJacques Vidrine L(LOCAL3),
2708373020dSJacques Vidrine L(LOCAL4),
2718373020dSJacques Vidrine L(LOCAL5),
2728373020dSJacques Vidrine L(LOCAL6),
2738373020dSJacques Vidrine L(LOCAL7),
2748373020dSJacques Vidrine { NULL, -1 }
2758373020dSJacques Vidrine };
2768373020dSJacques Vidrine
2778373020dSJacques Vidrine static int
find_value(const char * s,struct s2i * table)2788373020dSJacques Vidrine find_value(const char *s, struct s2i *table)
2798373020dSJacques Vidrine {
2808373020dSJacques Vidrine while(table->s && strcasecmp(table->s, s))
2818373020dSJacques Vidrine table++;
2828373020dSJacques Vidrine return table->val;
2838373020dSJacques Vidrine }
2848373020dSJacques Vidrine
2858373020dSJacques Vidrine static int
check_log(krb5_context context,const char * path,char * data)2868373020dSJacques Vidrine check_log(krb5_context context, const char *path, char *data)
2878373020dSJacques Vidrine {
2888373020dSJacques Vidrine /* XXX sync with log.c */
2898373020dSJacques Vidrine int min = 0, max = -1, n;
2908373020dSJacques Vidrine char c;
2918373020dSJacques Vidrine const char *p = data;
2928373020dSJacques Vidrine
2938373020dSJacques Vidrine n = sscanf(p, "%d%c%d/", &min, &c, &max);
2948373020dSJacques Vidrine if(n == 2){
2958373020dSJacques Vidrine if(c == '/') {
2968373020dSJacques Vidrine if(min < 0){
2978373020dSJacques Vidrine max = -min;
2988373020dSJacques Vidrine min = 0;
2998373020dSJacques Vidrine }else{
3008373020dSJacques Vidrine max = min;
3018373020dSJacques Vidrine }
3028373020dSJacques Vidrine }
3038373020dSJacques Vidrine }
3048373020dSJacques Vidrine if(n){
3058373020dSJacques Vidrine p = strchr(p, '/');
3068373020dSJacques Vidrine if(p == NULL) {
3078373020dSJacques Vidrine krb5_warnx(context, "%s: failed to parse \"%s\"", path, data);
3088373020dSJacques Vidrine return 1;
3098373020dSJacques Vidrine }
3108373020dSJacques Vidrine p++;
3118373020dSJacques Vidrine }
3128373020dSJacques Vidrine if(strcmp(p, "STDERR") == 0 ||
3138373020dSJacques Vidrine strcmp(p, "CONSOLE") == 0 ||
3148373020dSJacques Vidrine (strncmp(p, "FILE", 4) == 0 && (p[4] == ':' || p[4] == '=')) ||
3158373020dSJacques Vidrine (strncmp(p, "DEVICE", 6) == 0 && p[6] == '='))
3168373020dSJacques Vidrine return 0;
3178373020dSJacques Vidrine if(strncmp(p, "SYSLOG", 6) == 0){
3188373020dSJacques Vidrine int ret = 0;
3198373020dSJacques Vidrine char severity[128] = "";
3208373020dSJacques Vidrine char facility[128] = "";
3218373020dSJacques Vidrine p += 6;
3228373020dSJacques Vidrine if(*p != '\0')
3238373020dSJacques Vidrine p++;
3248373020dSJacques Vidrine if(strsep_copy(&p, ":", severity, sizeof(severity)) != -1)
3258373020dSJacques Vidrine strsep_copy(&p, ":", facility, sizeof(facility));
3268373020dSJacques Vidrine if(*severity == '\0')
3278373020dSJacques Vidrine strlcpy(severity, "ERR", sizeof(severity));
3288373020dSJacques Vidrine if(*facility == '\0')
3298373020dSJacques Vidrine strlcpy(facility, "AUTH", sizeof(facility));
330bbd80c28SJacques Vidrine if(find_value(severity, syslogvals) == -1) {
3318373020dSJacques Vidrine krb5_warnx(context, "%s: unknown syslog facility \"%s\"",
3328373020dSJacques Vidrine path, facility);
3338373020dSJacques Vidrine ret++;
3348373020dSJacques Vidrine }
335bbd80c28SJacques Vidrine if(find_value(severity, syslogvals) == -1) {
3368373020dSJacques Vidrine krb5_warnx(context, "%s: unknown syslog severity \"%s\"",
3378373020dSJacques Vidrine path, severity);
3388373020dSJacques Vidrine ret++;
3398373020dSJacques Vidrine }
3408373020dSJacques Vidrine return ret;
3418373020dSJacques Vidrine }else{
3428373020dSJacques Vidrine krb5_warnx(context, "%s: unknown log type: \"%s\"", path, data);
3438373020dSJacques Vidrine return 1;
3448373020dSJacques Vidrine }
3458373020dSJacques Vidrine }
3468373020dSJacques Vidrine
3474137ff4cSJacques Vidrine typedef int (*check_func_t)(krb5_context, const char*, char*);
3484137ff4cSJacques Vidrine struct entry {
3494137ff4cSJacques Vidrine const char *name;
3504137ff4cSJacques Vidrine int type;
3514137ff4cSJacques Vidrine void *check_data;
352ae771770SStanislav Sedov int deprecated;
3534137ff4cSJacques Vidrine };
3544137ff4cSJacques Vidrine
3554137ff4cSJacques Vidrine struct entry all_strings[] = {
3564137ff4cSJacques Vidrine { "", krb5_config_string, NULL },
3574137ff4cSJacques Vidrine { NULL }
3584137ff4cSJacques Vidrine };
3594137ff4cSJacques Vidrine
360c19800e8SDoug Rabson struct entry all_boolean[] = {
361c19800e8SDoug Rabson { "", krb5_config_string, check_boolean },
362c19800e8SDoug Rabson { NULL }
363c19800e8SDoug Rabson };
364c19800e8SDoug Rabson
365c19800e8SDoug Rabson
3664137ff4cSJacques Vidrine struct entry v4_name_convert_entries[] = {
3674137ff4cSJacques Vidrine { "host", krb5_config_list, all_strings },
3684137ff4cSJacques Vidrine { "plain", krb5_config_list, all_strings },
3694137ff4cSJacques Vidrine { NULL }
3704137ff4cSJacques Vidrine };
3714137ff4cSJacques Vidrine
3724137ff4cSJacques Vidrine struct entry libdefaults_entries[] = {
3734137ff4cSJacques Vidrine { "accept_null_addresses", krb5_config_string, check_boolean },
374ae771770SStanislav Sedov { "allow_weak_crypto", krb5_config_string, check_boolean },
375ae771770SStanislav Sedov { "capath", krb5_config_list, all_strings, 1 },
376c19800e8SDoug Rabson { "check_pac", krb5_config_string, check_boolean },
3774137ff4cSJacques Vidrine { "clockskew", krb5_config_string, check_time },
3784137ff4cSJacques Vidrine { "date_format", krb5_config_string, NULL },
379c19800e8SDoug Rabson { "default_cc_name", krb5_config_string, NULL },
3804137ff4cSJacques Vidrine { "default_etypes", krb5_config_string, NULL },
3814137ff4cSJacques Vidrine { "default_etypes_des", krb5_config_string, NULL },
3824137ff4cSJacques Vidrine { "default_keytab_modify_name", krb5_config_string, NULL },
3834137ff4cSJacques Vidrine { "default_keytab_name", krb5_config_string, NULL },
3844137ff4cSJacques Vidrine { "default_realm", krb5_config_string, NULL },
385c19800e8SDoug Rabson { "dns_canonize_hostname", krb5_config_string, check_boolean },
3864137ff4cSJacques Vidrine { "dns_proxy", krb5_config_string, NULL },
3878373020dSJacques Vidrine { "dns_lookup_kdc", krb5_config_string, check_boolean },
3888373020dSJacques Vidrine { "dns_lookup_realm", krb5_config_string, check_boolean },
3898373020dSJacques Vidrine { "dns_lookup_realm_labels", krb5_config_string, NULL },
3904137ff4cSJacques Vidrine { "egd_socket", krb5_config_string, NULL },
3914137ff4cSJacques Vidrine { "encrypt", krb5_config_string, check_boolean },
3924137ff4cSJacques Vidrine { "extra_addresses", krb5_config_string, NULL },
3934137ff4cSJacques Vidrine { "fcache_version", krb5_config_string, check_numeric },
394c19800e8SDoug Rabson { "fcc-mit-ticketflags", krb5_config_string, check_boolean },
3954137ff4cSJacques Vidrine { "forward", krb5_config_string, check_boolean },
3964137ff4cSJacques Vidrine { "forwardable", krb5_config_string, check_boolean },
3974137ff4cSJacques Vidrine { "http_proxy", krb5_config_string, check_host /* XXX */ },
3984137ff4cSJacques Vidrine { "ignore_addresses", krb5_config_string, NULL },
3994137ff4cSJacques Vidrine { "kdc_timeout", krb5_config_string, check_time },
4004137ff4cSJacques Vidrine { "kdc_timesync", krb5_config_string, check_boolean },
4014137ff4cSJacques Vidrine { "log_utc", krb5_config_string, check_boolean },
4024137ff4cSJacques Vidrine { "maxretries", krb5_config_string, check_numeric },
4034137ff4cSJacques Vidrine { "scan_interfaces", krb5_config_string, check_boolean },
4044137ff4cSJacques Vidrine { "srv_lookup", krb5_config_string, check_boolean },
4054137ff4cSJacques Vidrine { "srv_try_txt", krb5_config_string, check_boolean },
4064137ff4cSJacques Vidrine { "ticket_lifetime", krb5_config_string, check_time },
4074137ff4cSJacques Vidrine { "time_format", krb5_config_string, NULL },
4084137ff4cSJacques Vidrine { "transited_realms_reject", krb5_config_string, NULL },
409c19800e8SDoug Rabson { "no-addresses", krb5_config_string, check_boolean },
4104137ff4cSJacques Vidrine { "v4_instance_resolve", krb5_config_string, check_boolean },
4114137ff4cSJacques Vidrine { "v4_name_convert", krb5_config_list, v4_name_convert_entries },
4124137ff4cSJacques Vidrine { "verify_ap_req_nofail", krb5_config_string, check_boolean },
413c19800e8SDoug Rabson { "max_retries", krb5_config_string, check_time },
414c19800e8SDoug Rabson { "renew_lifetime", krb5_config_string, check_time },
415c19800e8SDoug Rabson { "proxiable", krb5_config_string, check_boolean },
416c19800e8SDoug Rabson { "warn_pwexpire", krb5_config_string, check_time },
417c19800e8SDoug Rabson /* MIT stuff */
418c19800e8SDoug Rabson { "permitted_enctypes", krb5_config_string, mit_entry },
419c19800e8SDoug Rabson { "default_tgs_enctypes", krb5_config_string, mit_entry },
420c19800e8SDoug Rabson { "default_tkt_enctypes", krb5_config_string, mit_entry },
4214137ff4cSJacques Vidrine { NULL }
4224137ff4cSJacques Vidrine };
4234137ff4cSJacques Vidrine
4244137ff4cSJacques Vidrine struct entry appdefaults_entries[] = {
425bbd80c28SJacques Vidrine { "afslog", krb5_config_string, check_boolean },
426bbd80c28SJacques Vidrine { "afs-use-524", krb5_config_string, check_524 },
427c19800e8SDoug Rabson { "encrypt", krb5_config_string, check_boolean },
428c19800e8SDoug Rabson { "forward", krb5_config_string, check_boolean },
4294137ff4cSJacques Vidrine { "forwardable", krb5_config_string, check_boolean },
4304137ff4cSJacques Vidrine { "proxiable", krb5_config_string, check_boolean },
4314137ff4cSJacques Vidrine { "ticket_lifetime", krb5_config_string, check_time },
4324137ff4cSJacques Vidrine { "renew_lifetime", krb5_config_string, check_time },
4334137ff4cSJacques Vidrine { "no-addresses", krb5_config_string, check_boolean },
4348373020dSJacques Vidrine { "krb4_get_tickets", krb5_config_string, check_boolean },
435c19800e8SDoug Rabson { "pkinit_anchors", krb5_config_string, NULL },
436c19800e8SDoug Rabson { "pkinit_win2k", krb5_config_string, NULL },
437c19800e8SDoug Rabson { "pkinit_win2k_require_binding", krb5_config_string, NULL },
438c19800e8SDoug Rabson { "pkinit_require_eku", krb5_config_string, NULL },
439c19800e8SDoug Rabson { "pkinit_require_krbtgt_otherName", krb5_config_string, NULL },
440c19800e8SDoug Rabson { "pkinit_require_hostname_match", krb5_config_string, NULL },
4414137ff4cSJacques Vidrine #if 0
4424137ff4cSJacques Vidrine { "anonymous", krb5_config_string, check_boolean },
4434137ff4cSJacques Vidrine #endif
4444137ff4cSJacques Vidrine { "", krb5_config_list, appdefaults_entries },
4454137ff4cSJacques Vidrine { NULL }
4464137ff4cSJacques Vidrine };
4474137ff4cSJacques Vidrine
4484137ff4cSJacques Vidrine struct entry realms_entries[] = {
4494137ff4cSJacques Vidrine { "forwardable", krb5_config_string, check_boolean },
4504137ff4cSJacques Vidrine { "proxiable", krb5_config_string, check_boolean },
4514137ff4cSJacques Vidrine { "ticket_lifetime", krb5_config_string, check_time },
4524137ff4cSJacques Vidrine { "renew_lifetime", krb5_config_string, check_time },
4534137ff4cSJacques Vidrine { "warn_pwexpire", krb5_config_string, check_time },
4544137ff4cSJacques Vidrine { "kdc", krb5_config_string, check_host },
4554137ff4cSJacques Vidrine { "admin_server", krb5_config_string, check_host },
4564137ff4cSJacques Vidrine { "kpasswd_server", krb5_config_string, check_host },
4574137ff4cSJacques Vidrine { "krb524_server", krb5_config_string, check_host },
4584137ff4cSJacques Vidrine { "v4_name_convert", krb5_config_list, v4_name_convert_entries },
4594137ff4cSJacques Vidrine { "v4_instance_convert", krb5_config_list, all_strings },
4604137ff4cSJacques Vidrine { "v4_domains", krb5_config_string, NULL },
4614137ff4cSJacques Vidrine { "default_domain", krb5_config_string, NULL },
462c19800e8SDoug Rabson { "win2k_pkinit", krb5_config_string, NULL },
4638373020dSJacques Vidrine /* MIT stuff */
4648373020dSJacques Vidrine { "admin_keytab", krb5_config_string, mit_entry },
4658373020dSJacques Vidrine { "acl_file", krb5_config_string, mit_entry },
4668373020dSJacques Vidrine { "dict_file", krb5_config_string, mit_entry },
4678373020dSJacques Vidrine { "kadmind_port", krb5_config_string, mit_entry },
4688373020dSJacques Vidrine { "kpasswd_port", krb5_config_string, mit_entry },
4698373020dSJacques Vidrine { "master_key_name", krb5_config_string, mit_entry },
4708373020dSJacques Vidrine { "master_key_type", krb5_config_string, mit_entry },
4718373020dSJacques Vidrine { "key_stash_file", krb5_config_string, mit_entry },
4728373020dSJacques Vidrine { "max_life", krb5_config_string, mit_entry },
4738373020dSJacques Vidrine { "max_renewable_life", krb5_config_string, mit_entry },
4748373020dSJacques Vidrine { "default_principal_expiration", krb5_config_string, mit_entry },
4758373020dSJacques Vidrine { "default_principal_flags", krb5_config_string, mit_entry },
4768373020dSJacques Vidrine { "supported_enctypes", krb5_config_string, mit_entry },
4778373020dSJacques Vidrine { "database_name", krb5_config_string, mit_entry },
4784137ff4cSJacques Vidrine { NULL }
4794137ff4cSJacques Vidrine };
4804137ff4cSJacques Vidrine
4814137ff4cSJacques Vidrine struct entry realms_foobar[] = {
4824137ff4cSJacques Vidrine { "", krb5_config_list, realms_entries },
4834137ff4cSJacques Vidrine { NULL }
4844137ff4cSJacques Vidrine };
4854137ff4cSJacques Vidrine
4864137ff4cSJacques Vidrine
4874137ff4cSJacques Vidrine struct entry kdc_database_entries[] = {
4884137ff4cSJacques Vidrine { "realm", krb5_config_string, NULL },
4894137ff4cSJacques Vidrine { "dbname", krb5_config_string, NULL },
4904137ff4cSJacques Vidrine { "mkey_file", krb5_config_string, NULL },
491c19800e8SDoug Rabson { "acl_file", krb5_config_string, NULL },
492c19800e8SDoug Rabson { "log_file", krb5_config_string, NULL },
4934137ff4cSJacques Vidrine { NULL }
4944137ff4cSJacques Vidrine };
4954137ff4cSJacques Vidrine
4964137ff4cSJacques Vidrine struct entry kdc_entries[] = {
4974137ff4cSJacques Vidrine { "database", krb5_config_list, kdc_database_entries },
4984137ff4cSJacques Vidrine { "key-file", krb5_config_string, NULL },
4998373020dSJacques Vidrine { "logging", krb5_config_string, check_log },
5004137ff4cSJacques Vidrine { "max-request", krb5_config_string, check_bytes },
5014137ff4cSJacques Vidrine { "require-preauth", krb5_config_string, check_boolean },
5024137ff4cSJacques Vidrine { "ports", krb5_config_string, NULL },
5034137ff4cSJacques Vidrine { "addresses", krb5_config_string, NULL },
5044137ff4cSJacques Vidrine { "enable-kerberos4", krb5_config_string, check_boolean },
5054137ff4cSJacques Vidrine { "enable-524", krb5_config_string, check_boolean },
5064137ff4cSJacques Vidrine { "enable-http", krb5_config_string, check_boolean },
507c19800e8SDoug Rabson { "check-ticket-addresses", krb5_config_string, check_boolean },
508c19800e8SDoug Rabson { "allow-null-ticket-addresses", krb5_config_string, check_boolean },
5094137ff4cSJacques Vidrine { "allow-anonymous", krb5_config_string, check_boolean },
5104137ff4cSJacques Vidrine { "v4_realm", krb5_config_string, NULL },
511*cf771f22SStanislav Sedov { "enable-kaserver", krb5_config_string, check_boolean, 1 },
5124137ff4cSJacques Vidrine { "encode_as_rep_as_tgs_rep", krb5_config_string, check_boolean },
5134137ff4cSJacques Vidrine { "kdc_warn_pwexpire", krb5_config_string, check_time },
514c19800e8SDoug Rabson { "use_2b", krb5_config_list, NULL },
515c19800e8SDoug Rabson { "enable-pkinit", krb5_config_string, check_boolean },
516c19800e8SDoug Rabson { "pkinit_identity", krb5_config_string, NULL },
517c19800e8SDoug Rabson { "pkinit_anchors", krb5_config_string, NULL },
518c19800e8SDoug Rabson { "pkinit_pool", krb5_config_string, NULL },
519c19800e8SDoug Rabson { "pkinit_revoke", krb5_config_string, NULL },
520c19800e8SDoug Rabson { "pkinit_kdc_ocsp", krb5_config_string, NULL },
521c19800e8SDoug Rabson { "pkinit_principal_in_certificate", krb5_config_string, NULL },
522c19800e8SDoug Rabson { "pkinit_dh_min_bits", krb5_config_string, NULL },
523c19800e8SDoug Rabson { "pkinit_allow_proxy_certificate", krb5_config_string, NULL },
524c19800e8SDoug Rabson { "hdb-ldap-create-base", krb5_config_string, NULL },
525c19800e8SDoug Rabson { "v4-realm", krb5_config_string, NULL },
5264137ff4cSJacques Vidrine { NULL }
5274137ff4cSJacques Vidrine };
5284137ff4cSJacques Vidrine
5294137ff4cSJacques Vidrine struct entry kadmin_entries[] = {
5304137ff4cSJacques Vidrine { "password_lifetime", krb5_config_string, check_time },
5314137ff4cSJacques Vidrine { "default_keys", krb5_config_string, NULL },
5324137ff4cSJacques Vidrine { "use_v4_salt", krb5_config_string, NULL },
533c19800e8SDoug Rabson { "require-preauth", krb5_config_string, check_boolean },
5344137ff4cSJacques Vidrine { NULL }
5354137ff4cSJacques Vidrine };
5368373020dSJacques Vidrine struct entry log_strings[] = {
5378373020dSJacques Vidrine { "", krb5_config_string, check_log },
5388373020dSJacques Vidrine { NULL }
5398373020dSJacques Vidrine };
5408373020dSJacques Vidrine
5418373020dSJacques Vidrine
542c19800e8SDoug Rabson /* MIT stuff */
5438373020dSJacques Vidrine struct entry kdcdefaults_entries[] = {
544855f5693SJacques Vidrine { "kdc_ports", krb5_config_string, mit_entry },
545855f5693SJacques Vidrine { "v4_mode", krb5_config_string, mit_entry },
5468373020dSJacques Vidrine { NULL }
5478373020dSJacques Vidrine };
548c19800e8SDoug Rabson
549c19800e8SDoug Rabson struct entry capaths_entries[] = {
550c19800e8SDoug Rabson { "", krb5_config_list, all_strings },
551c19800e8SDoug Rabson { NULL }
552c19800e8SDoug Rabson };
553c19800e8SDoug Rabson
554c19800e8SDoug Rabson struct entry password_quality_entries[] = {
555c19800e8SDoug Rabson { "policies", krb5_config_string, NULL },
556c19800e8SDoug Rabson { "external_program", krb5_config_string, NULL },
557c19800e8SDoug Rabson { "min_classes", krb5_config_string, check_numeric },
558c19800e8SDoug Rabson { "min_length", krb5_config_string, check_numeric },
559c19800e8SDoug Rabson { "", krb5_config_list, all_strings },
560c19800e8SDoug Rabson { NULL }
561c19800e8SDoug Rabson };
5628373020dSJacques Vidrine
5634137ff4cSJacques Vidrine struct entry toplevel_sections[] = {
5644137ff4cSJacques Vidrine { "libdefaults" , krb5_config_list, libdefaults_entries },
5654137ff4cSJacques Vidrine { "realms", krb5_config_list, realms_foobar },
5664137ff4cSJacques Vidrine { "domain_realm", krb5_config_list, all_strings },
5678373020dSJacques Vidrine { "logging", krb5_config_list, log_strings },
5684137ff4cSJacques Vidrine { "kdc", krb5_config_list, kdc_entries },
5694137ff4cSJacques Vidrine { "kadmin", krb5_config_list, kadmin_entries },
5704137ff4cSJacques Vidrine { "appdefaults", krb5_config_list, appdefaults_entries },
571c19800e8SDoug Rabson { "gssapi", krb5_config_list, NULL },
572c19800e8SDoug Rabson { "capaths", krb5_config_list, capaths_entries },
573c19800e8SDoug Rabson { "password_quality", krb5_config_list, password_quality_entries },
5748373020dSJacques Vidrine /* MIT stuff */
5758373020dSJacques Vidrine { "kdcdefaults", krb5_config_list, kdcdefaults_entries },
5764137ff4cSJacques Vidrine { NULL }
5774137ff4cSJacques Vidrine };
5784137ff4cSJacques Vidrine
5794137ff4cSJacques Vidrine
5804137ff4cSJacques Vidrine static int
check_section(krb5_context context,const char * path,krb5_config_section * cf,struct entry * entries)5814137ff4cSJacques Vidrine check_section(krb5_context context, const char *path, krb5_config_section *cf,
5824137ff4cSJacques Vidrine struct entry *entries)
5834137ff4cSJacques Vidrine {
5844137ff4cSJacques Vidrine int error = 0;
5854137ff4cSJacques Vidrine krb5_config_section *p;
5864137ff4cSJacques Vidrine struct entry *e;
5874137ff4cSJacques Vidrine
5884137ff4cSJacques Vidrine char *local;
5894137ff4cSJacques Vidrine
5904137ff4cSJacques Vidrine for(p = cf; p != NULL; p = p->next) {
591ae771770SStanislav Sedov local = NULL;
592ae771770SStanislav Sedov if (asprintf(&local, "%s/%s", path, p->name) < 0 || local == NULL)
593ae771770SStanislav Sedov errx(1, "out of memory");
5944137ff4cSJacques Vidrine for(e = entries; e->name != NULL; e++) {
5954137ff4cSJacques Vidrine if(*e->name == '\0' || strcmp(e->name, p->name) == 0) {
5964137ff4cSJacques Vidrine if(e->type != p->type) {
5974137ff4cSJacques Vidrine krb5_warnx(context, "%s: unknown or wrong type", local);
5984137ff4cSJacques Vidrine error |= 1;
5994137ff4cSJacques Vidrine } else if(p->type == krb5_config_string && e->check_data != NULL) {
6004137ff4cSJacques Vidrine error |= (*(check_func_t)e->check_data)(context, local, p->u.string);
6014137ff4cSJacques Vidrine } else if(p->type == krb5_config_list && e->check_data != NULL) {
6024137ff4cSJacques Vidrine error |= check_section(context, local, p->u.list, e->check_data);
6034137ff4cSJacques Vidrine }
604ae771770SStanislav Sedov if(e->deprecated) {
605ae771770SStanislav Sedov krb5_warnx(context, "%s: is a deprecated entry", local);
606ae771770SStanislav Sedov error |= 1;
607ae771770SStanislav Sedov }
6084137ff4cSJacques Vidrine break;
6094137ff4cSJacques Vidrine }
6104137ff4cSJacques Vidrine }
6114137ff4cSJacques Vidrine if(e->name == NULL) {
6124137ff4cSJacques Vidrine krb5_warnx(context, "%s: unknown entry", local);
6134137ff4cSJacques Vidrine error |= 1;
6144137ff4cSJacques Vidrine }
6154137ff4cSJacques Vidrine free(local);
6164137ff4cSJacques Vidrine }
6174137ff4cSJacques Vidrine return error;
6184137ff4cSJacques Vidrine }
6194137ff4cSJacques Vidrine
6204137ff4cSJacques Vidrine
6218373020dSJacques Vidrine static void
dumpconfig(int level,krb5_config_section * top)6228373020dSJacques Vidrine dumpconfig(int level, krb5_config_section *top)
6238373020dSJacques Vidrine {
6248373020dSJacques Vidrine krb5_config_section *x;
6258373020dSJacques Vidrine for(x = top; x; x = x->next) {
6268373020dSJacques Vidrine switch(x->type) {
6278373020dSJacques Vidrine case krb5_config_list:
6288373020dSJacques Vidrine if(level == 0) {
6298373020dSJacques Vidrine printf("[%s]\n", x->name);
6308373020dSJacques Vidrine } else {
6318373020dSJacques Vidrine printf("%*s%s = {\n", 4 * level, " ", x->name);
6328373020dSJacques Vidrine }
6338373020dSJacques Vidrine dumpconfig(level + 1, x->u.list);
6348373020dSJacques Vidrine if(level > 0)
6358373020dSJacques Vidrine printf("%*s}\n", 4 * level, " ");
6368373020dSJacques Vidrine break;
6378373020dSJacques Vidrine case krb5_config_string:
6388373020dSJacques Vidrine printf("%*s%s = %s\n", 4 * level, " ", x->name, x->u.string);
6398373020dSJacques Vidrine break;
6408373020dSJacques Vidrine }
6418373020dSJacques Vidrine }
6428373020dSJacques Vidrine }
6438373020dSJacques Vidrine
644b528cefcSMark Murray int
main(int argc,char ** argv)645b528cefcSMark Murray main(int argc, char **argv)
646b528cefcSMark Murray {
647adb0ddaeSAssar Westerlund krb5_context context;
648b528cefcSMark Murray krb5_error_code ret;
649b528cefcSMark Murray krb5_config_section *tmp_cf;
650c19800e8SDoug Rabson int optidx = 0;
651b528cefcSMark Murray
652adb0ddaeSAssar Westerlund setprogname (argv[0]);
653adb0ddaeSAssar Westerlund
654adb0ddaeSAssar Westerlund ret = krb5_init_context(&context);
655c19800e8SDoug Rabson if (ret == KRB5_CONFIG_BADFORMAT)
656c19800e8SDoug Rabson errx (1, "krb5_init_context failed to parse configuration file");
657c19800e8SDoug Rabson else if (ret)
658c19800e8SDoug Rabson errx (1, "krb5_init_context failed with %d", ret);
659b528cefcSMark Murray
660c19800e8SDoug Rabson if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
661b528cefcSMark Murray usage(1);
662b528cefcSMark Murray
663b528cefcSMark Murray if (help_flag)
664b528cefcSMark Murray usage (0);
665b528cefcSMark Murray
666b528cefcSMark Murray if(version_flag){
667b528cefcSMark Murray print_version(NULL);
668b528cefcSMark Murray exit(0);
669b528cefcSMark Murray }
670b528cefcSMark Murray
671c19800e8SDoug Rabson argc -= optidx;
672c19800e8SDoug Rabson argv += optidx;
673b528cefcSMark Murray
6748373020dSJacques Vidrine tmp_cf = NULL;
6758373020dSJacques Vidrine if(argc == 0)
6768373020dSJacques Vidrine krb5_get_default_config_files(&argv);
6778373020dSJacques Vidrine
6788373020dSJacques Vidrine while(*argv) {
6798373020dSJacques Vidrine ret = krb5_config_parse_file_multi(context, *argv, &tmp_cf);
6808373020dSJacques Vidrine if (ret != 0)
6818373020dSJacques Vidrine krb5_warn (context, ret, "krb5_config_parse_file");
6828373020dSJacques Vidrine argv++;
683b528cefcSMark Murray }
684b528cefcSMark Murray
6858373020dSJacques Vidrine if(dumpconfig_flag)
6868373020dSJacques Vidrine dumpconfig(0, tmp_cf);
6874137ff4cSJacques Vidrine
6884137ff4cSJacques Vidrine return check_section(context, "", tmp_cf, toplevel_sections);
6894137ff4cSJacques Vidrine }
690