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 rc = LOCK_ID(bdb->bi_dbenv, &locker);
57 send_ldap_result( conn, op, rc=LDAP_OTHER,
58 NULL, "internal error", NULL, NULL );
64 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0, locker, &lock );
71 send_ldap_result( conn, op, LDAP_BUSY,
72 NULL, "ldap server busy", NULL, NULL );
73 LOCK_ID_FREE(bdb->bi_dbenv, locker);
75 case DB_LOCK_DEADLOCK:
76 case DB_LOCK_NOTGRANTED:
79 send_ldap_result( conn, op, rc=LDAP_OTHER,
80 NULL, "internal error", NULL, NULL );
81 LOCK_ID_FREE(bdb->bi_dbenv, locker);
85 /* get entry with reader lock */
87 char *matched_dn = NULL;
90 if( matched != NULL ) {
91 matched_dn = ch_strdup( matched->e_dn );
93 refs = is_entry_referral( matched )
94 ? get_entry_referrals( be, conn, op, matched )
97 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, matched, &lock );
101 refs = referral_rewrite( default_referral,
102 NULL, dn, LDAP_SCOPE_DEFAULT );
105 /* allow noauth binds */
107 if ( method == LDAP_AUTH_SIMPLE ) {
108 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
109 ber_dupbv( edn, be_root_dn( be ) );
110 rc = LDAP_SUCCESS; /* front end will send result */
112 } else if ( refs != NULL ) {
113 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
114 matched_dn, NULL, refs, NULL );
117 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
118 NULL, NULL, NULL, NULL );
121 } else if ( refs != NULL ) {
122 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
123 matched_dn, NULL, refs, NULL );
126 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
127 NULL, NULL, NULL, NULL );
130 LOCK_ID_FREE(bdb->bi_dbenv, locker);
132 ber_bvarray_free( refs );
138 ber_dupbv( edn, &e->e_name );
140 /* check for deleted */
141 #ifdef BDB_SUBENTRIES
142 if ( is_entry_subentry( e ) ) {
143 /* entry is an subentry, don't allow bind */
145 LDAP_LOG ( OPERATION, DETAIL1,
146 "bdb_bind: entry is subentry\n", 0, 0, 0 );
148 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
152 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
153 NULL, NULL, NULL, NULL );
160 if ( is_entry_alias( e ) ) {
161 /* entry is an alias, don't allow bind */
163 LDAP_LOG ( OPERATION, DETAIL1, "bdb_bind: entry is alias\n", 0, 0, 0 );
165 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
169 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
170 NULL, "entry is alias", NULL, NULL );
176 if ( is_entry_referral( e ) ) {
177 /* entry is a referral, don't allow bind */
178 BerVarray refs = get_entry_referrals( be,
182 LDAP_LOG ( OPERATION, DETAIL1,
183 "bdb_bind: entry is referral\n", 0, 0, 0 );
185 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
190 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
191 e->e_dn, NULL, refs, NULL );
194 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
195 NULL, NULL, NULL, NULL );
198 ber_bvarray_free( refs );
204 case LDAP_AUTH_SIMPLE:
205 /* check for root dn/passwd */
206 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
207 /* front end will send result */
208 if(edn->bv_val != NULL) free( edn->bv_val );
209 ber_dupbv( edn, be_root_dn( be ) );
214 if ( ! access_allowed( be, conn, op, e,
215 password, NULL, ACL_AUTH, NULL ) )
217 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
218 NULL, NULL, NULL, NULL );
222 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
223 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
224 NULL, NULL, NULL, NULL );
228 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
229 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
230 NULL, NULL, NULL, NULL );
237 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
238 case LDAP_AUTH_KRBV41:
239 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
240 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
241 NULL, NULL, NULL, NULL );
245 if ( ! access_allowed( be, conn, op, e,
246 krbattr, NULL, ACL_AUTH, NULL ) )
248 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
249 NULL, NULL, NULL, NULL );
253 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
254 : "", ad.pinst, ad.prealm );
256 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
258 * no krbname values present: check against DN
260 if ( strcasecmp( dn, krbname ) == 0 ) {
264 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
265 NULL, NULL, NULL, NULL );
268 } else { /* look for krbname match */
269 struct berval krbval;
271 krbval.bv_val = krbname;
272 krbval.bv_len = strlen( krbname );
274 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
275 send_ldap_result( conn, op,
276 rc = LDAP_INVALID_CREDENTIALS,
277 NULL, NULL, NULL, NULL );
284 case LDAP_AUTH_KRBV42:
285 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
286 NULL, "Kerberos bind step 2 not supported",
292 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
293 NULL, "authentication method not supported", NULL, NULL );
298 /* free entry and reader lock */
300 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
303 LOCK_ID_FREE(bdb->bi_dbenv, locker);
305 /* front end with send result on success (rc==0) */