1 /* bind.c - bdb backend bind routine */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/unistd.h>
30 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
35 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
36 char krbname[MAX_K_NAME_SZ + 1];
37 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
41 AttributeDescription *password = slap_schema.si_ad_userPassword;
44 LDAP_LOG (( "bind", LDAP_LEVEL_ARGS, "==> bdb_bind: dn: %s\n", dn->bv_val ));
46 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", dn->bv_val, 0, 0);
50 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0 );
57 send_ldap_result( conn, op, LDAP_BUSY,
58 NULL, "ldap server busy", NULL, NULL );
61 send_ldap_result( conn, op, rc=LDAP_OTHER,
62 NULL, "internal error", NULL, NULL );
66 /* get entry with reader lock */
68 char *matched_dn = NULL;
71 if( matched != NULL ) {
72 matched_dn = ch_strdup( matched->e_dn );
74 refs = is_entry_referral( matched )
75 ? get_entry_referrals( be, conn, op, matched )
78 bdb_cache_return_entry_r( &bdb->bi_cache, matched );
82 refs = referral_rewrite( default_referral,
83 NULL, dn, LDAP_SCOPE_DEFAULT );
86 /* allow noauth binds */
88 if ( method == LDAP_AUTH_SIMPLE ) {
89 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
90 ber_dupbv( edn, be_root_dn( be ) );
91 rc = LDAP_SUCCESS; /* front end will send result */
93 } else if ( refs != NULL ) {
94 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
95 matched_dn, NULL, refs, NULL );
98 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
99 NULL, NULL, NULL, NULL );
102 } else if ( refs != NULL ) {
103 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
104 matched_dn, NULL, refs, NULL );
107 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
108 NULL, NULL, NULL, NULL );
111 ber_bvarray_free( refs );
117 ber_dupbv( edn, &e->e_name );
119 /* check for deleted */
120 #ifdef BDB_SUBENTRIES
121 if ( is_entry_subentry( e ) ) {
122 /* entry is an subentry, don't allow bind */
124 LDAP_LOG (( "bind", LDAP_LEVEL_DETAIL1, "bdb_bind: entry is subentry\n" ));
126 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
130 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
131 NULL, NULL, NULL, NULL );
138 if ( is_entry_alias( e ) ) {
139 /* entry is an alias, don't allow bind */
141 LDAP_LOG (( "bind", LDAP_LEVEL_DETAIL1, "bdb_bind: entry is alias\n" ));
143 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
147 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
148 NULL, "entry is alias", NULL, NULL );
154 if ( is_entry_referral( e ) ) {
155 /* entry is a referral, don't allow bind */
156 BerVarray refs = get_entry_referrals( be,
160 LDAP_LOG (( "bind", LDAP_LEVEL_DETAIL1, "bdb_bind: entry is referral\n" ));
162 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
167 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
168 e->e_dn, NULL, refs, NULL );
171 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
172 NULL, NULL, NULL, NULL );
175 ber_bvarray_free( refs );
181 case LDAP_AUTH_SIMPLE:
182 /* check for root dn/passwd */
183 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
184 /* front end will send result */
185 if(edn->bv_val != NULL) free( edn->bv_val );
186 ber_dupbv( edn, be_root_dn( be ) );
191 if ( ! access_allowed( be, conn, op, e,
192 password, NULL, ACL_AUTH, NULL ) )
194 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
195 NULL, NULL, NULL, NULL );
199 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
200 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
201 NULL, NULL, NULL, NULL );
205 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
206 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
207 NULL, NULL, NULL, NULL );
214 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
215 case LDAP_AUTH_KRBV41:
216 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
217 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
218 NULL, NULL, NULL, NULL );
222 if ( ! access_allowed( be, conn, op, e,
223 krbattr, NULL, ACL_AUTH, NULL ) )
225 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
226 NULL, NULL, NULL, NULL );
230 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
231 : "", ad.pinst, ad.prealm );
233 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
235 * no krbname values present: check against DN
237 if ( strcasecmp( dn, krbname ) == 0 ) {
241 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
242 NULL, NULL, NULL, NULL );
245 } else { /* look for krbname match */
246 struct berval krbval;
248 krbval.bv_val = krbname;
249 krbval.bv_len = strlen( krbname );
251 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
252 send_ldap_result( conn, op,
253 rc = LDAP_INVALID_CREDENTIALS,
254 NULL, NULL, NULL, NULL );
261 case LDAP_AUTH_KRBV42:
262 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
263 NULL, "Kerberos bind step 2 not supported",
269 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
270 NULL, "authentication method not supported", NULL, NULL );
275 /* free entry and reader lock */
277 bdb_cache_return_entry_r( &bdb->bi_cache, e );
280 /* front end with send result on success (rc==0) */