2 * Copyright (c) 1999 - 2003 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
36 #include <parse_bytes.h>
38 RCSID("$Id: verify_krb5_conf.c,v 1.17.2.2 2004/02/13 16:19:44 lha Exp $");
40 /* verify krb5.conf */
42 static int dumpconfig_flag = 0;
43 static int version_flag = 0;
44 static int help_flag = 0;
46 static struct getargs args[] = {
47 {"dumpconfig", 0, arg_flag, &dumpconfig_flag,
48 "show the parsed config files", NULL },
49 {"version", 0, arg_flag, &version_flag,
50 "print version", NULL },
51 {"help", 0, arg_flag, &help_flag,
59 sizeof(args)/sizeof(*args),
66 check_bytes(krb5_context context, const char *path, char *data)
68 if(parse_bytes(data, NULL) == -1) {
69 krb5_warnx(context, "%s: failed to parse \"%s\" as size", path, data);
76 check_time(krb5_context context, const char *path, char *data)
78 if(parse_time(data, NULL) == -1) {
79 krb5_warnx(context, "%s: failed to parse \"%s\" as time", path, data);
86 check_numeric(krb5_context context, const char *path, char *data)
90 v = strtol(data, &end, 0);
92 krb5_warnx(context, "%s: failed to parse \"%s\" as a number",
100 check_boolean(krb5_context context, const char *path, char *data)
104 if(strcasecmp(data, "yes") == 0 ||
105 strcasecmp(data, "true") == 0 ||
106 strcasecmp(data, "no") == 0 ||
107 strcasecmp(data, "false") == 0)
109 v = strtol(data, &end, 0);
111 krb5_warnx(context, "%s: failed to parse \"%s\" as a boolean",
116 krb5_warnx(context, "%s: numeric value \"%s\" is treated as \"true\"",
122 check_524(krb5_context context, const char *path, char *data)
124 if(strcasecmp(data, "yes") == 0 ||
125 strcasecmp(data, "no") == 0 ||
126 strcasecmp(data, "2b") == 0 ||
127 strcasecmp(data, "local") == 0)
130 krb5_warnx(context, "%s: didn't contain a valid option `%s'",
136 check_host(krb5_context context, const char *path, char *data)
140 const char *p = data;
142 /* XXX data could be a list of hosts that this code can't handle */
143 /* XXX copied from krbhst.c */
144 if(strncmp(p, "http://", 7) == 0){
146 } else if(strncmp(p, "http/", 5) == 0) {
148 }else if(strncmp(p, "tcp/", 4) == 0){
150 } else if(strncmp(p, "udp/", 4) == 0) {
153 if(strsep_copy(&p, ":", hostname, sizeof(hostname)) < 0) {
156 hostname[strcspn(hostname, "/")] = '\0';
157 ret = getaddrinfo(hostname, "telnet" /* XXX */, NULL, &ai);
159 krb5_warnx(context, "%s: %s (%s)", path, gai_strerror(ret), hostname);
167 mit_entry(krb5_context context, const char *path, char *data)
169 krb5_warnx(context, "%s is only used by MIT Kerberos", path);
179 #define L(X) { #X, LOG_ ## X }
181 static struct s2i syslogvals[] = {
226 find_value(const char *s, struct s2i *table)
228 while(table->s && strcasecmp(table->s, s))
234 check_log(krb5_context context, const char *path, char *data)
236 /* XXX sync with log.c */
237 int min = 0, max = -1, n;
239 const char *p = data;
241 n = sscanf(p, "%d%c%d/", &min, &c, &max);
255 krb5_warnx(context, "%s: failed to parse \"%s\"", path, data);
260 if(strcmp(p, "STDERR") == 0 ||
261 strcmp(p, "CONSOLE") == 0 ||
262 (strncmp(p, "FILE", 4) == 0 && (p[4] == ':' || p[4] == '=')) ||
263 (strncmp(p, "DEVICE", 6) == 0 && p[6] == '='))
265 if(strncmp(p, "SYSLOG", 6) == 0){
267 char severity[128] = "";
268 char facility[128] = "";
272 if(strsep_copy(&p, ":", severity, sizeof(severity)) != -1)
273 strsep_copy(&p, ":", facility, sizeof(facility));
274 if(*severity == '\0')
275 strlcpy(severity, "ERR", sizeof(severity));
276 if(*facility == '\0')
277 strlcpy(facility, "AUTH", sizeof(facility));
278 if(find_value(severity, syslogvals) == -1) {
279 krb5_warnx(context, "%s: unknown syslog facility \"%s\"",
283 if(find_value(severity, syslogvals) == -1) {
284 krb5_warnx(context, "%s: unknown syslog severity \"%s\"",
290 krb5_warnx(context, "%s: unknown log type: \"%s\"", path, data);
295 typedef int (*check_func_t)(krb5_context, const char*, char*);
302 struct entry all_strings[] = {
303 { "", krb5_config_string, NULL },
307 struct entry v4_name_convert_entries[] = {
308 { "host", krb5_config_list, all_strings },
309 { "plain", krb5_config_list, all_strings },
313 struct entry libdefaults_entries[] = {
314 { "accept_null_addresses", krb5_config_string, check_boolean },
315 { "capath", krb5_config_list, all_strings },
316 { "clockskew", krb5_config_string, check_time },
317 { "date_format", krb5_config_string, NULL },
318 { "default_etypes", krb5_config_string, NULL },
319 { "default_etypes_des", krb5_config_string, NULL },
320 { "default_keytab_modify_name", krb5_config_string, NULL },
321 { "default_keytab_name", krb5_config_string, NULL },
322 { "default_realm", krb5_config_string, NULL },
323 { "dns_proxy", krb5_config_string, NULL },
324 { "dns_lookup_kdc", krb5_config_string, check_boolean },
325 { "dns_lookup_realm", krb5_config_string, check_boolean },
326 { "dns_lookup_realm_labels", krb5_config_string, NULL },
327 { "egd_socket", krb5_config_string, NULL },
328 { "encrypt", krb5_config_string, check_boolean },
329 { "extra_addresses", krb5_config_string, NULL },
330 { "fcache_version", krb5_config_string, check_numeric },
331 { "forward", krb5_config_string, check_boolean },
332 { "forwardable", krb5_config_string, check_boolean },
333 { "http_proxy", krb5_config_string, check_host /* XXX */ },
334 { "ignore_addresses", krb5_config_string, NULL },
335 { "kdc_timeout", krb5_config_string, check_time },
336 { "kdc_timesync", krb5_config_string, check_boolean },
337 { "log_utc", krb5_config_string, check_boolean },
338 { "maxretries", krb5_config_string, check_numeric },
339 { "scan_interfaces", krb5_config_string, check_boolean },
340 { "srv_lookup", krb5_config_string, check_boolean },
341 { "srv_try_txt", krb5_config_string, check_boolean },
342 { "ticket_lifetime", krb5_config_string, check_time },
343 { "time_format", krb5_config_string, NULL },
344 { "transited_realms_reject", krb5_config_string, NULL },
345 { "v4_instance_resolve", krb5_config_string, check_boolean },
346 { "v4_name_convert", krb5_config_list, v4_name_convert_entries },
347 { "verify_ap_req_nofail", krb5_config_string, check_boolean },
351 struct entry appdefaults_entries[] = {
352 { "afslog", krb5_config_string, check_boolean },
353 { "afs-use-524", krb5_config_string, check_524 },
354 { "forwardable", krb5_config_string, check_boolean },
355 { "proxiable", krb5_config_string, check_boolean },
356 { "ticket_lifetime", krb5_config_string, check_time },
357 { "renew_lifetime", krb5_config_string, check_time },
358 { "no-addresses", krb5_config_string, check_boolean },
359 { "krb4_get_tickets", krb5_config_string, check_boolean },
361 { "anonymous", krb5_config_string, check_boolean },
363 { "", krb5_config_list, appdefaults_entries },
367 struct entry realms_entries[] = {
368 { "forwardable", krb5_config_string, check_boolean },
369 { "proxiable", krb5_config_string, check_boolean },
370 { "ticket_lifetime", krb5_config_string, check_time },
371 { "renew_lifetime", krb5_config_string, check_time },
372 { "warn_pwexpire", krb5_config_string, check_time },
373 { "kdc", krb5_config_string, check_host },
374 { "admin_server", krb5_config_string, check_host },
375 { "kpasswd_server", krb5_config_string, check_host },
376 { "krb524_server", krb5_config_string, check_host },
377 { "v4_name_convert", krb5_config_list, v4_name_convert_entries },
378 { "v4_instance_convert", krb5_config_list, all_strings },
379 { "v4_domains", krb5_config_string, NULL },
380 { "default_domain", krb5_config_string, NULL },
383 { "admin_keytab", krb5_config_string, mit_entry },
384 { "acl_file", krb5_config_string, mit_entry },
385 { "dict_file", krb5_config_string, mit_entry },
386 { "kadmind_port", krb5_config_string, mit_entry },
387 { "kpasswd_port", krb5_config_string, mit_entry },
388 { "master_key_name", krb5_config_string, mit_entry },
389 { "master_key_type", krb5_config_string, mit_entry },
390 { "key_stash_file", krb5_config_string, mit_entry },
391 { "max_life", krb5_config_string, mit_entry },
392 { "max_renewable_life", krb5_config_string, mit_entry },
393 { "default_principal_expiration", krb5_config_string, mit_entry },
394 { "default_principal_flags", krb5_config_string, mit_entry },
395 { "supported_enctypes", krb5_config_string, mit_entry },
396 { "database_name", krb5_config_string, mit_entry },
401 struct entry realms_foobar[] = {
402 { "", krb5_config_list, realms_entries },
407 struct entry kdc_database_entries[] = {
408 { "realm", krb5_config_string, NULL },
409 { "dbname", krb5_config_string, NULL },
410 { "mkey_file", krb5_config_string, NULL },
414 struct entry kdc_entries[] = {
415 { "database", krb5_config_list, kdc_database_entries },
416 { "key-file", krb5_config_string, NULL },
417 { "logging", krb5_config_string, check_log },
418 { "max-request", krb5_config_string, check_bytes },
419 { "require-preauth", krb5_config_string, check_boolean },
420 { "ports", krb5_config_string, NULL },
421 { "addresses", krb5_config_string, NULL },
422 { "enable-kerberos4", krb5_config_string, check_boolean },
423 { "enable-524", krb5_config_string, check_boolean },
424 { "enable-http", krb5_config_string, check_boolean },
425 { "check_ticket-addresses", krb5_config_string, check_boolean },
426 { "allow-null-addresses", krb5_config_string, check_boolean },
427 { "allow-anonymous", krb5_config_string, check_boolean },
428 { "v4_realm", krb5_config_string, NULL },
429 { "enable-kaserver", krb5_config_string, check_boolean },
430 { "encode_as_rep_as_tgs_rep", krb5_config_string, check_boolean },
431 { "kdc_warn_pwexpire", krb5_config_string, check_time },
435 struct entry kadmin_entries[] = {
436 { "password_lifetime", krb5_config_string, check_time },
437 { "default_keys", krb5_config_string, NULL },
438 { "use_v4_salt", krb5_config_string, NULL },
441 struct entry log_strings[] = {
442 { "", krb5_config_string, check_log },
448 struct entry kdcdefaults_entries[] = {
449 { "kdc_ports", krb5_config_string, mit_entry },
450 { "v4_mode", krb5_config_string, mit_entry },
455 struct entry toplevel_sections[] = {
456 { "libdefaults" , krb5_config_list, libdefaults_entries },
457 { "realms", krb5_config_list, realms_foobar },
458 { "domain_realm", krb5_config_list, all_strings },
459 { "logging", krb5_config_list, log_strings },
460 { "kdc", krb5_config_list, kdc_entries },
461 { "kadmin", krb5_config_list, kadmin_entries },
462 { "appdefaults", krb5_config_list, appdefaults_entries },
465 { "kdcdefaults", krb5_config_list, kdcdefaults_entries },
472 check_section(krb5_context context, const char *path, krb5_config_section *cf,
473 struct entry *entries)
476 krb5_config_section *p;
481 for(p = cf; p != NULL; p = p->next) {
482 asprintf(&local, "%s/%s", path, p->name);
483 for(e = entries; e->name != NULL; e++) {
484 if(*e->name == '\0' || strcmp(e->name, p->name) == 0) {
485 if(e->type != p->type) {
486 krb5_warnx(context, "%s: unknown or wrong type", local);
488 } else if(p->type == krb5_config_string && e->check_data != NULL) {
489 error |= (*(check_func_t)e->check_data)(context, local, p->u.string);
490 } else if(p->type == krb5_config_list && e->check_data != NULL) {
491 error |= check_section(context, local, p->u.list, e->check_data);
496 if(e->name == NULL) {
497 krb5_warnx(context, "%s: unknown entry", local);
507 dumpconfig(int level, krb5_config_section *top)
509 krb5_config_section *x;
510 for(x = top; x; x = x->next) {
512 case krb5_config_list:
514 printf("[%s]\n", x->name);
516 printf("%*s%s = {\n", 4 * level, " ", x->name);
518 dumpconfig(level + 1, x->u.list);
520 printf("%*s}\n", 4 * level, " ");
522 case krb5_config_string:
523 printf("%*s%s = %s\n", 4 * level, " ", x->name, x->u.string);
530 main(int argc, char **argv)
532 krb5_context context;
534 krb5_config_section *tmp_cf;
537 setprogname (argv[0]);
539 ret = krb5_init_context(&context);
541 errx (1, "krb5_init_context failed");
543 if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optind))
559 krb5_get_default_config_files(&argv);
562 ret = krb5_config_parse_file_multi(context, *argv, &tmp_cf);
564 krb5_warn (context, ret, "krb5_config_parse_file");
569 dumpconfig(0, tmp_cf);
571 return check_section(context, "", tmp_cf, toplevel_sections);