]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/compare.c
3ce083f724560c59c1e6f5ddc497838b4898e21c
[openldap] / servers / slapd / back-ldap / compare.c
1 /* compare.c - ldap backend compare function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003-2005 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
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.
13  *
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>.
17  */
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.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/socket.h>
30
31 #include "slap.h"
32 #include "back-ldap.h"
33
34 int
35 ldap_back_compare(
36                 Operation       *op,
37                 SlapReply       *rs )
38 {
39         struct ldapconn *lc;
40         ber_int_t       msgid;
41         int             do_retry = 1;
42         LDAPControl     **ctrls = NULL;
43         int             rc = LDAP_SUCCESS;
44
45         lc = ldap_back_getconn( op, rs );
46         if (!lc || !ldap_back_dobind( lc, op, rs ) ) {
47                 rc = -1;
48                 goto cleanup;
49         }
50
51         ctrls = op->o_ctrls;
52 #ifdef LDAP_BACK_PROXY_AUTHZ
53         rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
54         if ( rc != LDAP_SUCCESS ) {
55                 send_ldap_result( op, rs );
56                 rc = -1;
57                 goto cleanup;
58         }
59 #endif /* LDAP_BACK_PROXY_AUTHZ */
60
61 retry:
62         rs->sr_err = ldap_compare_ext( lc->lc_ld, op->o_req_ndn.bv_val,
63                         op->orc_ava->aa_desc->ad_cname.bv_val,
64                         &op->orc_ava->aa_value, 
65                         ctrls, NULL, &msgid );
66         rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
67         if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
68                 do_retry = 0;
69                 if ( ldap_back_retry(lc, op, rs ) ) {
70                         goto retry;
71                 }
72         }
73
74 cleanup:
75 #ifdef LDAP_BACK_PROXY_AUTHZ
76         (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
77 #endif /* LDAP_BACK_PROXY_AUTHZ */
78         
79         return rc;
80 }