1 /* bind.c - bdb backend bind routine */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/unistd.h>
30 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
35 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
36 char krbname[MAX_K_NAME_SZ + 1];
37 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", dn->bv_val, 0, 0 );
49 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", dn->bv_val, 0, 0);
52 LOCK_ID(bdb->bi_dbenv, &locker);
56 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0, locker, &lock );
63 send_ldap_result( conn, op, LDAP_BUSY,
64 NULL, "ldap server busy", NULL, NULL );
65 LOCK_ID_FREE(bdb->bi_dbenv, locker);
67 case DB_LOCK_DEADLOCK:
68 case DB_LOCK_NOTGRANTED:
71 send_ldap_result( conn, op, rc=LDAP_OTHER,
72 NULL, "internal error", NULL, NULL );
73 LOCK_ID_FREE(bdb->bi_dbenv, locker);
77 /* get entry with reader lock */
79 char *matched_dn = NULL;
82 if( matched != NULL ) {
83 matched_dn = ch_strdup( matched->e_dn );
85 refs = is_entry_referral( matched )
86 ? get_entry_referrals( be, conn, op, matched )
89 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, matched, &lock );
93 refs = referral_rewrite( default_referral,
94 NULL, dn, LDAP_SCOPE_DEFAULT );
97 /* allow noauth binds */
99 if ( method == LDAP_AUTH_SIMPLE ) {
100 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
101 ber_dupbv( edn, be_root_dn( be ) );
102 rc = LDAP_SUCCESS; /* front end will send result */
104 } else if ( refs != NULL ) {
105 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
106 matched_dn, NULL, refs, NULL );
109 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
110 NULL, NULL, NULL, NULL );
113 } else if ( refs != NULL ) {
114 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
115 matched_dn, NULL, refs, NULL );
118 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
119 NULL, NULL, NULL, NULL );
122 LOCK_ID_FREE(bdb->bi_dbenv, locker);
124 ber_bvarray_free( refs );
130 ber_dupbv( edn, &e->e_name );
132 /* check for deleted */
133 #ifdef BDB_SUBENTRIES
134 if ( is_entry_subentry( e ) ) {
135 /* entry is an subentry, don't allow bind */
137 LDAP_LOG ( OPERATION, DETAIL1,
138 "bdb_bind: entry is subentry\n", 0, 0, 0 );
140 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
144 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
145 NULL, NULL, NULL, NULL );
152 if ( is_entry_alias( e ) ) {
153 /* entry is an alias, don't allow bind */
155 LDAP_LOG ( OPERATION, DETAIL1, "bdb_bind: entry is alias\n", 0, 0, 0 );
157 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
161 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
162 NULL, "entry is alias", NULL, NULL );
168 if ( is_entry_referral( e ) ) {
169 /* entry is a referral, don't allow bind */
170 BerVarray refs = get_entry_referrals( be,
174 LDAP_LOG ( OPERATION, DETAIL1,
175 "bdb_bind: entry is referral\n", 0, 0, 0 );
177 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
182 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
183 e->e_dn, NULL, refs, NULL );
186 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
187 NULL, NULL, NULL, NULL );
190 ber_bvarray_free( refs );
196 case LDAP_AUTH_SIMPLE:
197 /* check for root dn/passwd */
198 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
199 /* front end will send result */
200 if(edn->bv_val != NULL) free( edn->bv_val );
201 ber_dupbv( edn, be_root_dn( be ) );
206 if ( ! access_allowed( be, conn, op, e,
207 password, NULL, ACL_AUTH, NULL ) )
209 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
210 NULL, NULL, NULL, NULL );
214 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
215 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
216 NULL, NULL, NULL, NULL );
220 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
221 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
222 NULL, NULL, NULL, NULL );
229 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
230 case LDAP_AUTH_KRBV41:
231 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
232 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
233 NULL, NULL, NULL, NULL );
237 if ( ! access_allowed( be, conn, op, e,
238 krbattr, NULL, ACL_AUTH, NULL ) )
240 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
241 NULL, NULL, NULL, NULL );
245 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
246 : "", ad.pinst, ad.prealm );
248 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
250 * no krbname values present: check against DN
252 if ( strcasecmp( dn, krbname ) == 0 ) {
256 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
257 NULL, NULL, NULL, NULL );
260 } else { /* look for krbname match */
261 struct berval krbval;
263 krbval.bv_val = krbname;
264 krbval.bv_len = strlen( krbname );
266 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
267 send_ldap_result( conn, op,
268 rc = LDAP_INVALID_CREDENTIALS,
269 NULL, NULL, NULL, NULL );
276 case LDAP_AUTH_KRBV42:
277 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
278 NULL, "Kerberos bind step 2 not supported",
284 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
285 NULL, "authentication method not supported", NULL, NULL );
290 /* free entry and reader lock */
292 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
295 LOCK_ID_FREE(bdb->bi_dbenv, locker);
297 /* front end with send result on success (rc==0) */