2 * Copyright (c) 1997 - 2004 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"
38 #if defined(HAVE_FRAMEWORK_COREFOUNDATION)
39 #include <CoreFoundation/CoreFoundation.h>
43 * Parse configuration files in the given directory and add the result
44 * into res. Only files whose names consist only of alphanumeric
45 * characters, hyphen, and underscore, will be parsed, though files
46 * ending in ".conf" will also be parsed.
48 * This interface can be used to parse several configuration directories
49 * into one resulting krb5_config_section by calling it repeatably.
51 * @param context a Kerberos 5 context.
52 * @param dname a directory name to a Kerberos configuration file
53 * @param res the returned result, must be free with krb5_free_config_files().
54 * @return Return an error code or 0, see krb5_get_error_message().
56 * @ingroup krb5_support
59 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
60 krb5_config_parse_dir_multi(krb5_context context
,
62 krb5_config_section
**res
)
65 heim_config_section
*section
= NULL
;
72 ret
= heim_config_parse_dir_multi(context
->hcontext
, dname
, §ion
);
73 if (ret
== HEIM_ERR_CONFIG_BADFORMAT
)
74 return KRB5_CONFIG_BADFORMAT
;
77 *res
= (krb5_config_section
*)section
;
82 * Parse a configuration file and add the result into res. This
83 * interface can be used to parse several configuration files into one
84 * resulting krb5_config_section by calling it repeatably.
86 * @param context a Kerberos 5 context.
87 * @param fname a file name to a Kerberos configuration file
88 * @param res the returned result, must be free with krb5_free_config_files().
89 * @return Return an error code or 0, see krb5_get_error_message().
91 * @ingroup krb5_support
94 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
95 krb5_config_parse_file_multi(krb5_context context
,
97 krb5_config_section
**res
)
100 heim_config_section
*section
= NULL
;
107 ret
= heim_config_parse_file_multi(context
->hcontext
, fname
, §ion
);
108 if (ret
== HEIM_ERR_CONFIG_BADFORMAT
)
109 return KRB5_CONFIG_BADFORMAT
;
112 *res
= (krb5_config_section
*)section
;
116 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
117 krb5_config_parse_file(krb5_context context
,
119 krb5_config_section
**res
)
121 return krb5_config_parse_file_multi(context
, fname
, res
);
125 * Free configuration file section, the result of
126 * krb5_config_parse_file() and krb5_config_parse_file_multi().
128 * @param context A Kerberos 5 context
129 * @param s the configuration section to free
131 * @return returns 0 on successes, otherwise an error code, see
132 * krb5_get_error_message()
134 * @ingroup krb5_support
137 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
138 krb5_config_file_free(krb5_context context
, krb5_config_section
*s
)
140 return heim_config_file_free(context
->hcontext
, (heim_config_section
*)s
);
143 #ifndef HEIMDAL_SMALLER
145 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
146 _krb5_config_copy(krb5_context context
,
147 krb5_config_section
*c
,
148 krb5_config_section
**res
)
151 heim_config_section
*section
= NULL
;
157 ret
= heim_config_copy(context
->hcontext
, (heim_config_section
*)c
, §ion
);
160 *res
= (krb5_config_section
*)section
;
164 #endif /* HEIMDAL_SMALLER */
166 KRB5_LIB_FUNCTION
const void * KRB5_LIB_CALL
167 _krb5_config_get_next(krb5_context context
,
168 const krb5_config_section
*c
,
169 const krb5_config_binding
**pointer
,
176 va_start(args
, type
);
177 ret
= heim_config_vget_next(context
->hcontext
,
178 (const heim_config_section
*)(c
? c
: context
->cf
),
179 (const heim_config_binding
**)pointer
, type
, args
);
184 KRB5_LIB_FUNCTION
const void * KRB5_LIB_CALL
185 _krb5_config_vget_next(krb5_context context
,
186 const krb5_config_section
*c
,
187 const krb5_config_binding
**pointer
,
191 return heim_config_vget_next(context
->hcontext
,
192 (const heim_config_section
*)(c
? c
: context
->cf
),
193 (const heim_config_binding
**)pointer
, type
, args
);
196 KRB5_LIB_FUNCTION
const void * KRB5_LIB_CALL
197 _krb5_config_get(krb5_context context
,
198 const krb5_config_section
*c
,
205 va_start(args
, type
);
206 ret
= heim_config_vget(context
->hcontext
,
207 (const heim_config_section
*)(c
? c
: context
->cf
),
214 KRB5_LIB_FUNCTION
const void * KRB5_LIB_CALL
215 _krb5_config_vget(krb5_context context
,
216 const krb5_config_section
*c
,
220 return heim_config_vget(context
->hcontext
,
221 (const heim_config_section
*)(c
? c
: context
->cf
),
226 * Get a list of configuration binding list for more processing
228 * @param context A Kerberos 5 context.
229 * @param c a configuration section, or NULL to use the section from context
230 * @param ... a list of names, terminated with NULL.
232 * @return NULL if configuration list is not found, a list otherwise
234 * @ingroup krb5_support
237 KRB5_LIB_FUNCTION
const krb5_config_binding
* KRB5_LIB_CALL
238 krb5_config_get_list(krb5_context context
,
239 const krb5_config_section
*c
,
242 const heim_config_binding
*ret
;
246 ret
= heim_config_vget_list(context
->hcontext
,
247 (const heim_config_section
*)(c
? c
: context
->cf
),
250 return (const krb5_config_binding
*)ret
;
254 * Get a list of configuration binding list for more processing
256 * @param context A Kerberos 5 context.
257 * @param c a configuration section, or NULL to use the section from context
258 * @param args a va_list of arguments
260 * @return NULL if configuration list is not found, a list otherwise
262 * @ingroup krb5_support
265 KRB5_LIB_FUNCTION
const krb5_config_binding
* KRB5_LIB_CALL
266 krb5_config_vget_list(krb5_context context
,
267 const krb5_config_section
*c
,
270 const heim_config_binding
*ret
;
272 ret
= heim_config_vget_list(context
->hcontext
,
273 (const heim_config_section
*)(c
? c
: context
->cf
),
275 return (const krb5_config_binding
*)ret
;
279 * Returns a "const char *" to a string in the configuration database.
280 * The string may not be valid after a reload of the configuration
281 * database so a caller should make a local copy if it needs to keep
284 * @param context A Kerberos 5 context.
285 * @param c a configuration section, or NULL to use the section from context
286 * @param ... a list of names, terminated with NULL.
288 * @return NULL if configuration string not found, a string otherwise
290 * @ingroup krb5_support
293 KRB5_LIB_FUNCTION
const char* KRB5_LIB_CALL
294 krb5_config_get_string(krb5_context context
,
295 const krb5_config_section
*c
,
302 ret
= heim_config_vget_string(context
->hcontext
,
303 (const heim_config_section
*)(c
? c
: context
->cf
),
310 * Like krb5_config_get_string(), but uses a va_list instead of ...
312 * @param context A Kerberos 5 context.
313 * @param c a configuration section, or NULL to use the section from context
314 * @param args a va_list of arguments
316 * @return NULL if configuration string not found, a string otherwise
318 * @ingroup krb5_support
321 KRB5_LIB_FUNCTION
const char* KRB5_LIB_CALL
322 krb5_config_vget_string(krb5_context context
,
323 const krb5_config_section
*c
,
326 return heim_config_vget_string(context
->hcontext
,
327 (const heim_config_section
*)(c
? c
: context
->cf
),
332 * Like krb5_config_vget_string(), but instead of returning NULL,
333 * instead return a default value.
335 * @param context A Kerberos 5 context.
336 * @param c a configuration section, or NULL to use the section from context
337 * @param def_value the default value to return if no configuration
338 * found in the database.
339 * @param args a va_list of arguments
341 * @return a configuration string
343 * @ingroup krb5_support
346 KRB5_LIB_FUNCTION
const char* KRB5_LIB_CALL
347 krb5_config_vget_string_default(krb5_context context
,
348 const krb5_config_section
*c
,
349 const char *def_value
,
352 return heim_config_vget_string_default(context
->hcontext
,
353 (const heim_config_section
*)(c
? c
: context
->cf
),
358 * Like krb5_config_get_string(), but instead of returning NULL,
359 * instead return a default value.
361 * @param context A Kerberos 5 context.
362 * @param c a configuration section, or NULL to use the section from context
363 * @param def_value the default value to return if no configuration
364 * found in the database.
365 * @param ... a list of names, terminated with NULL.
367 * @return a configuration string
369 * @ingroup krb5_support
372 KRB5_LIB_FUNCTION
const char* KRB5_LIB_CALL
373 krb5_config_get_string_default(krb5_context context
,
374 const krb5_config_section
*c
,
375 const char *def_value
,
381 va_start(args
, def_value
);
382 ret
= heim_config_vget_string_default(context
->hcontext
,
383 (const heim_config_section
*)(c
? c
: context
->cf
),
390 * Get a list of configuration strings, free the result with
391 * krb5_config_free_strings().
393 * @param context A Kerberos 5 context.
394 * @param c a configuration section, or NULL to use the section from context
395 * @param args a va_list of arguments
397 * @return TRUE or FALSE
399 * @ingroup krb5_support
402 KRB5_LIB_FUNCTION
char ** KRB5_LIB_CALL
403 krb5_config_vget_strings(krb5_context context
,
404 const krb5_config_section
*c
,
407 return heim_config_vget_strings(context
->hcontext
,
408 (const heim_config_section
*)(c
? c
: context
->cf
),
413 * Get a list of configuration strings, free the result with
414 * krb5_config_free_strings().
416 * @param context A Kerberos 5 context.
417 * @param c a configuration section, or NULL to use the section from context
418 * @param ... a list of names, terminated with NULL.
420 * @return TRUE or FALSE
422 * @ingroup krb5_support
425 KRB5_LIB_FUNCTION
char** KRB5_LIB_CALL
426 krb5_config_get_strings(krb5_context context
,
427 const krb5_config_section
*c
,
433 ret
= heim_config_vget_strings(context
->hcontext
,
434 (const heim_config_section
*)(c
? c
: context
->cf
),
441 * Free the resulting strings from krb5_config-get_strings() and
442 * krb5_config_vget_strings().
444 * @param strings strings to free
446 * @ingroup krb5_support
449 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
450 krb5_config_free_strings(char **strings
)
452 heim_config_free_strings(strings
);
456 * Like krb5_config_get_bool_default() but with a va_list list of
457 * configuration selection.
459 * Configuration value to a boolean value, where yes/true and any
460 * non-zero number means TRUE and other value is FALSE.
462 * @param context A Kerberos 5 context.
463 * @param c a configuration section, or NULL to use the section from context
464 * @param def_value the default value to return if no configuration
465 * found in the database.
466 * @param args a va_list of arguments
468 * @return TRUE or FALSE
470 * @ingroup krb5_support
473 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
474 krb5_config_vget_bool_default(krb5_context context
,
475 const krb5_config_section
*c
,
476 krb5_boolean def_value
,
479 return heim_config_vget_bool_default(context
->hcontext
,
480 (const heim_config_section
*)(c
? c
: context
->cf
),
485 * krb5_config_get_bool() will convert the configuration
486 * option value to a boolean value, where yes/true and any non-zero
487 * number means TRUE and other value is FALSE.
489 * @param context A Kerberos 5 context.
490 * @param c a configuration section, or NULL to use the section from context
491 * @param args a va_list of arguments
493 * @return TRUE or FALSE
495 * @ingroup krb5_support
498 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
499 krb5_config_vget_bool(krb5_context context
,
500 const krb5_config_section
*c
,
503 return heim_config_vget_bool_default(context
->hcontext
,
504 (const heim_config_section
*)(c
? c
: context
->cf
),
509 * krb5_config_get_bool_default() will convert the configuration
510 * option value to a boolean value, where yes/true and any non-zero
511 * number means TRUE and other value is FALSE.
513 * @param context A Kerberos 5 context.
514 * @param c a configuration section, or NULL to use the section from context
515 * @param def_value the default value to return if no configuration
516 * found in the database.
517 * @param ... a list of names, terminated with NULL.
519 * @return TRUE or FALSE
521 * @ingroup krb5_support
524 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
525 krb5_config_get_bool_default(krb5_context context
,
526 const krb5_config_section
*c
,
527 krb5_boolean def_value
,
532 va_start(ap
, def_value
);
533 ret
= heim_config_vget_bool_default(context
->hcontext
,
534 (const heim_config_section
*)(c
? c
: context
->cf
),
541 * Like krb5_config_get_bool() but with a va_list list of
542 * configuration selection.
544 * Configuration value to a boolean value, where yes/true and any
545 * non-zero number means TRUE and other value is FALSE.
547 * @param context A Kerberos 5 context.
548 * @param c a configuration section, or NULL to use the section from context
549 * @param ... a list of names, terminated with NULL.
551 * @return TRUE or FALSE
553 * @ingroup krb5_support
556 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
557 krb5_config_get_bool (krb5_context context
,
558 const krb5_config_section
*c
,
564 ret
= krb5_config_vget_bool (context
, c
, ap
);
570 * Get the time from the configuration file using a relative time.
572 * Like krb5_config_get_time_default() but with a va_list list of
573 * configuration selection.
575 * @param context A Kerberos 5 context.
576 * @param c a configuration section, or NULL to use the section from context
577 * @param def_value the default value to return if no configuration
578 * found in the database.
579 * @param args a va_list of arguments
581 * @return parsed the time (or def_value on parse error)
583 * @ingroup krb5_support
586 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
587 krb5_config_vget_time_default(krb5_context context
,
588 const krb5_config_section
*c
,
592 return heim_config_vget_time_default(context
->hcontext
,
593 (const heim_config_section
*)(c
? c
: context
->cf
),
598 * Get the time from the configuration file using a relative time, for example: 1h30s
600 * @param context A Kerberos 5 context.
601 * @param c a configuration section, or NULL to use the section from context
602 * @param args a va_list of arguments
604 * @return parsed the time or -1 on error
606 * @ingroup krb5_support
609 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
610 krb5_config_vget_time(krb5_context context
,
611 const krb5_config_section
*c
,
614 return heim_config_vget_time_default(context
->hcontext
,
615 (const heim_config_section
*)(c
? c
: context
->cf
),
620 * Get the time from the configuration file using a relative time, for example: 1h30s
622 * @param context A Kerberos 5 context.
623 * @param c a configuration section, or NULL to use the section from context
624 * @param def_value the default value to return if no configuration
625 * found in the database.
626 * @param ... a list of names, terminated with NULL.
628 * @return parsed the time (or def_value on parse error)
630 * @ingroup krb5_support
633 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
634 krb5_config_get_time_default(krb5_context context
,
635 const krb5_config_section
*c
,
641 va_start(ap
, def_value
);
642 ret
= heim_config_vget_time_default(context
->hcontext
,
643 (const heim_config_section
*)(c
? c
: context
->cf
),
650 * Get the time from the configuration file using a relative time, for example: 1h30s
652 * @param context A Kerberos 5 context.
653 * @param c a configuration section, or NULL to use the section from context
654 * @param ... a list of names, terminated with NULL.
656 * @return parsed the time or -1 on error
658 * @ingroup krb5_support
661 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
662 krb5_config_get_time(krb5_context context
,
663 const krb5_config_section
*c
,
669 ret
= heim_config_vget_time(context
->hcontext
,
670 (const heim_config_section
*)(c
? c
: context
->cf
),
677 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
678 krb5_config_vget_int_default(krb5_context context
,
679 const krb5_config_section
*c
,
683 return heim_config_vget_int_default(context
->hcontext
,
684 (const heim_config_section
*)(c
? c
: context
->cf
),
688 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
689 krb5_config_vget_int(krb5_context context
,
690 const krb5_config_section
*c
,
693 return heim_config_vget_int_default(context
->hcontext
,
694 (const heim_config_section
*)(c
? c
: context
->cf
),
698 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
699 krb5_config_get_int_default(krb5_context context
,
700 const krb5_config_section
*c
,
706 va_start(ap
, def_value
);
707 ret
= heim_config_vget_int_default(context
->hcontext
,
708 (const heim_config_section
*)(c
? c
: context
->cf
),
714 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
715 krb5_config_get_int(krb5_context context
,
716 const krb5_config_section
*c
,
722 ret
= heim_config_vget_int(context
->hcontext
,
723 (const heim_config_section
*)(c
? c
: context
->cf
),
730 #ifndef HEIMDAL_SMALLER
732 * Deprecated: configuration files are not strings
734 * @ingroup krb5_deprecated
737 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
738 krb5_config_parse_string_multi(krb5_context context
,
740 krb5_config_section
**res
)
741 KRB5_DEPRECATED_FUNCTION("Use X instead")
744 heim_config_section
*section
= NULL
;
750 ret
= heim_config_parse_string_multi(context
->hcontext
, string
, §ion
);
751 if (ret
== HEIM_ERR_CONFIG_BADFORMAT
)
752 return KRB5_CONFIG_BADFORMAT
;
755 *res
= (krb5_config_section
*)section
;