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"
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
38 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
39 char krbname[MAX_K_NAME_SZ + 1];
40 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
44 AttributeDescription *password = slap_schema.si_ad_userPassword;
47 LDAP_LOG( BACK_LDBM, ENTRY,
48 "ldbm_back_bind: dn: %s.\n", dn->bv_val, 0, 0 );
50 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn->bv_val, 0, 0);
55 /* grab giant lock for reading */
56 ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
58 /* get entry with reader lock */
59 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
60 char *matched_dn = NULL;
61 BerVarray refs = NULL;
63 if( matched != NULL ) {
64 matched_dn = ch_strdup( matched->e_dn );
66 refs = is_entry_referral( matched )
67 ? get_entry_referrals( be, conn, op, matched )
70 cache_return_entry_r( &li->li_cache, matched );
73 refs = referral_rewrite( default_referral,
74 NULL, dn, LDAP_SCOPE_DEFAULT );
77 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
79 /* allow noauth binds */
81 if ( method == LDAP_AUTH_SIMPLE ) {
82 if ( be_isroot_pw( be, conn, dn, cred ) ) {
83 ber_dupbv( edn, be_root_dn( be ) );
84 rc = 0; /* front end will send result */
86 } else if ( refs != NULL ) {
87 send_ldap_result( conn, op, LDAP_REFERRAL,
88 matched_dn, NULL, refs, NULL );
91 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
92 NULL, NULL, NULL, NULL );
95 } else if ( refs != NULL ) {
96 send_ldap_result( conn, op, LDAP_REFERRAL,
97 matched_dn, NULL, refs, NULL );
100 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
101 NULL, NULL, NULL, NULL );
104 if ( refs ) ber_bvarray_free( refs );
105 if ( matched_dn ) free( matched_dn );
109 ber_dupbv( edn, &e->e_name );
111 /* check for deleted */
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_dn, 0, 0 );
119 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
124 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
125 NULL, "entry is alias", NULL, NULL );
131 if ( is_entry_referral( e ) ) {
132 /* entry is a referral, don't allow bind */
133 BerVarray refs = get_entry_referrals( be,
137 LDAP_LOG( BACK_LDBM, INFO,
138 "ldbm_back_bind: entry(%s) is a referral.\n", e->e_dn, 0, 0 );
140 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
146 send_ldap_result( conn, op, LDAP_REFERRAL,
147 e->e_dn, NULL, refs, NULL );
150 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
151 NULL, NULL, NULL, NULL );
154 ber_bvarray_free( refs );
161 case LDAP_AUTH_SIMPLE:
162 /* check for root dn/passwd */
163 if ( be_isroot_pw( be, conn, dn, cred ) ) {
164 /* front end will send result */
165 if(edn->bv_val != NULL) free( edn->bv_val );
166 ber_dupbv( edn, be_root_dn( be ) );
171 if ( ! access_allowed( be, conn, op, e,
172 password, NULL, ACL_AUTH, NULL ) )
174 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
175 NULL, NULL, NULL, NULL );
180 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
181 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
182 NULL, NULL, NULL, NULL );
184 /* stop front end from sending result */
189 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
190 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
191 NULL, NULL, NULL, NULL );
192 /* stop front end from sending result */
200 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
201 case LDAP_AUTH_KRBV41:
202 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
203 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
204 NULL, NULL, NULL, NULL );
209 if ( ! access_allowed( be, conn, op, e,
210 krbattr, NULL, ACL_AUTH, NULL ) )
212 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
213 NULL, NULL, NULL, NULL );
218 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
219 : "", ad.pinst, ad.prealm );
221 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
223 * no krbname values present: check against DN
225 if ( strcasecmp( dn->bv_val, krbname ) == 0 ) {
229 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
230 NULL, NULL, NULL, NULL );
234 } else { /* look for krbname match */
235 struct berval krbval;
237 krbval.bv_val = krbname;
238 krbval.bv_len = strlen( krbname );
240 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
241 send_ldap_result( conn, op,
242 LDAP_INVALID_CREDENTIALS,
243 NULL, NULL, NULL, NULL );
251 case LDAP_AUTH_KRBV42:
252 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
253 NULL, "Kerberos bind step 2 not supported",
255 /* stop front end from sending result */
256 rc = LDAP_UNWILLING_TO_PERFORM;
261 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
262 NULL, "authentication method not supported", NULL, NULL );
268 /* free entry and reader lock */
269 cache_return_entry_r( &li->li_cache, e );
270 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
272 /* front end will send result on success (rc==0) */