Use hdb_get_dbinfo to pick up configuration.
ctx->config.realm can be NULL, check for that, from Bjorn S. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21413 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -53,45 +53,6 @@ set_funcs(kadm5_server_context *c)
|
|||||||
SET(c, rename_principal);
|
SET(c, rename_principal);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct database_spec {
|
|
||||||
char *dbpath;
|
|
||||||
char *logfile;
|
|
||||||
char *mkeyfile;
|
|
||||||
char *aclfile;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
set_field(krb5_context context, const krb5_config_binding *binding,
|
|
||||||
const char *dbname, const char *name, const char *ext,
|
|
||||||
char **variable)
|
|
||||||
{
|
|
||||||
const char *p;
|
|
||||||
|
|
||||||
if (*variable != NULL)
|
|
||||||
free (*variable);
|
|
||||||
|
|
||||||
p = krb5_config_get_string(context, binding, name, NULL);
|
|
||||||
if(p)
|
|
||||||
*variable = strdup(p);
|
|
||||||
else {
|
|
||||||
const char *p1;
|
|
||||||
p = strrchr(dbname, '.');
|
|
||||||
p1 = strrchr(dbname, '/');
|
|
||||||
if (p1) {
|
|
||||||
p1++;
|
|
||||||
if (p1 > p)
|
|
||||||
p = p1 + strlen(p1);
|
|
||||||
}
|
|
||||||
if(p1 == NULL)
|
|
||||||
asprintf(variable, "%s/%s.%s", HDB_DB_DIR, dbname, ext);
|
|
||||||
else
|
|
||||||
asprintf(variable, "%.*s/%.*s.%s",
|
|
||||||
(int)(p1 - dbname), dbname,
|
|
||||||
(int)(p - p1), p1,
|
|
||||||
ext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_socket_name(const char *dbname, struct sockaddr_un *un)
|
set_socket_name(const char *dbname, struct sockaddr_un *un)
|
||||||
{
|
{
|
||||||
@@ -107,77 +68,58 @@ set_socket_name(const char *dbname, struct sockaddr_un *un)
|
|||||||
(int)(p - dbname), dbname);
|
(int)(p - dbname), dbname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
set_config(kadm5_server_context *ctx,
|
|
||||||
const krb5_config_binding *binding)
|
|
||||||
{
|
|
||||||
const char *p;
|
|
||||||
if(ctx->config.dbname == NULL) {
|
|
||||||
p = krb5_config_get_string(ctx->context, binding, "dbname", NULL);
|
|
||||||
if(p)
|
|
||||||
ctx->config.dbname = strdup(p);
|
|
||||||
else
|
|
||||||
ctx->config.dbname = strdup(HDB_DEFAULT_DB);
|
|
||||||
}
|
|
||||||
if(ctx->log_context.log_file == NULL)
|
|
||||||
set_field(ctx->context, binding, ctx->config.dbname,
|
|
||||||
"log_file", "log", &ctx->log_context.log_file);
|
|
||||||
set_socket_name(ctx->config.dbname, &ctx->log_context.socket_name);
|
|
||||||
if(ctx->config.acl_file == NULL)
|
|
||||||
set_field(ctx->context, binding, ctx->config.dbname,
|
|
||||||
"acl_file", "acl", &ctx->config.acl_file);
|
|
||||||
if(ctx->config.stash_file == NULL)
|
|
||||||
set_field(ctx->context, binding, ctx->config.dbname,
|
|
||||||
"mkey_file", "mkey", &ctx->config.stash_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
static kadm5_ret_t
|
static kadm5_ret_t
|
||||||
find_db_spec(kadm5_server_context *ctx)
|
find_db_spec(kadm5_server_context *ctx)
|
||||||
{
|
{
|
||||||
const krb5_config_binding *top_binding = NULL;
|
|
||||||
const krb5_config_binding *db_binding;
|
|
||||||
const krb5_config_binding *default_binding = NULL;
|
|
||||||
krb5_context context = ctx->context;
|
krb5_context context = ctx->context;
|
||||||
|
struct hdb_dbinfo *info, *d;
|
||||||
|
krb5_error_code ret;
|
||||||
|
|
||||||
while((db_binding =
|
if (ctx->config.realm) {
|
||||||
krb5_config_get_next(context,
|
/* fetch the databases */
|
||||||
NULL,
|
ret = hdb_get_dbinfo(context, &info);
|
||||||
&top_binding,
|
if (ret)
|
||||||
krb5_config_list,
|
return ret;
|
||||||
"kdc",
|
|
||||||
"database",
|
d = NULL;
|
||||||
NULL))) {
|
while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {
|
||||||
const char *p;
|
const char *p = hdb_dbinfo_get_realm(context, d);
|
||||||
p = krb5_config_get_string(context, db_binding, "realm", NULL);
|
|
||||||
if(p == NULL) {
|
if(strcmp(ctx->config.realm, p) != 0)
|
||||||
if(default_binding) {
|
continue;
|
||||||
krb5_warnx(context, "WARNING: more than one realm-less "
|
|
||||||
"database specification");
|
ctx->config.dbname = strdup(p);
|
||||||
krb5_warnx(context, "WARNING: using the first encountered");
|
|
||||||
} else
|
p = hdb_dbinfo_get_acl_file(context, d);
|
||||||
default_binding = db_binding;
|
if (p)
|
||||||
continue;
|
ctx->config.acl_file = strdup(p);
|
||||||
|
|
||||||
|
p = hdb_dbinfo_get_mkey_file(context, d);
|
||||||
|
if (p)
|
||||||
|
ctx->config.stash_file = strdup(p);
|
||||||
|
|
||||||
|
p = hdb_dbinfo_get_log_file(context, d);
|
||||||
|
if (p)
|
||||||
|
ctx->log_context.log_file = strdup(p);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(strcmp(ctx->config.realm, p) != 0)
|
hdb_free_dbinfo(context, &info);
|
||||||
continue;
|
}
|
||||||
|
|
||||||
set_config(ctx, db_binding);
|
/* If any of the values was unset, pick up the default value */
|
||||||
return 0;
|
|
||||||
}
|
if (ctx->config.dbname == NULL)
|
||||||
if(default_binding)
|
ctx->config.dbname = strdup(HDB_DEFAULT_DB);
|
||||||
set_config(ctx, default_binding);
|
if (ctx->config.acl_file == NULL)
|
||||||
else {
|
ctx->config.acl_file = strdup(HDB_DB_DIR "/kadmind.acl");
|
||||||
ctx->config.dbname = strdup(HDB_DEFAULT_DB);
|
if (ctx->config.stash_file == NULL)
|
||||||
ctx->config.acl_file = strdup(HDB_DB_DIR "/kadmind.acl");
|
ctx->config.stash_file = strdup(HDB_DB_DIR "/m-key");
|
||||||
ctx->config.stash_file = strdup(HDB_DB_DIR "/m-key");
|
if (ctx->log_context.log_file == NULL)
|
||||||
ctx->log_context.log_file = strdup(HDB_DB_DIR "/log");
|
ctx->log_context.log_file = strdup(HDB_DB_DIR "/log");
|
||||||
memset(&ctx->log_context.socket_name, 0,
|
|
||||||
sizeof(ctx->log_context.socket_name));
|
set_socket_name(ctx->config.dbname,
|
||||||
ctx->log_context.socket_name.sun_family = AF_UNIX;
|
&ctx->log_context.socket_name);
|
||||||
strlcpy(ctx->log_context.socket_name.sun_path,
|
|
||||||
KADM5_LOG_SIGNAL,
|
|
||||||
sizeof(ctx->log_context.socket_name.sun_path));
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user