1 /* 2 * Copyright (c) 1997, 1998, 1999 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: init_s.c,v 1.9 1999/12/02 17:05:06 joda Exp $"); 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 assert(ctx->log_context.socket_name.sun_path[0] != '\0'); 59 60 ret = hdb_create(ctx->context, &ctx->db, ctx->config.dbname); 61 if(ret) 62 return ret; 63 ret = hdb_set_master_keyfile (ctx->context, 64 ctx->db, ctx->config.stash_file); 65 if(ret) 66 return ret; 67 68 ctx->log_context.log_fd = -1; 69 70 ctx->log_context.socket_fd = socket (AF_UNIX, SOCK_DGRAM, 0); 71 72 ret = krb5_parse_name(ctx->context, client_name, &ctx->caller); 73 if(ret) 74 return ret; 75 76 ret = _kadm5_acl_init(ctx); 77 if(ret) 78 return ret; 79 80 *server_handle = ctx; 81 return 0; 82 } 83 84 kadm5_ret_t 85 kadm5_s_init_with_password_ctx(krb5_context context, 86 const char *client_name, 87 const char *password, 88 const char *service_name, 89 kadm5_config_params *realm_params, 90 unsigned long struct_version, 91 unsigned long api_version, 92 void **server_handle) 93 { 94 return kadm5_s_init_with_context(context, 95 client_name, 96 service_name, 97 realm_params, 98 struct_version, 99 api_version, 100 server_handle); 101 } 102 103 kadm5_ret_t 104 kadm5_s_init_with_password(const char *client_name, 105 const char *password, 106 const char *service_name, 107 kadm5_config_params *realm_params, 108 unsigned long struct_version, 109 unsigned long api_version, 110 void **server_handle) 111 { 112 krb5_context context; 113 kadm5_ret_t ret; 114 kadm5_server_context *ctx; 115 116 krb5_init_context(&context); 117 ret = kadm5_s_init_with_password_ctx(context, 118 client_name, 119 password, 120 service_name, 121 realm_params, 122 struct_version, 123 api_version, 124 server_handle); 125 if(ret){ 126 krb5_free_context(context); 127 return ret; 128 } 129 ctx = *server_handle; 130 ctx->my_context = 1; 131 return 0; 132 } 133 134 kadm5_ret_t 135 kadm5_s_init_with_skey_ctx(krb5_context context, 136 const char *client_name, 137 const char *keytab, 138 const char *service_name, 139 kadm5_config_params *realm_params, 140 unsigned long struct_version, 141 unsigned long api_version, 142 void **server_handle) 143 { 144 return kadm5_s_init_with_context(context, 145 client_name, 146 service_name, 147 realm_params, 148 struct_version, 149 api_version, 150 server_handle); 151 } 152 153 kadm5_ret_t 154 kadm5_s_init_with_skey(const char *client_name, 155 const char *keytab, 156 const char *service_name, 157 kadm5_config_params *realm_params, 158 unsigned long struct_version, 159 unsigned long api_version, 160 void **server_handle) 161 { 162 krb5_context context; 163 kadm5_ret_t ret; 164 kadm5_server_context *ctx; 165 166 krb5_init_context(&context); 167 ret = kadm5_s_init_with_skey_ctx(context, 168 client_name, 169 keytab, 170 service_name, 171 realm_params, 172 struct_version, 173 api_version, 174 server_handle); 175 if(ret){ 176 krb5_free_context(context); 177 return ret; 178 } 179 ctx = *server_handle; 180 ctx->my_context = 1; 181 return 0; 182 } 183 184 kadm5_ret_t 185 kadm5_s_init_with_creds_ctx(krb5_context context, 186 const char *client_name, 187 krb5_ccache ccache, 188 const char *service_name, 189 kadm5_config_params *realm_params, 190 unsigned long struct_version, 191 unsigned long api_version, 192 void **server_handle) 193 { 194 return kadm5_s_init_with_context(context, 195 client_name, 196 service_name, 197 realm_params, 198 struct_version, 199 api_version, 200 server_handle); 201 } 202 203 kadm5_ret_t 204 kadm5_s_init_with_creds(const char *client_name, 205 krb5_ccache ccache, 206 const char *service_name, 207 kadm5_config_params *realm_params, 208 unsigned long struct_version, 209 unsigned long api_version, 210 void **server_handle) 211 { 212 krb5_context context; 213 kadm5_ret_t ret; 214 kadm5_server_context *ctx; 215 216 krb5_init_context(&context); 217 ret = kadm5_s_init_with_creds_ctx(context, 218 client_name, 219 ccache, 220 service_name, 221 realm_params, 222 struct_version, 223 api_version, 224 server_handle); 225 if(ret){ 226 krb5_free_context(context); 227 return ret; 228 } 229 ctx = *server_handle; 230 ctx->my_context = 1; 231 return 0; 232 } 233