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