1 /* compare.c - ldap backend compare function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/string.h>
29 #include <ac/socket.h>
32 #include "back-ldap.h"
39 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
41 struct berval mapped_at = BER_BVNULL, mapped_val = BER_BVNULL;
42 struct berval mdn = BER_BVNULL;
47 LDAPControl **ctrls = NULL;
48 int rc = LDAP_SUCCESS;
50 lc = ldap_back_getconn(op, rs);
51 if (!lc || !ldap_back_dobind( lc, op, rs ) ) {
56 * Rewrite the compare dn, if needed
58 dc.rwmap = &li->rwmap;
67 if ( ldap_back_dn_massage( &dc, &op->o_req_ndn, &mdn ) ) {
68 send_ldap_result( op, rs );
72 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
73 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass ) {
74 ldap_back_map(&li->rwmap.rwm_oc, &op->orc_ava->aa_value,
75 &mapped_val, BACKLDAP_MAP);
76 if (mapped_val.bv_val == NULL || mapped_val.bv_val[0] == '\0') {
79 mapped_at = op->orc_ava->aa_desc->ad_cname;
81 ldap_back_map(&li->rwmap.rwm_at,
82 &op->orc_ava->aa_desc->ad_cname, &mapped_at,
84 if (mapped_at.bv_val == NULL || mapped_at.bv_val[0] == '\0') {
87 if (op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) {
89 dc.ctx = "compareAttrDN";
91 ldap_back_dn_massage( &dc, &op->orc_ava->aa_value, &mapped_val );
92 if (mapped_val.bv_val == NULL || mapped_val.bv_val[0] == '\0') {
93 mapped_val = op->orc_ava->aa_value;
94 } else if (mapped_val.bv_val != op->orc_ava->aa_value.bv_val) {
98 mapped_val = op->orc_ava->aa_value;
103 #ifdef LDAP_BACK_PROXY_AUTHZ
104 rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
105 if ( rc != LDAP_SUCCESS ) {
106 send_ldap_result( op, rs );
110 #endif /* LDAP_BACK_PROXY_AUTHZ */
113 rs->sr_err = ldap_compare_ext( lc->ld, mdn.bv_val,
114 mapped_at.bv_val, &mapped_val,
115 ctrls, NULL, &msgid );
116 rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
117 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
119 if ( ldap_back_retry (lc, op, rs )) goto retry;
122 #ifdef LDAP_BACK_PROXY_AUTHZ
124 if ( ctrls && ctrls != op->o_ctrls ) {
128 #endif /* LDAP_BACK_PROXY_AUTHZ */
130 if ( mdn.bv_val != op->o_req_ndn.bv_val ) {
134 free( mapped_val.bv_val );