2 * appdefault - routines designed to be called from applications to
3 * handle the [appdefaults] profile section
12 /*xxx Duplicating this is annoying; try to work on a better way.*/
13 static const char *const conf_yes
[] = {
14 "y", "yes", "true", "t", "1", "on",
18 static const char *const conf_no
[] = {
19 "n", "no", "false", "nil", "0", "off",
23 static int conf_boolean(char *s
)
25 const char * const *p
;
26 for(p
=conf_yes
; *p
; p
++) {
27 if (!strcasecmp(*p
,s
))
30 for(p
=conf_no
; *p
; p
++) {
31 if (!strcasecmp(*p
,s
))
38 static krb5_error_code
appdefault_get(krb5_context context
, const char *appname
, const krb5_data
*realm
, const char *option
, char **ret_value
)
42 char **nameval
= NULL
;
43 krb5_error_code retval
;
44 const char * realmstr
= realm
?realm
->data
:NULL
;
46 if (!context
|| (context
->magic
!= KV5M_CONTEXT
))
49 profile
= context
->profile
;
62 names
[0] = "appdefaults";
69 retval
= profile_get_values(profile
, names
, &nameval
);
70 if (retval
== 0 && nameval
&& nameval
[0]) {
71 *ret_value
= strdup(nameval
[0]);
87 retval
= profile_get_values(profile
, names
, &nameval
);
88 if (retval
== 0 && nameval
&& nameval
[0]) {
89 *ret_value
= strdup(nameval
[0]);
105 retval
= profile_get_values(profile
, names
, &nameval
);
106 if (retval
== 0 && nameval
&& nameval
[0]) {
107 *ret_value
= strdup(nameval
[0]);
121 retval
= profile_get_values(profile
, names
, &nameval
);
122 if (retval
== 0 && nameval
&& nameval
[0]) {
123 *ret_value
= strdup(nameval
[0]);
131 for (cpp
= nameval
; *cpp
; cpp
++)
139 krb5_appdefault_boolean(krb5_context context
, const char *appname
, const krb5_data
*realm
, const char *option
, int default_value
, int *ret_value
)
142 krb5_error_code retval
;
144 retval
= appdefault_get(context
, appname
, realm
, option
, &string
);
146 if (! retval
&& string
) {
147 *ret_value
= conf_boolean(string
);
150 *ret_value
= default_value
;
154 krb5_appdefault_string(krb5_context context
, const char *appname
, const krb5_data
*realm
, const char *option
, const char *default_value
, char **ret_value
)
156 krb5_error_code retval
;
159 retval
= appdefault_get(context
, appname
, realm
, option
, &string
);
161 if (! retval
&& string
) {
164 *ret_value
= strdup(default_value
);