ldb: Allow repl_meta_data to override the O(^2) loop checking for duplciates
authorAndrew Bartlett <abartlet@samba.org>
Wed, 15 Jun 2016 04:11:28 +0000 (16:11 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 26 Jun 2016 22:18:17 +0000 (00:18 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_tdb.c

index 6a91f053f64d722f068b8459942f43fc579c0e07..1a4f4cad4c4b67108e95c300bcf418e6b759e2b6 100644 (file)
@@ -858,14 +858,22 @@ int ltdb_modify_internal(struct ldb_module *module,
                                goto done;
                        }
 
-                       /* TODO: This is O(n^2) - replace with more efficient check */
-                       for (j=0; j<el->num_values; j++) {
-                               if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) {
-                                       ldb_asprintf_errstring(ldb,
-                                                              "attribute '%s': value #%u on '%s' provided more than once",
-                                                              el->name, j, ldb_dn_get_linearized(msg2->dn));
-                                       ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
-                                       goto done;
+                       /*
+                        * We don't need to check this if we have been
+                        * pre-screened by the repl_meta_data module
+                        * in Samba, or someone else who can claim to
+                        * know what they are doing. 
+                        */
+                       if (!(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) { 
+                               /* TODO: This is O(n^2) - replace with more efficient check */
+                               for (j=0; j<el->num_values; j++) {
+                                       if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) {
+                                               ldb_asprintf_errstring(ldb,
+                                                                      "attribute '%s': value #%u on '%s' provided more than once",
+                                                                      el->name, j, ldb_dn_get_linearized(msg2->dn));
+                                               ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
+                                               goto done;
+                                       }
                                }
                        }