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/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 2000-2004 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/krb.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
2000-09-26 13:33:37 +08:00
|
|
|
#include "external.h"
|
2000-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
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
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
|
|
|
|
char krbname[MAX_K_NAME_SZ + 1];
|
|
|
|
AttributeDescription *krbattr = slap_schema.si_ad_krbName;
|
2003-03-30 17:03:54 +08:00
|
|
|
struct berval krbval;
|
2000-09-26 07:46:54 +08:00
|
|
|
AUTH_DAT ad;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
AttributeDescription *password = slap_schema.si_ad_userPassword;
|
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
u_int32_t locker;
|
|
|
|
DB_LOCK lock;
|
|
|
|
|
2002-03-27 01:34:57 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2003-03-30 17:03:54 +08:00
|
|
|
LDAP_LOG ( OPERATION, ARGS, "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0 );
|
2002-03-27 01:34:57 +08:00
|
|
|
#else
|
2003-03-30 17:03:54 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0);
|
2002-03-27 01:34:57 +08:00
|
|
|
#endif
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
/* allow noauth binds */
|
|
|
|
if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
|
|
|
|
ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
|
|
|
|
/* front end will send result */
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ) {
|
|
|
|
rs->sr_ref = is_entry_referral( e )
|
|
|
|
? get_entry_referrals( op, e )
|
2000-09-26 07:46:54 +08:00
|
|
|
: NULL;
|
2003-03-30 17:03:54 +08:00
|
|
|
if (rs->sr_ref)
|
2003-04-17 00:23:36 +08:00
|
|
|
rs->sr_matched = ch_strdup( e->e_name.bv_val );
|
2000-09-28 10:27:49 +08:00
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
|
|
|
|
e = NULL;
|
2000-09-26 07:46:54 +08:00
|
|
|
} else {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = referral_rewrite( default_referral,
|
|
|
|
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
2000-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_ref != NULL ) {
|
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
free( (char *)rs->sr_matched );
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2000-09-26 07:46:54 +08:00
|
|
|
} else {
|
2003-03-30 17:03:54 +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
|
|
|
#ifdef BDB_SUBENTRIES
|
|
|
|
if ( is_entry_subentry( e ) ) {
|
|
|
|
/* entry is an subentry, don't allow bind */
|
2002-03-27 01:34:57 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, DETAIL1,
|
|
|
|
"bdb_bind: entry is subentry\n", 0, 0, 0 );
|
2002-03-27 01:34:57 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
|
2002-01-29 12:53:47 +08:00
|
|
|
0, 0 );
|
2002-03-27 01:34:57 +08:00
|
|
|
#endif
|
2002-01-29 12:53:47 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2003-04-23 01:00:04 +08:00
|
|
|
send_ldap_result( op, rs );
|
2002-01-29 12:53:47 +08:00
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#endif
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2002-01-29 12:53:47 +08:00
|
|
|
#ifdef BDB_ALIASES
|
2000-09-26 07:46:54 +08:00
|
|
|
if ( is_entry_alias( e ) ) {
|
|
|
|
/* entry is an alias, don't allow bind */
|
2002-03-27 01:34:57 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, DETAIL1, "bdb_bind: entry is alias\n", 0, 0, 0 );
|
2002-03-27 01:34:57 +08:00
|
|
|
#else
|
2000-09-26 07:46:54 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
|
2000-09-28 06:28:59 +08:00
|
|
|
0, 0 );
|
2002-03-27 01:34:57 +08:00
|
|
|
#endif
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2003-04-05 14:35:16 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_ALIAS_PROBLEM, "entry is alias");
|
2000-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
2002-01-29 12:53:47 +08:00
|
|
|
#endif
|
2000-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
if ( is_entry_referral( e ) ) {
|
|
|
|
/* entry is a referral, don't allow bind */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = get_entry_referrals( op, e );
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2002-03-27 01:34:57 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, DETAIL1,
|
|
|
|
"bdb_bind: entry is referral\n", 0, 0, 0 );
|
2002-03-27 01:34:57 +08:00
|
|
|
#else
|
2000-09-26 07:46:54 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
|
2000-09-28 06:28:59 +08:00
|
|
|
0, 0 );
|
2002-03-27 01:34:57 +08:00
|
|
|
#endif
|
2000-09-26 07:46:54 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( rs->sr_ref != NULL ) {
|
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
rs->sr_matched = e->e_name.bv_val;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2000-09-26 07:46:54 +08:00
|
|
|
} else {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
send_ldap_result( op, rs );
|
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:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = access_allowed( op, e,
|
2002-12-30 09:12:10 +08:00
|
|
|
password, NULL, ACL_AUTH, NULL );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( ! rs->sr_err ) {
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-04-30 15:52:05 +08:00
|
|
|
if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = 0;
|
2000-09-26 07:46:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
|
|
|
|
case LDAP_AUTH_KRBV41:
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad ) != LDAP_SUCCESS ) {
|
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS,
|
|
|
|
send_ldap_result( op );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = access_allowed( op, e,
|
2002-12-30 09:12:10 +08:00
|
|
|
krbattr, NULL, ACL_AUTH, NULL );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( ! rs->sr_err ) {
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS,
|
|
|
|
send_ldap_result( op );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
krbval.bv_len = sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
|
2000-09-28 06:28:59 +08:00
|
|
|
: "", ad.pinst, ad.prealm );
|
2000-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
|
|
|
|
/*
|
2001-11-27 11:41:03 +08:00
|
|
|
* no krbname values present: check against DN
|
2000-09-26 07:46:54 +08:00
|
|
|
*/
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
|
|
|
|
rs->sr_err = 0;
|
2000-09-26 07:46:54 +08:00
|
|
|
break;
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INAPPROPRIATE_AUTH,
|
|
|
|
send_ldap_result( op );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
} else { /* look for krbname match */
|
|
|
|
krbval.bv_val = krbname;
|
|
|
|
|
|
|
|
if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
send_ldap_result( op );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = 0;
|
2000-09-26 07:46:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_AUTH_KRBV42:
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
|
|
|
|
"Kerberos bind step 2 not supported" );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_STRONG_AUTH_NOT_SUPPORTED,
|
|
|
|
"authentication method not supported" );
|
2000-09-26 07:46:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* free entry and reader lock */
|
2000-09-28 10:27:49 +08:00
|
|
|
if( e != NULL ) {
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, 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);
|
|
|
|
|
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
|
|
|
}
|