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,
66 dn->bv_val, LDAP_SCOPE_DEFAULT )
69 cache_return_entry_r( &li->li_cache, matched );
72 refs = referral_rewrite( default_referral,
73 NULL, dn->bv_val, LDAP_SCOPE_DEFAULT );
76 /* allow noauth binds */
78 if ( method == LDAP_AUTH_SIMPLE ) {
79 if ( be_isroot_pw( be, conn, dn, cred ) ) {
80 ber_dupbv( edn, be_root_dn( be ) );
81 rc = 0; /* front end will send result */
83 } else if ( refs != NULL ) {
84 send_ldap_result( conn, op, LDAP_REFERRAL,
85 matched_dn, NULL, refs, NULL );
88 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
89 NULL, NULL, NULL, NULL );
92 } else if ( refs != NULL ) {
93 send_ldap_result( conn, op, LDAP_REFERRAL,
94 matched_dn, NULL, refs, NULL );
97 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
98 NULL, NULL, NULL, NULL );
101 ber_bvecfree( refs );
106 ber_dupbv( edn, &e->e_name );
108 /* check for deleted */
110 if ( is_entry_alias( e ) ) {
111 /* entry is an alias, don't allow bind */
113 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
114 "ldbm_back_bind: entry (%s) is an alias.\n", e->e_dn ));
116 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
121 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
122 NULL, "entry is alias", NULL, NULL );
128 if ( is_entry_referral( e ) ) {
129 /* entry is a referral, don't allow bind */
130 struct berval **refs = get_entry_referrals( be,
131 conn, op, e, dn->bv_val, LDAP_SCOPE_DEFAULT );
134 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
135 "ldbm_back_bind: entry(%s) is a referral.\n", e->e_dn ));
137 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
143 send_ldap_result( conn, op, LDAP_REFERRAL,
144 e->e_dn, NULL, refs, NULL );
147 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
148 NULL, NULL, NULL, NULL );
151 ber_bvecfree( refs );
158 case LDAP_AUTH_SIMPLE:
159 /* check for root dn/passwd */
160 if ( be_isroot_pw( be, conn, dn, cred ) ) {
161 /* front end will send result */
162 if(edn->bv_val != NULL) free( edn->bv_val );
163 ber_dupbv( edn, be_root_dn( be ) );
168 if ( ! access_allowed( be, conn, op, e,
169 password, NULL, ACL_AUTH ) )
171 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
172 NULL, NULL, NULL, NULL );
177 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
178 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
179 NULL, NULL, NULL, NULL );
181 /* stop front end from sending result */
186 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
187 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
188 NULL, NULL, NULL, NULL );
189 /* stop front end from sending result */
197 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
198 case LDAP_AUTH_KRBV41:
199 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
200 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
201 NULL, NULL, NULL, NULL );
206 if ( ! access_allowed( be, conn, op, e,
207 krbattr, NULL, ACL_AUTH ) )
209 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
210 NULL, NULL, NULL, NULL );
215 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
216 : "", ad.pinst, ad.prealm );
218 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
220 * no krbname values present: check against DN
222 if ( strcasecmp( dn->bv_val, krbname ) == 0 ) {
226 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
227 NULL, NULL, NULL, NULL );
231 } else { /* look for krbname match */
232 struct berval krbval;
234 krbval.bv_val = krbname;
235 krbval.bv_len = strlen( krbname );
237 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
238 send_ldap_result( conn, op,
239 LDAP_INVALID_CREDENTIALS,
240 NULL, NULL, NULL, NULL );
248 case LDAP_AUTH_KRBV42:
249 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
250 NULL, "Kerberos bind step 2 not supported",
252 /* stop front end from sending result */
253 rc = LDAP_UNWILLING_TO_PERFORM;
258 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
259 NULL, "authentication method not supported", NULL, NULL );
265 /* free entry and reader lock */
266 cache_return_entry_r( &li->li_cache, e );
268 /* front end with send result on success (rc==0) */