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"
34 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
40 char krbname[MAX_K_NAME_SZ + 1];
44 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
49 /* get entry with reader lock */
50 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
51 char *matched_dn = NULL;
52 struct berval **refs = NULL;
54 if( matched != NULL ) {
55 matched_dn = ch_strdup( matched->e_dn );
57 refs = is_entry_referral( matched )
58 ? get_entry_referrals( be, conn, op, matched )
61 cache_return_entry_r( &li->li_cache, matched );
63 refs = default_referral;
66 /* allow noauth binds */
68 if ( method == LDAP_AUTH_SIMPLE ) {
69 if( cred->bv_len == 0 ) {
71 send_ldap_result( conn, op, LDAP_SUCCESS,
72 NULL, NULL, NULL, NULL );
74 } else if ( be_isroot_pw( be, dn, cred ) ) {
75 *edn = ch_strdup( be_root_dn( be ) );
76 rc = 0; /* front end will send result */
78 } else if ( refs != NULL ) {
79 send_ldap_result( conn, op, LDAP_REFERRAL,
80 matched_dn, NULL, refs, NULL );
83 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
84 NULL, NULL, NULL, NULL );
87 } else if ( method == LDAP_AUTH_SASL ) {
88 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
89 /* insert DIGEST calls here */
90 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
91 NULL, NULL, NULL, NULL );
94 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
95 NULL, NULL, NULL, NULL );
98 } else if ( refs != NULL ) {
99 send_ldap_result( conn, op, LDAP_REFERRAL,
100 matched_dn, NULL, refs, NULL );
103 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
104 NULL, NULL, NULL, NULL );
107 if ( matched != NULL ) {
108 ber_bvecfree( refs );
114 *edn = ch_strdup( e->e_dn );
116 /* check for deleted */
118 if ( ! access_allowed( be, conn, op, e,
119 "entry", NULL, ACL_AUTH ) )
121 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
122 NULL, NULL, NULL, NULL );
127 if ( is_entry_alias( e ) ) {
128 /* entry is an alias, don't allow bind */
129 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
132 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
133 NULL, NULL, NULL, NULL );
139 if ( is_entry_referral( e ) ) {
140 /* entry is a referral, don't allow bind */
141 struct berval **refs = get_entry_referrals( be,
144 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
148 send_ldap_result( conn, op, LDAP_REFERRAL,
149 e->e_dn, NULL, refs, NULL );
152 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
153 NULL, NULL, NULL, NULL );
156 ber_bvecfree( refs );
163 case LDAP_AUTH_SIMPLE:
164 if ( cred->bv_len == 0 ) {
165 send_ldap_result( conn, op, LDAP_SUCCESS,
166 NULL, NULL, NULL, NULL );
168 /* stop front end from sending result */
173 /* check for root dn/passwd */
174 if ( be_isroot_pw( be, dn, cred ) ) {
175 /* front end will send result */
176 if(*edn != NULL) free( *edn );
177 *edn = ch_strdup( be_root_dn( be ) );
182 if ( ! access_allowed( be, conn, op, e,
183 "userpassword", NULL, ACL_AUTH ) )
185 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
186 NULL, NULL, NULL, NULL );
191 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
192 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
193 NULL, NULL, NULL, NULL );
195 /* stop front end from sending result */
200 if ( slap_passwd_check( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
202 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
203 NULL, NULL, NULL, NULL );
204 /* stop front end from sending result */
213 case LDAP_AUTH_KRBV41:
214 if ( ! access_allowed( be, conn, op, e,
215 "krbname", NULL, ACL_AUTH ) )
217 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
218 NULL, NULL, NULL, NULL );
223 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
224 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
225 NULL, NULL, NULL, NULL );
230 if ( ! access_allowed( be, conn, op, e,
231 "krbname", NULL, ACL_AUTH ) )
233 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
234 NULL, NULL, NULL, NULL );
239 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
240 : "", ad.pinst, ad.prealm );
243 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
245 * no krbName values present: check against DN
247 if ( strcasecmp( dn, krbname ) == 0 ) {
251 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
252 NULL, NULL, NULL, NULL );
256 } else { /* look for krbName match */
257 struct berval krbval;
259 krbval.bv_val = krbname;
260 krbval.bv_len = strlen( krbname );
262 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
263 send_ldap_result( conn, op,
264 LDAP_INVALID_CREDENTIALS,
265 NULL, NULL, NULL, NULL );
273 case LDAP_AUTH_KRBV42:
274 send_ldap_result( conn, op, LDAP_SUCCESS,
275 NULL, NULL, NULL, NULL );
276 /* stop front end from sending result */
282 /* insert SASL code here */
285 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
286 NULL, "auth method not supported", NULL, NULL );
292 /* free entry and reader lock */
293 cache_return_entry_r( &li->li_cache, e );
295 /* front end with send result on success (rc==0) */