1 /* 2 * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 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. 16 * 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. 20 * 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. 32 */ 33 34 #include "kadm5_locl.h" 35 36 RCSID("$Id$"); 37 38 39 static kadm5_ret_t 40 kadm5_s_init_with_context(krb5_context context, 41 const char *client_name, 42 const char *service_name, 43 kadm5_config_params *realm_params, 44 unsigned long struct_version, 45 unsigned long api_version, 46 void **server_handle) 47 { 48 kadm5_ret_t ret; 49 kadm5_server_context *ctx; 50 ret = _kadm5_s_init_context(&ctx, realm_params, context); 51 if(ret) 52 return ret; 53 54 assert(ctx->config.dbname != NULL); 55 assert(ctx->config.stash_file != NULL); 56 assert(ctx->config.acl_file != NULL); 57 assert(ctx->log_context.log_file != NULL); 58 #ifndef NO_UNIX_SOCKETS 59 assert(ctx->log_context.socket_name.sun_path[0] != '\0'); 60 #else 61 assert(ctx->log_context.socket_info != NULL); 62 #endif 63 64 ret = hdb_create(ctx->context, &ctx->db, ctx->config.dbname); 65 if(ret) 66 return ret; 67 ret = hdb_set_master_keyfile (ctx->context, 68 ctx->db, ctx->config.stash_file); 69 if(ret) 70 return ret; 71 72 ctx->log_context.log_fd = -1; 73 74 #ifndef NO_UNIX_SOCKETS 75 ctx->log_context.socket_fd = socket (AF_UNIX, SOCK_DGRAM, 0); 76 #else 77 ctx->log_context.socket_fd = socket (ctx->log_context.socket_info->ai_family, 78 ctx->log_context.socket_info->ai_socktype, 79 ctx->log_context.socket_info->ai_protocol); 80 #endif 81 82 ret = krb5_parse_name(ctx->context, client_name, &ctx->caller); 83 if(ret) 84 return ret; 85 86 ret = _kadm5_acl_init(ctx); 87 if(ret) 88 return ret; 89 90 *server_handle = ctx; 91 return 0; 92 } 93 94 kadm5_ret_t 95 kadm5_s_init_with_password_ctx(krb5_context context, 96 const char *client_name, 97 const char *password, 98 const char *service_name, 99 kadm5_config_params *realm_params, 100 unsigned long struct_version, 101 unsigned long api_version, 102 void **server_handle) 103 { 104 return kadm5_s_init_with_context(context, 105 client_name, 106 service_name, 107 realm_params, 108 struct_version, 109 api_version, 110 server_handle); 111 } 112 113 kadm5_ret_t 114 kadm5_s_init_with_password(const char *client_name, 115 const char *password, 116 const char *service_name, 117 kadm5_config_params *realm_params, 118 unsigned long struct_version, 119 unsigned long api_version, 120 void **server_handle) 121 { 122 krb5_context context; 123 kadm5_ret_t ret; 124 kadm5_server_context *ctx; 125 126 ret = krb5_init_context(&context); 127 if (ret) 128 return ret; 129 ret = kadm5_s_init_with_password_ctx(context, 130 client_name, 131 password, 132 service_name, 133 realm_params, 134 struct_version, 135 api_version, 136 server_handle); 137 if(ret){ 138 krb5_free_context(context); 139 return ret; 140 } 141 ctx = *server_handle; 142 ctx->my_context = 1; 143 return 0; 144 } 145 146 kadm5_ret_t 147 kadm5_s_init_with_skey_ctx(krb5_context context, 148 const char *client_name, 149 const char *keytab, 150 const char *service_name, 151 kadm5_config_params *realm_params, 152 unsigned long struct_version, 153 unsigned long api_version, 154 void **server_handle) 155 { 156 return kadm5_s_init_with_context(context, 157 client_name, 158 service_name, 159 realm_params, 160 struct_version, 161 api_version, 162 server_handle); 163 } 164 165 kadm5_ret_t 166 kadm5_s_init_with_skey(const char *client_name, 167 const char *keytab, 168 const char *service_name, 169 kadm5_config_params *realm_params, 170 unsigned long struct_version, 171 unsigned long api_version, 172 void **server_handle) 173 { 174 krb5_context context; 175 kadm5_ret_t ret; 176 kadm5_server_context *ctx; 177 178 ret = krb5_init_context(&context); 179 if (ret) 180 return ret; 181 ret = kadm5_s_init_with_skey_ctx(context, 182 client_name, 183 keytab, 184 service_name, 185 realm_params, 186 struct_version, 187 api_version, 188 server_handle); 189 if(ret){ 190 krb5_free_context(context); 191 return ret; 192 } 193 ctx = *server_handle; 194 ctx->my_context = 1; 195 return 0; 196 } 197 198 kadm5_ret_t 199 kadm5_s_init_with_creds_ctx(krb5_context context, 200 const char *client_name, 201 krb5_ccache ccache, 202 const char *service_name, 203 kadm5_config_params *realm_params, 204 unsigned long struct_version, 205 unsigned long api_version, 206 void **server_handle) 207 { 208 return kadm5_s_init_with_context(context, 209 client_name, 210 service_name, 211 realm_params, 212 struct_version, 213 api_version, 214 server_handle); 215 } 216 217 kadm5_ret_t 218 kadm5_s_init_with_creds(const char *client_name, 219 krb5_ccache ccache, 220 const char *service_name, 221 kadm5_config_params *realm_params, 222 unsigned long struct_version, 223 unsigned long api_version, 224 void **server_handle) 225 { 226 krb5_context context; 227 kadm5_ret_t ret; 228 kadm5_server_context *ctx; 229 230 ret = krb5_init_context(&context); 231 if (ret) 232 return ret; 233 ret = kadm5_s_init_with_creds_ctx(context, 234 client_name, 235 ccache, 236 service_name, 237 realm_params, 238 struct_version, 239 api_version, 240 server_handle); 241 if(ret){ 242 krb5_free_context(context); 243 return ret; 244 } 245 ctx = *server_handle; 246 ctx->my_context = 1; 247 return 0; 248 } 249