ldb_tdb: Do not care about duplicates if single value check disabled
authorGarming Sam <garming@catalyst.net.nz>
Wed, 8 Mar 2017 04:12:21 +0000 (17:12 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 13 Mar 2017 04:10:10 +0000 (05:10 +0100)
This behaviour of ignoring duplicates with the flag
LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK is also used in the replace
case here.

When we add a forward DN+Binary link with a duplicate DN, this prevents
us from not being able to add the backlink because it appears to be a
duplicate here.

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Pair-programmed-with: Bob Campbell <bobcampbell@catalyst.net.nz>

lib/ldb/ldb_tdb/ldb_tdb.c

index 8c4989f6095a48a6209db33cac7eff33750e0d22..2dde0244f134631d47dca0d36529be7154a95e81 100644 (file)
@@ -794,31 +794,33 @@ int ltdb_modify_internal(struct ldb_module *module,
                                /* Check that values don't exist yet on multi-
                                   valued attributes or aren't provided twice */
                                /* TODO: This is O(n^2) - replace with more efficient check */
-                               for (j = 0; j < el->num_values; j++) {
-                                       if (ldb_msg_find_val(el2, &el->values[j]) != NULL) {
-                                               if (control_permissive) {
-                                                       /* remove this one as if it was never added */
-                                                       el->num_values--;
-                                                       for (k = j; k < el->num_values; k++) {
-                                                               el->values[k] = el->values[k + 1];
+                               if (!(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
+                                       for (j = 0; j < el->num_values; j++) {
+                                               if (ldb_msg_find_val(el2, &el->values[j]) != NULL) {
+                                                       if (control_permissive) {
+                                                               /* remove this one as if it was never added */
+                                                               el->num_values--;
+                                                               for (k = j; k < el->num_values; k++) {
+                                                                       el->values[k] = el->values[k + 1];
+                                                               }
+                                                               j--; /* rewind */
+
+                                                               continue;
                                                        }
-                                                       j--; /* rewind */
 
-                                                       continue;
+                                                       ldb_asprintf_errstring(ldb,
+                                                                              "attribute '%s': value #%u on '%s' already exists",
+                                                                              el->name, j, ldb_dn_get_linearized(msg2->dn));
+                                                       ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
+                                                       goto done;
+                                               }
+                                               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;
                                                }
-
-                                               ldb_asprintf_errstring(ldb,
-                                                                      "attribute '%s': value #%u on '%s' already exists",
-                                                                      el->name, j, ldb_dn_get_linearized(msg2->dn));
-                                               ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
-                                               goto done;
-                                       }
-                                       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;
                                        }
                                }