set id = NULL to avoid warning
[heimdal.git] / lib / krb5 / config_file.c
blobdf9dad01d825112fc30cdb4edd7a72dbfc5e4275
1 /*
2 * Copyright (c) 1997 - 2004 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"
36 /* Gaah! I want a portable funopen */
37 struct fileptr {
38 const char *s;
39 FILE *f;
42 static char *
43 config_fgets(char *str, size_t len, struct fileptr *ptr)
45 /* XXX this is not correct, in that they don't do the same if the
46 line is longer than len */
47 if(ptr->f != NULL)
48 return fgets(str, len, ptr->f);
49 else {
50 /* this is almost strsep_copy */
51 const char *p;
52 ssize_t l;
53 if(*ptr->s == '\0')
54 return NULL;
55 p = ptr->s + strcspn(ptr->s, "\n");
56 if(*p == '\n')
57 p++;
58 l = min(len, p - ptr->s);
59 if(len > 0) {
60 memcpy(str, ptr->s, l);
61 str[l] = '\0';
63 ptr->s = p;
64 return str;
68 static krb5_error_code parse_section(char *p, krb5_config_section **s,
69 krb5_config_section **res,
70 const char **error_message);
71 static krb5_error_code parse_binding(struct fileptr *f, unsigned *lineno, char *p,
72 krb5_config_binding **b,
73 krb5_config_binding **parent,
74 const char **error_message);
75 static krb5_error_code parse_list(struct fileptr *f, unsigned *lineno,
76 krb5_config_binding **parent,
77 const char **error_message);
79 static krb5_config_section *
80 get_entry(krb5_config_section **parent, const char *name, int type)
82 krb5_config_section **q;
84 for(q = parent; *q != NULL; q = &(*q)->next)
85 if(type == krb5_config_list &&
86 type == (*q)->type &&
87 strcmp(name, (*q)->name) == 0)
88 return *q;
89 *q = calloc(1, sizeof(**q));
90 if(*q == NULL)
91 return NULL;
92 (*q)->name = strdup(name);
93 (*q)->type = type;
94 if((*q)->name == NULL) {
95 free(*q);
96 *q = NULL;
97 return NULL;
99 return *q;
103 * Parse a section:
105 * [section]
106 * foo = bar
107 * b = {
110 * ...
112 * starting at the line in `p', storing the resulting structure in
113 * `s' and hooking it into `parent'.
114 * Store the error message in `error_message'.
117 static krb5_error_code
118 parse_section(char *p, krb5_config_section **s, krb5_config_section **parent,
119 const char **error_message)
121 char *p1;
122 krb5_config_section *tmp;
124 p1 = strchr (p + 1, ']');
125 if (p1 == NULL) {
126 *error_message = "missing ]";
127 return KRB5_CONFIG_BADFORMAT;
129 *p1 = '\0';
130 tmp = get_entry(parent, p + 1, krb5_config_list);
131 if(tmp == NULL) {
132 *error_message = "out of memory";
133 return KRB5_CONFIG_BADFORMAT;
135 *s = tmp;
136 return 0;
140 * Parse a brace-enclosed list from `f', hooking in the structure at
141 * `parent'.
142 * Store the error message in `error_message'.
145 static krb5_error_code
146 parse_list(struct fileptr *f, unsigned *lineno, krb5_config_binding **parent,
147 const char **error_message)
149 char buf[BUFSIZ];
150 krb5_error_code ret;
151 krb5_config_binding *b = NULL;
152 unsigned beg_lineno = *lineno;
154 while(config_fgets(buf, sizeof(buf), f) != NULL) {
155 char *p;
157 ++*lineno;
158 buf[strcspn(buf, "\r\n")] = '\0';
159 p = buf;
160 while(isspace((unsigned char)*p))
161 ++p;
162 if (*p == '#' || *p == ';' || *p == '\0')
163 continue;
164 while(isspace((unsigned char)*p))
165 ++p;
166 if (*p == '}')
167 return 0;
168 if (*p == '\0')
169 continue;
170 ret = parse_binding (f, lineno, p, &b, parent, error_message);
171 if (ret)
172 return ret;
174 *lineno = beg_lineno;
175 *error_message = "unclosed {";
176 return KRB5_CONFIG_BADFORMAT;
183 static krb5_error_code
184 parse_binding(struct fileptr *f, unsigned *lineno, char *p,
185 krb5_config_binding **b, krb5_config_binding **parent,
186 const char **error_message)
188 krb5_config_binding *tmp;
189 char *p1, *p2;
190 krb5_error_code ret = 0;
192 p1 = p;
193 while (*p && *p != '=' && !isspace((unsigned char)*p))
194 ++p;
195 if (*p == '\0') {
196 *error_message = "missing =";
197 return KRB5_CONFIG_BADFORMAT;
199 p2 = p;
200 while (isspace((unsigned char)*p))
201 ++p;
202 if (*p != '=') {
203 *error_message = "missing =";
204 return KRB5_CONFIG_BADFORMAT;
206 ++p;
207 while(isspace((unsigned char)*p))
208 ++p;
209 *p2 = '\0';
210 if (*p == '{') {
211 tmp = get_entry(parent, p1, krb5_config_list);
212 if (tmp == NULL) {
213 *error_message = "out of memory";
214 return KRB5_CONFIG_BADFORMAT;
216 ret = parse_list (f, lineno, &tmp->u.list, error_message);
217 } else {
218 tmp = get_entry(parent, p1, krb5_config_string);
219 if (tmp == NULL) {
220 *error_message = "out of memory";
221 return KRB5_CONFIG_BADFORMAT;
223 p1 = p;
224 p = p1 + strlen(p1);
225 while(p > p1 && isspace((unsigned char)*(p-1)))
226 --p;
227 *p = '\0';
228 tmp->u.string = strdup(p1);
230 *b = tmp;
231 return ret;
235 * Parse the config file `fname', generating the structures into `res'
236 * returning error messages in `error_message'
239 static krb5_error_code
240 krb5_config_parse_debug (struct fileptr *f,
241 krb5_config_section **res,
242 unsigned *lineno,
243 const char **error_message)
245 krb5_config_section *s = NULL;
246 krb5_config_binding *b = NULL;
247 char buf[BUFSIZ];
248 krb5_error_code ret;
250 while (config_fgets(buf, sizeof(buf), f) != NULL) {
251 char *p;
253 ++*lineno;
254 buf[strcspn(buf, "\r\n")] = '\0';
255 p = buf;
256 while(isspace((unsigned char)*p))
257 ++p;
258 if (*p == '#' || *p == ';')
259 continue;
260 if (*p == '[') {
261 ret = parse_section(p, &s, res, error_message);
262 if (ret)
263 return ret;
264 b = NULL;
265 } else if (*p == '}') {
266 *error_message = "unmatched }";
267 return EINVAL; /* XXX */
268 } else if(*p != '\0') {
269 if (s == NULL) {
270 *error_message = "binding before section";
271 return EINVAL;
273 ret = parse_binding(f, lineno, p, &b, &s->u.list, error_message);
274 if (ret)
275 return ret;
278 return 0;
281 krb5_error_code KRB5_LIB_FUNCTION
282 krb5_config_parse_string_multi(krb5_context context,
283 const char *string,
284 krb5_config_section **res)
286 const char *str;
287 unsigned lineno = 0;
288 krb5_error_code ret;
289 struct fileptr f;
290 f.f = NULL;
291 f.s = string;
293 ret = krb5_config_parse_debug (&f, res, &lineno, &str);
294 if (ret) {
295 krb5_set_error_message (context, ret, "%s:%u: %s",
296 "<constant>", lineno, str);
297 return ret;
299 return 0;
303 * Parse a configuration file and add the result into res. This
304 * interface can be used to parse several configuration files into one
305 * resulting krb5_config_section by calling it repeatably.
307 * @param context a Kerberos 5 context.
308 * @param fname a file name to a Kerberos configuration file
309 * @param res the returned result, must be free with krb5_free_config_files().
310 * @return Return an error code or 0, see krb5_get_error_message().
312 * @ingroup krb5_support
315 krb5_error_code KRB5_LIB_FUNCTION
316 krb5_config_parse_file_multi (krb5_context context,
317 const char *fname,
318 krb5_config_section **res)
320 const char *str;
321 char *newfname = NULL;
322 unsigned lineno = 0;
323 krb5_error_code ret;
324 struct fileptr f;
327 * If the fname starts with "~/" parse configuration file in the
328 * current users home directory. The behavior can be disabled and
329 * enabled by calling krb5_set_home_dir_access().
331 if (_krb5_homedir_access(context) && fname[0] == '~' && fname[1] == '/') {
332 const char *home = NULL;
334 if(!issuid())
335 home = getenv("HOME");
337 if (home == NULL) {
338 struct passwd *pw = getpwuid(getuid());
339 if(pw != NULL)
340 home = pw->pw_dir;
342 if (home) {
343 asprintf(&newfname, "%s%s", home, &fname[1]);
344 if (newfname == NULL) {
345 krb5_set_error_message(context, ENOMEM,
346 N_("malloc: out of memory", ""));
347 return ENOMEM;
349 fname = newfname;
353 f.f = fopen(fname, "r");
354 f.s = NULL;
355 if(f.f == NULL) {
356 ret = errno;
357 krb5_set_error_message (context, ret, "open %s: %s",
358 fname, strerror(ret));
359 if (newfname)
360 free(newfname);
361 return ret;
364 ret = krb5_config_parse_debug (&f, res, &lineno, &str);
365 fclose(f.f);
366 if (ret) {
367 krb5_set_error_message (context, ret, "%s:%u: %s", fname, lineno, str);
368 if (newfname)
369 free(newfname);
370 return ret;
372 if (newfname)
373 free(newfname);
374 return 0;
377 krb5_error_code KRB5_LIB_FUNCTION
378 krb5_config_parse_file (krb5_context context,
379 const char *fname,
380 krb5_config_section **res)
382 *res = NULL;
383 return krb5_config_parse_file_multi(context, fname, res);
386 static void
387 free_binding (krb5_context context, krb5_config_binding *b)
389 krb5_config_binding *next_b;
391 while (b) {
392 free (b->name);
393 if (b->type == krb5_config_string)
394 free (b->u.string);
395 else if (b->type == krb5_config_list)
396 free_binding (context, b->u.list);
397 else
398 krb5_abortx(context, "unknown binding type (%d) in free_binding",
399 b->type);
400 next_b = b->next;
401 free (b);
402 b = next_b;
407 * Free configuration file section, the result of
408 * krb5_config_parse_file() and krb5_config_parse_file_multi().
410 * @param context A Kerberos 5 context
411 * @param s the configuration section to free
413 * @return returns 0 on successes, otherwise an error code, see
414 * krb5_get_error_message()
416 * @ingroup krb5_support
419 krb5_error_code KRB5_LIB_FUNCTION
420 krb5_config_file_free (krb5_context context, krb5_config_section *s)
422 free_binding (context, s);
423 return 0;
426 #ifndef HEIMDAL_SMALLER
428 krb5_error_code
429 _krb5_config_copy(krb5_context context,
430 krb5_config_section *c,
431 krb5_config_section **head)
433 krb5_config_binding *d, *previous = NULL;
435 *head = NULL;
437 while (c) {
438 d = calloc(1, sizeof(*d));
440 if (*head == NULL)
441 *head = d;
443 d->name = strdup(c->name);
444 d->type = c->type;
445 if (d->type == krb5_config_string)
446 d->u.string = strdup(c->u.string);
447 else if (d->type == krb5_config_list)
448 _krb5_config_copy (context, c->u.list, &d->u.list);
449 else
450 krb5_abortx(context,
451 "unknown binding type (%d) in krb5_config_copy",
452 d->type);
453 if (previous)
454 previous->next = d;
456 previous = d;
457 c = c->next;
459 return 0;
462 #endif /* HEIMDAL_SMALLER */
464 const void *
465 _krb5_config_get_next (krb5_context context,
466 const krb5_config_section *c,
467 const krb5_config_binding **pointer,
468 int type,
469 ...)
471 const char *ret;
472 va_list args;
474 va_start(args, type);
475 ret = _krb5_config_vget_next (context, c, pointer, type, args);
476 va_end(args);
477 return ret;
480 static const void *
481 vget_next(krb5_context context,
482 const krb5_config_binding *b,
483 const krb5_config_binding **pointer,
484 int type,
485 const char *name,
486 va_list args)
488 const char *p = va_arg(args, const char *);
489 while(b != NULL) {
490 if(strcmp(b->name, name) == 0) {
491 if(b->type == type && p == NULL) {
492 *pointer = b;
493 return b->u.generic;
494 } else if(b->type == krb5_config_list && p != NULL) {
495 return vget_next(context, b->u.list, pointer, type, p, args);
498 b = b->next;
500 return NULL;
503 const void *
504 _krb5_config_vget_next (krb5_context context,
505 const krb5_config_section *c,
506 const krb5_config_binding **pointer,
507 int type,
508 va_list args)
510 const krb5_config_binding *b;
511 const char *p;
513 if(c == NULL)
514 c = context->cf;
516 if (c == NULL)
517 return NULL;
519 if (*pointer == NULL) {
520 /* first time here, walk down the tree looking for the right
521 section */
522 p = va_arg(args, const char *);
523 if (p == NULL)
524 return NULL;
525 return vget_next(context, c, pointer, type, p, args);
528 /* we were called again, so just look for more entries with the
529 same name and type */
530 for (b = (*pointer)->next; b != NULL; b = b->next) {
531 if(strcmp(b->name, (*pointer)->name) == 0 && b->type == type) {
532 *pointer = b;
533 return b->u.generic;
536 return NULL;
539 const void *
540 _krb5_config_get (krb5_context context,
541 const krb5_config_section *c,
542 int type,
543 ...)
545 const void *ret;
546 va_list args;
548 va_start(args, type);
549 ret = _krb5_config_vget (context, c, type, args);
550 va_end(args);
551 return ret;
554 const void *
555 _krb5_config_vget (krb5_context context,
556 const krb5_config_section *c,
557 int type,
558 va_list args)
560 const krb5_config_binding *foo = NULL;
562 return _krb5_config_vget_next (context, c, &foo, type, args);
566 * Get a list of configuration binding list for more processing
568 * @param context A Kerberos 5 context.
569 * @param c a configuration section, or NULL to use the section from context
570 * @param ... a list of names, terminated with NULL.
572 * @return NULL if configuration list is not found, a list otherwise
574 * @ingroup krb5_support
577 const krb5_config_binding *
578 krb5_config_get_list (krb5_context context,
579 const krb5_config_section *c,
580 ...)
582 const krb5_config_binding *ret;
583 va_list args;
585 va_start(args, c);
586 ret = krb5_config_vget_list (context, c, args);
587 va_end(args);
588 return ret;
592 * Get a list of configuration binding list for more processing
594 * @param context A Kerberos 5 context.
595 * @param c a configuration section, or NULL to use the section from context
596 * @param args a va_list of arguments
598 * @return NULL if configuration list is not found, a list otherwise
600 * @ingroup krb5_support
603 const krb5_config_binding *
604 krb5_config_vget_list (krb5_context context,
605 const krb5_config_section *c,
606 va_list args)
608 return _krb5_config_vget (context, c, krb5_config_list, args);
612 * Returns a "const char *" to a string in the configuration database.
613 * The string may not be valid after a reload of the configuration
614 * database so a caller should make a local copy if it needs to keep
615 * the string.
617 * @param context A Kerberos 5 context.
618 * @param c a configuration section, or NULL to use the section from context
619 * @param ... a list of names, terminated with NULL.
621 * @return NULL if configuration string not found, a string otherwise
623 * @ingroup krb5_support
626 const char* KRB5_LIB_FUNCTION
627 krb5_config_get_string (krb5_context context,
628 const krb5_config_section *c,
629 ...)
631 const char *ret;
632 va_list args;
634 va_start(args, c);
635 ret = krb5_config_vget_string (context, c, args);
636 va_end(args);
637 return ret;
641 * Like krb5_config_get_string(), but uses a va_list instead of ...
643 * @param context A Kerberos 5 context.
644 * @param c a configuration section, or NULL to use the section from context
645 * @param args a va_list of arguments
647 * @return NULL if configuration string not found, a string otherwise
649 * @ingroup krb5_support
652 const char* KRB5_LIB_FUNCTION
653 krb5_config_vget_string (krb5_context context,
654 const krb5_config_section *c,
655 va_list args)
657 return _krb5_config_vget (context, c, krb5_config_string, args);
661 * Like krb5_config_vget_string(), but instead of returning NULL,
662 * instead return a default value.
664 * @param context A Kerberos 5 context.
665 * @param c a configuration section, or NULL to use the section from context
666 * @param def_value the default value to return if no configuration
667 * found in the database.
668 * @param args a va_list of arguments
670 * @return a configuration string
672 * @ingroup krb5_support
675 const char* KRB5_LIB_FUNCTION
676 krb5_config_vget_string_default (krb5_context context,
677 const krb5_config_section *c,
678 const char *def_value,
679 va_list args)
681 const char *ret;
683 ret = krb5_config_vget_string (context, c, args);
684 if (ret == NULL)
685 ret = def_value;
686 return ret;
690 * Like krb5_config_get_string(), but instead of returning NULL,
691 * instead return a default value.
693 * @param context A Kerberos 5 context.
694 * @param c a configuration section, or NULL to use the section from context
695 * @param def_value the default value to return if no configuration
696 * found in the database.
697 * @param ... a list of names, terminated with NULL.
699 * @return a configuration string
701 * @ingroup krb5_support
704 const char* KRB5_LIB_FUNCTION
705 krb5_config_get_string_default (krb5_context context,
706 const krb5_config_section *c,
707 const char *def_value,
708 ...)
710 const char *ret;
711 va_list args;
713 va_start(args, def_value);
714 ret = krb5_config_vget_string_default (context, c, def_value, args);
715 va_end(args);
716 return ret;
720 * Get a list of configuration strings, free the result with
721 * krb5_config_free_strings().
723 * @param context A Kerberos 5 context.
724 * @param c a configuration section, or NULL to use the section from context
725 * @param args a va_list of arguments
727 * @return TRUE or FALSE
729 * @ingroup krb5_support
732 char ** KRB5_LIB_FUNCTION
733 krb5_config_vget_strings(krb5_context context,
734 const krb5_config_section *c,
735 va_list args)
737 char **strings = NULL;
738 int nstr = 0;
739 const krb5_config_binding *b = NULL;
740 const char *p;
742 while((p = _krb5_config_vget_next(context, c, &b,
743 krb5_config_string, args))) {
744 char *tmp = strdup(p);
745 char *pos = NULL;
746 char *s;
747 if(tmp == NULL)
748 goto cleanup;
749 s = strtok_r(tmp, " \t", &pos);
750 while(s){
751 char **tmp2 = realloc(strings, (nstr + 1) * sizeof(*strings));
752 if(tmp2 == NULL)
753 goto cleanup;
754 strings = tmp2;
755 strings[nstr] = strdup(s);
756 nstr++;
757 if(strings[nstr-1] == NULL)
758 goto cleanup;
759 s = strtok_r(NULL, " \t", &pos);
761 free(tmp);
763 if(nstr){
764 char **tmp = realloc(strings, (nstr + 1) * sizeof(*strings));
765 if(tmp == NULL)
766 goto cleanup;
767 strings = tmp;
768 strings[nstr] = NULL;
770 return strings;
771 cleanup:
772 while(nstr--)
773 free(strings[nstr]);
774 free(strings);
775 return NULL;
780 * Get a list of configuration strings, free the result with
781 * krb5_config_free_strings().
783 * @param context A Kerberos 5 context.
784 * @param c a configuration section, or NULL to use the section from context
785 * @param args a va_list of arguments
787 * @return TRUE or FALSE
789 * @ingroup krb5_support
792 char**
793 krb5_config_get_strings(krb5_context context,
794 const krb5_config_section *c,
795 ...)
797 va_list ap;
798 char **ret;
799 va_start(ap, c);
800 ret = krb5_config_vget_strings(context, c, ap);
801 va_end(ap);
802 return ret;
806 * Free the resulting strings from krb5_config-get_strings() and
807 * krb5_config_vget_strings().
809 * @param strings strings to free
811 * @ingroup krb5_support
814 void KRB5_LIB_FUNCTION
815 krb5_config_free_strings(char **strings)
817 char **s = strings;
818 while(s && *s){
819 free(*s);
820 s++;
822 free(strings);
826 * Like krb5_config_get_bool_default() but with a va_list list of
827 * configuration selection.
829 * Configuration value to a boolean value, where yes/true and any
830 * non-zero number means TRUE and other value is FALSE.
832 * @param context A Kerberos 5 context.
833 * @param c a configuration section, or NULL to use the section from context
834 * @param def_value the default value to return if no configuration
835 * found in the database.
836 * @param args a va_list of arguments
838 * @return TRUE or FALSE
840 * @ingroup krb5_support
843 krb5_boolean KRB5_LIB_FUNCTION
844 krb5_config_vget_bool_default (krb5_context context,
845 const krb5_config_section *c,
846 krb5_boolean def_value,
847 va_list args)
849 const char *str;
850 str = krb5_config_vget_string (context, c, args);
851 if(str == NULL)
852 return def_value;
853 if(strcasecmp(str, "yes") == 0 ||
854 strcasecmp(str, "true") == 0 ||
855 atoi(str)) return TRUE;
856 return FALSE;
860 * krb5_config_get_bool() will convert the configuration
861 * option value to a boolean value, where yes/true and any non-zero
862 * number means TRUE and other value is FALSE.
864 * @param context A Kerberos 5 context.
865 * @param c a configuration section, or NULL to use the section from context
866 * @param args a va_list of arguments
868 * @return TRUE or FALSE
870 * @ingroup krb5_support
873 krb5_boolean KRB5_LIB_FUNCTION
874 krb5_config_vget_bool (krb5_context context,
875 const krb5_config_section *c,
876 va_list args)
878 return krb5_config_vget_bool_default (context, c, FALSE, args);
882 * krb5_config_get_bool_default() will convert the configuration
883 * option value to a boolean value, where yes/true and any non-zero
884 * number means TRUE and other value is FALSE.
886 * @param context A Kerberos 5 context.
887 * @param c a configuration section, or NULL to use the section from context
888 * @param def_value the default value to return if no configuration
889 * found in the database.
890 * @param ... a list of names, terminated with NULL.
892 * @return TRUE or FALSE
894 * @ingroup krb5_support
897 krb5_boolean KRB5_LIB_FUNCTION
898 krb5_config_get_bool_default (krb5_context context,
899 const krb5_config_section *c,
900 krb5_boolean def_value,
901 ...)
903 va_list ap;
904 krb5_boolean ret;
905 va_start(ap, def_value);
906 ret = krb5_config_vget_bool_default(context, c, def_value, ap);
907 va_end(ap);
908 return ret;
912 * Like krb5_config_get_bool() but with a va_list list of
913 * configuration selection.
915 * Configuration value to a boolean value, where yes/true and any
916 * non-zero number means TRUE and other value is FALSE.
918 * @param context A Kerberos 5 context.
919 * @param c a configuration section, or NULL to use the section from context
920 * @param ... a list of names, terminated with NULL.
922 * @return TRUE or FALSE
924 * @ingroup krb5_support
927 krb5_boolean KRB5_LIB_FUNCTION
928 krb5_config_get_bool (krb5_context context,
929 const krb5_config_section *c,
930 ...)
932 va_list ap;
933 krb5_boolean ret;
934 va_start(ap, c);
935 ret = krb5_config_vget_bool (context, c, ap);
936 va_end(ap);
937 return ret;
940 int KRB5_LIB_FUNCTION
941 krb5_config_vget_time_default (krb5_context context,
942 const krb5_config_section *c,
943 int def_value,
944 va_list args)
946 const char *str;
947 krb5_deltat t;
949 str = krb5_config_vget_string (context, c, args);
950 if(str == NULL)
951 return def_value;
952 if (krb5_string_to_deltat(str, &t))
953 return def_value;
954 return t;
957 int KRB5_LIB_FUNCTION
958 krb5_config_vget_time (krb5_context context,
959 const krb5_config_section *c,
960 va_list args)
962 return krb5_config_vget_time_default (context, c, -1, args);
965 int KRB5_LIB_FUNCTION
966 krb5_config_get_time_default (krb5_context context,
967 const krb5_config_section *c,
968 int def_value,
969 ...)
971 va_list ap;
972 int ret;
973 va_start(ap, def_value);
974 ret = krb5_config_vget_time_default(context, c, def_value, ap);
975 va_end(ap);
976 return ret;
979 int KRB5_LIB_FUNCTION
980 krb5_config_get_time (krb5_context context,
981 const krb5_config_section *c,
982 ...)
984 va_list ap;
985 int ret;
986 va_start(ap, c);
987 ret = krb5_config_vget_time (context, c, ap);
988 va_end(ap);
989 return ret;
993 int KRB5_LIB_FUNCTION
994 krb5_config_vget_int_default (krb5_context context,
995 const krb5_config_section *c,
996 int def_value,
997 va_list args)
999 const char *str;
1000 str = krb5_config_vget_string (context, c, args);
1001 if(str == NULL)
1002 return def_value;
1003 else {
1004 char *endptr;
1005 long l;
1006 l = strtol(str, &endptr, 0);
1007 if (endptr == str)
1008 return def_value;
1009 else
1010 return l;
1014 int KRB5_LIB_FUNCTION
1015 krb5_config_vget_int (krb5_context context,
1016 const krb5_config_section *c,
1017 va_list args)
1019 return krb5_config_vget_int_default (context, c, -1, args);
1022 int KRB5_LIB_FUNCTION
1023 krb5_config_get_int_default (krb5_context context,
1024 const krb5_config_section *c,
1025 int def_value,
1026 ...)
1028 va_list ap;
1029 int ret;
1030 va_start(ap, def_value);
1031 ret = krb5_config_vget_int_default(context, c, def_value, ap);
1032 va_end(ap);
1033 return ret;
1036 int KRB5_LIB_FUNCTION
1037 krb5_config_get_int (krb5_context context,
1038 const krb5_config_section *c,
1039 ...)
1041 va_list ap;
1042 int ret;
1043 va_start(ap, c);
1044 ret = krb5_config_vget_int (context, c, ap);
1045 va_end(ap);
1046 return ret;