param: rename lp function and variable from "adduser_script" to "add_user_script"
[samba.git] / source3 / libnet / libnet_samsync.c
index 1141bed730b4b6f7f7cb354254e4aec1cc8a8c73..e7e1393fdc855d1d50cd35af92fb1007b1aba539 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "includes.h"
 #include "libnet/libnet_samsync.h"
-#include "../lib/crypto/crypto.h"
 #include "../libcli/samsync/samsync.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "rpc_client/rpc_client.h"
@@ -31,6 +30,7 @@
 #include "../librpc/gen_ndr/ndr_netlogon_c.h"
 #include "../libcli/security/security.h"
 #include "messages.h"
+#include "../libcli/auth/netlogon_creds_cli.h"
 
 /**
  * Fix up the delta, dealing with encryption issues so that the final
@@ -71,7 +71,7 @@ NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx,
 
        *ctx_p = NULL;
 
-       ctx = TALLOC_ZERO_P(mem_ctx, struct samsync_context);
+       ctx = talloc_zero(mem_ctx, struct samsync_context);
        NT_STATUS_HAVE_NO_MEMORY(ctx);
 
        if (domain_sid) {
@@ -82,8 +82,7 @@ NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx,
                NT_STATUS_HAVE_NO_MEMORY(ctx->domain_sid_str);
        }
 
-       ctx->msg_ctx = messaging_init(ctx, procid_self(),
-                                     event_context_init(ctx));
+       ctx->msg_ctx = messaging_init(ctx, samba_tevent_context_init(ctx));
        NT_STATUS_HAVE_NO_MEMORY(ctx->msg_ctx);
 
        *ctx_p = ctx;
@@ -204,7 +203,7 @@ static NTSTATUS libnet_samsync_delta(TALLOC_CTX *mem_ctx,
        NTSTATUS result, status;
        NTSTATUS callback_status;
        const char *logon_server = ctx->cli->desthost;
-       const char *computername = global_myname();
+       const char *computername = lp_netbios_name();
        struct netr_Authenticator credential;
        struct netr_Authenticator return_authenticator;
        uint16_t restart_state = 0;
@@ -215,8 +214,15 @@ static NTSTATUS libnet_samsync_delta(TALLOC_CTX *mem_ctx,
 
        do {
                struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
+               struct netlogon_creds_CredentialState *creds = NULL;
 
-               netlogon_creds_client_authenticator(ctx->cli->dc, &credential);
+               status = netlogon_creds_cli_lock(ctx->netlogon_creds,
+                                                mem_ctx, &creds);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               netlogon_creds_client_authenticator(creds, &credential);
 
                if (ctx->single_object_replication &&
                    !ctx->force_full_replication) {
@@ -256,28 +262,33 @@ static NTSTATUS libnet_samsync_delta(TALLOC_CTX *mem_ctx,
                }
 
                if (!NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(creds);
                        return status;
                }
 
                /* Check returned credentials. */
-               if (!netlogon_creds_client_check(ctx->cli->dc,
+               if (!netlogon_creds_client_check(creds,
                                                 &return_authenticator.cred)) {
+                       TALLOC_FREE(creds);
                        DEBUG(0,("credentials chain check failed\n"));
                        return NT_STATUS_ACCESS_DENIED;
                }
 
                if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) {
+                       TALLOC_FREE(creds);
                        return result;
                }
 
                if (NT_STATUS_IS_ERR(result)) {
+                       TALLOC_FREE(creds);
                        break;
                }
 
                samsync_fix_delta_array(mem_ctx,
-                                       ctx->cli->dc,
+                                       creds,
                                        database_id,
                                        delta_enum_array);
+               TALLOC_FREE(creds);
 
                /* Process results */
                callback_status = ctx->ops->process_objects(mem_ctx, database_id,
@@ -405,7 +416,7 @@ NTSTATUS pull_netr_AcctLockStr(TALLOC_CTX *mem_ctx,
 
        *str_p = NULL;
 
-       str = TALLOC_ZERO_P(mem_ctx, struct netr_AcctLockStr);
+       str = talloc_zero(mem_ctx, struct netr_AcctLockStr);
        if (!str) {
                return NT_STATUS_NO_MEMORY;
        }