]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/bind.c
remove experimental code as per ITS#4962 discussion
[openldap] / servers / slapd / back-bdb / bind.c
1 /* bind.c - bdb backend bind routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2007 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21 #include <ac/unistd.h>
22
23 #include "back-bdb.h"
24
25 int
26 bdb_bind( Operation *op, SlapReply *rs )
27 {
28         struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
29         Entry           *e;
30         Attribute       *a;
31         EntryInfo       *ei;
32
33         AttributeDescription *password = slap_schema.si_ad_userPassword;
34
35         BDB_LOCKER      locker;
36         DB_LOCK         lock;
37
38         Debug( LDAP_DEBUG_ARGS,
39                 "==> " LDAP_XSTRING(bdb_bind) ": dn: %s\n",
40                 op->o_req_dn.bv_val, 0, 0);
41
42         /* allow noauth binds */
43         switch ( be_rootdn_bind( op, NULL ) ) {
44         case LDAP_SUCCESS:
45                 /* frontend will send result */
46                 return rs->sr_err;
47
48         default:
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. */
55                 break;
56         }
57
58         rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
59         switch(rs->sr_err) {
60         case 0:
61                 break;
62         default:
63                 rs->sr_text = "internal error";
64                 send_ldap_result( op, rs );
65                 return rs->sr_err;
66         }
67
68 dn2entry_retry:
69         /* get entry with reader lock */
70         rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1,
71                 locker, &lock );
72
73         switch(rs->sr_err) {
74         case DB_NOTFOUND:
75         case 0:
76                 break;
77         case LDAP_BUSY:
78                 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
79                 LOCK_ID_FREE(bdb->bi_dbenv, locker);
80                 return LDAP_BUSY;
81         case DB_LOCK_DEADLOCK:
82         case DB_LOCK_NOTGRANTED:
83                 goto dn2entry_retry;
84         default:
85                 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
86                 LOCK_ID_FREE(bdb->bi_dbenv, locker);
87                 return rs->sr_err;
88         }
89
90         e = ei->bei_e;
91         if ( rs->sr_err == DB_NOTFOUND ) {
92                 if( e != NULL ) {
93                         bdb_cache_return_entry_r( bdb, e, &lock );
94                         e = NULL;
95                 }
96
97                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
98                 send_ldap_result( op, rs );
99
100                 LOCK_ID_FREE(bdb->bi_dbenv, locker);
101
102                 return rs->sr_err;
103         }
104
105         ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
106
107         /* check for deleted */
108         if ( is_entry_subentry( e ) ) {
109                 /* entry is an subentry, don't allow bind */
110                 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
111                         0, 0 );
112                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
113                 goto done;
114         }
115
116         if ( is_entry_alias( e ) ) {
117                 /* entry is an alias, don't allow bind */
118                 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
119                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
120                 goto done;
121         }
122
123         if ( is_entry_referral( e ) ) {
124                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
125                         0, 0 );
126                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
127                 goto done;
128         }
129
130         switch ( op->oq_bind.rb_method ) {
131         case LDAP_AUTH_SIMPLE:
132                 a = attr_find( e->e_attrs, password );
133                 if ( a == NULL ) {
134                         rs->sr_err = LDAP_INVALID_CREDENTIALS;
135                         goto done;
136                 }
137
138                 if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
139                                         &rs->sr_text ) != 0 )
140                 {
141                         /* failure; stop front end from sending result */
142                         rs->sr_err = LDAP_INVALID_CREDENTIALS;
143                         goto done;
144                 }
145                         
146                 rs->sr_err = 0;
147                 break;
148
149         default:
150                 assert( 0 ); /* should not be reachable */
151                 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
152                 rs->sr_text = "authentication method not supported";
153         }
154
155 done:
156         /* free entry and reader lock */
157         if( e != NULL ) {
158                 bdb_cache_return_entry_r( bdb, e, &lock );
159         }
160
161         LOCK_ID_FREE(bdb->bi_dbenv, locker);
162
163         if ( rs->sr_err ) {
164                 send_ldap_result( op, rs );
165                 if ( rs->sr_ref ) {
166                         ber_bvarray_free( rs->sr_ref );
167                         rs->sr_ref = NULL;
168                 }
169         }
170         /* front end will send result on success (rs->sr_err==0) */
171         return rs->sr_err;
172 }