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, cred ) != 0 ) {
201 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
202 NULL, NULL, NULL, NULL );
203 /* stop front end from sending result */
212 case LDAP_AUTH_KRBV41:
213 if ( ! access_allowed( be, conn, op, e,
214 "krbname", NULL, ACL_AUTH ) )
216 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
217 NULL, NULL, NULL, NULL );
222 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
223 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
224 NULL, NULL, NULL, NULL );
229 if ( ! access_allowed( be, conn, op, e,
230 "krbname", NULL, ACL_AUTH ) )
232 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
233 NULL, NULL, NULL, NULL );
238 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
239 : "", ad.pinst, ad.prealm );
242 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
244 * no krbName values present: check against DN
246 if ( strcasecmp( dn, krbname ) == 0 ) {
250 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
251 NULL, NULL, NULL, NULL );
255 } else { /* look for krbName match */
256 struct berval krbval;
258 krbval.bv_val = krbname;
259 krbval.bv_len = strlen( krbname );
261 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
262 send_ldap_result( conn, op,
263 LDAP_INVALID_CREDENTIALS,
264 NULL, NULL, NULL, NULL );
272 case LDAP_AUTH_KRBV42:
273 send_ldap_result( conn, op, LDAP_SUCCESS,
274 NULL, NULL, NULL, NULL );
275 /* stop front end from sending result */
281 /* insert SASL code here */
284 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
285 NULL, "auth method not supported", NULL, NULL );
291 /* free entry and reader lock */
292 cache_return_entry_r( &li->li_cache, e );
294 /* front end with send result on success (rc==0) */