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 ));
50 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
57 /* get entry with reader lock */
58 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
59 char *matched_dn = NULL;
60 struct berval **refs = NULL;
62 if( matched != NULL ) {
63 matched_dn = ch_strdup( matched->e_dn );
65 refs = is_entry_referral( matched )
66 ? get_entry_referrals( be, conn, op, matched )
69 cache_return_entry_r( &li->li_cache, matched );
71 refs = default_referral;
74 /* allow noauth binds */
76 if ( method == LDAP_AUTH_SIMPLE ) {
77 if ( be_isroot_pw( be, conn, dn, cred ) ) {
78 *edn = ch_strdup( be_root_dn( be ) );
79 rc = 0; /* front end will send result */
81 } else if ( refs != NULL ) {
82 send_ldap_result( conn, op, LDAP_REFERRAL,
83 matched_dn, NULL, refs, NULL );
86 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
87 NULL, NULL, NULL, NULL );
90 } else if ( refs != NULL ) {
91 send_ldap_result( conn, op, LDAP_REFERRAL,
92 matched_dn, NULL, refs, NULL );
95 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
96 NULL, NULL, NULL, NULL );
99 if ( matched != NULL ) {
100 ber_bvecfree( refs );
106 *edn = ch_strdup( e->e_dn );
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,
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 != NULL) free( *edn );
163 *edn = ch_strdup( 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, 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) */