Merge in the libkdc/kdc configuration split from Andrew Bartlet <abartlet@samba.org>
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15529 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
307
kdc/config.c
307
kdc/config.c
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 1997-2004 Kungliga Tekniska H<>gskolan
|
||||
* Copyright (c) 1997-2005 Kungliga Tekniska H<>skolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,50 +38,34 @@
|
||||
|
||||
RCSID("$Id$");
|
||||
|
||||
struct dbinfo {
|
||||
char *realm;
|
||||
char *dbname;
|
||||
char *mkey_file;
|
||||
struct dbinfo *next;
|
||||
};
|
||||
|
||||
static const char *config_file; /* location of kdc config file */
|
||||
|
||||
int require_preauth = -1; /* 1 == require preauth for all principals */
|
||||
|
||||
size_t max_request; /* maximal size of a request */
|
||||
|
||||
static int require_preauth = -1; /* 1 == require preauth for all principals */
|
||||
static char *max_request_str; /* `max_request' as a string */
|
||||
|
||||
time_t kdc_warn_pwexpire; /* time before expiration to print a warning */
|
||||
|
||||
struct dbinfo *databases;
|
||||
HDB **db;
|
||||
int num_db;
|
||||
|
||||
const char *port_str;
|
||||
|
||||
int detach_from_console = -1;
|
||||
#define DETACH_IS_DEFAULT FALSE
|
||||
|
||||
int enable_http = -1;
|
||||
krb5_boolean encode_as_rep_as_tgs_rep; /* bug compatibility */
|
||||
|
||||
krb5_boolean check_ticket_addresses;
|
||||
krb5_boolean allow_null_ticket_addresses;
|
||||
krb5_boolean allow_anonymous;
|
||||
int trpolicy;
|
||||
static const char *trpolicy_str;
|
||||
|
||||
static struct getarg_strings addresses_str; /* addresses to listen on */
|
||||
krb5_addresses explicit_addresses;
|
||||
|
||||
static int disable_des = -1;
|
||||
|
||||
char *v4_realm;
|
||||
int enable_v4 = -1;
|
||||
int enable_kaserver = -1;
|
||||
|
||||
int enable_524 = -1;
|
||||
int enable_v4_cross_realm = -1;
|
||||
static int enable_v4 = -1;
|
||||
static int enable_kaserver = -1;
|
||||
static int enable_524 = -1;
|
||||
static int enable_v4_cross_realm = -1;
|
||||
|
||||
static int builtin_hdb_flag;
|
||||
static int help_flag;
|
||||
static int version_flag;
|
||||
|
||||
static struct getarg_strings addresses_str; /* addresses to listen on */
|
||||
|
||||
static char *v4_realm;
|
||||
|
||||
static struct getargs args[] = {
|
||||
{
|
||||
"config-file", 'c', arg_string, &config_file,
|
||||
@@ -94,12 +79,6 @@ static struct getargs args[] = {
|
||||
"max-request", 0, arg_string, &max_request,
|
||||
"max size for a kdc-request", "size"
|
||||
},
|
||||
#if 0
|
||||
{
|
||||
"database", 'd', arg_string, &databases,
|
||||
"location of database", "database"
|
||||
},
|
||||
#endif
|
||||
{ "enable-http", 'H', arg_flag, &enable_http, "turn on HTTP support" },
|
||||
{ "524", 0, arg_negative_flag, &enable_524,
|
||||
"don't respond to 524 requests"
|
||||
@@ -153,7 +132,7 @@ usage(int ret)
|
||||
}
|
||||
|
||||
static void
|
||||
get_dbinfo(void)
|
||||
get_dbinfo(krb5_context context, struct krb5_kdc_configuration *config)
|
||||
{
|
||||
const krb5_config_binding *top_binding = NULL;
|
||||
const krb5_config_binding *db_binding;
|
||||
@@ -162,8 +141,10 @@ get_dbinfo(void)
|
||||
const char *default_dbname = HDB_DEFAULT_DB;
|
||||
const char *default_mkey = HDB_DB_DIR "/m-key";
|
||||
const char *p;
|
||||
krb5_error_code ret;
|
||||
|
||||
struct dbinfo *databases = NULL;
|
||||
|
||||
databases = NULL;
|
||||
dt = &databases;
|
||||
while((db_binding = (const krb5_config_binding *)
|
||||
krb5_config_get_next(context, NULL, &top_binding,
|
||||
@@ -229,10 +210,36 @@ get_dbinfo(void)
|
||||
(int)(p - di->dbname), di->dbname);
|
||||
}
|
||||
}
|
||||
|
||||
if (databases == NULL) {
|
||||
config->db = malloc(sizeof(*config->db));
|
||||
config->num_db = 1;
|
||||
ret = hdb_create(context, &config->db[0], NULL);
|
||||
if(ret)
|
||||
krb5_err(context, 1, ret, "hdb_create %s", HDB_DEFAULT_DB);
|
||||
ret = hdb_set_master_keyfile(context, config->db[0], NULL);
|
||||
if (ret)
|
||||
krb5_err(context, 1, ret, "hdb_set_master_keyfile");
|
||||
} else {
|
||||
struct dbinfo *d;
|
||||
int i;
|
||||
/* count databases */
|
||||
for(d = databases, i = 0; d; d = d->next, i++);
|
||||
config->db = malloc(i * sizeof(*config->db));
|
||||
for(d = databases, config->num_db = 0; d; d = d->next, config->num_db++) {
|
||||
ret = hdb_create(context, &config->db[config->num_db], d->dbname);
|
||||
if(ret)
|
||||
krb5_err(context, 1, ret, "hdb_create %s", d->dbname);
|
||||
ret = hdb_set_master_keyfile(context, config->db[config->num_db], d->mkey_file);
|
||||
if (ret)
|
||||
krb5_err(context, 1, ret, "hdb_set_master_keyfile");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
add_one_address (const char *str, int first)
|
||||
add_one_address (krb5_context context, const char *str, int first)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
krb5_addresses tmp;
|
||||
@@ -247,15 +254,21 @@ add_one_address (const char *str, int first)
|
||||
krb5_free_addresses (context, &tmp);
|
||||
}
|
||||
|
||||
void
|
||||
configure(int argc, char **argv)
|
||||
struct krb5_kdc_configuration *configure(krb5_context context, int argc, char **argv)
|
||||
{
|
||||
struct krb5_kdc_configuration *config = malloc(sizeof(*config));
|
||||
krb5_error_code ret;
|
||||
int optind = 0;
|
||||
int optidx = 0;
|
||||
const char *p;
|
||||
|
||||
while(getarg(args, num_args, argc, argv, &optind))
|
||||
warnx("error at argument `%s'", argv[optind]);
|
||||
if (!config) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
krb5_kdc_default_config(config);
|
||||
|
||||
while(getarg(args, num_args, argc, argv, &optidx))
|
||||
warnx("error at argument `%s'", argv[optidx]);
|
||||
|
||||
if(help_flag)
|
||||
usage (0);
|
||||
@@ -275,8 +288,8 @@ configure(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
argc -= optidx;
|
||||
argv += optidx;
|
||||
|
||||
if (argc != 0)
|
||||
usage(1);
|
||||
@@ -297,7 +310,9 @@ configure(int argc, char **argv)
|
||||
krb5_err(context, 1, ret, "reading configuration files");
|
||||
}
|
||||
|
||||
get_dbinfo();
|
||||
kdc_openlog(context, config);
|
||||
|
||||
get_dbinfo(context, config);
|
||||
|
||||
if(max_request_str)
|
||||
max_request = parse_bytes(max_request_str, NULL);
|
||||
@@ -312,9 +327,14 @@ configure(int argc, char **argv)
|
||||
max_request = parse_bytes(p, NULL);
|
||||
}
|
||||
|
||||
if(require_preauth == -1)
|
||||
require_preauth = krb5_config_get_bool(context, NULL, "kdc",
|
||||
"require-preauth", NULL);
|
||||
if(require_preauth == -1) {
|
||||
config->require_preauth = krb5_config_get_bool_default(context, NULL,
|
||||
config->require_preauth,
|
||||
"kdc",
|
||||
"require-preauth", NULL);
|
||||
} else {
|
||||
config->require_preauth = require_preauth;
|
||||
}
|
||||
|
||||
if(port_str == NULL){
|
||||
p = krb5_config_get_string(context, NULL, "kdc", "ports", NULL);
|
||||
@@ -328,58 +348,85 @@ configure(int argc, char **argv)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < addresses_str.num_strings; ++i)
|
||||
add_one_address (addresses_str.strings[i], i == 0);
|
||||
add_one_address (context, addresses_str.strings[i], i == 0);
|
||||
free_getarg_strings (&addresses_str);
|
||||
} else {
|
||||
char **foo = krb5_config_get_strings (context, NULL,
|
||||
"kdc", "addresses", NULL);
|
||||
|
||||
if (foo != NULL) {
|
||||
add_one_address (*foo++, TRUE);
|
||||
add_one_address (context, *foo++, TRUE);
|
||||
while (*foo)
|
||||
add_one_address (*foo++, FALSE);
|
||||
add_one_address (context, *foo++, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if(enable_v4 == -1)
|
||||
enable_v4 = krb5_config_get_bool_default(context, NULL, FALSE, "kdc",
|
||||
"enable-kerberos4", NULL);
|
||||
if(enable_v4_cross_realm == -1)
|
||||
enable_v4_cross_realm =
|
||||
if(enable_v4 == -1) {
|
||||
config->enable_v4 = krb5_config_get_bool_default(context, NULL,
|
||||
config->enable_v4,
|
||||
"kdc",
|
||||
"enable-kerberos4",
|
||||
NULL);
|
||||
} else {
|
||||
config->enable_v4 = enable_v4;
|
||||
}
|
||||
|
||||
if(enable_v4_cross_realm == -1) {
|
||||
config->enable_v4_cross_realm =
|
||||
krb5_config_get_bool_default(context, NULL,
|
||||
FALSE, "kdc",
|
||||
config->enable_v4_cross_realm,
|
||||
"kdc",
|
||||
"enable-kerberos4-cross-realm",
|
||||
NULL);
|
||||
if(enable_524 == -1)
|
||||
enable_524 = krb5_config_get_bool_default(context, NULL, enable_v4,
|
||||
"kdc", "enable-524", NULL);
|
||||
} else {
|
||||
config->enable_v4_cross_realm = enable_v4_cross_realm;
|
||||
}
|
||||
|
||||
if(enable_524 == -1) {
|
||||
config->enable_524 = krb5_config_get_bool_default(context, NULL,
|
||||
config->enable_v4,
|
||||
"kdc", "enable-524",
|
||||
NULL);
|
||||
} else {
|
||||
config->enable_524 = enable_524;
|
||||
}
|
||||
|
||||
if(enable_http == -1)
|
||||
enable_http = krb5_config_get_bool(context, NULL, "kdc",
|
||||
"enable-http", NULL);
|
||||
check_ticket_addresses =
|
||||
krb5_config_get_bool_default(context, NULL, TRUE, "kdc",
|
||||
|
||||
config->check_ticket_addresses =
|
||||
krb5_config_get_bool_default(context, NULL,
|
||||
config->check_ticket_addresses,
|
||||
"kdc",
|
||||
"check-ticket-addresses", NULL);
|
||||
allow_null_ticket_addresses =
|
||||
krb5_config_get_bool_default(context, NULL, TRUE, "kdc",
|
||||
config->allow_null_ticket_addresses =
|
||||
krb5_config_get_bool_default(context, NULL,
|
||||
config->allow_null_ticket_addresses,
|
||||
"kdc",
|
||||
"allow-null-ticket-addresses", NULL);
|
||||
|
||||
allow_anonymous =
|
||||
krb5_config_get_bool(context, NULL, "kdc",
|
||||
"allow-anonymous", NULL);
|
||||
config->allow_anonymous =
|
||||
krb5_config_get_bool_default(context, NULL,
|
||||
config->allow_anonymous,
|
||||
"kdc",
|
||||
"allow-anonymous", NULL);
|
||||
|
||||
trpolicy_str =
|
||||
krb5_config_get_string_default(context, NULL, "always-check", "kdc",
|
||||
krb5_config_get_string_default(context, NULL, "DEFAULT", "kdc",
|
||||
"transited-policy", NULL);
|
||||
if(strcasecmp(trpolicy_str, "always-check") == 0)
|
||||
trpolicy = TRPOLICY_ALWAYS_CHECK;
|
||||
else if(strcasecmp(trpolicy_str, "allow-per-principal") == 0)
|
||||
trpolicy = TRPOLICY_ALLOW_PER_PRINCIPAL;
|
||||
else if(strcasecmp(trpolicy_str, "always-honour-request") == 0)
|
||||
trpolicy = TRPOLICY_ALWAYS_HONOUR_REQUEST;
|
||||
else {
|
||||
kdc_log(0, "unknown transited-policy: %s, reverting to always-check",
|
||||
if(strcasecmp(trpolicy_str, "always-check") == 0) {
|
||||
config->trpolicy = TRPOLICY_ALWAYS_CHECK;
|
||||
} else if(strcasecmp(trpolicy_str, "allow-per-principal") == 0) {
|
||||
config->trpolicy = TRPOLICY_ALLOW_PER_PRINCIPAL;
|
||||
} else if(strcasecmp(trpolicy_str, "always-honour-request") == 0) {
|
||||
config->trpolicy = TRPOLICY_ALWAYS_HONOUR_REQUEST;
|
||||
} else if(strcasecmp(trpolicy_str, "DEFAULT") == 0) {
|
||||
/* default */
|
||||
} else {
|
||||
kdc_log(context, config,
|
||||
0, "unknown transited-policy: %s, reverting to default (always-check)",
|
||||
trpolicy_str);
|
||||
trpolicy = TRPOLICY_ALWAYS_CHECK;
|
||||
}
|
||||
|
||||
if (krb5_config_get_string(context, NULL, "kdc",
|
||||
@@ -393,51 +440,72 @@ configure(int argc, char **argv)
|
||||
"v4-realm",
|
||||
NULL);
|
||||
if(p != NULL) {
|
||||
v4_realm = strdup(p);
|
||||
if (v4_realm == NULL)
|
||||
config->v4_realm = strdup(p);
|
||||
if (config->v4_realm == NULL)
|
||||
krb5_errx(context, 1, "out of memory");
|
||||
} else {
|
||||
config->v4_realm = NULL;
|
||||
}
|
||||
} else {
|
||||
config->v4_realm = v4_realm;
|
||||
}
|
||||
if (enable_kaserver == -1)
|
||||
enable_kaserver = krb5_config_get_bool_default(context, NULL, FALSE,
|
||||
"kdc",
|
||||
"enable-kaserver",
|
||||
NULL);
|
||||
|
||||
encode_as_rep_as_tgs_rep = krb5_config_get_bool(context, NULL, "kdc",
|
||||
"encode_as_rep_as_tgs_rep",
|
||||
NULL);
|
||||
if (enable_kaserver == -1) {
|
||||
config->enable_kaserver =
|
||||
krb5_config_get_bool_default(context,
|
||||
NULL,
|
||||
config->enable_kaserver,
|
||||
"kdc",
|
||||
"enable-kaserver",
|
||||
NULL);
|
||||
} else {
|
||||
config->enable_kaserver = enable_kaserver;
|
||||
}
|
||||
|
||||
kdc_warn_pwexpire = krb5_config_get_time (context, NULL,
|
||||
"kdc",
|
||||
"kdc_warn_pwexpire",
|
||||
NULL);
|
||||
config->encode_as_rep_as_tgs_rep =
|
||||
krb5_config_get_bool_default(context, NULL,
|
||||
config->encode_as_rep_as_tgs_rep,
|
||||
"kdc",
|
||||
"encode_as_rep_as_tgs_rep",
|
||||
NULL);
|
||||
|
||||
config->kdc_warn_pwexpire =
|
||||
krb5_config_get_time_default (context, NULL,
|
||||
config->kdc_warn_pwexpire,
|
||||
"kdc",
|
||||
"kdc_warn_pwexpire",
|
||||
NULL);
|
||||
|
||||
if(detach_from_console == -1)
|
||||
detach_from_console = krb5_config_get_bool_default(context, NULL,
|
||||
DETACH_IS_DEFAULT,
|
||||
"kdc",
|
||||
"detach", NULL);
|
||||
kdc_openlog();
|
||||
|
||||
if(max_request == 0)
|
||||
max_request = 64 * 1024;
|
||||
if(require_preauth == -1)
|
||||
require_preauth = 1;
|
||||
|
||||
if(require_preauth != -1) {
|
||||
config->require_preauth = require_preauth;
|
||||
}
|
||||
if (port_str == NULL)
|
||||
port_str = "+";
|
||||
|
||||
#ifdef PKINIT
|
||||
enable_pkinit = krb5_config_get_bool_default(context, NULL, FALSE,
|
||||
"kdc",
|
||||
"enable-pkinit",
|
||||
NULL);
|
||||
if (enable_pkinit) {
|
||||
config->enable_pkinit =
|
||||
krb5_config_get_bool_default(context,
|
||||
NULL,
|
||||
config->enable_pkinit,
|
||||
"kdc",
|
||||
"enable-pkinit",
|
||||
NULL);
|
||||
if (config->enable_pkinit) {
|
||||
const char *user_id, *x509_anchors;
|
||||
|
||||
user_id = krb5_config_get_string(context, NULL,
|
||||
"kdc",
|
||||
"pki-identity",
|
||||
NULL);
|
||||
"kdc",
|
||||
"pki-identity",
|
||||
NULL);
|
||||
if (user_id == NULL)
|
||||
krb5_errx(context, 1, "pkinit enabled but no identity");
|
||||
|
||||
@@ -450,28 +518,29 @@ configure(int argc, char **argv)
|
||||
|
||||
pk_initialize(user_id, x509_anchors);
|
||||
|
||||
enable_pkinit_princ_in_cert =
|
||||
config->enable_pkinit_princ_in_cert =
|
||||
krb5_config_get_bool_default(context,
|
||||
NULL, TRUE,
|
||||
NULL,
|
||||
config->enable_pkinit_princ_in_cert,
|
||||
"kdc",
|
||||
"pkinit-principal-in-certificate",
|
||||
NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(v4_realm == NULL && (enable_kaserver || enable_v4)){
|
||||
if(config->v4_realm == NULL && (config->enable_kaserver || config->enable_v4)){
|
||||
#ifdef KRB4
|
||||
v4_realm = malloc(40); /* REALM_SZ */
|
||||
if (v4_realm == NULL)
|
||||
config->v4_realm = malloc(40); /* REALM_SZ */
|
||||
if (config->v4_realm == NULL)
|
||||
krb5_errx(context, 1, "out of memory");
|
||||
krb_get_lrealm(v4_realm, 1);
|
||||
krb_get_lrealm(config->v4_realm, 1);
|
||||
#else
|
||||
krb5_errx(context, 1, "No Kerberos 4 realm configured");
|
||||
#endif
|
||||
}
|
||||
if(disable_des == -1)
|
||||
disable_des = krb5_config_get_bool_default(context, NULL,
|
||||
0,
|
||||
FALSE,
|
||||
"kdc",
|
||||
"disable-des", NULL);
|
||||
if(disable_des) {
|
||||
@@ -482,10 +551,12 @@ configure(int argc, char **argv)
|
||||
krb5_enctype_disable(context, ETYPE_DES_CFB64_NONE);
|
||||
krb5_enctype_disable(context, ETYPE_DES_PCBC_NONE);
|
||||
|
||||
kdc_log(0, "DES was disabled, turned off Kerberos V4, 524 "
|
||||
kdc_log(context, config,
|
||||
0, "DES was disabled, turned off Kerberos V4, 524 "
|
||||
"and kaserver");
|
||||
enable_v4 = 0;
|
||||
enable_524 = 0;
|
||||
enable_kaserver = 0;
|
||||
config->enable_v4 = 0;
|
||||
config->enable_524 = 0;
|
||||
config->enable_kaserver = 0;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
Reference in New Issue
Block a user