Temporary fix for high-priority iprop issues
[heimdal.git] / lib / kadm5 / init_s.c
blob43bad3ebf25144ffafede1fe6bbef1bd8309ce3e
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>
37 RCSID("$Id$");
39 #ifndef O_NONBLOCK
40 #define NBLK FNDELAY
41 #else
42 #define NBLK O_NONBLOCK
43 #endif
45 static int non_blocking(int fd, int on)
47 int flags;
49 if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
50 return -1;
51 if (fcntl(fd, F_SETFL, on ? flags | NBLK : flags & ~NBLK) < 0)
52 return -1;
53 return ((flags & NBLK) != 0);
57 static kadm5_ret_t
58 kadm5_s_init_with_context(krb5_context context,
59 const char *client_name,
60 const char *service_name,
61 kadm5_config_params *realm_params,
62 unsigned long struct_version,
63 unsigned long api_version,
64 void **server_handle)
66 kadm5_ret_t ret;
67 kadm5_server_context *ctx;
68 char *dbname;
69 char *stash_file;
71 ret = _kadm5_s_init_context(&ctx, realm_params, context);
72 if(ret)
73 return ret;
75 if (realm_params->mask & KADM5_CONFIG_DBNAME)
76 dbname = realm_params->dbname;
77 else
78 dbname = ctx->config.dbname;
80 if (realm_params->mask & KADM5_CONFIG_STASH_FILE)
81 stash_file = realm_params->stash_file;
82 else
83 stash_file = ctx->config.stash_file;
85 assert(dbname != NULL);
86 assert(stash_file != NULL);
87 assert(ctx->config.acl_file != NULL);
88 assert(ctx->log_context.log_file != NULL);
89 #ifndef NO_UNIX_SOCKETS
90 assert(ctx->log_context.socket_name.sun_path[0] != '\0');
91 #else
92 assert(ctx->log_context.socket_info != NULL);
93 #endif
95 ret = hdb_create(ctx->context, &ctx->db, dbname);
96 if(ret)
97 return ret;
98 ret = hdb_set_master_keyfile (ctx->context,
99 ctx->db, stash_file);
100 if(ret)
101 return ret;
103 ctx->log_context.log_fd = -1;
105 #ifndef NO_UNIX_SOCKETS
106 ctx->log_context.socket_fd = socket (AF_UNIX, SOCK_DGRAM, 0);
107 #else
108 ctx->log_context.socket_fd = socket (ctx->log_context.socket_info->ai_family,
109 ctx->log_context.socket_info->ai_socktype,
110 ctx->log_context.socket_info->ai_protocol);
111 #endif
113 non_blocking(ctx->log_context.socket_fd, 1);
115 ret = krb5_parse_name(ctx->context, client_name, &ctx->caller);
116 if(ret)
117 return ret;
119 ret = _kadm5_acl_init(ctx);
120 if(ret)
121 return ret;
123 *server_handle = ctx;
124 return 0;
127 kadm5_ret_t
128 kadm5_s_init_with_password_ctx(krb5_context context,
129 const char *client_name,
130 const char *password,
131 const char *service_name,
132 kadm5_config_params *realm_params,
133 unsigned long struct_version,
134 unsigned long api_version,
135 void **server_handle)
137 return kadm5_s_init_with_context(context,
138 client_name,
139 service_name,
140 realm_params,
141 struct_version,
142 api_version,
143 server_handle);
146 kadm5_ret_t
147 kadm5_s_init_with_password(const char *client_name,
148 const char *password,
149 const char *service_name,
150 kadm5_config_params *realm_params,
151 unsigned long struct_version,
152 unsigned long api_version,
153 void **server_handle)
155 krb5_context context;
156 kadm5_ret_t ret;
157 kadm5_server_context *ctx;
159 ret = krb5_init_context(&context);
160 if (ret)
161 return ret;
162 ret = kadm5_s_init_with_password_ctx(context,
163 client_name,
164 password,
165 service_name,
166 realm_params,
167 struct_version,
168 api_version,
169 server_handle);
170 if(ret){
171 krb5_free_context(context);
172 return ret;
174 ctx = *server_handle;
175 ctx->my_context = 1;
176 return 0;
179 kadm5_ret_t
180 kadm5_s_init_with_skey_ctx(krb5_context context,
181 const char *client_name,
182 const char *keytab,
183 const char *service_name,
184 kadm5_config_params *realm_params,
185 unsigned long struct_version,
186 unsigned long api_version,
187 void **server_handle)
189 return kadm5_s_init_with_context(context,
190 client_name,
191 service_name,
192 realm_params,
193 struct_version,
194 api_version,
195 server_handle);
198 kadm5_ret_t
199 kadm5_s_init_with_skey(const char *client_name,
200 const char *keytab,
201 const char *service_name,
202 kadm5_config_params *realm_params,
203 unsigned long struct_version,
204 unsigned long api_version,
205 void **server_handle)
207 krb5_context context;
208 kadm5_ret_t ret;
209 kadm5_server_context *ctx;
211 ret = krb5_init_context(&context);
212 if (ret)
213 return ret;
214 ret = kadm5_s_init_with_skey_ctx(context,
215 client_name,
216 keytab,
217 service_name,
218 realm_params,
219 struct_version,
220 api_version,
221 server_handle);
222 if(ret){
223 krb5_free_context(context);
224 return ret;
226 ctx = *server_handle;
227 ctx->my_context = 1;
228 return 0;
231 kadm5_ret_t
232 kadm5_s_init_with_creds_ctx(krb5_context context,
233 const char *client_name,
234 krb5_ccache ccache,
235 const char *service_name,
236 kadm5_config_params *realm_params,
237 unsigned long struct_version,
238 unsigned long api_version,
239 void **server_handle)
241 return kadm5_s_init_with_context(context,
242 client_name,
243 service_name,
244 realm_params,
245 struct_version,
246 api_version,
247 server_handle);
250 kadm5_ret_t
251 kadm5_s_init_with_creds(const char *client_name,
252 krb5_ccache ccache,
253 const char *service_name,
254 kadm5_config_params *realm_params,
255 unsigned long struct_version,
256 unsigned long api_version,
257 void **server_handle)
259 krb5_context context;
260 kadm5_ret_t ret;
261 kadm5_server_context *ctx;
263 ret = krb5_init_context(&context);
264 if (ret)
265 return ret;
266 ret = kadm5_s_init_with_creds_ctx(context,
267 client_name,
268 ccache,
269 service_name,
270 realm_params,
271 struct_version,
272 api_version,
273 server_handle);
274 if(ret){
275 krb5_free_context(context);
276 return ret;
278 ctx = *server_handle;
279 ctx->my_context = 1;
280 return 0;