15e9cd1aeSAssar Westerlund /* 2adb0ddaeSAssar Westerlund * Copyright (c) 2000 - 2001 Kungliga Tekniska H�gskolan 35e9cd1aeSAssar Westerlund * (Royal Institute of Technology, Stockholm, Sweden). 45e9cd1aeSAssar Westerlund * All rights reserved. 55e9cd1aeSAssar Westerlund * 65e9cd1aeSAssar Westerlund * Redistribution and use in source and binary forms, with or without 75e9cd1aeSAssar Westerlund * modification, are permitted provided that the following conditions 85e9cd1aeSAssar Westerlund * are met: 95e9cd1aeSAssar Westerlund * 105e9cd1aeSAssar Westerlund * 1. Redistributions of source code must retain the above copyright 115e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer. 125e9cd1aeSAssar Westerlund * 135e9cd1aeSAssar Westerlund * 2. Redistributions in binary form must reproduce the above copyright 145e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer in the 155e9cd1aeSAssar Westerlund * documentation and/or other materials provided with the distribution. 165e9cd1aeSAssar Westerlund * 175e9cd1aeSAssar Westerlund * 3. Neither the name of the Institute nor the names of its contributors 185e9cd1aeSAssar Westerlund * may be used to endorse or promote products derived from this software 195e9cd1aeSAssar Westerlund * without specific prior written permission. 205e9cd1aeSAssar Westerlund * 215e9cd1aeSAssar Westerlund * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 225e9cd1aeSAssar Westerlund * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 235e9cd1aeSAssar Westerlund * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 245e9cd1aeSAssar Westerlund * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 255e9cd1aeSAssar Westerlund * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 265e9cd1aeSAssar Westerlund * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 275e9cd1aeSAssar Westerlund * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 285e9cd1aeSAssar Westerlund * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 295e9cd1aeSAssar Westerlund * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 305e9cd1aeSAssar Westerlund * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 315e9cd1aeSAssar Westerlund * SUCH DAMAGE. 325e9cd1aeSAssar Westerlund */ 335e9cd1aeSAssar Westerlund 345e9cd1aeSAssar Westerlund #include "krb5_locl.h" 355e9cd1aeSAssar Westerlund 36c19800e8SDoug Rabson RCSID("$Id: appdefault.c 14465 2005-01-05 05:40:59Z lukeh $"); 375e9cd1aeSAssar Westerlund 38c19800e8SDoug Rabson void KRB5_LIB_FUNCTION 395e9cd1aeSAssar Westerlund krb5_appdefault_boolean(krb5_context context, const char *appname, 404137ff4cSJacques Vidrine krb5_const_realm realm, const char *option, 415e9cd1aeSAssar Westerlund krb5_boolean def_val, krb5_boolean *ret_val) 425e9cd1aeSAssar Westerlund { 435e9cd1aeSAssar Westerlund 445e9cd1aeSAssar Westerlund if(appname == NULL) 45adb0ddaeSAssar Westerlund appname = getprogname(); 464137ff4cSJacques Vidrine 474137ff4cSJacques Vidrine def_val = krb5_config_get_bool_default(context, NULL, def_val, 484137ff4cSJacques Vidrine "libdefaults", option, NULL); 494137ff4cSJacques Vidrine if(realm != NULL) 504137ff4cSJacques Vidrine def_val = krb5_config_get_bool_default(context, NULL, def_val, 514137ff4cSJacques Vidrine "realms", realm, option, NULL); 524137ff4cSJacques Vidrine 535e9cd1aeSAssar Westerlund def_val = krb5_config_get_bool_default(context, NULL, def_val, 545e9cd1aeSAssar Westerlund "appdefaults", 555e9cd1aeSAssar Westerlund option, 565e9cd1aeSAssar Westerlund NULL); 575e9cd1aeSAssar Westerlund if(realm != NULL) 585e9cd1aeSAssar Westerlund def_val = krb5_config_get_bool_default(context, NULL, def_val, 595e9cd1aeSAssar Westerlund "appdefaults", 605e9cd1aeSAssar Westerlund realm, 615e9cd1aeSAssar Westerlund option, 625e9cd1aeSAssar Westerlund NULL); 635e9cd1aeSAssar Westerlund if(appname != NULL) { 645e9cd1aeSAssar Westerlund def_val = krb5_config_get_bool_default(context, NULL, def_val, 655e9cd1aeSAssar Westerlund "appdefaults", 665e9cd1aeSAssar Westerlund appname, 675e9cd1aeSAssar Westerlund option, 685e9cd1aeSAssar Westerlund NULL); 695e9cd1aeSAssar Westerlund if(realm != NULL) 705e9cd1aeSAssar Westerlund def_val = krb5_config_get_bool_default(context, NULL, def_val, 715e9cd1aeSAssar Westerlund "appdefaults", 725e9cd1aeSAssar Westerlund appname, 735e9cd1aeSAssar Westerlund realm, 745e9cd1aeSAssar Westerlund option, 755e9cd1aeSAssar Westerlund NULL); 765e9cd1aeSAssar Westerlund } 775e9cd1aeSAssar Westerlund *ret_val = def_val; 785e9cd1aeSAssar Westerlund } 795e9cd1aeSAssar Westerlund 80c19800e8SDoug Rabson void KRB5_LIB_FUNCTION 815e9cd1aeSAssar Westerlund krb5_appdefault_string(krb5_context context, const char *appname, 824137ff4cSJacques Vidrine krb5_const_realm realm, const char *option, 835e9cd1aeSAssar Westerlund const char *def_val, char **ret_val) 845e9cd1aeSAssar Westerlund { 855e9cd1aeSAssar Westerlund if(appname == NULL) 86adb0ddaeSAssar Westerlund appname = getprogname(); 874137ff4cSJacques Vidrine 884137ff4cSJacques Vidrine def_val = krb5_config_get_string_default(context, NULL, def_val, 894137ff4cSJacques Vidrine "libdefaults", option, NULL); 904137ff4cSJacques Vidrine if(realm != NULL) 914137ff4cSJacques Vidrine def_val = krb5_config_get_string_default(context, NULL, def_val, 924137ff4cSJacques Vidrine "realms", realm, option, NULL); 934137ff4cSJacques Vidrine 945e9cd1aeSAssar Westerlund def_val = krb5_config_get_string_default(context, NULL, def_val, 955e9cd1aeSAssar Westerlund "appdefaults", 965e9cd1aeSAssar Westerlund option, 975e9cd1aeSAssar Westerlund NULL); 985e9cd1aeSAssar Westerlund if(realm != NULL) 995e9cd1aeSAssar Westerlund def_val = krb5_config_get_string_default(context, NULL, def_val, 1005e9cd1aeSAssar Westerlund "appdefaults", 1015e9cd1aeSAssar Westerlund realm, 1025e9cd1aeSAssar Westerlund option, 1035e9cd1aeSAssar Westerlund NULL); 1045e9cd1aeSAssar Westerlund if(appname != NULL) { 1055e9cd1aeSAssar Westerlund def_val = krb5_config_get_string_default(context, NULL, def_val, 1065e9cd1aeSAssar Westerlund "appdefaults", 1075e9cd1aeSAssar Westerlund appname, 1085e9cd1aeSAssar Westerlund option, 1095e9cd1aeSAssar Westerlund NULL); 1105e9cd1aeSAssar Westerlund if(realm != NULL) 1115e9cd1aeSAssar Westerlund def_val = krb5_config_get_string_default(context, NULL, def_val, 1125e9cd1aeSAssar Westerlund "appdefaults", 1135e9cd1aeSAssar Westerlund appname, 1145e9cd1aeSAssar Westerlund realm, 1155e9cd1aeSAssar Westerlund option, 1165e9cd1aeSAssar Westerlund NULL); 1175e9cd1aeSAssar Westerlund } 1185e9cd1aeSAssar Westerlund if(def_val != NULL) 1195e9cd1aeSAssar Westerlund *ret_val = strdup(def_val); 1205e9cd1aeSAssar Westerlund else 1215e9cd1aeSAssar Westerlund *ret_val = NULL; 1225e9cd1aeSAssar Westerlund } 1235e9cd1aeSAssar Westerlund 124c19800e8SDoug Rabson void KRB5_LIB_FUNCTION 1255e9cd1aeSAssar Westerlund krb5_appdefault_time(krb5_context context, const char *appname, 1264137ff4cSJacques Vidrine krb5_const_realm realm, const char *option, 1275e9cd1aeSAssar Westerlund time_t def_val, time_t *ret_val) 1285e9cd1aeSAssar Westerlund { 129c19800e8SDoug Rabson krb5_deltat t; 1305e9cd1aeSAssar Westerlund char *val; 131c19800e8SDoug Rabson 132c19800e8SDoug Rabson krb5_appdefault_string(context, appname, realm, option, NULL, &val); 133c19800e8SDoug Rabson if (val == NULL) { 134c19800e8SDoug Rabson *ret_val = def_val; 135c19800e8SDoug Rabson return; 136c19800e8SDoug Rabson } 137c19800e8SDoug Rabson if (krb5_string_to_deltat(val, &t)) 138c19800e8SDoug Rabson *ret_val = def_val; 139c19800e8SDoug Rabson else 1405e9cd1aeSAssar Westerlund *ret_val = t; 141c19800e8SDoug Rabson free(val); 1425e9cd1aeSAssar Westerlund } 143