dsdb: Parse linked attributes using their DN+Binary or DN+String syntax, if needed
authorAndrew Bartlett <abartlet@samba.org>
Wed, 20 May 2015 09:06:22 +0000 (11:06 +0200)
committerGarming Sam <garming@samba.org>
Thu, 22 Dec 2016 21:42:22 +0000 (22:42 +0100)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/dsdb/samdb/ldb_modules/linked_attributes.c

index 8063162a0b808286cffc21c71c138d916557a34c..2016524a2d4138bce1285c2b3e7cad9793944c24 100644 (file)
@@ -172,28 +172,36 @@ static int la_guid_from_dn(struct ldb_module *module,
 /* Common routine to handle reading the attributes and creating a
  * series of modify requests */
 static int la_store_op(struct la_context *ac,
-                      enum la_op op, struct ldb_val *dn,
+                      enum la_op op, 
+                      const struct dsdb_attribute *schema_attr,
+                      struct ldb_val *dn,
                       const char *name)
 {
        struct ldb_context *ldb;
        struct la_op_store *os;
        struct ldb_dn *op_dn;
+       struct dsdb_dn *dsdb_dn;
        int ret;
 
        ldb = ldb_module_get_ctx(ac->module);
 
-       op_dn = ldb_dn_from_ldb_val(ac, ldb, dn);
-       if (!op_dn) {
-               ldb_asprintf_errstring(ldb,
-                                      "could not parse attribute as a DN");
-               return LDB_ERR_INVALID_DN_SYNTAX;
-       }
 
        os = talloc_zero(ac, struct la_op_store);
        if (!os) {
                return ldb_oom(ldb);
        }
 
+       dsdb_dn = dsdb_dn_parse(os, ldb, dn, schema_attr->syntax->ldap_oid);
+
+       if (!dsdb_dn) {
+               ldb_asprintf_errstring(ldb,
+                                      "could not parse attribute as a DN");
+               TALLOC_FREE(os);
+               return LDB_ERR_INVALID_DN_SYNTAX;
+       }
+
+       op_dn = dsdb_dn->dn;
+
        os->op = op;
 
        ret = la_guid_from_dn(ac->module, ac->req, op_dn, &os->guid);
@@ -319,6 +327,7 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
 
                for (j = 0; j < el->num_values; j++) {
                        ret = la_store_op(ac, LA_OP_ADD,
+                                         schema_attr,
                                          &el->values[j],
                                          attr_name);
                        if (ret != LDB_SUCCESS) {
@@ -423,6 +432,7 @@ static int la_mod_search_callback(struct ldb_request *req, struct ldb_reply *are
                        /* Now we know what was there, we can remove it for the re-add */
                        for (j = 0; j < search_el->num_values; j++) {
                                ret = la_store_op(ac, LA_OP_DEL,
+                                                 schema_attr, 
                                                  &search_el->values[j],
                                                  attr_name);
                                if (ret != LDB_SUCCESS) {
@@ -570,6 +580,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                        /* For each value being added, we need to setup the adds */
                        for (j = 0; j < el->num_values; j++) {
                                ret = la_store_op(ac, LA_OP_ADD,
+                                                 schema_attr,
                                                  &el->values[j],
                                                  attr_name);
                                if (ret != LDB_SUCCESS) {
@@ -584,6 +595,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                                /* For each value being deleted, we need to setup the delete */
                                for (j = 0; j < el->num_values; j++) {
                                        ret = la_store_op(ac, LA_OP_DEL,
+                                                         schema_attr,
                                                          &el->values[j],
                                                          attr_name);
                                        if (ret != LDB_SUCCESS) {