1 1.8 christos /* $NetBSD: context.c,v 1.8 2023/09/11 15:12:12 christos Exp $ */ 2 1.1 elric 3 1.1 elric /* 4 1.1 elric * Copyright (c) 1997 - 2010 Kungliga Tekniska Hgskolan 5 1.1 elric * (Royal Institute of Technology, Stockholm, Sweden). 6 1.1 elric * All rights reserved. 7 1.1 elric * 8 1.1 elric * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 9 1.1 elric * 10 1.1 elric * Redistribution and use in source and binary forms, with or without 11 1.1 elric * modification, are permitted provided that the following conditions 12 1.1 elric * are met: 13 1.1 elric * 14 1.1 elric * 1. Redistributions of source code must retain the above copyright 15 1.1 elric * notice, this list of conditions and the following disclaimer. 16 1.1 elric * 17 1.1 elric * 2. Redistributions in binary form must reproduce the above copyright 18 1.1 elric * notice, this list of conditions and the following disclaimer in the 19 1.1 elric * documentation and/or other materials provided with the distribution. 20 1.1 elric * 21 1.1 elric * 3. Neither the name of the Institute nor the names of its contributors 22 1.1 elric * may be used to endorse or promote products derived from this software 23 1.1 elric * without specific prior written permission. 24 1.1 elric * 25 1.1 elric * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 26 1.1 elric * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 1.1 elric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 1.1 elric * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 29 1.1 elric * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 1.1 elric * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 1.1 elric * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 1.1 elric * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 1.1 elric * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 1.1 elric * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 1.1 elric * SUCH DAMAGE. 36 1.1 elric */ 37 1.1 elric 38 1.1 elric #include "krb5_locl.h" 39 1.4 pettai #include <assert.h> 40 1.1 elric #include <krb5/com_err.h> 41 1.8 christos #if OPENSSL_VERSION_NUMBER >= 0x30000000UL 42 1.8 christos #include <openssl/provider.h> 43 1.8 christos #endif 44 1.1 elric 45 1.1 elric #define INIT_FIELD(C, T, E, D, F) \ 46 1.1 elric (C)->E = krb5_config_get_ ## T ## _default ((C), NULL, (D), \ 47 1.1 elric "libdefaults", F, NULL) 48 1.1 elric 49 1.1 elric #define INIT_FLAG(C, O, V, D, F) \ 50 1.1 elric do { \ 51 1.1 elric if (krb5_config_get_bool_default((C), NULL, (D),"libdefaults", F, NULL)) { \ 52 1.1 elric (C)->O |= V; \ 53 1.1 elric } \ 54 1.1 elric } while(0) 55 1.1 elric 56 1.5 christos static krb5_error_code 57 1.5 christos copy_enctypes(krb5_context context, 58 1.5 christos const krb5_enctype *in, 59 1.5 christos krb5_enctype **out); 60 1.5 christos 61 1.1 elric /* 62 1.1 elric * Set the list of etypes `ret_etypes' from the configuration variable 63 1.1 elric * `name' 64 1.1 elric */ 65 1.1 elric 66 1.1 elric static krb5_error_code 67 1.1 elric set_etypes (krb5_context context, 68 1.1 elric const char *name, 69 1.1 elric krb5_enctype **ret_enctypes) 70 1.1 elric { 71 1.1 elric char **etypes_str; 72 1.1 elric krb5_enctype *etypes = NULL; 73 1.1 elric 74 1.1 elric etypes_str = krb5_config_get_strings(context, NULL, "libdefaults", 75 1.1 elric name, NULL); 76 1.1 elric if(etypes_str){ 77 1.1 elric int i, j, k; 78 1.1 elric for(i = 0; etypes_str[i]; i++); 79 1.1 elric etypes = malloc((i+1) * sizeof(*etypes)); 80 1.1 elric if (etypes == NULL) { 81 1.1 elric krb5_config_free_strings (etypes_str); 82 1.5 christos return krb5_enomem(context); 83 1.1 elric } 84 1.1 elric for(j = 0, k = 0; j < i; j++) { 85 1.1 elric krb5_enctype e; 86 1.1 elric if(krb5_string_to_enctype(context, etypes_str[j], &e) != 0) 87 1.1 elric continue; 88 1.1 elric if (krb5_enctype_valid(context, e) != 0) 89 1.1 elric continue; 90 1.1 elric etypes[k++] = e; 91 1.1 elric } 92 1.1 elric etypes[k] = ETYPE_NULL; 93 1.1 elric krb5_config_free_strings(etypes_str); 94 1.1 elric } 95 1.1 elric *ret_enctypes = etypes; 96 1.1 elric return 0; 97 1.1 elric } 98 1.1 elric 99 1.1 elric /* 100 1.1 elric * read variables from the configuration file and set in `context' 101 1.1 elric */ 102 1.1 elric 103 1.1 elric static krb5_error_code 104 1.1 elric init_context_from_config_file(krb5_context context) 105 1.1 elric { 106 1.1 elric krb5_error_code ret; 107 1.1 elric const char * tmp; 108 1.1 elric char **s; 109 1.7 christos krb5_enctype *tmptypes = NULL; 110 1.1 elric 111 1.1 elric INIT_FIELD(context, time, max_skew, 5 * 60, "clockskew"); 112 1.5 christos INIT_FIELD(context, time, kdc_timeout, 30, "kdc_timeout"); 113 1.5 christos INIT_FIELD(context, time, host_timeout, 3, "host_timeout"); 114 1.1 elric INIT_FIELD(context, int, max_retries, 3, "max_retries"); 115 1.1 elric 116 1.1 elric INIT_FIELD(context, string, http_proxy, NULL, "http_proxy"); 117 1.1 elric 118 1.1 elric ret = krb5_config_get_bool_default(context, NULL, FALSE, 119 1.1 elric "libdefaults", 120 1.1 elric "allow_weak_crypto", NULL); 121 1.1 elric if (ret) { 122 1.1 elric krb5_enctype_enable(context, ETYPE_DES_CBC_CRC); 123 1.1 elric krb5_enctype_enable(context, ETYPE_DES_CBC_MD4); 124 1.1 elric krb5_enctype_enable(context, ETYPE_DES_CBC_MD5); 125 1.1 elric krb5_enctype_enable(context, ETYPE_DES_CBC_NONE); 126 1.1 elric krb5_enctype_enable(context, ETYPE_DES_CFB64_NONE); 127 1.1 elric krb5_enctype_enable(context, ETYPE_DES_PCBC_NONE); 128 1.1 elric } 129 1.1 elric 130 1.1 elric ret = set_etypes (context, "default_etypes", &tmptypes); 131 1.1 elric if(ret) 132 1.1 elric return ret; 133 1.1 elric free(context->etypes); 134 1.1 elric context->etypes = tmptypes; 135 1.1 elric 136 1.5 christos /* The etypes member may change during the lifetime 137 1.5 christos * of the context. To be able to reset it to 138 1.5 christos * config value, we keep another copy. 139 1.5 christos */ 140 1.5 christos free(context->cfg_etypes); 141 1.5 christos context->cfg_etypes = NULL; 142 1.5 christos if (tmptypes) { 143 1.5 christos ret = copy_enctypes(context, tmptypes, &context->cfg_etypes); 144 1.5 christos if (ret) 145 1.5 christos return ret; 146 1.5 christos } 147 1.5 christos 148 1.1 elric ret = set_etypes (context, "default_etypes_des", &tmptypes); 149 1.1 elric if(ret) 150 1.1 elric return ret; 151 1.1 elric free(context->etypes_des); 152 1.1 elric context->etypes_des = tmptypes; 153 1.1 elric 154 1.4 pettai ret = set_etypes (context, "default_as_etypes", &tmptypes); 155 1.4 pettai if(ret) 156 1.4 pettai return ret; 157 1.4 pettai free(context->as_etypes); 158 1.4 pettai context->as_etypes = tmptypes; 159 1.4 pettai 160 1.4 pettai ret = set_etypes (context, "default_tgs_etypes", &tmptypes); 161 1.4 pettai if(ret) 162 1.4 pettai return ret; 163 1.4 pettai free(context->tgs_etypes); 164 1.4 pettai context->tgs_etypes = tmptypes; 165 1.4 pettai 166 1.4 pettai ret = set_etypes (context, "permitted_enctypes", &tmptypes); 167 1.4 pettai if(ret) 168 1.4 pettai return ret; 169 1.4 pettai free(context->permitted_enctypes); 170 1.4 pettai context->permitted_enctypes = tmptypes; 171 1.4 pettai 172 1.5 christos INIT_FIELD(context, string, default_keytab, 173 1.5 christos KEYTAB_DEFAULT, "default_keytab_name"); 174 1.1 elric 175 1.1 elric INIT_FIELD(context, string, default_keytab_modify, 176 1.1 elric NULL, "default_keytab_modify_name"); 177 1.1 elric 178 1.1 elric INIT_FIELD(context, string, time_fmt, 179 1.1 elric "%Y-%m-%dT%H:%M:%S", "time_format"); 180 1.1 elric 181 1.1 elric INIT_FIELD(context, string, date_fmt, 182 1.1 elric "%Y-%m-%d", "date_format"); 183 1.1 elric 184 1.1 elric INIT_FIELD(context, bool, log_utc, 185 1.1 elric FALSE, "log_utc"); 186 1.1 elric 187 1.1 elric 188 1.1 elric 189 1.1 elric /* init dns-proxy slime */ 190 1.1 elric tmp = krb5_config_get_string(context, NULL, "libdefaults", 191 1.1 elric "dns_proxy", NULL); 192 1.1 elric if(tmp) 193 1.1 elric roken_gethostby_setup(context->http_proxy, tmp); 194 1.1 elric krb5_free_host_realm (context, context->default_realms); 195 1.1 elric context->default_realms = NULL; 196 1.1 elric 197 1.1 elric { 198 1.1 elric krb5_addresses addresses; 199 1.1 elric char **adr, **a; 200 1.1 elric 201 1.1 elric krb5_set_extra_addresses(context, NULL); 202 1.1 elric adr = krb5_config_get_strings(context, NULL, 203 1.1 elric "libdefaults", 204 1.1 elric "extra_addresses", 205 1.1 elric NULL); 206 1.1 elric memset(&addresses, 0, sizeof(addresses)); 207 1.1 elric for(a = adr; a && *a; a++) { 208 1.1 elric ret = krb5_parse_address(context, *a, &addresses); 209 1.1 elric if (ret == 0) { 210 1.1 elric krb5_add_extra_addresses(context, &addresses); 211 1.1 elric krb5_free_addresses(context, &addresses); 212 1.1 elric } 213 1.1 elric } 214 1.1 elric krb5_config_free_strings(adr); 215 1.1 elric 216 1.1 elric krb5_set_ignore_addresses(context, NULL); 217 1.1 elric adr = krb5_config_get_strings(context, NULL, 218 1.1 elric "libdefaults", 219 1.1 elric "ignore_addresses", 220 1.1 elric NULL); 221 1.1 elric memset(&addresses, 0, sizeof(addresses)); 222 1.1 elric for(a = adr; a && *a; a++) { 223 1.1 elric ret = krb5_parse_address(context, *a, &addresses); 224 1.1 elric if (ret == 0) { 225 1.1 elric krb5_add_ignore_addresses(context, &addresses); 226 1.1 elric krb5_free_addresses(context, &addresses); 227 1.1 elric } 228 1.1 elric } 229 1.1 elric krb5_config_free_strings(adr); 230 1.1 elric } 231 1.1 elric 232 1.1 elric INIT_FIELD(context, bool, scan_interfaces, TRUE, "scan_interfaces"); 233 1.1 elric INIT_FIELD(context, int, fcache_vno, 0, "fcache_version"); 234 1.1 elric /* prefer dns_lookup_kdc over srv_lookup. */ 235 1.1 elric INIT_FIELD(context, bool, srv_lookup, TRUE, "srv_lookup"); 236 1.1 elric INIT_FIELD(context, bool, srv_lookup, context->srv_lookup, "dns_lookup_kdc"); 237 1.1 elric INIT_FIELD(context, int, large_msg_size, 1400, "large_message_size"); 238 1.5 christos INIT_FIELD(context, int, max_msg_size, 1000 * 1024, "maximum_message_size"); 239 1.1 elric INIT_FLAG(context, flags, KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME, TRUE, "dns_canonicalize_hostname"); 240 1.1 elric INIT_FLAG(context, flags, KRB5_CTX_F_CHECK_PAC, TRUE, "check_pac"); 241 1.5 christos 242 1.5 christos if (context->default_cc_name) 243 1.5 christos free(context->default_cc_name); 244 1.1 elric context->default_cc_name = NULL; 245 1.1 elric context->default_cc_name_set = 0; 246 1.1 elric 247 1.1 elric s = krb5_config_get_strings(context, NULL, "logging", "krb5", NULL); 248 1.1 elric if(s) { 249 1.1 elric char **p; 250 1.5 christos 251 1.5 christos if (context->debug_dest) 252 1.5 christos krb5_closelog(context, context->debug_dest); 253 1.5 christos 254 1.1 elric krb5_initlog(context, "libkrb5", &context->debug_dest); 255 1.1 elric for(p = s; *p; p++) 256 1.1 elric krb5_addlog_dest(context, context->debug_dest, *p); 257 1.1 elric krb5_config_free_strings(s); 258 1.1 elric } 259 1.1 elric 260 1.1 elric tmp = krb5_config_get_string(context, NULL, "libdefaults", 261 1.1 elric "check-rd-req-server", NULL); 262 1.1 elric if (tmp == NULL && !issuid()) 263 1.1 elric tmp = getenv("KRB5_CHECK_RD_REQ_SERVER"); 264 1.1 elric if(tmp) { 265 1.1 elric if (strcasecmp(tmp, "ignore") == 0) 266 1.1 elric context->flags |= KRB5_CTX_F_RD_REQ_IGNORE; 267 1.1 elric } 268 1.5 christos ret = krb5_config_get_bool_default(context, NULL, TRUE, 269 1.5 christos "libdefaults", 270 1.5 christos "fcache_strict_checking", NULL); 271 1.5 christos if (ret) 272 1.5 christos context->flags |= KRB5_CTX_F_FCACHE_STRICT_CHECKING; 273 1.1 elric 274 1.1 elric return 0; 275 1.1 elric } 276 1.1 elric 277 1.1 elric static krb5_error_code 278 1.1 elric cc_ops_register(krb5_context context) 279 1.1 elric { 280 1.1 elric context->cc_ops = NULL; 281 1.1 elric context->num_cc_ops = 0; 282 1.1 elric 283 1.1 elric #ifndef KCM_IS_API_CACHE 284 1.1 elric krb5_cc_register(context, &krb5_acc_ops, TRUE); 285 1.1 elric #endif 286 1.1 elric krb5_cc_register(context, &krb5_fcc_ops, TRUE); 287 1.5 christos krb5_cc_register(context, &krb5_dcc_ops, TRUE); 288 1.1 elric krb5_cc_register(context, &krb5_mcc_ops, TRUE); 289 1.1 elric #ifdef HAVE_SCC 290 1.1 elric krb5_cc_register(context, &krb5_scc_ops, TRUE); 291 1.1 elric #endif 292 1.1 elric #ifdef HAVE_KCM 293 1.1 elric #ifdef KCM_IS_API_CACHE 294 1.1 elric krb5_cc_register(context, &krb5_akcm_ops, TRUE); 295 1.1 elric #endif 296 1.1 elric krb5_cc_register(context, &krb5_kcm_ops, TRUE); 297 1.1 elric #endif 298 1.1 elric _krb5_load_ccache_plugins(context); 299 1.1 elric return 0; 300 1.1 elric } 301 1.1 elric 302 1.1 elric static krb5_error_code 303 1.1 elric cc_ops_copy(krb5_context context, const krb5_context src_context) 304 1.1 elric { 305 1.1 elric const krb5_cc_ops **cc_ops; 306 1.1 elric 307 1.1 elric context->cc_ops = NULL; 308 1.1 elric context->num_cc_ops = 0; 309 1.1 elric 310 1.1 elric if (src_context->num_cc_ops == 0) 311 1.1 elric return 0; 312 1.1 elric 313 1.1 elric cc_ops = malloc(sizeof(cc_ops[0]) * src_context->num_cc_ops); 314 1.1 elric if (cc_ops == NULL) { 315 1.1 elric krb5_set_error_message(context, KRB5_CC_NOMEM, 316 1.1 elric N_("malloc: out of memory", "")); 317 1.1 elric return KRB5_CC_NOMEM; 318 1.1 elric } 319 1.1 elric 320 1.1 elric memcpy(rk_UNCONST(cc_ops), src_context->cc_ops, 321 1.1 elric sizeof(cc_ops[0]) * src_context->num_cc_ops); 322 1.1 elric context->cc_ops = cc_ops; 323 1.1 elric context->num_cc_ops = src_context->num_cc_ops; 324 1.1 elric 325 1.1 elric return 0; 326 1.1 elric } 327 1.1 elric 328 1.1 elric static krb5_error_code 329 1.1 elric kt_ops_register(krb5_context context) 330 1.1 elric { 331 1.1 elric context->num_kt_types = 0; 332 1.1 elric context->kt_types = NULL; 333 1.1 elric 334 1.1 elric krb5_kt_register (context, &krb5_fkt_ops); 335 1.1 elric krb5_kt_register (context, &krb5_wrfkt_ops); 336 1.1 elric krb5_kt_register (context, &krb5_javakt_ops); 337 1.1 elric krb5_kt_register (context, &krb5_mkt_ops); 338 1.1 elric #ifndef HEIMDAL_SMALLER 339 1.1 elric krb5_kt_register (context, &krb5_akf_ops); 340 1.1 elric #endif 341 1.1 elric krb5_kt_register (context, &krb5_any_ops); 342 1.1 elric return 0; 343 1.1 elric } 344 1.1 elric 345 1.1 elric static krb5_error_code 346 1.1 elric kt_ops_copy(krb5_context context, const krb5_context src_context) 347 1.1 elric { 348 1.1 elric context->num_kt_types = 0; 349 1.1 elric context->kt_types = NULL; 350 1.1 elric 351 1.1 elric if (src_context->num_kt_types == 0) 352 1.1 elric return 0; 353 1.1 elric 354 1.1 elric context->kt_types = malloc(sizeof(context->kt_types[0]) * src_context->num_kt_types); 355 1.5 christos if (context->kt_types == NULL) 356 1.5 christos return krb5_enomem(context); 357 1.1 elric 358 1.1 elric context->num_kt_types = src_context->num_kt_types; 359 1.1 elric memcpy(context->kt_types, src_context->kt_types, 360 1.1 elric sizeof(context->kt_types[0]) * src_context->num_kt_types); 361 1.1 elric 362 1.1 elric return 0; 363 1.1 elric } 364 1.1 elric 365 1.4 pettai static const char *sysplugin_dirs[] = { 366 1.5 christos #ifdef _WIN32 367 1.5 christos "$ORIGIN", 368 1.5 christos #else 369 1.5 christos "$ORIGIN/../lib/plugin/krb5", 370 1.5 christos #endif 371 1.5 christos #ifdef __APPLE__ 372 1.1 elric LIBDIR "/plugin/krb5", 373 1.5 christos #ifdef HEIM_PLUGINS_SEARCH_SYSTEM 374 1.1 elric "/Library/KerberosPlugins/KerberosFrameworkPlugins", 375 1.1 elric "/System/Library/KerberosPlugins/KerberosFrameworkPlugins", 376 1.1 elric #endif 377 1.5 christos #endif 378 1.1 elric NULL 379 1.1 elric }; 380 1.1 elric 381 1.1 elric static void 382 1.1 elric init_context_once(void *ctx) 383 1.1 elric { 384 1.1 elric krb5_context context = ctx; 385 1.5 christos char **dirs; 386 1.1 elric 387 1.5 christos #ifdef _WIN32 388 1.5 christos dirs = rk_UNCONST(sysplugin_dirs); 389 1.5 christos #else 390 1.5 christos dirs = krb5_config_get_strings(context, NULL, "libdefaults", 391 1.5 christos "plugin_dir", NULL); 392 1.5 christos if (dirs == NULL) 393 1.5 christos dirs = rk_UNCONST(sysplugin_dirs); 394 1.5 christos #endif 395 1.5 christos 396 1.5 christos _krb5_load_plugins(context, "krb5", (const char **)dirs); 397 1.5 christos 398 1.5 christos if (dirs != rk_UNCONST(sysplugin_dirs)) 399 1.5 christos krb5_config_free_strings(dirs); 400 1.4 pettai 401 1.1 elric bindtextdomain(HEIMDAL_TEXTDOMAIN, HEIMDAL_LOCALEDIR); 402 1.8 christos #if OPENSSL_VERSION_NUMBER >= 0x30000000UL 403 1.8 christos OSSL_PROVIDER_load(NULL, "legacy"); 404 1.8 christos #endif 405 1.1 elric } 406 1.1 elric 407 1.1 elric 408 1.1 elric /** 409 1.1 elric * Initializes the context structure and reads the configuration file 410 1.1 elric * /etc/krb5.conf. The structure should be freed by calling 411 1.1 elric * krb5_free_context() when it is no longer being used. 412 1.1 elric * 413 1.1 elric * @param context pointer to returned context 414 1.1 elric * 415 1.1 elric * @return Returns 0 to indicate success. Otherwise an errno code is 416 1.1 elric * returned. Failure means either that something bad happened during 417 1.1 elric * initialization (typically ENOMEM) or that Kerberos should not be 418 1.5 christos * used ENXIO. If the function returns HEIM_ERR_RANDOM_OFFLINE, the 419 1.5 christos * random source is not available and later Kerberos calls might fail. 420 1.1 elric * 421 1.1 elric * @ingroup krb5 422 1.1 elric */ 423 1.1 elric 424 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 425 1.1 elric krb5_init_context(krb5_context *context) 426 1.1 elric { 427 1.1 elric static heim_base_once_t init_context = HEIM_BASE_ONCE_INIT; 428 1.1 elric krb5_context p; 429 1.1 elric krb5_error_code ret; 430 1.1 elric char **files; 431 1.5 christos uint8_t rnd; 432 1.1 elric 433 1.1 elric *context = NULL; 434 1.1 elric 435 1.5 christos /** 436 1.5 christos * krb5_init_context() will get one random byte to make sure our 437 1.5 christos * random is alive. Assumption is that once the non blocking 438 1.5 christos * source allows us to pull bytes, its all seeded and allows us to 439 1.5 christos * pull more bytes. 440 1.5 christos * 441 1.5 christos * Most Kerberos users calls krb5_init_context(), so this is 442 1.5 christos * useful point where we can do the checking. 443 1.5 christos */ 444 1.5 christos ret = krb5_generate_random(&rnd, sizeof(rnd)); 445 1.5 christos if (ret) 446 1.5 christos return ret; 447 1.5 christos 448 1.1 elric p = calloc(1, sizeof(*p)); 449 1.1 elric if(!p) 450 1.1 elric return ENOMEM; 451 1.1 elric 452 1.5 christos HEIMDAL_MUTEX_init(&p->mutex); 453 1.1 elric 454 1.1 elric p->flags |= KRB5_CTX_F_HOMEDIR_ACCESS; 455 1.1 elric 456 1.1 elric ret = krb5_get_default_config_files(&files); 457 1.1 elric if(ret) 458 1.1 elric goto out; 459 1.1 elric ret = krb5_set_config_files(p, files); 460 1.1 elric krb5_free_config_files(files); 461 1.1 elric if(ret) 462 1.1 elric goto out; 463 1.1 elric 464 1.5 christos /* done enough to load plugins */ 465 1.5 christos heim_base_once_f(&init_context, p, init_context_once); 466 1.5 christos 467 1.1 elric /* init error tables */ 468 1.1 elric krb5_init_ets(p); 469 1.1 elric cc_ops_register(p); 470 1.1 elric kt_ops_register(p); 471 1.1 elric 472 1.1 elric #ifdef PKINIT 473 1.1 elric ret = hx509_context_init(&p->hx509ctx); 474 1.1 elric if (ret) 475 1.1 elric goto out; 476 1.4 pettai #endif 477 1.1 elric if (rk_SOCK_INIT()) 478 1.1 elric p->flags |= KRB5_CTX_F_SOCKETS_INITIALIZED; 479 1.1 elric 480 1.1 elric out: 481 1.1 elric if(ret) { 482 1.1 elric krb5_free_context(p); 483 1.1 elric p = NULL; 484 1.1 elric } 485 1.1 elric *context = p; 486 1.1 elric return ret; 487 1.1 elric } 488 1.1 elric 489 1.1 elric #ifndef HEIMDAL_SMALLER 490 1.1 elric 491 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 492 1.1 elric krb5_get_permitted_enctypes(krb5_context context, 493 1.1 elric krb5_enctype **etypes) 494 1.1 elric { 495 1.4 pettai return krb5_get_default_in_tkt_etypes(context, KRB5_PDU_NONE, etypes); 496 1.1 elric } 497 1.1 elric 498 1.1 elric /* 499 1.1 elric * 500 1.1 elric */ 501 1.1 elric 502 1.1 elric static krb5_error_code 503 1.1 elric copy_etypes (krb5_context context, 504 1.1 elric krb5_enctype *enctypes, 505 1.1 elric krb5_enctype **ret_enctypes) 506 1.1 elric { 507 1.1 elric unsigned int i; 508 1.1 elric 509 1.1 elric for (i = 0; enctypes[i]; i++) 510 1.1 elric ; 511 1.1 elric i++; 512 1.1 elric 513 1.5 christos *ret_enctypes = malloc(sizeof(enctypes[0]) * i); 514 1.5 christos if (*ret_enctypes == NULL) 515 1.6 christos return krb5_enomem(context); 516 1.5 christos memcpy(*ret_enctypes, enctypes, sizeof(enctypes[0]) * i); 517 1.1 elric return 0; 518 1.1 elric } 519 1.1 elric 520 1.1 elric /** 521 1.1 elric * Make a copy for the Kerberos 5 context, the new krb5_context shoud 522 1.1 elric * be freed with krb5_free_context(). 523 1.1 elric * 524 1.1 elric * @param context the Kerberos context to copy 525 1.1 elric * @param out the copy of the Kerberos, set to NULL error. 526 1.1 elric * 527 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 528 1.1 elric * error code is returned, see krb5_get_error_message(). 529 1.1 elric * 530 1.1 elric * @ingroup krb5 531 1.1 elric */ 532 1.1 elric 533 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 534 1.1 elric krb5_copy_context(krb5_context context, krb5_context *out) 535 1.1 elric { 536 1.1 elric krb5_error_code ret; 537 1.1 elric krb5_context p; 538 1.1 elric 539 1.1 elric *out = NULL; 540 1.1 elric 541 1.1 elric p = calloc(1, sizeof(*p)); 542 1.5 christos if (p == NULL) 543 1.5 christos return krb5_enomem(context); 544 1.1 elric 545 1.5 christos HEIMDAL_MUTEX_init(&p->mutex); 546 1.1 elric 547 1.1 elric if (context->default_cc_name) 548 1.1 elric p->default_cc_name = strdup(context->default_cc_name); 549 1.1 elric if (context->default_cc_name_env) 550 1.1 elric p->default_cc_name_env = strdup(context->default_cc_name_env); 551 1.4 pettai 552 1.1 elric if (context->etypes) { 553 1.1 elric ret = copy_etypes(context, context->etypes, &p->etypes); 554 1.1 elric if (ret) 555 1.1 elric goto out; 556 1.1 elric } 557 1.5 christos if (context->cfg_etypes) { 558 1.5 christos ret = copy_etypes(context, context->cfg_etypes, &p->cfg_etypes); 559 1.5 christos if (ret) 560 1.5 christos goto out; 561 1.5 christos } 562 1.1 elric if (context->etypes_des) { 563 1.1 elric ret = copy_etypes(context, context->etypes_des, &p->etypes_des); 564 1.1 elric if (ret) 565 1.1 elric goto out; 566 1.1 elric } 567 1.1 elric 568 1.1 elric if (context->default_realms) { 569 1.4 pettai ret = krb5_copy_host_realm(context, 570 1.1 elric context->default_realms, &p->default_realms); 571 1.1 elric if (ret) 572 1.1 elric goto out; 573 1.1 elric } 574 1.1 elric 575 1.1 elric ret = _krb5_config_copy(context, context->cf, &p->cf); 576 1.1 elric if (ret) 577 1.1 elric goto out; 578 1.1 elric 579 1.1 elric /* XXX should copy */ 580 1.1 elric krb5_init_ets(p); 581 1.1 elric 582 1.1 elric cc_ops_copy(p, context); 583 1.1 elric kt_ops_copy(p, context); 584 1.1 elric 585 1.1 elric #if 0 /* XXX */ 586 1.1 elric if(context->warn_dest != NULL) 587 1.1 elric ; 588 1.1 elric if(context->debug_dest != NULL) 589 1.1 elric ; 590 1.1 elric #endif 591 1.1 elric 592 1.1 elric ret = krb5_set_extra_addresses(p, context->extra_addresses); 593 1.1 elric if (ret) 594 1.1 elric goto out; 595 1.1 elric ret = krb5_set_extra_addresses(p, context->ignore_addresses); 596 1.1 elric if (ret) 597 1.1 elric goto out; 598 1.1 elric 599 1.1 elric ret = _krb5_copy_send_to_kdc_func(p, context); 600 1.1 elric if (ret) 601 1.1 elric goto out; 602 1.1 elric 603 1.1 elric *out = p; 604 1.1 elric 605 1.1 elric return 0; 606 1.1 elric 607 1.1 elric out: 608 1.1 elric krb5_free_context(p); 609 1.1 elric return ret; 610 1.1 elric } 611 1.1 elric 612 1.1 elric #endif 613 1.1 elric 614 1.1 elric /** 615 1.1 elric * Frees the krb5_context allocated by krb5_init_context(). 616 1.1 elric * 617 1.1 elric * @param context context to be freed. 618 1.1 elric * 619 1.1 elric * @ingroup krb5 620 1.1 elric */ 621 1.1 elric 622 1.1 elric KRB5_LIB_FUNCTION void KRB5_LIB_CALL 623 1.1 elric krb5_free_context(krb5_context context) 624 1.1 elric { 625 1.5 christos _krb5_free_name_canon_rules(context, context->name_canon_rules); 626 1.1 elric if (context->default_cc_name) 627 1.1 elric free(context->default_cc_name); 628 1.1 elric if (context->default_cc_name_env) 629 1.1 elric free(context->default_cc_name_env); 630 1.1 elric free(context->etypes); 631 1.5 christos free(context->cfg_etypes); 632 1.1 elric free(context->etypes_des); 633 1.1 elric krb5_free_host_realm (context, context->default_realms); 634 1.1 elric krb5_config_file_free (context, context->cf); 635 1.1 elric free_error_table (context->et_list); 636 1.1 elric free(rk_UNCONST(context->cc_ops)); 637 1.1 elric free(context->kt_types); 638 1.1 elric krb5_clear_error_message(context); 639 1.1 elric if(context->warn_dest != NULL) 640 1.1 elric krb5_closelog(context, context->warn_dest); 641 1.1 elric if(context->debug_dest != NULL) 642 1.1 elric krb5_closelog(context, context->debug_dest); 643 1.1 elric krb5_set_extra_addresses(context, NULL); 644 1.1 elric krb5_set_ignore_addresses(context, NULL); 645 1.1 elric krb5_set_send_to_kdc_func(context, NULL, NULL); 646 1.1 elric 647 1.1 elric #ifdef PKINIT 648 1.1 elric if (context->hx509ctx) 649 1.1 elric hx509_context_free(&context->hx509ctx); 650 1.1 elric #endif 651 1.1 elric 652 1.5 christos HEIMDAL_MUTEX_destroy(&context->mutex); 653 1.1 elric if (context->flags & KRB5_CTX_F_SOCKETS_INITIALIZED) { 654 1.1 elric rk_SOCK_EXIT(); 655 1.1 elric } 656 1.1 elric 657 1.1 elric memset(context, 0, sizeof(*context)); 658 1.1 elric free(context); 659 1.1 elric } 660 1.1 elric 661 1.1 elric /** 662 1.1 elric * Reinit the context from a new set of filenames. 663 1.1 elric * 664 1.1 elric * @param context context to add configuration too. 665 1.1 elric * @param filenames array of filenames, end of list is indicated with a NULL filename. 666 1.1 elric * 667 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 668 1.1 elric * error code is returned, see krb5_get_error_message(). 669 1.1 elric * 670 1.1 elric * @ingroup krb5 671 1.1 elric */ 672 1.1 elric 673 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 674 1.1 elric krb5_set_config_files(krb5_context context, char **filenames) 675 1.1 elric { 676 1.1 elric krb5_error_code ret; 677 1.1 elric krb5_config_binding *tmp = NULL; 678 1.1 elric while(filenames != NULL && *filenames != NULL && **filenames != '\0') { 679 1.1 elric ret = krb5_config_parse_file_multi(context, *filenames, &tmp); 680 1.5 christos if (ret != 0 && ret != ENOENT && ret != EACCES && ret != EPERM 681 1.5 christos && ret != KRB5_CONFIG_BADFORMAT) { 682 1.1 elric krb5_config_file_free(context, tmp); 683 1.1 elric return ret; 684 1.1 elric } 685 1.1 elric filenames++; 686 1.1 elric } 687 1.2 elric #if 1 688 1.1 elric /* with this enabled and if there are no config files, Kerberos is 689 1.1 elric considererd disabled */ 690 1.1 elric if(tmp == NULL) 691 1.1 elric return ENXIO; 692 1.1 elric #endif 693 1.1 elric 694 1.1 elric #ifdef _WIN32 695 1.1 elric _krb5_load_config_from_registry(context, &tmp); 696 1.1 elric #endif 697 1.1 elric 698 1.1 elric krb5_config_file_free(context, context->cf); 699 1.1 elric context->cf = tmp; 700 1.1 elric ret = init_context_from_config_file(context); 701 1.1 elric return ret; 702 1.1 elric } 703 1.1 elric 704 1.1 elric static krb5_error_code 705 1.1 elric add_file(char ***pfilenames, int *len, char *file) 706 1.1 elric { 707 1.1 elric char **pp = *pfilenames; 708 1.1 elric int i; 709 1.1 elric 710 1.1 elric for(i = 0; i < *len; i++) { 711 1.1 elric if(strcmp(pp[i], file) == 0) { 712 1.1 elric free(file); 713 1.1 elric return 0; 714 1.1 elric } 715 1.1 elric } 716 1.1 elric 717 1.1 elric pp = realloc(*pfilenames, (*len + 2) * sizeof(*pp)); 718 1.1 elric if (pp == NULL) { 719 1.1 elric free(file); 720 1.1 elric return ENOMEM; 721 1.1 elric } 722 1.1 elric 723 1.1 elric pp[*len] = file; 724 1.1 elric pp[*len + 1] = NULL; 725 1.1 elric *pfilenames = pp; 726 1.1 elric *len += 1; 727 1.1 elric return 0; 728 1.1 elric } 729 1.1 elric 730 1.1 elric /* 731 1.1 elric * `pq' isn't free, it's up the the caller 732 1.1 elric */ 733 1.1 elric 734 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 735 1.1 elric krb5_prepend_config_files(const char *filelist, char **pq, char ***ret_pp) 736 1.1 elric { 737 1.1 elric krb5_error_code ret; 738 1.1 elric const char *p, *q; 739 1.1 elric char **pp; 740 1.1 elric int len; 741 1.1 elric char *fn; 742 1.1 elric 743 1.1 elric pp = NULL; 744 1.1 elric 745 1.1 elric len = 0; 746 1.1 elric p = filelist; 747 1.1 elric while(1) { 748 1.1 elric ssize_t l; 749 1.1 elric q = p; 750 1.1 elric l = strsep_copy(&q, PATH_SEP, NULL, 0); 751 1.1 elric if(l == -1) 752 1.1 elric break; 753 1.1 elric fn = malloc(l + 1); 754 1.1 elric if(fn == NULL) { 755 1.1 elric krb5_free_config_files(pp); 756 1.1 elric return ENOMEM; 757 1.1 elric } 758 1.1 elric (void)strsep_copy(&p, PATH_SEP, fn, l + 1); 759 1.1 elric ret = add_file(&pp, &len, fn); 760 1.1 elric if (ret) { 761 1.1 elric krb5_free_config_files(pp); 762 1.1 elric return ret; 763 1.1 elric } 764 1.1 elric } 765 1.1 elric 766 1.1 elric if (pq != NULL) { 767 1.1 elric int i; 768 1.1 elric 769 1.1 elric for (i = 0; pq[i] != NULL; i++) { 770 1.1 elric fn = strdup(pq[i]); 771 1.1 elric if (fn == NULL) { 772 1.1 elric krb5_free_config_files(pp); 773 1.1 elric return ENOMEM; 774 1.1 elric } 775 1.1 elric ret = add_file(&pp, &len, fn); 776 1.1 elric if (ret) { 777 1.1 elric krb5_free_config_files(pp); 778 1.1 elric return ret; 779 1.1 elric } 780 1.1 elric } 781 1.1 elric } 782 1.1 elric 783 1.1 elric *ret_pp = pp; 784 1.1 elric return 0; 785 1.1 elric } 786 1.1 elric 787 1.1 elric /** 788 1.1 elric * Prepend the filename to the global configuration list. 789 1.1 elric * 790 1.1 elric * @param filelist a filename to add to the default list of filename 791 1.1 elric * @param pfilenames return array of filenames, should be freed with krb5_free_config_files(). 792 1.1 elric * 793 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 794 1.1 elric * error code is returned, see krb5_get_error_message(). 795 1.1 elric * 796 1.1 elric * @ingroup krb5 797 1.1 elric */ 798 1.1 elric 799 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 800 1.1 elric krb5_prepend_config_files_default(const char *filelist, char ***pfilenames) 801 1.1 elric { 802 1.1 elric krb5_error_code ret; 803 1.1 elric char **defpp, **pp = NULL; 804 1.1 elric 805 1.1 elric ret = krb5_get_default_config_files(&defpp); 806 1.1 elric if (ret) 807 1.1 elric return ret; 808 1.1 elric 809 1.1 elric ret = krb5_prepend_config_files(filelist, defpp, &pp); 810 1.1 elric krb5_free_config_files(defpp); 811 1.1 elric if (ret) { 812 1.1 elric return ret; 813 1.4 pettai } 814 1.1 elric *pfilenames = pp; 815 1.1 elric return 0; 816 1.1 elric } 817 1.1 elric 818 1.1 elric #ifdef _WIN32 819 1.1 elric 820 1.1 elric /** 821 1.1 elric * Checks the registry for configuration file location 822 1.1 elric * 823 1.1 elric * Kerberos for Windows and other legacy Kerberos applications expect 824 1.1 elric * to find the configuration file location in the 825 1.1 elric * SOFTWARE\MIT\Kerberos registry key under the value "config". 826 1.1 elric */ 827 1.5 christos KRB5_LIB_FUNCTION char * KRB5_LIB_CALL 828 1.1 elric _krb5_get_default_config_config_files_from_registry() 829 1.1 elric { 830 1.1 elric static const char * KeyName = "Software\\MIT\\Kerberos"; 831 1.1 elric char *config_file = NULL; 832 1.1 elric LONG rcode; 833 1.1 elric HKEY key; 834 1.1 elric 835 1.1 elric rcode = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName, 0, KEY_READ, &key); 836 1.1 elric if (rcode == ERROR_SUCCESS) { 837 1.1 elric config_file = _krb5_parse_reg_value_as_multi_string(NULL, key, "config", 838 1.1 elric REG_NONE, 0, PATH_SEP); 839 1.1 elric RegCloseKey(key); 840 1.1 elric } 841 1.1 elric 842 1.1 elric if (config_file) 843 1.1 elric return config_file; 844 1.1 elric 845 1.1 elric rcode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_READ, &key); 846 1.1 elric if (rcode == ERROR_SUCCESS) { 847 1.1 elric config_file = _krb5_parse_reg_value_as_multi_string(NULL, key, "config", 848 1.1 elric REG_NONE, 0, PATH_SEP); 849 1.1 elric RegCloseKey(key); 850 1.1 elric } 851 1.1 elric 852 1.1 elric return config_file; 853 1.1 elric } 854 1.1 elric 855 1.1 elric #endif 856 1.1 elric 857 1.1 elric /** 858 1.1 elric * Get the global configuration list. 859 1.1 elric * 860 1.1 elric * @param pfilenames return array of filenames, should be freed with krb5_free_config_files(). 861 1.1 elric * 862 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 863 1.1 elric * error code is returned, see krb5_get_error_message(). 864 1.1 elric * 865 1.1 elric * @ingroup krb5 866 1.1 elric */ 867 1.1 elric 868 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 869 1.1 elric krb5_get_default_config_files(char ***pfilenames) 870 1.1 elric { 871 1.1 elric const char *files = NULL; 872 1.1 elric 873 1.1 elric if (pfilenames == NULL) 874 1.1 elric return EINVAL; 875 1.1 elric if(!issuid()) 876 1.1 elric files = getenv("KRB5_CONFIG"); 877 1.1 elric 878 1.1 elric #ifdef _WIN32 879 1.1 elric if (files == NULL) { 880 1.1 elric char * reg_files; 881 1.1 elric reg_files = _krb5_get_default_config_config_files_from_registry(); 882 1.1 elric if (reg_files != NULL) { 883 1.1 elric krb5_error_code code; 884 1.1 elric 885 1.1 elric code = krb5_prepend_config_files(reg_files, NULL, pfilenames); 886 1.1 elric free(reg_files); 887 1.1 elric 888 1.1 elric return code; 889 1.1 elric } 890 1.1 elric } 891 1.1 elric #endif 892 1.1 elric 893 1.1 elric if (files == NULL) 894 1.1 elric files = krb5_config_file; 895 1.1 elric 896 1.1 elric return krb5_prepend_config_files(files, NULL, pfilenames); 897 1.1 elric } 898 1.1 elric 899 1.1 elric /** 900 1.1 elric * Free a list of configuration files. 901 1.1 elric * 902 1.1 elric * @param filenames list, terminated with a NULL pointer, to be 903 1.1 elric * freed. NULL is an valid argument. 904 1.1 elric * 905 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 906 1.1 elric * error code is returned, see krb5_get_error_message(). 907 1.1 elric * 908 1.1 elric * @ingroup krb5 909 1.1 elric */ 910 1.1 elric 911 1.1 elric KRB5_LIB_FUNCTION void KRB5_LIB_CALL 912 1.1 elric krb5_free_config_files(char **filenames) 913 1.1 elric { 914 1.1 elric char **p; 915 1.1 elric for(p = filenames; p && *p != NULL; p++) 916 1.1 elric free(*p); 917 1.1 elric free(filenames); 918 1.1 elric } 919 1.1 elric 920 1.1 elric /** 921 1.1 elric * Returns the list of Kerberos encryption types sorted in order of 922 1.1 elric * most preferred to least preferred encryption type. Note that some 923 1.1 elric * encryption types might be disabled, so you need to check with 924 1.1 elric * krb5_enctype_valid() before using the encryption type. 925 1.1 elric * 926 1.1 elric * @return list of enctypes, terminated with ETYPE_NULL. Its a static 927 1.1 elric * array completed into the Kerberos library so the content doesn't 928 1.1 elric * need to be freed. 929 1.1 elric * 930 1.1 elric * @ingroup krb5 931 1.1 elric */ 932 1.1 elric 933 1.1 elric KRB5_LIB_FUNCTION const krb5_enctype * KRB5_LIB_CALL 934 1.1 elric krb5_kerberos_enctypes(krb5_context context) 935 1.1 elric { 936 1.1 elric static const krb5_enctype p[] = { 937 1.1 elric ETYPE_AES256_CTS_HMAC_SHA1_96, 938 1.1 elric ETYPE_AES128_CTS_HMAC_SHA1_96, 939 1.5 christos ETYPE_AES256_CTS_HMAC_SHA384_192, 940 1.5 christos ETYPE_AES128_CTS_HMAC_SHA256_128, 941 1.5 christos ETYPE_DES3_CBC_SHA1, 942 1.5 christos ETYPE_ARCFOUR_HMAC_MD5, 943 1.5 christos ETYPE_NULL 944 1.5 christos }; 945 1.5 christos 946 1.5 christos static const krb5_enctype weak[] = { 947 1.5 christos ETYPE_AES256_CTS_HMAC_SHA1_96, 948 1.5 christos ETYPE_AES128_CTS_HMAC_SHA1_96, 949 1.5 christos ETYPE_AES256_CTS_HMAC_SHA384_192, 950 1.5 christos ETYPE_AES128_CTS_HMAC_SHA256_128, 951 1.1 elric ETYPE_DES3_CBC_SHA1, 952 1.1 elric ETYPE_DES3_CBC_MD5, 953 1.1 elric ETYPE_ARCFOUR_HMAC_MD5, 954 1.1 elric ETYPE_DES_CBC_MD5, 955 1.1 elric ETYPE_DES_CBC_MD4, 956 1.1 elric ETYPE_DES_CBC_CRC, 957 1.1 elric ETYPE_NULL 958 1.1 elric }; 959 1.5 christos 960 1.5 christos /* 961 1.5 christos * if the list of enctypes enabled by "allow_weak_crypto" 962 1.5 christos * are valid, then return the former default enctype list 963 1.5 christos * that contained the weak entries. 964 1.5 christos */ 965 1.5 christos if (krb5_enctype_valid(context, ETYPE_DES_CBC_CRC) == 0 && 966 1.5 christos krb5_enctype_valid(context, ETYPE_DES_CBC_MD4) == 0 && 967 1.5 christos krb5_enctype_valid(context, ETYPE_DES_CBC_MD5) == 0 && 968 1.5 christos krb5_enctype_valid(context, ETYPE_DES_CBC_NONE) == 0 && 969 1.5 christos krb5_enctype_valid(context, ETYPE_DES_CFB64_NONE) == 0 && 970 1.5 christos krb5_enctype_valid(context, ETYPE_DES_PCBC_NONE) == 0) 971 1.5 christos return weak; 972 1.5 christos 973 1.1 elric return p; 974 1.1 elric } 975 1.1 elric 976 1.1 elric /* 977 1.4 pettai * 978 1.1 elric */ 979 1.1 elric 980 1.1 elric static krb5_error_code 981 1.4 pettai copy_enctypes(krb5_context context, 982 1.4 pettai const krb5_enctype *in, 983 1.4 pettai krb5_enctype **out) 984 1.1 elric { 985 1.4 pettai krb5_enctype *p = NULL; 986 1.4 pettai size_t m, n; 987 1.1 elric 988 1.4 pettai for (n = 0; in[n]; n++) 989 1.4 pettai ; 990 1.4 pettai n++; 991 1.4 pettai ALLOC(p, n); 992 1.4 pettai if(p == NULL) 993 1.4 pettai return krb5_enomem(context); 994 1.4 pettai for (n = 0, m = 0; in[n]; n++) { 995 1.4 pettai if (krb5_enctype_valid(context, in[n]) != 0) 996 1.1 elric continue; 997 1.4 pettai p[m++] = in[n]; 998 1.4 pettai } 999 1.4 pettai p[m] = KRB5_ENCTYPE_NULL; 1000 1.4 pettai if (m == 0) { 1001 1.4 pettai free(p); 1002 1.4 pettai krb5_set_error_message (context, KRB5_PROG_ETYPE_NOSUPP, 1003 1.4 pettai N_("no valid enctype set", "")); 1004 1.4 pettai return KRB5_PROG_ETYPE_NOSUPP; 1005 1.1 elric } 1006 1.4 pettai *out = p; 1007 1.1 elric return 0; 1008 1.1 elric } 1009 1.1 elric 1010 1.4 pettai 1011 1.4 pettai /* 1012 1.4 pettai * set `etype' to a malloced list of the default enctypes 1013 1.4 pettai */ 1014 1.4 pettai 1015 1.4 pettai static krb5_error_code 1016 1.4 pettai default_etypes(krb5_context context, krb5_enctype **etype) 1017 1.4 pettai { 1018 1.4 pettai const krb5_enctype *p = krb5_kerberos_enctypes(context); 1019 1.4 pettai return copy_enctypes(context, p, etype); 1020 1.4 pettai } 1021 1.4 pettai 1022 1.1 elric /** 1023 1.1 elric * Set the default encryption types that will be use in communcation 1024 1.1 elric * with the KDC, clients and servers. 1025 1.1 elric * 1026 1.1 elric * @param context Kerberos 5 context. 1027 1.1 elric * @param etypes Encryption types, array terminated with ETYPE_NULL (0). 1028 1.5 christos * A value of NULL resets the encryption types to the defaults set in the 1029 1.5 christos * configuration file. 1030 1.1 elric * 1031 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1032 1.1 elric * error code is returned, see krb5_get_error_message(). 1033 1.1 elric * 1034 1.1 elric * @ingroup krb5 1035 1.1 elric */ 1036 1.1 elric 1037 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1038 1.1 elric krb5_set_default_in_tkt_etypes(krb5_context context, 1039 1.1 elric const krb5_enctype *etypes) 1040 1.1 elric { 1041 1.1 elric krb5_error_code ret; 1042 1.1 elric krb5_enctype *p = NULL; 1043 1.1 elric 1044 1.5 christos if(!etypes) { 1045 1.5 christos etypes = context->cfg_etypes; 1046 1.5 christos } 1047 1.5 christos 1048 1.1 elric if(etypes) { 1049 1.4 pettai ret = copy_enctypes(context, etypes, &p); 1050 1.4 pettai if (ret) 1051 1.4 pettai return ret; 1052 1.1 elric } 1053 1.1 elric if(context->etypes) 1054 1.1 elric free(context->etypes); 1055 1.1 elric context->etypes = p; 1056 1.1 elric return 0; 1057 1.1 elric } 1058 1.1 elric 1059 1.1 elric /** 1060 1.1 elric * Get the default encryption types that will be use in communcation 1061 1.1 elric * with the KDC, clients and servers. 1062 1.1 elric * 1063 1.1 elric * @param context Kerberos 5 context. 1064 1.5 christos * @param pdu_type request type (AS, TGS or none) 1065 1.1 elric * @param etypes Encryption types, array terminated with 1066 1.1 elric * ETYPE_NULL(0), caller should free array with krb5_xfree(): 1067 1.1 elric * 1068 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1069 1.1 elric * error code is returned, see krb5_get_error_message(). 1070 1.1 elric * 1071 1.1 elric * @ingroup krb5 1072 1.1 elric */ 1073 1.1 elric 1074 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1075 1.1 elric krb5_get_default_in_tkt_etypes(krb5_context context, 1076 1.4 pettai krb5_pdu pdu_type, 1077 1.1 elric krb5_enctype **etypes) 1078 1.1 elric { 1079 1.4 pettai krb5_enctype *enctypes = NULL; 1080 1.4 pettai krb5_error_code ret; 1081 1.1 elric krb5_enctype *p; 1082 1.1 elric 1083 1.4 pettai heim_assert(pdu_type == KRB5_PDU_AS_REQUEST || 1084 1.4 pettai pdu_type == KRB5_PDU_TGS_REQUEST || 1085 1.5 christos pdu_type == KRB5_PDU_NONE, "unexpected pdu type"); 1086 1.4 pettai 1087 1.4 pettai if (pdu_type == KRB5_PDU_AS_REQUEST && context->as_etypes != NULL) 1088 1.4 pettai enctypes = context->as_etypes; 1089 1.4 pettai else if (pdu_type == KRB5_PDU_TGS_REQUEST && context->tgs_etypes != NULL) 1090 1.4 pettai enctypes = context->tgs_etypes; 1091 1.4 pettai else if (context->etypes != NULL) 1092 1.4 pettai enctypes = context->etypes; 1093 1.4 pettai 1094 1.4 pettai if (enctypes != NULL) { 1095 1.4 pettai ret = copy_enctypes(context, enctypes, &p); 1096 1.4 pettai if (ret) 1097 1.4 pettai return ret; 1098 1.1 elric } else { 1099 1.1 elric ret = default_etypes(context, &p); 1100 1.1 elric if (ret) 1101 1.1 elric return ret; 1102 1.1 elric } 1103 1.1 elric *etypes = p; 1104 1.1 elric return 0; 1105 1.1 elric } 1106 1.1 elric 1107 1.1 elric /** 1108 1.1 elric * Init the built-in ets in the Kerberos library. 1109 1.1 elric * 1110 1.1 elric * @param context kerberos context to add the ets too 1111 1.1 elric * 1112 1.1 elric * @ingroup krb5 1113 1.1 elric */ 1114 1.1 elric 1115 1.1 elric KRB5_LIB_FUNCTION void KRB5_LIB_CALL 1116 1.1 elric krb5_init_ets(krb5_context context) 1117 1.1 elric { 1118 1.1 elric if(context->et_list == NULL){ 1119 1.1 elric krb5_add_et_list(context, initialize_krb5_error_table_r); 1120 1.1 elric krb5_add_et_list(context, initialize_asn1_error_table_r); 1121 1.1 elric krb5_add_et_list(context, initialize_heim_error_table_r); 1122 1.1 elric 1123 1.1 elric krb5_add_et_list(context, initialize_k524_error_table_r); 1124 1.1 elric 1125 1.1 elric #ifdef COM_ERR_BINDDOMAIN_krb5 1126 1.1 elric bindtextdomain(COM_ERR_BINDDOMAIN_krb5, HEIMDAL_LOCALEDIR); 1127 1.1 elric bindtextdomain(COM_ERR_BINDDOMAIN_asn1, HEIMDAL_LOCALEDIR); 1128 1.1 elric bindtextdomain(COM_ERR_BINDDOMAIN_heim, HEIMDAL_LOCALEDIR); 1129 1.1 elric bindtextdomain(COM_ERR_BINDDOMAIN_k524, HEIMDAL_LOCALEDIR); 1130 1.1 elric #endif 1131 1.1 elric 1132 1.1 elric #ifdef PKINIT 1133 1.1 elric krb5_add_et_list(context, initialize_hx_error_table_r); 1134 1.1 elric #ifdef COM_ERR_BINDDOMAIN_hx 1135 1.1 elric bindtextdomain(COM_ERR_BINDDOMAIN_hx, HEIMDAL_LOCALEDIR); 1136 1.1 elric #endif 1137 1.1 elric #endif 1138 1.1 elric } 1139 1.1 elric } 1140 1.1 elric 1141 1.1 elric /** 1142 1.1 elric * Make the kerberos library default to the admin KDC. 1143 1.1 elric * 1144 1.1 elric * @param context Kerberos 5 context. 1145 1.1 elric * @param flag boolean flag to select if the use the admin KDC or not. 1146 1.1 elric * 1147 1.1 elric * @ingroup krb5 1148 1.1 elric */ 1149 1.1 elric 1150 1.1 elric KRB5_LIB_FUNCTION void KRB5_LIB_CALL 1151 1.1 elric krb5_set_use_admin_kdc (krb5_context context, krb5_boolean flag) 1152 1.1 elric { 1153 1.1 elric context->use_admin_kdc = flag; 1154 1.1 elric } 1155 1.1 elric 1156 1.1 elric /** 1157 1.1 elric * Make the kerberos library default to the admin KDC. 1158 1.1 elric * 1159 1.1 elric * @param context Kerberos 5 context. 1160 1.1 elric * 1161 1.1 elric * @return boolean flag to telling the context will use admin KDC as the default KDC. 1162 1.1 elric * 1163 1.1 elric * @ingroup krb5 1164 1.1 elric */ 1165 1.1 elric 1166 1.1 elric KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL 1167 1.1 elric krb5_get_use_admin_kdc (krb5_context context) 1168 1.1 elric { 1169 1.1 elric return context->use_admin_kdc; 1170 1.1 elric } 1171 1.1 elric 1172 1.1 elric /** 1173 1.1 elric * Add extra address to the address list that the library will add to 1174 1.1 elric * the client's address list when communicating with the KDC. 1175 1.1 elric * 1176 1.1 elric * @param context Kerberos 5 context. 1177 1.1 elric * @param addresses addreses to add 1178 1.1 elric * 1179 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1180 1.1 elric * error code is returned, see krb5_get_error_message(). 1181 1.1 elric * 1182 1.1 elric * @ingroup krb5 1183 1.1 elric */ 1184 1.1 elric 1185 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1186 1.1 elric krb5_add_extra_addresses(krb5_context context, krb5_addresses *addresses) 1187 1.1 elric { 1188 1.1 elric 1189 1.1 elric if(context->extra_addresses) 1190 1.1 elric return krb5_append_addresses(context, 1191 1.1 elric context->extra_addresses, addresses); 1192 1.1 elric else 1193 1.1 elric return krb5_set_extra_addresses(context, addresses); 1194 1.1 elric } 1195 1.1 elric 1196 1.1 elric /** 1197 1.1 elric * Set extra address to the address list that the library will add to 1198 1.1 elric * the client's address list when communicating with the KDC. 1199 1.1 elric * 1200 1.1 elric * @param context Kerberos 5 context. 1201 1.1 elric * @param addresses addreses to set 1202 1.1 elric * 1203 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1204 1.1 elric * error code is returned, see krb5_get_error_message(). 1205 1.1 elric * 1206 1.1 elric * @ingroup krb5 1207 1.1 elric */ 1208 1.1 elric 1209 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1210 1.1 elric krb5_set_extra_addresses(krb5_context context, const krb5_addresses *addresses) 1211 1.1 elric { 1212 1.1 elric if(context->extra_addresses) 1213 1.1 elric krb5_free_addresses(context, context->extra_addresses); 1214 1.1 elric 1215 1.1 elric if(addresses == NULL) { 1216 1.1 elric if(context->extra_addresses != NULL) { 1217 1.1 elric free(context->extra_addresses); 1218 1.1 elric context->extra_addresses = NULL; 1219 1.1 elric } 1220 1.1 elric return 0; 1221 1.1 elric } 1222 1.1 elric if(context->extra_addresses == NULL) { 1223 1.1 elric context->extra_addresses = malloc(sizeof(*context->extra_addresses)); 1224 1.5 christos if (context->extra_addresses == NULL) 1225 1.5 christos return krb5_enomem(context); 1226 1.1 elric } 1227 1.1 elric return krb5_copy_addresses(context, addresses, context->extra_addresses); 1228 1.1 elric } 1229 1.1 elric 1230 1.1 elric /** 1231 1.1 elric * Get extra address to the address list that the library will add to 1232 1.1 elric * the client's address list when communicating with the KDC. 1233 1.1 elric * 1234 1.1 elric * @param context Kerberos 5 context. 1235 1.1 elric * @param addresses addreses to set 1236 1.1 elric * 1237 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1238 1.1 elric * error code is returned, see krb5_get_error_message(). 1239 1.1 elric * 1240 1.1 elric * @ingroup krb5 1241 1.1 elric */ 1242 1.1 elric 1243 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1244 1.1 elric krb5_get_extra_addresses(krb5_context context, krb5_addresses *addresses) 1245 1.1 elric { 1246 1.1 elric if(context->extra_addresses == NULL) { 1247 1.1 elric memset(addresses, 0, sizeof(*addresses)); 1248 1.1 elric return 0; 1249 1.1 elric } 1250 1.1 elric return krb5_copy_addresses(context,context->extra_addresses, addresses); 1251 1.1 elric } 1252 1.1 elric 1253 1.1 elric /** 1254 1.1 elric * Add extra addresses to ignore when fetching addresses from the 1255 1.1 elric * underlaying operating system. 1256 1.1 elric * 1257 1.1 elric * @param context Kerberos 5 context. 1258 1.1 elric * @param addresses addreses to ignore 1259 1.1 elric * 1260 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1261 1.1 elric * error code is returned, see krb5_get_error_message(). 1262 1.1 elric * 1263 1.1 elric * @ingroup krb5 1264 1.1 elric */ 1265 1.1 elric 1266 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1267 1.1 elric krb5_add_ignore_addresses(krb5_context context, krb5_addresses *addresses) 1268 1.1 elric { 1269 1.1 elric 1270 1.1 elric if(context->ignore_addresses) 1271 1.1 elric return krb5_append_addresses(context, 1272 1.1 elric context->ignore_addresses, addresses); 1273 1.1 elric else 1274 1.1 elric return krb5_set_ignore_addresses(context, addresses); 1275 1.1 elric } 1276 1.1 elric 1277 1.1 elric /** 1278 1.1 elric * Set extra addresses to ignore when fetching addresses from the 1279 1.1 elric * underlaying operating system. 1280 1.1 elric * 1281 1.1 elric * @param context Kerberos 5 context. 1282 1.1 elric * @param addresses addreses to ignore 1283 1.1 elric * 1284 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1285 1.1 elric * error code is returned, see krb5_get_error_message(). 1286 1.1 elric * 1287 1.1 elric * @ingroup krb5 1288 1.1 elric */ 1289 1.1 elric 1290 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1291 1.1 elric krb5_set_ignore_addresses(krb5_context context, const krb5_addresses *addresses) 1292 1.1 elric { 1293 1.1 elric if(context->ignore_addresses) 1294 1.1 elric krb5_free_addresses(context, context->ignore_addresses); 1295 1.1 elric if(addresses == NULL) { 1296 1.1 elric if(context->ignore_addresses != NULL) { 1297 1.1 elric free(context->ignore_addresses); 1298 1.1 elric context->ignore_addresses = NULL; 1299 1.1 elric } 1300 1.1 elric return 0; 1301 1.1 elric } 1302 1.1 elric if(context->ignore_addresses == NULL) { 1303 1.1 elric context->ignore_addresses = malloc(sizeof(*context->ignore_addresses)); 1304 1.5 christos if (context->ignore_addresses == NULL) 1305 1.5 christos return krb5_enomem(context); 1306 1.1 elric } 1307 1.1 elric return krb5_copy_addresses(context, addresses, context->ignore_addresses); 1308 1.1 elric } 1309 1.1 elric 1310 1.1 elric /** 1311 1.1 elric * Get extra addresses to ignore when fetching addresses from the 1312 1.1 elric * underlaying operating system. 1313 1.1 elric * 1314 1.1 elric * @param context Kerberos 5 context. 1315 1.1 elric * @param addresses list addreses ignored 1316 1.1 elric * 1317 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1318 1.1 elric * error code is returned, see krb5_get_error_message(). 1319 1.1 elric * 1320 1.1 elric * @ingroup krb5 1321 1.1 elric */ 1322 1.1 elric 1323 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1324 1.1 elric krb5_get_ignore_addresses(krb5_context context, krb5_addresses *addresses) 1325 1.1 elric { 1326 1.1 elric if(context->ignore_addresses == NULL) { 1327 1.1 elric memset(addresses, 0, sizeof(*addresses)); 1328 1.1 elric return 0; 1329 1.1 elric } 1330 1.1 elric return krb5_copy_addresses(context, context->ignore_addresses, addresses); 1331 1.1 elric } 1332 1.1 elric 1333 1.1 elric /** 1334 1.1 elric * Set version of fcache that the library should use. 1335 1.1 elric * 1336 1.1 elric * @param context Kerberos 5 context. 1337 1.1 elric * @param version version number. 1338 1.1 elric * 1339 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1340 1.1 elric * error code is returned, see krb5_get_error_message(). 1341 1.1 elric * 1342 1.1 elric * @ingroup krb5 1343 1.1 elric */ 1344 1.1 elric 1345 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1346 1.1 elric krb5_set_fcache_version(krb5_context context, int version) 1347 1.1 elric { 1348 1.1 elric context->fcache_vno = version; 1349 1.1 elric return 0; 1350 1.1 elric } 1351 1.1 elric 1352 1.1 elric /** 1353 1.1 elric * Get version of fcache that the library should use. 1354 1.1 elric * 1355 1.1 elric * @param context Kerberos 5 context. 1356 1.1 elric * @param version version number. 1357 1.1 elric * 1358 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1359 1.1 elric * error code is returned, see krb5_get_error_message(). 1360 1.1 elric * 1361 1.1 elric * @ingroup krb5 1362 1.1 elric */ 1363 1.1 elric 1364 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1365 1.1 elric krb5_get_fcache_version(krb5_context context, int *version) 1366 1.1 elric { 1367 1.1 elric *version = context->fcache_vno; 1368 1.1 elric return 0; 1369 1.1 elric } 1370 1.1 elric 1371 1.1 elric /** 1372 1.1 elric * Runtime check if the Kerberos library was complied with thread support. 1373 1.1 elric * 1374 1.1 elric * @return TRUE if the library was compiled with thread support, FALSE if not. 1375 1.1 elric * 1376 1.1 elric * @ingroup krb5 1377 1.1 elric */ 1378 1.1 elric 1379 1.1 elric 1380 1.1 elric KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL 1381 1.1 elric krb5_is_thread_safe(void) 1382 1.1 elric { 1383 1.1 elric #ifdef ENABLE_PTHREAD_SUPPORT 1384 1.1 elric return TRUE; 1385 1.1 elric #else 1386 1.1 elric return FALSE; 1387 1.1 elric #endif 1388 1.1 elric } 1389 1.1 elric 1390 1.1 elric /** 1391 1.1 elric * Set if the library should use DNS to canonicalize hostnames. 1392 1.1 elric * 1393 1.1 elric * @param context Kerberos 5 context. 1394 1.1 elric * @param flag if its dns canonicalizion is used or not. 1395 1.1 elric * 1396 1.1 elric * @ingroup krb5 1397 1.1 elric */ 1398 1.1 elric 1399 1.1 elric KRB5_LIB_FUNCTION void KRB5_LIB_CALL 1400 1.1 elric krb5_set_dns_canonicalize_hostname (krb5_context context, krb5_boolean flag) 1401 1.1 elric { 1402 1.1 elric if (flag) 1403 1.1 elric context->flags |= KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME; 1404 1.1 elric else 1405 1.1 elric context->flags &= ~KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME; 1406 1.1 elric } 1407 1.1 elric 1408 1.1 elric /** 1409 1.1 elric * Get if the library uses DNS to canonicalize hostnames. 1410 1.1 elric * 1411 1.1 elric * @param context Kerberos 5 context. 1412 1.1 elric * 1413 1.1 elric * @return return non zero if the library uses DNS to canonicalize hostnames. 1414 1.1 elric * 1415 1.1 elric * @ingroup krb5 1416 1.1 elric */ 1417 1.1 elric 1418 1.1 elric KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL 1419 1.1 elric krb5_get_dns_canonicalize_hostname (krb5_context context) 1420 1.1 elric { 1421 1.1 elric return (context->flags & KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME) ? 1 : 0; 1422 1.1 elric } 1423 1.1 elric 1424 1.1 elric /** 1425 1.1 elric * Get current offset in time to the KDC. 1426 1.1 elric * 1427 1.1 elric * @param context Kerberos 5 context. 1428 1.1 elric * @param sec seconds part of offset. 1429 1.1 elric * @param usec micro seconds part of offset. 1430 1.1 elric * 1431 1.1 elric * @return returns zero 1432 1.1 elric * 1433 1.1 elric * @ingroup krb5 1434 1.1 elric */ 1435 1.1 elric 1436 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1437 1.1 elric krb5_get_kdc_sec_offset (krb5_context context, int32_t *sec, int32_t *usec) 1438 1.1 elric { 1439 1.1 elric if (sec) 1440 1.1 elric *sec = context->kdc_sec_offset; 1441 1.1 elric if (usec) 1442 1.1 elric *usec = context->kdc_usec_offset; 1443 1.1 elric return 0; 1444 1.1 elric } 1445 1.1 elric 1446 1.1 elric /** 1447 1.1 elric * Set current offset in time to the KDC. 1448 1.1 elric * 1449 1.1 elric * @param context Kerberos 5 context. 1450 1.1 elric * @param sec seconds part of offset. 1451 1.1 elric * @param usec micro seconds part of offset. 1452 1.1 elric * 1453 1.1 elric * @return returns zero 1454 1.1 elric * 1455 1.1 elric * @ingroup krb5 1456 1.1 elric */ 1457 1.1 elric 1458 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1459 1.1 elric krb5_set_kdc_sec_offset (krb5_context context, int32_t sec, int32_t usec) 1460 1.1 elric { 1461 1.1 elric context->kdc_sec_offset = sec; 1462 1.1 elric if (usec >= 0) 1463 1.1 elric context->kdc_usec_offset = usec; 1464 1.1 elric return 0; 1465 1.1 elric } 1466 1.1 elric 1467 1.1 elric /** 1468 1.1 elric * Get max time skew allowed. 1469 1.1 elric * 1470 1.1 elric * @param context Kerberos 5 context. 1471 1.1 elric * 1472 1.1 elric * @return timeskew in seconds. 1473 1.1 elric * 1474 1.1 elric * @ingroup krb5 1475 1.1 elric */ 1476 1.1 elric 1477 1.1 elric KRB5_LIB_FUNCTION time_t KRB5_LIB_CALL 1478 1.1 elric krb5_get_max_time_skew (krb5_context context) 1479 1.1 elric { 1480 1.1 elric return context->max_skew; 1481 1.1 elric } 1482 1.1 elric 1483 1.1 elric /** 1484 1.1 elric * Set max time skew allowed. 1485 1.1 elric * 1486 1.1 elric * @param context Kerberos 5 context. 1487 1.1 elric * @param t timeskew in seconds. 1488 1.1 elric * 1489 1.1 elric * @ingroup krb5 1490 1.1 elric */ 1491 1.1 elric 1492 1.1 elric KRB5_LIB_FUNCTION void KRB5_LIB_CALL 1493 1.1 elric krb5_set_max_time_skew (krb5_context context, time_t t) 1494 1.1 elric { 1495 1.1 elric context->max_skew = t; 1496 1.1 elric } 1497 1.1 elric 1498 1.4 pettai /* 1499 1.1 elric * Init encryption types in len, val with etypes. 1500 1.1 elric * 1501 1.1 elric * @param context Kerberos 5 context. 1502 1.4 pettai * @param pdu_type type of pdu 1503 1.1 elric * @param len output length of val. 1504 1.1 elric * @param val output array of enctypes. 1505 1.1 elric * @param etypes etypes to set val and len to, if NULL, use default enctypes. 1506 1.1 elric 1507 1.1 elric * @return Returns 0 to indicate success. Otherwise an kerberos et 1508 1.1 elric * error code is returned, see krb5_get_error_message(). 1509 1.1 elric * 1510 1.1 elric * @ingroup krb5 1511 1.1 elric */ 1512 1.1 elric 1513 1.1 elric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL 1514 1.4 pettai _krb5_init_etype(krb5_context context, 1515 1.4 pettai krb5_pdu pdu_type, 1516 1.1 elric unsigned *len, 1517 1.1 elric krb5_enctype **val, 1518 1.1 elric const krb5_enctype *etypes) 1519 1.1 elric { 1520 1.1 elric krb5_error_code ret; 1521 1.1 elric 1522 1.4 pettai if (etypes == NULL) 1523 1.4 pettai ret = krb5_get_default_in_tkt_etypes(context, pdu_type, val); 1524 1.4 pettai else 1525 1.4 pettai ret = copy_enctypes(context, etypes, val); 1526 1.4 pettai if (ret) 1527 1.4 pettai return ret; 1528 1.4 pettai 1529 1.4 pettai if (len) { 1530 1.4 pettai *len = 0; 1531 1.4 pettai while ((*val)[*len] != KRB5_ENCTYPE_NULL) 1532 1.4 pettai (*len)++; 1533 1.1 elric } 1534 1.4 pettai return 0; 1535 1.1 elric } 1536 1.1 elric 1537 1.1 elric /* 1538 1.1 elric * Allow homedir accces 1539 1.1 elric */ 1540 1.1 elric 1541 1.1 elric static HEIMDAL_MUTEX homedir_mutex = HEIMDAL_MUTEX_INITIALIZER; 1542 1.1 elric static krb5_boolean allow_homedir = TRUE; 1543 1.1 elric 1544 1.5 christos KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL 1545 1.1 elric _krb5_homedir_access(krb5_context context) 1546 1.1 elric { 1547 1.1 elric krb5_boolean allow; 1548 1.1 elric 1549 1.1 elric if (context && (context->flags & KRB5_CTX_F_HOMEDIR_ACCESS) == 0) 1550 1.1 elric return FALSE; 1551 1.1 elric 1552 1.1 elric HEIMDAL_MUTEX_lock(&homedir_mutex); 1553 1.1 elric allow = allow_homedir; 1554 1.1 elric HEIMDAL_MUTEX_unlock(&homedir_mutex); 1555 1.1 elric return allow; 1556 1.1 elric } 1557 1.1 elric 1558 1.1 elric /** 1559 1.1 elric * Enable and disable home directory access on either the global state 1560 1.1 elric * or the krb5_context state. By calling krb5_set_home_dir_access() 1561 1.1 elric * with context set to NULL, the global state is configured otherwise 1562 1.1 elric * the state for the krb5_context is modified. 1563 1.1 elric * 1564 1.1 elric * For home directory access to be allowed, both the global state and 1565 1.1 elric * the krb5_context state have to be allowed. 1566 1.1 elric * 1567 1.1 elric * @param context a Kerberos 5 context or NULL 1568 1.1 elric * @param allow allow if TRUE home directory 1569 1.1 elric * @return the old value 1570 1.1 elric * 1571 1.1 elric * @ingroup krb5 1572 1.1 elric */ 1573 1.1 elric 1574 1.1 elric KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL 1575 1.1 elric krb5_set_home_dir_access(krb5_context context, krb5_boolean allow) 1576 1.1 elric { 1577 1.1 elric krb5_boolean old; 1578 1.1 elric if (context) { 1579 1.1 elric old = (context->flags & KRB5_CTX_F_HOMEDIR_ACCESS) ? TRUE : FALSE; 1580 1.1 elric if (allow) 1581 1.1 elric context->flags |= KRB5_CTX_F_HOMEDIR_ACCESS; 1582 1.1 elric else 1583 1.1 elric context->flags &= ~KRB5_CTX_F_HOMEDIR_ACCESS; 1584 1.1 elric } else { 1585 1.1 elric HEIMDAL_MUTEX_lock(&homedir_mutex); 1586 1.1 elric old = allow_homedir; 1587 1.1 elric allow_homedir = allow; 1588 1.1 elric HEIMDAL_MUTEX_unlock(&homedir_mutex); 1589 1.1 elric } 1590 1.1 elric 1591 1.1 elric return old; 1592 1.1 elric } 1593