2 * Copyright (c) 1999 - 2005 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("$Heimdal: verify_krb5_conf.c 22233 2007-12-08 21:43:37Z lha $"
41 /* verify krb5.conf */
43 static int dumpconfig_flag
= 0;
44 static int version_flag
= 0;
45 static int help_flag
= 0;
46 static int warn_mit_syntax_flag
= 0;
48 static struct getargs args
[] = {
49 {"dumpconfig", 0, arg_flag
, &dumpconfig_flag
,
50 "show the parsed config files", NULL
},
51 {"warn-mit-syntax", 0, arg_flag
, &warn_mit_syntax_flag
,
52 "show the parsed config files", NULL
},
53 {"version", 0, arg_flag
, &version_flag
,
54 "print version", NULL
},
55 {"help", 0, arg_flag
, &help_flag
,
63 sizeof(args
)/sizeof(*args
),
70 check_bytes(krb5_context context
, const char *path
, char *data
)
72 if(parse_bytes(data
, NULL
) == -1) {
73 krb5_warnx(context
, "%s: failed to parse \"%s\" as size", path
, data
);
80 check_time(krb5_context context
, const char *path
, char *data
)
82 if(parse_time(data
, NULL
) == -1) {
83 krb5_warnx(context
, "%s: failed to parse \"%s\" as time", path
, data
);
90 check_numeric(krb5_context context
, const char *path
, char *data
)
94 v
= strtol(data
, &end
, 0);
96 krb5_warnx(context
, "%s: failed to parse \"%s\" as a number",
104 check_boolean(krb5_context context
, const char *path
, char *data
)
108 if(strcasecmp(data
, "yes") == 0 ||
109 strcasecmp(data
, "true") == 0 ||
110 strcasecmp(data
, "no") == 0 ||
111 strcasecmp(data
, "false") == 0)
113 v
= strtol(data
, &end
, 0);
115 krb5_warnx(context
, "%s: failed to parse \"%s\" as a boolean",
120 krb5_warnx(context
, "%s: numeric value \"%s\" is treated as \"true\"",
126 check_524(krb5_context context
, const char *path
, char *data
)
128 if(strcasecmp(data
, "yes") == 0 ||
129 strcasecmp(data
, "no") == 0 ||
130 strcasecmp(data
, "2b") == 0 ||
131 strcasecmp(data
, "local") == 0)
134 krb5_warnx(context
, "%s: didn't contain a valid option `%s'",
140 check_host(krb5_context context
, const char *path
, char *data
)
144 const char *p
= data
;
145 struct addrinfo hints
;
151 hints
.ai_family
= PF_UNSPEC
;
152 hints
.ai_socktype
= 0;
153 hints
.ai_protocol
= 0;
155 hints
.ai_addrlen
= 0;
156 hints
.ai_canonname
= NULL
;
157 hints
.ai_addr
= NULL
;
158 hints
.ai_next
= NULL
;
160 /* XXX data could be a list of hosts that this code can't handle */
161 /* XXX copied from krbhst.c */
162 if(strncmp(p
, "http://", 7) == 0){
164 hints
.ai_socktype
= SOCK_STREAM
;
165 strlcpy(service
, "http", sizeof(service
));
167 } else if(strncmp(p
, "http/", 5) == 0) {
169 hints
.ai_socktype
= SOCK_STREAM
;
170 strlcpy(service
, "http", sizeof(service
));
172 }else if(strncmp(p
, "tcp/", 4) == 0){
174 hints
.ai_socktype
= SOCK_STREAM
;
175 strlcpy(service
, "kerberos", sizeof(service
));
177 } else if(strncmp(p
, "udp/", 4) == 0) {
179 hints
.ai_socktype
= SOCK_DGRAM
;
180 strlcpy(service
, "kerberos", sizeof(service
));
183 hints
.ai_socktype
= SOCK_DGRAM
;
184 strlcpy(service
, "kerberos", sizeof(service
));
187 if(strsep_copy(&p
, ":", hostname
, sizeof(hostname
)) < 0) {
190 hostname
[strcspn(hostname
, "/")] = '\0';
193 int tmp
= strtol(p
, &end
, 0);
195 krb5_warnx(context
, "%s: failed to parse port number in %s",
200 snprintf(service
, sizeof(service
), "%u", defport
);
202 ret
= getaddrinfo(hostname
, service
, &hints
, &ai
);
203 if(ret
== EAI_SERVICE
&& !isdigit((unsigned char)service
[0])) {
204 snprintf(service
, sizeof(service
), "%u", defport
);
205 ret
= getaddrinfo(hostname
, service
, &hints
, &ai
);
208 krb5_warnx(context
, "%s: %s (%s)", path
, gai_strerror(ret
), hostname
);
215 mit_entry(krb5_context context
, const char *path
, char *data
)
217 if (warn_mit_syntax_flag
)
218 krb5_warnx(context
, "%s is only used by MIT Kerberos", path
);
227 #define L(X) { #X, LOG_ ## X }
229 static struct s2i syslogvals
[] = {
274 find_value(const char *s
, struct s2i
*table
)
276 while(table
->s
&& strcasecmp(table
->s
, s
))
282 check_log(krb5_context context
, const char *path
, char *data
)
284 /* XXX sync with log.c */
285 int min
= 0, max
= -1, n
;
287 const char *p
= data
;
289 n
= sscanf(p
, "%d%c%d/", &min
, &c
, &max
);
303 krb5_warnx(context
, "%s: failed to parse \"%s\"", path
, data
);
308 if(strcmp(p
, "STDERR") == 0 ||
309 strcmp(p
, "CONSOLE") == 0 ||
310 (strncmp(p
, "FILE", 4) == 0 && (p
[4] == ':' || p
[4] == '=')) ||
311 (strncmp(p
, "DEVICE", 6) == 0 && p
[6] == '='))
313 if(strncmp(p
, "SYSLOG", 6) == 0){
315 char severity
[128] = "";
316 char facility
[128] = "";
320 if(strsep_copy(&p
, ":", severity
, sizeof(severity
)) != -1)
321 strsep_copy(&p
, ":", facility
, sizeof(facility
));
322 if(*severity
== '\0')
323 strlcpy(severity
, "ERR", sizeof(severity
));
324 if(*facility
== '\0')
325 strlcpy(facility
, "AUTH", sizeof(facility
));
326 if(find_value(severity
, syslogvals
) == -1) {
327 krb5_warnx(context
, "%s: unknown syslog facility \"%s\"",
331 if(find_value(severity
, syslogvals
) == -1) {
332 krb5_warnx(context
, "%s: unknown syslog severity \"%s\"",
338 krb5_warnx(context
, "%s: unknown log type: \"%s\"", path
, data
);
343 typedef int (*check_func_t
)(krb5_context
, const char*, char*);
350 struct entry all_strings
[] = {
351 { "", krb5_config_string
, NULL
},
355 struct entry all_boolean
[] = {
356 { "", krb5_config_string
, check_boolean
},
361 struct entry v4_name_convert_entries
[] = {
362 { "host", krb5_config_list
, all_strings
},
363 { "plain", krb5_config_list
, all_strings
},
367 struct entry libdefaults_entries
[] = {
368 { "accept_null_addresses", krb5_config_string
, check_boolean
},
369 { "capath", krb5_config_list
, all_strings
},
370 { "check_pac", krb5_config_string
, check_boolean
},
371 { "clockskew", krb5_config_string
, check_time
},
372 { "date_format", krb5_config_string
, NULL
},
373 { "default_cc_name", krb5_config_string
, NULL
},
374 { "default_etypes", krb5_config_string
, NULL
},
375 { "default_etypes_des", krb5_config_string
, NULL
},
376 { "default_keytab_modify_name", krb5_config_string
, NULL
},
377 { "default_keytab_name", krb5_config_string
, NULL
},
378 { "default_realm", krb5_config_string
, NULL
},
379 { "dns_canonize_hostname", krb5_config_string
, check_boolean
},
380 { "dns_proxy", krb5_config_string
, NULL
},
381 { "dns_lookup_kdc", krb5_config_string
, check_boolean
},
382 { "dns_lookup_realm", krb5_config_string
, check_boolean
},
383 { "dns_lookup_realm_labels", krb5_config_string
, NULL
},
384 { "egd_socket", krb5_config_string
, NULL
},
385 { "encrypt", krb5_config_string
, check_boolean
},
386 { "extra_addresses", krb5_config_string
, NULL
},
387 { "fcache_version", krb5_config_string
, check_numeric
},
388 { "fcc-mit-ticketflags", krb5_config_string
, check_boolean
},
389 { "forward", krb5_config_string
, check_boolean
},
390 { "forwardable", krb5_config_string
, check_boolean
},
391 { "http_proxy", krb5_config_string
, check_host
/* XXX */ },
392 { "ignore_addresses", krb5_config_string
, NULL
},
393 { "kdc_timeout", krb5_config_string
, check_time
},
394 { "kdc_timesync", krb5_config_string
, check_boolean
},
395 { "log_utc", krb5_config_string
, check_boolean
},
396 { "maxretries", krb5_config_string
, check_numeric
},
397 { "scan_interfaces", krb5_config_string
, check_boolean
},
398 { "srv_lookup", krb5_config_string
, check_boolean
},
399 { "srv_try_txt", krb5_config_string
, check_boolean
},
400 { "ticket_lifetime", krb5_config_string
, check_time
},
401 { "time_format", krb5_config_string
, NULL
},
402 { "transited_realms_reject", krb5_config_string
, NULL
},
403 { "no-addresses", krb5_config_string
, check_boolean
},
404 { "v4_instance_resolve", krb5_config_string
, check_boolean
},
405 { "v4_name_convert", krb5_config_list
, v4_name_convert_entries
},
406 { "verify_ap_req_nofail", krb5_config_string
, check_boolean
},
407 { "max_retries", krb5_config_string
, check_time
},
408 { "renew_lifetime", krb5_config_string
, check_time
},
409 { "proxiable", krb5_config_string
, check_boolean
},
410 { "warn_pwexpire", krb5_config_string
, check_time
},
412 { "permitted_enctypes", krb5_config_string
, mit_entry
},
413 { "default_tgs_enctypes", krb5_config_string
, mit_entry
},
414 { "default_tkt_enctypes", krb5_config_string
, mit_entry
},
418 struct entry appdefaults_entries
[] = {
419 { "afslog", krb5_config_string
, check_boolean
},
420 { "afs-use-524", krb5_config_string
, check_524
},
421 { "encrypt", krb5_config_string
, check_boolean
},
422 { "forward", krb5_config_string
, check_boolean
},
423 { "forwardable", krb5_config_string
, check_boolean
},
424 { "proxiable", krb5_config_string
, check_boolean
},
425 { "ticket_lifetime", krb5_config_string
, check_time
},
426 { "renew_lifetime", krb5_config_string
, check_time
},
427 { "no-addresses", krb5_config_string
, check_boolean
},
428 { "krb4_get_tickets", krb5_config_string
, check_boolean
},
429 { "pkinit_anchors", krb5_config_string
, NULL
},
430 { "pkinit_win2k", krb5_config_string
, NULL
},
431 { "pkinit_win2k_require_binding", krb5_config_string
, NULL
},
432 { "pkinit_require_eku", krb5_config_string
, NULL
},
433 { "pkinit_require_krbtgt_otherName", krb5_config_string
, NULL
},
434 { "pkinit_require_hostname_match", krb5_config_string
, NULL
},
436 { "anonymous", krb5_config_string
, check_boolean
},
438 { "", krb5_config_list
, appdefaults_entries
},
442 struct entry realms_entries
[] = {
443 { "forwardable", krb5_config_string
, check_boolean
},
444 { "proxiable", krb5_config_string
, check_boolean
},
445 { "ticket_lifetime", krb5_config_string
, check_time
},
446 { "renew_lifetime", krb5_config_string
, check_time
},
447 { "warn_pwexpire", krb5_config_string
, check_time
},
448 { "kdc", krb5_config_string
, check_host
},
449 { "admin_server", krb5_config_string
, check_host
},
450 { "kpasswd_server", krb5_config_string
, check_host
},
451 { "krb524_server", krb5_config_string
, check_host
},
452 { "v4_name_convert", krb5_config_list
, v4_name_convert_entries
},
453 { "v4_instance_convert", krb5_config_list
, all_strings
},
454 { "v4_domains", krb5_config_string
, NULL
},
455 { "default_domain", krb5_config_string
, NULL
},
456 { "win2k_pkinit", krb5_config_string
, NULL
},
458 { "admin_keytab", krb5_config_string
, mit_entry
},
459 { "acl_file", krb5_config_string
, mit_entry
},
460 { "dict_file", krb5_config_string
, mit_entry
},
461 { "kadmind_port", krb5_config_string
, mit_entry
},
462 { "kpasswd_port", krb5_config_string
, mit_entry
},
463 { "master_key_name", krb5_config_string
, mit_entry
},
464 { "master_key_type", krb5_config_string
, mit_entry
},
465 { "key_stash_file", krb5_config_string
, mit_entry
},
466 { "max_life", krb5_config_string
, mit_entry
},
467 { "max_renewable_life", krb5_config_string
, mit_entry
},
468 { "default_principal_expiration", krb5_config_string
, mit_entry
},
469 { "default_principal_flags", krb5_config_string
, mit_entry
},
470 { "supported_enctypes", krb5_config_string
, mit_entry
},
471 { "database_name", krb5_config_string
, mit_entry
},
475 struct entry realms_foobar
[] = {
476 { "", krb5_config_list
, realms_entries
},
481 struct entry kdc_database_entries
[] = {
482 { "realm", krb5_config_string
, NULL
},
483 { "dbname", krb5_config_string
, NULL
},
484 { "mkey_file", krb5_config_string
, NULL
},
485 { "acl_file", krb5_config_string
, NULL
},
486 { "log_file", krb5_config_string
, NULL
},
490 struct entry kdc_entries
[] = {
491 { "database", krb5_config_list
, kdc_database_entries
},
492 { "key-file", krb5_config_string
, NULL
},
493 { "logging", krb5_config_string
, check_log
},
494 { "max-request", krb5_config_string
, check_bytes
},
495 { "require-preauth", krb5_config_string
, check_boolean
},
496 { "ports", krb5_config_string
, NULL
},
497 { "addresses", krb5_config_string
, NULL
},
498 { "enable-kerberos4", krb5_config_string
, check_boolean
},
499 { "enable-524", krb5_config_string
, check_boolean
},
500 { "enable-http", krb5_config_string
, check_boolean
},
501 { "check-ticket-addresses", krb5_config_string
, check_boolean
},
502 { "allow-null-ticket-addresses", krb5_config_string
, check_boolean
},
503 { "allow-anonymous", krb5_config_string
, check_boolean
},
504 { "v4_realm", krb5_config_string
, NULL
},
505 { "enable-kaserver", krb5_config_string
, check_boolean
},
506 { "encode_as_rep_as_tgs_rep", krb5_config_string
, check_boolean
},
507 { "kdc_warn_pwexpire", krb5_config_string
, check_time
},
508 { "use_2b", krb5_config_list
, NULL
},
509 { "enable-pkinit", krb5_config_string
, check_boolean
},
510 { "pkinit_identity", krb5_config_string
, NULL
},
511 { "pkinit_anchors", krb5_config_string
, NULL
},
512 { "pkinit_pool", krb5_config_string
, NULL
},
513 { "pkinit_revoke", krb5_config_string
, NULL
},
514 { "pkinit_kdc_ocsp", krb5_config_string
, NULL
},
515 { "pkinit_principal_in_certificate", krb5_config_string
, NULL
},
516 { "pkinit_dh_min_bits", krb5_config_string
, NULL
},
517 { "pkinit_allow_proxy_certificate", krb5_config_string
, NULL
},
518 { "hdb-ldap-create-base", krb5_config_string
, NULL
},
519 { "v4-realm", krb5_config_string
, NULL
},
523 struct entry kadmin_entries
[] = {
524 { "password_lifetime", krb5_config_string
, check_time
},
525 { "default_keys", krb5_config_string
, NULL
},
526 { "use_v4_salt", krb5_config_string
, NULL
},
527 { "require-preauth", krb5_config_string
, check_boolean
},
530 struct entry log_strings
[] = {
531 { "", krb5_config_string
, check_log
},
537 struct entry kdcdefaults_entries
[] = {
538 { "kdc_ports", krb5_config_string
, mit_entry
},
539 { "v4_mode", krb5_config_string
, mit_entry
},
543 struct entry capaths_entries
[] = {
544 { "", krb5_config_list
, all_strings
},
548 struct entry password_quality_entries
[] = {
549 { "policies", krb5_config_string
, NULL
},
550 { "external_program", krb5_config_string
, NULL
},
551 { "min_classes", krb5_config_string
, check_numeric
},
552 { "min_length", krb5_config_string
, check_numeric
},
553 { "", krb5_config_list
, all_strings
},
557 struct entry toplevel_sections
[] = {
558 { "libdefaults" , krb5_config_list
, libdefaults_entries
},
559 { "realms", krb5_config_list
, realms_foobar
},
560 { "domain_realm", krb5_config_list
, all_strings
},
561 { "logging", krb5_config_list
, log_strings
},
562 { "kdc", krb5_config_list
, kdc_entries
},
563 { "kadmin", krb5_config_list
, kadmin_entries
},
564 { "appdefaults", krb5_config_list
, appdefaults_entries
},
565 { "gssapi", krb5_config_list
, NULL
},
566 { "capaths", krb5_config_list
, capaths_entries
},
567 { "password_quality", krb5_config_list
, password_quality_entries
},
569 { "kdcdefaults", krb5_config_list
, kdcdefaults_entries
},
575 check_section(krb5_context context
, const char *path
, krb5_config_section
*cf
,
576 struct entry
*entries
)
579 krb5_config_section
*p
;
584 for(p
= cf
; p
!= NULL
; p
= p
->next
) {
585 asprintf(&local
, "%s/%s", path
, p
->name
);
586 for(e
= entries
; e
->name
!= NULL
; e
++) {
587 if(*e
->name
== '\0' || strcmp(e
->name
, p
->name
) == 0) {
588 if(e
->type
!= p
->type
) {
589 krb5_warnx(context
, "%s: unknown or wrong type", local
);
591 } else if(p
->type
== krb5_config_string
&& e
->check_data
!= NULL
) {
592 error
|= (*(check_func_t
)e
->check_data
)(context
, local
, p
->u
.string
);
593 } else if(p
->type
== krb5_config_list
&& e
->check_data
!= NULL
) {
594 error
|= check_section(context
, local
, p
->u
.list
, e
->check_data
);
599 if(e
->name
== NULL
) {
600 krb5_warnx(context
, "%s: unknown entry", local
);
610 dumpconfig(int level
, krb5_config_section
*top
)
612 krb5_config_section
*x
;
613 for(x
= top
; x
; x
= x
->next
) {
615 case krb5_config_list
:
617 printf("[%s]\n", x
->name
);
619 printf("%*s%s = {\n", 4 * level
, " ", x
->name
);
621 dumpconfig(level
+ 1, x
->u
.list
);
623 printf("%*s}\n", 4 * level
, " ");
625 case krb5_config_string
:
626 printf("%*s%s = %s\n", 4 * level
, " ", x
->name
, x
->u
.string
);
633 main(int argc
, char **argv
)
635 krb5_context context
;
637 krb5_config_section
*tmp_cf
;
640 setprogname (argv
[0]);
642 ret
= krb5_init_context(&context
);
643 if (ret
== KRB5_CONFIG_BADFORMAT
)
644 errx (1, "krb5_init_context failed to parse configuration file");
646 errx (1, "krb5_init_context failed with %d", ret
);
648 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
664 krb5_get_default_config_files(&argv
);
667 ret
= krb5_config_parse_file_multi(context
, *argv
, &tmp_cf
);
669 krb5_warn (context
, ret
, "krb5_config_parse_file");
674 dumpconfig(0, tmp_cf
);
676 return check_section(context
, "", tmp_cf
, toplevel_sections
);