2 * Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
4 * Redistribution and use in source and binary forms are permitted only
5 * as authorized by the OpenLDAP Public License. A copy of this
6 * license is available at http://www.OpenLDAP.org/license.html or
7 * in file LICENSE in the top-level directory of the distribution.
15 #include <sys/types.h>
23 backsql_bind( Operation *op, SlapReply *rs )
25 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
26 backsql_entryID user_id;
28 AttributeDescription *password = slap_schema.si_ad_userPassword;
31 backsql_srch_info bsi;
34 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
36 if ( be_isroot_pw( op ) ) {
37 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
38 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
43 ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
45 if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
46 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
47 rs->sr_text = "authentication method not supported";
48 send_ldap_result( op, rs );
53 * method = LDAP_AUTH_SIMPLE
55 rs->sr_err = backsql_get_db_conn( op, &dbh );
57 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
58 "could not get connection handle - exiting\n",
61 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
62 ? "SQL-backend error" : NULL;
63 send_ldap_result( op, rs );
67 rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
68 if ( rc != LDAP_SUCCESS ) {
69 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
70 "could not retrieve bind dn id - no such entry\n",
72 rs->sr_err = LDAP_INVALID_CREDENTIALS;
73 send_ldap_result( op, rs );
77 backsql_init_search( &bsi, bi, &op->o_req_ndn, LDAP_SCOPE_BASE,
78 -1, -1, -1, NULL, dbh, op->o_bd, op->o_conn, op, NULL );
79 e = backsql_id2entry( &bsi, &user_entry, &user_id );
81 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
82 "error in backsql_id2entry() - auth failed\n",
84 rs->sr_err = LDAP_OTHER;
85 send_ldap_result( op, rs );
89 if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
90 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
91 send_ldap_result( op, rs );
95 if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
96 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
97 send_ldap_result( op, rs );
101 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred ) != 0 ) {
102 rs->sr_err = LDAP_INVALID_CREDENTIALS;
103 send_ldap_result( op, rs );
107 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
111 #endif /* SLAPD_SQL */