1 /* bind.c - ldbm backend bind and unbind routines */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
18 #include "back-ldbm.h"
19 #include "proto-back-ldbm.h"
26 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
31 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
32 char krbname[MAX_K_NAME_SZ + 1];
33 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
37 AttributeDescription *password = slap_schema.si_ad_userPassword;
40 LDAP_LOG( BACK_LDBM, ENTRY,
41 "ldbm_back_bind: dn: %s.\n", op->o_req_dn.bv_val, 0, 0 );
43 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0);
46 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
47 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
48 /* front end will send result */
52 /* grab giant lock for reading */
53 ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
55 /* get entry with reader lock */
56 if ( (e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched )) == NULL ) {
57 if( matched != NULL ) {
58 rs->sr_matched = ch_strdup( matched->e_dn );
60 rs->sr_ref = is_entry_referral( matched )
61 ? get_entry_referrals( op, matched )
64 cache_return_entry_r( &li->li_cache, matched );
67 rs->sr_ref = referral_rewrite( default_referral,
68 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
71 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
73 /* allow noauth binds */
75 if ( rs->sr_ref != NULL ) {
76 rs->sr_err = LDAP_REFERRAL;
78 rs->sr_err = LDAP_INVALID_CREDENTIALS;
80 send_ldap_result( op, rs );
82 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
83 if ( rs->sr_matched ) free( (char *)rs->sr_matched );
85 rs->sr_matched = NULL;
89 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
91 /* check for deleted */
92 #ifdef LDBM_SUBENTRIES
93 if ( is_entry_subentry( e ) ) {
94 /* entry is an subentry, don't allow bind */
96 LDAP_LOG ( OPERATION, DETAIL1,
97 "bdb_bind: entry is subentry\n", 0, 0, 0 );
99 Debug( LDAP_DEBUG_TRACE,
100 "entry is subentry\n", 0, 0, 0 );
102 rs->sr_err = LDAP_INVALID_CREDENTIALS;
103 send_ldap_result( op, rs );
104 rc = LDAP_INVALID_CREDENTIALS;
109 if ( is_entry_alias( e ) ) {
110 /* entry is an alias, don't allow bind */
112 LDAP_LOG( BACK_LDBM, INFO,
113 "ldbm_back_bind: entry (%s) is an alias.\n", e->e_name.bv_val, 0, 0 );
115 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
120 send_ldap_error( op, rs, LDAP_ALIAS_PROBLEM,
123 rc = LDAP_ALIAS_PROBLEM;
127 if ( is_entry_referral( e ) ) {
128 /* entry is a referral, don't allow bind */
129 rs->sr_ref = get_entry_referrals( op, e );
132 LDAP_LOG( BACK_LDBM, INFO,
133 "ldbm_back_bind: entry(%s) is a referral.\n", e->e_dn, 0, 0 );
135 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
140 if( rs->sr_ref != NULL ) {
141 rs->sr_err = LDAP_REFERRAL;
142 rs->sr_matched = e->e_name.bv_val;
145 rs->sr_err = LDAP_INVALID_CREDENTIALS;
147 send_ldap_result( op, rs );
149 ber_bvarray_free( rs->sr_ref );
150 rs->sr_matched = NULL;
156 switch ( op->oq_bind.rb_method ) {
157 case LDAP_AUTH_SIMPLE:
158 if ( ! access_allowed( op, e,
159 password, NULL, ACL_AUTH, NULL ) )
161 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
162 rc = LDAP_INSUFFICIENT_ACCESS;
166 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
167 send_ldap_error( op, rs, LDAP_INAPPROPRIATE_AUTH, NULL );
169 /* stop front end from sending result */
170 rc = LDAP_INAPPROPRIATE_AUTH;
174 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
175 send_ldap_error( op, rs, LDAP_INVALID_CREDENTIALS, NULL );
176 /* stop front end from sending result */
177 rc = LDAP_INVALID_CREDENTIALS;
184 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
185 case LDAP_AUTH_KRBV41:
186 if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad ) != LDAP_SUCCESS ) {
187 send_ldap_error( op, rs, LDAP_INVALID_CREDENTIALS, NULL );
188 rc = LDAP_INVALID_CREDENTIALS;
192 if ( ! access_allowed( op, e,
193 krbattr, NULL, ACL_AUTH, NULL ) )
195 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
197 rc = LDAP_INSUFFICIENT_ACCESS;
201 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
202 : "", ad.pinst, ad.prealm );
204 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
206 * no krbname values present: check against DN
208 if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
212 send_ldap_error( op, rs, LDAP_INAPPROPRIATE_AUTH, NULL );
213 rc = LDAP_INAPPROPRIATE_AUTH;
216 } else { /* look for krbname match */
217 struct berval krbval;
219 krbval.bv_val = krbname;
220 krbval.bv_len = strlen( krbname );
222 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
223 send_ldap_error( op, rs,
224 LDAP_INVALID_CREDENTIALS, NULL );
225 rc = LDAP_INVALID_CREDENTIALS;
232 case LDAP_AUTH_KRBV42:
233 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
234 "Kerberos bind step 2 not supported" );
235 /* stop front end from sending result */
236 rc = LDAP_UNWILLING_TO_PERFORM;
241 send_ldap_error( op, rs, LDAP_STRONG_AUTH_NOT_SUPPORTED,
242 "authentication method not supported" );
243 rc = LDAP_STRONG_AUTH_NOT_SUPPORTED;
248 /* free entry and reader lock */
249 cache_return_entry_r( &li->li_cache, e );
250 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
252 /* front end will send result on success (rc==0) */