2000-09-26 11:47:56 +08:00
|
|
|
/* passwd.c - bdb backend password routines */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
2000-09-26 11:47:56 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
2000-09-26 13:33:37 +08:00
|
|
|
#include "external.h"
|
2003-02-16 14:15:28 +08:00
|
|
|
#include "lber_pvt.h"
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
int
|
2003-03-30 17:03:54 +08:00
|
|
|
bdb_exop_passwd( Operation *op, SlapReply *rs )
|
2000-09-26 11:47:56 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2000-09-26 11:47:56 +08:00
|
|
|
int rc;
|
|
|
|
Entry *e = NULL;
|
2003-04-17 00:23:36 +08:00
|
|
|
EntryInfo *ei;
|
2002-01-02 19:00:36 +08:00
|
|
|
struct berval hash = { 0, NULL };
|
2003-04-17 00:23:36 +08:00
|
|
|
DB_TXN *ltid = NULL, *lt2;
|
2000-09-28 06:28:59 +08:00
|
|
|
struct bdb_op_info opinfo;
|
2001-06-15 15:08:37 +08:00
|
|
|
char textbuf[SLAP_TEXT_BUFLEN];
|
|
|
|
size_t textlen = sizeof textbuf;
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
struct berval id = { 0, NULL };
|
|
|
|
struct berval new = { 0, NULL };
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2003-03-23 00:38:31 +08:00
|
|
|
struct berval dn = { 0, NULL };
|
|
|
|
struct berval ndn = { 0, NULL };
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2003-02-07 23:47:32 +08:00
|
|
|
u_int32_t locker = 0;
|
2002-06-01 04:49:19 +08:00
|
|
|
DB_LOCK lock;
|
|
|
|
|
2003-07-01 19:55:18 +08:00
|
|
|
int num_retries = 0;
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->oq_extended.rs_reqoid ) == 0 );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = slap_passwd_parse( op->oq_extended.rs_reqdata,
|
|
|
|
&id, NULL, &new, &rs->sr_text );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-03-16 01:21:06 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( ACL, ENTRY,
|
|
|
|
"==>bdb_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0, 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#else
|
2000-09-26 11:47:56 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
|
2002-01-02 19:00:36 +08:00
|
|
|
id.bv_val ? id.bv_val : "", 0, 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#endif
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
if( new.bv_len == 0 ) {
|
|
|
|
slap_passwd_generate(&new);
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
if( new.bv_len == 0 ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "password generation failed.";
|
2000-09-26 11:47:56 +08:00
|
|
|
rc = LDAP_OTHER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_rspdata = slap_passwd_return( &new );
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:52:05 +08:00
|
|
|
slap_passwd_hash( &new, &hash, &rs->sr_text );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
if( hash.bv_len == 0 ) {
|
2003-04-30 15:52:05 +08:00
|
|
|
if( !rs->sr_text ) rs->sr_text = "password hash failed";
|
2000-09-26 11:47:56 +08:00
|
|
|
rc = LDAP_OTHER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-03-13 06:46:13 +08:00
|
|
|
if( id.bv_len ) {
|
|
|
|
dn = id;
|
|
|
|
} else {
|
|
|
|
dn = op->o_dn;
|
|
|
|
}
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-03-16 01:21:06 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
|
|
|
|
dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#else
|
2000-09-28 10:27:49 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
|
2002-03-13 06:46:13 +08:00
|
|
|
dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#endif
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-03-13 06:46:13 +08:00
|
|
|
if( dn.bv_len == 0 ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "No password is associated with the Root DSE";
|
2002-08-01 06:49:02 +08:00
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
2000-09-26 11:47:56 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-04-30 02:28:14 +08:00
|
|
|
rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, op->o_tmpmemctx );
|
2002-03-13 06:46:13 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "Invalid DN";
|
2002-03-13 06:46:13 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2001-11-28 05:59:56 +08:00
|
|
|
if( 0 ) {
|
2000-09-28 10:27:49 +08:00
|
|
|
retry: /* transaction retry */
|
2002-01-25 15:19:01 +08:00
|
|
|
if ( e != NULL ) {
|
2003-02-15 06:30:07 +08:00
|
|
|
bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
2002-03-16 01:21:06 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#else
|
2000-09-28 10:27:49 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#endif
|
2002-02-02 11:28:32 +08:00
|
|
|
rc = TXN_ABORT( ltid );
|
2000-09-28 06:28:59 +08:00
|
|
|
ltid = NULL;
|
|
|
|
op->o_private = NULL;
|
2003-02-26 20:09:10 +08:00
|
|
|
op->o_do_not_cache = opinfo.boi_acl_cache;
|
2000-09-28 06:28:59 +08:00
|
|
|
if( rc != 0 ) {
|
|
|
|
rc = LDAP_OTHER;
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "internal error";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2002-01-18 21:34:50 +08:00
|
|
|
ldap_pvt_thread_yield();
|
2003-09-27 11:16:38 +08:00
|
|
|
bdb_trans_backoff( ++num_retries );
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
2002-01-29 06:57:50 +08:00
|
|
|
/* begin transaction */
|
2002-02-02 11:28:32 +08:00
|
|
|
rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
|
2002-01-29 06:57:50 +08:00
|
|
|
bdb->bi_db_opflags );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = NULL;
|
2002-01-29 06:57:50 +08:00
|
|
|
if( rc != 0 ) {
|
2002-03-16 01:21:06 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( ACL, ERR,
|
|
|
|
"bdb_exop_passwd: txn_begin failed: %s (%d)\n",
|
|
|
|
db_strerror(rc), rc, 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#else
|
2002-01-29 06:57:50 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"bdb_exop_passwd: txn_begin failed: %s (%d)\n",
|
|
|
|
db_strerror(rc), rc, 0 );
|
2002-03-16 01:21:06 +08:00
|
|
|
#endif
|
2002-01-29 06:57:50 +08:00
|
|
|
rc = LDAP_OTHER;
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "internal error";
|
2002-01-29 06:57:50 +08:00
|
|
|
goto done;
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
locker = TXN_ID ( ltid );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
opinfo.boi_bdb = op->o_bd;
|
2000-09-28 06:28:59 +08:00
|
|
|
opinfo.boi_txn = ltid;
|
2003-02-07 23:47:32 +08:00
|
|
|
opinfo.boi_locker = locker;
|
2000-09-28 06:28:59 +08:00
|
|
|
opinfo.boi_err = 0;
|
2003-02-26 20:09:10 +08:00
|
|
|
opinfo.boi_acl_cache = op->o_do_not_cache;
|
2000-09-28 06:28:59 +08:00
|
|
|
op->o_private = &opinfo;
|
|
|
|
|
|
|
|
/* get entry */
|
2003-05-25 08:53:08 +08:00
|
|
|
rc = bdb_dn2entry( op, ltid, &ndn, &ei, 0 , locker, &lock );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
switch(rc) {
|
2000-09-28 06:28:59 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
2000-09-26 11:47:56 +08:00
|
|
|
case DB_NOTFOUND:
|
|
|
|
case 0:
|
|
|
|
break;
|
2002-04-20 05:41:32 +08:00
|
|
|
case LDAP_BUSY:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "ldap server busy";
|
2002-04-20 05:41:32 +08:00
|
|
|
goto done;
|
2000-09-26 11:47:56 +08:00
|
|
|
default:
|
2000-09-28 06:28:59 +08:00
|
|
|
rc = LDAP_OTHER;
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "internal error";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto done;
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
if ( ei ) e = ei->bei_e;
|
|
|
|
|
2003-06-28 08:52:40 +08:00
|
|
|
if ( e == NULL || is_entry_glue( e )) {
|
2003-07-15 08:43:39 +08:00
|
|
|
/* FIXME: dn2entry() should return non-glue entry */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "could not locate authorization entry";
|
2000-10-12 02:19:26 +08:00
|
|
|
rc = LDAP_NO_SUCH_OBJECT;
|
2000-09-26 11:47:56 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-01-29 12:53:47 +08:00
|
|
|
#ifdef BDB_SUBENTRIES
|
2002-04-05 14:28:52 +08:00
|
|
|
if( is_entry_subentry( e ) ) {
|
2003-05-01 00:39:40 +08:00
|
|
|
/* entry is a subentry, don't allow operation */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "authorization entry is subentry";
|
2002-01-29 12:53:47 +08:00
|
|
|
rc = LDAP_OTHER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#endif
|
2003-07-15 08:43:39 +08:00
|
|
|
|
2002-01-29 12:53:47 +08:00
|
|
|
#ifdef BDB_ALIASES
|
2000-09-26 11:47:56 +08:00
|
|
|
if( is_entry_alias( e ) ) {
|
|
|
|
/* entry is an alias, don't allow operation */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "authorization entry is alias";
|
2000-09-26 11:47:56 +08:00
|
|
|
rc = LDAP_ALIAS_PROBLEM;
|
|
|
|
goto done;
|
|
|
|
}
|
2002-01-29 12:53:47 +08:00
|
|
|
#endif
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
if( is_entry_referral( e ) ) {
|
|
|
|
/* entry is an referral, don't allow operation */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "authorization entry is referral";
|
2002-01-29 12:53:47 +08:00
|
|
|
rc = LDAP_OTHER;
|
2000-09-26 11:47:56 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
/* nested transaction */
|
|
|
|
rc = TXN_BEGIN( bdb->bi_dbenv, ltid, <2,
|
|
|
|
bdb->bi_db_opflags );
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
if( rc != 0 ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( OPERATION, ERR,
|
2003-09-16 05:53:58 +08:00
|
|
|
"bdb_exop_passwd: txn_begin(2) failed: %s (%d)\n",
|
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
2003-04-17 00:23:36 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"bdb_exop_passwd: txn_begin(2) failed: %s (%d)\n",
|
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
|
|
|
#endif
|
|
|
|
rc = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
|
|
|
goto done;
|
|
|
|
}
|
2003-09-16 05:53:58 +08:00
|
|
|
|
2000-09-26 11:47:56 +08:00
|
|
|
{
|
|
|
|
Modifications ml;
|
2002-01-02 19:00:36 +08:00
|
|
|
struct berval vals[2];
|
2003-04-17 00:23:36 +08:00
|
|
|
Entry dummy, *save;
|
|
|
|
|
|
|
|
save = e;
|
|
|
|
dummy = *e;
|
|
|
|
e = &dummy;
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
vals[0] = hash;
|
2002-01-02 19:00:36 +08:00
|
|
|
vals[1].bv_val = NULL;
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
ml.sml_desc = slap_schema.si_ad_userPassword;
|
2003-02-26 06:49:41 +08:00
|
|
|
ml.sml_values = vals;
|
2003-03-16 14:03:23 +08:00
|
|
|
ml.sml_nvalues = NULL;
|
2000-09-26 11:47:56 +08:00
|
|
|
ml.sml_op = LDAP_MOD_REPLACE;
|
|
|
|
ml.sml_next = NULL;
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
rc = bdb_modify_internal( op, lt2,
|
2003-03-30 17:03:54 +08:00
|
|
|
&ml, e, &rs->sr_text, textbuf, textlen );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-02-26 20:49:21 +08:00
|
|
|
if ( (rc == LDAP_INSUFFICIENT_ACCESS) && opinfo.boi_err ) {
|
|
|
|
rc = opinfo.boi_err;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
switch(rc) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = NULL;
|
2000-09-28 06:28:59 +08:00
|
|
|
goto retry;
|
|
|
|
case 0:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = NULL;
|
2000-09-28 06:28:59 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = LDAP_OTHER;
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "entry modify failed";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2001-12-26 02:20:35 +08:00
|
|
|
/* change the entry itself */
|
2003-04-17 00:23:36 +08:00
|
|
|
rc = bdb_id2entry_update( op->o_bd, lt2, e );
|
2001-12-26 02:20:35 +08:00
|
|
|
if( rc != 0 ) {
|
|
|
|
switch(rc) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "entry update failed";
|
2001-12-26 02:20:35 +08:00
|
|
|
rc = LDAP_OTHER;
|
|
|
|
}
|
2003-04-17 00:23:36 +08:00
|
|
|
if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
|
|
|
|
rc = LDAP_OTHER;
|
|
|
|
rs->sr_text = "txn_commit(2) failed";
|
|
|
|
}
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-01-29 06:57:50 +08:00
|
|
|
if( rc == 0 ) {
|
2002-01-29 08:02:27 +08:00
|
|
|
if( op->o_noop ) {
|
2002-02-02 11:28:32 +08:00
|
|
|
rc = TXN_ABORT( ltid );
|
2002-01-29 08:02:27 +08:00
|
|
|
} else {
|
2003-04-17 00:23:36 +08:00
|
|
|
bdb_cache_modify( save, e->e_attrs,
|
|
|
|
bdb->bi_dbenv, locker, &lock );
|
2002-02-02 11:28:32 +08:00
|
|
|
rc = TXN_COMMIT( ltid, 0 );
|
2002-01-29 08:02:27 +08:00
|
|
|
}
|
2001-12-26 02:20:35 +08:00
|
|
|
ltid = NULL;
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
2001-12-26 02:20:35 +08:00
|
|
|
op->o_private = NULL;
|
2001-11-27 11:41:03 +08:00
|
|
|
|
2001-12-26 02:20:35 +08:00
|
|
|
if( rc == LDAP_SUCCESS ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
op->o_req_dn = e->e_name;
|
|
|
|
op->o_req_ndn = e->e_nname;
|
|
|
|
op->oq_modify.rs_modlist = &ml;
|
|
|
|
replog( op );
|
|
|
|
op->oq_extended.rs_reqoid = slap_EXOP_MODIFY_PASSWD;
|
2001-12-26 02:20:35 +08:00
|
|
|
}
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2000-09-26 11:47:56 +08:00
|
|
|
done:
|
|
|
|
if( e != NULL ) {
|
2003-02-15 06:30:07 +08:00
|
|
|
bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e );
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
2002-01-25 15:19:01 +08:00
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
if( hash.bv_val != NULL ) {
|
|
|
|
free( hash.bv_val );
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
2003-03-23 00:59:41 +08:00
|
|
|
if( ndn.bv_val != NULL ) {
|
2003-04-12 18:47:11 +08:00
|
|
|
op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
|
2003-03-23 00:59:41 +08:00
|
|
|
}
|
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
if( ltid != NULL ) {
|
2002-02-02 11:28:32 +08:00
|
|
|
TXN_ABORT( ltid );
|
2000-09-28 06:28:59 +08:00
|
|
|
op->o_private = NULL;
|
|
|
|
}
|
|
|
|
|
2000-09-26 11:47:56 +08:00
|
|
|
return rc;
|
|
|
|
}
|