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>
33 backsql_info *bi = (backsql_info*)be->be_private;
34 backsql_entryID user_id;
36 AttributeDescription *password = slap_schema.si_ad_userPassword;
39 backsql_srch_info bsi;
42 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
44 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
45 ber_dupbv( edn, be_root_dn( be ) );
46 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
51 ber_dupbv( edn, ndn );
53 if ( method != LDAP_AUTH_SIMPLE ) {
54 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
55 NULL, "authentication method not supported",
61 * method = LDAP_AUTH_SIMPLE
63 rc = backsql_get_db_conn( be, conn, &dbh );
65 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
66 "could not get connection handle - exiting\n",
68 send_ldap_result( conn, op, rc, "",
69 rc == LDAP_OTHER ? "SQL-backend error" : "",
74 if ( backsql_dn2id( bi, &user_id, dbh, ndn ) != LDAP_SUCCESS ) {
75 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
76 "could not retrieve bind dn id - no such entry\n",
78 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
79 NULL, NULL, NULL, NULL );
83 backsql_init_search( &bsi, bi, ndn, LDAP_SCOPE_BASE, -1, -1, -1,
84 NULL, dbh, be, conn, op, NULL );
85 e = backsql_id2entry( &bsi, &user_entry, &user_id );
87 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
88 "error in backsql_id2entry() - auth failed\n",
90 send_ldap_result( conn, op, LDAP_OTHER,
91 NULL, NULL, NULL, NULL );
95 if ( ! access_allowed( be, conn, op, e, password, NULL,
97 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
98 NULL, NULL, NULL, NULL );
102 if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
103 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
104 NULL, NULL, NULL, NULL );
108 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
109 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
110 NULL, NULL, NULL, NULL );
114 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
124 Debug( LDAP_DEBUG_TRACE, "==>backsql_unbind()\n", 0, 0, 0 );
125 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, 0 );
126 Debug( LDAP_DEBUG_TRACE, "<==backsql_unbind()\n", 0, 0, 0 );
130 #endif /* SLAPD_SQL */