use DES_set_key_unchecked().
[heimdal.git] / lib / krb5 / context.c
bloba04220a6167dc3fff4eae6bceaf0523ce4a89052
1 /*
2 * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
31 * SUCH DAMAGE.
34 #include "krb5_locl.h"
35 #include <com_err.h>
37 RCSID("$Id$");
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) \
44 do { \
45 if (krb5_config_get_bool_default((C), NULL, (D),"libdefaults", F, NULL)) { \
46 (C)->O |= V; \
47 } \
48 } while(0)
51 * Set the list of etypes `ret_etypes' from the configuration variable
52 * `name'
55 static krb5_error_code
56 set_etypes (krb5_context context,
57 const char *name,
58 krb5_enctype **ret_enctypes)
60 char **etypes_str;
61 krb5_enctype *etypes = NULL;
63 etypes_str = krb5_config_get_strings(context, NULL, "libdefaults",
64 name, NULL);
65 if(etypes_str){
66 int i, j, k;
67 for(i = 0; etypes_str[i]; i++);
68 etypes = malloc((i+1) * sizeof(*etypes));
69 if (etypes == NULL) {
70 krb5_config_free_strings (etypes_str);
71 krb5_set_error_string (context, "malloc: out of memory");
72 return ENOMEM;
74 for(j = 0, k = 0; j < i; j++) {
75 krb5_enctype e;
76 if(krb5_string_to_enctype(context, etypes_str[j], &e) != 0)
77 continue;
78 if (krb5_enctype_valid(context, e) != 0)
79 continue;
80 etypes[k++] = e;
82 etypes[k] = ETYPE_NULL;
83 krb5_config_free_strings(etypes_str);
85 *ret_enctypes = etypes;
86 return 0;
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)
96 krb5_error_code ret;
97 const char * tmp;
98 krb5_enctype *tmptypes;
100 INIT_FIELD(context, time, max_skew, 5 * 60, "clockskew");
101 INIT_FIELD(context, time, kdc_timeout, 3, "kdc_timeout");
102 INIT_FIELD(context, int, max_retries, 3, "max_retries");
104 INIT_FIELD(context, string, http_proxy, NULL, "http_proxy");
106 ret = set_etypes (context, "default_etypes", &tmptypes);
107 if(ret)
108 return ret;
109 free(context->etypes);
110 context->etypes = tmptypes;
112 ret = set_etypes (context, "default_etypes_des", &tmptypes);
113 if(ret)
114 return ret;
115 free(context->etypes_des);
116 context->etypes_des = tmptypes;
118 /* default keytab name */
119 tmp = NULL;
120 if(!issuid())
121 tmp = getenv("KRB5_KTNAME");
122 if(tmp != NULL)
123 context->default_keytab = tmp;
124 else
125 INIT_FIELD(context, string, default_keytab,
126 KEYTAB_DEFAULT, "default_keytab_name");
128 INIT_FIELD(context, string, default_keytab_modify,
129 NULL, "default_keytab_modify_name");
131 INIT_FIELD(context, string, time_fmt,
132 "%Y-%m-%dT%H:%M:%S", "time_format");
134 INIT_FIELD(context, string, date_fmt,
135 "%Y-%m-%d", "date_format");
137 INIT_FIELD(context, bool, log_utc,
138 FALSE, "log_utc");
142 /* init dns-proxy slime */
143 tmp = krb5_config_get_string(context, NULL, "libdefaults",
144 "dns_proxy", NULL);
145 if(tmp)
146 roken_gethostby_setup(context->http_proxy, tmp);
147 krb5_free_host_realm (context, context->default_realms);
148 context->default_realms = NULL;
151 krb5_addresses addresses;
152 char **adr, **a;
154 krb5_set_extra_addresses(context, NULL);
155 adr = krb5_config_get_strings(context, NULL,
156 "libdefaults",
157 "extra_addresses",
158 NULL);
159 memset(&addresses, 0, sizeof(addresses));
160 for(a = adr; a && *a; a++) {
161 ret = krb5_parse_address(context, *a, &addresses);
162 if (ret == 0) {
163 krb5_add_extra_addresses(context, &addresses);
164 krb5_free_addresses(context, &addresses);
167 krb5_config_free_strings(adr);
169 krb5_set_ignore_addresses(context, NULL);
170 adr = krb5_config_get_strings(context, NULL,
171 "libdefaults",
172 "ignore_addresses",
173 NULL);
174 memset(&addresses, 0, sizeof(addresses));
175 for(a = adr; a && *a; a++) {
176 ret = krb5_parse_address(context, *a, &addresses);
177 if (ret == 0) {
178 krb5_add_ignore_addresses(context, &addresses);
179 krb5_free_addresses(context, &addresses);
182 krb5_config_free_strings(adr);
185 INIT_FIELD(context, bool, scan_interfaces, TRUE, "scan_interfaces");
186 INIT_FIELD(context, int, fcache_vno, 0, "fcache_version");
187 /* prefer dns_lookup_kdc over srv_lookup. */
188 INIT_FIELD(context, bool, srv_lookup, TRUE, "srv_lookup");
189 INIT_FIELD(context, bool, srv_lookup, context->srv_lookup, "dns_lookup_kdc");
190 INIT_FIELD(context, int, large_msg_size, 1400, "large_message_size");
191 INIT_FLAG(context, flags, KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME, TRUE, "dns_canonicalize_hostname");
192 INIT_FLAG(context, flags, KRB5_CTX_F_CHECK_PAC, TRUE, "check_pac");
193 context->default_cc_name = NULL;
194 context->default_cc_name_set = 0;
195 return 0;
199 * Initializes the context structure and reads the configuration file
200 * /etc/krb5.conf. The structure should be freed by calling
201 * krb5_free_context() when it is no longer being used.
203 * @param context pointer to returned context
205 * @return Returns 0 to indicate success. Otherwise an errno code is
206 * returned. Failure means either that something bad happened during
207 * initialization (typically ENOMEM) or that Kerberos should not be
208 * used ENXIO.
210 * @ingroup krb5
213 krb5_error_code KRB5_LIB_FUNCTION
214 krb5_init_context(krb5_context *context)
216 krb5_context p;
217 krb5_error_code ret;
218 char **files;
220 *context = NULL;
222 p = calloc(1, sizeof(*p));
223 if(!p)
224 return ENOMEM;
226 p->mutex = malloc(sizeof(HEIMDAL_MUTEX));
227 if (p->mutex == NULL) {
228 free(p);
229 return ENOMEM;
231 HEIMDAL_MUTEX_init(p->mutex);
233 ret = krb5_get_default_config_files(&files);
234 if(ret)
235 goto out;
236 ret = krb5_set_config_files(p, files);
237 krb5_free_config_files(files);
238 if(ret)
239 goto out;
241 /* init error tables */
242 krb5_init_ets(p);
244 p->cc_ops = NULL;
245 p->num_cc_ops = 0;
246 krb5_cc_register(p, &krb5_acc_ops, TRUE);
247 krb5_cc_register(p, &krb5_fcc_ops, TRUE);
248 krb5_cc_register(p, &krb5_mcc_ops, TRUE);
249 krb5_cc_register(p, &krb5_scc_ops, TRUE);
250 #ifdef HAVE_KCM
251 krb5_cc_register(p, &krb5_kcm_ops, TRUE);
252 #endif
254 p->num_kt_types = 0;
255 p->kt_types = NULL;
256 krb5_kt_register (p, &krb5_fkt_ops);
257 krb5_kt_register (p, &krb5_wrfkt_ops);
258 krb5_kt_register (p, &krb5_javakt_ops);
259 krb5_kt_register (p, &krb5_mkt_ops);
260 krb5_kt_register (p, &krb5_akf_ops);
261 krb5_kt_register (p, &krb4_fkt_ops);
262 krb5_kt_register (p, &krb5_srvtab_fkt_ops);
263 krb5_kt_register (p, &krb5_any_ops);
265 out:
266 if(ret) {
267 krb5_free_context(p);
268 p = NULL;
270 *context = p;
271 return ret;
275 * Frees the krb5_context allocated by krb5_init_context().
277 * @param context context to be freed.
279 * @ingroup krb5
282 void KRB5_LIB_FUNCTION
283 krb5_free_context(krb5_context context)
285 if (context->default_cc_name)
286 free(context->default_cc_name);
287 if (context->default_cc_name_env)
288 free(context->default_cc_name_env);
289 free(context->etypes);
290 free(context->etypes_des);
291 krb5_free_host_realm (context, context->default_realms);
292 krb5_config_file_free (context, context->cf);
293 free_error_table (context->et_list);
294 free(context->cc_ops);
295 free(context->kt_types);
296 krb5_clear_error_string(context);
297 if(context->warn_dest != NULL)
298 krb5_closelog(context, context->warn_dest);
299 krb5_set_extra_addresses(context, NULL);
300 krb5_set_ignore_addresses(context, NULL);
301 krb5_set_send_to_kdc_func(context, NULL, NULL);
302 if (context->mutex != NULL) {
303 HEIMDAL_MUTEX_destroy(context->mutex);
304 free(context->mutex);
306 memset(context, 0, sizeof(*context));
307 free(context);
311 * Reinit the context from a new set of filenames.
313 * @param context context to add configuration too.
314 * @param filenames array of filenames, end of list is indicated with a NULL filename.
316 * @return Returns 0 to indicate success. Otherwise an kerberos et
317 * error code is returned, see krb5_get_error_message().
319 * @ingroup krb5
322 krb5_error_code KRB5_LIB_FUNCTION
323 krb5_set_config_files(krb5_context context, char **filenames)
325 krb5_error_code ret;
326 krb5_config_binding *tmp = NULL;
327 while(filenames != NULL && *filenames != NULL && **filenames != '\0') {
328 ret = krb5_config_parse_file_multi(context, *filenames, &tmp);
329 if(ret != 0 && ret != ENOENT && ret != EACCES) {
330 krb5_config_file_free(context, tmp);
331 return ret;
333 filenames++;
335 #if 0
336 /* with this enabled and if there are no config files, Kerberos is
337 considererd disabled */
338 if(tmp == NULL)
339 return ENXIO;
340 #endif
341 krb5_config_file_free(context, context->cf);
342 context->cf = tmp;
343 ret = init_context_from_config_file(context);
344 return ret;
347 static krb5_error_code
348 add_file(char ***pfilenames, int *len, char *file)
350 char **pp = *pfilenames;
351 int i;
353 for(i = 0; i < *len; i++) {
354 if(strcmp(pp[i], file) == 0) {
355 free(file);
356 return 0;
360 pp = realloc(*pfilenames, (*len + 2) * sizeof(*pp));
361 if (pp == NULL) {
362 free(file);
363 return ENOMEM;
366 pp[*len] = file;
367 pp[*len + 1] = NULL;
368 *pfilenames = pp;
369 *len += 1;
370 return 0;
374 * `pq' isn't free, it's up the the caller
377 krb5_error_code KRB5_LIB_FUNCTION
378 krb5_prepend_config_files(const char *filelist, char **pq, char ***ret_pp)
380 krb5_error_code ret;
381 const char *p, *q;
382 char **pp;
383 int len;
384 char *fn;
386 pp = NULL;
388 len = 0;
389 p = filelist;
390 while(1) {
391 ssize_t l;
392 q = p;
393 l = strsep_copy(&q, ":", NULL, 0);
394 if(l == -1)
395 break;
396 fn = malloc(l + 1);
397 if(fn == NULL) {
398 krb5_free_config_files(pp);
399 return ENOMEM;
401 l = strsep_copy(&p, ":", fn, l + 1);
402 ret = add_file(&pp, &len, fn);
403 if (ret) {
404 krb5_free_config_files(pp);
405 return ret;
409 if (pq != NULL) {
410 int i;
412 for (i = 0; pq[i] != NULL; i++) {
413 fn = strdup(pq[i]);
414 if (fn == NULL) {
415 krb5_free_config_files(pp);
416 return ENOMEM;
418 ret = add_file(&pp, &len, fn);
419 if (ret) {
420 krb5_free_config_files(pp);
421 return ret;
426 *ret_pp = pp;
427 return 0;
431 * Prepend the filename to the global configuration list.
433 * @param filelist a filename to add to the default list of filename
434 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
436 * @return Returns 0 to indicate success. Otherwise an kerberos et
437 * error code is returned, see krb5_get_error_message().
439 * @ingroup krb5
442 krb5_error_code KRB5_LIB_FUNCTION
443 krb5_prepend_config_files_default(const char *filelist, char ***pfilenames)
445 krb5_error_code ret;
446 char **defpp, **pp = NULL;
448 ret = krb5_get_default_config_files(&defpp);
449 if (ret)
450 return ret;
452 ret = krb5_prepend_config_files(filelist, defpp, &pp);
453 krb5_free_config_files(defpp);
454 if (ret) {
455 return ret;
457 *pfilenames = pp;
458 return 0;
462 * Get the global configuration list.
464 * @param pfilenames return array of filenames, should be freed with krb5_free_config_files().
466 * @return Returns 0 to indicate success. Otherwise an kerberos et
467 * error code is returned, see krb5_get_error_message().
469 * @ingroup krb5
472 krb5_error_code KRB5_LIB_FUNCTION
473 krb5_get_default_config_files(char ***pfilenames)
475 const char *files = NULL;
477 if (pfilenames == NULL)
478 return EINVAL;
479 if(!issuid())
480 files = getenv("KRB5_CONFIG");
481 if (files == NULL)
482 files = krb5_config_file;
484 return krb5_prepend_config_files(files, NULL, pfilenames);
488 * Free a list of configuration files.
490 * @param filenames list to be freed.
492 * @return Returns 0 to indicate success. Otherwise an kerberos et
493 * error code is returned, see krb5_get_error_message().
495 * @ingroup krb5
498 void KRB5_LIB_FUNCTION
499 krb5_free_config_files(char **filenames)
501 char **p;
502 for(p = filenames; *p != NULL; p++)
503 free(*p);
504 free(filenames);
508 * Returns the list of Kerberos encryption types sorted in order of
509 * most preferred to least preferred encryption type. Note that some
510 * encryption types might be disabled, so you need to check with
511 * krb5_enctype_valid() before using the encryption type.
513 * @return list of enctypes, terminated with ETYPE_NULL. Its a static
514 * array completed into the Kerberos library so the content doesn't
515 * need to be freed.
517 * @ingroup krb5
520 const krb5_enctype * KRB5_LIB_FUNCTION
521 krb5_kerberos_enctypes(krb5_context context)
523 static const krb5_enctype p[] = {
524 ETYPE_AES256_CTS_HMAC_SHA1_96,
525 ETYPE_AES128_CTS_HMAC_SHA1_96,
526 ETYPE_DES3_CBC_SHA1,
527 ETYPE_DES3_CBC_MD5,
528 ETYPE_ARCFOUR_HMAC_MD5,
529 ETYPE_DES_CBC_MD5,
530 ETYPE_DES_CBC_MD4,
531 ETYPE_DES_CBC_CRC,
532 ETYPE_NULL
534 return p;
538 * set `etype' to a malloced list of the default enctypes
541 static krb5_error_code
542 default_etypes(krb5_context context, krb5_enctype **etype)
544 const krb5_enctype *p;
545 krb5_enctype *e = NULL, *ep;
546 int i, n = 0;
548 p = krb5_kerberos_enctypes(context);
550 for (i = 0; p[i] != ETYPE_NULL; i++) {
551 if (krb5_enctype_valid(context, p[i]) != 0)
552 continue;
553 ep = realloc(e, (n + 2) * sizeof(*e));
554 if (ep == NULL) {
555 free(e);
556 krb5_set_error_string (context, "malloc: out of memory");
557 return ENOMEM;
559 e = ep;
560 e[n] = p[i];
561 e[n + 1] = ETYPE_NULL;
562 n++;
564 *etype = e;
565 return 0;
569 * Set the default encryption types that will be use in communcation
570 * with the KDC, clients and servers.
572 * @param context Kerberos 5 context.
573 * @param etypes Encryption types, array terminated with ETYPE_NULL (0).
575 * @return Returns 0 to indicate success. Otherwise an kerberos et
576 * error code is returned, see krb5_get_error_message().
578 * @ingroup krb5
581 krb5_error_code KRB5_LIB_FUNCTION
582 krb5_set_default_in_tkt_etypes(krb5_context context,
583 const krb5_enctype *etypes)
585 krb5_enctype *p = NULL;
586 int i;
588 if(etypes) {
589 for (i = 0; etypes[i]; ++i) {
590 krb5_error_code ret;
591 ret = krb5_enctype_valid(context, etypes[i]);
592 if (ret)
593 return ret;
595 ++i;
596 ALLOC(p, i);
597 if(!p) {
598 krb5_set_error_string (context, "malloc: out of memory");
599 return ENOMEM;
601 memmove(p, etypes, i * sizeof(krb5_enctype));
603 if(context->etypes)
604 free(context->etypes);
605 context->etypes = p;
606 return 0;
610 * Get the default encryption types that will be use in communcation
611 * with the KDC, clients and servers.
613 * @param context Kerberos 5 context.
614 * @param etypes Encryption types, array terminated with
615 * ETYPE_NULL(0), caller should free array with krb5_xfree():
617 * @return Returns 0 to indicate success. Otherwise an kerberos et
618 * error code is returned, see krb5_get_error_message().
620 * @ingroup krb5
623 krb5_error_code KRB5_LIB_FUNCTION
624 krb5_get_default_in_tkt_etypes(krb5_context context,
625 krb5_enctype **etypes)
627 krb5_enctype *p;
628 int i;
629 krb5_error_code ret;
631 if(context->etypes) {
632 for(i = 0; context->etypes[i]; i++);
633 ++i;
634 ALLOC(p, i);
635 if(!p) {
636 krb5_set_error_string (context, "malloc: out of memory");
637 return ENOMEM;
639 memmove(p, context->etypes, i * sizeof(krb5_enctype));
640 } else {
641 ret = default_etypes(context, &p);
642 if (ret)
643 return ret;
645 *etypes = p;
646 return 0;
650 * Return the error string for the error code. The caller must not
651 * free the string.
653 * @param context Kerberos 5 context.
654 * @param code Kerberos error code.
656 * @return the error message matching code
658 * @ingroup krb5
661 const char* KRB5_LIB_FUNCTION
662 krb5_get_err_text(krb5_context context, krb5_error_code code)
664 const char *p = NULL;
665 if(context != NULL)
666 p = com_right(context->et_list, code);
667 if(p == NULL)
668 p = strerror(code);
669 if (p == NULL)
670 p = "Unknown error";
671 return p;
675 * Init the built-in ets in the Kerberos library.
677 * @param context kerberos context to add the ets too
679 * @ingroup krb5
682 void KRB5_LIB_FUNCTION
683 krb5_init_ets(krb5_context context)
685 if(context->et_list == NULL){
686 krb5_add_et_list(context, initialize_krb5_error_table_r);
687 krb5_add_et_list(context, initialize_asn1_error_table_r);
688 krb5_add_et_list(context, initialize_heim_error_table_r);
689 krb5_add_et_list(context, initialize_k524_error_table_r);
690 #ifdef PKINIT
691 krb5_add_et_list(context, initialize_hx_error_table_r);
692 #endif
697 * Make the kerberos library default to the admin KDC.
699 * @param context Kerberos 5 context.
700 * @param flag boolean flag to select if the use the admin KDC or not.
702 * @ingroup krb5
705 void KRB5_LIB_FUNCTION
706 krb5_set_use_admin_kdc (krb5_context context, krb5_boolean flag)
708 context->use_admin_kdc = flag;
712 * Make the kerberos library default to the admin KDC.
714 * @param context Kerberos 5 context.
716 * @return boolean flag to telling the context will use admin KDC as the default KDC.
718 * @ingroup krb5
721 krb5_boolean KRB5_LIB_FUNCTION
722 krb5_get_use_admin_kdc (krb5_context context)
724 return context->use_admin_kdc;
728 * Add extra address to the address list that the library will add to
729 * the client's address list when communicating with the KDC.
731 * @param context Kerberos 5 context.
732 * @param addresses addreses to add
734 * @return Returns 0 to indicate success. Otherwise an kerberos et
735 * error code is returned, see krb5_get_error_message().
737 * @ingroup krb5
740 krb5_error_code KRB5_LIB_FUNCTION
741 krb5_add_extra_addresses(krb5_context context, krb5_addresses *addresses)
744 if(context->extra_addresses)
745 return krb5_append_addresses(context,
746 context->extra_addresses, addresses);
747 else
748 return krb5_set_extra_addresses(context, addresses);
752 * Set extra address to the address list that the library will add to
753 * the client's address list when communicating with the KDC.
755 * @param context Kerberos 5 context.
756 * @param addresses addreses to set
758 * @return Returns 0 to indicate success. Otherwise an kerberos et
759 * error code is returned, see krb5_get_error_message().
761 * @ingroup krb5
764 krb5_error_code KRB5_LIB_FUNCTION
765 krb5_set_extra_addresses(krb5_context context, const krb5_addresses *addresses)
767 if(context->extra_addresses)
768 krb5_free_addresses(context, context->extra_addresses);
770 if(addresses == NULL) {
771 if(context->extra_addresses != NULL) {
772 free(context->extra_addresses);
773 context->extra_addresses = NULL;
775 return 0;
777 if(context->extra_addresses == NULL) {
778 context->extra_addresses = malloc(sizeof(*context->extra_addresses));
779 if(context->extra_addresses == NULL) {
780 krb5_set_error_string (context, "malloc: out of memory");
781 return ENOMEM;
784 return krb5_copy_addresses(context, addresses, context->extra_addresses);
788 * Get extra address to the address list that the library will add to
789 * the client's address list when communicating with the KDC.
791 * @param context Kerberos 5 context.
792 * @param addresses addreses to set
794 * @return Returns 0 to indicate success. Otherwise an kerberos et
795 * error code is returned, see krb5_get_error_message().
797 * @ingroup krb5
800 krb5_error_code KRB5_LIB_FUNCTION
801 krb5_get_extra_addresses(krb5_context context, krb5_addresses *addresses)
803 if(context->extra_addresses == NULL) {
804 memset(addresses, 0, sizeof(*addresses));
805 return 0;
807 return krb5_copy_addresses(context,context->extra_addresses, addresses);
811 * Add extra addresses to ignore when fetching addresses from the
812 * underlaying operating system.
814 * @param context Kerberos 5 context.
815 * @param addresses addreses to ignore
817 * @return Returns 0 to indicate success. Otherwise an kerberos et
818 * error code is returned, see krb5_get_error_message().
820 * @ingroup krb5
823 krb5_error_code KRB5_LIB_FUNCTION
824 krb5_add_ignore_addresses(krb5_context context, krb5_addresses *addresses)
827 if(context->ignore_addresses)
828 return krb5_append_addresses(context,
829 context->ignore_addresses, addresses);
830 else
831 return krb5_set_ignore_addresses(context, addresses);
835 * Set extra addresses to ignore when fetching addresses from the
836 * underlaying operating system.
838 * @param context Kerberos 5 context.
839 * @param addresses addreses to ignore
841 * @return Returns 0 to indicate success. Otherwise an kerberos et
842 * error code is returned, see krb5_get_error_message().
844 * @ingroup krb5
847 krb5_error_code KRB5_LIB_FUNCTION
848 krb5_set_ignore_addresses(krb5_context context, const krb5_addresses *addresses)
850 if(context->ignore_addresses)
851 krb5_free_addresses(context, context->ignore_addresses);
852 if(addresses == NULL) {
853 if(context->ignore_addresses != NULL) {
854 free(context->ignore_addresses);
855 context->ignore_addresses = NULL;
857 return 0;
859 if(context->ignore_addresses == NULL) {
860 context->ignore_addresses = malloc(sizeof(*context->ignore_addresses));
861 if(context->ignore_addresses == NULL) {
862 krb5_set_error_string (context, "malloc: out of memory");
863 return ENOMEM;
866 return krb5_copy_addresses(context, addresses, context->ignore_addresses);
870 * Get extra addresses to ignore when fetching addresses from the
871 * underlaying operating system.
873 * @param context Kerberos 5 context.
874 * @param addresses list addreses ignored
876 * @return Returns 0 to indicate success. Otherwise an kerberos et
877 * error code is returned, see krb5_get_error_message().
879 * @ingroup krb5
882 krb5_error_code KRB5_LIB_FUNCTION
883 krb5_get_ignore_addresses(krb5_context context, krb5_addresses *addresses)
885 if(context->ignore_addresses == NULL) {
886 memset(addresses, 0, sizeof(*addresses));
887 return 0;
889 return krb5_copy_addresses(context, context->ignore_addresses, addresses);
893 * Set version of fcache that the library should use.
895 * @param context Kerberos 5 context.
896 * @param version version number.
898 * @return Returns 0 to indicate success. Otherwise an kerberos et
899 * error code is returned, see krb5_get_error_message().
901 * @ingroup krb5
904 krb5_error_code KRB5_LIB_FUNCTION
905 krb5_set_fcache_version(krb5_context context, int version)
907 context->fcache_vno = version;
908 return 0;
912 * Get version of fcache that the library should use.
914 * @param context Kerberos 5 context.
915 * @param version version number.
917 * @return Returns 0 to indicate success. Otherwise an kerberos et
918 * error code is returned, see krb5_get_error_message().
920 * @ingroup krb5
923 krb5_error_code KRB5_LIB_FUNCTION
924 krb5_get_fcache_version(krb5_context context, int *version)
926 *version = context->fcache_vno;
927 return 0;
931 * Runtime check if the Kerberos library was complied with thread support.
933 * @return TRUE if the library was compiled with thread support, FALSE if not.
935 * @ingroup krb5
939 krb5_boolean KRB5_LIB_FUNCTION
940 krb5_is_thread_safe(void)
942 #ifdef ENABLE_PTHREAD_SUPPORT
943 return TRUE;
944 #else
945 return FALSE;
946 #endif
950 * Set if the library should use DNS to canonicalize hostnames.
952 * @param context Kerberos 5 context.
953 * @param flag if its dns canonicalizion is used or not.
955 * @ingroup krb5
958 void KRB5_LIB_FUNCTION
959 krb5_set_dns_canonicalize_hostname (krb5_context context, krb5_boolean flag)
961 if (flag)
962 context->flags |= KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME;
963 else
964 context->flags &= ~KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME;
968 * Get if the library uses DNS to canonicalize hostnames.
970 * @param context Kerberos 5 context.
972 * @return return non zero if the library uses DNS to canonicalize hostnames.
974 * @ingroup krb5
977 krb5_boolean KRB5_LIB_FUNCTION
978 krb5_get_dns_canonicalize_hostname (krb5_context context)
980 return (context->flags & KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME) ? 1 : 0;
984 * Get current offset in time to the KDC.
986 * @param context Kerberos 5 context.
987 * @param sec seconds part of offset.
988 * @param usec micro seconds part of offset.
990 * @return return non zero if the library uses DNS to canonicalize hostnames.
992 * @ingroup krb5
995 krb5_error_code KRB5_LIB_FUNCTION
996 krb5_get_kdc_sec_offset (krb5_context context, int32_t *sec, int32_t *usec)
998 if (sec)
999 *sec = context->kdc_sec_offset;
1000 if (usec)
1001 *usec = context->kdc_usec_offset;
1002 return 0;
1006 * Get max time skew allowed.
1008 * @param context Kerberos 5 context.
1010 * @return timeskew in seconds.
1012 * @ingroup krb5
1015 time_t KRB5_LIB_FUNCTION
1016 krb5_get_max_time_skew (krb5_context context)
1018 return context->max_skew;
1022 * Set max time skew allowed.
1024 * @param context Kerberos 5 context.
1025 * @param t timeskew in seconds.
1027 * @ingroup krb5
1030 void KRB5_LIB_FUNCTION
1031 krb5_set_max_time_skew (krb5_context context, time_t t)
1033 context->max_skew = t;