1 /* bind.c - ldbm backend bind and unbind routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-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>.
22 #include <ac/socket.h>
23 #include <ac/string.h>
24 #include <ac/unistd.h>
27 #include "back-ldbm.h"
28 #include "proto-back-ldbm.h"
35 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
40 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
41 char krbname[MAX_K_NAME_SZ + 1];
42 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
46 AttributeDescription *password = slap_schema.si_ad_userPassword;
49 LDAP_LOG( BACK_LDBM, ENTRY,
50 "ldbm_back_bind: dn: %s.\n", op->o_req_dn.bv_val, 0, 0 );
52 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0);
55 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
56 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
57 /* front end will send result */
61 /* grab giant lock for reading */
62 ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
64 /* get entry with reader lock */
65 if ( (e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched )) == NULL ) {
66 if( matched != NULL ) {
67 rs->sr_matched = ch_strdup( matched->e_dn );
68 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
70 rs->sr_ref = is_entry_referral( matched )
71 ? get_entry_referrals( op, matched )
74 cache_return_entry_r( &li->li_cache, matched );
77 rs->sr_ref = referral_rewrite( default_referral,
78 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
81 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
83 /* allow noauth binds */
85 if ( rs->sr_ref != NULL ) {
86 rs->sr_err = LDAP_REFERRAL;
88 rs->sr_err = LDAP_INVALID_CREDENTIALS;
90 send_ldap_result( op, rs );
92 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
97 /* check for deleted */
98 #ifdef LDBM_SUBENTRIES
99 if ( is_entry_subentry( e ) ) {
100 /* entry is an subentry, don't allow bind */
102 LDAP_LOG ( OPERATION, DETAIL1,
103 "bdb_bind: entry is subentry\n", 0, 0, 0 );
105 Debug( LDAP_DEBUG_TRACE,
106 "entry is subentry\n", 0, 0, 0 );
108 rc = LDAP_INVALID_CREDENTIALS;
113 if ( is_entry_alias( e ) ) {
114 /* entry is an alias, don't allow bind */
116 LDAP_LOG( BACK_LDBM, INFO,
117 "ldbm_back_bind: entry (%s) is an alias.\n", e->e_name.bv_val, 0, 0 );
119 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
122 rs->sr_text = "entry is alias";
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 ) {
142 rs->sr_matched = ch_strdup( e->e_name.bv_val );
143 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
146 rc = LDAP_INVALID_CREDENTIALS;
151 switch ( op->oq_bind.rb_method ) {
152 case LDAP_AUTH_SIMPLE:
153 if ( ! access_allowed( op, e,
154 password, NULL, ACL_AUTH, NULL ) )
156 rc = LDAP_INSUFFICIENT_ACCESS;
160 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
161 /* stop front end from sending result */
162 rc = LDAP_INAPPROPRIATE_AUTH;
166 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
167 /* stop front end from sending result */
168 rc = LDAP_INVALID_CREDENTIALS;
175 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
176 case LDAP_AUTH_KRBV41:
177 if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad ) != LDAP_SUCCESS ) {
178 rc = LDAP_INVALID_CREDENTIALS;
182 if ( ! access_allowed( op, e,
183 krbattr, NULL, ACL_AUTH, NULL ) )
185 rc = LDAP_INSUFFICIENT_ACCESS;
189 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
190 : "", ad.pinst, ad.prealm );
192 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
194 * no krbname values present: check against DN
196 if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
200 rc = LDAP_INAPPROPRIATE_AUTH;
203 } else { /* look for krbname match */
204 struct berval krbval;
206 krbval.bv_val = krbname;
207 krbval.bv_len = strlen( krbname );
209 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
210 rc = LDAP_INVALID_CREDENTIALS;
217 case LDAP_AUTH_KRBV42:
218 rs->sr_text = "Kerberos bind step 2 not supported";
219 /* stop front end from sending result */
220 rc = LDAP_UNWILLING_TO_PERFORM;
225 rs->sr_text = "authentication method not supported";
226 rc = LDAP_STRONG_AUTH_NOT_SUPPORTED;
230 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
233 /* free entry and reader lock */
234 cache_return_entry_r( &li->li_cache, e );
235 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
239 send_ldap_result( op, rs );
241 ber_bvarray_free( rs->sr_ref );
246 /* front end will send result on success (rc==0) */