2 * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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.
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.
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
36 #include "krb5_locl.h"
39 #define INIT_FIELD(C, T, E, D, F) \
40 (C)->E = krb5_config_get_ ## T ## _default ((C), NULL, (D), \
41 "libdefaults", F, NULL)
43 #define INIT_FLAG(C, O, V, D, F) \
45 if (krb5_config_get_bool_default((C), NULL, (D),"libdefaults", F, NULL)) { \
51 * Set the list of etypes `ret_etypes' from the configuration variable
55 static krb5_error_code
56 set_etypes (krb5_context context
,
58 krb5_enctype
**ret_enctypes
)
61 krb5_enctype
*etypes
= NULL
;
63 etypes_str
= krb5_config_get_strings(context
, NULL
, "libdefaults",
67 for(i
= 0; etypes_str
[i
]; i
++);
68 etypes
= malloc((i
+1) * sizeof(*etypes
));
70 krb5_config_free_strings (etypes_str
);
71 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
74 for(j
= 0, k
= 0; j
< i
; j
++) {
76 if(krb5_string_to_enctype(context
, etypes_str
[j
], &e
) != 0)
78 if (krb5_enctype_valid(context
, e
) != 0)
82 etypes
[k
] = ETYPE_NULL
;
83 krb5_config_free_strings(etypes_str
);
85 *ret_enctypes
= etypes
;
90 * read variables from the configuration file and set in `context'
93 static krb5_error_code
94 init_context_from_config_file(krb5_context context
)
99 krb5_enctype
*tmptypes
;
101 INIT_FIELD(context
, time
, max_skew
, 5 * 60, "clockskew");
102 INIT_FIELD(context
, time
, kdc_timeout
, 3, "kdc_timeout");
103 INIT_FIELD(context
, int, max_retries
, 3, "max_retries");
105 INIT_FIELD(context
, string
, http_proxy
, NULL
, "http_proxy");
107 ret
= set_etypes (context
, "default_etypes", &tmptypes
);
110 free(context
->etypes
);
111 context
->etypes
= tmptypes
;
113 ret
= set_etypes (context
, "default_etypes_des", &tmptypes
);
116 free(context
->etypes_des
);
117 context
->etypes_des
= tmptypes
;
119 /* default keytab name */
122 tmp
= getenv("KRB5_KTNAME");
124 context
->default_keytab
= tmp
;
126 INIT_FIELD(context
, string
, default_keytab
,
127 KEYTAB_DEFAULT
, "default_keytab_name");
129 INIT_FIELD(context
, string
, default_keytab_modify
,
130 NULL
, "default_keytab_modify_name");
132 INIT_FIELD(context
, string
, time_fmt
,
133 "%Y-%m-%dT%H:%M:%S", "time_format");
135 INIT_FIELD(context
, string
, date_fmt
,
136 "%Y-%m-%d", "date_format");
138 INIT_FIELD(context
, bool, log_utc
,
143 /* init dns-proxy slime */
144 tmp
= krb5_config_get_string(context
, NULL
, "libdefaults",
147 roken_gethostby_setup(context
->http_proxy
, tmp
);
148 krb5_free_host_realm (context
, context
->default_realms
);
149 context
->default_realms
= NULL
;
152 krb5_addresses addresses
;
155 krb5_set_extra_addresses(context
, NULL
);
156 adr
= krb5_config_get_strings(context
, NULL
,
160 memset(&addresses
, 0, sizeof(addresses
));
161 for(a
= adr
; a
&& *a
; a
++) {
162 ret
= krb5_parse_address(context
, *a
, &addresses
);
164 krb5_add_extra_addresses(context
, &addresses
);
165 krb5_free_addresses(context
, &addresses
);
168 krb5_config_free_strings(adr
);
170 krb5_set_ignore_addresses(context
, NULL
);
171 adr
= krb5_config_get_strings(context
, NULL
,
175 memset(&addresses
, 0, sizeof(addresses
));
176 for(a
= adr
; a
&& *a
; a
++) {
177 ret
= krb5_parse_address(context
, *a
, &addresses
);
179 krb5_add_ignore_addresses(context
, &addresses
);
180 krb5_free_addresses(context
, &addresses
);
183 krb5_config_free_strings(adr
);
186 INIT_FIELD(context
, bool, scan_interfaces
, TRUE
, "scan_interfaces");
187 INIT_FIELD(context
, int, fcache_vno
, 0, "fcache_version");
188 /* prefer dns_lookup_kdc over srv_lookup. */
189 INIT_FIELD(context
, bool, srv_lookup
, TRUE
, "srv_lookup");
190 INIT_FIELD(context
, bool, srv_lookup
, context
->srv_lookup
, "dns_lookup_kdc");
191 INIT_FIELD(context
, int, large_msg_size
, 1400, "large_message_size");
192 INIT_FLAG(context
, flags
, KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
, TRUE
, "dns_canonicalize_hostname");
193 INIT_FLAG(context
, flags
, KRB5_CTX_F_CHECK_PAC
, TRUE
, "check_pac");
194 context
->default_cc_name
= NULL
;
195 context
->default_cc_name_set
= 0;
197 ret
= krb5_config_get_bool_default(context
, NULL
, FALSE
,
199 "allow_weak_crypto", NULL
);
201 krb5_enctype_enable(context
, ETYPE_DES_CBC_CRC
);
202 krb5_enctype_enable(context
, ETYPE_DES_CBC_MD4
);
203 krb5_enctype_enable(context
, ETYPE_DES_CBC_MD5
);
204 krb5_enctype_enable(context
, ETYPE_DES_CBC_NONE
);
205 krb5_enctype_enable(context
, ETYPE_DES_CFB64_NONE
);
206 krb5_enctype_enable(context
, ETYPE_DES_PCBC_NONE
);
209 s
= krb5_config_get_strings(context
, NULL
, "logging", "krb5", NULL
);
212 krb5_initlog(context
, "libkrb5", &context
->debug_dest
);
214 krb5_addlog_dest(context
, context
->debug_dest
, *p
);
215 krb5_config_free_strings(s
);
222 static krb5_error_code
223 cc_ops_register(krb5_context context
)
225 context
->cc_ops
= NULL
;
226 context
->num_cc_ops
= 0;
228 #ifndef KCM_IS_API_CACHE
229 krb5_cc_register(context
, &krb5_acc_ops
, TRUE
);
231 krb5_cc_register(context
, &krb5_fcc_ops
, TRUE
);
232 krb5_cc_register(context
, &krb5_mcc_ops
, TRUE
);
234 krb5_cc_register(context
, &krb5_scc_ops
, TRUE
);
237 #ifdef KCM_IS_API_CACHE
238 krb5_cc_register(context
, &krb5_akcm_ops
, TRUE
);
240 krb5_cc_register(context
, &krb5_kcm_ops
, TRUE
);
245 static krb5_error_code
246 cc_ops_copy(krb5_context context
, const krb5_context src_context
)
248 krb5_cc_ops
**cc_ops
;
250 context
->cc_ops
= NULL
;
251 context
->num_cc_ops
= 0;
253 if (src_context
->num_cc_ops
== 0)
256 cc_ops
= malloc(sizeof(cc_ops
[0]) * src_context
->num_cc_ops
);
257 if (cc_ops
== NULL
) {
258 krb5_set_error_message(context
, KRB5_CC_NOMEM
,
259 N_("malloc: out of memory", ""));
260 return KRB5_CC_NOMEM
;
263 memcpy(cc_ops
, src_context
->cc_ops
,
264 sizeof(cc_ops
[0]) * src_context
->num_cc_ops
);
265 context
->cc_ops
= cc_ops
;
266 context
->num_cc_ops
= src_context
->num_cc_ops
;
271 static krb5_error_code
272 kt_ops_register(krb5_context context
)
274 context
->num_kt_types
= 0;
275 context
->kt_types
= NULL
;
277 krb5_kt_register (context
, &krb5_fkt_ops
);
278 krb5_kt_register (context
, &krb5_wrfkt_ops
);
279 krb5_kt_register (context
, &krb5_javakt_ops
);
280 krb5_kt_register (context
, &krb5_mkt_ops
);
281 #ifndef HEIMDAL_SMALLER
282 krb5_kt_register (context
, &krb5_akf_ops
);
284 krb5_kt_register (context
, &krb5_any_ops
);
288 static krb5_error_code
289 kt_ops_copy(krb5_context context
, const krb5_context src_context
)
291 context
->num_kt_types
= 0;
292 context
->kt_types
= NULL
;
294 if (src_context
->num_kt_types
== 0)
297 context
->kt_types
= malloc(sizeof(context
->kt_types
[0]) * src_context
->num_kt_types
);
298 if (context
->kt_types
== NULL
) {
299 krb5_set_error_message(context
, ENOMEM
,
300 N_("malloc: out of memory", ""));
304 context
->num_kt_types
= src_context
->num_kt_types
;
305 memcpy(context
->kt_types
, src_context
->kt_types
,
306 sizeof(context
->kt_types
[0]) * src_context
->num_kt_types
);
312 * Initializes the context structure and reads the configuration file
313 * /etc/krb5.conf. The structure should be freed by calling
314 * krb5_free_context() when it is no longer being used.
316 * @param context pointer to returned context
318 * @return Returns 0 to indicate success. Otherwise an errno code is
319 * returned. Failure means either that something bad happened during
320 * initialization (typically ENOMEM) or that Kerberos should not be
326 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
327 krb5_init_context(krb5_context
*context
)
335 /* should have a run_once */
336 bindtextdomain(HEIMDAL_TEXTDOMAIN
, HEIMDAL_LOCALEDIR
);
338 p
= calloc(1, sizeof(*p
));
342 p
->mutex
= malloc(sizeof(HEIMDAL_MUTEX
));
343 if (p
->mutex
== NULL
) {
347 HEIMDAL_MUTEX_init(p
->mutex
);
349 p
->flags
|= KRB5_CTX_F_HOMEDIR_ACCESS
;
351 ret
= krb5_get_default_config_files(&files
);
354 ret
= krb5_set_config_files(p
, files
);
355 krb5_free_config_files(files
);
359 /* init error tables */
365 ret
= hx509_context_init(&p
->hx509ctx
);
370 p
->flags
|= KRB5_CTX_F_SOCKETS_INITIALIZED
;
374 krb5_free_context(p
);
381 #ifndef HEIMDAL_SMALLER
387 static krb5_error_code
388 copy_etypes (krb5_context context
,
389 krb5_enctype
*enctypes
,
390 krb5_enctype
**ret_enctypes
)
394 for (i
= 0; enctypes
[i
]; i
++)
398 *ret_enctypes
= malloc(sizeof(ret_enctypes
[0]) * i
);
399 if (*ret_enctypes
== NULL
) {
400 krb5_set_error_message(context
, ENOMEM
,
401 N_("malloc: out of memory", ""));
404 memcpy(*ret_enctypes
, enctypes
, sizeof(ret_enctypes
[0]) * i
);
409 * Make a copy for the Kerberos 5 context, the new krb5_context shoud
410 * be freed with krb5_free_context().
412 * @param context the Kerberos context to copy
413 * @param out the copy of the Kerberos, set to NULL error.
415 * @return Returns 0 to indicate success. Otherwise an kerberos et
416 * error code is returned, see krb5_get_error_message().
421 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
422 krb5_copy_context(krb5_context context
, krb5_context
*out
)
429 p
= calloc(1, sizeof(*p
));
431 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
435 p
->mutex
= malloc(sizeof(HEIMDAL_MUTEX
));
436 if (p
->mutex
== NULL
) {
437 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
441 HEIMDAL_MUTEX_init(p
->mutex
);
444 if (context
->default_cc_name
)
445 p
->default_cc_name
= strdup(context
->default_cc_name
);
446 if (context
->default_cc_name_env
)
447 p
->default_cc_name_env
= strdup(context
->default_cc_name_env
);
449 if (context
->etypes
) {
450 ret
= copy_etypes(context
, context
->etypes
, &p
->etypes
);
454 if (context
->etypes_des
) {
455 ret
= copy_etypes(context
, context
->etypes_des
, &p
->etypes_des
);
460 if (context
->default_realms
) {
461 ret
= krb5_copy_host_realm(context
,
462 context
->default_realms
, &p
->default_realms
);
467 ret
= _krb5_config_copy(context
, context
->cf
, &p
->cf
);
471 /* XXX should copy */
474 cc_ops_copy(p
, context
);
475 kt_ops_copy(p
, context
);
478 if(context
->warn_dest
!= NULL
)
480 if(context
->debug_dest
!= NULL
)
484 ret
= krb5_set_extra_addresses(p
, context
->extra_addresses
);
487 ret
= krb5_set_extra_addresses(p
, context
->ignore_addresses
);
491 ret
= _krb5_copy_send_to_kdc_func(p
, context
);
500 krb5_free_context(p
);
507 * Frees the krb5_context allocated by krb5_init_context().
509 * @param context context to be freed.
514 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
515 krb5_free_context(krb5_context context
)
517 if (context
->default_cc_name
)
518 free(context
->default_cc_name
);
519 if (context
->default_cc_name_env
)
520 free(context
->default_cc_name_env
);
521 free(context
->etypes
);
522 free(context
->etypes_des
);
523 krb5_free_host_realm (context
, context
->default_realms
);
524 krb5_config_file_free (context
, context
->cf
);
525 free_error_table (context
->et_list
);
526 free(context
->cc_ops
);
527 free(context
->kt_types
);
528 krb5_clear_error_message(context
);
529 if(context
->warn_dest
!= NULL
)
530 krb5_closelog(context
, context
->warn_dest
);
531 if(context
->debug_dest
!= NULL
)
532 krb5_closelog(context
, context
->debug_dest
);
533 krb5_set_extra_addresses(context
, NULL
);
534 krb5_set_ignore_addresses(context
, NULL
);
535 krb5_set_send_to_kdc_func(context
, NULL
, NULL
);
538 hx509_context_free(&context
->hx509ctx
);
541 HEIMDAL_MUTEX_destroy(context
->mutex
);
542 free(context
->mutex
);
543 if (context
->flags
& KRB5_CTX_F_SOCKETS_INITIALIZED
) {
547 memset(context
, 0, sizeof(*context
));
552 * Reinit the context from a new set of filenames.
554 * @param context context to add configuration too.
555 * @param filenames array of filenames, end of list is indicated with a NULL filename.
557 * @return Returns 0 to indicate success. Otherwise an kerberos et
558 * error code is returned, see krb5_get_error_message().
563 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
564 krb5_set_config_files(krb5_context context
, char **filenames
)
567 krb5_config_binding
*tmp
= NULL
;
568 while(filenames
!= NULL
&& *filenames
!= NULL
&& **filenames
!= '\0') {
569 ret
= krb5_config_parse_file_multi(context
, *filenames
, &tmp
);
570 if(ret
!= 0 && ret
!= ENOENT
&& ret
!= EACCES
&& ret
!= EPERM
) {
571 krb5_config_file_free(context
, tmp
);
577 /* with this enabled and if there are no config files, Kerberos is
578 considererd disabled */
582 krb5_config_file_free(context
, context
->cf
);
584 ret
= init_context_from_config_file(context
);
588 static krb5_error_code
589 add_file(char ***pfilenames
, int *len
, char *file
)
591 char **pp
= *pfilenames
;
594 for(i
= 0; i
< *len
; i
++) {
595 if(strcmp(pp
[i
], file
) == 0) {
601 pp
= realloc(*pfilenames
, (*len
+ 2) * sizeof(*pp
));
615 * `pq' isn't free, it's up the the caller
618 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
619 krb5_prepend_config_files(const char *filelist
, char **pq
, char ***ret_pp
)
634 l
= strsep_copy(&q
, ":", NULL
, 0);
639 krb5_free_config_files(pp
);
642 (void)strsep_copy(&p
, ":", fn
, l
+ 1);
643 ret
= add_file(&pp
, &len
, fn
);
645 krb5_free_config_files(pp
);
653 for (i
= 0; pq
[i
] != NULL
; i
++) {
656 krb5_free_config_files(pp
);
659 ret
= add_file(&pp
, &len
, fn
);
661 krb5_free_config_files(pp
);
672 * Prepend the filename to the global configuration list.
674 * @param filelist a filename to add to the default list of filename
675 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
677 * @return Returns 0 to indicate success. Otherwise an kerberos et
678 * error code is returned, see krb5_get_error_message().
683 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
684 krb5_prepend_config_files_default(const char *filelist
, char ***pfilenames
)
687 char **defpp
, **pp
= NULL
;
689 ret
= krb5_get_default_config_files(&defpp
);
693 ret
= krb5_prepend_config_files(filelist
, defpp
, &pp
);
694 krb5_free_config_files(defpp
);
703 * Get the global configuration list.
705 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
707 * @return Returns 0 to indicate success. Otherwise an kerberos et
708 * error code is returned, see krb5_get_error_message().
713 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
714 krb5_get_default_config_files(char ***pfilenames
)
716 const char *files
= NULL
;
718 if (pfilenames
== NULL
)
721 files
= getenv("KRB5_CONFIG");
723 files
= krb5_config_file
;
725 return krb5_prepend_config_files(files
, NULL
, pfilenames
);
729 * Free a list of configuration files.
731 * @param filenames list, terminated with a NULL pointer, to be
732 * freed. NULL is an valid argument.
734 * @return Returns 0 to indicate success. Otherwise an kerberos et
735 * error code is returned, see krb5_get_error_message().
740 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
741 krb5_free_config_files(char **filenames
)
744 for(p
= filenames
; p
&& *p
!= NULL
; p
++)
750 * Returns the list of Kerberos encryption types sorted in order of
751 * most preferred to least preferred encryption type. Note that some
752 * encryption types might be disabled, so you need to check with
753 * krb5_enctype_valid() before using the encryption type.
755 * @return list of enctypes, terminated with ETYPE_NULL. Its a static
756 * array completed into the Kerberos library so the content doesn't
762 KRB5_LIB_FUNCTION
const krb5_enctype
* KRB5_LIB_CALL
763 krb5_kerberos_enctypes(krb5_context context
)
765 static const krb5_enctype p
[] = {
766 ETYPE_AES256_CTS_HMAC_SHA1_96
,
767 ETYPE_AES128_CTS_HMAC_SHA1_96
,
770 ETYPE_ARCFOUR_HMAC_MD5
,
780 * set `etype' to a malloced list of the default enctypes
783 static krb5_error_code
784 default_etypes(krb5_context context
, krb5_enctype
**etype
)
786 const krb5_enctype
*p
;
787 krb5_enctype
*e
= NULL
, *ep
;
790 p
= krb5_kerberos_enctypes(context
);
792 for (i
= 0; p
[i
] != ETYPE_NULL
; i
++) {
793 if (krb5_enctype_valid(context
, p
[i
]) != 0)
795 ep
= realloc(e
, (n
+ 2) * sizeof(*e
));
798 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
803 e
[n
+ 1] = ETYPE_NULL
;
811 * Set the default encryption types that will be use in communcation
812 * with the KDC, clients and servers.
814 * @param context Kerberos 5 context.
815 * @param etypes Encryption types, array terminated with ETYPE_NULL (0).
817 * @return Returns 0 to indicate success. Otherwise an kerberos et
818 * error code is returned, see krb5_get_error_message().
823 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
824 krb5_set_default_in_tkt_etypes(krb5_context context
,
825 const krb5_enctype
*etypes
)
827 krb5_enctype
*p
= NULL
;
831 for (i
= 0; etypes
[i
]; ++i
) {
833 ret
= krb5_enctype_valid(context
, etypes
[i
]);
840 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
843 memmove(p
, etypes
, i
* sizeof(krb5_enctype
));
846 free(context
->etypes
);
852 * Get the default encryption types that will be use in communcation
853 * with the KDC, clients and servers.
855 * @param context Kerberos 5 context.
856 * @param etypes Encryption types, array terminated with
857 * ETYPE_NULL(0), caller should free array with krb5_xfree():
859 * @return Returns 0 to indicate success. Otherwise an kerberos et
860 * error code is returned, see krb5_get_error_message().
865 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
866 krb5_get_default_in_tkt_etypes(krb5_context context
,
867 krb5_enctype
**etypes
)
873 if(context
->etypes
) {
874 for(i
= 0; context
->etypes
[i
]; i
++);
878 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
881 memmove(p
, context
->etypes
, i
* sizeof(krb5_enctype
));
883 ret
= default_etypes(context
, &p
);
892 * Init the built-in ets in the Kerberos library.
894 * @param context kerberos context to add the ets too
899 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
900 krb5_init_ets(krb5_context context
)
902 if(context
->et_list
== NULL
){
903 krb5_add_et_list(context
, initialize_krb5_error_table_r
);
904 krb5_add_et_list(context
, initialize_asn1_error_table_r
);
905 krb5_add_et_list(context
, initialize_heim_error_table_r
);
907 krb5_add_et_list(context
, initialize_k524_error_table_r
);
909 #ifdef COM_ERR_BINDDOMAIN_krb5
910 bindtextdomain(COM_ERR_BINDDOMAIN_krb5
, HEIMDAL_LOCALEDIR
);
911 bindtextdomain(COM_ERR_BINDDOMAIN_asn1
, HEIMDAL_LOCALEDIR
);
912 bindtextdomain(COM_ERR_BINDDOMAIN_heim
, HEIMDAL_LOCALEDIR
);
913 bindtextdomain(COM_ERR_BINDDOMAIN_k524
, HEIMDAL_LOCALEDIR
);
917 krb5_add_et_list(context
, initialize_hx_error_table_r
);
918 #ifdef COM_ERR_BINDDOMAIN_hx
919 bindtextdomain(COM_ERR_BINDDOMAIN_hx
, HEIMDAL_LOCALEDIR
);
926 * Make the kerberos library default to the admin KDC.
928 * @param context Kerberos 5 context.
929 * @param flag boolean flag to select if the use the admin KDC or not.
934 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
935 krb5_set_use_admin_kdc (krb5_context context
, krb5_boolean flag
)
937 context
->use_admin_kdc
= flag
;
941 * Make the kerberos library default to the admin KDC.
943 * @param context Kerberos 5 context.
945 * @return boolean flag to telling the context will use admin KDC as the default KDC.
950 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
951 krb5_get_use_admin_kdc (krb5_context context
)
953 return context
->use_admin_kdc
;
957 * Add extra address to the address list that the library will add to
958 * the client's address list when communicating with the KDC.
960 * @param context Kerberos 5 context.
961 * @param addresses addreses to add
963 * @return Returns 0 to indicate success. Otherwise an kerberos et
964 * error code is returned, see krb5_get_error_message().
969 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
970 krb5_add_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
973 if(context
->extra_addresses
)
974 return krb5_append_addresses(context
,
975 context
->extra_addresses
, addresses
);
977 return krb5_set_extra_addresses(context
, addresses
);
981 * Set extra address to the address list that the library will add to
982 * the client's address list when communicating with the KDC.
984 * @param context Kerberos 5 context.
985 * @param addresses addreses to set
987 * @return Returns 0 to indicate success. Otherwise an kerberos et
988 * error code is returned, see krb5_get_error_message().
993 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
994 krb5_set_extra_addresses(krb5_context context
, const krb5_addresses
*addresses
)
996 if(context
->extra_addresses
)
997 krb5_free_addresses(context
, context
->extra_addresses
);
999 if(addresses
== NULL
) {
1000 if(context
->extra_addresses
!= NULL
) {
1001 free(context
->extra_addresses
);
1002 context
->extra_addresses
= NULL
;
1006 if(context
->extra_addresses
== NULL
) {
1007 context
->extra_addresses
= malloc(sizeof(*context
->extra_addresses
));
1008 if(context
->extra_addresses
== NULL
) {
1009 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
1013 return krb5_copy_addresses(context
, addresses
, context
->extra_addresses
);
1017 * Get extra address to the address list that the library will add to
1018 * the client's address list when communicating with the KDC.
1020 * @param context Kerberos 5 context.
1021 * @param addresses addreses to set
1023 * @return Returns 0 to indicate success. Otherwise an kerberos et
1024 * error code is returned, see krb5_get_error_message().
1029 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1030 krb5_get_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
1032 if(context
->extra_addresses
== NULL
) {
1033 memset(addresses
, 0, sizeof(*addresses
));
1036 return krb5_copy_addresses(context
,context
->extra_addresses
, addresses
);
1040 * Add extra addresses to ignore when fetching addresses from the
1041 * underlaying operating system.
1043 * @param context Kerberos 5 context.
1044 * @param addresses addreses to ignore
1046 * @return Returns 0 to indicate success. Otherwise an kerberos et
1047 * error code is returned, see krb5_get_error_message().
1052 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1053 krb5_add_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1056 if(context
->ignore_addresses
)
1057 return krb5_append_addresses(context
,
1058 context
->ignore_addresses
, addresses
);
1060 return krb5_set_ignore_addresses(context
, addresses
);
1064 * Set extra addresses to ignore when fetching addresses from the
1065 * underlaying operating system.
1067 * @param context Kerberos 5 context.
1068 * @param addresses addreses to ignore
1070 * @return Returns 0 to indicate success. Otherwise an kerberos et
1071 * error code is returned, see krb5_get_error_message().
1076 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1077 krb5_set_ignore_addresses(krb5_context context
, const krb5_addresses
*addresses
)
1079 if(context
->ignore_addresses
)
1080 krb5_free_addresses(context
, context
->ignore_addresses
);
1081 if(addresses
== NULL
) {
1082 if(context
->ignore_addresses
!= NULL
) {
1083 free(context
->ignore_addresses
);
1084 context
->ignore_addresses
= NULL
;
1088 if(context
->ignore_addresses
== NULL
) {
1089 context
->ignore_addresses
= malloc(sizeof(*context
->ignore_addresses
));
1090 if(context
->ignore_addresses
== NULL
) {
1091 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
1095 return krb5_copy_addresses(context
, addresses
, context
->ignore_addresses
);
1099 * Get extra addresses to ignore when fetching addresses from the
1100 * underlaying operating system.
1102 * @param context Kerberos 5 context.
1103 * @param addresses list addreses ignored
1105 * @return Returns 0 to indicate success. Otherwise an kerberos et
1106 * error code is returned, see krb5_get_error_message().
1111 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1112 krb5_get_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1114 if(context
->ignore_addresses
== NULL
) {
1115 memset(addresses
, 0, sizeof(*addresses
));
1118 return krb5_copy_addresses(context
, context
->ignore_addresses
, addresses
);
1122 * Set version of fcache that the library should use.
1124 * @param context Kerberos 5 context.
1125 * @param version version number.
1127 * @return Returns 0 to indicate success. Otherwise an kerberos et
1128 * error code is returned, see krb5_get_error_message().
1133 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1134 krb5_set_fcache_version(krb5_context context
, int version
)
1136 context
->fcache_vno
= version
;
1141 * Get version of fcache that the library should use.
1143 * @param context Kerberos 5 context.
1144 * @param version version number.
1146 * @return Returns 0 to indicate success. Otherwise an kerberos et
1147 * error code is returned, see krb5_get_error_message().
1152 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1153 krb5_get_fcache_version(krb5_context context
, int *version
)
1155 *version
= context
->fcache_vno
;
1160 * Runtime check if the Kerberos library was complied with thread support.
1162 * @return TRUE if the library was compiled with thread support, FALSE if not.
1168 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
1169 krb5_is_thread_safe(void)
1171 #ifdef ENABLE_PTHREAD_SUPPORT
1179 * Set if the library should use DNS to canonicalize hostnames.
1181 * @param context Kerberos 5 context.
1182 * @param flag if its dns canonicalizion is used or not.
1187 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
1188 krb5_set_dns_canonicalize_hostname (krb5_context context
, krb5_boolean flag
)
1191 context
->flags
|= KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1193 context
->flags
&= ~KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1197 * Get if the library uses DNS to canonicalize hostnames.
1199 * @param context Kerberos 5 context.
1201 * @return return non zero if the library uses DNS to canonicalize hostnames.
1206 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
1207 krb5_get_dns_canonicalize_hostname (krb5_context context
)
1209 return (context
->flags
& KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
) ? 1 : 0;
1213 * Get current offset in time to the KDC.
1215 * @param context Kerberos 5 context.
1216 * @param sec seconds part of offset.
1217 * @param usec micro seconds part of offset.
1219 * @return returns zero
1224 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1225 krb5_get_kdc_sec_offset (krb5_context context
, int32_t *sec
, int32_t *usec
)
1228 *sec
= context
->kdc_sec_offset
;
1230 *usec
= context
->kdc_usec_offset
;
1235 * Set current offset in time to the KDC.
1237 * @param context Kerberos 5 context.
1238 * @param sec seconds part of offset.
1239 * @param usec micro seconds part of offset.
1241 * @return returns zero
1246 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1247 krb5_set_kdc_sec_offset (krb5_context context
, int32_t sec
, int32_t usec
)
1249 context
->kdc_sec_offset
= sec
;
1251 context
->kdc_usec_offset
= usec
;
1256 * Get max time skew allowed.
1258 * @param context Kerberos 5 context.
1260 * @return timeskew in seconds.
1265 KRB5_LIB_FUNCTION
time_t KRB5_LIB_CALL
1266 krb5_get_max_time_skew (krb5_context context
)
1268 return context
->max_skew
;
1272 * Set max time skew allowed.
1274 * @param context Kerberos 5 context.
1275 * @param t timeskew in seconds.
1280 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
1281 krb5_set_max_time_skew (krb5_context context
, time_t t
)
1283 context
->max_skew
= t
;
1287 * Init encryption types in len, val with etypes.
1289 * @param context Kerberos 5 context.
1290 * @param len output length of val.
1291 * @param val output array of enctypes.
1292 * @param etypes etypes to set val and len to, if NULL, use default enctypes.
1294 * @return Returns 0 to indicate success. Otherwise an kerberos et
1295 * error code is returned, see krb5_get_error_message().
1300 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1301 krb5_init_etype (krb5_context context
,
1304 const krb5_enctype
*etypes
)
1307 krb5_error_code ret
;
1308 krb5_enctype
*tmp
= NULL
;
1311 if (etypes
== NULL
) {
1312 ret
= krb5_get_default_in_tkt_etypes(context
, &tmp
);
1318 for (i
= 0; etypes
[i
]; ++i
)
1321 *val
= malloc(i
* sizeof(**val
));
1322 if (i
!= 0 && *val
== NULL
) {
1324 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", ""));
1337 * Allow homedir accces
1340 static HEIMDAL_MUTEX homedir_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
1341 static krb5_boolean allow_homedir
= TRUE
;
1344 _krb5_homedir_access(krb5_context context
)
1349 /* is never allowed for root */
1354 if (context
&& (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) == 0)
1357 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1358 allow
= allow_homedir
;
1359 HEIMDAL_MUTEX_unlock(&homedir_mutex
);
1364 * Enable and disable home directory access on either the global state
1365 * or the krb5_context state. By calling krb5_set_home_dir_access()
1366 * with context set to NULL, the global state is configured otherwise
1367 * the state for the krb5_context is modified.
1369 * For home directory access to be allowed, both the global state and
1370 * the krb5_context state have to be allowed.
1372 * Administrator (root user), never uses the home directory.
1374 * @param context a Kerberos 5 context or NULL
1375 * @param allow allow if TRUE home directory
1376 * @return the old value
1381 krb5_set_home_dir_access(krb5_context context
, krb5_boolean allow
)
1385 old
= (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) ? TRUE
: FALSE
;
1387 context
->flags
|= KRB5_CTX_F_HOMEDIR_ACCESS
;
1389 context
->flags
&= ~KRB5_CTX_F_HOMEDIR_ACCESS
;
1391 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1392 old
= allow_homedir
;
1393 allow_homedir
= allow
;
1394 HEIMDAL_MUTEX_unlock(&homedir_mutex
);