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;
46 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
51 /* get entry with reader lock */
52 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
53 char *matched_dn = NULL;
54 struct berval **refs = NULL;
56 if( matched != NULL ) {
57 matched_dn = ch_strdup( matched->e_dn );
59 refs = is_entry_referral( matched )
60 ? get_entry_referrals( be, conn, op, matched )
63 cache_return_entry_r( &li->li_cache, matched );
65 refs = default_referral;
68 /* allow noauth binds */
70 if ( method == LDAP_AUTH_SIMPLE ) {
71 if ( be_isroot_pw( be, conn, dn, cred ) ) {
72 *edn = ch_strdup( be_root_dn( be ) );
73 rc = 0; /* front end will send result */
75 } else if ( refs != NULL ) {
76 send_ldap_result( conn, op, LDAP_REFERRAL,
77 matched_dn, NULL, refs, NULL );
80 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
81 NULL, NULL, NULL, NULL );
84 } else if ( refs != NULL ) {
85 send_ldap_result( conn, op, LDAP_REFERRAL,
86 matched_dn, NULL, refs, NULL );
89 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
90 NULL, NULL, NULL, NULL );
93 if ( matched != NULL ) {
100 *edn = ch_strdup( e->e_dn );
102 /* check for deleted */
104 if ( is_entry_alias( e ) ) {
105 /* entry is an alias, don't allow bind */
106 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
109 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
110 NULL, "entry is alias", NULL, NULL );
116 if ( is_entry_referral( e ) ) {
117 /* entry is a referral, don't allow bind */
118 struct berval **refs = get_entry_referrals( be,
121 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
125 send_ldap_result( conn, op, LDAP_REFERRAL,
126 e->e_dn, NULL, refs, NULL );
129 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
130 NULL, NULL, NULL, NULL );
133 ber_bvecfree( refs );
140 case LDAP_AUTH_SIMPLE:
141 /* check for root dn/passwd */
142 if ( be_isroot_pw( be, conn, dn, cred ) ) {
143 /* front end will send result */
144 if(*edn != NULL) free( *edn );
145 *edn = ch_strdup( be_root_dn( be ) );
150 if ( ! access_allowed( be, conn, op, e,
151 password, NULL, ACL_AUTH ) )
153 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
154 NULL, NULL, NULL, NULL );
159 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
160 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
161 NULL, NULL, NULL, NULL );
163 /* stop front end from sending result */
168 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
169 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
170 NULL, NULL, NULL, NULL );
171 /* stop front end from sending result */
179 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
180 case LDAP_AUTH_KRBV41:
181 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
182 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
183 NULL, NULL, NULL, NULL );
188 if ( ! access_allowed( be, conn, op, e,
189 krbattr, NULL, ACL_AUTH ) )
191 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
192 NULL, NULL, NULL, NULL );
197 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
198 : "", ad.pinst, ad.prealm );
200 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
202 * no krbname values present: check against DN
204 if ( strcasecmp( dn, krbname ) == 0 ) {
208 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
209 NULL, NULL, NULL, NULL );
213 } else { /* look for krbname match */
214 struct berval krbval;
216 krbval.bv_val = krbname;
217 krbval.bv_len = strlen( krbname );
219 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
220 send_ldap_result( conn, op,
221 LDAP_INVALID_CREDENTIALS,
222 NULL, NULL, NULL, NULL );
230 case LDAP_AUTH_KRBV42:
231 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
232 NULL, "Kerberos bind step 2 not supported",
234 /* stop front end from sending result */
235 rc = LDAP_UNWILLING_TO_PERFORM;
240 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
241 NULL, "authentication method not supported", NULL, NULL );
247 /* free entry and reader lock */
248 cache_return_entry_r( &li->li_cache, e );
250 /* front end with send result on success (rc==0) */