2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
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>.
17 * This work was initially developed by Dmitry Kovalev for inclusion
18 * by OpenLDAP Software.
26 #include <sys/types.h>
34 backsql_bind( Operation *op, SlapReply *rs )
36 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
37 backsql_entryID user_id;
39 AttributeDescription *password = slap_schema.si_ad_userPassword;
42 backsql_srch_info bsi;
43 AttributeName anlist[2];
46 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
48 if ( be_isroot_pw( op ) ) {
49 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
50 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
55 ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
57 if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
58 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
59 rs->sr_text = "authentication method not supported";
60 send_ldap_result( op, rs );
65 * method = LDAP_AUTH_SIMPLE
67 rs->sr_err = backsql_get_db_conn( op, &dbh );
69 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
70 "could not get connection handle - exiting\n",
73 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
74 ? "SQL-backend error" : NULL;
75 send_ldap_result( op, rs );
79 rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
80 if ( rc != LDAP_SUCCESS ) {
81 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
82 "could not retrieve bind dn id - no such entry\n",
84 rs->sr_err = LDAP_INVALID_CREDENTIALS;
85 send_ldap_result( op, rs );
89 anlist[0].an_name = password->ad_cname;
90 anlist[0].an_desc = password;
91 anlist[1].an_name.bv_val = NULL;
92 backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
93 -1, -1, -1, NULL, dbh, op, anlist );
94 e = backsql_id2entry( &bsi, &user_entry, &user_id );
96 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
97 "error in backsql_id2entry() - auth failed\n",
99 rs->sr_err = LDAP_OTHER;
100 send_ldap_result( op, rs );
104 if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
105 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
106 send_ldap_result( op, rs );
110 if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
111 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
112 send_ldap_result( op, rs );
116 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
117 rs->sr_err = LDAP_INVALID_CREDENTIALS;
118 send_ldap_result( op, rs );
122 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
126 #endif /* SLAPD_SQL */