1 /* bind.c - ldbm backend bind and unbind routines */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
18 #include "back-ldbm.h"
19 #include "proto-back-ldbm.h"
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
38 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
39 char krbname[MAX_K_NAME_SZ + 1];
40 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
44 AttributeDescription *password = slap_schema.si_ad_userPassword;
47 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
48 "ldbm_back_bind: dn: %s.\n", dn->bv_val ));
50 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn->bv_val, 0, 0);
56 /* get entry with reader lock */
57 if ( (e = dn2entry_r( be, dn->bv_val, &matched )) == NULL ) {
58 char *matched_dn = NULL;
59 struct berval **refs = NULL;
61 if( matched != NULL ) {
62 matched_dn = ch_strdup( matched->e_dn );
64 refs = is_entry_referral( matched )
65 ? get_entry_referrals( be, conn, op, matched )
68 cache_return_entry_r( &li->li_cache, matched );
71 refs = referral_rewrite( default_referral,
72 NULL, dn, LDAP_SCOPE_DEFAULT );
75 /* allow noauth binds */
77 if ( method == LDAP_AUTH_SIMPLE ) {
78 if ( be_isroot_pw( be, conn, dn, cred ) ) {
79 ber_dupbv( edn, be_root_dn( be ) );
80 rc = 0; /* front end will send result */
82 } else if ( refs != NULL ) {
83 send_ldap_result( conn, op, LDAP_REFERRAL,
84 matched_dn, NULL, refs, NULL );
87 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
88 NULL, NULL, NULL, NULL );
91 } else if ( refs != NULL ) {
92 send_ldap_result( conn, op, LDAP_REFERRAL,
93 matched_dn, NULL, refs, NULL );
96 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
97 NULL, NULL, NULL, NULL );
100 ber_bvecfree( refs );
105 ber_dupbv( edn, &e->e_name );
107 /* check for deleted */
109 if ( is_entry_alias( e ) ) {
110 /* entry is an alias, don't allow bind */
112 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
113 "ldbm_back_bind: entry (%s) is an alias.\n", e->e_dn ));
115 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
120 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
121 NULL, "entry is alias", NULL, NULL );
127 if ( is_entry_referral( e ) ) {
128 /* entry is a referral, don't allow bind */
129 struct berval **refs = get_entry_referrals( be,
133 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
134 "ldbm_back_bind: entry(%s) is a referral.\n", e->e_dn ));
136 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
142 send_ldap_result( conn, op, LDAP_REFERRAL,
143 e->e_dn, NULL, refs, NULL );
146 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
147 NULL, NULL, NULL, NULL );
150 ber_bvecfree( refs );
157 case LDAP_AUTH_SIMPLE:
158 /* check for root dn/passwd */
159 if ( be_isroot_pw( be, conn, dn, cred ) ) {
160 /* front end will send result */
161 if(edn->bv_val != NULL) free( edn->bv_val );
162 ber_dupbv( edn, be_root_dn( be ) );
167 if ( ! access_allowed( be, conn, op, e,
168 password, NULL, ACL_AUTH ) )
170 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
171 NULL, NULL, NULL, NULL );
176 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
177 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
178 NULL, NULL, NULL, NULL );
180 /* stop front end from sending result */
185 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
186 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
187 NULL, NULL, NULL, NULL );
188 /* stop front end from sending result */
196 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
197 case LDAP_AUTH_KRBV41:
198 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
199 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
200 NULL, NULL, NULL, NULL );
205 if ( ! access_allowed( be, conn, op, e,
206 krbattr, NULL, ACL_AUTH ) )
208 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
209 NULL, NULL, NULL, NULL );
214 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
215 : "", ad.pinst, ad.prealm );
217 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
219 * no krbname values present: check against DN
221 if ( strcasecmp( dn->bv_val, krbname ) == 0 ) {
225 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
226 NULL, NULL, NULL, NULL );
230 } else { /* look for krbname match */
231 struct berval krbval;
233 krbval.bv_val = krbname;
234 krbval.bv_len = strlen( krbname );
236 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
237 send_ldap_result( conn, op,
238 LDAP_INVALID_CREDENTIALS,
239 NULL, NULL, NULL, NULL );
247 case LDAP_AUTH_KRBV42:
248 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
249 NULL, "Kerberos bind step 2 not supported",
251 /* stop front end from sending result */
252 rc = LDAP_UNWILLING_TO_PERFORM;
257 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
258 NULL, "authentication method not supported", NULL, NULL );
264 /* free entry and reader lock */
265 cache_return_entry_r( &li->li_cache, e );
267 /* front end with send result on success (rc==0) */