13641Ssemery /* 2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 33641Ssemery * Use is subject to license terms. 43641Ssemery */ 53641Ssemery 60Sstevel@tonic-gate 70Sstevel@tonic-gate /* 80Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 90Sstevel@tonic-gate * 100Sstevel@tonic-gate * Openvision retains the copyright to derivative works of 110Sstevel@tonic-gate * this source code. Do *NOT* create a derivative of this 120Sstevel@tonic-gate * source code before consulting with your legal department. 130Sstevel@tonic-gate * Do *NOT* integrate *ANY* of this source code into another 140Sstevel@tonic-gate * product before consulting with your legal department. 150Sstevel@tonic-gate * 160Sstevel@tonic-gate * For further information, read the top-level Openvision 170Sstevel@tonic-gate * copyright which is contained in the top-level MIT Kerberos 180Sstevel@tonic-gate * copyright. 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 210Sstevel@tonic-gate * 220Sstevel@tonic-gate */ 230Sstevel@tonic-gate 240Sstevel@tonic-gate 250Sstevel@tonic-gate /* 260Sstevel@tonic-gate * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved 270Sstevel@tonic-gate * 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 304960Swillf #include <k5-int.h> 314960Swillf #include <krb5/kdb.h> 320Sstevel@tonic-gate #include <kadm5/server_internal.h> 330Sstevel@tonic-gate #include "misc.h" 340Sstevel@tonic-gate 350Sstevel@tonic-gate /* 362881Smp153739 * Function: chpass_principal_wrapper_3 372881Smp153739 * 380Sstevel@tonic-gate * Purpose: wrapper to kadm5_chpass_principal that checks to see if 390Sstevel@tonic-gate * pw_min_life has been reached. if not it returns an error. 400Sstevel@tonic-gate * otherwise it calls kadm5_chpass_principal 410Sstevel@tonic-gate * 420Sstevel@tonic-gate * Arguments: 430Sstevel@tonic-gate * principal (input) krb5_principals whose password we are 440Sstevel@tonic-gate * changing 452881Smp153739 * keepold (input) whether to preserve old keys 462881Smp153739 * n_ks_tuple (input) the number of key-salt tuples in ks_tuple 472881Smp153739 * ks_tuple (input) array of tuples indicating the caller's 482881Smp153739 * requested enctypes/salttypes 492881Smp153739 * password (input) password we are going to change to. 502881Smp153739 * <return value> 0 on success error code on failure. 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * Requires: 530Sstevel@tonic-gate * kadm5_init to have been run. 542881Smp153739 * 550Sstevel@tonic-gate * Effects: 560Sstevel@tonic-gate * calls kadm5_chpass_principal which changes the kdb and the 570Sstevel@tonic-gate * the admin db. 580Sstevel@tonic-gate * 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate kadm5_ret_t 612881Smp153739 chpass_principal_wrapper_3(void *server_handle, 622881Smp153739 krb5_principal principal, 632881Smp153739 krb5_boolean keepold, 642881Smp153739 int n_ks_tuple, 652881Smp153739 krb5_key_salt_tuple *ks_tuple, 662881Smp153739 char *password) 670Sstevel@tonic-gate { 682881Smp153739 kadm5_ret_t ret; 690Sstevel@tonic-gate 70*7934SMark.Phalan@Sun.COM ret = check_min_life(server_handle, principal, NULL, 0); 712881Smp153739 if (ret) 722881Smp153739 return ret; 730Sstevel@tonic-gate 742881Smp153739 return kadm5_chpass_principal_3(server_handle, principal, 752881Smp153739 keepold, n_ks_tuple, ks_tuple, 762881Smp153739 password); 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 812881Smp153739 * Function: randkey_principal_wrapper_3 822881Smp153739 * 830Sstevel@tonic-gate * Purpose: wrapper to kadm5_randkey_principal which checks the 842881Smp153739 * password's min. life. 850Sstevel@tonic-gate * 860Sstevel@tonic-gate * Arguments: 870Sstevel@tonic-gate * principal (input) krb5_principal whose password we are 880Sstevel@tonic-gate * changing 892881Smp153739 * keepold (input) whether to preserve old keys 902881Smp153739 * n_ks_tuple (input) the number of key-salt tuples in ks_tuple 912881Smp153739 * ks_tuple (input) array of tuples indicating the caller's 922881Smp153739 * requested enctypes/salttypes 930Sstevel@tonic-gate * key (output) new random key 942881Smp153739 * <return value> 0, error code on error. 950Sstevel@tonic-gate * 960Sstevel@tonic-gate * Requires: 970Sstevel@tonic-gate * kadm5_init needs to be run 982881Smp153739 * 990Sstevel@tonic-gate * Effects: 1000Sstevel@tonic-gate * calls kadm5_randkey_principal 1010Sstevel@tonic-gate * 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate kadm5_ret_t 1042881Smp153739 randkey_principal_wrapper_3(void *server_handle, 1052881Smp153739 krb5_principal principal, 1062881Smp153739 krb5_boolean keepold, 1072881Smp153739 int n_ks_tuple, 1082881Smp153739 krb5_key_salt_tuple *ks_tuple, 1092881Smp153739 krb5_keyblock **keys, int *n_keys) 1100Sstevel@tonic-gate { 1112881Smp153739 kadm5_ret_t ret; 1120Sstevel@tonic-gate 113*7934SMark.Phalan@Sun.COM ret = check_min_life(server_handle, principal, NULL, 0); 1142881Smp153739 if (ret) 1152881Smp153739 return ret; 1162881Smp153739 return kadm5_randkey_principal_3(server_handle, principal, 1172881Smp153739 keepold, n_ks_tuple, ks_tuple, 1182881Smp153739 keys, n_keys); 1192881Smp153739 } 1200Sstevel@tonic-gate 1212881Smp153739 kadm5_ret_t 122*7934SMark.Phalan@Sun.COM schpw_util_wrapper(void *server_handle, krb5_principal princ, 123*7934SMark.Phalan@Sun.COM char *new_pw, char **ret_pw, 124*7934SMark.Phalan@Sun.COM char *msg_ret, unsigned int msg_len) 1252881Smp153739 { 1262881Smp153739 kadm5_ret_t ret; 1272881Smp153739 128*7934SMark.Phalan@Sun.COM ret = check_min_life(server_handle, princ, msg_ret, msg_len); 1292881Smp153739 if (ret) 1302881Smp153739 return ret; 1312881Smp153739 1322881Smp153739 return kadm5_chpass_principal_util(server_handle, princ, 1332881Smp153739 new_pw, ret_pw, 1342881Smp153739 msg_ret, msg_len); 1352881Smp153739 } 1360Sstevel@tonic-gate 1372881Smp153739 kadm5_ret_t 1383641Ssemery randkey_principal_wrapper(void *server_handle, krb5_principal princ, 1393641Ssemery krb5_keyblock ** keys, int *n_keys) 1403641Ssemery { 1413641Ssemery kadm5_ret_t ret; 1423641Ssemery 143*7934SMark.Phalan@Sun.COM ret = check_min_life(server_handle, princ, NULL, 0); 1443641Ssemery if (ret) 1453641Ssemery return ret; 1463641Ssemery 1473641Ssemery return kadm5_randkey_principal(server_handle, princ, keys, n_keys); 1483641Ssemery } 1493641Ssemery 1503641Ssemery kadm5_ret_t 151*7934SMark.Phalan@Sun.COM check_min_life(void *server_handle, krb5_principal principal, 152*7934SMark.Phalan@Sun.COM char *msg_ret, unsigned int msg_len) 1532881Smp153739 { 1542881Smp153739 krb5_int32 now; 1552881Smp153739 kadm5_ret_t ret; 1562881Smp153739 kadm5_policy_ent_rec pol; 1572881Smp153739 kadm5_principal_ent_rec princ; 1582881Smp153739 kadm5_server_handle_t handle = server_handle; 1592881Smp153739 160*7934SMark.Phalan@Sun.COM if (msg_ret != NULL) 161*7934SMark.Phalan@Sun.COM *msg_ret = '\0'; 162*7934SMark.Phalan@Sun.COM 1632881Smp153739 ret = krb5_timeofday(handle->context, &now); 1642881Smp153739 if (ret) 1652881Smp153739 return ret; 1662881Smp153739 1672881Smp153739 ret = kadm5_get_principal(handle->lhandle, principal, 1682881Smp153739 &princ, KADM5_PRINCIPAL_NORMAL_MASK); 1694960Swillf if(ret) 1702881Smp153739 return ret; 1712881Smp153739 if(princ.aux_attributes & KADM5_POLICY) { 1722881Smp153739 if((ret=kadm5_get_policy(handle->lhandle, 1732881Smp153739 princ.policy, &pol)) != KADM5_OK) { 1742881Smp153739 (void) kadm5_free_principal_ent(handle->lhandle, &princ); 1752881Smp153739 return ret; 1760Sstevel@tonic-gate } 1772881Smp153739 if((now - princ.last_pwd_change) < pol.pw_min_life && 1782881Smp153739 !(princ.attributes & KRB5_KDB_REQUIRES_PWCHANGE)) { 179*7934SMark.Phalan@Sun.COM if (msg_ret != NULL) { 180*7934SMark.Phalan@Sun.COM time_t until; 181*7934SMark.Phalan@Sun.COM char *time_string, *ptr, *errstr; 182*7934SMark.Phalan@Sun.COM 183*7934SMark.Phalan@Sun.COM until = princ.last_pwd_change + pol.pw_min_life; 184*7934SMark.Phalan@Sun.COM 185*7934SMark.Phalan@Sun.COM time_string = ctime(&until); 186*7934SMark.Phalan@Sun.COM errstr = (char *)error_message(CHPASS_UTIL_PASSWORD_TOO_SOON); 187*7934SMark.Phalan@Sun.COM 188*7934SMark.Phalan@Sun.COM if (strlen(errstr) + strlen(time_string) >= msg_len) { 189*7934SMark.Phalan@Sun.COM *errstr = '\0'; 190*7934SMark.Phalan@Sun.COM } else { 191*7934SMark.Phalan@Sun.COM if (*(ptr = &time_string[strlen(time_string)-1]) == '\n') 192*7934SMark.Phalan@Sun.COM *ptr = '\0'; 193*7934SMark.Phalan@Sun.COM sprintf(msg_ret, errstr, time_string); 194*7934SMark.Phalan@Sun.COM } 195*7934SMark.Phalan@Sun.COM } 196*7934SMark.Phalan@Sun.COM 1972881Smp153739 (void) kadm5_free_policy_ent(handle->lhandle, &pol); 1982881Smp153739 (void) kadm5_free_principal_ent(handle->lhandle, &princ); 1992881Smp153739 return KADM5_PASS_TOOSOON; 2002881Smp153739 } 2012881Smp153739 2022881Smp153739 ret = kadm5_free_policy_ent(handle->lhandle, &pol); 2032881Smp153739 if (ret) { 2042881Smp153739 (void) kadm5_free_principal_ent(handle->lhandle, &princ); 2052881Smp153739 return ret; 2062881Smp153739 } 2072881Smp153739 } 2082881Smp153739 2092881Smp153739 return kadm5_free_principal_ent(handle->lhandle, &princ); 2100Sstevel@tonic-gate } 211