2003-11-27 09:17:14 +08:00
|
|
|
/* passwd.c - password extended operation routines */
|
1999-11-24 03:00:09 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-27 09:17:14 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2008-01-08 08:19:56 +08:00
|
|
|
* Copyright 1998-2008 The OpenLDAP Foundation.
|
2003-11-27 09:17:14 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1999-11-24 03:00:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
2005-03-18 14:06:38 +08:00
|
|
|
#ifdef SLAPD_CRYPT
|
|
|
|
#include <ac/crypt.h>
|
|
|
|
#endif
|
|
|
|
|
1999-11-24 03:00:09 +08:00
|
|
|
#include "slap.h"
|
|
|
|
|
2002-05-01 09:04:57 +08:00
|
|
|
#include <lber_pvt.h>
|
1999-11-24 03:00:09 +08:00
|
|
|
#include <lutil.h>
|
2005-02-28 00:46:45 +08:00
|
|
|
#include <lutil_sha1.h>
|
1999-11-24 03:00:09 +08:00
|
|
|
|
2006-03-07 08:48:14 +08:00
|
|
|
const struct berval slap_EXOP_MODIFY_PASSWD = BER_BVC(LDAP_EXOP_MODIFY_PASSWD);
|
|
|
|
|
2004-03-03 06:12:23 +08:00
|
|
|
static const char *defhash[] = {
|
|
|
|
#ifdef LUTIL_SHA1_BYTES
|
|
|
|
"{SSHA}",
|
|
|
|
#else
|
|
|
|
"{SMD5}",
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
1999-12-10 07:05:15 +08:00
|
|
|
int passwd_extop(
|
2003-03-30 17:03:54 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs )
|
1999-12-08 12:37:59 +08:00
|
|
|
{
|
2004-03-01 03:04:34 +08:00
|
|
|
struct berval id = {0, NULL}, hash, *rsp = NULL;
|
|
|
|
req_pwdexop_s *qpw = &op->oq_pwdexop;
|
2005-03-14 08:12:48 +08:00
|
|
|
req_extended_s qext = op->oq_extended;
|
2004-03-01 03:04:34 +08:00
|
|
|
Modifications *ml;
|
2003-12-07 16:51:23 +08:00
|
|
|
slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
|
2004-03-03 06:12:23 +08:00
|
|
|
int i, nhash;
|
2007-09-23 12:40:51 +08:00
|
|
|
char **hashes, idNul;
|
2006-01-02 20:44:38 +08:00
|
|
|
int rc;
|
2005-03-17 12:29:31 +08:00
|
|
|
BackendDB *op_be;
|
2006-01-02 20:44:38 +08:00
|
|
|
int freenewpw = 0;
|
2003-12-01 20:38:11 +08:00
|
|
|
|
2003-03-31 15:49:34 +08:00
|
|
|
assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
|
1999-12-08 12:37:59 +08:00
|
|
|
|
2001-12-24 23:11:01 +08:00
|
|
|
if( op->o_dn.bv_len == 0 ) {
|
2005-08-14 08:14:58 +08:00
|
|
|
Statslog( LDAP_DEBUG_STATS, "%s PASSMOD\n",
|
|
|
|
op->o_log_prefix, 0, 0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "only authenticated users may change passwords";
|
1999-12-08 12:37:59 +08:00
|
|
|
return LDAP_STRONG_AUTH_REQUIRED;
|
|
|
|
}
|
|
|
|
|
2005-10-07 03:27:53 +08:00
|
|
|
qpw->rs_old.bv_len = 0;
|
2004-03-01 03:04:34 +08:00
|
|
|
qpw->rs_old.bv_val = NULL;
|
2005-10-07 03:27:53 +08:00
|
|
|
qpw->rs_new.bv_len = 0;
|
2004-03-01 03:04:34 +08:00
|
|
|
qpw->rs_new.bv_val = NULL;
|
|
|
|
qpw->rs_mods = NULL;
|
|
|
|
qpw->rs_modtail = NULL;
|
|
|
|
|
2005-09-29 16:00:33 +08:00
|
|
|
rs->sr_err = slap_passwd_parse( op->ore_reqdata, &id,
|
|
|
|
&qpw->rs_old, &qpw->rs_new, &rs->sr_text );
|
2003-12-06 03:54:42 +08:00
|
|
|
|
2007-09-23 12:40:51 +08:00
|
|
|
if ( !BER_BVISNULL( &id )) {
|
|
|
|
idNul = id.bv_val[id.bv_len];
|
|
|
|
id.bv_val[id.bv_len] = '\0';
|
|
|
|
}
|
2005-08-14 08:14:58 +08:00
|
|
|
if ( rs->sr_err == LDAP_SUCCESS && !BER_BVISEMPTY( &id ) ) {
|
|
|
|
Statslog( LDAP_DEBUG_STATS, "%s PASSMOD id=\"%s\"%s%s\n",
|
|
|
|
op->o_log_prefix, id.bv_val,
|
|
|
|
qpw->rs_old.bv_val ? " old" : "",
|
|
|
|
qpw->rs_new.bv_val ? " new" : "", 0 );
|
|
|
|
} else {
|
2005-11-10 20:57:42 +08:00
|
|
|
Statslog( LDAP_DEBUG_STATS, "%s PASSMOD%s%s\n",
|
2005-10-01 00:14:50 +08:00
|
|
|
op->o_log_prefix,
|
|
|
|
qpw->rs_old.bv_val ? " old" : "",
|
|
|
|
qpw->rs_new.bv_val ? " new" : "", 0, 0 );
|
2005-08-14 08:14:58 +08:00
|
|
|
}
|
|
|
|
|
2003-12-01 20:38:11 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2007-09-23 12:40:51 +08:00
|
|
|
if ( !BER_BVISNULL( &id ))
|
|
|
|
id.bv_val[id.bv_len] = idNul;
|
2003-12-01 19:12:04 +08:00
|
|
|
return rs->sr_err;
|
|
|
|
}
|
2003-12-01 20:38:11 +08:00
|
|
|
|
2005-05-30 22:49:47 +08:00
|
|
|
if ( !BER_BVISEMPTY( &id ) ) {
|
|
|
|
rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn,
|
|
|
|
&op->o_req_ndn, op->o_tmpmemctx );
|
2007-09-23 12:40:51 +08:00
|
|
|
id.bv_val[id.bv_len] = idNul;
|
2003-12-01 20:38:11 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
rs->sr_text = "Invalid DN";
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = rs->sr_err;
|
|
|
|
goto error_return;
|
2003-12-01 20:38:11 +08:00
|
|
|
}
|
2007-07-13 11:18:20 +08:00
|
|
|
op->o_bd = select_backend( &op->o_req_ndn, 1 );
|
2004-07-20 08:22:05 +08:00
|
|
|
|
2003-12-01 19:12:04 +08:00
|
|
|
} else {
|
2004-07-20 08:22:05 +08:00
|
|
|
ber_dupbv_x( &op->o_req_dn, &op->o_dn, op->o_tmpmemctx );
|
|
|
|
ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx );
|
2003-12-01 20:38:11 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
|
2003-12-01 19:12:04 +08:00
|
|
|
op->o_bd = op->o_conn->c_authz_backend;
|
2003-12-01 20:38:11 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
|
2003-12-01 19:12:04 +08:00
|
|
|
}
|
2002-06-12 06:56:47 +08:00
|
|
|
|
2003-12-01 20:51:54 +08:00
|
|
|
if( op->o_bd == NULL ) {
|
2005-09-29 16:05:38 +08:00
|
|
|
if ( qpw->rs_old.bv_val != NULL ) {
|
|
|
|
rs->sr_text = "unwilling to verify old password";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
2003-12-01 20:51:54 +08:00
|
|
|
#ifdef HAVE_CYRUS_SASL
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = slap_sasl_setpass( op, rs );
|
2003-12-01 20:51:54 +08:00
|
|
|
#else
|
|
|
|
rs->sr_text = "no authz backend";
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = LDAP_OTHER;
|
2003-12-01 20:51:54 +08:00
|
|
|
#endif
|
2004-07-20 08:22:05 +08:00
|
|
|
goto error_return;
|
2003-12-01 20:38:11 +08:00
|
|
|
}
|
|
|
|
|
2004-03-01 03:04:34 +08:00
|
|
|
if ( op->o_req_ndn.bv_len == 0 ) {
|
2003-12-01 20:51:54 +08:00
|
|
|
rs->sr_text = "no password is associated with the Root DSE";
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto error_return;
|
2002-05-01 09:04:57 +08:00
|
|
|
}
|
1999-12-16 07:22:47 +08:00
|
|
|
|
2005-03-17 12:29:31 +08:00
|
|
|
/* If we've got a glued backend, check the real backend */
|
|
|
|
op_be = op->o_bd;
|
|
|
|
if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
|
2007-07-13 11:18:20 +08:00
|
|
|
op->o_bd = select_backend( &op->o_req_ndn, 0 );
|
2005-03-17 12:29:31 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if (backend_check_restrictions( op, rs,
|
|
|
|
(struct berval *)&slap_EXOP_MODIFY_PASSWD ) != LDAP_SUCCESS) {
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = rs->sr_err;
|
|
|
|
goto error_return;
|
2002-05-01 09:04:57 +08:00
|
|
|
}
|
|
|
|
|
2005-01-13 07:22:56 +08:00
|
|
|
/* check for referrals */
|
|
|
|
if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
|
|
|
|
rc = rs->sr_err;
|
|
|
|
goto error_return;
|
|
|
|
}
|
2002-06-12 08:13:29 +08:00
|
|
|
|
2002-11-22 08:56:20 +08:00
|
|
|
/* This does not apply to multi-master case */
|
2006-02-06 12:45:12 +08:00
|
|
|
if(!( !SLAP_SINGLE_SHADOW( op->o_bd ) || be_isupdate( op ))) {
|
2002-05-01 09:04:57 +08:00
|
|
|
/* we SHOULD return a referral in this case */
|
2004-04-06 08:47:21 +08:00
|
|
|
BerVarray defref = op->o_bd->be_update_refs
|
2004-10-06 13:51:38 +08:00
|
|
|
? op->o_bd->be_update_refs : default_referral;
|
2004-04-06 08:47:21 +08:00
|
|
|
|
|
|
|
if( defref != NULL ) {
|
|
|
|
rs->sr_ref = referral_rewrite( op->o_bd->be_update_refs,
|
2003-05-02 07:39:29 +08:00
|
|
|
NULL, NULL, LDAP_SCOPE_DEFAULT );
|
2004-04-06 08:47:21 +08:00
|
|
|
if(rs->sr_ref) {
|
|
|
|
rs->sr_flags |= REP_REF_MUSTBEFREED;
|
|
|
|
} else {
|
|
|
|
rs->sr_ref = defref;
|
|
|
|
}
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = LDAP_REFERRAL;
|
|
|
|
goto error_return;
|
2004-04-06 08:47:21 +08:00
|
|
|
|
2003-05-02 07:39:29 +08:00
|
|
|
}
|
2004-04-06 08:47:21 +08:00
|
|
|
|
|
|
|
rs->sr_text = "shadow context; no update referral";
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto error_return;
|
2003-12-01 20:38:11 +08:00
|
|
|
}
|
2003-12-01 20:51:54 +08:00
|
|
|
|
2004-03-01 03:04:34 +08:00
|
|
|
/* 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 );
|
2006-01-02 20:44:38 +08:00
|
|
|
freenewpw = 1;
|
2004-03-01 03:04:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( qpw->rs_new.bv_len == 0 ) {
|
|
|
|
rs->sr_text = "password generation failed";
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = LDAP_OTHER;
|
|
|
|
goto error_return;
|
2004-03-01 03:04:34 +08:00
|
|
|
}
|
|
|
|
|
2005-03-17 12:29:31 +08:00
|
|
|
op->o_bd = op_be;
|
|
|
|
|
2003-12-01 20:51:54 +08:00
|
|
|
/* Give the backend a chance to handle this itself */
|
|
|
|
if ( op->o_bd->be_extended ) {
|
|
|
|
rs->sr_err = op->o_bd->be_extended( op, rs );
|
2004-03-01 03:04:34 +08:00
|
|
|
if ( rs->sr_err != LDAP_UNWILLING_TO_PERFORM &&
|
2006-01-02 20:44:38 +08:00
|
|
|
rs->sr_err != SLAP_CB_CONTINUE )
|
|
|
|
{
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = rs->sr_err;
|
2006-01-02 20:44:38 +08:00
|
|
|
if ( rsp ) {
|
|
|
|
rs->sr_rspdata = rsp;
|
|
|
|
rsp = NULL;
|
|
|
|
}
|
2004-07-20 08:22:05 +08:00
|
|
|
goto error_return;
|
2003-12-01 20:51:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The backend didn't handle it, so try it here */
|
|
|
|
if( op->o_bd && !op->o_bd->be_modify ) {
|
|
|
|
rs->sr_text = "operation not supported for current user";
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto error_return;
|
2003-12-01 20:51:54 +08:00
|
|
|
}
|
|
|
|
|
2005-09-29 16:00:33 +08:00
|
|
|
if ( qpw->rs_old.bv_val != NULL ) {
|
2005-10-01 23:12:39 +08:00
|
|
|
Entry *e = NULL;
|
|
|
|
|
|
|
|
rc = be_entry_get_rw( op, &op->o_req_ndn, NULL,
|
|
|
|
slap_schema.si_ad_userPassword, 0, &e );
|
|
|
|
if ( rc == LDAP_SUCCESS && e ) {
|
|
|
|
Attribute *a = attr_find( e->e_attrs,
|
|
|
|
slap_schema.si_ad_userPassword );
|
2008-11-07 00:58:03 +08:00
|
|
|
if ( a )
|
2005-10-01 23:12:39 +08:00
|
|
|
rc = slap_passwd_check( op, e, a, &qpw->rs_old, &rs->sr_text );
|
|
|
|
else
|
|
|
|
rc = 1;
|
|
|
|
be_entry_release_r( op, e );
|
|
|
|
if ( rc == LDAP_SUCCESS )
|
|
|
|
goto old_good;
|
|
|
|
}
|
2005-09-29 16:00:33 +08:00
|
|
|
rs->sr_text = "unwilling to verify old password";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
2005-10-01 23:12:39 +08:00
|
|
|
old_good:
|
2004-03-03 06:12:23 +08:00
|
|
|
ml = ch_malloc( sizeof(Modifications) );
|
|
|
|
if ( !qpw->rs_modtail ) qpw->rs_modtail = &ml->sml_next;
|
|
|
|
|
2004-10-06 13:51:38 +08:00
|
|
|
if ( default_passwd_hash ) {
|
|
|
|
for ( nhash = 0; default_passwd_hash[nhash]; nhash++ );
|
|
|
|
hashes = default_passwd_hash;
|
2004-03-03 06:12:23 +08:00
|
|
|
} else {
|
|
|
|
nhash = 1;
|
|
|
|
hashes = (char **)defhash;
|
2003-12-01 20:38:11 +08:00
|
|
|
}
|
2007-09-21 16:43:56 +08:00
|
|
|
ml->sml_numvals = nhash;
|
2004-03-03 06:12:23 +08:00
|
|
|
ml->sml_values = ch_malloc( (nhash+1)*sizeof(struct berval) );
|
|
|
|
for ( i=0; hashes[i]; i++ ) {
|
2004-03-16 04:58:41 +08:00
|
|
|
slap_passwd_hash_type( &qpw->rs_new, &hash, hashes[i], &rs->sr_text );
|
2004-03-03 06:12:23 +08:00
|
|
|
if ( hash.bv_len == 0 ) {
|
|
|
|
if ( !rs->sr_text ) {
|
|
|
|
rs->sr_text = "password hash failed";
|
|
|
|
}
|
|
|
|
break;
|
2003-12-01 20:38:11 +08:00
|
|
|
}
|
2004-03-03 06:12:23 +08:00
|
|
|
ml->sml_values[i] = hash;
|
2003-12-01 20:38:11 +08:00
|
|
|
}
|
2004-03-03 06:12:23 +08:00
|
|
|
ml->sml_values[i].bv_val = NULL;
|
2004-03-01 03:04:34 +08:00
|
|
|
ml->sml_nvalues = NULL;
|
2004-03-03 06:12:23 +08:00
|
|
|
ml->sml_desc = slap_schema.si_ad_userPassword;
|
2005-12-22 04:43:14 +08:00
|
|
|
ml->sml_type = ml->sml_desc->ad_cname;
|
2004-03-18 06:21:21 +08:00
|
|
|
ml->sml_op = LDAP_MOD_REPLACE;
|
2005-06-04 17:44:39 +08:00
|
|
|
ml->sml_flags = 0;
|
2004-03-01 03:04:34 +08:00
|
|
|
ml->sml_next = qpw->rs_mods;
|
|
|
|
qpw->rs_mods = ml;
|
2004-03-16 12:24:39 +08:00
|
|
|
|
2004-03-03 06:12:23 +08:00
|
|
|
if ( hashes[i] ) {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
2003-12-01 20:38:11 +08:00
|
|
|
|
2004-07-20 08:22:05 +08:00
|
|
|
} else {
|
2005-03-14 08:12:48 +08:00
|
|
|
slap_callback *sc = op->o_callback;
|
|
|
|
|
|
|
|
op->o_tag = LDAP_REQ_MODIFY;
|
2007-04-06 08:21:02 +08:00
|
|
|
op->o_callback = &cb;
|
2005-03-14 08:12:48 +08:00
|
|
|
op->orm_modlist = qpw->rs_mods;
|
2007-05-19 22:06:42 +08:00
|
|
|
op->orm_no_opattrs = 0;
|
|
|
|
|
2007-04-06 08:21:02 +08:00
|
|
|
cb.sc_private = qpw; /* let Modify know this was pwdMod,
|
2004-03-16 03:52:17 +08:00
|
|
|
* if it cares... */
|
2003-12-01 20:38:11 +08:00
|
|
|
|
2005-10-13 19:58:44 +08:00
|
|
|
rs->sr_err = op->o_bd->be_modify( op, rs );
|
2006-09-03 18:53:38 +08:00
|
|
|
|
|
|
|
/* be_modify() might have shuffled modifications */
|
|
|
|
qpw->rs_mods = op->orm_modlist;
|
|
|
|
|
2004-03-03 06:12:23 +08:00
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
|
|
|
rs->sr_rspdata = rsp;
|
2006-09-03 18:53:38 +08:00
|
|
|
|
2004-03-03 06:12:23 +08:00
|
|
|
} else if ( rsp ) {
|
|
|
|
ber_bvfree( rsp );
|
2006-01-02 20:44:38 +08:00
|
|
|
rsp = NULL;
|
2004-03-03 06:12:23 +08:00
|
|
|
}
|
2005-03-14 08:12:48 +08:00
|
|
|
op->o_tag = LDAP_REQ_EXTENDED;
|
|
|
|
op->o_callback = sc;
|
1999-12-10 05:30:32 +08:00
|
|
|
}
|
|
|
|
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = rs->sr_err;
|
2005-03-14 08:12:48 +08:00
|
|
|
op->oq_extended = qext;
|
2004-07-20 08:22:05 +08:00
|
|
|
|
|
|
|
error_return:;
|
2006-01-02 20:44:38 +08:00
|
|
|
if ( qpw->rs_mods ) {
|
|
|
|
slap_mods_free( qpw->rs_mods, 1 );
|
|
|
|
}
|
|
|
|
if ( freenewpw ) {
|
|
|
|
free( qpw->rs_new.bv_val );
|
|
|
|
}
|
2004-07-20 08:22:05 +08:00
|
|
|
if ( !BER_BVISNULL( &op->o_req_dn ) ) {
|
|
|
|
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
|
2005-11-10 11:42:44 +08:00
|
|
|
BER_BVZERO( &op->o_req_dn );
|
2004-07-20 08:22:05 +08:00
|
|
|
}
|
|
|
|
if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
|
|
|
|
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
|
2005-11-10 11:42:44 +08:00
|
|
|
BER_BVZERO( &op->o_req_ndn );
|
2004-07-20 08:22:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
1999-12-10 05:30:32 +08:00
|
|
|
}
|
|
|
|
|
2007-09-23 12:40:51 +08:00
|
|
|
/* NOTE: The DN in *id is NOT NUL-terminated here. dnNormalize will
|
|
|
|
* reject it in this condition, the caller must NUL-terminate it.
|
|
|
|
* FIXME: should dnNormalize still be complaining about that?
|
|
|
|
*/
|
1999-12-10 05:30:32 +08:00
|
|
|
int slap_passwd_parse( struct berval *reqdata,
|
2002-01-02 19:00:36 +08:00
|
|
|
struct berval *id,
|
|
|
|
struct berval *oldpass,
|
|
|
|
struct berval *newpass,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char **text )
|
1999-12-10 05:30:32 +08:00
|
|
|
{
|
|
|
|
int rc = LDAP_SUCCESS;
|
|
|
|
ber_tag_t tag;
|
2003-12-06 03:54:42 +08:00
|
|
|
ber_len_t len = -1;
|
2003-10-12 12:45:09 +08:00
|
|
|
BerElementBuffer berbuf;
|
|
|
|
BerElement *ber = (BerElement *)&berbuf;
|
1999-12-10 05:30:32 +08:00
|
|
|
|
1999-12-10 12:52:32 +08:00
|
|
|
if( reqdata == NULL ) {
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
1999-12-10 05:30:32 +08:00
|
|
|
|
2002-06-11 03:56:17 +08:00
|
|
|
if( reqdata->bv_len == 0 ) {
|
|
|
|
*text = "empty request data field";
|
|
|
|
return LDAP_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-02-14 21:32:40 +08:00
|
|
|
/* ber_init2 uses reqdata directly, doesn't allocate new buffers */
|
|
|
|
ber_init2( ber, reqdata, 0 );
|
1999-12-08 12:37:59 +08:00
|
|
|
|
2007-09-23 12:40:51 +08:00
|
|
|
tag = ber_skip_tag( ber, &len );
|
1999-12-12 03:33:45 +08:00
|
|
|
|
2007-09-23 12:40:51 +08:00
|
|
|
if( tag != LBER_SEQUENCE ) {
|
2003-12-06 03:54:42 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"slap_passwd_parse: decoding error\n", 0, 0, 0 );
|
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
|
|
|
goto done;
|
1999-12-12 03:33:45 +08:00
|
|
|
}
|
1999-12-10 05:30:32 +08:00
|
|
|
|
2003-12-06 03:54:42 +08:00
|
|
|
tag = ber_peek_tag( ber, &len );
|
2002-01-29 04:25:30 +08:00
|
|
|
if( tag == LDAP_TAG_EXOP_MODIFY_PASSWD_ID ) {
|
1999-12-10 05:30:32 +08:00
|
|
|
if( id == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: ID not allowed.\n",
|
|
|
|
0, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
*text = "user must change own password";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-09-23 12:40:51 +08:00
|
|
|
tag = ber_get_stringbv( ber, id, LBER_BV_NOTERM );
|
1999-12-10 05:30:32 +08:00
|
|
|
|
|
|
|
if( tag == LBER_ERROR ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: ID parse failed.\n",
|
|
|
|
0, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
goto decoding_error;
|
|
|
|
}
|
|
|
|
|
2005-05-30 22:49:47 +08:00
|
|
|
tag = ber_peek_tag( ber, &len );
|
1999-12-08 12:37:59 +08:00
|
|
|
}
|
|
|
|
|
2002-01-29 04:25:30 +08:00
|
|
|
if( tag == LDAP_TAG_EXOP_MODIFY_PASSWD_OLD ) {
|
2000-04-30 23:26:51 +08:00
|
|
|
if( oldpass == NULL ) {
|
1999-12-10 05:30:32 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: OLD not allowed.\n",
|
|
|
|
0, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
*text = "use bind to verify old password";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-09-23 12:40:51 +08:00
|
|
|
tag = ber_get_stringbv( ber, oldpass, LBER_BV_NOTERM );
|
1999-12-10 05:30:32 +08:00
|
|
|
|
|
|
|
if( tag == LBER_ERROR ) {
|
2004-09-23 10:48:14 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: OLD parse failed.\n",
|
1999-12-10 05:30:32 +08:00
|
|
|
0, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
goto decoding_error;
|
|
|
|
}
|
|
|
|
|
2005-09-29 15:49:15 +08:00
|
|
|
if( oldpass->bv_len == 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: OLD empty.\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
|
|
|
|
*text = "old password value is empty";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-03-13 07:07:07 +08:00
|
|
|
tag = ber_peek_tag( ber, &len );
|
1999-12-08 12:37:59 +08:00
|
|
|
}
|
|
|
|
|
2002-01-29 04:25:30 +08:00
|
|
|
if( tag == LDAP_TAG_EXOP_MODIFY_PASSWD_NEW ) {
|
2000-04-30 23:26:51 +08:00
|
|
|
if( newpass == NULL ) {
|
1999-12-10 05:30:32 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: NEW not allowed.\n",
|
|
|
|
0, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
*text = "user specified passwords disallowed";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-12-08 12:37:59 +08:00
|
|
|
|
2007-09-23 12:40:51 +08:00
|
|
|
tag = ber_get_stringbv( ber, newpass, LBER_BV_NOTERM );
|
1999-12-10 05:30:32 +08:00
|
|
|
|
|
|
|
if( tag == LBER_ERROR ) {
|
2004-09-23 10:48:14 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: NEW parse failed.\n",
|
1999-12-10 05:30:32 +08:00
|
|
|
0, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
goto decoding_error;
|
|
|
|
}
|
|
|
|
|
2005-09-29 15:49:15 +08:00
|
|
|
if( newpass->bv_len == 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: NEW empty.\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
|
|
|
|
*text = "new password value is empty";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
tag = ber_peek_tag( ber, &len );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( len != 0 ) {
|
|
|
|
decoding_error:
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"slap_passwd_parse: decoding error, len=%ld\n",
|
|
|
|
(long) len, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
2000-03-03 04:36:53 +08:00
|
|
|
*text = "data decoding error";
|
1999-12-10 05:30:32 +08:00
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
1999-12-08 12:37:59 +08:00
|
|
|
}
|
|
|
|
|
1999-12-10 05:30:32 +08:00
|
|
|
done:
|
1999-12-08 12:37:59 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1999-12-10 12:52:32 +08:00
|
|
|
struct berval * slap_passwd_return(
|
|
|
|
struct berval *cred )
|
|
|
|
{
|
|
|
|
int rc;
|
2001-12-31 14:02:35 +08:00
|
|
|
struct berval *bv = NULL;
|
2003-10-12 12:45:09 +08:00
|
|
|
BerElementBuffer berbuf;
|
2001-12-31 14:02:35 +08:00
|
|
|
/* opaque structure, size unknown but smaller than berbuf */
|
2003-10-12 12:45:09 +08:00
|
|
|
BerElement *ber = (BerElement *)&berbuf;
|
1999-12-10 12:52:32 +08:00
|
|
|
|
|
|
|
assert( cred != NULL );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_return: %ld\n",
|
|
|
|
(long) cred->bv_len, 0, 0 );
|
|
|
|
|
2001-12-31 14:02:35 +08:00
|
|
|
ber_init_w_nullc( ber, LBER_USE_DER );
|
|
|
|
|
2000-06-24 09:40:39 +08:00
|
|
|
rc = ber_printf( ber, "{tON}",
|
2002-01-29 04:25:30 +08:00
|
|
|
LDAP_TAG_EXOP_MODIFY_PASSWD_GEN, cred );
|
1999-12-10 12:52:32 +08:00
|
|
|
|
2001-12-31 14:02:35 +08:00
|
|
|
if( rc >= 0 ) {
|
|
|
|
(void) ber_flatten( ber, &bv );
|
1999-12-10 12:52:32 +08:00
|
|
|
}
|
|
|
|
|
2001-12-31 14:09:29 +08:00
|
|
|
ber_free_buf( ber );
|
1999-12-10 12:52:32 +08:00
|
|
|
|
|
|
|
return bv;
|
|
|
|
}
|
|
|
|
|
2005-01-07 21:50:38 +08:00
|
|
|
/*
|
|
|
|
* if "e" is provided, access to each value of the password is checked first
|
|
|
|
*/
|
1999-11-24 03:00:09 +08:00
|
|
|
int
|
|
|
|
slap_passwd_check(
|
2005-01-07 21:50:38 +08:00
|
|
|
Operation *op,
|
|
|
|
Entry *e,
|
|
|
|
Attribute *a,
|
|
|
|
struct berval *cred,
|
|
|
|
const char **text )
|
1999-11-24 03:00:09 +08:00
|
|
|
{
|
2005-01-07 21:50:38 +08:00
|
|
|
int result = 1;
|
|
|
|
struct berval *bv;
|
|
|
|
AccessControlState acl_state = ACL_STATE_INIT;
|
2008-11-07 00:58:03 +08:00
|
|
|
char credNul = cred->bv_val[cred->bv_len];
|
1999-11-24 03:00:09 +08:00
|
|
|
|
2005-03-18 14:06:38 +08:00
|
|
|
#ifdef SLAPD_SPASSWD
|
2008-01-08 04:08:22 +08:00
|
|
|
void *old_authctx = NULL;
|
|
|
|
|
2008-01-11 14:07:43 +08:00
|
|
|
ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)slap_sasl_bind,
|
|
|
|
op->o_conn->c_sasl_authctx, 0, &old_authctx, NULL );
|
2005-03-18 14:06:38 +08:00
|
|
|
#endif
|
2005-03-18 08:10:10 +08:00
|
|
|
|
2008-11-07 00:58:03 +08:00
|
|
|
if ( credNul ) cred->bv_val[cred->bv_len] = 0;
|
|
|
|
|
2005-03-18 14:06:38 +08:00
|
|
|
for ( bv = a->a_vals; bv->bv_val != NULL; bv++ ) {
|
2005-01-07 21:50:38 +08:00
|
|
|
/* if e is provided, check access */
|
|
|
|
if ( e && access_allowed( op, e, a->a_desc, bv,
|
|
|
|
ACL_AUTH, &acl_state ) == 0 )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2005-03-18 14:06:38 +08:00
|
|
|
|
|
|
|
if ( !lutil_passwd( bv, cred, NULL, text ) ) {
|
2005-03-18 08:10:10 +08:00
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-09-20 08:28:57 +08:00
|
|
|
|
2008-11-07 00:58:03 +08:00
|
|
|
if ( credNul ) cred->bv_val[cred->bv_len] = credNul;
|
|
|
|
|
2005-03-18 14:06:38 +08:00
|
|
|
#ifdef SLAPD_SPASSWD
|
2008-01-11 14:07:43 +08:00
|
|
|
ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)slap_sasl_bind,
|
|
|
|
old_authctx, 0, NULL, NULL );
|
2005-03-18 14:06:38 +08:00
|
|
|
#endif
|
|
|
|
|
2000-09-20 08:28:57 +08:00
|
|
|
return result;
|
1999-11-24 03:00:09 +08:00
|
|
|
}
|
1999-12-08 12:37:59 +08:00
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
void
|
|
|
|
slap_passwd_generate( struct berval *pass )
|
1999-12-10 12:52:32 +08:00
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "slap_passwd_generate\n", 0, 0, 0 );
|
2006-05-14 23:11:23 +08:00
|
|
|
BER_BVZERO( pass );
|
2004-03-03 06:12:23 +08:00
|
|
|
|
1999-12-12 03:33:45 +08:00
|
|
|
/*
|
|
|
|
* generate passwords of only 8 characters as some getpass(3)
|
|
|
|
* implementations truncate at 8 characters.
|
|
|
|
*/
|
2004-03-03 06:12:23 +08:00
|
|
|
lutil_passwd_generate( pass, 8 );
|
1999-12-10 12:52:32 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
void
|
2004-03-16 04:58:41 +08:00
|
|
|
slap_passwd_hash_type(
|
2002-01-02 19:00:36 +08:00
|
|
|
struct berval * cred,
|
2003-04-30 15:52:05 +08:00
|
|
|
struct berval * new,
|
2004-03-16 04:58:41 +08:00
|
|
|
char *hash,
|
2003-04-30 15:52:05 +08:00
|
|
|
const char **text )
|
1999-12-08 12:37:59 +08:00
|
|
|
{
|
2004-03-03 06:12:23 +08:00
|
|
|
new->bv_len = 0;
|
|
|
|
new->bv_val = NULL;
|
1999-12-08 12:37:59 +08:00
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( hash != NULL );
|
2004-03-16 03:52:17 +08:00
|
|
|
|
2004-03-03 06:12:23 +08:00
|
|
|
lutil_passwd_hash( cred , hash, new, text );
|
1999-12-08 12:37:59 +08:00
|
|
|
}
|
2004-03-16 04:58:41 +08:00
|
|
|
void
|
|
|
|
slap_passwd_hash(
|
|
|
|
struct berval * cred,
|
|
|
|
struct berval * new,
|
|
|
|
const char **text )
|
|
|
|
{
|
2004-03-16 11:24:08 +08:00
|
|
|
char *hash = NULL;
|
2004-10-06 13:51:38 +08:00
|
|
|
if ( default_passwd_hash ) {
|
|
|
|
hash = default_passwd_hash[0];
|
2004-03-16 04:58:41 +08:00
|
|
|
}
|
|
|
|
if ( !hash ) {
|
|
|
|
hash = (char *)defhash[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
slap_passwd_hash_type( cred, new, hash, text );
|
|
|
|
}
|
2005-03-18 14:06:38 +08:00
|
|
|
|
|
|
|
#ifdef SLAPD_CRYPT
|
|
|
|
static ldap_pvt_thread_mutex_t passwd_mutex;
|
|
|
|
static lutil_cryptfunc slapd_crypt;
|
|
|
|
|
2005-03-18 14:12:54 +08:00
|
|
|
static int slapd_crypt( const char *key, const char *salt, char **hash )
|
2005-03-18 14:06:38 +08:00
|
|
|
{
|
|
|
|
char *cr;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &passwd_mutex );
|
|
|
|
|
|
|
|
cr = crypt( key, salt );
|
|
|
|
if ( cr == NULL || cr[0] == '\0' ) {
|
|
|
|
/* salt must have been invalid */
|
|
|
|
rc = LUTIL_PASSWD_ERR;
|
|
|
|
} else {
|
|
|
|
if ( hash ) {
|
|
|
|
*hash = ber_strdup( cr );
|
|
|
|
rc = LUTIL_PASSWD_OK;
|
2005-06-28 23:58:33 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
rc = strcmp( salt, cr ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
|
2005-03-18 14:06:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif /* SLAPD_CRYPT */
|
|
|
|
|
2005-03-18 14:12:27 +08:00
|
|
|
void slap_passwd_init()
|
|
|
|
{
|
|
|
|
#ifdef SLAPD_CRYPT
|
|
|
|
ldap_pvt_thread_mutex_init( &passwd_mutex );
|
|
|
|
lutil_cryptptr = slapd_crypt;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|