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