X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fpasswd.c;h=ebb98e23c0573c225745c3fd18e479e2636235a2;hb=1939ed3fc29d0d1c01a0a9390d2c51ac2a85260f;hp=0cd0ec74b8058dd23f4d9b9b5954ba6bb7185044;hpb=0e1f737774536220a9534dc4a4527c3d9b7f7fcc;p=openldap diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index 0cd0ec74b8..ebb98e23c0 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2005 The OpenLDAP Foundation. + * Copyright 1998-2006 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,6 +33,8 @@ #include #include +const struct berval slap_EXOP_MODIFY_PASSWD = BER_BVC(LDAP_EXOP_MODIFY_PASSWD); + static const char *defhash[] = { #ifdef LUTIL_SHA1_BYTES "{SSHA}", @@ -54,8 +56,9 @@ int passwd_extop( slap_callback cb2 = { NULL, slap_replog_cb, NULL, NULL }; int i, nhash; char **hashes; - int rc; + int rc; BackendDB *op_be; + int freenewpw = 0; cb2.sc_next = &cb; @@ -84,7 +87,7 @@ int passwd_extop( qpw->rs_old.bv_val ? " old" : "", qpw->rs_new.bv_val ? " new" : "", 0 ); } else { - Statslog( LDAP_DEBUG_STATS, "%s PASSMOD %s%s\n", + Statslog( LDAP_DEBUG_STATS, "%s PASSMOD%s%s\n", op->o_log_prefix, qpw->rs_old.bv_val ? " old" : "", qpw->rs_new.bv_val ? " new" : "", 0, 0 ); @@ -152,9 +155,8 @@ int passwd_extop( goto error_return; } -#ifndef SLAPD_MULTIMASTER /* This does not apply to multi-master case */ - if(!( !SLAP_SHADOW( op->o_bd ) || be_isupdate( op ))) { + if(!( !SLAP_SINGLE_SHADOW( op->o_bd ) || be_isupdate( op ))) { /* we SHOULD return a referral in this case */ BerVarray defref = op->o_bd->be_update_refs ? op->o_bd->be_update_refs : default_referral; @@ -176,13 +178,13 @@ int passwd_extop( rc = LDAP_UNWILLING_TO_PERFORM; goto error_return; } -#endif /* !SLAPD_MULTIMASTER */ /* generate a new password if none was provided */ if ( qpw->rs_new.bv_len == 0 ) { slap_passwd_generate( &qpw->rs_new ); if ( qpw->rs_new.bv_len ) { rsp = slap_passwd_return( &qpw->rs_new ); + freenewpw = 1; } } if ( qpw->rs_new.bv_len == 0 ) { @@ -197,8 +199,13 @@ int passwd_extop( if ( op->o_bd->be_extended ) { rs->sr_err = op->o_bd->be_extended( op, rs ); if ( rs->sr_err != LDAP_UNWILLING_TO_PERFORM && - rs->sr_err != SLAP_CB_CONTINUE ) { + rs->sr_err != SLAP_CB_CONTINUE ) + { rc = rs->sr_err; + if ( rsp ) { + rs->sr_rspdata = rsp; + rsp = NULL; + } goto error_return; } } @@ -256,6 +263,7 @@ old_good: ml->sml_values[i].bv_val = NULL; ml->sml_nvalues = NULL; ml->sml_desc = slap_schema.si_ad_userPassword; + ml->sml_type = ml->sml_desc->ad_cname; ml->sml_op = LDAP_MOD_REPLACE; ml->sml_flags = 0; ml->sml_next = qpw->rs_mods; @@ -274,23 +282,31 @@ old_good: * if it cares... */ rs->sr_err = op->o_bd->be_modify( op, rs ); + + /* be_modify() might have shuffled modifications */ + qpw->rs_mods = op->orm_modlist; + if ( rs->sr_err == LDAP_SUCCESS ) { rs->sr_rspdata = rsp; + } else if ( rsp ) { ber_bvfree( rsp ); + rsp = NULL; } op->o_tag = LDAP_REQ_EXTENDED; op->o_callback = sc; } - slap_mods_free( qpw->rs_mods, 1 ); - if ( rsp ) { - free( qpw->rs_new.bv_val ); - } rc = rs->sr_err; op->oq_extended = qext; error_return:; + if ( qpw->rs_mods ) { + slap_mods_free( qpw->rs_mods, 1 ); + } + if ( freenewpw ) { + free( qpw->rs_new.bv_val ); + } if ( !BER_BVISNULL( &op->o_req_dn ) ) { op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx ); BER_BVZERO( &op->o_req_dn ); @@ -509,8 +525,7 @@ void slap_passwd_generate( struct berval *pass ) { Debug( LDAP_DEBUG_TRACE, "slap_passwd_generate\n", 0, 0, 0 ); - pass->bv_val = NULL; - pass->bv_len = 0; + BER_BVZERO( pass ); /* * generate passwords of only 8 characters as some getpass(3)