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
|
|
|
*
|
2008-01-08 08:19:56 +08:00
|
|
|
* Copyright 1999-2008 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:34:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#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
|
|
|
{
|
2005-01-02 00:21:55 +08:00
|
|
|
SQLHDBC dbh = SQL_NULL_HDBC;
|
2005-01-16 02:43:34 +08:00
|
|
|
Entry e = { 0 };
|
2004-07-19 05:44:29 +08:00
|
|
|
Attribute *a = NULL;
|
2005-01-18 03:32:28 +08:00
|
|
|
backsql_srch_info bsi = { 0 };
|
2003-04-03 06:58:02 +08:00
|
|
|
int rc;
|
2005-01-20 08:17:52 +08:00
|
|
|
int manageDSAit = get_manageDSAit( op );
|
|
|
|
AttributeName anlist[2];
|
2003-04-17 04:55:42 +08:00
|
|
|
|
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 );
|
2007-08-20 08:27:47 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2003-04-03 06:58:02 +08:00
|
|
|
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
|
|
|
|
2005-01-16 02:43:34 +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;
|
|
|
|
BER_BVZERO( &anlist[ 1 ].an_name );
|
2003-04-17 04:55:42 +08:00
|
|
|
|
2005-01-14 20:01:03 +08:00
|
|
|
/*
|
2005-01-16 02:43:34 +08:00
|
|
|
* Get the entry
|
2005-01-14 20:01:03 +08:00
|
|
|
*/
|
2005-01-16 02:43:34 +08:00
|
|
|
bsi.bsi_e = &e;
|
2005-08-08 04:43:07 +08:00
|
|
|
rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
|
2005-01-20 08:17:52 +08:00
|
|
|
(time_t)(-1), NULL, dbh, op, rs, anlist,
|
2005-01-16 02:43:34 +08:00
|
|
|
( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) );
|
2005-01-20 08:17:52 +08:00
|
|
|
switch ( rc ) {
|
|
|
|
case LDAP_SUCCESS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_REFERRAL:
|
|
|
|
if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
|
|
|
|
dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname ) )
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
|
|
|
if ( rs->sr_ref ) {
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthru */
|
|
|
|
|
|
|
|
default:
|
2005-01-12 08:28:37 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
|
|
|
|
"could not retrieve compareDN ID - no such entry\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2005-01-17 07:12:36 +08:00
|
|
|
if ( get_assert( op ) &&
|
|
|
|
( test_filter( op, &e, get_assertion( op ) )
|
|
|
|
!= LDAP_COMPARE_TRUE ) )
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_ASSERTION_FAILED;
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-04-17 04:55:42 +08:00
|
|
|
if ( is_at_operational( op->oq_compare.rs_ava->aa_desc->ad_type ) ) {
|
2004-07-19 05:44:29 +08:00
|
|
|
SlapReply nrs = { 0 };
|
2005-01-20 08:17:52 +08:00
|
|
|
Attribute **ap;
|
2003-04-17 04:55:42 +08:00
|
|
|
|
2005-01-20 08:17:52 +08:00
|
|
|
for ( ap = &e.e_attrs; *ap; ap = &(*ap)->a_next )
|
|
|
|
;
|
2003-04-17 04:55:42 +08:00
|
|
|
|
2004-07-19 05:44:29 +08:00
|
|
|
nrs.sr_attrs = anlist;
|
2005-01-16 02:43:34 +08:00
|
|
|
nrs.sr_entry = &e;
|
2004-07-26 07:16:40 +08:00
|
|
|
nrs.sr_attr_flags = SLAP_OPATTRS_NO;
|
2004-07-19 05:44:29 +08:00
|
|
|
nrs.sr_operational_attrs = NULL;
|
2003-04-17 04:55:42 +08:00
|
|
|
|
2004-07-19 05:44:29 +08:00
|
|
|
rs->sr_err = backsql_operational( op, &nrs );
|
2003-04-17 04:55:42 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2005-01-20 08:17:52 +08:00
|
|
|
*ap = nrs.sr_operational_attrs;
|
2003-04-03 06:58:02 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
if ( ! access_allowed( op, &e, op->oq_compare.rs_ava->aa_desc,
|
2003-04-03 06:58:02 +08:00
|
|
|
&op->oq_compare.rs_ava->aa_value,
|
2005-01-16 02:43:34 +08:00
|
|
|
ACL_COMPARE, NULL ) )
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
2003-04-03 06:58:02 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
|
2005-01-16 02:43:34 +08:00
|
|
|
for ( a = attrs_find( e.e_attrs, op->oq_compare.rs_ava->aa_desc );
|
2003-04-03 06:58:02 +08:00
|
|
|
a != NULL;
|
2005-01-12 08:28:37 +08:00
|
|
|
a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ) )
|
2003-04-03 06:58:02 +08:00
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_COMPARE_FALSE;
|
2007-09-24 13:02:31 +08:00
|
|
|
if ( attr_valfind( a,
|
2003-04-03 06:58:02 +08:00
|
|
|
SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
|
|
|
|
SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
|
2007-09-24 13:02:31 +08:00
|
|
|
&op->oq_compare.rs_ava->aa_value, NULL,
|
2003-04-12 07:23:03 +08:00
|
|
|
op->o_tmpmemctx ) == 0 )
|
2003-04-03 06:58:02 +08:00
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_COMPARE_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return_results:;
|
2005-01-16 02:43:34 +08:00
|
|
|
switch ( rs->sr_err ) {
|
|
|
|
case LDAP_COMPARE_TRUE:
|
|
|
|
case LDAP_COMPARE_FALSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if ( !BER_BVISNULL( &e.e_nname ) &&
|
|
|
|
! access_allowed( op, &e,
|
|
|
|
slap_schema.si_ad_entry, NULL,
|
|
|
|
ACL_DISCLOSE, NULL ) )
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
send_ldap_result( op, rs );
|
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
if ( rs->sr_matched ) {
|
|
|
|
rs->sr_matched = NULL;
|
2004-09-29 07:27:39 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 02:43:34 +08:00
|
|
|
if ( rs->sr_ref ) {
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2005-01-16 02:43:34 +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 );
|
2003-04-17 04:55:42 +08:00
|
|
|
}
|
|
|
|
|
2005-01-14 08:39:24 +08:00
|
|
|
if ( bsi.bsi_attrs != NULL ) {
|
|
|
|
op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
|
|
|
|
}
|
|
|
|
|
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:
|
2005-01-16 02:43:34 +08:00
|
|
|
return LDAP_SUCCESS;
|
2003-04-03 06:58:02 +08:00
|
|
|
|
|
|
|
default:
|
2005-01-16 02:43:34 +08:00
|
|
|
return rs->sr_err;
|
2003-04-03 06:58:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|