2 * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
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.
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
34 #include "kadm5_locl.h"
36 RCSID("$Id: context_s.c,v 1.17 2002/08/26 13:28:36 assar Exp $");
39 set_funcs(kadm5_server_context *c)
41 #define SET(C, F) (C)->funcs.F = kadm5_s_ ## F
42 SET(c, chpass_principal);
43 SET(c, chpass_principal_with_key);
44 SET(c, create_principal);
45 SET(c, delete_principal);
48 SET(c, get_principal);
49 SET(c, get_principals);
51 SET(c, modify_principal);
52 SET(c, randkey_principal);
53 SET(c, rename_principal);
56 struct database_spec {
64 set_field(krb5_context context, krb5_config_binding *binding,
65 const char *dbname, const char *name, const char *ext,
70 if (*variable != NULL)
73 p = krb5_config_get_string(context, binding, name, NULL);
75 *variable = strdup(p);
77 p = strrchr(dbname, '.');
79 asprintf(variable, "%s.%s", dbname, ext);
81 asprintf(variable, "%.*s.%s", (int)(p - dbname), dbname, ext);
86 set_socket_name(const char *dbname, struct sockaddr_un *un)
89 memset(un, 0, sizeof(*un));
90 un->sun_family = AF_UNIX;
91 p = strrchr(dbname, '.');
93 snprintf(un->sun_path, sizeof(un->sun_path), "%s.signal",
96 snprintf(un->sun_path, sizeof(un->sun_path), "%.*s.signal",
97 (int)(p - dbname), dbname);
101 set_config(kadm5_server_context *ctx,
102 krb5_config_binding *binding)
105 if(ctx->config.dbname == NULL) {
106 p = krb5_config_get_string(ctx->context, binding, "dbname", NULL);
108 ctx->config.dbname = strdup(p);
110 ctx->config.dbname = strdup(HDB_DEFAULT_DB);
112 if(ctx->log_context.log_file == NULL)
113 set_field(ctx->context, binding, ctx->config.dbname,
114 "log_file", "log", &ctx->log_context.log_file);
115 set_socket_name(ctx->config.dbname, &ctx->log_context.socket_name);
116 if(ctx->config.acl_file == NULL)
117 set_field(ctx->context, binding, ctx->config.dbname,
118 "acl_file", "acl", &ctx->config.acl_file);
119 if(ctx->config.stash_file == NULL)
120 set_field(ctx->context, binding, ctx->config.dbname,
121 "mkey_file", "mkey", &ctx->config.stash_file);
125 find_db_spec(kadm5_server_context *ctx)
127 const krb5_config_binding *top_binding = NULL;
128 krb5_config_binding *db_binding;
129 krb5_config_binding *default_binding = NULL;
130 krb5_context context = ctx->context;
132 while((db_binding = (krb5_config_binding *)
133 krb5_config_get_next(context,
141 p = krb5_config_get_string(context, db_binding, "realm", NULL);
143 if(default_binding) {
144 krb5_warnx(context, "WARNING: more than one realm-less "
145 "database specification");
146 krb5_warnx(context, "WARNING: using the first encountered");
148 default_binding = db_binding;
151 if(strcmp(ctx->config.realm, p) != 0)
154 set_config(ctx, db_binding);
158 set_config(ctx, default_binding);
160 ctx->config.dbname = strdup(HDB_DEFAULT_DB);
161 ctx->config.acl_file = strdup(HDB_DB_DIR "/kadmind.acl");
162 ctx->config.stash_file = strdup(HDB_DB_DIR "/m-key");
163 ctx->log_context.log_file = strdup(HDB_DB_DIR "/log");
164 memset(&ctx->log_context.socket_name, 0,
165 sizeof(ctx->log_context.socket_name));
166 ctx->log_context.socket_name.sun_family = AF_UNIX;
167 strlcpy(ctx->log_context.socket_name.sun_path,
169 sizeof(ctx->log_context.socket_name.sun_path));
175 _kadm5_s_init_context(kadm5_server_context **ctx,
176 kadm5_config_params *params,
177 krb5_context context)
179 *ctx = malloc(sizeof(**ctx));
182 memset(*ctx, 0, sizeof(**ctx));
184 (*ctx)->context = context;
185 krb5_add_et_list (context, initialize_kadm5_error_table_r);
186 #define is_set(M) (params && params->mask & KADM5_CONFIG_ ## M)
188 (*ctx)->config.realm = strdup(params->realm);
190 krb5_get_default_realm(context, &(*ctx)->config.realm);
192 (*ctx)->config.dbname = strdup(params->dbname);
194 (*ctx)->config.acl_file = strdup(params->acl_file);
195 if(is_set(STASH_FILE))
196 (*ctx)->config.stash_file = strdup(params->stash_file);
200 /* PROFILE can't be specified for now */
201 /* KADMIND_PORT is supposed to be used on the server also,
202 but this doesn't make sense */
203 /* ADMIN_SERVER is client only */
204 /* ADNAME is not used at all (as far as I can tell) */
205 /* ADB_LOCKFILE ditto */
208 /* MKEY_FROM_KEYBOARD is not supported */
209 /* MKEY_NAME neither */
221 _kadm5_s_get_db(void *server_handle)
223 kadm5_server_context *context = server_handle;