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;
44 LDAP_LOG (( "bind", LDAP_LEVEL_ARGS, "==> bdb_bind: dn: %s\n", dn->bv_val ));
46 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", dn->bv_val, 0, 0);
50 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0 );
57 send_ldap_result( conn, op, rc=LDAP_OTHER,
58 NULL, "internal error", NULL, NULL );
62 /* get entry with reader lock */
64 char *matched_dn = NULL;
67 if( matched != NULL ) {
68 matched_dn = ch_strdup( matched->e_dn );
70 refs = is_entry_referral( matched )
71 ? get_entry_referrals( be, conn, op, matched )
74 bdb_cache_return_entry_r( &bdb->bi_cache, matched );
78 refs = referral_rewrite( default_referral,
79 NULL, dn, LDAP_SCOPE_DEFAULT );
82 /* allow noauth binds */
84 if ( method == LDAP_AUTH_SIMPLE ) {
85 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
86 ber_dupbv( edn, be_root_dn( be ) );
87 rc = LDAP_SUCCESS; /* front end will send result */
89 } else if ( refs != NULL ) {
90 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
91 matched_dn, NULL, refs, NULL );
94 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
95 NULL, NULL, NULL, NULL );
98 } else if ( refs != NULL ) {
99 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
100 matched_dn, NULL, refs, NULL );
103 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
104 NULL, NULL, NULL, NULL );
107 ber_bvarray_free( refs );
113 ber_dupbv( edn, &e->e_name );
115 /* check for deleted */
116 #ifdef BDB_SUBENTRIES
117 if ( is_entry_subentry( e ) ) {
118 /* entry is an subentry, don't allow bind */
120 LDAP_LOG (( "bind", LDAP_LEVEL_DETAIL1, "bdb_bind: entry is subentry\n" ));
122 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
126 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
127 NULL, NULL, NULL, NULL );
134 if ( is_entry_alias( e ) ) {
135 /* entry is an alias, don't allow bind */
137 LDAP_LOG (( "bind", LDAP_LEVEL_DETAIL1, "bdb_bind: entry is alias\n" ));
139 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
143 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
144 NULL, "entry is alias", NULL, NULL );
150 if ( is_entry_referral( e ) ) {
151 /* entry is a referral, don't allow bind */
152 BerVarray refs = get_entry_referrals( be,
156 LDAP_LOG (( "bind", LDAP_LEVEL_DETAIL1, "bdb_bind: entry is referral\n" ));
158 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
163 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
164 e->e_dn, NULL, refs, NULL );
167 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
168 NULL, NULL, NULL, NULL );
171 ber_bvarray_free( refs );
177 case LDAP_AUTH_SIMPLE:
178 /* check for root dn/passwd */
179 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
180 /* front end will send result */
181 if(edn->bv_val != NULL) free( edn->bv_val );
182 ber_dupbv( edn, be_root_dn( be ) );
187 if ( ! access_allowed( be, conn, op, e,
188 password, NULL, ACL_AUTH, NULL ) )
190 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
191 NULL, NULL, NULL, NULL );
195 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
196 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
197 NULL, NULL, NULL, NULL );
201 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
202 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
203 NULL, NULL, NULL, NULL );
210 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
211 case LDAP_AUTH_KRBV41:
212 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
213 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
214 NULL, NULL, NULL, NULL );
218 if ( ! access_allowed( be, conn, op, e,
219 krbattr, NULL, ACL_AUTH, NULL ) )
221 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
222 NULL, NULL, NULL, NULL );
226 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
227 : "", ad.pinst, ad.prealm );
229 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
231 * no krbname values present: check against DN
233 if ( strcasecmp( dn, krbname ) == 0 ) {
237 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
238 NULL, NULL, NULL, NULL );
241 } else { /* look for krbname match */
242 struct berval krbval;
244 krbval.bv_val = krbname;
245 krbval.bv_len = strlen( krbname );
247 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
248 send_ldap_result( conn, op,
249 rc = LDAP_INVALID_CREDENTIALS,
250 NULL, NULL, NULL, NULL );
257 case LDAP_AUTH_KRBV42:
258 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
259 NULL, "Kerberos bind step 2 not supported",
265 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
266 NULL, "authentication method not supported", NULL, NULL );
271 /* free entry and reader lock */
273 bdb_cache_return_entry_r( &bdb->bi_cache, e );
276 /* front end with send result on success (rc==0) */