dsdb: make get_parsed_dns_trusted() a common helper function
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 9 Jan 2019 02:12:43 +0000 (15:12 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 13 Feb 2019 03:15:14 +0000 (04:15 +0100)
We are already using it in two places, and are about to add a third.

The version in repl_meta_data.c did more work in the case that the
parsed_dns can't really be trusted to conform to the expected format;
this is now a wrapper called get_parsed_dns_trusted_fallback().

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/common/util_links.c
source4/dsdb/common/util_links.h
source4/dsdb/samdb/ldb_modules/repl_meta_data.c
source4/rpc_server/drsuapi/getncchanges.c

index cf1f4be58bdcb51c97943225855f2ffc8b8c1b1b..daa4b2f43a6b0f2568970a9a2b0574f5ce537f36 100644 (file)
@@ -110,6 +110,25 @@ int really_parse_trusted_dn(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
 }
 
 
+int get_parsed_dns_trusted(TALLOC_CTX *mem_ctx, struct ldb_message_element *el,
+                                 struct parsed_dn **pdn)
+{
+       /* Here we get a list of 'struct parsed_dns' without the parsing */
+       int i;
+       *pdn = talloc_zero_array(mem_ctx, struct parsed_dn,
+                                el->num_values);
+       if (!*pdn) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       for (i = 0; i < el->num_values; i++) {
+               (*pdn)[i].v = &el->values[i];
+       }
+
+       return LDB_SUCCESS;
+}
+
+
 int parsed_dn_find(struct ldb_context *ldb, struct parsed_dn *pdn,
                   unsigned int count,
                   const struct GUID *guid,
index c529cb542517f102fef5331021dc95e080798638..e6dc41b636fe13eb6a6c1b2b7b1a23195de5acb3 100644 (file)
@@ -40,4 +40,9 @@ struct parsed_dn {
        struct ldb_val *v;
 };
 
+
+int get_parsed_dns_trusted(TALLOC_CTX *mem_ctx,
+                          struct ldb_message_element *el,
+                          struct parsed_dn **pdn);
+
 #endif /* __DSDB_COMMON_UTIL_LINKS_H__ */
index cfa63af706690befa2886e22aa1e20f5ce62c485..fbb9fd88313f75cd628264cfda0d25132f8327d1 100644 (file)
@@ -2142,15 +2142,14 @@ static int get_parsed_dns(struct ldb_module *module, TALLOC_CTX *mem_ctx,
  * We also ensure that the links are in the Functional Level 2003
  * linked attributes format.
  */
-static int get_parsed_dns_trusted(struct ldb_module *module,
-                                 struct replmd_private *replmd_private,
-                                 TALLOC_CTX *mem_ctx,
-                                 struct ldb_message_element *el,
-                                 struct parsed_dn **pdn,
-                                 const char *ldap_oid,
-                                 struct ldb_request *parent)
+static int get_parsed_dns_trusted_fallback(struct ldb_module *module,
+                                          struct replmd_private *replmd_private,
+                                          TALLOC_CTX *mem_ctx,
+                                          struct ldb_message_element *el,
+                                          struct parsed_dn **pdn,
+                                          const char *ldap_oid,
+                                          struct ldb_request *parent)
 {
-       unsigned int i;
        int ret;
        if (el == NULL) {
                *pdn = NULL;
@@ -2167,17 +2166,11 @@ static int get_parsed_dns_trusted(struct ldb_module *module,
                        return ret;
                }
        } else {
-               /* Here we get a list of 'struct parsed_dns' without the parsing */
-               *pdn = talloc_zero_array(mem_ctx, struct parsed_dn,
-                                        el->num_values);
-               if (!*pdn) {
+               ret = get_parsed_dns_trusted(mem_ctx, el, pdn);
+               if (ret != LDB_SUCCESS) {
                        ldb_module_oom(module);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
-
-               for (i = 0; i < el->num_values; i++) {
-                       (*pdn)[i].v = &el->values[i];
-               }
        }
 
        /*
@@ -2318,10 +2311,10 @@ static int replmd_check_upgrade_links(struct ldb_context *ldb,
 
        /*
         * This sort() is critical for the operation of
-        * get_parsed_dns_trusted() because callers of this function
+        * get_parsed_dns_trusted_fallback() because callers of this function
         * expect a sorted list, and FL2000 style links are not
         * sorted.  In particular, as well as the upgrade case,
-        * get_parsed_dns_trusted() is called from
+        * get_parsed_dns_trusted_fallback() is called from
         * replmd_delete_remove_link() even in FL2000 mode
         *
         * We do not normally pay the cost of the qsort() due to the
@@ -2496,9 +2489,10 @@ static int replmd_modify_la_add(struct ldb_module *module,
        }
 
        /* get the existing DNs, lazily parsed */
-       ret = get_parsed_dns_trusted(module, replmd_private,
-                                    tmp_ctx, old_el, &old_dns,
-                                    schema_attr->syntax->ldap_oid, parent);
+       ret = get_parsed_dns_trusted_fallback(module, replmd_private,
+                                             tmp_ctx, old_el, &old_dns,
+                                             schema_attr->syntax->ldap_oid,
+                                             parent);
 
        if (ret != LDB_SUCCESS) {
                talloc_free(tmp_ctx);
@@ -2820,9 +2814,10 @@ static int replmd_modify_la_delete(struct ldb_module *module,
                return ret;
        }
 
-       ret = get_parsed_dns_trusted(module, replmd_private,
-                                    tmp_ctx, old_el, &old_dns,
-                                    schema_attr->syntax->ldap_oid, parent);
+       ret = get_parsed_dns_trusted_fallback(module, replmd_private,
+                                             tmp_ctx, old_el, &old_dns,
+                                             schema_attr->syntax->ldap_oid,
+                                             parent);
 
        if (ret != LDB_SUCCESS) {
                talloc_free(tmp_ctx);
@@ -4086,9 +4081,11 @@ static int replmd_delete_remove_link(struct ldb_module *module,
                 * this is safe to call in FL2000 or on databases that
                 * have been run at that level in the past.
                 */
-               ret = get_parsed_dns_trusted(module, replmd_private, tmp_ctx,
-                                            link_el, &link_dns,
-                                            target_attr->syntax->ldap_oid, parent);
+               ret = get_parsed_dns_trusted_fallback(module, replmd_private,
+                                               tmp_ctx,
+                                               link_el, &link_dns,
+                                               target_attr->syntax->ldap_oid,
+                                               parent);
                if (ret != LDB_SUCCESS) {
                        talloc_free(tmp_ctx);
                        return ret;
@@ -8333,11 +8330,12 @@ static int replmd_process_la_group(struct ldb_module *module,
                 * group, so we try to minimize the times we do it)
                 */
                if (pdn_list == NULL) {
-                       ret = get_parsed_dns_trusted(module, replmd_private,
-                                                    tmp_ctx, old_el,
-                                                    &pdn_list,
-                                                    attr->syntax->ldap_oid,
-                                                    NULL);
+                       ret = get_parsed_dns_trusted_fallback(module,
+                                                       replmd_private,
+                                                       tmp_ctx, old_el,
+                                                       &pdn_list,
+                                                       attr->syntax->ldap_oid,
+                                                       NULL);
 
                        if (ret != LDB_SUCCESS) {
                                return ret;
index 9c6b9801d7f679bc51946a193710ce2461d85abe..9a4da547e04fee64014c98d47d651bd11d374659 100644 (file)
@@ -225,28 +225,6 @@ fail:
        }
 }
 
-/*
- * Similar to function in repl_meta_data without the extra
- * dependencies.
- */
-static WERROR get_parsed_dns_trusted(TALLOC_CTX *mem_ctx, struct ldb_message_element *el,
-                                 struct parsed_dn **pdn)
-{
-       /* Here we get a list of 'struct parsed_dns' without the parsing */
-       int i;
-       *pdn = talloc_zero_array(mem_ctx, struct parsed_dn,
-                                el->num_values);
-       if (!*pdn) {
-               return WERR_DS_DRA_INTERNAL_ERROR;
-       }
-
-       for (i = 0; i < el->num_values; i++) {
-               (*pdn)[i].v = &el->values[i];
-       }
-
-       return WERR_OK;
-}
-
 static WERROR getncchanges_update_revealed_list(struct ldb_context *sam_ctx,
                                                TALLOC_CTX *mem_ctx,
                                                struct ldb_message **msg,
@@ -290,13 +268,12 @@ static WERROR getncchanges_update_revealed_list(struct ldb_context *sam_ctx,
                /* Replace the old value (if one exists) with the current one */
                struct parsed_dn *link_dns;
                struct parsed_dn *exact = NULL, *unused = NULL;
-               WERROR werr;
                uint8_t attid[4];
                DATA_BLOB partial_meta;
 
-               werr = get_parsed_dns_trusted(mem_ctx, existing, &link_dns);
-               if (!W_ERROR_IS_OK(werr)) {
-                       return werr;
+               ldb_err = get_parsed_dns_trusted(mem_ctx, existing, &link_dns);
+               if (ldb_err != LDB_SUCCESS) {
+                       return WERR_DS_DRA_INTERNAL_ERROR;
                }
 
                /* Construct a partial metadata blob to match on in the DB */