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;
41 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
43 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
44 ber_dupbv( edn, be_root_dn( be ) );
45 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
50 ber_dupbv( edn, ndn );
52 if ( method != LDAP_AUTH_SIMPLE ) {
53 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
54 NULL, "authentication method not supported",
60 * method = LDAP_AUTH_SIMPLE
62 dbh = backsql_get_db_conn( be, conn );
64 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
65 "could not get connection handle - exiting\n",
67 send_ldap_result( conn, op, LDAP_OTHER, "",
68 "SQL-backend error", NULL, NULL );
72 if ( backsql_dn2id( bi, &user_id, dbh, ndn ) != LDAP_SUCCESS ) {
73 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
74 "could not retrieve bind dn id - no such entry\n",
76 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
77 NULL, NULL, NULL, NULL );
81 backsql_init_search( &bsi, bi, ndn, LDAP_SCOPE_BASE, -1, -1, -1,
82 NULL, dbh, be, conn, op, NULL );
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 send_ldap_result( conn, op, LDAP_OTHER,
89 NULL, NULL, NULL, NULL );
93 if ( ! access_allowed( be, conn, op, e, password, NULL,
95 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
96 NULL, NULL, NULL, NULL );
100 if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
101 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
102 NULL, NULL, NULL, NULL );
106 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
107 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
108 NULL, NULL, NULL, NULL );
112 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
122 Debug( LDAP_DEBUG_TRACE, "==>backsql_unbind()\n", 0, 0, 0 );
123 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, 0 );
124 Debug( LDAP_DEBUG_TRACE, "<==backsql_unbind()\n", 0, 0, 0 );
128 #endif /* SLAPD_SQL */