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
|
|
|
*
|
2019-01-15 02:46:16 +08:00
|
|
|
* Copyright 1999-2019 The OpenLDAP Foundation.
|
2003-12-08 03:19:18 +08:00
|
|
|
* Portions Copyright 1999 Dmitry Kovalev.
|
2005-01-03 18:51:59 +08:00
|
|
|
* Portions Copyright 2002 Pierangelo Masarati.
|
2003-12-08 03:19:18 +08:00
|
|
|
* 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
|
2005-01-03 18:51:59 +08:00
|
|
|
* by OpenLDAP Software. Additional significant contributors include
|
|
|
|
* Pierangelo Masarati.
|
2000-03-17 03:08:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#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
|
|
|
{
|
2005-01-02 00:21:55 +08:00
|
|
|
SQLHDBC dbh = SQL_NULL_HDBC;
|
2005-01-16 02:43:34 +08:00
|
|
|
Entry e = { 0 };
|
2002-08-14 01:12:27 +08:00
|
|
|
Attribute *a;
|
2005-01-18 03:32:28 +08:00
|
|
|
backsql_srch_info bsi = { 0 };
|
2003-04-16 07:11:31 +08:00
|
|
|
AttributeName anlist[2];
|
2002-08-17 00:45:24 +08:00
|
|
|
int rc;
|
2000-10-31 04:36:29 +08:00
|
|
|
|
2019-02-16 00:49:52 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n" );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2007-08-16 17:38:15 +08:00
|
|
|
switch ( be_rootdn_bind( op, rs ) ) {
|
|
|
|
case SLAP_CB_CONTINUE:
|
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2007-08-16 17:38:15 +08:00
|
|
|
default:
|
|
|
|
/* in case of success, front end will send result;
|
|
|
|
* otherwise, be_rootdn_bind() did */
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_bind(%d)\n",
|
2019-02-16 00:49:52 +08:00
|
|
|
rs->sr_err );
|
2005-01-16 02:43:34 +08:00
|
|
|
return rs->sr_err;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_err = backsql_get_db_conn( op, &dbh );
|
2007-08-20 08:27:47 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
|
2019-02-16 00:49:52 +08:00
|
|
|
"could not get connection handle - exiting\n" );
|
2003-04-03 06:58:02 +08:00
|
|
|
|
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
2005-01-16 02:43:34 +08:00
|
|
|
goto error_return;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2005-01-08 17:59:16 +08:00
|
|
|
anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname;
|
|
|
|
anlist[0].an_desc = slap_schema.si_ad_userPassword;
|
2004-09-29 07:27:39 +08:00
|
|
|
anlist[1].an_name.bv_val = NULL;
|
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
bsi.bsi_e = &e;
|
2004-12-02 08:33:36 +08:00
|
|
|
rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
|
2005-01-02 00:21:55 +08:00
|
|
|
(time_t)(-1), NULL, dbh, op, rs, anlist,
|
2005-01-16 02:43:34 +08:00
|
|
|
BACKSQL_ISF_GET_ENTRY );
|
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(): "
|
2019-02-16 00:49:52 +08:00
|
|
|
"could not retrieve bindDN ID - no such entry\n" );
|
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;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
a = attr_find( e.e_attrs, slap_schema.si_ad_userPassword );
|
2004-08-20 20:06:03 +08:00
|
|
|
if ( a == NULL ) {
|
2004-09-12 04:01:03 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
if ( slap_passwd_check( op, &e, a, &op->oq_bind.rb_cred,
|
2005-01-07 21:50:38 +08:00
|
|
|
&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:;
|
2005-01-18 03:32:28 +08:00
|
|
|
if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
|
2007-08-20 08:27:47 +08:00
|
|
|
(void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
|
2005-01-18 03:32:28 +08:00
|
|
|
}
|
2004-09-29 07:27:39 +08:00
|
|
|
|
2005-01-18 03:32:28 +08:00
|
|
|
if ( !BER_BVISNULL( &e.e_nname ) ) {
|
2005-06-02 03:35:13 +08:00
|
|
|
backsql_entry_clean( op, &e );
|
2005-01-08 17:59:16 +08:00
|
|
|
}
|
|
|
|
|
2005-01-14 08:39:24 +08:00
|
|
|
if ( bsi.bsi_attrs != NULL ) {
|
|
|
|
op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
|
|
|
|
}
|
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2003-04-03 06:58:02 +08:00
|
|
|
send_ldap_result( op, rs );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2004-04-10 17:33:55 +08:00
|
|
|
|
2019-02-16 00:49:52 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,"<==backsql_bind()\n" );
|
2005-01-08 17:59:16 +08:00
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
return rs->sr_err;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
|