Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-ldap / compare.c
blobaa6c5c8db51d700f63ebd87634f4cdfbe36b18ab
1 /* compare.c - ldap backend compare function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-ldap/compare.c,v 1.60.2.5 2008/02/11 23:26:46 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2008 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
12 * Public License.
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>.
18 /* ACKNOWLEDGEMENTS:
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
21 * Masarati.
24 #include "portable.h"
26 #include <stdio.h>
28 #include <ac/string.h>
29 #include <ac/socket.h>
31 #include "slap.h"
32 #include "back-ldap.h"
34 int
35 ldap_back_compare(
36 Operation *op,
37 SlapReply *rs )
39 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
41 ldapconn_t *lc = NULL;
42 ber_int_t msgid;
43 ldap_back_send_t retrying = LDAP_BACK_RETRYING;
44 LDAPControl **ctrls = NULL;
45 int rc = LDAP_SUCCESS;
47 if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
48 lc = NULL;
49 goto cleanup;
52 retry:
53 ctrls = op->o_ctrls;
54 rc = ldap_back_controls_add( op, rs, lc, &ctrls );
55 if ( rc != LDAP_SUCCESS ) {
56 send_ldap_result( op, rs );
57 goto cleanup;
60 rs->sr_err = ldap_compare_ext( lc->lc_ld, op->o_req_dn.bv_val,
61 op->orc_ava->aa_desc->ad_cname.bv_val,
62 &op->orc_ava->aa_value,
63 ctrls, NULL, &msgid );
64 rc = ldap_back_op_result( lc, op, rs, msgid,
65 li->li_timeout[ SLAP_OP_COMPARE ],
66 ( LDAP_BACK_SENDRESULT | retrying ) );
67 if ( rc == LDAP_UNAVAILABLE && retrying ) {
68 retrying &= ~LDAP_BACK_RETRYING;
69 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
70 /* if the identity changed, there might be need to re-authz */
71 (void)ldap_back_controls_free( op, rs, &ctrls );
72 goto retry;
76 cleanup:
77 (void)ldap_back_controls_free( op, rs, &ctrls );
79 if ( lc != NULL ) {
80 ldap_back_release_conn( li, lc );
83 return rs->sr_err;