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 ) {
78 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
84 char krbname[MAX_K_NAME_SZ + 1];
88 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
92 /* get entry with reader lock */
93 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
94 char *matched_dn = NULL;
95 struct berval **refs = NULL;
97 if( matched != NULL ) {
98 matched_dn = ch_strdup( matched->e_dn );
100 refs = is_entry_referral( matched )
101 ? get_entry_referrals( be, conn, op, matched )
104 cache_return_entry_r( &li->li_cache, matched );
106 refs = default_referral;
109 /* allow noauth binds */
111 if ( method == LDAP_AUTH_SIMPLE ) {
112 if( cred->bv_len == 0 ) {
114 send_ldap_result( conn, op, LDAP_SUCCESS,
115 NULL, NULL, NULL, NULL );
117 } else if ( be_isroot_pw( be, dn, cred ) ) {
118 *edn = ch_strdup( be_root_dn( be ) );
119 rc = 0; /* front end will send result */
122 send_ldap_result( conn, op, LDAP_REFERRAL,
123 matched_dn, NULL, refs, NULL );
126 } else if ( method == LDAP_AUTH_SASL ) {
127 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
128 /* insert DIGEST calls here */
129 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
130 NULL, NULL, NULL, NULL );
133 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
134 NULL, NULL, NULL, NULL );
138 send_ldap_result( conn, op, LDAP_REFERRAL,
139 matched_dn, NULL, refs, NULL );
142 if ( matched != NULL ) {
143 ber_bvecfree( refs );
149 *edn = ch_strdup( e->e_dn );
151 /* check for deleted */
153 if ( ! access_allowed( be, conn, op, e,
154 "entry", NULL, ACL_AUTH ) )
156 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
157 NULL, NULL, NULL, NULL );
162 if ( is_entry_alias( e ) ) {
163 /* entry is an alias, don't allow bind */
164 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
167 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
168 NULL, NULL, NULL, NULL );
174 if ( is_entry_referral( e ) ) {
175 /* entry is a referral, don't allow bind */
176 struct berval **refs = get_entry_referrals( be,
179 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
182 send_ldap_result( conn, op, LDAP_REFERRAL,
183 e->e_dn, NULL, refs, NULL );
185 ber_bvecfree( refs );
192 case LDAP_AUTH_SIMPLE:
193 if ( cred->bv_len == 0 ) {
194 send_ldap_result( conn, op, LDAP_SUCCESS,
195 NULL, NULL, NULL, NULL );
197 /* stop front end from sending result */
202 /* check for root dn/passwd */
203 if ( be_isroot_pw( be, dn, cred ) ) {
204 /* front end will send result */
205 if(*edn != NULL) free( *edn );
206 *edn = ch_strdup( be_root_dn( be ) );
211 if ( ! access_allowed( be, conn, op, e,
212 "userpassword", NULL, ACL_AUTH ) )
214 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
215 NULL, NULL, NULL, NULL );
220 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
221 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
222 NULL, NULL, NULL, NULL );
224 /* stop front end from sending result */
229 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
231 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
232 NULL, NULL, NULL, NULL );
233 /* stop front end from sending result */
242 case LDAP_AUTH_KRBV41:
243 if ( ! access_allowed( be, conn, op, e,
244 "krbname", NULL, ACL_AUTH ) )
246 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
247 NULL, NULL, NULL, NULL );
252 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
253 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
254 NULL, NULL, NULL, NULL );
259 if ( ! access_allowed( be, conn, op, e,
260 "krbname", NULL, ACL_AUTH ) )
262 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
263 NULL, NULL, NULL, NULL );
268 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
269 : "", ad.pinst, ad.prealm );
272 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
274 * no krbName values present: check against DN
276 if ( strcasecmp( dn, krbname ) == 0 ) {
280 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
281 NULL, NULL, NULL, NULL );
285 } else { /* look for krbName match */
286 struct berval krbval;
288 krbval.bv_val = krbname;
289 krbval.bv_len = strlen( krbname );
291 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
292 send_ldap_result( conn, op,
293 LDAP_INVALID_CREDENTIALS,
294 NULL, NULL, NULL, NULL );
302 case LDAP_AUTH_KRBV42:
303 send_ldap_result( conn, op, LDAP_SUCCESS,
304 NULL, NULL, NULL, NULL );
305 /* stop front end from sending result */
311 /* insert SASL code here */
314 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
315 NULL, "auth method not supported", NULL, NULL );
321 /* free entry and reader lock */
322 cache_return_entry_r( &li->li_cache, e );
324 /* front end with send result on success (rc==0) */