2000-09-26 07:46:54 +08:00
|
|
|
/* bind.c - bdb backend bind routine */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2007-01-03 04:00:42 +08:00
|
|
|
* Copyright 2000-2007 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +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>.
|
2000-09-26 07:46:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
|
|
|
|
|
|
|
int
|
2003-03-30 17:03:54 +08:00
|
|
|
bdb_bind( Operation *op, SlapReply *rs )
|
2000-09-26 07:46:54 +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 07:46:54 +08:00
|
|
|
Entry *e;
|
|
|
|
Attribute *a;
|
2003-04-17 00:23:36 +08:00
|
|
|
EntryInfo *ei;
|
2000-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
AttributeDescription *password = slap_schema.si_ad_userPassword;
|
|
|
|
|
2007-08-18 04:33:46 +08:00
|
|
|
BDB_LOCKER locker;
|
2002-06-01 04:49:19 +08:00
|
|
|
DB_LOCK lock;
|
|
|
|
|
2004-03-28 02:19:52 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
2004-11-17 22:53:03 +08:00
|
|
|
"==> " LDAP_XSTRING(bdb_bind) ": dn: %s\n",
|
|
|
|
op->o_req_dn.bv_val, 0, 0);
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2007-08-17 17:51:29 +08:00
|
|
|
/* allow noauth binds */
|
|
|
|
switch ( be_rootdn_bind( op, NULL ) ) {
|
|
|
|
case LDAP_SUCCESS:
|
|
|
|
/* frontend will send result */
|
|
|
|
return rs->sr_err;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* give the database a chanche */
|
2007-09-07 20:33:21 +08:00
|
|
|
/* NOTE: this behavior departs from that of other backends,
|
|
|
|
* since the others, in case of password checking failure
|
|
|
|
* do not give the database a chance. If an entry with
|
|
|
|
* rootdn's name does not exist in the database the result
|
|
|
|
* will be the same. See ITS#4962 for discussion. */
|
2007-08-17 17:51:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
|
|
|
|
switch(rs->sr_err) {
|
2002-08-20 11:10:08 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "internal error";
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
return rs->sr_err;
|
2002-08-20 11:10:08 +08:00
|
|
|
}
|
2002-06-01 04:49:19 +08:00
|
|
|
|
|
|
|
dn2entry_retry:
|
2003-03-30 17:03:54 +08:00
|
|
|
/* get entry with reader lock */
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1,
|
|
|
|
locker, &lock );
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
switch(rs->sr_err) {
|
2000-09-26 07:46:54 +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
|
|
|
send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE(bdb->bi_dbenv, locker);
|
2002-04-20 05:41:32 +08:00
|
|
|
return LDAP_BUSY;
|
2002-06-01 04:49:19 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto dn2entry_retry;
|
2000-09-26 07:46:54 +08:00
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE(bdb->bi_dbenv, locker);
|
2003-03-30 17:03:54 +08:00
|
|
|
return rs->sr_err;
|
2000-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
e = ei->bei_e;
|
|
|
|
if ( rs->sr_err == DB_NOTFOUND ) {
|
|
|
|
if( e != NULL ) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, e, &lock );
|
2003-04-17 00:23:36 +08:00
|
|
|
e = NULL;
|
2000-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
2004-03-28 06:47:31 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE(bdb->bi_dbenv, locker);
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
return rs->sr_err;
|
2000-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
|
2000-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
/* check for deleted */
|
2002-01-29 12:53:47 +08:00
|
|
|
if ( is_entry_subentry( e ) ) {
|
|
|
|
/* entry is an subentry, don't allow bind */
|
2002-03-27 01:34:57 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
|
2002-01-29 12:53:47 +08:00
|
|
|
0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2002-01-29 12:53:47 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2000-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
if ( is_entry_alias( e ) ) {
|
|
|
|
/* entry is an alias, don't allow bind */
|
2004-03-28 02:19:52 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_entry_referral( e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
|
2000-09-28 06:28:59 +08:00
|
|
|
0, 0 );
|
2004-03-28 06:47:31 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
switch ( op->oq_bind.rb_method ) {
|
2000-09-26 07:46:54 +08:00
|
|
|
case LDAP_AUTH_SIMPLE:
|
2005-01-07 21:50:38 +08:00
|
|
|
a = attr_find( e->e_attrs, password );
|
|
|
|
if ( a == NULL ) {
|
2004-03-28 02:19:52 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2005-01-07 21:50:38 +08:00
|
|
|
if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
|
|
|
|
&rs->sr_text ) != 0 )
|
2004-03-28 02:19:52 +08:00
|
|
|
{
|
2005-01-07 21:50:38 +08:00
|
|
|
/* failure; stop front end from sending result */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2005-01-07 21:50:38 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = 0;
|
2000-09-26 07:46:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-01-10 08:23:28 +08:00
|
|
|
assert( 0 ); /* should not be reachable */
|
2004-03-13 05:08:37 +08:00
|
|
|
rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
|
|
|
|
rs->sr_text = "authentication method not supported";
|
2000-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* free entry and reader lock */
|
2000-09-28 10:27:49 +08:00
|
|
|
if( e != NULL ) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, e, &lock );
|
2000-09-28 10:27:49 +08:00
|
|
|
}
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE(bdb->bi_dbenv, locker);
|
|
|
|
|
2004-03-13 05:08:37 +08:00
|
|
|
if ( rs->sr_err ) {
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
if ( rs->sr_ref ) {
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
/* front end will send result on success (rs->sr_err==0) */
|
|
|
|
return rs->sr_err;
|
2000-09-26 13:33:37 +08:00
|
|
|
}
|