2003-12-08 03:19:18 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
2000-03-17 03:34:46 +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:34:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
2000-03-19 14:18:27 +08:00
|
|
|
#ifdef SLAPD_SQL
|
|
|
|
|
2000-03-17 03:34:46 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2004-01-20 06:13:15 +08:00
|
|
|
|
2000-03-17 03:34:46 +08:00
|
|
|
#include "slap.h"
|
2004-01-20 06:13:15 +08:00
|
|
|
#include "proto-sql.h"
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
2003-04-03 06:58:02 +08:00
|
|
|
backsql_compare( Operation *op, SlapReply *rs )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2003-04-03 06:58:02 +08:00
|
|
|
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
|
2004-04-10 17:33:55 +08:00
|
|
|
backsql_entryID user_id = BACKSQL_ENTRYID_INIT;
|
2003-04-03 06:58:02 +08:00
|
|
|
SQLHDBC dbh;
|
2003-04-17 04:55:42 +08:00
|
|
|
Entry *e = NULL, user_entry;
|
|
|
|
Attribute *a = NULL, *a_op = NULL;
|
2003-04-03 06:58:02 +08:00
|
|
|
backsql_srch_info bsi;
|
|
|
|
int rc;
|
|
|
|
AttributeName anlist[2];
|
2004-04-10 17:33:55 +08:00
|
|
|
struct berval dn;
|
2003-04-17 04:55:42 +08:00
|
|
|
|
|
|
|
user_entry.e_name.bv_val = NULL;
|
|
|
|
user_entry.e_name.bv_len = 0;
|
|
|
|
user_entry.e_nname.bv_val = NULL;
|
|
|
|
user_entry.e_nname.bv_len = 0;
|
|
|
|
user_entry.e_attrs = NULL;
|
2003-04-03 06:58:02 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_compare()\n", 0, 0, 0 );
|
|
|
|
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_err = backsql_get_db_conn( op, &dbh );
|
2003-04-03 06:58:02 +08:00
|
|
|
if (!dbh) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
2002-08-14 01:12:27 +08:00
|
|
|
0, 0, 0 );
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
goto return_results;
|
|
|
|
}
|
2000-03-19 14:18:27 +08:00
|
|
|
|
2004-04-10 17:33:55 +08:00
|
|
|
dn = op->o_req_dn;
|
|
|
|
if ( backsql_api_dn2odbc( op, rs, &dn ) ) {
|
|
|
|
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 return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = backsql_dn2id( bi, &user_id, dbh, &dn );
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
|
2003-04-17 04:55:42 +08:00
|
|
|
"could not retrieve compare dn id - no such entry\n",
|
2003-04-03 06:58:02 +08:00
|
|
|
0, 0, 0 );
|
2003-04-17 04:55:42 +08:00
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
2003-04-03 06:58:02 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
|
|
|
|
anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
|
|
|
|
anlist[1].an_name.bv_val = NULL;
|
2003-04-17 04:55:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to get attr as dynamic operational
|
|
|
|
*/
|
|
|
|
if ( is_at_operational( op->oq_compare.rs_ava->aa_desc->ad_type ) ) {
|
|
|
|
AttributeName *an_old;
|
|
|
|
Entry *e_old;
|
|
|
|
|
|
|
|
user_entry.e_attrs = NULL;
|
|
|
|
user_entry.e_name = op->o_req_dn;
|
|
|
|
user_entry.e_nname = op->o_req_ndn;
|
|
|
|
|
|
|
|
an_old = rs->sr_attrs;
|
|
|
|
e_old = rs->sr_entry;
|
|
|
|
|
|
|
|
rs->sr_attrs = anlist;
|
|
|
|
rs->sr_entry = &user_entry;
|
|
|
|
rs->sr_err = backsql_operational( op, rs, 0, &a_op );
|
|
|
|
rs->sr_attrs = an_old;
|
|
|
|
rs->sr_entry = e_old;
|
|
|
|
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* attr was dynamic operational
|
|
|
|
*/
|
|
|
|
if ( a_op != NULL ) {
|
|
|
|
user_entry.e_attrs = a_op;
|
|
|
|
e = &user_entry;
|
|
|
|
|
|
|
|
} else {
|
2004-04-10 17:33:55 +08:00
|
|
|
backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE,
|
|
|
|
-1, -1, -1, NULL, dbh, op, rs, anlist );
|
2003-04-17 04:55:42 +08:00
|
|
|
e = backsql_id2entry( &bsi, &user_entry, &user_id );
|
|
|
|
if ( e == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
|
|
|
|
"error in backsql_id2entry() "
|
|
|
|
"- compare failed\n", 0, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
goto return_results;
|
|
|
|
}
|
2003-04-03 06:58:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
|
|
|
|
&op->oq_compare.rs_ava->aa_value,
|
|
|
|
ACL_COMPARE, NULL ) ) {
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
|
|
|
|
a != NULL;
|
|
|
|
a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_COMPARE_FALSE;
|
|
|
|
if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
|
|
|
|
SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
|
|
|
|
SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
|
2003-04-12 07:23:03 +08:00
|
|
|
a->a_nvals,
|
|
|
|
&op->oq_compare.rs_ava->aa_value,
|
|
|
|
op->o_tmpmemctx ) == 0 )
|
2003-04-03 06:58:02 +08:00
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_COMPARE_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return_results:;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
|
2004-04-10 17:33:55 +08:00
|
|
|
if ( dn.bv_val != op->o_req_dn.bv_val ) {
|
|
|
|
ch_free( dn.bv_val );
|
|
|
|
}
|
|
|
|
|
2003-04-17 04:55:42 +08:00
|
|
|
if ( e != NULL ) {
|
|
|
|
if ( e->e_name.bv_val != NULL ) {
|
|
|
|
free( e->e_name.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( e->e_nname.bv_val != NULL ) {
|
|
|
|
free( e->e_nname.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( e->e_attrs != NULL ) {
|
|
|
|
attrs_free( e->e_attrs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
|
|
|
|
switch ( rs->sr_err ) {
|
|
|
|
case LDAP_COMPARE_TRUE:
|
|
|
|
case LDAP_COMPARE_FALSE:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-27 00:03:32 +08:00
|
|
|
#endif /* SLAPD_SQL */
|
2002-08-14 01:12:27 +08:00
|
|
|
|