Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-meta / compare.c
blob6157a853ac087f8854e58166c85c99412eba68ca
1 /* $OpenLDAP: pkg/ldap/servers/slapd/back-meta/compare.c,v 1.50.2.7 2008/02/12 00:25:47 quanah Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2008 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
11 * Public License.
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
17 /* ACKNOWLEDGEMENTS:
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
20 * Masarati.
23 #include "portable.h"
25 #include <stdio.h>
27 #include <ac/string.h>
28 #include <ac/socket.h>
30 #include "slap.h"
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
34 int
35 meta_back_compare( Operation *op, SlapReply *rs )
37 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
38 metatarget_t *mt;
39 metaconn_t *mc;
40 int rc = 0;
41 int candidate = -1;
42 struct berval mdn = BER_BVNULL;
43 dncookie dc;
44 struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname;
45 struct berval mapped_value = op->orc_ava->aa_value;
46 int msgid;
47 int do_retry = 1;
48 LDAPControl **ctrls = NULL;
50 mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
51 if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
52 return rs->sr_err;
55 assert( mc->mc_conns[ candidate ].msc_ld != NULL );
58 * Rewrite the modify dn, if needed
60 mt = mi->mi_targets[ candidate ];
61 dc.target = mt;
62 dc.conn = op->o_conn;
63 dc.rs = rs;
64 dc.ctx = "compareDN";
66 switch ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
67 case LDAP_UNWILLING_TO_PERFORM:
68 rc = 1;
69 goto cleanup;
71 default:
72 break;
76 * if attr is objectClass, try to remap the value
78 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass ) {
79 ldap_back_map( &mt->mt_rwmap.rwm_oc,
80 &op->orc_ava->aa_value,
81 &mapped_value, BACKLDAP_MAP );
83 if ( BER_BVISNULL( &mapped_value ) || BER_BVISEMPTY( &mapped_value ) ) {
84 goto cleanup;
88 * else try to remap the attribute
90 } else {
91 ldap_back_map( &mt->mt_rwmap.rwm_at,
92 &op->orc_ava->aa_desc->ad_cname,
93 &mapped_attr, BACKLDAP_MAP );
94 if ( BER_BVISNULL( &mapped_attr ) || BER_BVISEMPTY( &mapped_attr ) ) {
95 goto cleanup;
98 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
100 dc.ctx = "compareAttrDN";
102 switch ( ldap_back_dn_massage( &dc, &op->orc_ava->aa_value, &mapped_value ) )
104 case LDAP_UNWILLING_TO_PERFORM:
105 rc = 1;
106 goto cleanup;
108 default:
109 break;
114 retry:;
115 ctrls = op->o_ctrls;
116 rc = meta_back_controls_add( op, rs, mc, candidate, &ctrls );
117 if ( rc != LDAP_SUCCESS ) {
118 send_ldap_result( op, rs );
119 goto cleanup;
122 rs->sr_err = ldap_compare_ext( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
123 mapped_attr.bv_val, &mapped_value,
124 ctrls, NULL, &msgid );
126 rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
127 mt->mt_timeout[ SLAP_OP_COMPARE ], LDAP_BACK_SENDRESULT );
128 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
129 do_retry = 0;
130 if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR ) ) {
131 /* if the identity changed, there might be need to re-authz */
132 (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
133 goto retry;
137 cleanup:;
138 (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
140 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
141 free( mdn.bv_val );
144 if ( op->orc_ava->aa_value.bv_val != mapped_value.bv_val ) {
145 free( mapped_value.bv_val );
148 if ( mc ) {
149 meta_back_release_conn( mi, mc );
152 return rs->sr_err;