]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9753 back-mdb: Fix index updating for replace ops
authorHoward Chu <hyc@openldap.org>
Tue, 23 Nov 2021 17:10:29 +0000 (17:10 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 23 Nov 2021 22:19:46 +0000 (22:19 +0000)
(cherry picked from commit 739081f217c9cdb2636d99250092e8d7b30bdd94)

servers/slapd/back-mdb/modify.c

index d1a2a7324fe3f742ea9a51a83b1b58b80854e2fb..f8c93de046022e55b34d8649a05c89d0bbcc9b26 100644 (file)
@@ -27,11 +27,14 @@ static struct berval scbva[] = {
        BER_BVNULL
 };
 
+#define        CHECK_ADD       1
+#define        CHECK_DEL       2
+
 static void
 mdb_modify_idxflags(
        Operation *op,
        AttributeDescription *desc,
-       int got_delete,
+       int ixcheck,
        Attribute *newattrs,
        Attribute *oldattrs )
 {
@@ -42,7 +45,7 @@ mdb_modify_idxflags(
         * but not in case of NOOP... */
        ai = mdb_index_mask( op->o_bd, desc, &ix_at );
        if ( ai ) {
-               if ( got_delete ) {
+               if ( ixcheck & CHECK_DEL ) {
                        Attribute       *ap;
                        struct berval   ix2;
 
@@ -65,7 +68,8 @@ mdb_modify_idxflags(
                                }
                        }
 
-               } else {
+               }
+               if ( ixcheck & CHECK_ADD ) {
                        Attribute       *ap;
 
                        ap = attr_find( newattrs, desc );
@@ -91,7 +95,7 @@ int mdb_modify_internal(
        Attribute       *ap, *aold, *anew;
        int                     glue_attr_delete = 0;
        int                     softop, chkpresent;
-       int                     got_delete;
+       int                     ixcheck;
        int                     a_flags;
        MDB_cursor      *mvc = NULL;
 
@@ -140,7 +144,7 @@ int mdb_modify_internal(
 
        for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
                mod = &ml->sml_mod;
-               got_delete = 0;
+               ixcheck = 0;
 
                aold = attr_find( e->e_attrs, mod->sm_desc );
                if (aold)
@@ -207,6 +211,7 @@ mval_fail:                                  strncpy( textbuf, mdb_strerror( err ), textlen );
                                        if ( err )
                                                goto mval_fail;
                                }
+                               ixcheck |= CHECK_ADD;
                        }
                        break;
 
@@ -237,7 +242,7 @@ do_del:
                                        err, *text );
                        } else {
                                if (softop != 2)
-                                       got_delete = 1;
+                                       ixcheck |= CHECK_DEL;
                                /* check for big multivalued attrs */
                                if (a_flags & SLAP_ATTR_BIG_MULTI) {
                                        Attribute a_dummy;
@@ -285,7 +290,9 @@ do_del:
                                        err, *text );
                        } else {
                                unsigned hi;
-                               got_delete = 1;
+                               ixcheck = CHECK_DEL;
+                               if ( mod->sm_numvals )
+                                       ixcheck |= CHECK_ADD;
                                if (a_flags & SLAP_ATTR_BIG_MULTI) {
                                        Attribute a_dummy;
                                        if (!mvc) {
@@ -331,7 +338,7 @@ do_del:
                                        "mdb_modify_internal: %d %s\n",
                                        err, *text );
                        } else {
-                               got_delete = 1;
+                               ixcheck = CHECK_ADD|CHECK_DEL;
                        }
                        break;
 
@@ -403,7 +410,7 @@ do_del:
                /* check if modified attribute was indexed
                 * but not in case of NOOP... */
                if ( !op->o_noop ) {
-                       mdb_modify_idxflags( op, mod->sm_desc, got_delete, e->e_attrs, save_attrs );
+                       mdb_modify_idxflags( op, mod->sm_desc, ixcheck, e->e_attrs, save_attrs );
                }
        }
 
@@ -434,7 +441,7 @@ do_del:
                assert( ap->a_desc == slap_schema.si_ad_structuralObjectClass );
                if ( !op->o_noop ) {
                        mdb_modify_idxflags( op, slap_schema.si_ad_structuralObjectClass,
-                               1, e->e_attrs, save_attrs );
+                               CHECK_ADD|CHECK_DEL, e->e_attrs, save_attrs );
                }
        }