1 /* bind.c - bdb backend bind routine */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/unistd.h>
19 bdb_bind( Operation *op, SlapReply *rs )
21 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
25 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
26 char krbname[MAX_K_NAME_SZ + 1];
27 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
32 AttributeDescription *password = slap_schema.si_ad_userPassword;
38 LDAP_LOG ( OPERATION, ARGS, "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0 );
40 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0);
43 /* allow noauth binds */
44 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
45 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
46 /* front end will send result */
50 rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
55 rs->sr_text = "internal error";
56 send_ldap_result( op, rs );
61 /* get entry with reader lock */
62 rs->sr_err = bdb_dn2entry( op->o_bd, NULL, &op->o_req_ndn, &ei, 1,
63 locker, &lock, op->o_tmpmemctx );
70 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
71 LOCK_ID_FREE(bdb->bi_dbenv, locker);
73 case DB_LOCK_DEADLOCK:
74 case DB_LOCK_NOTGRANTED:
77 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
78 LOCK_ID_FREE(bdb->bi_dbenv, locker);
83 if ( rs->sr_err == DB_NOTFOUND ) {
85 rs->sr_ref = is_entry_referral( e )
86 ? get_entry_referrals( op, e )
89 rs->sr_matched = ch_strdup( e->e_name.bv_val );
91 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
94 rs->sr_ref = referral_rewrite( default_referral,
95 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
98 if ( rs->sr_ref != NULL ) {
99 rs->sr_err = LDAP_REFERRAL;
100 send_ldap_result( op, rs );
101 free( (char *)rs->sr_matched );
102 ber_bvarray_free( rs->sr_ref );
104 rs->sr_matched = NULL;
106 rs->sr_err = LDAP_INVALID_CREDENTIALS;
107 send_ldap_result( op, rs );
110 LOCK_ID_FREE(bdb->bi_dbenv, locker);
115 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
117 /* check for deleted */
118 #ifdef BDB_SUBENTRIES
119 if ( is_entry_subentry( e ) ) {
120 /* entry is an subentry, don't allow bind */
122 LDAP_LOG ( OPERATION, DETAIL1,
123 "bdb_bind: entry is subentry\n", 0, 0, 0 );
125 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
129 rs->sr_err = LDAP_INVALID_CREDENTIALS;
130 send_ldap_result( op, rs );
137 if ( is_entry_alias( e ) ) {
138 /* entry is an alias, don't allow bind */
140 LDAP_LOG ( OPERATION, DETAIL1, "bdb_bind: entry is alias\n", 0, 0, 0 );
142 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
146 send_ldap_error( op, rs, LDAP_ALIAS_PROBLEM, "entry is alias");
152 if ( is_entry_referral( e ) ) {
153 /* entry is a referral, don't allow bind */
154 rs->sr_ref = get_entry_referrals( op, e );
157 LDAP_LOG ( OPERATION, DETAIL1,
158 "bdb_bind: entry is referral\n", 0, 0, 0 );
160 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
164 if( rs->sr_ref != NULL ) {
165 rs->sr_err = LDAP_REFERRAL;
166 rs->sr_matched = e->e_name.bv_val;
167 send_ldap_result( op, rs );
168 ber_bvarray_free( rs->sr_ref );
170 rs->sr_matched = NULL;
172 rs->sr_err = LDAP_INVALID_CREDENTIALS;
173 send_ldap_result( op, rs );
179 switch ( op->oq_bind.rb_method ) {
180 case LDAP_AUTH_SIMPLE:
181 rs->sr_err = access_allowed( op, e,
182 password, NULL, ACL_AUTH, NULL );
183 if ( ! rs->sr_err ) {
184 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
185 send_ldap_result( op, rs );
189 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
190 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
191 send_ldap_result( op, rs );
195 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
196 rs->sr_err = LDAP_INVALID_CREDENTIALS;
197 send_ldap_result( op, rs );
204 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
205 case LDAP_AUTH_KRBV41:
206 if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad ) != LDAP_SUCCESS ) {
207 rs->sr_err = LDAP_INVALID_CREDENTIALS,
208 send_ldap_result( op );
212 rs->sr_err = access_allowed( op, e,
213 krbattr, NULL, ACL_AUTH, NULL );
214 if ( ! rs->sr_err ) {
215 rs->sr_err = LDAP_INSUFFICIENT_ACCESS,
216 send_ldap_result( op );
220 krbval.bv_len = sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
221 : "", ad.pinst, ad.prealm );
223 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
225 * no krbname values present: check against DN
227 if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
231 rs->sr_err = LDAP_INAPPROPRIATE_AUTH,
232 send_ldap_result( op );
235 } else { /* look for krbname match */
236 krbval.bv_val = krbname;
238 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
239 rs->sr_err = LDAP_INVALID_CREDENTIALS;
240 send_ldap_result( op );
247 case LDAP_AUTH_KRBV42:
248 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
249 "Kerberos bind step 2 not supported" );
254 send_ldap_error( op, rs, LDAP_STRONG_AUTH_NOT_SUPPORTED,
255 "authentication method not supported" );
260 /* free entry and reader lock */
262 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
265 LOCK_ID_FREE(bdb->bi_dbenv, locker);
267 /* front end will send result on success (rs->sr_err==0) */