summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-02-14 10:07:21 +1100
committerAndrew Tridgell <tridge@samba.org>2011-02-14 17:55:08 +1100
commita48328a8282d116d17515cfe681c1b41f6541d39 (patch)
treebe1a0cdc1cd41ce7b526fe1761e9c4d55b10344b /source4/lib/ldb/ldb_tdb
parenta26f8b8ae6e147b59747cb140dbde2eddef8c970 (diff)
downloadsamba-a48328a8282d116d17515cfe681c1b41f6541d39.tar.gz
samba-a48328a8282d116d17515cfe681c1b41f6541d39.tar.bz2
samba-a48328a8282d116d17515cfe681c1b41f6541d39.zip
s4-ldb: use a helper function for single valued checking
this gives us a single piece of logic for single value checking in the tdb backend Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index b0f9bf934b..5c1dd1bdce 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -276,6 +276,26 @@ done:
}
+/*
+ check if a attribute is a single valued, for a given element
+ */
+static bool ldb_tdb_single_valued(const struct ldb_schema_attribute *a,
+ struct ldb_message_element *el)
+{
+ if (!a) return false;
+ if (el != NULL) {
+ if (el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK) {
+ /* override from a ldb module, for example used for
+ deleted linked attribute entries */
+ return false;
+ }
+ }
+ if (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) {
+ return true;
+ }
+ return false;
+}
+
static int ltdb_add_internal(struct ldb_module *module,
const struct ldb_message *msg)
{
@@ -292,13 +312,10 @@ static int ltdb_add_internal(struct ldb_module *module,
el->name, ldb_dn_get_linearized(msg->dn));
return LDB_ERR_CONSTRAINT_VIOLATION;
}
- if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
- !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
- if (el->num_values > 1) {
- ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
- el->name, ldb_dn_get_linearized(msg->dn));
- return LDB_ERR_CONSTRAINT_VIOLATION;
- }
+ if (el->num_values > 1 && ldb_tdb_single_valued(a, el)) {
+ ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
+ el->name, ldb_dn_get_linearized(msg->dn));
+ return LDB_ERR_CONSTRAINT_VIOLATION;
}
}
@@ -692,14 +709,11 @@ int ltdb_modify_internal(struct ldb_module *module,
}
}
- if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
- !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
- if (el->num_values > 1) {
- ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
- el->name, ldb_dn_get_linearized(msg2->dn));
- ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
- goto done;
- }
+ if (el->num_values > 1 && ldb_tdb_single_valued(a, el)) {
+ ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
+ el->name, ldb_dn_get_linearized(msg2->dn));
+ ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
+ goto done;
}
/* Checks if element already exists */
@@ -720,8 +734,7 @@ int ltdb_modify_internal(struct ldb_module *module,
/* We cannot add another value on a existing one
if the attribute is single-valued */
- if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
- !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
+ if (ldb_tdb_single_valued(a, el)) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
@@ -787,14 +800,11 @@ int ltdb_modify_internal(struct ldb_module *module,
case LDB_FLAG_MOD_REPLACE:
- if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
- !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
- if (el->num_values > 1) {
- ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
- el->name, ldb_dn_get_linearized(msg2->dn));
- ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
- goto done;
- }
+ if (el->num_values > 1 && ldb_tdb_single_valued(a, el)) {
+ ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
+ el->name, ldb_dn_get_linearized(msg2->dn));
+ ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
+ goto done;
}
/* TODO: This is O(n^2) - replace with more efficient check */