summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/kadm5/context_s.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/heimdal/lib/kadm5/context_s.c')
-rw-r--r--crypto/heimdal/lib/kadm5/context_s.c153
1 files changed, 51 insertions, 102 deletions
diff --git a/crypto/heimdal/lib/kadm5/context_s.c b/crypto/heimdal/lib/kadm5/context_s.c
index a5a78e6..6ac7a9c 100644
--- a/crypto/heimdal/lib/kadm5/context_s.c
+++ b/crypto/heimdal/lib/kadm5/context_s.c
@@ -33,7 +33,7 @@
#include "kadm5_locl.h"
-RCSID("$Id: context_s.c,v 1.17 2002/08/26 13:28:36 assar Exp $");
+RCSID("$Id: context_s.c 22211 2007-12-07 19:27:27Z lha $");
static void
set_funcs(kadm5_server_context *c)
@@ -53,121 +53,70 @@ set_funcs(kadm5_server_context *c)
SET(c, rename_principal);
}
-struct database_spec {
- char *dbpath;
- char *logfile;
- char *mkeyfile;
- char *aclfile;
-};
-
static void
-set_field(krb5_context context, krb5_config_binding *binding,
- const char *dbname, const char *name, const char *ext,
- char **variable)
+set_socket_name(krb5_context context, struct sockaddr_un *un)
{
- const char *p;
-
- if (*variable != NULL)
- free (*variable);
-
- p = krb5_config_get_string(context, binding, name, NULL);
- if(p)
- *variable = strdup(p);
- else {
- p = strrchr(dbname, '.');
- if(p == NULL)
- asprintf(variable, "%s.%s", dbname, ext);
- else
- asprintf(variable, "%.*s.%s", (int)(p - dbname), dbname, ext);
- }
-}
+ const char *fn = kadm5_log_signal_socket(context);
-static void
-set_socket_name(const char *dbname, struct sockaddr_un *un)
-{
- const char *p;
memset(un, 0, sizeof(*un));
un->sun_family = AF_UNIX;
- p = strrchr(dbname, '.');
- if(p == NULL)
- snprintf(un->sun_path, sizeof(un->sun_path), "%s.signal",
- dbname);
- else
- snprintf(un->sun_path, sizeof(un->sun_path), "%.*s.signal",
- (int)(p - dbname), dbname);
-}
-
-static void
-set_config(kadm5_server_context *ctx,
- 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);
+ strlcpy (un->sun_path, fn, sizeof(un->sun_path));
}
static kadm5_ret_t
find_db_spec(kadm5_server_context *ctx)
{
- const krb5_config_binding *top_binding = NULL;
- krb5_config_binding *db_binding;
- krb5_config_binding *default_binding = NULL;
krb5_context context = ctx->context;
+ struct hdb_dbinfo *info, *d;
+ krb5_error_code ret;
- while((db_binding = (krb5_config_binding *)
- krb5_config_get_next(context,
- NULL,
- &top_binding,
- krb5_config_list,
- "kdc",
- "database",
- NULL))) {
- const char *p;
- p = krb5_config_get_string(context, db_binding, "realm", NULL);
- if(p == NULL) {
- if(default_binding) {
- krb5_warnx(context, "WARNING: more than one realm-less "
- "database specification");
- krb5_warnx(context, "WARNING: using the first encountered");
- } else
- default_binding = db_binding;
- continue;
- }
- if(strcmp(ctx->config.realm, p) != 0)
- continue;
+ if (ctx->config.realm) {
+ /* fetch the databases */
+ ret = hdb_get_dbinfo(context, &info);
+ if (ret)
+ return ret;
- set_config(ctx, db_binding);
- return 0;
- }
- if(default_binding)
- set_config(ctx, default_binding);
- else {
- ctx->config.dbname = strdup(HDB_DEFAULT_DB);
- ctx->config.acl_file = strdup(HDB_DB_DIR "/kadmind.acl");
- ctx->config.stash_file = strdup(HDB_DB_DIR "/m-key");
- ctx->log_context.log_file = strdup(HDB_DB_DIR "/log");
- memset(&ctx->log_context.socket_name, 0,
- sizeof(ctx->log_context.socket_name));
- ctx->log_context.socket_name.sun_family = AF_UNIX;
- strlcpy(ctx->log_context.socket_name.sun_path,
- KADM5_LOG_SIGNAL,
- sizeof(ctx->log_context.socket_name.sun_path));
+ d = NULL;
+ while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {
+ const char *p = hdb_dbinfo_get_realm(context, d);
+
+ /* match default (realm-less) */
+ if(p != NULL && strcmp(ctx->config.realm, p) != 0)
+ continue;
+
+ p = hdb_dbinfo_get_dbname(context, d);
+ if (p)
+ ctx->config.dbname = strdup(p);
+
+ p = hdb_dbinfo_get_acl_file(context, d);
+ if (p)
+ 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;
+ }
+ hdb_free_dbinfo(context, &info);
}
+
+ /* If any of the values was unset, pick up the default value */
+
+ if (ctx->config.dbname == NULL)
+ ctx->config.dbname = strdup(hdb_default_db(context));
+ if (ctx->config.acl_file == NULL)
+ asprintf(&ctx->config.acl_file, "%s/kadmind.acl", hdb_db_dir(context));
+ if (ctx->config.stash_file == NULL)
+ asprintf(&ctx->config.stash_file, "%s/m-key", hdb_db_dir(context));
+ if (ctx->log_context.log_file == NULL)
+ asprintf(&ctx->log_context.log_file, "%s/log", hdb_db_dir(context));
+
+ set_socket_name(context, &ctx->log_context.socket_name);
+
return 0;
}
OpenPOWER on IntegriCloud