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];
43 AttributeDescription *password = slap_schema.si_ad_userPassword;
45 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
50 /* get entry with reader lock */
51 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
52 char *matched_dn = NULL;
53 struct berval **refs = NULL;
55 if( matched != NULL ) {
56 matched_dn = ch_strdup( matched->e_dn );
58 refs = is_entry_referral( matched )
59 ? get_entry_referrals( be, conn, op, matched )
62 cache_return_entry_r( &li->li_cache, matched );
64 refs = default_referral;
67 /* allow noauth binds */
69 if ( method == LDAP_AUTH_SIMPLE ) {
70 if ( be_isroot_pw( be, dn, cred ) ) {
71 *edn = ch_strdup( be_root_dn( be ) );
72 rc = 0; /* front end will send result */
74 } else if ( refs != NULL ) {
75 send_ldap_result( conn, op, LDAP_REFERRAL,
76 matched_dn, NULL, refs, NULL );
79 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
80 NULL, NULL, NULL, NULL );
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 if ( matched != NULL ) {
99 *edn = ch_strdup( e->e_dn );
101 /* check for deleted */
103 if ( is_entry_alias( e ) ) {
104 /* entry is an alias, don't allow bind */
105 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
108 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
109 NULL, "entry is alias", NULL, NULL );
115 if ( is_entry_referral( e ) ) {
116 /* entry is a referral, don't allow bind */
117 struct berval **refs = get_entry_referrals( be,
120 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
124 send_ldap_result( conn, op, LDAP_REFERRAL,
125 e->e_dn, NULL, refs, NULL );
128 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
129 NULL, NULL, NULL, NULL );
132 ber_bvecfree( refs );
139 case LDAP_AUTH_SIMPLE:
140 /* check for root dn/passwd */
141 if ( be_isroot_pw( be, dn, cred ) ) {
142 /* front end will send result */
143 if(*edn != NULL) free( *edn );
144 *edn = ch_strdup( be_root_dn( be ) );
149 if ( ! access_allowed( be, conn, op, e,
150 password, NULL, ACL_AUTH ) )
152 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
153 NULL, NULL, NULL, NULL );
158 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
159 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
160 NULL, NULL, NULL, NULL );
162 /* stop front end from sending result */
167 if ( slap_passwd_check( a, cred ) != 0 ) {
168 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
169 NULL, NULL, NULL, NULL );
170 /* stop front end from sending result */
178 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
179 case LDAP_AUTH_KRBV41:
180 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
181 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
182 NULL, NULL, NULL, NULL );
187 if ( ! access_allowed( be, conn, op, e,
188 "krbname", NULL, ACL_AUTH ) )
190 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
191 NULL, NULL, NULL, NULL );
196 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
197 : "", ad.pinst, ad.prealm );
199 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
201 * no krbname values present: check against DN
203 if ( strcasecmp( dn, krbname ) == 0 ) {
207 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
208 NULL, NULL, NULL, NULL );
212 } else { /* look for krbname match */
213 struct berval krbval;
215 krbval.bv_val = krbname;
216 krbval.bv_len = strlen( krbname );
218 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
219 send_ldap_result( conn, op,
220 LDAP_INVALID_CREDENTIALS,
221 NULL, NULL, NULL, NULL );
229 case LDAP_AUTH_KRBV42:
230 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
231 NULL, "Kerberos bind step 2 not supported",
233 /* stop front end from sending result */
234 rc = LDAP_UNWILLING_TO_PERFORM;
239 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
240 NULL, "authentication method not supported", NULL, NULL );
246 /* free entry and reader lock */
247 cache_return_entry_r( &li->li_cache, e );
249 /* front end with send result on success (rc==0) */