1 /* bind.c - bdb backend bind routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2006 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>
27 bdb_bind( Operation *op, SlapReply *rs )
29 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
33 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
34 char krbname[MAX_K_NAME_SZ + 1];
35 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
40 AttributeDescription *password = slap_schema.si_ad_userPassword;
45 Debug( LDAP_DEBUG_ARGS,
46 "==> " LDAP_XSTRING(bdb_bind) ": dn: %s\n",
47 op->o_req_dn.bv_val, 0, 0);
49 /* allow noauth binds */
50 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
51 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
52 /* front end will send result */
56 rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
61 rs->sr_text = "internal error";
62 send_ldap_result( op, rs );
67 /* get entry with reader lock */
68 rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1,
76 send_ldap_error( op, rs, LDAP_BUSY, "ldap_server_busy" );
77 LOCK_ID_FREE(bdb->bi_dbenv, locker);
79 case DB_LOCK_DEADLOCK:
80 case DB_LOCK_NOTGRANTED:
83 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
84 LOCK_ID_FREE(bdb->bi_dbenv, locker);
89 if ( rs->sr_err == DB_NOTFOUND ) {
91 bdb_cache_return_entry_r( bdb, e, &lock );
95 rs->sr_err = LDAP_INVALID_CREDENTIALS;
96 send_ldap_result( op, rs );
98 LOCK_ID_FREE(bdb->bi_dbenv, locker);
103 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
105 /* check for deleted */
106 if ( is_entry_subentry( e ) ) {
107 /* entry is an subentry, don't allow bind */
108 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
110 rs->sr_err = LDAP_INVALID_CREDENTIALS;
114 if ( is_entry_alias( e ) ) {
115 /* entry is an alias, don't allow bind */
116 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
117 rs->sr_err = LDAP_INVALID_CREDENTIALS;
121 if ( is_entry_referral( e ) ) {
122 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
124 rs->sr_err = LDAP_INVALID_CREDENTIALS;
128 switch ( op->oq_bind.rb_method ) {
129 case LDAP_AUTH_SIMPLE:
130 a = attr_find( e->e_attrs, password );
132 rs->sr_err = LDAP_INVALID_CREDENTIALS;
136 if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
137 &rs->sr_text ) != 0 )
139 /* failure; stop front end from sending result */
140 rs->sr_err = LDAP_INVALID_CREDENTIALS;
147 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
148 case LDAP_AUTH_KRBV41:
149 if ( krbv4_ldap_auth( op->o_bd, &op->oq_bind.rb_cred, &ad )
152 rs->sr_err = LDAP_INVALID_CREDENTIALS,
156 rs->sr_err = access_allowed( op, e,
157 krbattr, NULL, ACL_AUTH, NULL );
158 if ( ! rs->sr_err ) {
159 rs->sr_err = LDAP_INSUFFICIENT_ACCESS,
163 krbval.bv_len = sprintf( krbname, "%s%s%s@%s", ad.pname,
164 *ad.pinst ? "." : "", ad.pinst, ad.prealm );
166 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
168 * no krbname values present: check against DN
170 if ( strcasecmp( op->o_req_dn.bv_val, krbname ) == 0 ) {
174 rs->sr_err = LDAP_INAPPROPRIATE_AUTH,
177 } else { /* look for krbname match */
178 krbval.bv_val = krbname;
180 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
181 rs->sr_err = LDAP_INVALID_CREDENTIALS;
190 assert( 0 ); /* should not be unreachable */
191 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
192 rs->sr_text = "authentication method not supported";
196 /* free entry and reader lock */
198 bdb_cache_return_entry_r( bdb, e, &lock );
201 LOCK_ID_FREE(bdb->bi_dbenv, locker);
204 send_ldap_result( op, rs );
206 ber_bvarray_free( rs->sr_ref );
210 /* front end will send result on success (rs->sr_err==0) */