2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Dmitry Kovalev for inclusion
18 * by OpenLDAP Software.
24 #include <sys/types.h>
27 #include "proto-sql.h"
30 backsql_compare( Operation *op, SlapReply *rs )
33 Entry *e = NULL, user_entry;
35 backsql_srch_info bsi;
37 AttributeName anlist[2];
39 user_entry.e_name.bv_val = NULL;
40 user_entry.e_name.bv_len = 0;
41 user_entry.e_nname.bv_val = NULL;
42 user_entry.e_nname.bv_len = 0;
43 user_entry.e_attrs = NULL;
45 Debug( LDAP_DEBUG_TRACE, "==>backsql_compare()\n", 0, 0, 0 );
47 rs->sr_err = backsql_get_db_conn( op, &dbh );
49 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
50 "could not get connection handle - exiting\n",
53 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
54 ? "SQL-backend error" : NULL;
58 memset( &anlist[0], 0, 2 * sizeof( AttributeName ) );
59 anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
60 anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
63 * Try to get attr as dynamic operational
65 if ( is_at_operational( op->oq_compare.rs_ava->aa_desc->ad_type ) ) {
66 SlapReply nrs = { 0 };
68 user_entry.e_attrs = NULL;
69 user_entry.e_name = op->o_req_dn;
70 user_entry.e_nname = op->o_req_ndn;
72 nrs.sr_attrs = anlist;
73 nrs.sr_entry = &user_entry;
74 nrs.sr_attr_flags = SLAP_OPATTRS_NO;
75 nrs.sr_operational_attrs = NULL;
77 rs->sr_err = backsql_operational( op, &nrs );
78 if ( rs->sr_err != LDAP_SUCCESS ) {
82 user_entry.e_attrs = nrs.sr_operational_attrs;
85 rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
86 -1, -1, -1, NULL, dbh, op, rs, anlist,
87 ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
88 if ( rc != LDAP_SUCCESS ) {
89 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
90 "could not retrieve compareDN ID - no such entry\n",
92 rs->sr_err = LDAP_NO_SUCH_OBJECT;
96 bsi.bsi_e = &user_entry;
97 rc = backsql_id2entry( &bsi, &bsi.bsi_base_id );
98 if ( rc != LDAP_SUCCESS ) {
99 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
100 "error %d in backsql_id2entry() "
101 "- compare failed\n", rc, 0, 0 );
108 if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
109 &op->oq_compare.rs_ava->aa_value,
110 ACL_COMPARE, NULL ) ) {
111 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
115 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
116 for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
118 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
120 rs->sr_err = LDAP_COMPARE_FALSE;
121 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
122 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
123 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
125 &op->oq_compare.rs_ava->aa_value,
126 op->o_tmpmemctx ) == 0 )
128 rs->sr_err = LDAP_COMPARE_TRUE;
134 send_ldap_result( op, rs );
136 if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
137 (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
144 Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
145 switch ( rs->sr_err ) {
146 case LDAP_COMPARE_TRUE:
147 case LDAP_COMPARE_FALSE: