1 /* bind.c - bdb backend bind routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2005 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>.
21 #include <ac/string.h>
22 #include <ac/unistd.h>
28 bdb_bind( Operation *op, SlapReply *rs )
30 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
34 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
35 char krbname[MAX_K_NAME_SZ + 1];
36 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
41 AttributeDescription *password = slap_schema.si_ad_userPassword;
46 Debug( LDAP_DEBUG_ARGS,
47 "==> " LDAP_XSTRING(bdb_bind) ": dn: %s\n",
48 op->o_req_dn.bv_val, 0, 0);
50 /* allow noauth binds */
51 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
52 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
53 /* front end will send result */
57 rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
62 rs->sr_text = "internal error";
63 send_ldap_result( op, rs );
68 /* get entry with reader lock */
69 rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1,
77 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
78 LOCK_ID_FREE(bdb->bi_dbenv, locker);
80 case DB_LOCK_DEADLOCK:
81 case DB_LOCK_NOTGRANTED:
84 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
85 LOCK_ID_FREE(bdb->bi_dbenv, locker);
90 if ( rs->sr_err == DB_NOTFOUND ) {
92 bdb_cache_return_entry_r( bdb->bi_dbenv,
93 &bdb->bi_cache, e, &lock );
97 rs->sr_err = LDAP_INVALID_CREDENTIALS;
98 send_ldap_result( op, rs );
100 LOCK_ID_FREE(bdb->bi_dbenv, locker);
105 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
107 /* check for deleted */
108 #ifdef BDB_SUBENTRIES
109 if ( is_entry_subentry( e ) ) {
110 /* entry is an subentry, don't allow bind */
111 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
113 rs->sr_err = LDAP_INVALID_CREDENTIALS;
118 if ( is_entry_alias( e ) ) {
119 /* entry is an alias, don't allow bind */
120 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
121 rs->sr_err = LDAP_INVALID_CREDENTIALS;
125 if ( is_entry_referral( e ) ) {
126 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
128 rs->sr_err = LDAP_INVALID_CREDENTIALS;
132 switch ( op->oq_bind.rb_method ) {
133 case LDAP_AUTH_SIMPLE:
134 rs->sr_err = access_allowed( op, e,
135 password, NULL, ACL_AUTH, NULL );
136 if ( ! rs->sr_err ) {
137 rs->sr_err = LDAP_INVALID_CREDENTIALS;
141 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
142 rs->sr_err = LDAP_INVALID_CREDENTIALS;
146 if ( slap_passwd_check( op->o_conn,
147 a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 )
149 rs->sr_err = LDAP_INVALID_CREDENTIALS;
156 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
157 case LDAP_AUTH_KRBV41:
158 if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad )
161 rs->sr_err = LDAP_INVALID_CREDENTIALS,
165 rs->sr_err = access_allowed( op, e,
166 krbattr, NULL, ACL_AUTH, NULL );
167 if ( ! rs->sr_err ) {
168 rs->sr_err = LDAP_INSUFFICIENT_ACCESS,
172 krbval.bv_len = sprintf( krbname, "%s%s%s@%s", ad.pname,
173 *ad.pinst ? "." : "", ad.pinst, ad.prealm );
175 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
177 * no krbname values present: check against DN
179 if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
183 rs->sr_err = LDAP_INAPPROPRIATE_AUTH,
186 } else { /* look for krbname match */
187 krbval.bv_val = krbname;
189 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
190 rs->sr_err = LDAP_INVALID_CREDENTIALS;
199 assert( 0 ); /* should not be unreachable */
200 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
201 rs->sr_text = "authentication method not supported";
205 /* free entry and reader lock */
207 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
210 LOCK_ID_FREE(bdb->bi_dbenv, locker);
213 send_ldap_result( op, rs );
215 ber_bvarray_free( rs->sr_ref );
219 /* front end will send result on success (rs->sr_err==0) */