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 const 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 if (context
->hx509ctx
)
539 hx509_context_free(&context
->hx509ctx
);
542 HEIMDAL_MUTEX_destroy(context
->mutex
);
543 free(context
->mutex
);
544 if (context
->flags
& KRB5_CTX_F_SOCKETS_INITIALIZED
) {
548 memset(context
, 0, sizeof(*context
));
553 * Reinit the context from a new set of filenames.
555 * @param context context to add configuration too.
556 * @param filenames array of filenames, end of list is indicated with a NULL filename.
558 * @return Returns 0 to indicate success. Otherwise an kerberos et
559 * error code is returned, see krb5_get_error_message().
564 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
565 krb5_set_config_files(krb5_context context
, char **filenames
)
568 krb5_config_binding
*tmp
= NULL
;
569 while(filenames
!= NULL
&& *filenames
!= NULL
&& **filenames
!= '\0') {
570 ret
= krb5_config_parse_file_multi(context
, *filenames
, &tmp
);
571 if(ret
!= 0 && ret
!= ENOENT
&& ret
!= EACCES
&& ret
!= EPERM
) {
572 krb5_config_file_free(context
, tmp
);
578 /* with this enabled and if there are no config files, Kerberos is
579 considererd disabled */
583 krb5_config_file_free(context
, context
->cf
);
585 ret
= init_context_from_config_file(context
);
589 static krb5_error_code
590 add_file(char ***pfilenames
, int *len
, char *file
)
592 char **pp
= *pfilenames
;
595 for(i
= 0; i
< *len
; i
++) {
596 if(strcmp(pp
[i
], file
) == 0) {
602 pp
= realloc(*pfilenames
, (*len
+ 2) * sizeof(*pp
));
616 * `pq' isn't free, it's up the the caller
619 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
620 krb5_prepend_config_files(const char *filelist
, char **pq
, char ***ret_pp
)
635 l
= strsep_copy(&q
, ":", NULL
, 0);
640 krb5_free_config_files(pp
);
643 (void)strsep_copy(&p
, ":", fn
, l
+ 1);
644 ret
= add_file(&pp
, &len
, fn
);
646 krb5_free_config_files(pp
);
654 for (i
= 0; pq
[i
] != NULL
; i
++) {
657 krb5_free_config_files(pp
);
660 ret
= add_file(&pp
, &len
, fn
);
662 krb5_free_config_files(pp
);
673 * Prepend the filename to the global configuration list.
675 * @param filelist a filename to add to the default list of filename
676 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
678 * @return Returns 0 to indicate success. Otherwise an kerberos et
679 * error code is returned, see krb5_get_error_message().
684 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
685 krb5_prepend_config_files_default(const char *filelist
, char ***pfilenames
)
688 char **defpp
, **pp
= NULL
;
690 ret
= krb5_get_default_config_files(&defpp
);
694 ret
= krb5_prepend_config_files(filelist
, defpp
, &pp
);
695 krb5_free_config_files(defpp
);
704 * Get the global configuration list.
706 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
708 * @return Returns 0 to indicate success. Otherwise an kerberos et
709 * error code is returned, see krb5_get_error_message().
714 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
715 krb5_get_default_config_files(char ***pfilenames
)
717 const char *files
= NULL
;
719 if (pfilenames
== NULL
)
722 files
= getenv("KRB5_CONFIG");
724 files
= krb5_config_file
;
726 return krb5_prepend_config_files(files
, NULL
, pfilenames
);
730 * Free a list of configuration files.
732 * @param filenames list, terminated with a NULL pointer, to be
733 * freed. NULL is an valid argument.
735 * @return Returns 0 to indicate success. Otherwise an kerberos et
736 * error code is returned, see krb5_get_error_message().
741 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
742 krb5_free_config_files(char **filenames
)
745 for(p
= filenames
; p
&& *p
!= NULL
; p
++)
751 * Returns the list of Kerberos encryption types sorted in order of
752 * most preferred to least preferred encryption type. Note that some
753 * encryption types might be disabled, so you need to check with
754 * krb5_enctype_valid() before using the encryption type.
756 * @return list of enctypes, terminated with ETYPE_NULL. Its a static
757 * array completed into the Kerberos library so the content doesn't
763 KRB5_LIB_FUNCTION
const krb5_enctype
* KRB5_LIB_CALL
764 krb5_kerberos_enctypes(krb5_context context
)
766 static const krb5_enctype p
[] = {
767 ETYPE_AES256_CTS_HMAC_SHA1_96
,
768 ETYPE_AES128_CTS_HMAC_SHA1_96
,
771 ETYPE_ARCFOUR_HMAC_MD5
,
781 * set `etype' to a malloced list of the default enctypes
784 static krb5_error_code
785 default_etypes(krb5_context context
, krb5_enctype
**etype
)
787 const krb5_enctype
*p
;
788 krb5_enctype
*e
= NULL
, *ep
;
791 p
= krb5_kerberos_enctypes(context
);
793 for (i
= 0; p
[i
] != ETYPE_NULL
; i
++) {
794 if (krb5_enctype_valid(context
, p
[i
]) != 0)
796 ep
= realloc(e
, (n
+ 2) * sizeof(*e
));
799 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
804 e
[n
+ 1] = ETYPE_NULL
;
812 * Set the default encryption types that will be use in communcation
813 * with the KDC, clients and servers.
815 * @param context Kerberos 5 context.
816 * @param etypes Encryption types, array terminated with ETYPE_NULL (0).
818 * @return Returns 0 to indicate success. Otherwise an kerberos et
819 * error code is returned, see krb5_get_error_message().
824 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
825 krb5_set_default_in_tkt_etypes(krb5_context context
,
826 const krb5_enctype
*etypes
)
829 krb5_enctype
*p
= NULL
;
833 for (n
= 0; etypes
[n
]; n
++)
838 krb5_set_error_message (context
, ENOMEM
,
839 N_("malloc: out of memory", ""));
842 for (n
= 0, m
= 0; etypes
[n
]; n
++) {
843 ret
= krb5_enctype_valid(context
, etypes
[n
]);
851 krb5_set_error_message (context
, KRB5_PROG_ETYPE_NOSUPP
,
852 N_("no valid enctype set", ""));
853 return KRB5_PROG_ETYPE_NOSUPP
;
857 free(context
->etypes
);
863 * Get the default encryption types that will be use in communcation
864 * with the KDC, clients and servers.
866 * @param context Kerberos 5 context.
867 * @param etypes Encryption types, array terminated with
868 * ETYPE_NULL(0), caller should free array with krb5_xfree():
870 * @return Returns 0 to indicate success. Otherwise an kerberos et
871 * error code is returned, see krb5_get_error_message().
876 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
877 krb5_get_default_in_tkt_etypes(krb5_context context
,
878 krb5_enctype
**etypes
)
884 if(context
->etypes
) {
885 for(i
= 0; context
->etypes
[i
]; i
++);
889 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
892 memmove(p
, context
->etypes
, i
* sizeof(krb5_enctype
));
894 ret
= default_etypes(context
, &p
);
903 * Init the built-in ets in the Kerberos library.
905 * @param context kerberos context to add the ets too
910 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
911 krb5_init_ets(krb5_context context
)
913 if(context
->et_list
== NULL
){
914 krb5_add_et_list(context
, initialize_krb5_error_table_r
);
915 krb5_add_et_list(context
, initialize_asn1_error_table_r
);
916 krb5_add_et_list(context
, initialize_heim_error_table_r
);
918 krb5_add_et_list(context
, initialize_k524_error_table_r
);
920 #ifdef COM_ERR_BINDDOMAIN_krb5
921 bindtextdomain(COM_ERR_BINDDOMAIN_krb5
, HEIMDAL_LOCALEDIR
);
922 bindtextdomain(COM_ERR_BINDDOMAIN_asn1
, HEIMDAL_LOCALEDIR
);
923 bindtextdomain(COM_ERR_BINDDOMAIN_heim
, HEIMDAL_LOCALEDIR
);
924 bindtextdomain(COM_ERR_BINDDOMAIN_k524
, HEIMDAL_LOCALEDIR
);
928 krb5_add_et_list(context
, initialize_hx_error_table_r
);
929 #ifdef COM_ERR_BINDDOMAIN_hx
930 bindtextdomain(COM_ERR_BINDDOMAIN_hx
, HEIMDAL_LOCALEDIR
);
937 * Make the kerberos library default to the admin KDC.
939 * @param context Kerberos 5 context.
940 * @param flag boolean flag to select if the use the admin KDC or not.
945 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
946 krb5_set_use_admin_kdc (krb5_context context
, krb5_boolean flag
)
948 context
->use_admin_kdc
= flag
;
952 * Make the kerberos library default to the admin KDC.
954 * @param context Kerberos 5 context.
956 * @return boolean flag to telling the context will use admin KDC as the default KDC.
961 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
962 krb5_get_use_admin_kdc (krb5_context context
)
964 return context
->use_admin_kdc
;
968 * Add extra address to the address list that the library will add to
969 * the client's address list when communicating with the KDC.
971 * @param context Kerberos 5 context.
972 * @param addresses addreses to add
974 * @return Returns 0 to indicate success. Otherwise an kerberos et
975 * error code is returned, see krb5_get_error_message().
980 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
981 krb5_add_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
984 if(context
->extra_addresses
)
985 return krb5_append_addresses(context
,
986 context
->extra_addresses
, addresses
);
988 return krb5_set_extra_addresses(context
, addresses
);
992 * Set extra address to the address list that the library will add to
993 * the client's address list when communicating with the KDC.
995 * @param context Kerberos 5 context.
996 * @param addresses addreses to set
998 * @return Returns 0 to indicate success. Otherwise an kerberos et
999 * error code is returned, see krb5_get_error_message().
1004 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1005 krb5_set_extra_addresses(krb5_context context
, const krb5_addresses
*addresses
)
1007 if(context
->extra_addresses
)
1008 krb5_free_addresses(context
, context
->extra_addresses
);
1010 if(addresses
== NULL
) {
1011 if(context
->extra_addresses
!= NULL
) {
1012 free(context
->extra_addresses
);
1013 context
->extra_addresses
= NULL
;
1017 if(context
->extra_addresses
== NULL
) {
1018 context
->extra_addresses
= malloc(sizeof(*context
->extra_addresses
));
1019 if(context
->extra_addresses
== NULL
) {
1020 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
1024 return krb5_copy_addresses(context
, addresses
, context
->extra_addresses
);
1028 * Get extra address to the address list that the library will add to
1029 * the client's address list when communicating with the KDC.
1031 * @param context Kerberos 5 context.
1032 * @param addresses addreses to set
1034 * @return Returns 0 to indicate success. Otherwise an kerberos et
1035 * error code is returned, see krb5_get_error_message().
1040 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1041 krb5_get_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
1043 if(context
->extra_addresses
== NULL
) {
1044 memset(addresses
, 0, sizeof(*addresses
));
1047 return krb5_copy_addresses(context
,context
->extra_addresses
, addresses
);
1051 * Add extra addresses to ignore when fetching addresses from the
1052 * underlaying operating system.
1054 * @param context Kerberos 5 context.
1055 * @param addresses addreses to ignore
1057 * @return Returns 0 to indicate success. Otherwise an kerberos et
1058 * error code is returned, see krb5_get_error_message().
1063 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1064 krb5_add_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1067 if(context
->ignore_addresses
)
1068 return krb5_append_addresses(context
,
1069 context
->ignore_addresses
, addresses
);
1071 return krb5_set_ignore_addresses(context
, addresses
);
1075 * Set extra addresses to ignore when fetching addresses from the
1076 * underlaying operating system.
1078 * @param context Kerberos 5 context.
1079 * @param addresses addreses to ignore
1081 * @return Returns 0 to indicate success. Otherwise an kerberos et
1082 * error code is returned, see krb5_get_error_message().
1087 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1088 krb5_set_ignore_addresses(krb5_context context
, const krb5_addresses
*addresses
)
1090 if(context
->ignore_addresses
)
1091 krb5_free_addresses(context
, context
->ignore_addresses
);
1092 if(addresses
== NULL
) {
1093 if(context
->ignore_addresses
!= NULL
) {
1094 free(context
->ignore_addresses
);
1095 context
->ignore_addresses
= NULL
;
1099 if(context
->ignore_addresses
== NULL
) {
1100 context
->ignore_addresses
= malloc(sizeof(*context
->ignore_addresses
));
1101 if(context
->ignore_addresses
== NULL
) {
1102 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
1106 return krb5_copy_addresses(context
, addresses
, context
->ignore_addresses
);
1110 * Get extra addresses to ignore when fetching addresses from the
1111 * underlaying operating system.
1113 * @param context Kerberos 5 context.
1114 * @param addresses list addreses ignored
1116 * @return Returns 0 to indicate success. Otherwise an kerberos et
1117 * error code is returned, see krb5_get_error_message().
1122 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1123 krb5_get_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1125 if(context
->ignore_addresses
== NULL
) {
1126 memset(addresses
, 0, sizeof(*addresses
));
1129 return krb5_copy_addresses(context
, context
->ignore_addresses
, addresses
);
1133 * Set version of fcache that the library should use.
1135 * @param context Kerberos 5 context.
1136 * @param version version number.
1138 * @return Returns 0 to indicate success. Otherwise an kerberos et
1139 * error code is returned, see krb5_get_error_message().
1144 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1145 krb5_set_fcache_version(krb5_context context
, int version
)
1147 context
->fcache_vno
= version
;
1152 * Get version of fcache that the library should use.
1154 * @param context Kerberos 5 context.
1155 * @param version version number.
1157 * @return Returns 0 to indicate success. Otherwise an kerberos et
1158 * error code is returned, see krb5_get_error_message().
1163 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1164 krb5_get_fcache_version(krb5_context context
, int *version
)
1166 *version
= context
->fcache_vno
;
1171 * Runtime check if the Kerberos library was complied with thread support.
1173 * @return TRUE if the library was compiled with thread support, FALSE if not.
1179 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
1180 krb5_is_thread_safe(void)
1182 #ifdef ENABLE_PTHREAD_SUPPORT
1190 * Set if the library should use DNS to canonicalize hostnames.
1192 * @param context Kerberos 5 context.
1193 * @param flag if its dns canonicalizion is used or not.
1198 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
1199 krb5_set_dns_canonicalize_hostname (krb5_context context
, krb5_boolean flag
)
1202 context
->flags
|= KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1204 context
->flags
&= ~KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1208 * Get if the library uses DNS to canonicalize hostnames.
1210 * @param context Kerberos 5 context.
1212 * @return return non zero if the library uses DNS to canonicalize hostnames.
1217 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
1218 krb5_get_dns_canonicalize_hostname (krb5_context context
)
1220 return (context
->flags
& KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
) ? 1 : 0;
1224 * Get current offset in time to the KDC.
1226 * @param context Kerberos 5 context.
1227 * @param sec seconds part of offset.
1228 * @param usec micro seconds part of offset.
1230 * @return returns zero
1235 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1236 krb5_get_kdc_sec_offset (krb5_context context
, int32_t *sec
, int32_t *usec
)
1239 *sec
= context
->kdc_sec_offset
;
1241 *usec
= context
->kdc_usec_offset
;
1246 * Set current offset in time to the KDC.
1248 * @param context Kerberos 5 context.
1249 * @param sec seconds part of offset.
1250 * @param usec micro seconds part of offset.
1252 * @return returns zero
1257 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1258 krb5_set_kdc_sec_offset (krb5_context context
, int32_t sec
, int32_t usec
)
1260 context
->kdc_sec_offset
= sec
;
1262 context
->kdc_usec_offset
= usec
;
1267 * Get max time skew allowed.
1269 * @param context Kerberos 5 context.
1271 * @return timeskew in seconds.
1276 KRB5_LIB_FUNCTION
time_t KRB5_LIB_CALL
1277 krb5_get_max_time_skew (krb5_context context
)
1279 return context
->max_skew
;
1283 * Set max time skew allowed.
1285 * @param context Kerberos 5 context.
1286 * @param t timeskew in seconds.
1291 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
1292 krb5_set_max_time_skew (krb5_context context
, time_t t
)
1294 context
->max_skew
= t
;
1298 * Init encryption types in len, val with etypes.
1300 * @param context Kerberos 5 context.
1301 * @param len output length of val.
1302 * @param val output array of enctypes.
1303 * @param etypes etypes to set val and len to, if NULL, use default enctypes.
1305 * @return Returns 0 to indicate success. Otherwise an kerberos et
1306 * error code is returned, see krb5_get_error_message().
1311 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1312 krb5_init_etype (krb5_context context
,
1315 const krb5_enctype
*etypes
)
1318 krb5_error_code ret
;
1319 krb5_enctype
*tmp
= NULL
;
1322 if (etypes
== NULL
) {
1323 ret
= krb5_get_default_in_tkt_etypes(context
, &tmp
);
1329 for (i
= 0; etypes
[i
]; ++i
)
1332 *val
= malloc(i
* sizeof(**val
));
1333 if (i
!= 0 && *val
== NULL
) {
1335 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", ""));
1348 * Allow homedir accces
1351 static HEIMDAL_MUTEX homedir_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
1352 static krb5_boolean allow_homedir
= TRUE
;
1355 _krb5_homedir_access(krb5_context context
)
1360 /* is never allowed for root */
1365 if (context
&& (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) == 0)
1368 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1369 allow
= allow_homedir
;
1370 HEIMDAL_MUTEX_unlock(&homedir_mutex
);
1375 * Enable and disable home directory access on either the global state
1376 * or the krb5_context state. By calling krb5_set_home_dir_access()
1377 * with context set to NULL, the global state is configured otherwise
1378 * the state for the krb5_context is modified.
1380 * For home directory access to be allowed, both the global state and
1381 * the krb5_context state have to be allowed.
1383 * Administrator (root user), never uses the home directory.
1385 * @param context a Kerberos 5 context or NULL
1386 * @param allow allow if TRUE home directory
1387 * @return the old value
1393 krb5_set_home_dir_access(krb5_context context
, krb5_boolean allow
)
1397 old
= (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) ? TRUE
: FALSE
;
1399 context
->flags
|= KRB5_CTX_F_HOMEDIR_ACCESS
;
1401 context
->flags
&= ~KRB5_CTX_F_HOMEDIR_ACCESS
;
1403 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1404 old
= allow_homedir
;
1405 allow_homedir
= allow
;
1406 HEIMDAL_MUTEX_unlock(&homedir_mutex
);