Back to index

openldap  2.4.31
compare.c
Go to the documentation of this file.
00001 /* compare.c - ldap backend compare function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2003-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 1999-2003 Howard Chu.
00007  * Portions Copyright 2000-2003 Pierangelo Masarati.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted only as authorized by the OpenLDAP
00012  * Public License.
00013  *
00014  * A copy of this license is available in the file LICENSE in the
00015  * top-level directory of the distribution or, alternatively, at
00016  * <http://www.OpenLDAP.org/license.html>.
00017  */
00018 /* ACKNOWLEDGEMENTS:
00019  * This work was initially developed by the Howard Chu for inclusion
00020  * in OpenLDAP Software and subsequently enhanced by Pierangelo
00021  * Masarati.
00022  */
00023 
00024 #include "portable.h"
00025 
00026 #include <stdio.h>
00027 
00028 #include <ac/string.h>
00029 #include <ac/socket.h>
00030 
00031 #include "slap.h"
00032 #include "back-ldap.h"
00033 
00034 int
00035 ldap_back_compare(
00036               Operation     *op,
00037               SlapReply     *rs )
00038 {
00039        ldapinfo_t           *li = (ldapinfo_t *)op->o_bd->be_private;
00040 
00041        ldapconn_t           *lc = NULL;
00042        ber_int_t            msgid;
00043        ldap_back_send_t     retrying = LDAP_BACK_RETRYING;
00044        LDAPControl          **ctrls = NULL;
00045        int                  rc = LDAP_SUCCESS;
00046 
00047        if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
00048               lc = NULL;
00049               goto cleanup;
00050        }
00051 
00052 retry:
00053        ctrls = op->o_ctrls;
00054        rc = ldap_back_controls_add( op, rs, lc, &ctrls );
00055        if ( rc != LDAP_SUCCESS ) {
00056               send_ldap_result( op, rs );
00057               goto cleanup;
00058        }
00059 
00060        rs->sr_err = ldap_compare_ext( lc->lc_ld, op->o_req_dn.bv_val,
00061                      op->orc_ava->aa_desc->ad_cname.bv_val,
00062                      &op->orc_ava->aa_value, 
00063                      ctrls, NULL, &msgid );
00064        rc = ldap_back_op_result( lc, op, rs, msgid,
00065               li->li_timeout[ SLAP_OP_COMPARE ],
00066               ( LDAP_BACK_SENDRESULT | retrying ) );
00067        if ( rc == LDAP_UNAVAILABLE && retrying ) {
00068               retrying &= ~LDAP_BACK_RETRYING;
00069               if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
00070                      /* if the identity changed, there might be need to re-authz */
00071                      (void)ldap_back_controls_free( op, rs, &ctrls );
00072                      goto retry;
00073               }
00074        }
00075 
00076 cleanup:
00077        (void)ldap_back_controls_free( op, rs, &ctrls );
00078        
00079        if ( lc != NULL ) {
00080               ldap_back_release_conn( li, lc );
00081        }
00082 
00083        return rs->sr_err;
00084 }