1 /* bind.c - ldbm backend bind and unbind routines */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
14 #include <ac/unistd.h>
17 #include "back-ldbm.h"
18 #include "proto-back-ldbm.h"
23 extern int krbv4_ldap_auth();
36 for ( i = 0; vals[i] != NULL; i++ ) {
37 if ( syntax != SYNTAX_BIN ) {
41 ldap_pvt_thread_mutex_lock( &crypt_mutex );
44 result = lutil_passwd(
46 (char*) vals[i]->bv_val,
50 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
56 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {
77 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
83 char krbname[MAX_K_NAME_SZ + 1];
87 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
91 /* get entry with reader lock */
92 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
93 char *matched_dn = NULL;
94 struct berval **refs = NULL;
96 if( matched != NULL ) {
97 matched_dn = ch_strdup( matched->e_dn );
99 refs = is_entry_referral( matched )
100 ? get_entry_referrals( be, conn, op, matched )
103 cache_return_entry_r( &li->li_cache, matched );
105 refs = default_referral;
108 /* allow noauth binds */
110 if ( method == LDAP_AUTH_SIMPLE ) {
111 if( cred->bv_len == 0 ) {
113 send_ldap_result( conn, op, LDAP_SUCCESS,
114 NULL, NULL, NULL, NULL );
116 } else if ( be_isroot_pw( be, dn, cred ) ) {
117 *edn = ch_strdup( be_root_dn( be ) );
118 rc = 0; /* front end will send result */
121 send_ldap_result( conn, op, LDAP_REFERRAL,
122 matched_dn, NULL, refs, NULL );
125 } else if ( method == LDAP_AUTH_SASL ) {
126 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
127 /* insert DIGEST calls here */
128 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
129 NULL, NULL, NULL, NULL );
132 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
133 NULL, NULL, NULL, NULL );
137 send_ldap_result( conn, op, LDAP_REFERRAL,
138 matched_dn, NULL, refs, NULL );
141 if ( matched != NULL ) {
142 ber_bvecfree( refs );
148 *edn = ch_strdup( e->e_dn );
150 /* check for deleted */
152 if ( ! access_allowed( be, conn, op, e,
153 "entry", NULL, ACL_AUTH ) )
155 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
156 NULL, NULL, NULL, NULL );
161 if ( is_entry_alias( e ) ) {
162 /* entry is an alias, don't allow bind */
163 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
166 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
167 NULL, NULL, NULL, NULL );
173 if ( is_entry_referral( e ) ) {
174 /* entry is a referral, don't allow bind */
175 struct berval **refs = get_entry_referrals( be,
178 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
181 send_ldap_result( conn, op, LDAP_REFERRAL,
182 e->e_dn, NULL, refs, NULL );
184 ber_bvecfree( refs );
191 case LDAP_AUTH_SIMPLE:
192 if ( cred->bv_len == 0 ) {
193 send_ldap_result( conn, op, LDAP_SUCCESS,
194 NULL, NULL, NULL, NULL );
196 /* stop front end from sending result */
201 /* check for root dn/passwd */
202 if ( be_isroot_pw( be, dn, cred ) ) {
203 /* front end will send result */
204 if(*edn != NULL) free( *edn );
205 *edn = ch_strdup( be_root_dn( be ) );
210 if ( ! access_allowed( be, conn, op, e,
211 "userpassword", NULL, ACL_AUTH ) )
213 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
214 NULL, NULL, NULL, NULL );
219 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
220 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
221 NULL, NULL, NULL, NULL );
223 /* stop front end from sending result */
228 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
230 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
231 NULL, NULL, NULL, NULL );
232 /* stop front end from sending result */
241 case LDAP_AUTH_KRBV41:
242 if ( ! access_allowed( be, conn, op, e,
243 "krbname", NULL, ACL_AUTH ) )
245 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
246 NULL, NULL, NULL, NULL );
251 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
252 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
253 NULL, NULL, NULL, NULL );
258 if ( ! access_allowed( be, conn, op, e,
259 "krbname", NULL, ACL_AUTH ) )
261 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
262 NULL, NULL, NULL, NULL );
267 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
268 : "", ad.pinst, ad.prealm );
271 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
273 * no krbName values present: check against DN
275 if ( strcasecmp( dn, krbname ) == 0 ) {
279 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
280 NULL, NULL, NULL, NULL );
284 } else { /* look for krbName match */
285 struct berval krbval;
287 krbval.bv_val = krbname;
288 krbval.bv_len = strlen( krbname );
290 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
291 send_ldap_result( conn, op,
292 LDAP_INVALID_CREDENTIALS,
293 NULL, NULL, NULL, NULL );
301 case LDAP_AUTH_KRBV42:
302 send_ldap_result( conn, op, LDAP_SUCCESS,
303 NULL, NULL, NULL, NULL );
304 /* stop front end from sending result */
310 /* insert SASL code here */
313 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
314 NULL, "auth method not supported", NULL, NULL );
320 /* free entry and reader lock */
321 cache_return_entry_r( &li->li_cache, e );
323 /* front end with send result on success (rc==0) */