]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/compare.c
ITS#2888 don't return LDAP_SIZELIMIT_EXCEEDED prematurely
[openldap] / servers / slapd / compare.c
index d999b7c20ff5342e7e3e3c22d420104d212eaf37..fdfccea5193fe8ad345aee050ae58846b595ac8a 100644 (file)
@@ -1,10 +1,18 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
-/*
- * Copyright (c) 1995 Regents of the University of Michigan.
+/* Portions Copyright (c) 1995 Regents of the University of Michigan.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
@@ -19,6 +27,7 @@
 
 #include <stdio.h>
 #include <ac/socket.h>
+#include <ac/string.h>
 
 #include "ldap_pvt.h"
 #include "slap.h"
@@ -44,10 +53,6 @@ do_compare(
        AttributeAssertion ava = { NULL, { 0, NULL } };
        int manageDSAit;
 
-#ifdef LDAP_SLAPI
-       Slapi_PBlock *pb = op->o_pb;
-#endif
-
        ava.aa_desc = NULL;
 
 #ifdef NEW_LOGGING
@@ -253,28 +258,33 @@ do_compare(
                ava.aa_desc->ad_cname.bv_val, 0 );
 
 #if defined( LDAP_SLAPI )
-       slapi_x_pblock_set_operation( pb, op );
-       slapi_pblock_set( pb, SLAPI_COMPARE_TARGET, (void *)dn.bv_val );
-       slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
-       slapi_pblock_set( pb, SLAPI_COMPARE_TYPE, (void *)desc.bv_val );
-       slapi_pblock_set( pb, SLAPI_COMPARE_VALUE, (void *)&value );
-
-       rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_COMPARE_FN, pb );
-       if ( rs->sr_err != 0 ) {
-               /*
-                * A preoperation plugin failure will abort the
-                * entire operation.
-                */
+#define        pb      op->o_pb
+       if ( pb ) {
+               slapi_int_pblock_set_operation( pb, op );
+               slapi_pblock_set( pb, SLAPI_COMPARE_TARGET, (void *)dn.bv_val );
+               slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
+               slapi_pblock_set( pb, SLAPI_COMPARE_TYPE, (void *)desc.bv_val );
+               slapi_pblock_set( pb, SLAPI_COMPARE_VALUE, (void *)&value );
+
+               rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_COMPARE_FN, pb );
+               if ( rs->sr_err < 0 ) {
+                       /*
+                        * A preoperation plugin failure will abort the
+                        * entire operation.
+                        */
 #ifdef NEW_LOGGING
-               LDAP_LOG( OPERATION, INFO, "do_compare: compare preoperation plugin "
-                               "failed\n", 0, 0, 0);
+                       LDAP_LOG( OPERATION, INFO, "do_compare: compare preoperation plugin "
+                                       "failed\n", 0, 0, 0);
 #else
-               Debug(LDAP_DEBUG_TRACE, "do_compare: compare preoperation plugin "
-                               "failed.\n", 0, 0, 0);
+                       Debug(LDAP_DEBUG_TRACE, "do_compare: compare preoperation plugin "
+                                       "failed.\n", 0, 0, 0);
 #endif
-               if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0)
-                       rs->sr_err = LDAP_OTHER;
-               goto cleanup;
+                       if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 )  ||
+                                rs->sr_err == LDAP_SUCCESS ) {
+                               rs->sr_err = LDAP_OTHER;
+                       }
+                       goto cleanup;
+               }
        }
 #endif /* defined( LDAP_SLAPI ) */
 
@@ -287,7 +297,7 @@ do_compare(
        }
 
 #if defined( LDAP_SLAPI )
-       if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_COMPARE_FN, pb ) != 0 ) {
+       if ( pb && doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_COMPARE_FN, pb ) < 0 ) {
 #ifdef NEW_LOGGING
                LDAP_LOG( OPERATION, INFO, "do_compare: compare postoperation plugins "
                                "failed\n", 0, 0, 0 );