1 /* bind.c - mdb backend bind routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2011 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 mdb_bind( Operation *op, SlapReply *rs )
28 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
32 AttributeDescription *password = slap_schema.si_ad_userPassword;
35 mdb_op_info opinfo = {0}, *moi = &opinfo;
37 Debug( LDAP_DEBUG_ARGS,
38 "==> " LDAP_XSTRING(mdb_bind) ": dn: %s\n",
39 op->o_req_dn.bv_val, 0, 0);
41 /* allow noauth binds */
42 switch ( be_rootdn_bind( op, NULL ) ) {
44 /* frontend will send result */
45 return rs->sr_err = LDAP_SUCCESS;
48 /* give the database a chance */
49 /* NOTE: this behavior departs from that of other backends,
50 * since the others, in case of password checking failure
51 * do not give the database a chance. If an entry with
52 * rootdn's name does not exist in the database the result
53 * will be the same. See ITS#4962 for discussion. */
57 rs->sr_err = mdb_opinfo_get(op, mdb, 1, &moi);
62 rs->sr_text = "internal error";
63 send_ldap_result( op, rs );
69 /* get entry with reader lock */
70 rs->sr_err = mdb_dn2entry( op, rtxn, &op->o_req_ndn, &e, 0 );
74 rs->sr_err = LDAP_INVALID_CREDENTIALS;
79 rs->sr_text = "ldap_server_busy";
82 rs->sr_err = LDAP_OTHER;
83 rs->sr_text = "internal error";
87 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
89 /* check for deleted */
90 if ( is_entry_subentry( e ) ) {
91 /* entry is an subentry, don't allow bind */
92 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
94 rs->sr_err = LDAP_INVALID_CREDENTIALS;
98 if ( is_entry_alias( e ) ) {
99 /* entry is an alias, don't allow bind */
100 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
101 rs->sr_err = LDAP_INVALID_CREDENTIALS;
105 if ( is_entry_referral( e ) ) {
106 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
108 rs->sr_err = LDAP_INVALID_CREDENTIALS;
112 switch ( op->oq_bind.rb_method ) {
113 case LDAP_AUTH_SIMPLE:
114 a = attr_find( e->e_attrs, password );
116 rs->sr_err = LDAP_INVALID_CREDENTIALS;
120 if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
121 &rs->sr_text ) != 0 )
123 /* failure; stop front end from sending result */
124 rs->sr_err = LDAP_INVALID_CREDENTIALS;
132 assert( 0 ); /* should not be reachable */
133 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
134 rs->sr_text = "authentication method not supported";
138 if ( moi == &opinfo ) {
139 mdb_txn_reset( moi->moi_txn );
140 LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next );
142 /* free entry and reader lock */
144 mdb_entry_return( e );
148 send_ldap_result( op, rs );
150 ber_bvarray_free( rs->sr_ref );
154 /* front end will send result on success (rs->sr_err==0) */