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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
44 AttributeDescription *password = slap_schema.si_ad_userPassword;
45 AttributeDescription *entry = slap_schema.si_ad_entry;
47 static const char *password = "userpassword";
48 static const char *entry = "entry";
51 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
56 /* get entry with reader lock */
57 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
58 char *matched_dn = NULL;
59 struct berval **refs = NULL;
61 if( matched != NULL ) {
62 matched_dn = ch_strdup( matched->e_dn );
64 refs = is_entry_referral( matched )
65 ? get_entry_referrals( be, conn, op, matched )
68 cache_return_entry_r( &li->li_cache, matched );
70 refs = default_referral;
73 /* allow noauth binds */
75 if ( method == LDAP_AUTH_SIMPLE ) {
76 if ( be_isroot_pw( be, dn, cred ) ) {
77 *edn = ch_strdup( be_root_dn( be ) );
78 rc = 0; /* front end will send result */
80 } else if ( refs != NULL ) {
81 send_ldap_result( conn, op, LDAP_REFERRAL,
82 matched_dn, NULL, refs, NULL );
85 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
86 NULL, NULL, NULL, NULL );
89 } else if ( refs != NULL ) {
90 send_ldap_result( conn, op, LDAP_REFERRAL,
91 matched_dn, NULL, refs, NULL );
94 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
95 NULL, NULL, NULL, NULL );
98 if ( matched != NULL ) {
105 *edn = ch_strdup( e->e_dn );
107 /* check for deleted */
109 if ( ! access_allowed( be, conn, op, e,
110 entry, NULL, ACL_AUTH ) )
112 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
113 NULL, NULL, NULL, NULL );
118 if ( is_entry_alias( e ) ) {
119 /* entry is an alias, don't allow bind */
120 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
123 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
124 NULL, "entry is alias", NULL, NULL );
130 if ( is_entry_referral( e ) ) {
131 /* entry is a referral, don't allow bind */
132 struct berval **refs = get_entry_referrals( be,
135 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
139 send_ldap_result( conn, op, LDAP_REFERRAL,
140 e->e_dn, NULL, refs, NULL );
143 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
144 NULL, NULL, NULL, NULL );
147 ber_bvecfree( refs );
154 case LDAP_AUTH_SIMPLE:
155 /* check for root dn/passwd */
156 if ( be_isroot_pw( be, dn, cred ) ) {
157 /* front end will send result */
158 if(*edn != NULL) free( *edn );
159 *edn = ch_strdup( be_root_dn( be ) );
164 if ( ! access_allowed( be, conn, op, e,
165 password, NULL, ACL_AUTH ) )
167 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
168 NULL, NULL, NULL, NULL );
173 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
174 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
175 NULL, NULL, NULL, NULL );
177 /* stop front end from sending result */
182 if ( slap_passwd_check( a, cred ) != 0 ) {
183 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
184 NULL, NULL, NULL, NULL );
185 /* stop front end from sending result */
193 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
194 case LDAP_AUTH_KRBV41:
195 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
196 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
197 NULL, NULL, NULL, NULL );
202 if ( ! access_allowed( be, conn, op, e,
203 "krbname", NULL, ACL_AUTH ) )
205 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
206 NULL, NULL, NULL, NULL );
211 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
212 : "", ad.pinst, ad.prealm );
214 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
216 * no krbname values present: check against DN
218 if ( strcasecmp( dn, krbname ) == 0 ) {
222 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
223 NULL, NULL, NULL, NULL );
227 } else { /* look for krbname match */
228 struct berval krbval;
230 krbval.bv_val = krbname;
231 krbval.bv_len = strlen( krbname );
233 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
234 send_ldap_result( conn, op,
235 LDAP_INVALID_CREDENTIALS,
236 NULL, NULL, NULL, NULL );
244 case LDAP_AUTH_KRBV42:
245 send_ldap_result( conn, op, LDAP_SUCCESS,
246 NULL, NULL, NULL, NULL );
247 /* stop front end from sending result */
253 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
254 NULL, "authentication method not supported", NULL, NULL );
260 /* free entry and reader lock */
261 cache_return_entry_r( &li->li_cache, e );
263 /* front end with send result on success (rc==0) */