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;
91 static krb5_error_code
92 copy_etypes (krb5_context context,
93 krb5_enctype *enctypes,
94 krb5_enctype **ret_enctypes)
98 for (i = 0; enctypes[i]; i++)
102 *ret_enctypes = malloc(sizeof(ret_enctypes[0]) * i);
103 if (*ret_enctypes == NULL) {
104 krb5_set_error_message(context, ENOMEM,
105 N_("malloc: out of memory", ""));
108 memcpy(*ret_enctypes, enctypes, sizeof(ret_enctypes[0]) * i);
114 * read variables from the configuration file and set in `context'
117 static krb5_error_code
118 init_context_from_config_file(krb5_context context)
122 krb5_enctype *tmptypes;
124 INIT_FIELD(context, time, max_skew, 5 * 60, "clockskew");
125 INIT_FIELD(context, time, kdc_timeout, 3, "kdc_timeout");
126 INIT_FIELD(context, int, max_retries, 3, "max_retries");
128 INIT_FIELD(context, string, http_proxy, NULL, "http_proxy");
130 ret = set_etypes (context, "default_etypes", &tmptypes);
133 free(context->etypes);
134 context->etypes = tmptypes;
136 ret = set_etypes (context, "default_etypes_des", &tmptypes);
139 free(context->etypes_des);
140 context->etypes_des = tmptypes;
142 /* default keytab name */
145 tmp = getenv("KRB5_KTNAME");
147 context->default_keytab = tmp;
149 INIT_FIELD(context, string, default_keytab,
150 KEYTAB_DEFAULT, "default_keytab_name");
152 INIT_FIELD(context, string, default_keytab_modify,
153 NULL, "default_keytab_modify_name");
155 INIT_FIELD(context, string, time_fmt,
156 "%Y-%m-%dT%H:%M:%S", "time_format");
158 INIT_FIELD(context, string, date_fmt,
159 "%Y-%m-%d", "date_format");
161 INIT_FIELD(context, bool, log_utc,
166 /* init dns-proxy slime */
167 tmp = krb5_config_get_string(context, NULL, "libdefaults",
170 roken_gethostby_setup(context->http_proxy, tmp);
171 krb5_free_host_realm (context, context->default_realms);
172 context->default_realms = NULL;
175 krb5_addresses addresses;
178 krb5_set_extra_addresses(context, NULL);
179 adr = krb5_config_get_strings(context, NULL,
183 memset(&addresses, 0, sizeof(addresses));
184 for(a = adr; a && *a; a++) {
185 ret = krb5_parse_address(context, *a, &addresses);
187 krb5_add_extra_addresses(context, &addresses);
188 krb5_free_addresses(context, &addresses);
191 krb5_config_free_strings(adr);
193 krb5_set_ignore_addresses(context, NULL);
194 adr = krb5_config_get_strings(context, NULL,
198 memset(&addresses, 0, sizeof(addresses));
199 for(a = adr; a && *a; a++) {
200 ret = krb5_parse_address(context, *a, &addresses);
202 krb5_add_ignore_addresses(context, &addresses);
203 krb5_free_addresses(context, &addresses);
206 krb5_config_free_strings(adr);
209 INIT_FIELD(context, bool, scan_interfaces, TRUE, "scan_interfaces");
210 INIT_FIELD(context, int, fcache_vno, 0, "fcache_version");
211 /* prefer dns_lookup_kdc over srv_lookup. */
212 INIT_FIELD(context, bool, srv_lookup, TRUE, "srv_lookup");
213 INIT_FIELD(context, bool, srv_lookup, context->srv_lookup, "dns_lookup_kdc");
214 INIT_FIELD(context, int, large_msg_size, 1400, "large_message_size");
215 INIT_FLAG(context, flags, KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME, TRUE, "dns_canonicalize_hostname");
216 INIT_FLAG(context, flags, KRB5_CTX_F_CHECK_PAC, TRUE, "check_pac");
217 context->default_cc_name = NULL;
218 context->default_cc_name_set = 0;
220 ret = krb5_config_get_bool_default(context, NULL, FALSE,
222 "allow_weak_crypto", NULL);
224 krb5_enctype_enable(context, ETYPE_DES_CBC_CRC);
225 krb5_enctype_enable(context, ETYPE_DES_CBC_MD4);
226 krb5_enctype_enable(context, ETYPE_DES_CBC_MD5);
227 krb5_enctype_enable(context, ETYPE_DES_CBC_NONE);
228 krb5_enctype_enable(context, ETYPE_DES_CFB64_NONE);
229 krb5_enctype_enable(context, ETYPE_DES_PCBC_NONE);
235 static krb5_error_code
236 cc_ops_register(krb5_context context)
238 context->cc_ops = NULL;
239 context->num_cc_ops = 0;
241 krb5_cc_register(context, &krb5_acc_ops, TRUE);
242 krb5_cc_register(context, &krb5_fcc_ops, TRUE);
243 krb5_cc_register(context, &krb5_mcc_ops, TRUE);
244 krb5_cc_register(context, &krb5_scc_ops, TRUE);
246 krb5_cc_register(context, &krb5_kcm_ops, TRUE);
251 static krb5_error_code
252 kt_ops_register(krb5_context context)
254 context->num_kt_types = 0;
255 context->kt_types = NULL;
257 krb5_kt_register (context, &krb5_fkt_ops);
258 krb5_kt_register (context, &krb5_wrfkt_ops);
259 krb5_kt_register (context, &krb5_javakt_ops);
260 krb5_kt_register (context, &krb5_mkt_ops);
261 #ifndef HEIMDAL_SMALLER
262 krb5_kt_register (context, &krb5_akf_ops);
264 krb5_kt_register (context, &krb5_any_ops);
270 * Initializes the context structure and reads the configuration file
271 * /etc/krb5.conf. The structure should be freed by calling
272 * krb5_free_context() when it is no longer being used.
274 * @param context pointer to returned context
276 * @return Returns 0 to indicate success. Otherwise an errno code is
277 * returned. Failure means either that something bad happened during
278 * initialization (typically ENOMEM) or that Kerberos should not be
284 krb5_error_code KRB5_LIB_FUNCTION
285 krb5_init_context(krb5_context *context)
293 /* should have a run_once */
294 #if defined(HEIMDAL_LOCALEDIR)
295 bindtextdomain(HEIMDAL_TEXTDOMAIN, HEIMDAL_LOCALEDIR);
298 p = calloc(1, sizeof(*p));
302 p->mutex = malloc(sizeof(HEIMDAL_MUTEX));
303 if (p->mutex == NULL) {
307 HEIMDAL_MUTEX_init(p->mutex);
309 p->flags |= KRB5_CTX_F_HOMEDIR_ACCESS;
311 ret = krb5_get_default_config_files(&files);
314 ret = krb5_set_config_files(p, files);
315 krb5_free_config_files(files);
319 /* init error tables */
326 krb5_free_context(p);
334 * Make a copy for the Kerberos 5 context, allocated krb5_contex shoud
335 * be freed with krb5_free_context().
337 * @param context the Kerberos context to copy
338 * @param out the copy of the Kerberos, set to NULL error.
340 * @return Returns 0 to indicate success. Otherwise an kerberos et
341 * error code is returned, see krb5_get_error_message().
346 krb5_error_code KRB5_LIB_FUNCTION
347 krb5_copy_context(krb5_context context, krb5_context *out)
354 p = calloc(1, sizeof(*p));
356 krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
360 p->mutex = malloc(sizeof(HEIMDAL_MUTEX));
361 if (p->mutex == NULL) {
362 krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
366 HEIMDAL_MUTEX_init(p->mutex);
369 if (context->default_cc_name)
370 p->default_cc_name = strdup(context->default_cc_name);
371 if (context->default_cc_name_env)
372 p->default_cc_name_env = strdup(context->default_cc_name_env);
374 if (context->etypes) {
375 ret = copy_etypes(context, context->etypes, &p->etypes);
379 if (context->etypes_des) {
380 ret = copy_etypes(context, context->etypes_des, &p->etypes_des);
385 if (context->default_realms) {
386 ret = krb5_copy_host_realm(context,
387 context->default_realms, &p->default_realms);
392 ret = _krb5_config_copy(context, context->cf, &p->cf);
396 /* XXX should copy */
402 if(context->warn_dest != NULL)
406 ret = krb5_set_extra_addresses(p, context->extra_addresses);
409 ret = krb5_set_extra_addresses(p, context->ignore_addresses);
413 ret = _krb5_copy_send_to_kdc_func(p, context);
422 krb5_free_context(p);
427 * Frees the krb5_context allocated by krb5_init_context().
429 * @param context context to be freed.
434 void KRB5_LIB_FUNCTION
435 krb5_free_context(krb5_context context)
437 if (context->default_cc_name)
438 free(context->default_cc_name);
439 if (context->default_cc_name_env)
440 free(context->default_cc_name_env);
441 free(context->etypes);
442 free(context->etypes_des);
443 krb5_free_host_realm (context, context->default_realms);
444 krb5_config_file_free (context, context->cf);
445 free_error_table (context->et_list);
446 free(context->cc_ops);
447 free(context->kt_types);
448 krb5_clear_error_message(context);
449 if(context->warn_dest != NULL)
450 krb5_closelog(context, context->warn_dest);
451 krb5_set_extra_addresses(context, NULL);
452 krb5_set_ignore_addresses(context, NULL);
453 krb5_set_send_to_kdc_func(context, NULL, NULL);
455 HEIMDAL_MUTEX_destroy(context->mutex);
456 free(context->mutex);
458 memset(context, 0, sizeof(*context));
463 * Reinit the context from a new set of filenames.
465 * @param context context to add configuration too.
466 * @param filenames array of filenames, end of list is indicated with a NULL filename.
468 * @return Returns 0 to indicate success. Otherwise an kerberos et
469 * error code is returned, see krb5_get_error_message().
474 krb5_error_code KRB5_LIB_FUNCTION
475 krb5_set_config_files(krb5_context context, char **filenames)
478 krb5_config_binding *tmp = NULL;
479 while(filenames != NULL && *filenames != NULL && **filenames != '\0') {
480 ret = krb5_config_parse_file_multi(context, *filenames, &tmp);
481 if(ret != 0 && ret != ENOENT && ret != EACCES) {
482 krb5_config_file_free(context, tmp);
488 /* with this enabled and if there are no config files, Kerberos is
489 considererd disabled */
493 krb5_config_file_free(context, context->cf);
495 ret = init_context_from_config_file(context);
499 static krb5_error_code
500 add_file(char ***pfilenames, int *len, char *file)
502 char **pp = *pfilenames;
505 for(i = 0; i < *len; i++) {
506 if(strcmp(pp[i], file) == 0) {
512 pp = realloc(*pfilenames, (*len + 2) * sizeof(*pp));
526 * `pq' isn't free, it's up the the caller
529 krb5_error_code KRB5_LIB_FUNCTION
530 krb5_prepend_config_files(const char *filelist, char **pq, char ***ret_pp)
545 l = strsep_copy(&q, ":", NULL, 0);
550 krb5_free_config_files(pp);
553 (void)strsep_copy(&p, ":", fn, l + 1);
554 ret = add_file(&pp, &len, fn);
556 krb5_free_config_files(pp);
564 for (i = 0; pq[i] != NULL; i++) {
567 krb5_free_config_files(pp);
570 ret = add_file(&pp, &len, fn);
572 krb5_free_config_files(pp);
583 * Prepend the filename to the global configuration list.
585 * @param filelist a filename to add to the default list of filename
586 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
588 * @return Returns 0 to indicate success. Otherwise an kerberos et
589 * error code is returned, see krb5_get_error_message().
594 krb5_error_code KRB5_LIB_FUNCTION
595 krb5_prepend_config_files_default(const char *filelist, char ***pfilenames)
598 char **defpp, **pp = NULL;
600 ret = krb5_get_default_config_files(&defpp);
604 ret = krb5_prepend_config_files(filelist, defpp, &pp);
605 krb5_free_config_files(defpp);
614 * Get the global configuration list.
616 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
618 * @return Returns 0 to indicate success. Otherwise an kerberos et
619 * error code is returned, see krb5_get_error_message().
624 krb5_error_code KRB5_LIB_FUNCTION
625 krb5_get_default_config_files(char ***pfilenames)
627 const char *files = NULL;
629 if (pfilenames == NULL)
632 files = getenv("KRB5_CONFIG");
634 files = krb5_config_file;
636 return krb5_prepend_config_files(files, NULL, pfilenames);
640 * Free a list of configuration files.
642 * @param filenames list, terminated with a NULL pointer, to be
643 * freed. NULL is an valid argument.
645 * @return Returns 0 to indicate success. Otherwise an kerberos et
646 * error code is returned, see krb5_get_error_message().
651 void KRB5_LIB_FUNCTION
652 krb5_free_config_files(char **filenames)
655 for(p = filenames; p && *p != NULL; p++)
661 * Returns the list of Kerberos encryption types sorted in order of
662 * most preferred to least preferred encryption type. Note that some
663 * encryption types might be disabled, so you need to check with
664 * krb5_enctype_valid() before using the encryption type.
666 * @return list of enctypes, terminated with ETYPE_NULL. Its a static
667 * array completed into the Kerberos library so the content doesn't
673 const krb5_enctype * KRB5_LIB_FUNCTION
674 krb5_kerberos_enctypes(krb5_context context)
676 static const krb5_enctype p[] = {
677 ETYPE_AES256_CTS_HMAC_SHA1_96,
678 ETYPE_AES128_CTS_HMAC_SHA1_96,
681 ETYPE_ARCFOUR_HMAC_MD5,
691 * set `etype' to a malloced list of the default enctypes
694 static krb5_error_code
695 default_etypes(krb5_context context, krb5_enctype **etype)
697 const krb5_enctype *p;
698 krb5_enctype *e = NULL, *ep;
701 p = krb5_kerberos_enctypes(context);
703 for (i = 0; p[i] != ETYPE_NULL; i++) {
704 if (krb5_enctype_valid(context, p[i]) != 0)
706 ep = realloc(e, (n + 2) * sizeof(*e));
709 krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
714 e[n + 1] = ETYPE_NULL;
722 * Set the default encryption types that will be use in communcation
723 * with the KDC, clients and servers.
725 * @param context Kerberos 5 context.
726 * @param etypes Encryption types, array terminated with ETYPE_NULL (0).
728 * @return Returns 0 to indicate success. Otherwise an kerberos et
729 * error code is returned, see krb5_get_error_message().
734 krb5_error_code KRB5_LIB_FUNCTION
735 krb5_set_default_in_tkt_etypes(krb5_context context,
736 const krb5_enctype *etypes)
738 krb5_enctype *p = NULL;
742 for (i = 0; etypes[i]; ++i) {
744 ret = krb5_enctype_valid(context, etypes[i]);
751 krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
754 memmove(p, etypes, i * sizeof(krb5_enctype));
757 free(context->etypes);
763 * Get the default encryption types that will be use in communcation
764 * with the KDC, clients and servers.
766 * @param context Kerberos 5 context.
767 * @param etypes Encryption types, array terminated with
768 * ETYPE_NULL(0), caller should free array with krb5_xfree():
770 * @return Returns 0 to indicate success. Otherwise an kerberos et
771 * error code is returned, see krb5_get_error_message().
776 krb5_error_code KRB5_LIB_FUNCTION
777 krb5_get_default_in_tkt_etypes(krb5_context context,
778 krb5_enctype **etypes)
784 if(context->etypes) {
785 for(i = 0; context->etypes[i]; i++);
789 krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
792 memmove(p, context->etypes, i * sizeof(krb5_enctype));
794 ret = default_etypes(context, &p);
803 * Return the error string for the error code. The caller must not
806 * @param context Kerberos 5 context.
807 * @param code Kerberos error code.
809 * @return the error message matching code
814 const char* KRB5_LIB_FUNCTION
815 krb5_get_err_text(krb5_context context, krb5_error_code code)
817 const char *p = NULL;
819 p = com_right(context->et_list, code);
828 * Init the built-in ets in the Kerberos library.
830 * @param context kerberos context to add the ets too
835 void KRB5_LIB_FUNCTION
836 krb5_init_ets(krb5_context context)
838 if(context->et_list == NULL){
839 krb5_add_et_list(context, initialize_krb5_error_table_r);
840 #if defined(HEIMDAL_LOCALEDIR)
841 bindtextdomain(COM_ERR_BINDDOMAIN_krb5, HEIMDAL_LOCALEDIR);
844 krb5_add_et_list(context, initialize_asn1_error_table_r);
845 #if defined(HEIMDAL_LOCALEDIR)
846 bindtextdomain(COM_ERR_BINDDOMAIN_asn1, HEIMDAL_LOCALEDIR);
849 krb5_add_et_list(context, initialize_heim_error_table_r);
850 #if defined(HEIMDAL_LOCALEDIR)
851 bindtextdomain(COM_ERR_BINDDOMAIN_heim, HEIMDAL_LOCALEDIR);
854 krb5_add_et_list(context, initialize_k524_error_table_r);
855 #if defined(HEIMDAL_LOCALEDIR)
856 bindtextdomain(COM_ERR_BINDDOMAIN_k524, HEIMDAL_LOCALEDIR);
860 krb5_add_et_list(context, initialize_hx_error_table_r);
861 #if defined(HEIMDAL_LOCALEDIR)
862 bindtextdomain(COM_ERR_BINDDOMAIN_hx, HEIMDAL_LOCALEDIR);
869 * Make the kerberos library default to the admin KDC.
871 * @param context Kerberos 5 context.
872 * @param flag boolean flag to select if the use the admin KDC or not.
877 void KRB5_LIB_FUNCTION
878 krb5_set_use_admin_kdc (krb5_context context, krb5_boolean flag)
880 context->use_admin_kdc = flag;
884 * Make the kerberos library default to the admin KDC.
886 * @param context Kerberos 5 context.
888 * @return boolean flag to telling the context will use admin KDC as the default KDC.
893 krb5_boolean KRB5_LIB_FUNCTION
894 krb5_get_use_admin_kdc (krb5_context context)
896 return context->use_admin_kdc;
900 * Add extra address to the address list that the library will add to
901 * the client's address list when communicating with the KDC.
903 * @param context Kerberos 5 context.
904 * @param addresses addreses to add
906 * @return Returns 0 to indicate success. Otherwise an kerberos et
907 * error code is returned, see krb5_get_error_message().
912 krb5_error_code KRB5_LIB_FUNCTION
913 krb5_add_extra_addresses(krb5_context context, krb5_addresses *addresses)
916 if(context->extra_addresses)
917 return krb5_append_addresses(context,
918 context->extra_addresses, addresses);
920 return krb5_set_extra_addresses(context, addresses);
924 * Set extra address to the address list that the library will add to
925 * the client's address list when communicating with the KDC.
927 * @param context Kerberos 5 context.
928 * @param addresses addreses to set
930 * @return Returns 0 to indicate success. Otherwise an kerberos et
931 * error code is returned, see krb5_get_error_message().
936 krb5_error_code KRB5_LIB_FUNCTION
937 krb5_set_extra_addresses(krb5_context context, const krb5_addresses *addresses)
939 if(context->extra_addresses)
940 krb5_free_addresses(context, context->extra_addresses);
942 if(addresses == NULL) {
943 if(context->extra_addresses != NULL) {
944 free(context->extra_addresses);
945 context->extra_addresses = NULL;
949 if(context->extra_addresses == NULL) {
950 context->extra_addresses = malloc(sizeof(*context->extra_addresses));
951 if(context->extra_addresses == NULL) {
952 krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
956 return krb5_copy_addresses(context, addresses, context->extra_addresses);
960 * Get extra address to the address list that the library will add to
961 * the client's address list when communicating with the KDC.
963 * @param context Kerberos 5 context.
964 * @param addresses addreses to set
966 * @return Returns 0 to indicate success. Otherwise an kerberos et
967 * error code is returned, see krb5_get_error_message().
972 krb5_error_code KRB5_LIB_FUNCTION
973 krb5_get_extra_addresses(krb5_context context, krb5_addresses *addresses)
975 if(context->extra_addresses == NULL) {
976 memset(addresses, 0, sizeof(*addresses));
979 return krb5_copy_addresses(context,context->extra_addresses, addresses);
983 * Add extra addresses to ignore when fetching addresses from the
984 * underlaying operating system.
986 * @param context Kerberos 5 context.
987 * @param addresses addreses to ignore
989 * @return Returns 0 to indicate success. Otherwise an kerberos et
990 * error code is returned, see krb5_get_error_message().
995 krb5_error_code KRB5_LIB_FUNCTION
996 krb5_add_ignore_addresses(krb5_context context, krb5_addresses *addresses)
999 if(context->ignore_addresses)
1000 return krb5_append_addresses(context,
1001 context->ignore_addresses, addresses);
1003 return krb5_set_ignore_addresses(context, addresses);
1007 * Set extra addresses to ignore when fetching addresses from the
1008 * underlaying operating system.
1010 * @param context Kerberos 5 context.
1011 * @param addresses addreses to ignore
1013 * @return Returns 0 to indicate success. Otherwise an kerberos et
1014 * error code is returned, see krb5_get_error_message().
1019 krb5_error_code KRB5_LIB_FUNCTION
1020 krb5_set_ignore_addresses(krb5_context context, const krb5_addresses *addresses)
1022 if(context->ignore_addresses)
1023 krb5_free_addresses(context, context->ignore_addresses);
1024 if(addresses == NULL) {
1025 if(context->ignore_addresses != NULL) {
1026 free(context->ignore_addresses);
1027 context->ignore_addresses = NULL;
1031 if(context->ignore_addresses == NULL) {
1032 context->ignore_addresses = malloc(sizeof(*context->ignore_addresses));
1033 if(context->ignore_addresses == NULL) {
1034 krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
1038 return krb5_copy_addresses(context, addresses, context->ignore_addresses);
1042 * Get extra addresses to ignore when fetching addresses from the
1043 * underlaying operating system.
1045 * @param context Kerberos 5 context.
1046 * @param addresses list addreses ignored
1048 * @return Returns 0 to indicate success. Otherwise an kerberos et
1049 * error code is returned, see krb5_get_error_message().
1054 krb5_error_code KRB5_LIB_FUNCTION
1055 krb5_get_ignore_addresses(krb5_context context, krb5_addresses *addresses)
1057 if(context->ignore_addresses == NULL) {
1058 memset(addresses, 0, sizeof(*addresses));
1061 return krb5_copy_addresses(context, context->ignore_addresses, addresses);
1065 * Set version of fcache that the library should use.
1067 * @param context Kerberos 5 context.
1068 * @param version version number.
1070 * @return Returns 0 to indicate success. Otherwise an kerberos et
1071 * error code is returned, see krb5_get_error_message().
1076 krb5_error_code KRB5_LIB_FUNCTION
1077 krb5_set_fcache_version(krb5_context context, int version)
1079 context->fcache_vno = version;
1084 * Get version of fcache that the library should use.
1086 * @param context Kerberos 5 context.
1087 * @param version version number.
1089 * @return Returns 0 to indicate success. Otherwise an kerberos et
1090 * error code is returned, see krb5_get_error_message().
1095 krb5_error_code KRB5_LIB_FUNCTION
1096 krb5_get_fcache_version(krb5_context context, int *version)
1098 *version = context->fcache_vno;
1103 * Runtime check if the Kerberos library was complied with thread support.
1105 * @return TRUE if the library was compiled with thread support, FALSE if not.
1111 krb5_boolean KRB5_LIB_FUNCTION
1112 krb5_is_thread_safe(void)
1114 #ifdef ENABLE_PTHREAD_SUPPORT
1122 * Set if the library should use DNS to canonicalize hostnames.
1124 * @param context Kerberos 5 context.
1125 * @param flag if its dns canonicalizion is used or not.
1130 void KRB5_LIB_FUNCTION
1131 krb5_set_dns_canonicalize_hostname (krb5_context context, krb5_boolean flag)
1134 context->flags |= KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME;
1136 context->flags &= ~KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME;
1140 * Get if the library uses DNS to canonicalize hostnames.
1142 * @param context Kerberos 5 context.
1144 * @return return non zero if the library uses DNS to canonicalize hostnames.
1149 krb5_boolean KRB5_LIB_FUNCTION
1150 krb5_get_dns_canonicalize_hostname (krb5_context context)
1152 return (context->flags & KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME) ? 1 : 0;
1156 * Get current offset in time to the KDC.
1158 * @param context Kerberos 5 context.
1159 * @param sec seconds part of offset.
1160 * @param usec micro seconds part of offset.
1162 * @return returns zero
1167 krb5_error_code KRB5_LIB_FUNCTION
1168 krb5_get_kdc_sec_offset (krb5_context context, int32_t *sec, int32_t *usec)
1171 *sec = context->kdc_sec_offset;
1173 *usec = context->kdc_usec_offset;
1178 * Set current offset in time to the KDC.
1180 * @param context Kerberos 5 context.
1181 * @param sec seconds part of offset.
1182 * @param usec micro seconds part of offset.
1184 * @return returns zero
1189 krb5_error_code KRB5_LIB_FUNCTION
1190 krb5_set_kdc_sec_offset (krb5_context context, int32_t sec, int32_t usec)
1192 context->kdc_sec_offset = sec;
1194 context->kdc_usec_offset = usec;
1199 * Get max time skew allowed.
1201 * @param context Kerberos 5 context.
1203 * @return timeskew in seconds.
1208 time_t KRB5_LIB_FUNCTION
1209 krb5_get_max_time_skew (krb5_context context)
1211 return context->max_skew;
1215 * Set max time skew allowed.
1217 * @param context Kerberos 5 context.
1218 * @param t timeskew in seconds.
1223 void KRB5_LIB_FUNCTION
1224 krb5_set_max_time_skew (krb5_context context, time_t t)
1226 context->max_skew = t;
1230 * Init encryption types in len, val with etypes.
1232 * @param context Kerberos 5 context.
1233 * @param len output length of val.
1234 * @param val output array of enctypes.
1235 * @param etypes etypes to set val and len to, if NULL, use default enctypes.
1237 * @return Returns 0 to indicate success. Otherwise an kerberos et
1238 * error code is returned, see krb5_get_error_message().
1243 krb5_error_code KRB5_LIB_FUNCTION
1244 krb5_init_etype (krb5_context context,
1247 const krb5_enctype *etypes)
1250 krb5_error_code ret;
1251 krb5_enctype *tmp = NULL;
1254 if (etypes == NULL) {
1255 ret = krb5_get_default_in_tkt_etypes(context, &tmp);
1261 for (i = 0; etypes[i]; ++i)
1264 *val = malloc(i * sizeof(**val));
1265 if (i != 0 && *val == NULL) {
1267 krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
1280 * Allow homedir accces
1283 static HEIMDAL_MUTEX homedir_mutex = HEIMDAL_MUTEX_INITIALIZER;
1284 static krb5_boolean allow_homedir = TRUE;
1287 _krb5_homedir_access(krb5_context context)
1291 /* is never allowed for root */
1295 if (context && (context->flags & KRB5_CTX_F_HOMEDIR_ACCESS) == 0)
1298 HEIMDAL_MUTEX_lock(&homedir_mutex);
1299 allow = allow_homedir;
1300 HEIMDAL_MUTEX_unlock(&homedir_mutex);
1305 * Enable and disable home directory access on either the global state
1306 * or the krb5_context state. By calling krb5_set_home_dir_access()
1307 * with context set to NULL, the global state is configured otherwise
1308 * the state for the krb5_context is modified.
1310 * For home directory access to be allowed, both the global state and
1311 * the krb5_context state have to be allowed.
1313 * Administrator (root user), never uses the home directory.
1315 * @param context a Kerberos 5 context or NULL
1316 * @param allow allow if TRUE home directory
1317 * @return the old value
1322 krb5_set_home_dir_access(krb5_context context, krb5_boolean allow)
1326 old = (context->flags & KRB5_CTX_F_HOMEDIR_ACCESS) ? TRUE : FALSE;
1328 context->flags |= KRB5_CTX_F_HOMEDIR_ACCESS;
1330 context->flags &= ~KRB5_CTX_F_HOMEDIR_ACCESS;
1332 HEIMDAL_MUTEX_lock(&homedir_mutex);
1333 old = allow_homedir;
1334 allow_homedir = allow;
1335 HEIMDAL_MUTEX_unlock(&homedir_mutex);