Author: tridge
Date: 2004-12-19 10:56:29 +0000 (Sun, 19 Dec 2004)
New Revision: 4281

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=4281

Log:
fixed an ldb indexing bug in ldb found by volker.

index entries were not always being removed on modify

Modified:
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c       2004-12-19 
07:50:19 UTC (rev 4280)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c       2004-12-19 
10:56:29 UTC (rev 4281)
@@ -746,8 +746,8 @@
 /*
   delete an index entry for one message element
 */
-static int ltdb_index_del1(struct ldb_module *module, const char *dn, 
-                          struct ldb_message_element *el, int v_idx)
+int ltdb_index_del_value(struct ldb_module *module, const char *dn, 
+                        struct ldb_message_element *el, int v_idx)
 {
        struct ldb_context *ldb = module->ldb;
        struct ldb_message msg;
@@ -826,7 +826,7 @@
                        continue;
                }
                for (j=0;j<msg->elements[i].num_values;j++) {
-                       ret = ltdb_index_del1(module, msg->dn, 
&msg->elements[i], j);
+                       ret = ltdb_index_del_value(module, msg->dn, 
&msg->elements[i], j);
                        if (ret == -1) {
                                return -1;
                        }

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c 2004-12-19 07:50:19 UTC 
(rev 4280)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c 2004-12-19 10:56:29 UTC 
(rev 4281)
@@ -403,10 +403,11 @@
 /*
   delete all elements having a specified attribute name
 */
-static int msg_delete_attribute(struct ldb_context *ldb,
+static int msg_delete_attribute(struct ldb_module *module,
+                               struct ldb_context *ldb,
                                struct ldb_message *msg, const char *name)
 {
-       unsigned int i, count=0;
+       unsigned int i, j, count=0;
        struct ldb_message_element *el2;
 
        el2 = ldb_malloc_array_p(ldb, struct ldb_message_element, 
msg->num_elements);
@@ -419,6 +420,9 @@
                if (ldb_attr_cmp(msg->elements[i].name, name) != 0) {
                        el2[count++] = msg->elements[i];
                } else {
+                       for (j=0;j<msg->elements[i].num_values;j++) {
+                               ltdb_index_del_value(module, msg->dn, 
&msg->elements[i], j);
+                       }
                        ldb_free(ldb, msg->elements[i].values);
                }
        }
@@ -460,7 +464,7 @@
                        }
                        el->num_values--;
                        if (el->num_values == 0) {
-                               return msg_delete_attribute(ldb, msg, name);
+                               return msg_delete_attribute(module, ldb, msg, 
name);
                        }
                        return 0;
                }
@@ -532,7 +536,7 @@
                case LDB_FLAG_MOD_REPLACE:
                        /* replace all elements of this attribute name with the 
elements
                           listed. The attribute not existing is not an error */
-                       msg_delete_attribute(ldb, &msg2, msg->elements[i].name);
+                       msg_delete_attribute(module, ldb, &msg2, 
msg->elements[i].name);
 
                        /* add the replacement element, if not empty */
                        if (msg->elements[i].num_values != 0 &&
@@ -545,7 +549,7 @@
                        /* we could be being asked to delete all
                           values or just some values */
                        if (msg->elements[i].num_values == 0) {
-                               if (msg_delete_attribute(ldb, &msg2, 
+                               if (msg_delete_attribute(module, ldb, &msg2, 
                                                         msg->elements[i].name) 
!= 0) {
                                        ltdb->last_err_string = "No such 
attribute";
                                        goto failed;
@@ -560,6 +564,9 @@
                                        ltdb->last_err_string = "No such 
attribute";
                                        goto failed;
                                }
+                               if (ltdb_index_del_value(module, msg->dn, 
&msg->elements[i], j) != 0) {
+                                       goto failed;
+                               }
                        }
                        break;
                }

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h 2004-12-19 07:50:19 UTC 
(rev 4280)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h 2004-12-19 10:56:29 UTC 
(rev 4281)
@@ -112,3 +112,7 @@
                      struct ldb_parse_tree *tree,
                      const char *base,
                      enum ldb_scope scope);
+
+int ltdb_index_del_value(struct ldb_module *module, const char *dn, 
+                        struct ldb_message_element *el, int v_idx);
+

Reply via email to