1b528cefcSMark Murray /* 2b528cefcSMark Murray * Copyright (c) 1997-1999 Kungliga Tekniska H�gskolan 3b528cefcSMark Murray * (Royal Institute of Technology, Stockholm, Sweden). 4b528cefcSMark Murray * All rights reserved. 5b528cefcSMark Murray * 6b528cefcSMark Murray * Redistribution and use in source and binary forms, with or without 7b528cefcSMark Murray * modification, are permitted provided that the following conditions 8b528cefcSMark Murray * are met: 9b528cefcSMark Murray * 10b528cefcSMark Murray * 1. Redistributions of source code must retain the above copyright 11b528cefcSMark Murray * notice, this list of conditions and the following disclaimer. 12b528cefcSMark Murray * 13b528cefcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright 14b528cefcSMark Murray * notice, this list of conditions and the following disclaimer in the 15b528cefcSMark Murray * documentation and/or other materials provided with the distribution. 16b528cefcSMark Murray * 17b528cefcSMark Murray * 3. Neither the name of the Institute nor the names of its contributors 18b528cefcSMark Murray * may be used to endorse or promote products derived from this software 19b528cefcSMark Murray * without specific prior written permission. 20b528cefcSMark Murray * 21b528cefcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22b528cefcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23b528cefcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24b528cefcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25b528cefcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26b528cefcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27b528cefcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28b528cefcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29b528cefcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30b528cefcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31b528cefcSMark Murray * SUCH DAMAGE. 32b528cefcSMark Murray */ 33b528cefcSMark Murray 34b528cefcSMark Murray #include "kadm5_locl.h" 35b528cefcSMark Murray 36b528cefcSMark Murray RCSID("$Id: password_quality.c,v 1.3 1999/12/02 17:05:06 joda Exp $"); 37b528cefcSMark Murray 38b528cefcSMark Murray #ifdef HAVE_DLFCN_H 39b528cefcSMark Murray #include <dlfcn.h> 40b528cefcSMark Murray #endif 41b528cefcSMark Murray 42b528cefcSMark Murray static const char * 43b528cefcSMark Murray simple_passwd_quality (krb5_context context, 44b528cefcSMark Murray krb5_principal principal, 45b528cefcSMark Murray krb5_data *pwd) 46b528cefcSMark Murray { 47b528cefcSMark Murray if (pwd->length < 6) 48b528cefcSMark Murray return "Password too short"; 49b528cefcSMark Murray else 50b528cefcSMark Murray return NULL; 51b528cefcSMark Murray } 52b528cefcSMark Murray 53b528cefcSMark Murray typedef const char* (*passwd_quality_check_func)(krb5_context, 54b528cefcSMark Murray krb5_principal, 55b528cefcSMark Murray krb5_data*); 56b528cefcSMark Murray 57b528cefcSMark Murray static passwd_quality_check_func passwd_quality_check = simple_passwd_quality; 58b528cefcSMark Murray 59b528cefcSMark Murray #ifdef HAVE_DLOPEN 60b528cefcSMark Murray extern const char *check_library; 61b528cefcSMark Murray extern const char *check_function; 62b528cefcSMark Murray 63b528cefcSMark Murray #define PASSWD_VERSION 0 64b528cefcSMark Murray 65b528cefcSMark Murray #endif 66b528cefcSMark Murray 67b528cefcSMark Murray /* 68b528cefcSMark Murray * setup the password quality hook 69b528cefcSMark Murray */ 70b528cefcSMark Murray 71b528cefcSMark Murray void 72b528cefcSMark Murray kadm5_setup_passwd_quality_check(krb5_context context, 73b528cefcSMark Murray const char *check_library, 74b528cefcSMark Murray const char *check_function) 75b528cefcSMark Murray { 76b528cefcSMark Murray #ifdef HAVE_DLOPEN 77b528cefcSMark Murray void *handle; 78b528cefcSMark Murray void *sym; 79b528cefcSMark Murray int *version; 80b528cefcSMark Murray int flags; 81b528cefcSMark Murray const char *tmp; 82b528cefcSMark Murray 83b528cefcSMark Murray #ifdef RTLD_NOW 84b528cefcSMark Murray flags = RTLD_NOW; 85b528cefcSMark Murray #else 86b528cefcSMark Murray flags = 0; 87b528cefcSMark Murray #endif 88b528cefcSMark Murray 89b528cefcSMark Murray if(check_library == NULL) { 90b528cefcSMark Murray tmp = krb5_config_get_string(context, NULL, 91b528cefcSMark Murray "password_quality", 92b528cefcSMark Murray "check_library", 93b528cefcSMark Murray NULL); 94b528cefcSMark Murray if(tmp != NULL) 95b528cefcSMark Murray check_library = tmp; 96b528cefcSMark Murray } 97b528cefcSMark Murray if(check_function == NULL) { 98b528cefcSMark Murray tmp = krb5_config_get_string(context, NULL, 99b528cefcSMark Murray "password_quality", 100b528cefcSMark Murray "check_function", 101b528cefcSMark Murray NULL); 102b528cefcSMark Murray if(tmp != NULL) 103b528cefcSMark Murray check_function = tmp; 104b528cefcSMark Murray } 105b528cefcSMark Murray if(check_library != NULL && check_function == NULL) 106b528cefcSMark Murray check_function = "passwd_check"; 107b528cefcSMark Murray 108b528cefcSMark Murray if(check_library == NULL) 109b528cefcSMark Murray return; 110b528cefcSMark Murray handle = dlopen(check_library, flags); 111b528cefcSMark Murray if(handle == NULL) { 112b528cefcSMark Murray krb5_warnx(context, "failed to open `%s'", check_library); 113b528cefcSMark Murray return; 114b528cefcSMark Murray } 115b528cefcSMark Murray version = dlsym(handle, "version"); 116b528cefcSMark Murray if(version == NULL) { 117b528cefcSMark Murray krb5_warnx(context, 118b528cefcSMark Murray "didn't find `version' symbol in `%s'", check_library); 119b528cefcSMark Murray dlclose(handle); 120b528cefcSMark Murray return; 121b528cefcSMark Murray } 122b528cefcSMark Murray if(*version != PASSWD_VERSION) { 123b528cefcSMark Murray krb5_warnx(context, 124b528cefcSMark Murray "version of loaded library is %d (expected %d)", 125b528cefcSMark Murray *version, PASSWD_VERSION); 126b528cefcSMark Murray dlclose(handle); 127b528cefcSMark Murray return; 128b528cefcSMark Murray } 129b528cefcSMark Murray sym = dlsym(handle, check_function); 130b528cefcSMark Murray if(sym == NULL) { 131b528cefcSMark Murray krb5_warnx(context, 132b528cefcSMark Murray "didn't find `%s' symbol in `%s'", 133b528cefcSMark Murray check_function, check_library); 134b528cefcSMark Murray dlclose(handle); 135b528cefcSMark Murray return; 136b528cefcSMark Murray } 137b528cefcSMark Murray passwd_quality_check = (passwd_quality_check_func) sym; 138b528cefcSMark Murray #endif /* HAVE_DLOPEN */ 139b528cefcSMark Murray } 140b528cefcSMark Murray 141b528cefcSMark Murray const char * 142b528cefcSMark Murray kadm5_check_password_quality (krb5_context context, 143b528cefcSMark Murray krb5_principal principal, 144b528cefcSMark Murray krb5_data *pwd_data) 145b528cefcSMark Murray { 146b528cefcSMark Murray return (*passwd_quality_check) (context, principal, pwd_data); 147b528cefcSMark Murray } 148