1 /* bind.c - ldbm backend bind and unbind routines */
4 * Copyright 1998-2000 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"
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
38 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
39 char krbname[MAX_K_NAME_SZ + 1];
43 AttributeDescription *password = slap_schema.si_ad_userPassword;
44 AttributeDescription *entry = slap_schema.si_ad_entry;
46 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
51 /* get entry with reader lock */
52 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
53 char *matched_dn = NULL;
54 struct berval **refs = NULL;
56 if( matched != NULL ) {
57 matched_dn = ch_strdup( matched->e_dn );
59 refs = is_entry_referral( matched )
60 ? get_entry_referrals( be, conn, op, matched )
63 cache_return_entry_r( &li->li_cache, matched );
65 refs = default_referral;
68 /* allow noauth binds */
70 if ( method == LDAP_AUTH_SIMPLE ) {
71 if ( be_isroot_pw( be, dn, cred ) ) {
72 *edn = ch_strdup( be_root_dn( be ) );
73 rc = 0; /* front end will send result */
75 } else if ( refs != NULL ) {
76 send_ldap_result( conn, op, LDAP_REFERRAL,
77 matched_dn, NULL, refs, NULL );
80 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
81 NULL, NULL, NULL, NULL );
84 } else if ( refs != NULL ) {
85 send_ldap_result( conn, op, LDAP_REFERRAL,
86 matched_dn, NULL, refs, NULL );
89 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
90 NULL, NULL, NULL, NULL );
93 if ( matched != NULL ) {
100 *edn = ch_strdup( e->e_dn );
102 /* check for deleted */
104 if ( ! access_allowed( be, conn, op, e,
105 entry, NULL, ACL_AUTH ) )
107 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
108 NULL, NULL, NULL, NULL );
113 if ( is_entry_alias( e ) ) {
114 /* entry is an alias, don't allow bind */
115 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
118 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
119 NULL, "entry is alias", NULL, NULL );
125 if ( is_entry_referral( e ) ) {
126 /* entry is a referral, don't allow bind */
127 struct berval **refs = get_entry_referrals( be,
130 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
134 send_ldap_result( conn, op, LDAP_REFERRAL,
135 e->e_dn, NULL, refs, NULL );
138 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
139 NULL, NULL, NULL, NULL );
142 ber_bvecfree( refs );
149 case LDAP_AUTH_SIMPLE:
150 /* check for root dn/passwd */
151 if ( be_isroot_pw( be, dn, cred ) ) {
152 /* front end will send result */
153 if(*edn != NULL) free( *edn );
154 *edn = ch_strdup( be_root_dn( be ) );
159 if ( ! access_allowed( be, conn, op, e,
160 password, NULL, ACL_AUTH ) )
162 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
163 NULL, NULL, NULL, NULL );
168 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
169 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
170 NULL, NULL, NULL, NULL );
172 /* stop front end from sending result */
177 if ( slap_passwd_check( a, cred ) != 0 ) {
178 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
179 NULL, NULL, NULL, NULL );
180 /* stop front end from sending result */
188 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
189 case LDAP_AUTH_KRBV41:
190 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
191 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
192 NULL, NULL, NULL, NULL );
197 if ( ! access_allowed( be, conn, op, e,
198 "krbname", NULL, ACL_AUTH ) )
200 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
201 NULL, NULL, NULL, NULL );
206 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
207 : "", ad.pinst, ad.prealm );
209 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
211 * no krbname values present: check against DN
213 if ( strcasecmp( dn, krbname ) == 0 ) {
217 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
218 NULL, NULL, NULL, NULL );
222 } else { /* look for krbname match */
223 struct berval krbval;
225 krbval.bv_val = krbname;
226 krbval.bv_len = strlen( krbname );
228 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
229 send_ldap_result( conn, op,
230 LDAP_INVALID_CREDENTIALS,
231 NULL, NULL, NULL, NULL );
239 case LDAP_AUTH_KRBV42:
240 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
241 NULL, "Kerberos bind step 2 not supported",
243 /* stop front end from sending result */
244 rc = LDAP_UNWILLING_TO_PERFORM;
249 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
250 NULL, "authentication method not supported", NULL, NULL );
256 /* free entry and reader lock */
257 cache_return_entry_r( &li->li_cache, e );
259 /* front end with send result on success (rc==0) */