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;
43 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", dn->bv_val, 0, 0);
46 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0 );
53 send_ldap_result( conn, op, rc=LDAP_OTHER,
54 NULL, "internal error", NULL, NULL );
58 /* get entry with reader lock */
60 char *matched_dn = 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 bdb_cache_return_entry_r( &bdb->bi_cache, matched );
74 refs = referral_rewrite( default_referral,
75 NULL, dn, LDAP_SCOPE_DEFAULT );
78 /* allow noauth binds */
80 if ( method == LDAP_AUTH_SIMPLE ) {
81 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
82 ber_dupbv( edn, be_root_dn( be ) );
83 rc = LDAP_SUCCESS; /* front end will send result */
85 } else if ( refs != NULL ) {
86 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
87 matched_dn, NULL, refs, NULL );
90 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
91 NULL, NULL, NULL, NULL );
94 } else if ( refs != NULL ) {
95 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
96 matched_dn, NULL, refs, NULL );
99 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
100 NULL, NULL, NULL, NULL );
103 ber_bvarray_free( refs );
109 ber_dupbv( edn, &e->e_name );
111 /* check for deleted */
112 #ifdef BDB_SUBENTRIES
113 if ( is_entry_subentry( e ) ) {
114 /* entry is an subentry, don't allow bind */
115 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
118 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
119 NULL, NULL, NULL, NULL );
126 if ( is_entry_alias( e ) ) {
127 /* entry is an alias, don't allow bind */
128 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
131 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
132 NULL, "entry is alias", NULL, NULL );
138 if ( is_entry_referral( e ) ) {
139 /* entry is a referral, don't allow bind */
140 BerVarray refs = get_entry_referrals( be,
143 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
147 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
148 e->e_dn, NULL, refs, NULL );
151 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
152 NULL, NULL, NULL, NULL );
155 ber_bvarray_free( refs );
161 case LDAP_AUTH_SIMPLE:
162 /* check for root dn/passwd */
163 if ( be_isroot_pw( be, conn, ndn, 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, rc = LDAP_INSUFFICIENT_ACCESS,
175 NULL, NULL, NULL, NULL );
179 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
180 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
181 NULL, NULL, NULL, NULL );
185 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
186 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
187 NULL, NULL, NULL, NULL );
194 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
195 case LDAP_AUTH_KRBV41:
196 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
197 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
198 NULL, NULL, NULL, NULL );
202 if ( ! access_allowed( be, conn, op, e,
203 krbattr, NULL, ACL_AUTH, NULL ) )
205 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
206 NULL, NULL, NULL, NULL );
210 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
211 : "", ad.pinst, ad.prealm );
213 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
215 * no krbname values present: check against DN
217 if ( strcasecmp( dn, krbname ) == 0 ) {
221 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
222 NULL, NULL, NULL, NULL );
225 } else { /* look for krbname match */
226 struct berval krbval;
228 krbval.bv_val = krbname;
229 krbval.bv_len = strlen( krbname );
231 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
232 send_ldap_result( conn, op,
233 rc = LDAP_INVALID_CREDENTIALS,
234 NULL, NULL, NULL, NULL );
241 case LDAP_AUTH_KRBV42:
242 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
243 NULL, "Kerberos bind step 2 not supported",
249 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
250 NULL, "authentication method not supported", NULL, NULL );
255 /* free entry and reader lock */
257 bdb_cache_return_entry_r( &bdb->bi_cache, e );
260 /* front end with send result on success (rc==0) */