1 /* bind.c - bdb backend bind routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
21 #include <ac/unistd.h>
26 bdb_bind( Operation *op, SlapReply *rs )
28 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
33 AttributeDescription *password = slap_schema.si_ad_userPassword;
38 Debug( LDAP_DEBUG_ARGS,
39 "==> " LDAP_XSTRING(bdb_bind) ": dn: %s\n",
40 op->o_req_dn.bv_val, 0, 0);
42 /* allow noauth binds */
43 switch ( be_rootdn_bind( op, NULL ) ) {
45 /* frontend will send result */
49 /* give the database a chanche */
50 /* NOTE: this behavior departs from that of other backends,
51 * since the others, in case of password checking failure
52 * do not give the database a chance. If an entry with
53 * rootdn's name does not exist in the database the result
54 * will be the same. See ITS#4962 for discussion. */
58 rs->sr_err = bdb_reader_get(op, bdb->bi_dbenv, &rtxn);
63 rs->sr_text = "internal error";
64 send_ldap_result( op, rs );
69 /* get entry with reader lock */
70 rs->sr_err = bdb_dn2entry( op, rtxn, &op->o_req_ndn, &ei, 1,
78 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
80 case DB_LOCK_DEADLOCK:
81 case DB_LOCK_NOTGRANTED:
84 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
89 if ( rs->sr_err == DB_NOTFOUND ) {
91 bdb_cache_return_entry_r( bdb, e, &lock );
95 rs->sr_err = LDAP_INVALID_CREDENTIALS;
96 send_ldap_result( op, rs );
101 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
103 /* check for deleted */
104 if ( is_entry_subentry( e ) ) {
105 /* entry is an subentry, don't allow bind */
106 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
108 rs->sr_err = LDAP_INVALID_CREDENTIALS;
112 if ( is_entry_alias( e ) ) {
113 /* entry is an alias, don't allow bind */
114 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
115 rs->sr_err = LDAP_INVALID_CREDENTIALS;
119 if ( is_entry_referral( e ) ) {
120 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
122 rs->sr_err = LDAP_INVALID_CREDENTIALS;
126 switch ( op->oq_bind.rb_method ) {
127 case LDAP_AUTH_SIMPLE:
128 a = attr_find( e->e_attrs, password );
130 rs->sr_err = LDAP_INVALID_CREDENTIALS;
134 if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
135 &rs->sr_text ) != 0 )
137 /* failure; stop front end from sending result */
138 rs->sr_err = LDAP_INVALID_CREDENTIALS;
146 assert( 0 ); /* should not be reachable */
147 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
148 rs->sr_text = "authentication method not supported";
152 /* free entry and reader lock */
154 bdb_cache_return_entry_r( bdb, e, &lock );
158 send_ldap_result( op, rs );
160 ber_bvarray_free( rs->sr_ref );
164 /* front end will send result on success (rs->sr_err==0) */