2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 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.
26 #include <sys/types.h>
29 #include "proto-sql.h"
32 backsql_compare( Operation *op, SlapReply *rs )
34 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
35 backsql_entryID user_id = BACKSQL_ENTRYID_INIT;
37 Entry *e = NULL, user_entry;
39 backsql_srch_info bsi;
41 AttributeName anlist[2];
44 user_entry.e_name.bv_val = NULL;
45 user_entry.e_name.bv_len = 0;
46 user_entry.e_nname.bv_val = NULL;
47 user_entry.e_nname.bv_len = 0;
48 user_entry.e_attrs = NULL;
50 Debug( LDAP_DEBUG_TRACE, "==>backsql_compare()\n", 0, 0, 0 );
52 rs->sr_err = backsql_get_db_conn( op, &dbh );
54 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
55 "could not get connection handle - exiting\n",
58 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
59 ? "SQL-backend error" : NULL;
64 if ( backsql_api_dn2odbc( op, rs, &dn ) ) {
65 Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
66 "backsql_api_dn2odbc failed\n",
68 rs->sr_err = LDAP_OTHER;
69 rs->sr_text = "SQL-backend error";
73 rc = backsql_dn2id( bi, &user_id, dbh, &dn );
74 if ( rc != LDAP_SUCCESS ) {
75 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
76 "could not retrieve compare dn id - no such entry\n",
78 rs->sr_err = LDAP_NO_SUCH_OBJECT;
82 memset( &anlist[0], 0, 2 * sizeof( AttributeName ) );
83 anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
84 anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
87 * Try to get attr as dynamic operational
89 if ( is_at_operational( op->oq_compare.rs_ava->aa_desc->ad_type ) ) {
90 SlapReply nrs = { 0 };
92 user_entry.e_attrs = NULL;
93 user_entry.e_name = op->o_req_dn;
94 user_entry.e_nname = op->o_req_ndn;
96 nrs.sr_attrs = anlist;
97 nrs.sr_entry = &user_entry;
98 rs->sr_err = backsql_operational( op, &nrs, 0, &user_entry.e_attrs );
100 if ( rs->sr_err != LDAP_SUCCESS ) {
105 backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE,
106 -1, -1, -1, NULL, dbh, op, rs, anlist );
107 bsi.bsi_e = &user_entry;
108 rc = backsql_id2entry( &bsi, &user_id );
109 if ( rc != LDAP_SUCCESS ) {
110 Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
111 "error %d in backsql_id2entry() "
112 "- compare failed\n", rc, 0, 0 );
119 if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
120 &op->oq_compare.rs_ava->aa_value,
121 ACL_COMPARE, NULL ) ) {
122 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
126 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
127 for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
129 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
131 rs->sr_err = LDAP_COMPARE_FALSE;
132 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
133 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
134 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
136 &op->oq_compare.rs_ava->aa_value,
137 op->o_tmpmemctx ) == 0 )
139 rs->sr_err = LDAP_COMPARE_TRUE;
145 send_ldap_result( op, rs );
147 if ( dn.bv_val != op->o_req_dn.bv_val ) {
148 ch_free( dn.bv_val );
155 Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
156 switch ( rs->sr_err ) {
157 case LDAP_COMPARE_TRUE:
158 case LDAP_COMPARE_FALSE:
166 #endif /* SLAPD_SQL */