1 /* bind.c - bdb backend bind routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/string.h>
22 #include <ac/unistd.h>
28 bdb_bind( Operation *op, SlapReply *rs )
30 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
34 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
35 char krbname[MAX_K_NAME_SZ + 1];
36 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
41 AttributeDescription *password = slap_schema.si_ad_userPassword;
47 LDAP_LOG ( OPERATION, ARGS,
48 "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0 );
50 Debug( LDAP_DEBUG_ARGS,
51 "==> bdb_bind: dn: %s\n", op->o_req_dn.bv_val, 0, 0);
54 /* allow noauth binds */
55 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
56 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
57 /* front end will send result */
61 rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
66 rs->sr_text = "internal error";
67 send_ldap_result( op, rs );
72 /* get entry with reader lock */
73 rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1,
81 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
82 LOCK_ID_FREE(bdb->bi_dbenv, locker);
84 case DB_LOCK_DEADLOCK:
85 case DB_LOCK_NOTGRANTED:
88 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
89 LOCK_ID_FREE(bdb->bi_dbenv, locker);
94 if ( rs->sr_err == DB_NOTFOUND ) {
96 bdb_cache_return_entry_r( bdb->bi_dbenv,
97 &bdb->bi_cache, e, &lock );
101 rs->sr_err = LDAP_INVALID_CREDENTIALS;
102 send_ldap_result( op, rs );
104 LOCK_ID_FREE(bdb->bi_dbenv, locker);
109 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
111 /* check for deleted */
112 #ifdef BDB_SUBENTRIES
113 if ( is_entry_subentry( e ) ) {
114 /* entry is an subentry, don't allow bind */
116 LDAP_LOG ( OPERATION, DETAIL1,
117 "bdb_bind: entry is subentry\n", 0, 0, 0 );
119 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
122 rs->sr_err = LDAP_INVALID_CREDENTIALS;
128 if ( is_entry_alias( e ) ) {
129 /* entry is an alias, don't allow bind */
131 LDAP_LOG ( OPERATION, DETAIL1,
132 "bdb_bind: entry is alias\n", 0, 0, 0 );
134 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
138 rs->sr_err = LDAP_INVALID_CREDENTIALS;
140 rs->sr_err = LDAP_ALIAS_PROBLEM;
141 rs->sr_text = "entry is alias";
147 if ( is_entry_referral( e ) ) {
149 LDAP_LOG ( OPERATION, DETAIL1,
150 "bdb_bind: entry is referral\n", 0, 0, 0 );
152 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
155 rs->sr_err = LDAP_INVALID_CREDENTIALS;
159 switch ( op->oq_bind.rb_method ) {
160 case LDAP_AUTH_SIMPLE:
161 rs->sr_err = access_allowed( op, e,
162 password, NULL, ACL_AUTH, NULL );
163 if ( ! rs->sr_err ) {
165 rs->sr_err = LDAP_INVALID_CREDENTIALS;
167 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
172 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
174 rs->sr_err = LDAP_INVALID_CREDENTIALS;
176 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
181 if ( slap_passwd_check( op->o_conn,
182 a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 )
184 rs->sr_err = LDAP_INVALID_CREDENTIALS;
191 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
192 case LDAP_AUTH_KRBV41:
193 if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad )
196 rs->sr_err = LDAP_INVALID_CREDENTIALS,
200 rs->sr_err = access_allowed( op, e,
201 krbattr, NULL, ACL_AUTH, NULL );
202 if ( ! rs->sr_err ) {
203 rs->sr_err = LDAP_INSUFFICIENT_ACCESS,
207 krbval.bv_len = sprintf( krbname, "%s%s%s@%s", ad.pname,
208 *ad.pinst ? "." : "", ad.pinst, ad.prealm );
210 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
212 * no krbname values present: check against DN
214 if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
218 rs->sr_err = LDAP_INAPPROPRIATE_AUTH,
221 } else { /* look for krbname match */
222 krbval.bv_val = krbname;
224 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
225 rs->sr_err = LDAP_INVALID_CREDENTIALS;
234 assert( 0 ); /* should not be unreachable */
235 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
236 rs->sr_text = "authentication method not supported";
240 /* free entry and reader lock */
242 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
245 LOCK_ID_FREE(bdb->bi_dbenv, locker);
248 send_ldap_result( op, rs );
250 ber_bvarray_free( rs->sr_ref );
254 /* front end will send result on success (rs->sr_err==0) */