export get_dbinfo as krb5_kdc_set_dbinfo and call from users. This to allows libkdc users to to specify their own databases

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21110 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2007-06-18 10:52:20 +00:00
parent b1f3eb8118
commit c561d08c04
4 changed files with 34 additions and 11 deletions

View File

@@ -202,6 +202,10 @@ configure(krb5_context context, int argc, char **argv)
kdc_openlog(context, config); kdc_openlog(context, config);
ret = krb5_kdc_set_dbinfo(context, config);
if (ret)
krb5_err(context, 1, ret, "krb5_kdc_set_dbinfo");
if(max_request_str) if(max_request_str)
max_request = parse_bytes(max_request_str, NULL); max_request = parse_bytes(max_request_str, NULL);

View File

@@ -38,36 +38,39 @@
RCSID("$Id$"); RCSID("$Id$");
static void krb5_error_code
get_dbinfo(krb5_context context, struct krb5_kdc_configuration *c) krb5_kdc_set_dbinfo(krb5_context context, struct krb5_kdc_configuration *c)
{ {
struct hdb_dbinfo *info, *d; struct hdb_dbinfo *info, *d;
krb5_error_code ret; krb5_error_code ret;
int i;
/* fetch the databases */ /* fetch the databases */
ret = hdb_get_dbinfo(context, &info); ret = hdb_get_dbinfo(context, &info);
if (ret) if (ret)
krb5_err(context, 1, ret, "hdb_get_dbinfo"); return ret;
d = NULL; d = NULL;
while ((d = hdb_dbinfo_get_next(info, d)) != NULL) { while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {
void *ptr; void *ptr;
ptr = realloc(c->db, (c->num_db + 1) * sizeof(*c->db)); ptr = realloc(c->db, (c->num_db + 1) * sizeof(*c->db));
if (ptr == NULL) if (ptr == NULL) {
krb5_err(context, 1, ret, "out of memory"); ret = ENOMEM;
krb5_set_error_string(context, "out of memory");
goto out;
}
c->db = ptr; c->db = ptr;
ret = hdb_create(context, &c->db[c->num_db], ret = hdb_create(context, &c->db[c->num_db],
hdb_dbinfo_get_dbname(context, d)); hdb_dbinfo_get_dbname(context, d));
if(ret) if(ret)
krb5_err(context, 1, ret, "hdb_create %s", goto out;
hdb_dbinfo_get_dbname(context, d));
ret = hdb_set_master_keyfile(context, c->db[c->num_db], ret = hdb_set_master_keyfile(context, c->db[c->num_db],
hdb_dbinfo_get_mkey_file(context, d)); hdb_dbinfo_get_mkey_file(context, d));
if (ret) if (ret)
krb5_err(context, 1, ret, "hdb_set_master_keyfile"); goto out;
c->num_db++; c->num_db++;
@@ -81,10 +84,23 @@ get_dbinfo(krb5_context context, struct krb5_kdc_configuration *c)
hdb_dbinfo_get_mkey_file(context, d)); hdb_dbinfo_get_mkey_file(context, d));
} }
hdb_free_dbinfo(context, &info); hdb_free_dbinfo(context, &info);
return 0;
out:
for (i = 0; i < c->num_db; i++)
if (c->db[i] && c->db[i]->hdb_destroy)
(*c->db[i]->hdb_destroy)(context, c->db[i]);
c->num_db = 0;
free(c->db);
c->db = NULL;
hdb_free_dbinfo(context, &info);
return ret;
} }
int krb5_error_code
krb5_kdc_get_config(krb5_context context, krb5_kdc_configuration **config) krb5_kdc_get_config(krb5_context context, krb5_kdc_configuration **config)
{ {
krb5_kdc_configuration *c; krb5_kdc_configuration *c;
@@ -112,8 +128,6 @@ krb5_kdc_get_config(krb5_context context, krb5_kdc_configuration **config)
c->num_db = 0; c->num_db = 0;
c->logf = NULL; c->logf = NULL;
get_dbinfo(context, c);
c->require_preauth = c->require_preauth =
krb5_config_get_bool_default(context, NULL, krb5_config_get_bool_default(context, NULL,
c->require_preauth, c->require_preauth,

View File

@@ -84,6 +84,10 @@ main(int argc, char **argv)
kdc_openlog(context, config); kdc_openlog(context, config);
ret = krb5_kdc_set_dbinfo(context, config);
if (ret)
krb5_err(context, 1, ret, "krb5_kdc_set_dbinfo");
if (argc != 2) if (argc != 2)
errx(1, "argc != 2"); errx(1, "argc != 2");

View File

@@ -8,6 +8,7 @@ HEIMDAL_KDC_1.0 {
kdc_openlog; kdc_openlog;
krb5_kdc_windc_init; krb5_kdc_windc_init;
krb5_kdc_get_config; krb5_kdc_get_config;
krb5_kdc_set_dbinfo;
krb5_kdc_process_krb5_request; krb5_kdc_process_krb5_request;
krb5_kdc_process_request; krb5_kdc_process_request;
krb5_kdc_save_request; krb5_kdc_save_request;