2 * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
37 #define INIT_FIELD(C, T, E, D, F) \
38 (C)->E = krb5_config_get_ ## T ## _default ((C), NULL, (D), \
39 "libdefaults", F, NULL)
41 #define INIT_FLAG(C, O, V, D, F) \
43 if (krb5_config_get_bool_default((C), NULL, (D),"libdefaults", F, NULL)) { \
49 * Set the list of etypes `ret_etypes' from the configuration variable
53 static krb5_error_code
54 set_etypes (krb5_context context
,
56 krb5_enctype
**ret_enctypes
)
59 krb5_enctype
*etypes
= NULL
;
61 etypes_str
= krb5_config_get_strings(context
, NULL
, "libdefaults",
65 for(i
= 0; etypes_str
[i
]; i
++);
66 etypes
= malloc((i
+1) * sizeof(*etypes
));
68 krb5_config_free_strings (etypes_str
);
69 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
72 for(j
= 0, k
= 0; j
< i
; j
++) {
74 if(krb5_string_to_enctype(context
, etypes_str
[j
], &e
) != 0)
76 if (krb5_enctype_valid(context
, e
) != 0)
80 etypes
[k
] = ETYPE_NULL
;
81 krb5_config_free_strings(etypes_str
);
83 *ret_enctypes
= etypes
;
88 * read variables from the configuration file and set in `context'
91 static krb5_error_code
92 init_context_from_config_file(krb5_context context
)
97 krb5_enctype
*tmptypes
;
99 INIT_FIELD(context
, time
, max_skew
, 5 * 60, "clockskew");
100 INIT_FIELD(context
, time
, kdc_timeout
, 3, "kdc_timeout");
101 INIT_FIELD(context
, int, max_retries
, 3, "max_retries");
103 INIT_FIELD(context
, string
, http_proxy
, NULL
, "http_proxy");
105 ret
= set_etypes (context
, "default_etypes", &tmptypes
);
108 free(context
->etypes
);
109 context
->etypes
= tmptypes
;
111 ret
= set_etypes (context
, "default_etypes_des", &tmptypes
);
114 free(context
->etypes_des
);
115 context
->etypes_des
= tmptypes
;
117 /* default keytab name */
120 tmp
= getenv("KRB5_KTNAME");
122 context
->default_keytab
= tmp
;
124 INIT_FIELD(context
, string
, default_keytab
,
125 KEYTAB_DEFAULT
, "default_keytab_name");
127 INIT_FIELD(context
, string
, default_keytab_modify
,
128 NULL
, "default_keytab_modify_name");
130 INIT_FIELD(context
, string
, time_fmt
,
131 "%Y-%m-%dT%H:%M:%S", "time_format");
133 INIT_FIELD(context
, string
, date_fmt
,
134 "%Y-%m-%d", "date_format");
136 INIT_FIELD(context
, bool, log_utc
,
141 /* init dns-proxy slime */
142 tmp
= krb5_config_get_string(context
, NULL
, "libdefaults",
145 roken_gethostby_setup(context
->http_proxy
, tmp
);
146 krb5_free_host_realm (context
, context
->default_realms
);
147 context
->default_realms
= NULL
;
150 krb5_addresses addresses
;
153 krb5_set_extra_addresses(context
, NULL
);
154 adr
= krb5_config_get_strings(context
, NULL
,
158 memset(&addresses
, 0, sizeof(addresses
));
159 for(a
= adr
; a
&& *a
; a
++) {
160 ret
= krb5_parse_address(context
, *a
, &addresses
);
162 krb5_add_extra_addresses(context
, &addresses
);
163 krb5_free_addresses(context
, &addresses
);
166 krb5_config_free_strings(adr
);
168 krb5_set_ignore_addresses(context
, NULL
);
169 adr
= krb5_config_get_strings(context
, NULL
,
173 memset(&addresses
, 0, sizeof(addresses
));
174 for(a
= adr
; a
&& *a
; a
++) {
175 ret
= krb5_parse_address(context
, *a
, &addresses
);
177 krb5_add_ignore_addresses(context
, &addresses
);
178 krb5_free_addresses(context
, &addresses
);
181 krb5_config_free_strings(adr
);
184 INIT_FIELD(context
, bool, scan_interfaces
, TRUE
, "scan_interfaces");
185 INIT_FIELD(context
, int, fcache_vno
, 0, "fcache_version");
186 /* prefer dns_lookup_kdc over srv_lookup. */
187 INIT_FIELD(context
, bool, srv_lookup
, TRUE
, "srv_lookup");
188 INIT_FIELD(context
, bool, srv_lookup
, context
->srv_lookup
, "dns_lookup_kdc");
189 INIT_FIELD(context
, int, large_msg_size
, 1400, "large_message_size");
190 INIT_FLAG(context
, flags
, KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
, TRUE
, "dns_canonicalize_hostname");
191 INIT_FLAG(context
, flags
, KRB5_CTX_F_CHECK_PAC
, TRUE
, "check_pac");
192 context
->default_cc_name
= NULL
;
193 context
->default_cc_name_set
= 0;
195 ret
= krb5_config_get_bool_default(context
, NULL
, FALSE
,
197 "allow_weak_crypto", NULL
);
199 krb5_enctype_enable(context
, ETYPE_DES_CBC_CRC
);
200 krb5_enctype_enable(context
, ETYPE_DES_CBC_MD4
);
201 krb5_enctype_enable(context
, ETYPE_DES_CBC_MD5
);
202 krb5_enctype_enable(context
, ETYPE_DES_CBC_NONE
);
203 krb5_enctype_enable(context
, ETYPE_DES_CFB64_NONE
);
204 krb5_enctype_enable(context
, ETYPE_DES_PCBC_NONE
);
207 s
= krb5_config_get_strings(context
, NULL
, "logging", "krb5", NULL
);
210 krb5_initlog(context
, "libkrb5", &context
->debug_dest
);
212 krb5_addlog_dest(context
, context
->debug_dest
, *p
);
213 krb5_config_free_strings(s
);
220 static krb5_error_code
221 cc_ops_register(krb5_context context
)
223 context
->cc_ops
= NULL
;
224 context
->num_cc_ops
= 0;
226 krb5_cc_register(context
, &krb5_acc_ops
, TRUE
);
227 krb5_cc_register(context
, &krb5_fcc_ops
, TRUE
);
228 krb5_cc_register(context
, &krb5_mcc_ops
, TRUE
);
229 krb5_cc_register(context
, &krb5_scc_ops
, TRUE
);
231 krb5_cc_register(context
, &krb5_kcm_ops
, TRUE
);
236 static krb5_error_code
237 kt_ops_register(krb5_context context
)
239 context
->num_kt_types
= 0;
240 context
->kt_types
= NULL
;
242 krb5_kt_register (context
, &krb5_fkt_ops
);
243 krb5_kt_register (context
, &krb5_wrfkt_ops
);
244 krb5_kt_register (context
, &krb5_javakt_ops
);
245 krb5_kt_register (context
, &krb5_mkt_ops
);
246 #ifndef HEIMDAL_SMALLER
247 krb5_kt_register (context
, &krb5_akf_ops
);
249 krb5_kt_register (context
, &krb5_any_ops
);
255 * Initializes the context structure and reads the configuration file
256 * /etc/krb5.conf. The structure should be freed by calling
257 * krb5_free_context() when it is no longer being used.
259 * @param context pointer to returned context
261 * @return Returns 0 to indicate success. Otherwise an errno code is
262 * returned. Failure means either that something bad happened during
263 * initialization (typically ENOMEM) or that Kerberos should not be
269 krb5_error_code KRB5_LIB_FUNCTION
270 krb5_init_context(krb5_context
*context
)
278 /* should have a run_once */
279 bindtextdomain(HEIMDAL_TEXTDOMAIN
, HEIMDAL_LOCALEDIR
);
281 p
= calloc(1, sizeof(*p
));
285 p
->mutex
= malloc(sizeof(HEIMDAL_MUTEX
));
286 if (p
->mutex
== NULL
) {
290 HEIMDAL_MUTEX_init(p
->mutex
);
292 p
->flags
|= KRB5_CTX_F_HOMEDIR_ACCESS
;
294 ret
= krb5_get_default_config_files(&files
);
297 ret
= krb5_set_config_files(p
, files
);
298 krb5_free_config_files(files
);
302 /* init error tables */
308 ret
= hx509_context_init(&p
->hx509ctx
);
315 krb5_free_context(p
);
322 #ifndef HEIMDAL_SMALLER
328 static krb5_error_code
329 copy_etypes (krb5_context context
,
330 krb5_enctype
*enctypes
,
331 krb5_enctype
**ret_enctypes
)
335 for (i
= 0; enctypes
[i
]; i
++)
339 *ret_enctypes
= malloc(sizeof(ret_enctypes
[0]) * i
);
340 if (*ret_enctypes
== NULL
) {
341 krb5_set_error_message(context
, ENOMEM
,
342 N_("malloc: out of memory", ""));
345 memcpy(*ret_enctypes
, enctypes
, sizeof(ret_enctypes
[0]) * i
);
350 * Make a copy for the Kerberos 5 context, the new krb5_context shoud
351 * be freed with krb5_free_context().
353 * @param context the Kerberos context to copy
354 * @param out the copy of the Kerberos, set to NULL error.
356 * @return Returns 0 to indicate success. Otherwise an kerberos et
357 * error code is returned, see krb5_get_error_message().
362 krb5_error_code KRB5_LIB_FUNCTION
363 krb5_copy_context(krb5_context context
, krb5_context
*out
)
370 p
= calloc(1, sizeof(*p
));
372 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
376 p
->mutex
= malloc(sizeof(HEIMDAL_MUTEX
));
377 if (p
->mutex
== NULL
) {
378 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
382 HEIMDAL_MUTEX_init(p
->mutex
);
385 if (context
->default_cc_name
)
386 p
->default_cc_name
= strdup(context
->default_cc_name
);
387 if (context
->default_cc_name_env
)
388 p
->default_cc_name_env
= strdup(context
->default_cc_name_env
);
390 if (context
->etypes
) {
391 ret
= copy_etypes(context
, context
->etypes
, &p
->etypes
);
395 if (context
->etypes_des
) {
396 ret
= copy_etypes(context
, context
->etypes_des
, &p
->etypes_des
);
401 if (context
->default_realms
) {
402 ret
= krb5_copy_host_realm(context
,
403 context
->default_realms
, &p
->default_realms
);
408 ret
= _krb5_config_copy(context
, context
->cf
, &p
->cf
);
412 /* XXX should copy */
418 if(context
->warn_dest
!= NULL
)
420 if(context
->debug_dest
!= NULL
)
424 ret
= krb5_set_extra_addresses(p
, context
->extra_addresses
);
427 ret
= krb5_set_extra_addresses(p
, context
->ignore_addresses
);
431 ret
= _krb5_copy_send_to_kdc_func(p
, context
);
440 krb5_free_context(p
);
447 * Frees the krb5_context allocated by krb5_init_context().
449 * @param context context to be freed.
454 void KRB5_LIB_FUNCTION
455 krb5_free_context(krb5_context context
)
457 if (context
->default_cc_name
)
458 free(context
->default_cc_name
);
459 if (context
->default_cc_name_env
)
460 free(context
->default_cc_name_env
);
461 free(context
->etypes
);
462 free(context
->etypes_des
);
463 krb5_free_host_realm (context
, context
->default_realms
);
464 krb5_config_file_free (context
, context
->cf
);
465 free_error_table (context
->et_list
);
466 free(context
->cc_ops
);
467 free(context
->kt_types
);
468 krb5_clear_error_message(context
);
469 if(context
->warn_dest
!= NULL
)
470 krb5_closelog(context
, context
->warn_dest
);
471 if(context
->debug_dest
!= NULL
)
472 krb5_closelog(context
, context
->debug_dest
);
473 krb5_set_extra_addresses(context
, NULL
);
474 krb5_set_ignore_addresses(context
, NULL
);
475 krb5_set_send_to_kdc_func(context
, NULL
, NULL
);
478 if (context
->hx509ctx
)
479 hx509_context_free(&context
->hx509ctx
);
482 HEIMDAL_MUTEX_destroy(context
->mutex
);
483 free(context
->mutex
);
485 memset(context
, 0, sizeof(*context
));
490 * Reinit the context from a new set of filenames.
492 * @param context context to add configuration too.
493 * @param filenames array of filenames, end of list is indicated with a NULL filename.
495 * @return Returns 0 to indicate success. Otherwise an kerberos et
496 * error code is returned, see krb5_get_error_message().
501 krb5_error_code KRB5_LIB_FUNCTION
502 krb5_set_config_files(krb5_context context
, char **filenames
)
505 krb5_config_binding
*tmp
= NULL
;
506 while(filenames
!= NULL
&& *filenames
!= NULL
&& **filenames
!= '\0') {
507 ret
= krb5_config_parse_file_multi(context
, *filenames
, &tmp
);
508 if(ret
!= 0 && ret
!= ENOENT
&& ret
!= EACCES
) {
509 krb5_config_file_free(context
, tmp
);
515 /* with this enabled and if there are no config files, Kerberos is
516 considererd disabled */
520 krb5_config_file_free(context
, context
->cf
);
522 ret
= init_context_from_config_file(context
);
526 static krb5_error_code
527 add_file(char ***pfilenames
, int *len
, char *file
)
529 char **pp
= *pfilenames
;
532 for(i
= 0; i
< *len
; i
++) {
533 if(strcmp(pp
[i
], file
) == 0) {
539 pp
= realloc(*pfilenames
, (*len
+ 2) * sizeof(*pp
));
553 * `pq' isn't free, it's up the the caller
556 krb5_error_code KRB5_LIB_FUNCTION
557 krb5_prepend_config_files(const char *filelist
, char **pq
, char ***ret_pp
)
572 l
= strsep_copy(&q
, ":", NULL
, 0);
577 krb5_free_config_files(pp
);
580 (void)strsep_copy(&p
, ":", fn
, l
+ 1);
581 ret
= add_file(&pp
, &len
, fn
);
583 krb5_free_config_files(pp
);
591 for (i
= 0; pq
[i
] != NULL
; i
++) {
594 krb5_free_config_files(pp
);
597 ret
= add_file(&pp
, &len
, fn
);
599 krb5_free_config_files(pp
);
610 * Prepend the filename to the global configuration list.
612 * @param filelist a filename to add to the default list of filename
613 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
615 * @return Returns 0 to indicate success. Otherwise an kerberos et
616 * error code is returned, see krb5_get_error_message().
621 krb5_error_code KRB5_LIB_FUNCTION
622 krb5_prepend_config_files_default(const char *filelist
, char ***pfilenames
)
625 char **defpp
, **pp
= NULL
;
627 ret
= krb5_get_default_config_files(&defpp
);
631 ret
= krb5_prepend_config_files(filelist
, defpp
, &pp
);
632 krb5_free_config_files(defpp
);
641 * Get the global configuration list.
643 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
645 * @return Returns 0 to indicate success. Otherwise an kerberos et
646 * error code is returned, see krb5_get_error_message().
651 krb5_error_code KRB5_LIB_FUNCTION
652 krb5_get_default_config_files(char ***pfilenames
)
654 const char *files
= NULL
;
656 if (pfilenames
== NULL
)
659 files
= getenv("KRB5_CONFIG");
661 files
= krb5_config_file
;
663 return krb5_prepend_config_files(files
, NULL
, pfilenames
);
667 * Free a list of configuration files.
669 * @param filenames list, terminated with a NULL pointer, to be
670 * freed. NULL is an valid argument.
672 * @return Returns 0 to indicate success. Otherwise an kerberos et
673 * error code is returned, see krb5_get_error_message().
678 void KRB5_LIB_FUNCTION
679 krb5_free_config_files(char **filenames
)
682 for(p
= filenames
; p
&& *p
!= NULL
; p
++)
688 * Returns the list of Kerberos encryption types sorted in order of
689 * most preferred to least preferred encryption type. Note that some
690 * encryption types might be disabled, so you need to check with
691 * krb5_enctype_valid() before using the encryption type.
693 * @return list of enctypes, terminated with ETYPE_NULL. Its a static
694 * array completed into the Kerberos library so the content doesn't
700 const krb5_enctype
* KRB5_LIB_FUNCTION
701 krb5_kerberos_enctypes(krb5_context context
)
703 static const krb5_enctype p
[] = {
704 ETYPE_AES256_CTS_HMAC_SHA1_96
,
705 ETYPE_AES128_CTS_HMAC_SHA1_96
,
708 ETYPE_ARCFOUR_HMAC_MD5
,
718 * set `etype' to a malloced list of the default enctypes
721 static krb5_error_code
722 default_etypes(krb5_context context
, krb5_enctype
**etype
)
724 const krb5_enctype
*p
;
725 krb5_enctype
*e
= NULL
, *ep
;
728 p
= krb5_kerberos_enctypes(context
);
730 for (i
= 0; p
[i
] != ETYPE_NULL
; i
++) {
731 if (krb5_enctype_valid(context
, p
[i
]) != 0)
733 ep
= realloc(e
, (n
+ 2) * sizeof(*e
));
736 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
741 e
[n
+ 1] = ETYPE_NULL
;
749 * Set the default encryption types that will be use in communcation
750 * with the KDC, clients and servers.
752 * @param context Kerberos 5 context.
753 * @param etypes Encryption types, array terminated with ETYPE_NULL (0).
755 * @return Returns 0 to indicate success. Otherwise an kerberos et
756 * error code is returned, see krb5_get_error_message().
761 krb5_error_code KRB5_LIB_FUNCTION
762 krb5_set_default_in_tkt_etypes(krb5_context context
,
763 const krb5_enctype
*etypes
)
766 krb5_enctype
*p
= NULL
;
770 for (n
= 0; etypes
[n
]; n
++)
775 krb5_set_error_message (context
, ENOMEM
,
776 N_("malloc: out of memory", ""));
779 for (n
= 0, m
= 0; etypes
[n
]; n
++) {
780 ret
= krb5_enctype_valid(context
, etypes
[n
]);
788 krb5_set_error_message (context
, KRB5_PROG_ETYPE_NOSUPP
,
789 N_("no valid enctype set", ""));
790 return KRB5_PROG_ETYPE_NOSUPP
;
794 free(context
->etypes
);
800 * Get the default encryption types that will be use in communcation
801 * with the KDC, clients and servers.
803 * @param context Kerberos 5 context.
804 * @param etypes Encryption types, array terminated with
805 * ETYPE_NULL(0), caller should free array with krb5_xfree():
807 * @return Returns 0 to indicate success. Otherwise an kerberos et
808 * error code is returned, see krb5_get_error_message().
813 krb5_error_code KRB5_LIB_FUNCTION
814 krb5_get_default_in_tkt_etypes(krb5_context context
,
815 krb5_enctype
**etypes
)
821 if(context
->etypes
) {
822 for(i
= 0; context
->etypes
[i
]; i
++);
826 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
829 memmove(p
, context
->etypes
, i
* sizeof(krb5_enctype
));
831 ret
= default_etypes(context
, &p
);
840 * Init the built-in ets in the Kerberos library.
842 * @param context kerberos context to add the ets too
847 void KRB5_LIB_FUNCTION
848 krb5_init_ets(krb5_context context
)
850 if(context
->et_list
== NULL
){
851 krb5_add_et_list(context
, initialize_krb5_error_table_r
);
852 krb5_add_et_list(context
, initialize_asn1_error_table_r
);
853 krb5_add_et_list(context
, initialize_heim_error_table_r
);
855 krb5_add_et_list(context
, initialize_k524_error_table_r
);
857 #ifdef COM_ERR_BINDDOMAIN_krb5
858 bindtextdomain(COM_ERR_BINDDOMAIN_krb5
, HEIMDAL_LOCALEDIR
);
859 bindtextdomain(COM_ERR_BINDDOMAIN_asn1
, HEIMDAL_LOCALEDIR
);
860 bindtextdomain(COM_ERR_BINDDOMAIN_heim
, HEIMDAL_LOCALEDIR
);
861 bindtextdomain(COM_ERR_BINDDOMAIN_k524
, HEIMDAL_LOCALEDIR
);
865 krb5_add_et_list(context
, initialize_hx_error_table_r
);
866 #ifdef COM_ERR_BINDDOMAIN_hx
867 bindtextdomain(COM_ERR_BINDDOMAIN_hx
, HEIMDAL_LOCALEDIR
);
874 * Make the kerberos library default to the admin KDC.
876 * @param context Kerberos 5 context.
877 * @param flag boolean flag to select if the use the admin KDC or not.
882 void KRB5_LIB_FUNCTION
883 krb5_set_use_admin_kdc (krb5_context context
, krb5_boolean flag
)
885 context
->use_admin_kdc
= flag
;
889 * Make the kerberos library default to the admin KDC.
891 * @param context Kerberos 5 context.
893 * @return boolean flag to telling the context will use admin KDC as the default KDC.
898 krb5_boolean KRB5_LIB_FUNCTION
899 krb5_get_use_admin_kdc (krb5_context context
)
901 return context
->use_admin_kdc
;
905 * Add extra address to the address list that the library will add to
906 * the client's address list when communicating with the KDC.
908 * @param context Kerberos 5 context.
909 * @param addresses addreses to add
911 * @return Returns 0 to indicate success. Otherwise an kerberos et
912 * error code is returned, see krb5_get_error_message().
917 krb5_error_code KRB5_LIB_FUNCTION
918 krb5_add_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
921 if(context
->extra_addresses
)
922 return krb5_append_addresses(context
,
923 context
->extra_addresses
, addresses
);
925 return krb5_set_extra_addresses(context
, addresses
);
929 * Set extra address to the address list that the library will add to
930 * the client's address list when communicating with the KDC.
932 * @param context Kerberos 5 context.
933 * @param addresses addreses to set
935 * @return Returns 0 to indicate success. Otherwise an kerberos et
936 * error code is returned, see krb5_get_error_message().
941 krb5_error_code KRB5_LIB_FUNCTION
942 krb5_set_extra_addresses(krb5_context context
, const krb5_addresses
*addresses
)
944 if(context
->extra_addresses
)
945 krb5_free_addresses(context
, context
->extra_addresses
);
947 if(addresses
== NULL
) {
948 if(context
->extra_addresses
!= NULL
) {
949 free(context
->extra_addresses
);
950 context
->extra_addresses
= NULL
;
954 if(context
->extra_addresses
== NULL
) {
955 context
->extra_addresses
= malloc(sizeof(*context
->extra_addresses
));
956 if(context
->extra_addresses
== NULL
) {
957 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
961 return krb5_copy_addresses(context
, addresses
, context
->extra_addresses
);
965 * Get extra address to the address list that the library will add to
966 * the client's address list when communicating with the KDC.
968 * @param context Kerberos 5 context.
969 * @param addresses addreses to set
971 * @return Returns 0 to indicate success. Otherwise an kerberos et
972 * error code is returned, see krb5_get_error_message().
977 krb5_error_code KRB5_LIB_FUNCTION
978 krb5_get_extra_addresses(krb5_context context
, krb5_addresses
*addresses
)
980 if(context
->extra_addresses
== NULL
) {
981 memset(addresses
, 0, sizeof(*addresses
));
984 return krb5_copy_addresses(context
,context
->extra_addresses
, addresses
);
988 * Add extra addresses to ignore when fetching addresses from the
989 * underlaying operating system.
991 * @param context Kerberos 5 context.
992 * @param addresses addreses to ignore
994 * @return Returns 0 to indicate success. Otherwise an kerberos et
995 * error code is returned, see krb5_get_error_message().
1000 krb5_error_code KRB5_LIB_FUNCTION
1001 krb5_add_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1004 if(context
->ignore_addresses
)
1005 return krb5_append_addresses(context
,
1006 context
->ignore_addresses
, addresses
);
1008 return krb5_set_ignore_addresses(context
, addresses
);
1012 * Set extra addresses to ignore when fetching addresses from the
1013 * underlaying operating system.
1015 * @param context Kerberos 5 context.
1016 * @param addresses addreses to ignore
1018 * @return Returns 0 to indicate success. Otherwise an kerberos et
1019 * error code is returned, see krb5_get_error_message().
1024 krb5_error_code KRB5_LIB_FUNCTION
1025 krb5_set_ignore_addresses(krb5_context context
, const krb5_addresses
*addresses
)
1027 if(context
->ignore_addresses
)
1028 krb5_free_addresses(context
, context
->ignore_addresses
);
1029 if(addresses
== NULL
) {
1030 if(context
->ignore_addresses
!= NULL
) {
1031 free(context
->ignore_addresses
);
1032 context
->ignore_addresses
= NULL
;
1036 if(context
->ignore_addresses
== NULL
) {
1037 context
->ignore_addresses
= malloc(sizeof(*context
->ignore_addresses
));
1038 if(context
->ignore_addresses
== NULL
) {
1039 krb5_set_error_message (context
, ENOMEM
, N_("malloc: out of memory", ""));
1043 return krb5_copy_addresses(context
, addresses
, context
->ignore_addresses
);
1047 * Get extra addresses to ignore when fetching addresses from the
1048 * underlaying operating system.
1050 * @param context Kerberos 5 context.
1051 * @param addresses list addreses ignored
1053 * @return Returns 0 to indicate success. Otherwise an kerberos et
1054 * error code is returned, see krb5_get_error_message().
1059 krb5_error_code KRB5_LIB_FUNCTION
1060 krb5_get_ignore_addresses(krb5_context context
, krb5_addresses
*addresses
)
1062 if(context
->ignore_addresses
== NULL
) {
1063 memset(addresses
, 0, sizeof(*addresses
));
1066 return krb5_copy_addresses(context
, context
->ignore_addresses
, addresses
);
1070 * Set version of fcache that the library should use.
1072 * @param context Kerberos 5 context.
1073 * @param version version number.
1075 * @return Returns 0 to indicate success. Otherwise an kerberos et
1076 * error code is returned, see krb5_get_error_message().
1081 krb5_error_code KRB5_LIB_FUNCTION
1082 krb5_set_fcache_version(krb5_context context
, int version
)
1084 context
->fcache_vno
= version
;
1089 * Get version of fcache that the library should use.
1091 * @param context Kerberos 5 context.
1092 * @param version version number.
1094 * @return Returns 0 to indicate success. Otherwise an kerberos et
1095 * error code is returned, see krb5_get_error_message().
1100 krb5_error_code KRB5_LIB_FUNCTION
1101 krb5_get_fcache_version(krb5_context context
, int *version
)
1103 *version
= context
->fcache_vno
;
1108 * Runtime check if the Kerberos library was complied with thread support.
1110 * @return TRUE if the library was compiled with thread support, FALSE if not.
1116 krb5_boolean KRB5_LIB_FUNCTION
1117 krb5_is_thread_safe(void)
1119 #ifdef ENABLE_PTHREAD_SUPPORT
1127 * Set if the library should use DNS to canonicalize hostnames.
1129 * @param context Kerberos 5 context.
1130 * @param flag if its dns canonicalizion is used or not.
1135 void KRB5_LIB_FUNCTION
1136 krb5_set_dns_canonicalize_hostname (krb5_context context
, krb5_boolean flag
)
1139 context
->flags
|= KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1141 context
->flags
&= ~KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
;
1145 * Get if the library uses DNS to canonicalize hostnames.
1147 * @param context Kerberos 5 context.
1149 * @return return non zero if the library uses DNS to canonicalize hostnames.
1154 krb5_boolean KRB5_LIB_FUNCTION
1155 krb5_get_dns_canonicalize_hostname (krb5_context context
)
1157 return (context
->flags
& KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME
) ? 1 : 0;
1161 * Get current offset in time to the KDC.
1163 * @param context Kerberos 5 context.
1164 * @param sec seconds part of offset.
1165 * @param usec micro seconds part of offset.
1167 * @return returns zero
1172 krb5_error_code KRB5_LIB_FUNCTION
1173 krb5_get_kdc_sec_offset (krb5_context context
, int32_t *sec
, int32_t *usec
)
1176 *sec
= context
->kdc_sec_offset
;
1178 *usec
= context
->kdc_usec_offset
;
1183 * Set current offset in time to the KDC.
1185 * @param context Kerberos 5 context.
1186 * @param sec seconds part of offset.
1187 * @param usec micro seconds part of offset.
1189 * @return returns zero
1194 krb5_error_code KRB5_LIB_FUNCTION
1195 krb5_set_kdc_sec_offset (krb5_context context
, int32_t sec
, int32_t usec
)
1197 context
->kdc_sec_offset
= sec
;
1199 context
->kdc_usec_offset
= usec
;
1204 * Get max time skew allowed.
1206 * @param context Kerberos 5 context.
1208 * @return timeskew in seconds.
1213 time_t KRB5_LIB_FUNCTION
1214 krb5_get_max_time_skew (krb5_context context
)
1216 return context
->max_skew
;
1220 * Set max time skew allowed.
1222 * @param context Kerberos 5 context.
1223 * @param t timeskew in seconds.
1228 void KRB5_LIB_FUNCTION
1229 krb5_set_max_time_skew (krb5_context context
, time_t t
)
1231 context
->max_skew
= t
;
1235 * Init encryption types in len, val with etypes.
1237 * @param context Kerberos 5 context.
1238 * @param len output length of val.
1239 * @param val output array of enctypes.
1240 * @param etypes etypes to set val and len to, if NULL, use default enctypes.
1242 * @return Returns 0 to indicate success. Otherwise an kerberos et
1243 * error code is returned, see krb5_get_error_message().
1248 krb5_error_code KRB5_LIB_FUNCTION
1249 krb5_init_etype (krb5_context context
,
1252 const krb5_enctype
*etypes
)
1255 krb5_error_code ret
;
1256 krb5_enctype
*tmp
= NULL
;
1259 if (etypes
== NULL
) {
1260 ret
= krb5_get_default_in_tkt_etypes(context
, &tmp
);
1266 for (i
= 0; etypes
[i
]; ++i
)
1269 *val
= malloc(i
* sizeof(**val
));
1270 if (i
!= 0 && *val
== NULL
) {
1272 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", ""));
1285 * Allow homedir accces
1288 static HEIMDAL_MUTEX homedir_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
1289 static krb5_boolean allow_homedir
= TRUE
;
1292 _krb5_homedir_access(krb5_context context
)
1296 /* is never allowed for root */
1300 if (context
&& (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) == 0)
1303 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1304 allow
= allow_homedir
;
1305 HEIMDAL_MUTEX_unlock(&homedir_mutex
);
1310 * Enable and disable home directory access on either the global state
1311 * or the krb5_context state. By calling krb5_set_home_dir_access()
1312 * with context set to NULL, the global state is configured otherwise
1313 * the state for the krb5_context is modified.
1315 * For home directory access to be allowed, both the global state and
1316 * the krb5_context state have to be allowed.
1318 * Administrator (root user), never uses the home directory.
1320 * @param context a Kerberos 5 context or NULL
1321 * @param allow allow if TRUE home directory
1322 * @return the old value
1327 krb5_set_home_dir_access(krb5_context context
, krb5_boolean allow
)
1331 old
= (context
->flags
& KRB5_CTX_F_HOMEDIR_ACCESS
) ? TRUE
: FALSE
;
1333 context
->flags
|= KRB5_CTX_F_HOMEDIR_ACCESS
;
1335 context
->flags
&= ~KRB5_CTX_F_HOMEDIR_ACCESS
;
1337 HEIMDAL_MUTEX_lock(&homedir_mutex
);
1338 old
= allow_homedir
;
1339 allow_homedir
= allow
;
1340 HEIMDAL_MUTEX_unlock(&homedir_mutex
);