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.
24 #include <sys/types.h>
27 #include "proto-sql.h"
30 backsql_bind( Operation *op, SlapReply *rs )
33 AttributeDescription *password = slap_schema.si_ad_userPassword;
36 backsql_srch_info bsi;
37 AttributeName anlist[2];
40 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
42 if ( be_isroot_pw( op ) ) {
43 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
44 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
49 ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
51 if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
52 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
53 rs->sr_text = "authentication method not supported";
54 send_ldap_result( op, rs );
59 * method = LDAP_AUTH_SIMPLE
61 rs->sr_err = backsql_get_db_conn( op, &dbh );
63 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
64 "could not get connection handle - exiting\n",
67 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
68 ? "SQL-backend error" : NULL;
69 send_ldap_result( op, rs );
73 anlist[0].an_name = password->ad_cname;
74 anlist[0].an_desc = password;
75 anlist[1].an_name.bv_val = NULL;
77 rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
78 -1, -1, -1, NULL, dbh, op, rs, anlist,
79 ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
80 if ( rc != LDAP_SUCCESS ) {
81 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
82 "could not retrieve bindDN ID - no such entry\n",
84 rs->sr_err = LDAP_INVALID_CREDENTIALS;
85 send_ldap_result( op, rs );
89 bsi.bsi_e = &user_entry;
90 rc = backsql_id2entry( &bsi, &bsi.bsi_base_id );
91 if ( rc != LDAP_SUCCESS ) {
92 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
93 "error %d in backsql_id2entry() "
94 "- auth failed\n", rc, 0, 0 );
95 rs->sr_err = LDAP_INVALID_CREDENTIALS;
100 if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
102 rs->sr_err = LDAP_INVALID_CREDENTIALS;
104 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
109 a = attr_find( e->e_attrs, password );
112 rs->sr_err = LDAP_INVALID_CREDENTIALS;
114 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
119 if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
120 rs->sr_err = LDAP_INVALID_CREDENTIALS;
125 if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
126 (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
130 send_ldap_result( op, rs );
134 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);