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;
32 AttributeName anlist[2];
35 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
37 if ( be_isroot_pw( op ) ) {
38 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
39 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
44 ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
46 if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
47 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
48 rs->sr_text = "authentication method not supported";
49 send_ldap_result( op, rs );
54 * method = LDAP_AUTH_SIMPLE
56 rs->sr_err = backsql_get_db_conn( op, &dbh );
58 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
59 "could not get connection handle - exiting\n",
62 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
63 ? "SQL-backend error" : NULL;
64 send_ldap_result( op, rs );
68 rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
69 if ( rc != LDAP_SUCCESS ) {
70 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
71 "could not retrieve bind dn id - no such entry\n",
73 rs->sr_err = LDAP_INVALID_CREDENTIALS;
74 send_ldap_result( op, rs );
78 anlist[0].an_name = password->ad_cname;
79 anlist[0].an_desc = password;
80 anlist[1].an_name.bv_val = NULL;
81 backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
82 -1, -1, -1, NULL, dbh, op, anlist );
83 e = backsql_id2entry( &bsi, &user_entry, &user_id );
85 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
86 "error in backsql_id2entry() - auth failed\n",
88 rs->sr_err = LDAP_OTHER;
89 send_ldap_result( op, rs );
93 if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
94 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
95 send_ldap_result( op, rs );
99 if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
100 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
101 send_ldap_result( op, rs );
105 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
106 rs->sr_err = LDAP_INVALID_CREDENTIALS;
107 send_ldap_result( op, rs );
111 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
115 #endif /* SLAPD_SQL */