X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Fbind.c;h=526786be5922aeed5e17d9308704e6e0ca884ed3;hb=95d472aa9830a031821f2c6274aff38aa4eb0990;hp=c4a2092e0a9ec28b0461411c6357f1c76793e61e;hpb=b29e311ae7d44186295963c22898d72b6f49ef3c;p=openldap diff --git a/servers/slapd/back-bdb/bind.c b/servers/slapd/back-bdb/bind.c index c4a2092e0a..526786be59 100644 --- a/servers/slapd/back-bdb/bind.c +++ b/servers/slapd/back-bdb/bind.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2000-2004 The OpenLDAP Foundation. + * Copyright 2000-2008 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -17,12 +17,10 @@ #include "portable.h" #include -#include #include #include #include "back-bdb.h" -#include "external.h" int bdb_bind( Operation *op, SlapReply *rs ) @@ -31,29 +29,33 @@ bdb_bind( Operation *op, SlapReply *rs ) Entry *e; Attribute *a; EntryInfo *ei; -#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND - char krbname[MAX_K_NAME_SZ + 1]; - AttributeDescription *krbattr = slap_schema.si_ad_krbName; - struct berval krbval; - AUTH_DAT ad; -#endif AttributeDescription *password = slap_schema.si_ad_userPassword; - u_int32_t locker; + DB_TXN *rtxn; DB_LOCK lock; Debug( LDAP_DEBUG_ARGS, - "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0); + "==> " LDAP_XSTRING(bdb_bind) ": dn: %s\n", + op->o_req_dn.bv_val, 0, 0); /* 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; + switch ( be_rootdn_bind( op, NULL ) ) { + case LDAP_SUCCESS: + /* frontend will send result */ + return rs->sr_err; + + default: + /* give the database a chanche */ + /* 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. */ + break; } - rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker); + rs->sr_err = bdb_reader_get(op, bdb->bi_dbenv, &rtxn); switch(rs->sr_err) { case 0: break; @@ -65,8 +67,8 @@ bdb_bind( Operation *op, SlapReply *rs ) dn2entry_retry: /* get entry with reader lock */ - rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1, - locker, &lock ); + rs->sr_err = bdb_dn2entry( op, rtxn, &op->o_req_ndn, &ei, 1, + &lock ); switch(rs->sr_err) { case DB_NOTFOUND: @@ -74,37 +76,31 @@ dn2entry_retry: break; case LDAP_BUSY: send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" ); - LOCK_ID_FREE(bdb->bi_dbenv, locker); return LDAP_BUSY; case DB_LOCK_DEADLOCK: case DB_LOCK_NOTGRANTED: goto dn2entry_retry; default: send_ldap_error( op, rs, LDAP_OTHER, "internal error" ); - LOCK_ID_FREE(bdb->bi_dbenv, locker); return rs->sr_err; } e = ei->bei_e; if ( rs->sr_err == DB_NOTFOUND ) { if( e != NULL ) { - bdb_cache_return_entry_r( bdb->bi_dbenv, - &bdb->bi_cache, e, &lock ); + bdb_cache_return_entry_r( bdb, e, &lock ); e = NULL; } rs->sr_err = LDAP_INVALID_CREDENTIALS; send_ldap_result( op, rs ); - LOCK_ID_FREE(bdb->bi_dbenv, locker); - return rs->sr_err; } ber_dupbv( &op->oq_bind.rb_edn, &e->e_name ); /* check for deleted */ -#ifdef BDB_SUBENTRIES if ( is_entry_subentry( e ) ) { /* entry is an subentry, don't allow bind */ Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0, @@ -112,7 +108,6 @@ dn2entry_retry: rs->sr_err = LDAP_INVALID_CREDENTIALS; goto done; } -#endif if ( is_entry_alias( e ) ) { /* entry is an alias, don't allow bind */ @@ -130,72 +125,25 @@ dn2entry_retry: switch ( op->oq_bind.rb_method ) { case LDAP_AUTH_SIMPLE: - rs->sr_err = access_allowed( op, e, - password, NULL, ACL_AUTH, NULL ); - if ( ! rs->sr_err ) { + a = attr_find( e->e_attrs, password ); + if ( a == NULL ) { rs->sr_err = LDAP_INVALID_CREDENTIALS; goto done; } - if ( (a = attr_find( e->e_attrs, password )) == NULL ) { - rs->sr_err = LDAP_INVALID_CREDENTIALS; - goto done; - } - - if ( slap_passwd_check( op->o_conn, - a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) + if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred, + &rs->sr_text ) != 0 ) { + /* failure; stop front end from sending result */ rs->sr_err = LDAP_INVALID_CREDENTIALS; goto done; } - + rs->sr_err = 0; break; -#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND - case LDAP_AUTH_KRBV41: - if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad ) - != LDAP_SUCCESS ) - { - rs->sr_err = LDAP_INVALID_CREDENTIALS, - goto done; - } - - rs->sr_err = access_allowed( op, e, - krbattr, NULL, ACL_AUTH, NULL ); - if ( ! rs->sr_err ) { - rs->sr_err = LDAP_INSUFFICIENT_ACCESS, - goto done; - } - - krbval.bv_len = sprintf( krbname, "%s%s%s@%s", ad.pname, - *ad.pinst ? "." : "", ad.pinst, ad.prealm ); - - if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) { - /* - * no krbname values present: check against DN - */ - if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) { - rs->sr_err = 0; - break; - } - rs->sr_err = LDAP_INAPPROPRIATE_AUTH, - goto done; - - } else { /* look for krbname match */ - krbval.bv_val = krbname; - - if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) { - rs->sr_err = LDAP_INVALID_CREDENTIALS; - goto done; - } - } - rs->sr_err = 0; - break; -#endif - default: - assert( 0 ); /* should not be unreachable */ + assert( 0 ); /* should not be reachable */ rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED; rs->sr_text = "authentication method not supported"; } @@ -203,11 +151,9 @@ dn2entry_retry: done: /* free entry and reader lock */ if( e != NULL ) { - bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock ); + bdb_cache_return_entry_r( bdb, e, &lock ); } - LOCK_ID_FREE(bdb->bi_dbenv, locker); - if ( rs->sr_err ) { send_ldap_result( op, rs ); if ( rs->sr_ref ) {