s4-drs: use dsdb linked attribute parse functions
authorAndrew Tridgell <tridge@samba.org>
Mon, 28 Dec 2009 06:19:29 +0000 (17:19 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 1 Jan 2010 21:16:54 +0000 (08:16 +1100)
This makes the code considerably more readable

source4/dsdb/samdb/ldb_modules/repl_meta_data.c
source4/rpc_server/drsuapi/getncchanges.c

index 3c713ec4d9ea035579f2bf2048269138a68874fc..baae44a30da5c4bace6767caad56c5aaf07ba0d3 100644 (file)
@@ -3345,9 +3345,7 @@ static int replmd_process_linked_attribute(struct ldb_module *module,
        const struct dsdb_attribute *attr;
        struct dsdb_dn *dsdb_dn;
        uint64_t seq_num = 0;
-       struct drsuapi_DsReplicaAttribute drs;
-       struct drsuapi_DsAttributeValue val;
-       struct ldb_message_element new_el, *old_el;
+       struct ldb_message_element *old_el;
        WERROR status;
        time_t t = time(NULL);
        struct ldb_result *res;
@@ -3358,10 +3356,6 @@ static int replmd_process_linked_attribute(struct ldb_module *module,
        bool active = (la->flags & DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE)?true:false;
        const struct GUID *our_invocation_id;
 
-       drs.value_ctr.num_values = 1;
-       drs.value_ctr.values = &val;
-       val.blob = la->value.blob;
-
 /*
 linked_attributes[0]:                                                     
      &objs->linked_attributes[i]: struct drsuapi_DsReplicaLinkedAttribute 
@@ -3462,23 +3456,10 @@ linked_attributes[0]:
                return ret;
        }
 
-       status = attr->syntax->drsuapi_to_ldb(ldb, schema, attr, &drs, tmp_ctx, &new_el);
+       status = dsdb_dn_la_from_blob(ldb, attr, schema, tmp_ctx, la->value.blob, &dsdb_dn);
        if (!W_ERROR_IS_OK(status)) {
-               ldb_asprintf_errstring(ldb, "Failed to parsed linked attribute blob for %s on %s\n",
-                                      old_el->name, ldb_dn_get_linearized(msg->dn));
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
-       if (new_el.num_values != 1) {
-               ldb_asprintf_errstring(ldb, "Failed to find value in linked attribute blob for %s on %s\n",
-                                      old_el->name, ldb_dn_get_linearized(msg->dn));
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
-       dsdb_dn = dsdb_dn_parse(tmp_ctx, ldb, &new_el.values[0], attr->syntax->ldap_oid);
-       if (!dsdb_dn) {
-               ldb_asprintf_errstring(ldb, "Failed to parse DN in linked attribute blob for %s on %s\n",
-                                      old_el->name, ldb_dn_get_linearized(msg->dn));
+               ldb_asprintf_errstring(ldb, "Failed to parsed linked attribute blob for %s on %s - %s\n",
+                                      old_el->name, ldb_dn_get_linearized(msg->dn), win_errstr(status));
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
index cf4b637c0c6740bfc4f9b8915af16b545c911331..dc4483c8f88695a5c9e2108b45ebb3cf4f5b94f6 100644 (file)
@@ -246,10 +246,7 @@ static WERROR get_nc_changes_add_la(TALLOC_CTX *mem_ctx,
        struct drsuapi_DsReplicaLinkedAttribute *la;
        bool active;
        NTSTATUS status;
-       struct ldb_message_element val_el;
-       struct ldb_val v;
        WERROR werr;
-       struct drsuapi_DsReplicaAttribute drs;
 
        (*la_list) = talloc_realloc(mem_ctx, *la_list, struct drsuapi_DsReplicaLinkedAttribute, (*la_count)+1);
        W_ERROR_HAVE_NO_MEMORY(*la_list);
@@ -285,24 +282,9 @@ static WERROR get_nc_changes_add_la(TALLOC_CTX *mem_ctx,
                return ntstatus_to_werror(status);
        }
 
-       /* we need a message_element with just one value in it */
-       v = data_blob_string_const(dsdb_dn_get_extended_linearized(*la_list, dsdb_dn, 1));
-
-       val_el.name = sa->lDAPDisplayName;
-       val_el.values = &v;
-       val_el.num_values = 1;
-
-       werr = sa->syntax->ldb_to_drsuapi(sam_ctx, schema, sa, &val_el, *la_list, &drs);
+       werr = dsdb_dn_la_to_blob(sam_ctx, sa, schema, *la_list, dsdb_dn, &la->value.blob);
        W_ERROR_NOT_OK_RETURN(werr);
 
-       if (drs.value_ctr.num_values != 1) {
-               DEBUG(1,(__location__ ": Failed to build DRS blob for linked attribute %s in %s\n",
-                        sa->lDAPDisplayName, ldb_dn_get_linearized(msg->dn)));
-               return WERR_DS_DRA_INTERNAL_ERROR;
-       }
-
-       la->value.blob = drs.value_ctr.values[0].blob;
-
        (*la_count)++;
        return WERR_OK;
 }