From: Garming Sam Date: Wed, 8 Mar 2017 04:12:21 +0000 (+1300) Subject: ldb_tdb: Do not care about duplicates if single value check disabled X-Git-Tag: tdb-1.3.13~505 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3b5aeaba957696f17a6aac7d748e578886050c2b;p=thirdparty%2Fsamba.git ldb_tdb: Do not care about duplicates if single value check disabled 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 Reviewed-by: Andrew Bartlett Pair-programmed-with: Bob Campbell --- diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index 8c4989f6095..2dde0244f13 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -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; } }