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;
36 Debug( LDAP_DEBUG_ARGS,
37 "==> " LDAP_XSTRING(mdb_bind) ": dn: %s\n",
38 op->o_req_dn.bv_val, 0, 0);
40 /* allow noauth binds */
41 switch ( be_rootdn_bind( op, NULL ) ) {
43 /* frontend will send result */
44 return rs->sr_err = LDAP_SUCCESS;
47 /* give the database a chance */
48 /* NOTE: this behavior departs from that of other backends,
49 * since the others, in case of password checking failure
50 * do not give the database a chance. If an entry with
51 * rootdn's name does not exist in the database the result
52 * will be the same. See ITS#4962 for discussion. */
56 rs->sr_err = mdb_reader_get(op, mdb->mi_dbenv, &rtxn);
61 rs->sr_text = "internal error";
62 send_ldap_result( op, rs );
66 /* get entry with reader lock */
67 rs->sr_err = mdb_dn2entry( op, rtxn, &op->o_req_ndn, &e, 0 );
71 rs->sr_err = LDAP_INVALID_CREDENTIALS;
72 send_ldap_result( op, rs );
77 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
80 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
84 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
86 /* check for deleted */
87 if ( is_entry_subentry( e ) ) {
88 /* entry is an subentry, don't allow bind */
89 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
91 rs->sr_err = LDAP_INVALID_CREDENTIALS;
95 if ( is_entry_alias( e ) ) {
96 /* entry is an alias, don't allow bind */
97 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
98 rs->sr_err = LDAP_INVALID_CREDENTIALS;
102 if ( is_entry_referral( e ) ) {
103 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
105 rs->sr_err = LDAP_INVALID_CREDENTIALS;
109 switch ( op->oq_bind.rb_method ) {
110 case LDAP_AUTH_SIMPLE:
111 a = attr_find( e->e_attrs, password );
113 rs->sr_err = LDAP_INVALID_CREDENTIALS;
117 if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
118 &rs->sr_text ) != 0 )
120 /* failure; stop front end from sending result */
121 rs->sr_err = LDAP_INVALID_CREDENTIALS;
129 assert( 0 ); /* should not be reachable */
130 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
131 rs->sr_text = "authentication method not supported";
135 /* free entry and reader lock */
137 mdb_entry_return( e );
141 send_ldap_result( op, rs );
143 ber_bvarray_free( rs->sr_ref );
147 /* front end will send result on success (rs->sr_err==0) */