ldb/tdb: make sure we use the default syntax for all attributes of dn: @ATTRIBUTES
authorStefan Metzmacher <metze@samba.org>
Wed, 11 Sep 2013 06:33:14 +0000 (08:33 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 25 Sep 2013 08:42:01 +0000 (10:42 +0200)
The values are already checked in ltdb_check_special_dn() which is called
before calling into ltdb_add_internal/ltdb_modify_internal.

So ltdb_add_internal/ltdb_modify_internal should not verify it again
and get the default syntax by forcing "@" as attribute name
for ldb_schema_attribute_by_name().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/ldb_tdb/ldb_tdb.c

index e427cab2b58da8dd35337e29baec85b96caf6169..3c24c15f0483d0d178ab2cc38a100651827c8b31 100644 (file)
@@ -330,10 +330,29 @@ static int ltdb_add_internal(struct ldb_module *module,
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        int ret = LDB_SUCCESS;
        unsigned int i, j;
+       const char *forced_schema_attr_name = NULL;
+
+       if (ldb_dn_is_special(msg->dn) &&
+           ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) {
+               /*
+                * @ATTRIBUTES is checked in ltdb_check_special_dn()
+                *
+                * Here we force the ldb_attribute_default syntax
+                * for all attributes of the @ATTRIBUTES object.
+                */
+               forced_schema_attr_name = "@";
+       }
 
        for (i=0;i<msg->num_elements;i++) {
                struct ldb_message_element *el = &msg->elements[i];
-               const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, el->name);
+               const char *schema_attr_name = el->name;
+               const struct ldb_schema_attribute *a;
+
+               if (forced_schema_attr_name != NULL) {
+                       schema_attr_name = forced_schema_attr_name;
+               }
+
+               a = ldb_schema_attribute_by_name(ldb, schema_attr_name);
 
                if (el->num_values == 0) {
                        ldb_asprintf_errstring(ldb, "attribute '%s' on '%s' specified, but with 0 values (illegal)",
@@ -679,6 +698,7 @@ int ltdb_modify_internal(struct ldb_module *module,
        unsigned int i, j, k;
        int ret = LDB_SUCCESS, idx;
        struct ldb_control *control_permissive = NULL;
+       const char *forced_schema_attr_name = NULL;
 
        if (req) {
                control_permissive = ldb_request_get_control(req,
@@ -716,11 +736,29 @@ int ltdb_modify_internal(struct ldb_module *module,
                msg2->dn = msg->dn;
        }
 
+       if (ldb_dn_is_special(msg2->dn) &&
+           ldb_dn_check_special(msg2->dn, LTDB_ATTRIBUTES)) {
+               /*
+                * @ATTRIBUTES is checked in ltdb_check_special_dn()
+                *
+                * Here we force the ldb_attribute_default syntax
+                * for all attributes of the @ATTRIBUTES object.
+                */
+               forced_schema_attr_name = "@";
+       }
+
        for (i=0; i<msg->num_elements; i++) {
                struct ldb_message_element *el = &msg->elements[i], *el2;
                struct ldb_val *vals;
-               const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, el->name);
                const char *dn;
+               const char *schema_attr_name = el->name;
+               const struct ldb_schema_attribute *a;
+
+               if (forced_schema_attr_name != NULL) {
+                       schema_attr_name = forced_schema_attr_name;
+               }
+
+               a = ldb_schema_attribute_by_name(ldb, schema_attr_name);
 
                switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) {
                case LDB_FLAG_MOD_ADD: