summaryrefslogtreecommitdiff
path: root/source4/dsdb/samdb/ldb_modules
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-08-09 14:41:20 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-08-09 11:56:23 +0200
commit4ede333f468b36fb7435c9de1216da3b66bf0490 (patch)
tree2fb641d6df7f893ca29432fc89fe732d673a1450 /source4/dsdb/samdb/ldb_modules
parent2ba18d89eb066cf52d8bbd18a28e494bb4247d9c (diff)
downloadsamba-4ede333f468b36fb7435c9de1216da3b66bf0490.tar.gz
samba-4ede333f468b36fb7435c9de1216da3b66bf0490.tar.bz2
samba-4ede333f468b36fb7435c9de1216da3b66bf0490.zip
s4-dsdb: add auto-normalisation of attributes
this auto-normalises some attributes when they are added/modified. The list that we auto-normalise is currently: Boolean INT32 INTEGER UTC_TIME This fixes a problem with groupType being stored in an unnormalised form Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules')
-rw-r--r--source4/dsdb/samdb/ldb_modules/objectclass_attrs.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c b/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c
index 4525cf3ddd..9893adae93 100644
--- a/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c
+++ b/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c
@@ -88,6 +88,45 @@ static int oc_validate_dsheuristics(struct ldb_message_element *el)
return LDB_SUCCESS;
}
+/*
+ auto normalise values on input
+ */
+static int oc_auto_normalise(struct ldb_context *ldb, const struct dsdb_attribute *attr,
+ struct ldb_message *msg, struct ldb_message_element *el)
+{
+ int i;
+ bool values_copied = false;
+
+ for (i=0; i<el->num_values; i++) {
+ struct ldb_val v;
+ int ret;
+ ret = attr->ldb_schema_attribute->syntax->canonicalise_fn(ldb, el->values, &el->values[i], &v);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+ if (data_blob_cmp(&v, &el->values[i]) == 0) {
+ /* no need to replace it */
+ talloc_free(v.data);
+ continue;
+ }
+
+ /* we need to copy the values array on the first change */
+ if (!values_copied) {
+ struct ldb_val *v2;
+ v2 = talloc_array(msg->elements, struct ldb_val, el->num_values);
+ if (v2 == NULL) {
+ return ldb_oom(ldb);
+ }
+ memcpy(v2, el->values, sizeof(struct ldb_val) * el->num_values);
+ el->values = v2;
+ values_copied = true;
+ }
+
+ el->values[i] = v;
+ }
+ return LDB_SUCCESS;
+}
+
static int attr_handler(struct oc_context *ac)
{
struct ldb_context *ldb;
@@ -174,6 +213,14 @@ static int attr_handler(struct oc_context *ac)
}
}
+ /* auto normalise some attribute values */
+ if (attr->syntax->auto_normalise) {
+ ret = oc_auto_normalise(ldb, attr, msg, &msg->elements[i]);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+ }
+
/* Substitute the attribute name to match in case */
msg->elements[i].name = attr->lDAPDisplayName;
}