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>
29 #include "proto-sql.h"
32 backsql_bind( Operation *op, SlapReply *rs )
34 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
35 backsql_entryID user_id;
37 AttributeDescription *password = slap_schema.si_ad_userPassword;
40 backsql_srch_info bsi;
41 AttributeName anlist[2];
44 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
46 if ( be_isroot_pw( op ) ) {
47 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
48 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
53 ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
55 if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
56 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
57 rs->sr_text = "authentication method not supported";
58 send_ldap_result( op, rs );
63 * method = LDAP_AUTH_SIMPLE
65 rs->sr_err = backsql_get_db_conn( op, &dbh );
67 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
68 "could not get connection handle - exiting\n",
71 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
72 ? "SQL-backend error" : NULL;
73 send_ldap_result( op, rs );
77 rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
78 if ( rc != LDAP_SUCCESS ) {
79 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
80 "could not retrieve bind dn id - no such entry\n",
82 rs->sr_err = LDAP_INVALID_CREDENTIALS;
83 send_ldap_result( op, rs );
87 anlist[0].an_name = password->ad_cname;
88 anlist[0].an_desc = password;
89 anlist[1].an_name.bv_val = NULL;
90 backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
91 -1, -1, -1, NULL, dbh, op, anlist );
92 e = backsql_id2entry( &bsi, &user_entry, &user_id );
94 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
95 "error in backsql_id2entry() - auth failed\n",
97 rs->sr_err = LDAP_OTHER;
98 send_ldap_result( op, rs );
102 if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
103 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
104 send_ldap_result( op, rs );
108 if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
109 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
110 send_ldap_result( op, rs );
114 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
115 rs->sr_err = LDAP_INVALID_CREDENTIALS;
116 send_ldap_result( op, rs );
120 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
124 #endif /* SLAPD_SQL */