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/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 1998-2005 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/krb.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
|
|
|
|
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-01-06 02:32:27 +08:00
|
|
|
slap_callback cb2 = { NULL, slap_replog_cb, NULL, NULL };
|
2004-03-03 06:12:23 +08:00
|
|
|
int i, nhash;
|
|
|
|
char **hashes;
|
2004-07-20 08:22:05 +08:00
|
|
|
int rc;
|
2005-03-17 12:29:31 +08:00
|
|
|
BackendDB *op_be;
|
2003-12-01 20:38:11 +08:00
|
|
|
|
2004-03-08 19:01:52 +08:00
|
|
|
cb2.sc_next = &cb;
|
|
|
|
|
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 ) {
|
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;
|
|
|
|
}
|
|
|
|
|
2004-03-01 03:04:34 +08:00
|
|
|
qpw->rs_old.bv_val = NULL;
|
|
|
|
qpw->rs_new.bv_val = NULL;
|
|
|
|
qpw->rs_mods = NULL;
|
|
|
|
qpw->rs_modtail = NULL;
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-12-01 20:38:11 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
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 );
|
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
|
|
|
}
|
2004-12-05 03:26:22 +08:00
|
|
|
op->o_bd = select_backend( &op->o_req_ndn, 0, 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 ) {
|
|
|
|
#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 )) {
|
|
|
|
op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2003-08-28 06:16:04 +08:00
|
|
|
#ifndef SLAPD_MULTIMASTER
|
2002-11-22 08:56:20 +08:00
|
|
|
/* This does not apply to multi-master case */
|
2004-04-06 17:42:40 +08:00
|
|
|
if(!( !SLAP_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
|
|
|
}
|
2002-11-22 08:56:20 +08:00
|
|
|
#endif /* !SLAPD_MULTIMASTER */
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 &&
|
|
|
|
rs->sr_err != SLAP_CB_CONTINUE ) {
|
2004-07-20 08:22:05 +08:00
|
|
|
rc = rs->sr_err;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
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;
|
2004-03-18 06:21:21 +08:00
|
|
|
ml->sml_op = LDAP_MOD_REPLACE;
|
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;
|
|
|
|
op->o_callback = &cb2;
|
|
|
|
op->orm_modlist = qpw->rs_mods;
|
2004-03-16 03:52:17 +08:00
|
|
|
cb2.sc_private = qpw; /* let Modify know this was pwdMod,
|
|
|
|
* if it cares... */
|
2003-12-01 20:38:11 +08:00
|
|
|
|
2005-03-14 08:12:48 +08:00
|
|
|
rs->sr_err = slap_mods_opattrs( op, ml, qpw->rs_modtail, &rs->sr_text,
|
2004-09-11 10:02:09 +08:00
|
|
|
NULL, 0, 1 );
|
2004-03-03 06:12:23 +08:00
|
|
|
|
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
2005-03-14 08:12:48 +08:00
|
|
|
rs->sr_err = op->o_bd->be_modify( op, rs );
|
2004-03-03 06:12:23 +08:00
|
|
|
}
|
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
|
|
|
rs->sr_rspdata = rsp;
|
|
|
|
} else if ( rsp ) {
|
|
|
|
ber_bvfree( rsp );
|
|
|
|
}
|
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-03-03 06:12:23 +08:00
|
|
|
slap_mods_free( qpw->rs_mods );
|
2004-03-16 03:52:17 +08:00
|
|
|
if ( rsp ) {
|
|
|
|
free( qpw->rs_new.bv_val );
|
|
|
|
}
|
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:;
|
|
|
|
if ( !BER_BVISNULL( &op->o_req_dn ) ) {
|
|
|
|
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
|
|
|
|
}
|
|
|
|
if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
|
|
|
|
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
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
|
|
|
|
1999-12-12 03:33:45 +08:00
|
|
|
tag = ber_scanf( ber, "{" /*}*/ );
|
|
|
|
|
2003-12-06 03:54:42 +08:00
|
|
|
if( tag == LBER_ERROR ) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-01-06 14:11:01 +08:00
|
|
|
tag = ber_scanf( ber, "m", id );
|
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;
|
|
|
|
}
|
|
|
|
|
2002-01-06 14:11:01 +08:00
|
|
|
tag = ber_scanf( ber, "m", oldpass );
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2002-01-06 14:11:01 +08:00
|
|
|
tag = ber_scanf( ber, "m", newpass );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
1999-11-24 03:00:09 +08:00
|
|
|
|
2005-03-18 14:06:38 +08:00
|
|
|
#ifdef SLAPD_SPASSWD
|
|
|
|
ldap_pvt_thread_pool_setkey( op->o_threadctx, slap_sasl_bind,
|
|
|
|
op->o_conn->c_sasl_authctx, NULL );
|
|
|
|
#endif
|
2005-03-18 08:10:10 +08:00
|
|
|
|
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
|
|
|
|
2005-03-18 14:06:38 +08:00
|
|
|
#ifdef SLAPD_SPASSWD
|
|
|
|
ldap_pvt_thread_pool_setkey( op->o_threadctx, slap_sasl_bind,
|
|
|
|
NULL, NULL );
|
|
|
|
#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 );
|
2004-03-03 06:12:23 +08:00
|
|
|
pass->bv_val = NULL;
|
|
|
|
pass->bv_len = 0;
|
|
|
|
|
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
|
|
|
|
2004-03-16 04:58:41 +08:00
|
|
|
assert( hash );
|
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;
|
|
|
|
}
|
|
|
|
rc = strcmp( salt, cr ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|