1 /* bind.c - bdb backend bind routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 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;
47 LDAP_LOG ( OPERATION, ARGS, "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0 );
49 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0);
52 /* allow noauth binds */
53 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
54 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
55 /* front end will send result */
59 rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
64 rs->sr_text = "internal error";
65 send_ldap_result( op, rs );
70 /* get entry with reader lock */
71 rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1,
79 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
80 LOCK_ID_FREE(bdb->bi_dbenv, locker);
82 case DB_LOCK_DEADLOCK:
83 case DB_LOCK_NOTGRANTED:
86 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
87 LOCK_ID_FREE(bdb->bi_dbenv, locker);
92 if ( rs->sr_err == DB_NOTFOUND ) {
94 rs->sr_ref = is_entry_referral( e )
95 ? get_entry_referrals( op, e )
98 rs->sr_matched = ch_strdup( e->e_name.bv_val );
100 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
103 rs->sr_ref = referral_rewrite( default_referral,
104 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
107 if ( rs->sr_ref != NULL ) {
108 rs->sr_err = LDAP_REFERRAL;
109 send_ldap_result( op, rs );
110 free( (char *)rs->sr_matched );
111 ber_bvarray_free( rs->sr_ref );
113 rs->sr_matched = NULL;
115 rs->sr_err = LDAP_INVALID_CREDENTIALS;
116 send_ldap_result( op, rs );
119 LOCK_ID_FREE(bdb->bi_dbenv, locker);
124 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
126 /* check for deleted */
127 #ifdef BDB_SUBENTRIES
128 if ( is_entry_subentry( e ) ) {
129 /* entry is an subentry, don't allow bind */
131 LDAP_LOG ( OPERATION, DETAIL1,
132 "bdb_bind: entry is subentry\n", 0, 0, 0 );
134 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
138 rs->sr_err = LDAP_INVALID_CREDENTIALS;
139 send_ldap_result( op, rs );
146 if ( is_entry_alias( e ) ) {
147 /* entry is an alias, don't allow bind */
149 LDAP_LOG ( OPERATION, DETAIL1, "bdb_bind: entry is alias\n", 0, 0, 0 );
151 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
155 send_ldap_error( op, rs, LDAP_ALIAS_PROBLEM, "entry is alias");
161 if ( is_entry_referral( e ) ) {
162 /* entry is a referral, don't allow bind */
163 rs->sr_ref = get_entry_referrals( op, e );
166 LDAP_LOG ( OPERATION, DETAIL1,
167 "bdb_bind: entry is referral\n", 0, 0, 0 );
169 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
173 if( rs->sr_ref != NULL ) {
174 rs->sr_err = LDAP_REFERRAL;
175 rs->sr_matched = e->e_name.bv_val;
176 send_ldap_result( op, rs );
177 ber_bvarray_free( rs->sr_ref );
179 rs->sr_matched = NULL;
181 rs->sr_err = LDAP_INVALID_CREDENTIALS;
182 send_ldap_result( op, rs );
188 switch ( op->oq_bind.rb_method ) {
189 case LDAP_AUTH_SIMPLE:
190 rs->sr_err = access_allowed( op, e,
191 password, NULL, ACL_AUTH, NULL );
192 if ( ! rs->sr_err ) {
193 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
194 send_ldap_result( op, rs );
198 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
199 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
200 send_ldap_result( op, rs );
204 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
205 rs->sr_err = LDAP_INVALID_CREDENTIALS;
206 send_ldap_result( op, rs );
213 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
214 case LDAP_AUTH_KRBV41:
215 if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad ) != LDAP_SUCCESS ) {
216 rs->sr_err = LDAP_INVALID_CREDENTIALS,
217 send_ldap_result( op );
221 rs->sr_err = access_allowed( op, e,
222 krbattr, NULL, ACL_AUTH, NULL );
223 if ( ! rs->sr_err ) {
224 rs->sr_err = LDAP_INSUFFICIENT_ACCESS,
225 send_ldap_result( op );
229 krbval.bv_len = sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
230 : "", ad.pinst, ad.prealm );
232 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
234 * no krbname values present: check against DN
236 if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
240 rs->sr_err = LDAP_INAPPROPRIATE_AUTH,
241 send_ldap_result( op );
244 } else { /* look for krbname match */
245 krbval.bv_val = krbname;
247 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
248 rs->sr_err = LDAP_INVALID_CREDENTIALS;
249 send_ldap_result( op );
256 case LDAP_AUTH_KRBV42:
257 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
258 "Kerberos bind step 2 not supported" );
263 send_ldap_error( op, rs, LDAP_STRONG_AUTH_NOT_SUPPORTED,
264 "authentication method not supported" );
269 /* free entry and reader lock */
271 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
274 LOCK_ID_FREE(bdb->bi_dbenv, locker);
276 /* front end will send result on success (rs->sr_err==0) */