2003-12-08 03:19:18 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
2000-03-17 03:08:22 +08:00
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1999-2004 The OpenLDAP Foundation.
|
2003-12-08 03:19:18 +08:00
|
|
|
* Portions Copyright 1999 Dmitry Kovalev.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Dmitry Kovalev for inclusion
|
|
|
|
* by OpenLDAP Software.
|
2000-03-17 03:08:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
2000-03-19 14:18:27 +08:00
|
|
|
#ifdef SLAPD_SQL
|
|
|
|
|
2000-03-17 03:08:22 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2004-01-20 06:13:15 +08:00
|
|
|
|
2000-03-17 03:08:22 +08:00
|
|
|
#include "slap.h"
|
2004-01-20 06:13:15 +08:00
|
|
|
#include "proto-sql.h"
|
2000-10-31 04:36:29 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
2003-04-03 06:58:02 +08:00
|
|
|
backsql_bind( Operation *op, SlapReply *rs )
|
2000-03-17 03:08:22 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLHDBC dbh;
|
|
|
|
AttributeDescription *password = slap_schema.si_ad_userPassword;
|
|
|
|
Entry *e, user_entry;
|
|
|
|
Attribute *a;
|
|
|
|
backsql_srch_info bsi;
|
2003-04-16 07:11:31 +08:00
|
|
|
AttributeName anlist[2];
|
2002-08-17 00:45:24 +08:00
|
|
|
int rc;
|
2004-10-04 05:08:54 +08:00
|
|
|
struct berval ndn;
|
2000-10-31 04:36:29 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
|
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( be_isroot_pw( op ) ) {
|
|
|
|
ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n",
|
|
|
|
0, 0, 0 );
|
2003-04-03 06:58:02 +08:00
|
|
|
return 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
|
|
|
|
rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
|
|
|
|
rs->sr_text = "authentication method not supported";
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* method = LDAP_AUTH_SIMPLE
|
|
|
|
*/
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_err = backsql_get_db_conn( op, &dbh );
|
2004-10-04 09:19:53 +08:00
|
|
|
if ( !dbh ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
2003-04-03 06:58:02 +08:00
|
|
|
|
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-10-04 05:08:54 +08:00
|
|
|
ndn = op->o_req_ndn;
|
|
|
|
if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
|
2004-04-10 17:33:55 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
|
|
|
|
"backsql_api_dn2odbc failed\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "SQL-backend error";
|
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
2004-09-29 07:27:39 +08:00
|
|
|
anlist[0].an_name = password->ad_cname;
|
|
|
|
anlist[0].an_desc = password;
|
|
|
|
anlist[1].an_name.bv_val = NULL;
|
|
|
|
|
2004-10-04 05:08:54 +08:00
|
|
|
rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE,
|
2004-09-29 07:27:39 +08:00
|
|
|
-1, -1, -1, NULL, dbh, op, rs, anlist, 1 );
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
|
2004-10-04 05:08:54 +08:00
|
|
|
"could not retrieve bindDN ID - no such entry\n",
|
2002-08-14 01:12:27 +08:00
|
|
|
0, 0, 0 );
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-08-20 20:06:03 +08:00
|
|
|
bsi.bsi_e = &user_entry;
|
2004-09-29 07:27:39 +08:00
|
|
|
rc = backsql_id2entry( &bsi, &bsi.bsi_base_id );
|
2004-08-20 20:06:03 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
|
2004-08-20 20:06:03 +08:00
|
|
|
"error %d in backsql_id2entry() "
|
|
|
|
"- auth failed\n", rc, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2004-04-10 17:33:55 +08:00
|
|
|
goto error_return;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2004-08-20 20:06:03 +08:00
|
|
|
e = &user_entry;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
|
2004-09-12 04:01:03 +08:00
|
|
|
#if 1
|
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
#else
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
2004-09-12 04:01:03 +08:00
|
|
|
#endif
|
2004-04-10 17:33:55 +08:00
|
|
|
goto error_return;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2004-08-20 20:06:03 +08:00
|
|
|
a = attr_find( e->e_attrs, password );
|
|
|
|
if ( a == NULL ) {
|
2004-09-12 04:01:03 +08:00
|
|
|
#if 1
|
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
#else
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
|
2004-09-12 04:01:03 +08:00
|
|
|
#endif
|
2004-04-10 17:33:55 +08:00
|
|
|
goto error_return;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:52:05 +08:00
|
|
|
if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2004-04-10 17:33:55 +08:00
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_return:;
|
2004-10-04 05:08:54 +08:00
|
|
|
if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
|
2004-09-29 07:27:39 +08:00
|
|
|
(void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
|
|
|
|
}
|
|
|
|
|
2004-04-10 17:33:55 +08:00
|
|
|
if ( rs->sr_err ) {
|
2003-04-03 06:58:02 +08:00
|
|
|
send_ldap_result( op, rs );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2004-04-10 17:33:55 +08:00
|
|
|
|
2004-10-04 05:08:54 +08:00
|
|
|
if ( ndn.bv_val != op->o_req_ndn.bv_val ) {
|
|
|
|
ch_free( ndn.bv_val );
|
2004-04-10 17:33:55 +08:00
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
|
|
|
|
return 0;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
#endif /* SLAPD_SQL */
|
2002-08-14 01:12:27 +08:00
|
|
|
|