2 * Kerberos compatibility functions for AIX's NAS libraries.
4 * AIX for some reason doesn't provide the krb5_appdefault_* functions, but
5 * does provide the underlying profile library functions (as a separate
6 * libk5profile with a separate k5profile.h header file).
8 * This file is therefore (apart from the includes, opening and closing
9 * comments, and the spots marked with an rra-c-util comment) a verbatim copy
10 * of src/lib/krb5/krb/appdefault.c from MIT Kerberos 1.4.4.
12 * The canonical version of this file is maintained in the rra-c-util package,
13 * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
15 * Copyright 1985-2005 by the Massachusetts Institute of Technology.
16 * For license information, see the end of this file.
22 #ifdef HAVE_K5PROFILE_H
23 # include <k5profile.h>
31 /*xxx Duplicating this is annoying; try to work on a better way.*/
32 static const char *const conf_yes[] = {
33 "y", "yes", "true", "t", "1", "on",
37 static const char *const conf_no[] = {
38 "n", "no", "false", "nil", "0", "off",
42 static int conf_boolean(char *s)
44 const char * const *p;
45 for(p=conf_yes; *p; p++) {
46 if (!strcasecmp(*p,s))
49 for(p=conf_no; *p; p++) {
50 if (!strcasecmp(*p,s))
57 static krb5_error_code appdefault_get(krb5_context context, const char *appname, const krb5_data *realm, const char *option, char **ret_value)
61 char **nameval = NULL;
62 krb5_error_code retval;
63 const char * realmstr = realm?realm->data:NULL;
66 * rra-c-util: The magic values are internal, so a magic check for the
67 * context struct was removed here. Call krb5_get_profile if it's
68 * available since the krb5_context struct may be opaque.
73 #ifdef HAVE_KRB5_GET_PROFILE
74 krb5_get_profile(context, &profile);
76 profile = context->profile;
90 names[0] = "appdefaults";
97 retval = profile_get_values(profile, names, &nameval);
98 if (retval == 0 && nameval && nameval[0]) {
99 *ret_value = strdup(nameval[0]);
115 retval = profile_get_values(profile, names, &nameval);
116 if (retval == 0 && nameval && nameval[0]) {
117 *ret_value = strdup(nameval[0]);
133 retval = profile_get_values(profile, names, &nameval);
134 if (retval == 0 && nameval && nameval[0]) {
135 *ret_value = strdup(nameval[0]);
149 retval = profile_get_values(profile, names, &nameval);
150 if (retval == 0 && nameval && nameval[0]) {
151 *ret_value = strdup(nameval[0]);
159 for (cpp = nameval; *cpp; cpp++)
167 krb5_appdefault_boolean(krb5_context context, const char *appname, const krb5_data *realm, const char *option, int default_value, int *ret_value)
170 krb5_error_code retval;
172 retval = appdefault_get(context, appname, realm, option, &string);
174 if (! retval && string) {
175 *ret_value = conf_boolean(string);
178 *ret_value = default_value;
182 krb5_appdefault_string(krb5_context context, const char *appname, const krb5_data *realm, const char *option, const char *default_value, char **ret_value)
184 krb5_error_code retval;
187 retval = appdefault_get(context, appname, realm, option, &string);
189 if (! retval && string) {
192 *ret_value = strdup(default_value);
197 * Copyright (C) 1985-2005 by the Massachusetts Institute of Technology.
198 * All rights reserved.
200 * Export of this software from the United States of America may require
201 * a specific license from the United States Government. It is the
202 * responsibility of any person or organization contemplating export to
203 * obtain such a license before exporting.
205 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
206 * distribute this software and its documentation for any purpose and
207 * without fee is hereby granted, provided that the above copyright
208 * notice appear in all copies and that both that copyright notice and
209 * this permission notice appear in supporting documentation, and that
210 * the name of M.I.T. not be used in advertising or publicity pertaining
211 * to distribution of the software without specific, written prior
212 * permission. Furthermore if you modify this software you must label
213 * your software as modified software and not distribute it in such a
214 * fashion that it might be confused with the original MIT software.
215 * M.I.T. makes no representations about the suitability of this software
216 * for any purpose. It is provided "as is" without express or implied
219 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
220 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
221 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
223 * Individual source code files are copyright MIT, Cygnus Support,
224 * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
226 * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
227 * and Zephyr are trademarks of the Massachusetts Institute of Technology
228 * (MIT). No commercial use of these trademarks may be made without
229 * prior written permission of MIT.
231 * "Commercial use" means use of a name in a product or other for-profit
232 * manner. It does NOT prevent a commercial firm from referring to the
233 * MIT trademarks in order to convey information (although in doing so,
234 * recognition of their trademark status should be given).
236 * There is no SPDX-License-Identifier registered for this license.