afslog.1: Remove documentation for removed no-v4 argument.
[heimdal.git] / lib / kadm5 / init_s.c
blob67154254aaaeb950ec4b12a2eff0c56a489dd286
1 /*
2 * Copyright (c) 1997 - 2000 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"
35 #include <fcntl.h>
38 static kadm5_ret_t
39 kadm5_s_init_with_context(krb5_context context,
40 const char *client_name,
41 const char *service_name,
42 kadm5_config_params *realm_params,
43 unsigned long struct_version,
44 unsigned long api_version,
45 void **server_handle)
47 kadm5_ret_t ret;
48 kadm5_server_context *ctx;
49 char *dbname;
50 char *stash_file;
52 ret = _kadm5_s_init_context(&ctx, realm_params, context);
53 if(ret)
54 return ret;
56 if (realm_params->mask & KADM5_CONFIG_DBNAME)
57 dbname = realm_params->dbname;
58 else
59 dbname = ctx->config.dbname;
61 if (realm_params->mask & KADM5_CONFIG_STASH_FILE)
62 stash_file = realm_params->stash_file;
63 else
64 stash_file = ctx->config.stash_file;
66 assert(dbname != NULL);
67 assert(stash_file != NULL);
68 assert(ctx->config.acl_file != NULL);
69 assert(ctx->log_context.log_file != NULL);
70 #ifndef NO_UNIX_SOCKETS
71 assert(ctx->log_context.socket_name.sun_path[0] != '\0');
72 #else
73 assert(ctx->log_context.socket_info != NULL);
74 #endif
76 ret = hdb_create(ctx->context, &ctx->db, dbname);
77 if(ret)
78 return ret;
79 ret = hdb_set_master_keyfile (ctx->context,
80 ctx->db, stash_file);
81 if(ret)
82 return ret;
84 ctx->log_context.log_fd = -1;
86 #ifndef NO_UNIX_SOCKETS
87 ctx->log_context.socket_fd = socket (AF_UNIX, SOCK_DGRAM, 0);
88 #else
89 ctx->log_context.socket_fd = socket (ctx->log_context.socket_info->ai_family,
90 ctx->log_context.socket_info->ai_socktype,
91 ctx->log_context.socket_info->ai_protocol);
92 #endif
94 socket_set_nonblocking(ctx->log_context.socket_fd, 1);
96 ret = krb5_parse_name(ctx->context, client_name, &ctx->caller);
97 if(ret)
98 return ret;
100 ret = _kadm5_acl_init(ctx);
101 if(ret)
102 return ret;
104 *server_handle = ctx;
105 return 0;
108 kadm5_ret_t
109 kadm5_s_init_with_password_ctx(krb5_context context,
110 const char *client_name,
111 const char *password,
112 const char *service_name,
113 kadm5_config_params *realm_params,
114 unsigned long struct_version,
115 unsigned long api_version,
116 void **server_handle)
118 return kadm5_s_init_with_context(context,
119 client_name,
120 service_name,
121 realm_params,
122 struct_version,
123 api_version,
124 server_handle);
127 kadm5_ret_t
128 kadm5_s_init_with_password(const char *client_name,
129 const char *password,
130 const char *service_name,
131 kadm5_config_params *realm_params,
132 unsigned long struct_version,
133 unsigned long api_version,
134 void **server_handle)
136 krb5_context context;
137 kadm5_ret_t ret;
138 kadm5_server_context *ctx;
140 ret = krb5_init_context(&context);
141 if (ret)
142 return ret;
143 ret = kadm5_s_init_with_password_ctx(context,
144 client_name,
145 password,
146 service_name,
147 realm_params,
148 struct_version,
149 api_version,
150 server_handle);
151 if(ret){
152 krb5_free_context(context);
153 return ret;
155 ctx = *server_handle;
156 ctx->my_context = 1;
157 return 0;
160 kadm5_ret_t
161 kadm5_s_init_with_skey_ctx(krb5_context context,
162 const char *client_name,
163 const char *keytab,
164 const char *service_name,
165 kadm5_config_params *realm_params,
166 unsigned long struct_version,
167 unsigned long api_version,
168 void **server_handle)
170 return kadm5_s_init_with_context(context,
171 client_name,
172 service_name,
173 realm_params,
174 struct_version,
175 api_version,
176 server_handle);
179 kadm5_ret_t
180 kadm5_s_init_with_skey(const char *client_name,
181 const char *keytab,
182 const char *service_name,
183 kadm5_config_params *realm_params,
184 unsigned long struct_version,
185 unsigned long api_version,
186 void **server_handle)
188 krb5_context context;
189 kadm5_ret_t ret;
190 kadm5_server_context *ctx;
192 ret = krb5_init_context(&context);
193 if (ret)
194 return ret;
195 ret = kadm5_s_init_with_skey_ctx(context,
196 client_name,
197 keytab,
198 service_name,
199 realm_params,
200 struct_version,
201 api_version,
202 server_handle);
203 if(ret){
204 krb5_free_context(context);
205 return ret;
207 ctx = *server_handle;
208 ctx->my_context = 1;
209 return 0;
212 kadm5_ret_t
213 kadm5_s_init_with_creds_ctx(krb5_context context,
214 const char *client_name,
215 krb5_ccache ccache,
216 const char *service_name,
217 kadm5_config_params *realm_params,
218 unsigned long struct_version,
219 unsigned long api_version,
220 void **server_handle)
222 return kadm5_s_init_with_context(context,
223 client_name,
224 service_name,
225 realm_params,
226 struct_version,
227 api_version,
228 server_handle);
231 kadm5_ret_t
232 kadm5_s_init_with_creds(const char *client_name,
233 krb5_ccache ccache,
234 const char *service_name,
235 kadm5_config_params *realm_params,
236 unsigned long struct_version,
237 unsigned long api_version,
238 void **server_handle)
240 krb5_context context;
241 kadm5_ret_t ret;
242 kadm5_server_context *ctx;
244 ret = krb5_init_context(&context);
245 if (ret)
246 return ret;
247 ret = kadm5_s_init_with_creds_ctx(context,
248 client_name,
249 ccache,
250 service_name,
251 realm_params,
252 struct_version,
253 api_version,
254 server_handle);
255 if(ret){
256 krb5_free_context(context);
257 return ret;
259 ctx = *server_handle;
260 ctx->my_context = 1;
261 return 0;