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 /* XXYYZ: need to check return value */
53 LOCK_ID(bdb->bi_dbenv, &locker);
57 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0, locker, &lock );
64 send_ldap_result( conn, op, LDAP_BUSY,
65 NULL, "ldap server busy", NULL, NULL );
66 LOCK_ID_FREE(bdb->bi_dbenv, locker);
68 case DB_LOCK_DEADLOCK:
69 case DB_LOCK_NOTGRANTED:
72 send_ldap_result( conn, op, rc=LDAP_OTHER,
73 NULL, "internal error", NULL, NULL );
74 LOCK_ID_FREE(bdb->bi_dbenv, locker);
78 /* get entry with reader lock */
80 char *matched_dn = NULL;
83 if( matched != NULL ) {
84 matched_dn = ch_strdup( matched->e_dn );
86 refs = is_entry_referral( matched )
87 ? get_entry_referrals( be, conn, op, matched )
90 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, matched, &lock );
94 refs = referral_rewrite( default_referral,
95 NULL, dn, LDAP_SCOPE_DEFAULT );
98 /* allow noauth binds */
100 if ( method == LDAP_AUTH_SIMPLE ) {
101 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
102 ber_dupbv( edn, be_root_dn( be ) );
103 rc = LDAP_SUCCESS; /* front end will send result */
105 } else if ( refs != NULL ) {
106 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
107 matched_dn, NULL, refs, NULL );
110 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
111 NULL, NULL, NULL, NULL );
114 } else if ( refs != NULL ) {
115 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
116 matched_dn, NULL, refs, NULL );
119 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
120 NULL, NULL, NULL, NULL );
123 LOCK_ID_FREE(bdb->bi_dbenv, locker);
125 ber_bvarray_free( refs );
131 ber_dupbv( edn, &e->e_name );
133 /* check for deleted */
134 #ifdef BDB_SUBENTRIES
135 if ( is_entry_subentry( e ) ) {
136 /* entry is an subentry, don't allow bind */
138 LDAP_LOG ( OPERATION, DETAIL1,
139 "bdb_bind: entry is subentry\n", 0, 0, 0 );
141 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
145 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
146 NULL, NULL, NULL, NULL );
153 if ( is_entry_alias( e ) ) {
154 /* entry is an alias, don't allow bind */
156 LDAP_LOG ( OPERATION, DETAIL1, "bdb_bind: entry is alias\n", 0, 0, 0 );
158 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
162 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
163 NULL, "entry is alias", NULL, NULL );
169 if ( is_entry_referral( e ) ) {
170 /* entry is a referral, don't allow bind */
171 BerVarray refs = get_entry_referrals( be,
175 LDAP_LOG ( OPERATION, DETAIL1,
176 "bdb_bind: entry is referral\n", 0, 0, 0 );
178 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
183 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
184 e->e_dn, NULL, refs, NULL );
187 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
188 NULL, NULL, NULL, NULL );
191 ber_bvarray_free( refs );
197 case LDAP_AUTH_SIMPLE:
198 /* check for root dn/passwd */
199 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
200 /* front end will send result */
201 if(edn->bv_val != NULL) free( edn->bv_val );
202 ber_dupbv( edn, be_root_dn( be ) );
207 if ( ! access_allowed( be, conn, op, e,
208 password, NULL, ACL_AUTH, NULL ) )
210 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
211 NULL, NULL, NULL, NULL );
215 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
216 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
217 NULL, NULL, NULL, NULL );
221 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
222 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
223 NULL, NULL, NULL, NULL );
230 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
231 case LDAP_AUTH_KRBV41:
232 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
233 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
234 NULL, NULL, NULL, NULL );
238 if ( ! access_allowed( be, conn, op, e,
239 krbattr, NULL, ACL_AUTH, NULL ) )
241 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
242 NULL, NULL, NULL, NULL );
246 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
247 : "", ad.pinst, ad.prealm );
249 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
251 * no krbname values present: check against DN
253 if ( strcasecmp( dn, krbname ) == 0 ) {
257 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
258 NULL, NULL, NULL, NULL );
261 } else { /* look for krbname match */
262 struct berval krbval;
264 krbval.bv_val = krbname;
265 krbval.bv_len = strlen( krbname );
267 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
268 send_ldap_result( conn, op,
269 rc = LDAP_INVALID_CREDENTIALS,
270 NULL, NULL, NULL, NULL );
277 case LDAP_AUTH_KRBV42:
278 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
279 NULL, "Kerberos bind step 2 not supported",
285 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
286 NULL, "authentication method not supported", NULL, NULL );
291 /* free entry and reader lock */
293 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
296 LOCK_ID_FREE(bdb->bi_dbenv, locker);
298 /* front end with send result on success (rc==0) */