Path: blob/main/crypto/heimdal/lib/kadm5/context_s.c
34870 views
/*1* Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "kadm5_locl.h"3435RCSID("$Id$");3637static void38set_funcs(kadm5_server_context *c)39{40#define SET(C, F) (C)->funcs.F = kadm5_s_ ## F41SET(c, chpass_principal);42SET(c, chpass_principal_with_key);43SET(c, create_principal);44SET(c, delete_principal);45SET(c, destroy);46SET(c, flush);47SET(c, get_principal);48SET(c, get_principals);49SET(c, get_privs);50SET(c, modify_principal);51SET(c, randkey_principal);52SET(c, rename_principal);53}5455#ifndef NO_UNIX_SOCKETS5657static void58set_socket_name(krb5_context context, struct sockaddr_un *un)59{60const char *fn = kadm5_log_signal_socket(context);6162memset(un, 0, sizeof(*un));63un->sun_family = AF_UNIX;64strlcpy (un->sun_path, fn, sizeof(un->sun_path));6566}67#else6869static void70set_socket_info(krb5_context context, struct addrinfo **info)71{72kadm5_log_signal_socket_info(context, 0, info);73}7475#endif7677static kadm5_ret_t78find_db_spec(kadm5_server_context *ctx)79{80krb5_context context = ctx->context;81struct hdb_dbinfo *info, *d;82krb5_error_code ret;8384if (ctx->config.realm) {85/* fetch the databases */86ret = hdb_get_dbinfo(context, &info);87if (ret)88return ret;8990d = NULL;91while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {92const char *p = hdb_dbinfo_get_realm(context, d);9394/* match default (realm-less) */95if(p != NULL && strcmp(ctx->config.realm, p) != 0)96continue;9798p = hdb_dbinfo_get_dbname(context, d);99if (p)100ctx->config.dbname = strdup(p);101102p = hdb_dbinfo_get_acl_file(context, d);103if (p)104ctx->config.acl_file = strdup(p);105106p = hdb_dbinfo_get_mkey_file(context, d);107if (p)108ctx->config.stash_file = strdup(p);109110p = hdb_dbinfo_get_log_file(context, d);111if (p)112ctx->log_context.log_file = strdup(p);113break;114}115hdb_free_dbinfo(context, &info);116}117118/* If any of the values was unset, pick up the default value */119120if (ctx->config.dbname == NULL)121ctx->config.dbname = strdup(hdb_default_db(context));122if (ctx->config.acl_file == NULL)123asprintf(&ctx->config.acl_file, "%s/kadmind.acl", hdb_db_dir(context));124if (ctx->config.stash_file == NULL)125asprintf(&ctx->config.stash_file, "%s/m-key", hdb_db_dir(context));126if (ctx->log_context.log_file == NULL)127asprintf(&ctx->log_context.log_file, "%s/log", hdb_db_dir(context));128129#ifndef NO_UNIX_SOCKETS130set_socket_name(context, &ctx->log_context.socket_name);131#else132set_socket_info(context, &ctx->log_context.socket_info);133#endif134135return 0;136}137138kadm5_ret_t139_kadm5_s_init_context(kadm5_server_context **ctx,140kadm5_config_params *params,141krb5_context context)142{143*ctx = malloc(sizeof(**ctx));144if(*ctx == NULL)145return ENOMEM;146memset(*ctx, 0, sizeof(**ctx));147set_funcs(*ctx);148(*ctx)->context = context;149krb5_add_et_list (context, initialize_kadm5_error_table_r);150#define is_set(M) (params && params->mask & KADM5_CONFIG_ ## M)151if(is_set(REALM))152(*ctx)->config.realm = strdup(params->realm);153else154krb5_get_default_realm(context, &(*ctx)->config.realm);155if(is_set(DBNAME))156(*ctx)->config.dbname = strdup(params->dbname);157if(is_set(ACL_FILE))158(*ctx)->config.acl_file = strdup(params->acl_file);159if(is_set(STASH_FILE))160(*ctx)->config.stash_file = strdup(params->stash_file);161162find_db_spec(*ctx);163164/* PROFILE can't be specified for now */165/* KADMIND_PORT is supposed to be used on the server also,166but this doesn't make sense */167/* ADMIN_SERVER is client only */168/* ADNAME is not used at all (as far as I can tell) */169/* ADB_LOCKFILE ditto */170/* DICT_FILE */171/* ADMIN_KEYTAB */172/* MKEY_FROM_KEYBOARD is not supported */173/* MKEY_NAME neither */174/* ENCTYPE */175/* MAX_LIFE */176/* MAX_RLIFE */177/* EXPIRATION */178/* FLAGS */179/* ENCTYPES */180181return 0;182}183184HDB *185_kadm5_s_get_db(void *server_handle)186{187kadm5_server_context *context = server_handle;188return context->db;189}190191192