Sync usage with man page.
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / kadm5 / context_s.c
blob9b71282ae6648477294a38366a7e3f7183bd47e8
1 /*
2 * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
31 * SUCH DAMAGE.
34 #include "kadm5_locl.h"
36 __RCSID("$Heimdal: context_s.c 22211 2007-12-07 19:27:27Z lha $"
37 "$NetBSD$");
39 static void
40 set_funcs(kadm5_server_context *c)
42 #define SET(C, F) (C)->funcs.F = kadm5_s_ ## F
43 SET(c, chpass_principal);
44 SET(c, chpass_principal_with_key);
45 SET(c, create_principal);
46 SET(c, delete_principal);
47 SET(c, destroy);
48 SET(c, flush);
49 SET(c, get_principal);
50 SET(c, get_principals);
51 SET(c, get_privs);
52 SET(c, modify_principal);
53 SET(c, randkey_principal);
54 SET(c, rename_principal);
57 static void
58 set_socket_name(krb5_context context, struct sockaddr_un *un)
60 const char *fn = kadm5_log_signal_socket(context);
62 memset(un, 0, sizeof(*un));
63 un->sun_family = AF_UNIX;
64 strlcpy (un->sun_path, fn, sizeof(un->sun_path));
67 static kadm5_ret_t
68 find_db_spec(kadm5_server_context *ctx)
70 krb5_context context = ctx->context;
71 struct hdb_dbinfo *info, *d;
72 krb5_error_code ret;
74 if (ctx->config.realm) {
75 /* fetch the databases */
76 ret = hdb_get_dbinfo(context, &info);
77 if (ret)
78 return ret;
80 d = NULL;
81 while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {
82 const char *p = hdb_dbinfo_get_realm(context, d);
84 /* match default (realm-less) */
85 if(p != NULL && strcmp(ctx->config.realm, p) != 0)
86 continue;
88 p = hdb_dbinfo_get_dbname(context, d);
89 if (p)
90 ctx->config.dbname = strdup(p);
92 p = hdb_dbinfo_get_acl_file(context, d);
93 if (p)
94 ctx->config.acl_file = strdup(p);
96 p = hdb_dbinfo_get_mkey_file(context, d);
97 if (p)
98 ctx->config.stash_file = strdup(p);
100 p = hdb_dbinfo_get_log_file(context, d);
101 if (p)
102 ctx->log_context.log_file = strdup(p);
103 break;
105 hdb_free_dbinfo(context, &info);
108 /* If any of the values was unset, pick up the default value */
110 if (ctx->config.dbname == NULL)
111 ctx->config.dbname = strdup(hdb_default_db(context));
112 if (ctx->config.acl_file == NULL)
113 asprintf(&ctx->config.acl_file, "%s/kadmind.acl", hdb_db_dir(context));
114 if (ctx->config.stash_file == NULL)
115 asprintf(&ctx->config.stash_file, "%s/m-key", hdb_db_dir(context));
116 if (ctx->log_context.log_file == NULL)
117 asprintf(&ctx->log_context.log_file, "%s/log", hdb_db_dir(context));
119 set_socket_name(context, &ctx->log_context.socket_name);
121 return 0;
124 kadm5_ret_t
125 _kadm5_s_init_context(kadm5_server_context **ctx,
126 kadm5_config_params *params,
127 krb5_context context)
129 *ctx = malloc(sizeof(**ctx));
130 if(*ctx == NULL)
131 return ENOMEM;
132 memset(*ctx, 0, sizeof(**ctx));
133 set_funcs(*ctx);
134 (*ctx)->context = context;
135 krb5_add_et_list (context, initialize_kadm5_error_table_r);
136 #define is_set(M) (params && params->mask & KADM5_CONFIG_ ## M)
137 if(is_set(REALM))
138 (*ctx)->config.realm = strdup(params->realm);
139 else
140 krb5_get_default_realm(context, &(*ctx)->config.realm);
141 if(is_set(DBNAME))
142 (*ctx)->config.dbname = strdup(params->dbname);
143 if(is_set(ACL_FILE))
144 (*ctx)->config.acl_file = strdup(params->acl_file);
145 if(is_set(STASH_FILE))
146 (*ctx)->config.stash_file = strdup(params->stash_file);
148 find_db_spec(*ctx);
150 /* PROFILE can't be specified for now */
151 /* KADMIND_PORT is supposed to be used on the server also,
152 but this doesn't make sense */
153 /* ADMIN_SERVER is client only */
154 /* ADNAME is not used at all (as far as I can tell) */
155 /* ADB_LOCKFILE ditto */
156 /* DICT_FILE */
157 /* ADMIN_KEYTAB */
158 /* MKEY_FROM_KEYBOARD is not supported */
159 /* MKEY_NAME neither */
160 /* ENCTYPE */
161 /* MAX_LIFE */
162 /* MAX_RLIFE */
163 /* EXPIRATION */
164 /* FLAGS */
165 /* ENCTYPES */
167 return 0;
170 HDB *
171 _kadm5_s_get_db(void *server_handle)
173 kadm5_server_context *context = server_handle;
174 return context->db;