s3-rpc_client: Move client pipe functions to own header.
[samba.git] / source3 / libnet / libnet_dssync.c
index 37d2aaafb009e37ada137676f6cb5b19be88566a..47ceff15092a234d3dc309d6ddce488648500479 100644 (file)
 
 
 #include "includes.h"
-#include "libnet/libnet.h"
+#include "libnet/libnet_dssync.h"
+#include "rpc_client/cli_pipe.h"
 #include "../libcli/drsuapi/drsuapi.h"
-#include "../librpc/gen_ndr/cli_drsuapi.h"
+#include "../librpc/gen_ndr/ndr_drsuapi_c.h"
 
 /****************************************************************
 ****************************************************************/
 
 static int libnet_dssync_free_context(struct dssync_context *ctx)
 {
+       WERROR result;
+       struct dcerpc_binding_handle *b;
+
        if (!ctx) {
                return 0;
        }
 
        if (is_valid_policy_hnd(&ctx->bind_handle) && ctx->cli) {
-               rpccli_drsuapi_DsUnbind(ctx->cli, ctx, &ctx->bind_handle, NULL);
+               b = ctx->cli->binding_handle;
+               dcerpc_drsuapi_DsUnbind(b, ctx, &ctx->bind_handle, &result);
        }
 
        return 0;
@@ -124,6 +129,7 @@ static NTSTATUS libnet_dssync_bind(TALLOC_CTX *mem_ctx,
        struct GUID bind_guid;
        struct drsuapi_DsBindInfoCtr bind_info;
        struct drsuapi_DsBindInfo28 info28;
+       struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
 
        ZERO_STRUCT(info28);
 
@@ -164,7 +170,7 @@ static NTSTATUS libnet_dssync_bind(TALLOC_CTX *mem_ctx,
        bind_info.length = 28;
        bind_info.info.info28 = info28;
 
-       status = rpccli_drsuapi_DsBind(ctx->cli, mem_ctx,
+       status = dcerpc_drsuapi_DsBind(b, mem_ctx,
                                       &bind_guid,
                                       &bind_info,
                                       &ctx->bind_handle,
@@ -218,11 +224,12 @@ static NTSTATUS libnet_dssync_lookup_nc(TALLOC_CTX *mem_ctx,
 {
        NTSTATUS status;
        WERROR werr;
-       int32_t level = 1;
+       uint32_t level = 1;
        union drsuapi_DsNameRequest req;
-       int32_t level_out;
+       uint32_t level_out;
        struct drsuapi_DsNameString names[1];
        union drsuapi_DsNameCtr ctr;
+       struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
 
        names[0].str = talloc_asprintf(mem_ctx, "%s\\", ctx->domain_name);
        NT_STATUS_HAVE_NO_MEMORY(names[0].str);
@@ -235,7 +242,7 @@ static NTSTATUS libnet_dssync_lookup_nc(TALLOC_CTX *mem_ctx,
        req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_UNKNOWN;
        req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
 
-       status = rpccli_drsuapi_DsCrackNames(ctx->cli, mem_ctx,
+       status = dcerpc_drsuapi_DsCrackNames(b, mem_ctx,
                                             &ctx->bind_handle,
                                             level,
                                             &req,
@@ -245,11 +252,14 @@ static NTSTATUS libnet_dssync_lookup_nc(TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(status)) {
                ctx->error_message = talloc_asprintf(ctx,
                        "Failed to lookup DN for domain name: %s",
-                       get_friendly_werror_msg(werr));
+                       get_friendly_nt_error_msg(status));
                return status;
        }
 
        if (!W_ERROR_IS_OK(werr)) {
+               ctx->error_message = talloc_asprintf(ctx,
+                       "Failed to lookup DN for domain name: %s",
+                       get_friendly_werror_msg(werr));
                return werror_to_ntstatus(werr);
        }
 
@@ -429,6 +439,7 @@ static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
        uint32_t out_level = 0;
        int y;
        bool last_query;
+       struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
 
        if (!ctx->single_object_replication) {
                new_utdv = TALLOC_ZERO_P(mem_ctx, struct replUpToDateVectorBlob);
@@ -441,6 +452,8 @@ static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
        for (y=0, last_query = false; !last_query; y++) {
                struct drsuapi_DsReplicaObjectListItemEx *first_object = NULL;
                struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr = NULL;
+               uint32_t linked_attributes_count = 0;
+               struct drsuapi_DsReplicaLinkedAttribute *linked_attributes = NULL;
 
                if (level == 8) {
                        DEBUG(1,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
@@ -452,7 +465,7 @@ static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
                                (long long)req->req5.highwatermark.highest_usn));
                }
 
-               status = rpccli_drsuapi_DsGetNCChanges(ctx->cli, mem_ctx,
+               status = dcerpc_drsuapi_DsGetNCChanges(b, mem_ctx,
                                                       &ctx->bind_handle,
                                                       level,
                                                       req,
@@ -462,12 +475,15 @@ static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
                if (!NT_STATUS_IS_OK(status)) {
                        ctx->error_message = talloc_asprintf(ctx,
                                "Failed to get NC Changes: %s",
-                               get_friendly_werror_msg(werr));
+                               get_friendly_nt_error_msg(status));
                        goto out;
                }
 
                if (!W_ERROR_IS_OK(werr)) {
                        status = werror_to_ntstatus(werr);
+                       ctx->error_message = talloc_asprintf(ctx,
+                               "Failed to get NC Changes: %s",
+                               get_friendly_werror_msg(werr));
                        goto out;
                }
 
@@ -524,6 +540,9 @@ static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
                        first_object = ctr6->first_object;
                        mapping_ctr = &ctr6->mapping_ctr;
 
+                       linked_attributes = ctr6->linked_attributes;
+                       linked_attributes_count = ctr6->linked_attributes_count;
+
                        if (ctr6->more_data) {
                                req->req8.highwatermark = ctr6->new_highwatermark;
                        } else {
@@ -563,6 +582,23 @@ static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
                                goto out;
                        }
                }
+
+               if (linked_attributes_count == 0) {
+                       continue;
+               }
+
+               if (ctx->ops->process_links) {
+                       status = ctx->ops->process_links(ctx, mem_ctx,
+                                                        linked_attributes_count,
+                                                        linked_attributes,
+                                                        mapping_ctr);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               ctx->error_message = talloc_asprintf(ctx,
+                                       "Failed to call processing function: %s",
+                                       nt_errstr(status));
+                               goto out;
+                       }
+               }
        }
 
        *pnew_utdv = new_utdv;