2 * Copyright (c) 1997 - 2010 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
= krb5_config_get_bool_default(context
, NULL
, FALSE
,
109 "allow_weak_crypto", NULL
);
111 krb5_enctype_enable(context
, ETYPE_DES_CBC_CRC
);
112 krb5_enctype_enable(context
, ETYPE_DES_CBC_MD4
);
113 krb5_enctype_enable(context
, ETYPE_DES_CBC_MD5
);
114 krb5_enctype_enable(context
, ETYPE_DES_CBC_NONE
);
115 krb5_enctype_enable(context
, ETYPE_DES_CFB64_NONE
);
116 krb5_enctype_enable(context
, ETYPE_DES_PCBC_NONE
);
119 ret
= set_etypes (context
, "default_etypes", &tmptypes
);
122 free(context
->etypes
);
123 context
->etypes
= tmptypes
;
125 ret
= set_etypes (context
, "default_etypes_des", &tmptypes
);
128 free(context
->etypes_des
);
129 context
->etypes_des
= tmptypes
;
131 /* default keytab name */
134 tmp
= getenv("KRB5_KTNAME");
136 context
->default_keytab
= tmp
;
138 INIT_FIELD(context
, string
, default_keytab
,
139 KEYTAB_DEFAULT
, "default_keytab_name");
141 INIT_FIELD(context
, string
, default_keytab_modify
,
142 NULL
, "default_keytab_modify_name");
144 INIT_FIELD(context
, string
, time_fmt
,
145 "%Y-%m-%dT%H:%M:%S", "time_format");
147 INIT_FIELD(context
, string
, date_fmt
,
148 "%Y-%m-%d", "date_format");
150 INIT_FIELD(context
, bool, log_utc
,
155 /* init dns-proxy slime */
156 tmp
= krb5_config_get_string(context
, NULL
, "libdefaults",
159 roken_gethostby_setup(context
->http_proxy
, tmp
);
160 krb5_free_host_realm (context
, context
->default_realms
);
161 context
->default_realms
= NULL
;
164 krb5_addresses addresses
;
167 krb5_set_extra_addresses(context
, NULL
);
168 adr
= krb5_config_get_strings(context
, NULL
,
172 memset(&addresses
, 0, sizeof(addresses
));
173 for(a
= adr
; a
&& *a
; a
++) {
174 ret
= krb5_parse_address(context
, *a
, &addresses
);
176 krb5_add_extra_addresses(context
, &addresses
);
177 krb5_free_addresses(context
, &addresses
);
180 krb5_config_free_strings(adr
);
182 krb5_set_ignore_addresses(context
, NULL
);
183 adr
= krb5_config_get_strings(context
, NULL
,
187 memset(&addresses
, 0, sizeof(addresses
));
188 for(a
= adr
; a
&& *a
; a
++) {
189 ret
= krb5_parse_address(context
, *a
, &addresses
);
191 krb5_add_ignore_addresses(context
, &addresses
);
192 krb5_free_addresses(context
, &addresses
);
195 krb5_config_free_strings(adr
);
198 INIT_FIELD(context
, bool, scan_interfaces
, TRUE
, "scan_interfaces");
199 INIT_FIELD(context
, int, fcache_vno
, 0, "fcache_version");
200 /* prefer dns_lookup_kdc over srv_lookup. */
201 INIT_FIELD(context
, bool, srv_lookup
, TRUE
, "srv_lookup");
202 INIT_FIELD(context
, bool, srv_lookup
, context
->srv_lookup
, "dns_lookup_kdc");
203 INIT_FIELD(context
, int, large_msg_size
, 1400, "large_message_size");
204 INIT_FLAG(context
, flags
, KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
, TRUE
, "dns_canonicalize_hostname");
205 INIT_FLAG(context
, flags
, KRB5_CTX_F_CHECK_PAC
, TRUE
, "check_pac");
206 context
->default_cc_name
= NULL
;
207 context
->default_cc_name_set
= 0;
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
);
218 tmp
= krb5_config_get_string(context
, NULL
, "libdefaults",
219 "check-rd-req-server", NULL
);
220 if (tmp
== NULL
&& !issuid())
221 tmp
= getenv("KRB5_CHECK_RD_REQ_SERVER");
223 if (strcasecmp(tmp
, "ignore") == 0)
224 context
->flags
|= KRB5_CTX_F_RD_REQ_IGNORE
;
230 static krb5_error_code
231 cc_ops_register(krb5_context context
)
233 context
->cc_ops
= NULL
;
234 context
->num_cc_ops
= 0;
236 #ifndef KCM_IS_API_CACHE
237 krb5_cc_register(context
, &krb5_acc_ops
, TRUE
);
239 krb5_cc_register(context
, &krb5_fcc_ops
, TRUE
);
240 krb5_cc_register(context
, &krb5_mcc_ops
, TRUE
);
242 krb5_cc_register(context
, &krb5_scc_ops
, TRUE
);
245 #ifdef KCM_IS_API_CACHE
246 krb5_cc_register(context
, &krb5_akcm_ops
, TRUE
);
248 krb5_cc_register(context
, &krb5_kcm_ops
, TRUE
);
250 _krb5_load_ccache_plugins(context
);
254 static krb5_error_code
255 cc_ops_copy(krb5_context context
, const krb5_context src_context
)
257 const krb5_cc_ops
**cc_ops
;
259 context
->cc_ops
= NULL
;
260 context
->num_cc_ops
= 0;
262 if (src_context
->num_cc_ops
== 0)
265 cc_ops
= malloc(sizeof(cc_ops
[0]) * src_context
->num_cc_ops
);
266 if (cc_ops
== NULL
) {
267 krb5_set_error_message(context
, KRB5_CC_NOMEM
,
268 N_("malloc: out of memory", ""));
269 return KRB5_CC_NOMEM
;
272 memcpy(cc_ops
, src_context
->cc_ops
,
273 sizeof(cc_ops
[0]) * src_context
->num_cc_ops
);
274 context
->cc_ops
= cc_ops
;
275 context
->num_cc_ops
= src_context
->num_cc_ops
;
280 static krb5_error_code
281 kt_ops_register(krb5_context context
)
283 context
->num_kt_types
= 0;
284 context
->kt_types
= NULL
;
286 krb5_kt_register (context
, &krb5_fkt_ops
);
287 krb5_kt_register (context
, &krb5_wrfkt_ops
);
288 krb5_kt_register (context
, &krb5_javakt_ops
);
289 krb5_kt_register (context
, &krb5_mkt_ops
);
290 #ifndef HEIMDAL_SMALLER
291 krb5_kt_register (context
, &krb5_akf_ops
);
293 krb5_kt_register (context
, &krb5_any_ops
);
297 static krb5_error_code
298 kt_ops_copy(krb5_context context
, const krb5_context src_context
)
300 context
->num_kt_types
= 0;
301 context
->kt_types
= NULL
;
303 if (src_context
->num_kt_types
== 0)
306 context
->kt_types
= malloc(sizeof(context
->kt_types
[0]) * src_context
->num_kt_types
);
307 if (context
->kt_types
== NULL
) {
308 krb5_set_error_message(context
, ENOMEM
,
309 N_("malloc: out of memory", ""));
313 context
->num_kt_types
= src_context
->num_kt_types
;
314 memcpy(context
->kt_types
, src_context
->kt_types
,
315 sizeof(context
->kt_types
[0]) * src_context
->num_kt_types
);
321 * Initializes the context structure and reads the configuration file
322 * /etc/krb5.conf. The structure should be freed by calling
323 * krb5_free_context() when it is no longer being used.
325 * @param context pointer to returned context
327 * @return Returns 0 to indicate success. Otherwise an errno code is
328 * returned. Failure means either that something bad happened during
329 * initialization (typically ENOMEM) or that Kerberos should not be
335 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
336 krb5_init_context(krb5_context
*context
)
344 /* should have a run_once */
345 bindtextdomain(HEIMDAL_TEXTDOMAIN
, HEIMDAL_LOCALEDIR
);
347 p
= calloc(1, sizeof(*p
));
351 p
->mutex
= malloc(sizeof(HEIMDAL_MUTEX
));
352 if (p
->mutex
== NULL
) {
356 HEIMDAL_MUTEX_init(p
->mutex
);
358 p
->flags
|= KRB5_CTX_F_HOMEDIR_ACCESS
;
360 ret
= krb5_get_default_config_files(&files
);
363 ret
= krb5_set_config_files(p
, files
);
364 krb5_free_config_files(files
);
368 /* init error tables */
374 ret
= hx509_context_init(&p
->hx509ctx
);
379 p
->flags
|= KRB5_CTX_F_SOCKETS_INITIALIZED
;
383 krb5_free_context(p
);
390 #ifndef HEIMDAL_SMALLER
392 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
393 krb5_get_permitted_enctypes(krb5_context context
,
394 krb5_enctype
**etypes
)
396 return krb5_get_default_in_tkt_etypes(context
, etypes
);
403 static krb5_error_code
404 copy_etypes (krb5_context context
,
405 krb5_enctype
*enctypes
,
406 krb5_enctype
**ret_enctypes
)
410 for (i
= 0; enctypes
[i
]; i
++)
414 *ret_enctypes
= malloc(sizeof(ret_enctypes
[0]) * i
);
415 if (*ret_enctypes
== NULL
) {
416 krb5_set_error_message(context
, ENOMEM
,
417 N_("malloc: out of memory", ""));
420 memcpy(*ret_enctypes
, enctypes
, sizeof(ret_enctypes
[0]) * i
);
425 * Make a copy for the Kerberos 5 context, the new krb5_context shoud
426 * be freed with krb5_free_context().
428 * @param context the Kerberos context to copy
429 * @param out the copy of the Kerberos, set to NULL error.
431 * @return Returns 0 to indicate success. Otherwise an kerberos et
432 * error code is returned, see krb5_get_error_message().
437 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
438 krb5_copy_context(krb5_context context
, krb5_context
*out
)
445 p
= calloc(1, sizeof(*p
));
447 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
451 p
->mutex
= malloc(sizeof(HEIMDAL_MUTEX
));
452 if (p
->mutex
== NULL
) {
453 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
457 HEIMDAL_MUTEX_init(p
->mutex
);
460 if (context
->default_cc_name
)
461 p
->default_cc_name
= strdup(context
->default_cc_name
);
462 if (context
->default_cc_name_env
)
463 p
->default_cc_name_env
= strdup(context
->default_cc_name_env
);
465 if (context
->etypes
) {
466 ret
= copy_etypes(context
, context
->etypes
, &p
->etypes
);
470 if (context
->etypes_des
) {
471 ret
= copy_etypes(context
, context
->etypes_des
, &p
->etypes_des
);
476 if (context
->default_realms
) {
477 ret
= krb5_copy_host_realm(context
,
478 context
->default_realms
, &p
->default_realms
);
483 ret
= _krb5_config_copy(context
, context
->cf
, &p
->cf
);
487 /* XXX should copy */
490 cc_ops_copy(p
, context
);
491 kt_ops_copy(p
, context
);
494 if(context
->warn_dest
!= NULL
)
496 if(context
->debug_dest
!= NULL
)
500 ret
= krb5_set_extra_addresses(p
, context
->extra_addresses
);
503 ret
= krb5_set_extra_addresses(p
, context
->ignore_addresses
);
507 ret
= _krb5_copy_send_to_kdc_func(p
, context
);
516 krb5_free_context(p
);
523 * Frees the krb5_context allocated by krb5_init_context().
525 * @param context context to be freed.
530 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
531 krb5_free_context(krb5_context context
)
533 if (context
->default_cc_name
)
534 free(context
->default_cc_name
);
535 if (context
->default_cc_name_env
)
536 free(context
->default_cc_name_env
);
537 free(context
->etypes
);
538 free(context
->etypes_des
);
539 krb5_free_host_realm (context
, context
->default_realms
);
540 krb5_config_file_free (context
, context
->cf
);
541 free_error_table (context
->et_list
);
542 free(context
->cc_ops
);
543 free(context
->kt_types
);
544 krb5_clear_error_message(context
);
545 if(context
->warn_dest
!= NULL
)
546 krb5_closelog(context
, context
->warn_dest
);
547 if(context
->debug_dest
!= NULL
)
548 krb5_closelog(context
, context
->debug_dest
);
549 krb5_set_extra_addresses(context
, NULL
);
550 krb5_set_ignore_addresses(context
, NULL
);
551 krb5_set_send_to_kdc_func(context
, NULL
, NULL
);
554 if (context
->hx509ctx
)
555 hx509_context_free(&context
->hx509ctx
);
558 HEIMDAL_MUTEX_destroy(context
->mutex
);
559 free(context
->mutex
);
560 if (context
->flags
& KRB5_CTX_F_SOCKETS_INITIALIZED
) {
564 memset(context
, 0, sizeof(*context
));
569 * Reinit the context from a new set of filenames.
571 * @param context context to add configuration too.
572 * @param filenames array of filenames, end of list is indicated with a NULL filename.
574 * @return Returns 0 to indicate success. Otherwise an kerberos et
575 * error code is returned, see krb5_get_error_message().
580 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
581 krb5_set_config_files(krb5_context context
, char **filenames
)
584 krb5_config_binding
*tmp
= NULL
;
585 while(filenames
!= NULL
&& *filenames
!= NULL
&& **filenames
!= '\0') {
586 ret
= krb5_config_parse_file_multi(context
, *filenames
, &tmp
);
587 if(ret
!= 0 && ret
!= ENOENT
&& ret
!= EACCES
&& ret
!= EPERM
) {
588 krb5_config_file_free(context
, tmp
);
594 /* with this enabled and if there are no config files, Kerberos is
595 considererd disabled */
599 krb5_config_file_free(context
, context
->cf
);
601 ret
= init_context_from_config_file(context
);
605 static krb5_error_code
606 add_file(char ***pfilenames
, int *len
, char *file
)
608 char **pp
= *pfilenames
;
611 for(i
= 0; i
< *len
; i
++) {
612 if(strcmp(pp
[i
], file
) == 0) {
618 pp
= realloc(*pfilenames
, (*len
+ 2) * sizeof(*pp
));
632 * `pq' isn't free, it's up the the caller
635 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
636 krb5_prepend_config_files(const char *filelist
, char **pq
, char ***ret_pp
)
651 l
= strsep_copy(&q
, ":", NULL
, 0);
656 krb5_free_config_files(pp
);
659 (void)strsep_copy(&p
, ":", fn
, l
+ 1);
660 ret
= add_file(&pp
, &len
, fn
);
662 krb5_free_config_files(pp
);
670 for (i
= 0; pq
[i
] != NULL
; i
++) {
673 krb5_free_config_files(pp
);
676 ret
= add_file(&pp
, &len
, fn
);
678 krb5_free_config_files(pp
);
689 * Prepend the filename to the global configuration list.
691 * @param filelist a filename to add to the default list of filename
692 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
694 * @return Returns 0 to indicate success. Otherwise an kerberos et
695 * error code is returned, see krb5_get_error_message().
700 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
701 krb5_prepend_config_files_default(const char *filelist
, char ***pfilenames
)
704 char **defpp
, **pp
= NULL
;
706 ret
= krb5_get_default_config_files(&defpp
);
710 ret
= krb5_prepend_config_files(filelist
, defpp
, &pp
);
711 krb5_free_config_files(defpp
);
720 * Get the global configuration list.
722 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
724 * @return Returns 0 to indicate success. Otherwise an kerberos et
725 * error code is returned, see krb5_get_error_message().
730 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
731 krb5_get_default_config_files(char ***pfilenames
)
733 const char *files
= NULL
;
735 if (pfilenames
== NULL
)
738 files
= getenv("KRB5_CONFIG");
740 files
= krb5_config_file
;
742 return krb5_prepend_config_files(files
, NULL
, pfilenames
);
746 * Free a list of configuration files.
748 * @param filenames list, terminated with a NULL pointer, to be
749 * freed. NULL is an valid argument.
751 * @return Returns 0 to indicate success. Otherwise an kerberos et
752 * error code is returned, see krb5_get_error_message().
757 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
758 krb5_free_config_files(char **filenames
)
761 for(p
= filenames
; p
&& *p
!= NULL
; p
++)
767 * Returns the list of Kerberos encryption types sorted in order of
768 * most preferred to least preferred encryption type. Note that some
769 * encryption types might be disabled, so you need to check with
770 * krb5_enctype_valid() before using the encryption type.
772 * @return list of enctypes, terminated with ETYPE_NULL. Its a static
773 * array completed into the Kerberos library so the content doesn't
779 KRB5_LIB_FUNCTION
const krb5_enctype
* KRB5_LIB_CALL
780 krb5_kerberos_enctypes(krb5_context context
)
782 static const krb5_enctype p
[] = {
783 ETYPE_AES256_CTS_HMAC_SHA1_96
,
784 ETYPE_AES128_CTS_HMAC_SHA1_96
,
787 ETYPE_ARCFOUR_HMAC_MD5
,
797 * set `etype' to a malloced list of the default enctypes
800 static krb5_error_code
801 default_etypes(krb5_context context
, krb5_enctype
**etype
)
803 const krb5_enctype
*p
;
804 krb5_enctype
*e
= NULL
, *ep
;
807 p
= krb5_kerberos_enctypes(context
);
809 for (i
= 0; p
[i
] != ETYPE_NULL
; i
++) {
810 if (krb5_enctype_valid(context
, p
[i
]) != 0)
812 ep
= realloc(e
, (n
+ 2) * sizeof(*e
));
815 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
820 e
[n
+ 1] = ETYPE_NULL
;
828 * Set the default encryption types that will be use in communcation
829 * with the KDC, clients and servers.
831 * @param context Kerberos 5 context.
832 * @param etypes Encryption types, array terminated with ETYPE_NULL (0).
834 * @return Returns 0 to indicate success. Otherwise an kerberos et
835 * error code is returned, see krb5_get_error_message().
840 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
841 krb5_set_default_in_tkt_etypes(krb5_context context
,
842 const krb5_enctype
*etypes
)
845 krb5_enctype
*p
= NULL
;
849 for (n
= 0; etypes
[n
]; n
++)
854 krb5_set_error_message (context
, ENOMEM
,
855 N_("malloc: out of memory", ""));
858 for (n
= 0, m
= 0; etypes
[n
]; n
++) {
859 ret
= krb5_enctype_valid(context
, etypes
[n
]);
867 krb5_set_error_message (context
, KRB5_PROG_ETYPE_NOSUPP
,
868 N_("no valid enctype set", ""));
869 return KRB5_PROG_ETYPE_NOSUPP
;
873 free(context
->etypes
);
879 * Get the default encryption types that will be use in communcation
880 * with the KDC, clients and servers.
882 * @param context Kerberos 5 context.
883 * @param etypes Encryption types, array terminated with
884 * ETYPE_NULL(0), caller should free array with krb5_xfree():
886 * @return Returns 0 to indicate success. Otherwise an kerberos et
887 * error code is returned, see krb5_get_error_message().
892 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
893 krb5_get_default_in_tkt_etypes(krb5_context context
,
894 krb5_enctype
**etypes
)
900 if(context
->etypes
) {
901 for(i
= 0; context
->etypes
[i
]; i
++);
905 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
908 memmove(p
, context
->etypes
, i
* sizeof(krb5_enctype
));
910 ret
= default_etypes(context
, &p
);
919 * Init the built-in ets in the Kerberos library.
921 * @param context kerberos context to add the ets too
926 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
927 krb5_init_ets(krb5_context context
)
929 if(context
->et_list
== NULL
){
930 krb5_add_et_list(context
, initialize_krb5_error_table_r
);
931 krb5_add_et_list(context
, initialize_asn1_error_table_r
);
932 krb5_add_et_list(context
, initialize_heim_error_table_r
);
934 krb5_add_et_list(context
, initialize_k524_error_table_r
);
936 #ifdef COM_ERR_BINDDOMAIN_krb5
937 bindtextdomain(COM_ERR_BINDDOMAIN_krb5
, HEIMDAL_LOCALEDIR
);
938 bindtextdomain(COM_ERR_BINDDOMAIN_asn1
, HEIMDAL_LOCALEDIR
);
939 bindtextdomain(COM_ERR_BINDDOMAIN_heim
, HEIMDAL_LOCALEDIR
);
940 bindtextdomain(COM_ERR_BINDDOMAIN_k524
, HEIMDAL_LOCALEDIR
);
944 krb5_add_et_list(context
, initialize_hx_error_table_r
);
945 #ifdef COM_ERR_BINDDOMAIN_hx
946 bindtextdomain(COM_ERR_BINDDOMAIN_hx
, HEIMDAL_LOCALEDIR
);
953 * Make the kerberos library default to the admin KDC.
955 * @param context Kerberos 5 context.
956 * @param flag boolean flag to select if the use the admin KDC or not.
961 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
962 krb5_set_use_admin_kdc (krb5_context context
, krb5_boolean flag
)
964 context
->use_admin_kdc
= flag
;
968 * Make the kerberos library default to the admin KDC.
970 * @param context Kerberos 5 context.
972 * @return boolean flag to telling the context will use admin KDC as the default KDC.
977 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
978 krb5_get_use_admin_kdc (krb5_context context
)
980 return context
->use_admin_kdc
;
984 * Add extra address to the address list that the library will add to
985 * the client's address list when communicating with the KDC.
987 * @param context Kerberos 5 context.
988 * @param addresses addreses to add
990 * @return Returns 0 to indicate success. Otherwise an kerberos et
991 * error code is returned, see krb5_get_error_message().
996 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
997 krb5_add_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
1000 if(context
->extra_addresses
)
1001 return krb5_append_addresses(context
,
1002 context
->extra_addresses
, addresses
);
1004 return krb5_set_extra_addresses(context
, addresses
);
1008 * Set extra address to the address list that the library will add to
1009 * the client's address list when communicating with the KDC.
1011 * @param context Kerberos 5 context.
1012 * @param addresses addreses to set
1014 * @return Returns 0 to indicate success. Otherwise an kerberos et
1015 * error code is returned, see krb5_get_error_message().
1020 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1021 krb5_set_extra_addresses(krb5_context context
, const krb5_addresses
*addresses
)
1023 if(context
->extra_addresses
)
1024 krb5_free_addresses(context
, context
->extra_addresses
);
1026 if(addresses
== NULL
) {
1027 if(context
->extra_addresses
!= NULL
) {
1028 free(context
->extra_addresses
);
1029 context
->extra_addresses
= NULL
;
1033 if(context
->extra_addresses
== NULL
) {
1034 context
->extra_addresses
= malloc(sizeof(*context
->extra_addresses
));
1035 if(context
->extra_addresses
== NULL
) {
1036 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
1040 return krb5_copy_addresses(context
, addresses
, context
->extra_addresses
);
1044 * Get extra address to the address list that the library will add to
1045 * the client's address list when communicating with the KDC.
1047 * @param context Kerberos 5 context.
1048 * @param addresses addreses to set
1050 * @return Returns 0 to indicate success. Otherwise an kerberos et
1051 * error code is returned, see krb5_get_error_message().
1056 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1057 krb5_get_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
1059 if(context
->extra_addresses
== NULL
) {
1060 memset(addresses
, 0, sizeof(*addresses
));
1063 return krb5_copy_addresses(context
,context
->extra_addresses
, addresses
);
1067 * Add extra addresses to ignore when fetching addresses from the
1068 * underlaying operating system.
1070 * @param context Kerberos 5 context.
1071 * @param addresses addreses to ignore
1073 * @return Returns 0 to indicate success. Otherwise an kerberos et
1074 * error code is returned, see krb5_get_error_message().
1079 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1080 krb5_add_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1083 if(context
->ignore_addresses
)
1084 return krb5_append_addresses(context
,
1085 context
->ignore_addresses
, addresses
);
1087 return krb5_set_ignore_addresses(context
, addresses
);
1091 * Set extra addresses to ignore when fetching addresses from the
1092 * underlaying operating system.
1094 * @param context Kerberos 5 context.
1095 * @param addresses addreses to ignore
1097 * @return Returns 0 to indicate success. Otherwise an kerberos et
1098 * error code is returned, see krb5_get_error_message().
1103 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1104 krb5_set_ignore_addresses(krb5_context context
, const krb5_addresses
*addresses
)
1106 if(context
->ignore_addresses
)
1107 krb5_free_addresses(context
, context
->ignore_addresses
);
1108 if(addresses
== NULL
) {
1109 if(context
->ignore_addresses
!= NULL
) {
1110 free(context
->ignore_addresses
);
1111 context
->ignore_addresses
= NULL
;
1115 if(context
->ignore_addresses
== NULL
) {
1116 context
->ignore_addresses
= malloc(sizeof(*context
->ignore_addresses
));
1117 if(context
->ignore_addresses
== NULL
) {
1118 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
1122 return krb5_copy_addresses(context
, addresses
, context
->ignore_addresses
);
1126 * Get extra addresses to ignore when fetching addresses from the
1127 * underlaying operating system.
1129 * @param context Kerberos 5 context.
1130 * @param addresses list addreses ignored
1132 * @return Returns 0 to indicate success. Otherwise an kerberos et
1133 * error code is returned, see krb5_get_error_message().
1138 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1139 krb5_get_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1141 if(context
->ignore_addresses
== NULL
) {
1142 memset(addresses
, 0, sizeof(*addresses
));
1145 return krb5_copy_addresses(context
, context
->ignore_addresses
, addresses
);
1149 * Set version of fcache that the library should use.
1151 * @param context Kerberos 5 context.
1152 * @param version version number.
1154 * @return Returns 0 to indicate success. Otherwise an kerberos et
1155 * error code is returned, see krb5_get_error_message().
1160 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1161 krb5_set_fcache_version(krb5_context context
, int version
)
1163 context
->fcache_vno
= version
;
1168 * Get version of fcache that the library should use.
1170 * @param context Kerberos 5 context.
1171 * @param version version number.
1173 * @return Returns 0 to indicate success. Otherwise an kerberos et
1174 * error code is returned, see krb5_get_error_message().
1179 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1180 krb5_get_fcache_version(krb5_context context
, int *version
)
1182 *version
= context
->fcache_vno
;
1187 * Runtime check if the Kerberos library was complied with thread support.
1189 * @return TRUE if the library was compiled with thread support, FALSE if not.
1195 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
1196 krb5_is_thread_safe(void)
1198 #ifdef ENABLE_PTHREAD_SUPPORT
1206 * Set if the library should use DNS to canonicalize hostnames.
1208 * @param context Kerberos 5 context.
1209 * @param flag if its dns canonicalizion is used or not.
1214 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
1215 krb5_set_dns_canonicalize_hostname (krb5_context context
, krb5_boolean flag
)
1218 context
->flags
|= KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1220 context
->flags
&= ~KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1224 * Get if the library uses DNS to canonicalize hostnames.
1226 * @param context Kerberos 5 context.
1228 * @return return non zero if the library uses DNS to canonicalize hostnames.
1233 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
1234 krb5_get_dns_canonicalize_hostname (krb5_context context
)
1236 return (context
->flags
& KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
) ? 1 : 0;
1240 * Get current offset in time to the KDC.
1242 * @param context Kerberos 5 context.
1243 * @param sec seconds part of offset.
1244 * @param usec micro seconds part of offset.
1246 * @return returns zero
1251 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1252 krb5_get_kdc_sec_offset (krb5_context context
, int32_t *sec
, int32_t *usec
)
1255 *sec
= context
->kdc_sec_offset
;
1257 *usec
= context
->kdc_usec_offset
;
1262 * Set current offset in time to the KDC.
1264 * @param context Kerberos 5 context.
1265 * @param sec seconds part of offset.
1266 * @param usec micro seconds part of offset.
1268 * @return returns zero
1273 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1274 krb5_set_kdc_sec_offset (krb5_context context
, int32_t sec
, int32_t usec
)
1276 context
->kdc_sec_offset
= sec
;
1278 context
->kdc_usec_offset
= usec
;
1283 * Get max time skew allowed.
1285 * @param context Kerberos 5 context.
1287 * @return timeskew in seconds.
1292 KRB5_LIB_FUNCTION
time_t KRB5_LIB_CALL
1293 krb5_get_max_time_skew (krb5_context context
)
1295 return context
->max_skew
;
1299 * Set max time skew allowed.
1301 * @param context Kerberos 5 context.
1302 * @param t timeskew in seconds.
1307 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
1308 krb5_set_max_time_skew (krb5_context context
, time_t t
)
1310 context
->max_skew
= t
;
1314 * Init encryption types in len, val with etypes.
1316 * @param context Kerberos 5 context.
1317 * @param len output length of val.
1318 * @param val output array of enctypes.
1319 * @param etypes etypes to set val and len to, if NULL, use default enctypes.
1321 * @return Returns 0 to indicate success. Otherwise an kerberos et
1322 * error code is returned, see krb5_get_error_message().
1327 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1328 krb5_init_etype (krb5_context context
,
1331 const krb5_enctype
*etypes
)
1334 krb5_error_code ret
;
1335 krb5_enctype
*tmp
= NULL
;
1338 if (etypes
== NULL
) {
1339 ret
= krb5_get_default_in_tkt_etypes(context
, &tmp
);
1345 for (i
= 0; etypes
[i
]; ++i
)
1348 *val
= malloc(i
* sizeof(**val
));
1349 if (i
!= 0 && *val
== NULL
) {
1351 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", ""));
1364 * Allow homedir accces
1367 static HEIMDAL_MUTEX homedir_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
1368 static krb5_boolean allow_homedir
= TRUE
;
1371 _krb5_homedir_access(krb5_context context
)
1376 /* is never allowed for root */
1381 if (context
&& (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) == 0)
1384 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1385 allow
= allow_homedir
;
1386 HEIMDAL_MUTEX_unlock(&homedir_mutex
);
1391 * Enable and disable home directory access on either the global state
1392 * or the krb5_context state. By calling krb5_set_home_dir_access()
1393 * with context set to NULL, the global state is configured otherwise
1394 * the state for the krb5_context is modified.
1396 * For home directory access to be allowed, both the global state and
1397 * the krb5_context state have to be allowed.
1399 * Administrator (root user), never uses the home directory.
1401 * @param context a Kerberos 5 context or NULL
1402 * @param allow allow if TRUE home directory
1403 * @return the old value
1409 krb5_set_home_dir_access(krb5_context context
, krb5_boolean allow
)
1413 old
= (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) ? TRUE
: FALSE
;
1415 context
->flags
|= KRB5_CTX_F_HOMEDIR_ACCESS
;
1417 context
->flags
&= ~KRB5_CTX_F_HOMEDIR_ACCESS
;
1419 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1420 old
= allow_homedir
;
1421 allow_homedir
= allow
;
1422 HEIMDAL_MUTEX_unlock(&homedir_mutex
);