1 /* bind.c - ldbm backend bind and unbind routines */
4 * Copyright 1998-1999 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"
24 extern int krbv4_ldap_auth();
37 for ( i = 0; vals[i] != NULL; i++ ) {
38 if ( syntax != SYNTAX_BIN ) {
42 ldap_pvt_thread_mutex_lock( &crypt_mutex );
45 result = lutil_passwd(
47 (char*) vals[i]->bv_val,
51 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
57 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {
79 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
85 char krbname[MAX_K_NAME_SZ + 1];
89 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
94 /* get entry with reader lock */
95 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
96 char *matched_dn = NULL;
97 struct berval **refs = NULL;
99 if( matched != NULL ) {
100 matched_dn = ch_strdup( matched->e_dn );
102 refs = is_entry_referral( matched )
103 ? get_entry_referrals( be, conn, op, matched )
106 cache_return_entry_r( &li->li_cache, matched );
108 refs = default_referral;
111 /* allow noauth binds */
113 if ( method == LDAP_AUTH_SIMPLE ) {
114 if( cred->bv_len == 0 ) {
116 send_ldap_result( conn, op, LDAP_SUCCESS,
117 NULL, NULL, NULL, NULL );
119 } else if ( be_isroot_pw( be, dn, cred ) ) {
120 *edn = ch_strdup( be_root_dn( be ) );
121 rc = 0; /* front end will send result */
124 send_ldap_result( conn, op, LDAP_REFERRAL,
125 matched_dn, NULL, refs, NULL );
128 } else if ( method == LDAP_AUTH_SASL ) {
129 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
130 /* insert DIGEST calls here */
131 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
132 NULL, NULL, NULL, NULL );
135 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
136 NULL, NULL, NULL, NULL );
140 send_ldap_result( conn, op, LDAP_REFERRAL,
141 matched_dn, NULL, refs, NULL );
144 if ( matched != NULL ) {
145 ber_bvecfree( refs );
151 *edn = ch_strdup( e->e_dn );
153 /* check for deleted */
155 if ( ! access_allowed( be, conn, op, e,
156 "entry", NULL, ACL_AUTH ) )
158 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
159 NULL, NULL, NULL, NULL );
164 if ( is_entry_alias( e ) ) {
165 /* entry is an alias, don't allow bind */
166 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
169 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
170 NULL, NULL, NULL, NULL );
176 if ( is_entry_referral( e ) ) {
177 /* entry is a referral, don't allow bind */
178 struct berval **refs = get_entry_referrals( be,
181 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
184 send_ldap_result( conn, op, LDAP_REFERRAL,
185 e->e_dn, NULL, refs, NULL );
187 ber_bvecfree( refs );
194 case LDAP_AUTH_SIMPLE:
195 if ( cred->bv_len == 0 ) {
196 send_ldap_result( conn, op, LDAP_SUCCESS,
197 NULL, NULL, NULL, NULL );
199 /* stop front end from sending result */
204 /* check for root dn/passwd */
205 if ( be_isroot_pw( be, dn, cred ) ) {
206 /* front end will send result */
207 if(*edn != NULL) free( *edn );
208 *edn = ch_strdup( be_root_dn( be ) );
213 if ( ! access_allowed( be, conn, op, e,
214 "userpassword", NULL, ACL_AUTH ) )
216 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
217 NULL, NULL, NULL, NULL );
222 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
223 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
224 NULL, NULL, NULL, NULL );
226 /* stop front end from sending result */
231 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
233 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
234 NULL, NULL, NULL, NULL );
235 /* stop front end from sending result */
244 case LDAP_AUTH_KRBV41:
245 if ( ! access_allowed( be, conn, op, e,
246 "krbname", NULL, ACL_AUTH ) )
248 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
249 NULL, NULL, NULL, NULL );
254 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
255 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
256 NULL, NULL, NULL, NULL );
261 if ( ! access_allowed( be, conn, op, e,
262 "krbname", NULL, ACL_AUTH ) )
264 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
265 NULL, NULL, NULL, NULL );
270 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
271 : "", ad.pinst, ad.prealm );
274 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
276 * no krbName values present: check against DN
278 if ( strcasecmp( dn, krbname ) == 0 ) {
282 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
283 NULL, NULL, NULL, NULL );
287 } else { /* look for krbName match */
288 struct berval krbval;
290 krbval.bv_val = krbname;
291 krbval.bv_len = strlen( krbname );
293 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
294 send_ldap_result( conn, op,
295 LDAP_INVALID_CREDENTIALS,
296 NULL, NULL, NULL, NULL );
304 case LDAP_AUTH_KRBV42:
305 send_ldap_result( conn, op, LDAP_SUCCESS,
306 NULL, NULL, NULL, NULL );
307 /* stop front end from sending result */
313 /* insert SASL code here */
316 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
317 NULL, "auth method not supported", NULL, NULL );
323 /* free entry and reader lock */
324 cache_return_entry_r( &li->li_cache, e );
326 /* front end with send result on success (rc==0) */