]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/compare.c
ITS#2368 - fix deleting key from range IDL
[openldap] / servers / slapd / compare.c
index 91cf820c37d023e6bbf43070537b13484fa9ed67..bca36de6faacf06c6e609b333fecd34aa80020b9 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /*
@@ -22,6 +22,9 @@
 
 #include "ldap_pvt.h"
 #include "slap.h"
+#ifdef LDAP_SLAPI
+#include "slapi.h"
+#endif
 
 static int compare_entry(
        Connection *conn,
@@ -36,22 +39,26 @@ do_compare(
 )
 {
        Entry *entry = NULL;
+       Entry *fentry = NULL;
        struct berval dn = { 0, NULL };
        struct berval pdn = { 0, NULL };
        struct berval ndn = { 0, NULL };
        struct berval desc = { 0, NULL };
        struct berval value = { 0, NULL };
-       AttributeAssertion ava = { 0 };
+       AttributeAssertion ava = { NULL, { 0, NULL } };
        Backend *be;
        int rc = LDAP_SUCCESS;
        const char *text = NULL;
        int manageDSAit;
 
+#ifdef LDAP_SLAPI
+       Slapi_PBlock *pb = op->o_pb;
+#endif
+
        ava.aa_desc = NULL;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
-               "do_compare: conn %d\n", conn->c_connid ));
+       LDAP_LOG( OPERATION, ENTRY, "do_compare: conn %d\n", conn->c_connid, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "do_compare\n", 0, 0, 0 );
 #endif
@@ -69,8 +76,8 @@ do_compare(
 
        if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                       "do_compare: conn %d  ber_scanf failed\n", conn->c_connid ));
+               LDAP_LOG( OPERATION, ERR, 
+                       "do_compare: conn %d  ber_scanf failed\n", conn->c_connid, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
 #endif
@@ -81,8 +88,8 @@ do_compare(
 
        if ( ber_scanf( op->o_ber, "{mm}", &desc, &value ) == LBER_ERROR ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                       "do_compare: conn %d  get ava failed\n", conn->c_connid ));
+               LDAP_LOG( OPERATION, ERR, 
+                       "do_compare: conn %d  get ava failed\n", conn->c_connid, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY, "do_compare: get ava failed\n", 0, 0, 0 );
 #endif
@@ -94,8 +101,8 @@ do_compare(
 
        if ( ber_scanf( op->o_ber, /*{*/ "}" ) == LBER_ERROR ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                       "do_compare: conn %d  ber_scanf failed\n", conn->c_connid ));
+               LDAP_LOG( OPERATION, ERR, 
+                       "do_compare: conn %d  ber_scanf failed\n", conn->c_connid, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
 #endif
@@ -107,8 +114,8 @@ do_compare(
 
        if( ( rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
-                       "do_compare: conn %d  get_ctrls failed\n", conn->c_connid ));
+               LDAP_LOG( OPERATION, INFO, 
+                       "do_compare: conn %d  get_ctrls failed\n", conn->c_connid, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY, "do_compare: get_ctrls failed\n", 0, 0, 0 );
 #endif
@@ -118,9 +125,9 @@ do_compare(
        rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
+               LDAP_LOG( OPERATION, INFO, 
                        "do_compare: conn %d  invalid dn (%s)\n",
-                       conn->c_connid, dn.bv_val ));
+                       conn->c_connid, dn.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "do_compare: invalid dn (%s)\n", dn.bv_val, 0, 0 );
@@ -136,7 +143,15 @@ do_compare(
                goto cleanup;
        }
 
-       rc = value_normalize( ava.aa_desc, SLAP_MR_EQUALITY, &value, &ava.aa_value, &text );
+#ifdef SLAP_NVALUES
+       rc = asserted_value_validate_normalize( ava.aa_desc,
+               ava.aa_desc->ad_type->sat_equality,
+               SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
+               &value, &ava.aa_value, &text );
+#else
+       rc = value_validate_normalize( ava.aa_desc, SLAP_MR_EQUALITY,
+               &value, &ava.aa_value, &text );
+#endif
        if( rc != LDAP_SUCCESS ) {
                send_ldap_result( conn, op, rc, NULL, text, NULL, NULL );
                goto cleanup;
@@ -144,17 +159,16 @@ do_compare(
 
        if( strcasecmp( ndn.bv_val, LDAP_ROOT_DSE ) == 0 ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
-                       "do_compare: conn %d  dn (%s) attr(%s) value (%s)\n",
-                       conn->c_connid, pdn.bv_val,
-                       ava.aa_desc->ad_cname.bv_val, ava.aa_value.bv_val ));
+               LDAP_LOG( OPERATION, ARGS, 
+                       "do_compare: dn (%s) attr(%s) value (%s)\n",
+                       pdn.bv_val, ava.aa_desc->ad_cname.bv_val, ava.aa_value.bv_val );
 #else
                Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
                        pdn.bv_val, ava.aa_desc->ad_cname.bv_val, ava.aa_value.bv_val );
 #endif
 
                Statslog( LDAP_DEBUG_STATS,
-                       "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
+                       "conn=%lu op=%lu CMP dn=\"%s\" attr=\"%s\"\n",
                        op->o_connid, op->o_opid, pdn.bv_val,
                        ava.aa_desc->ad_cname.bv_val, 0 );
 
@@ -170,19 +184,21 @@ do_compare(
                        goto cleanup;
                }
 
-       } else if ( strcasecmp( ndn.bv_val, SLAPD_SCHEMA_DN ) == 0 ) {
+               fentry = entry;
+
+       } else if ( bvmatch( &ndn, &global_schemandn ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
-                       "do_compare: conn %d  dn (%s) attr(%s) value (%s)\n",
-                       conn->c_connid, pdn.bv_val, ava.aa_desc->ad_cname.bv_val,
-                       ava.aa_value.bv_val ));
+               LDAP_LOG( OPERATION, ARGS, 
+                       "do_compare: dn (%s) attr(%s) value (%s)\n",
+                       pdn.bv_val, ava.aa_desc->ad_cname.bv_val,
+                       ava.aa_value.bv_val );
 #else
                Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
                        pdn.bv_val, ava.aa_desc->ad_cname.bv_val, ava.aa_value.bv_val );
 #endif
 
                Statslog( LDAP_DEBUG_STATS,
-                       "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
+                       "conn=%lu op=%lu CMP dn=\"%s\" attr=\"%s\"\n",
                        op->o_connid, op->o_opid, pdn.bv_val,
                        ava.aa_desc->ad_cname.bv_val, 0 );
 
@@ -199,11 +215,12 @@ do_compare(
                        rc = 0;
                        goto cleanup;
                }
+               fentry = entry;
        }
 
        if( entry ) {
                rc = compare_entry( conn, op, entry, &ava );
-               entry_free( entry );
+               if( fentry) entry_free( fentry );
 
                send_ldap_result( conn, op, rc, NULL, text, NULL, NULL );
 
@@ -248,22 +265,45 @@ do_compare(
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
-               "do_compare: conn %d     dn (%s) attr(%s) value (%s)\n",
-               conn->c_connid, pdn.bv_val, ava.aa_desc->ad_cname.bv_val,
-               ava.aa_value.bv_val ));
+       LDAP_LOG( OPERATION, ARGS, 
+               "do_compare: dn (%s) attr(%s) value (%s)\n",
+               pdn.bv_val, ava.aa_desc->ad_cname.bv_val, ava.aa_value.bv_val );
 #else
        Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
            pdn.bv_val, ava.aa_desc->ad_cname.bv_val, ava.aa_value.bv_val );
 #endif
 
-       Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d CMP dn=\"%s\" attr=\"%s\"\n",
+       Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu CMP dn=\"%s\" attr=\"%s\"\n",
            op->o_connid, op->o_opid, pdn.bv_val,
                ava.aa_desc->ad_cname.bv_val, 0 );
 
-
-       /* deref suffix alias if appropriate */
-       suffix_alias( be, &ndn );
+#if defined( LDAP_SLAPI )
+       slapi_x_backend_set_pb( pb, be );
+       slapi_x_connection_set_pb( pb, conn );
+       slapi_x_operation_set_pb( 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 );
+
+       rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_COMPARE_FN, pb );
+       if ( rc != 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);
+#else
+               Debug(LDAP_DEBUG_TRACE, "do_compare: compare preoperation plugin "
+                               "failed.\n", 0, 0, 0);
+#endif
+               if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rc ) != 0)
+                       rc = LDAP_OTHER;
+               goto cleanup;
+       }
+#endif /* defined( LDAP_SLAPI ) */
 
        if ( be->be_compare ) {
                (*be->be_compare)( be, conn, op, &pdn, &ndn, &ava );
@@ -273,6 +313,18 @@ do_compare(
                        NULL, NULL );
        }
 
+#if defined( LDAP_SLAPI )
+       if ( doPluginFNs( be, SLAPI_PLUGIN_POST_COMPARE_FN, pb ) != 0 ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, INFO, "do_compare: compare postoperation plugins "
+                               "failed\n", 0, 0, 0 );
+#else
+               Debug(LDAP_DEBUG_TRACE, "do_compare: compare postoperation plugins "
+                               "failed.\n", 0, 0, 0);
+#endif
+       }
+#endif /* defined( LDAP_SLAPI ) */
+
 cleanup:
        free( pdn.bv_val );
        free( ndn.bv_val );
@@ -302,7 +354,15 @@ static int compare_entry(
        {
                rc = LDAP_COMPARE_FALSE;
 
-               if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) {
+#ifdef SLAP_NVALUES
+               if ( value_find_ex( ava->aa_desc,
+                       SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
+                       a->a_nvals ? a->a_nvals : a->a_vals,
+                       &ava->aa_value ) == 0 )
+#else
+               if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 )
+#endif
+               {
                        rc = LDAP_COMPARE_TRUE;
                        break;
                }