s3-lib: Do not set an empty string in split_domain_user()
[samba.git] / source3 / libnet / libnet_samsync.c
index 6e416af180ce0c46ed7a8c5e193854c5fc9f07a7..e7e1393fdc855d1d50cd35af92fb1007b1aba539 100644 (file)
 
 #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"
 #include "../librpc/gen_ndr/ndr_netlogon.h"
-#include "../librpc/gen_ndr/cli_netlogon.h"
-#include "../libcli/security/dom_sid.h"
+#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
@@ -69,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) {
@@ -80,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;
@@ -199,35 +200,44 @@ static NTSTATUS libnet_samsync_delta(TALLOC_CTX *mem_ctx,
                                     struct samsync_context *ctx,
                                     struct netr_ChangeLogEntry *e)
 {
-       NTSTATUS result;
+       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;
        uint32_t sync_context = 0;
+       struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
 
        ZERO_STRUCT(return_authenticator);
 
        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) {
-                       result = rpccli_netr_DatabaseRedo(ctx->cli, mem_ctx,
+                       status = dcerpc_netr_DatabaseRedo(b, mem_ctx,
                                                          logon_server,
                                                          computername,
                                                          &credential,
                                                          &return_authenticator,
                                                          *e,
                                                          0,
-                                                         &delta_enum_array);
+                                                         &delta_enum_array,
+                                                         &result);
                } else if (!ctx->force_full_replication &&
                           sequence_num && (*sequence_num > 0)) {
-                       result = rpccli_netr_DatabaseDeltas(ctx->cli, mem_ctx,
+                       status = dcerpc_netr_DatabaseDeltas(b, mem_ctx,
                                                            logon_server,
                                                            computername,
                                                            &credential,
@@ -235,9 +245,10 @@ static NTSTATUS libnet_samsync_delta(TALLOC_CTX *mem_ctx,
                                                            database_id,
                                                            sequence_num,
                                                            &delta_enum_array,
-                                                           0xffff);
+                                                           0xffff,
+                                                           &result);
                } else {
-                       result = rpccli_netr_DatabaseSync2(ctx->cli, mem_ctx,
+                       status = dcerpc_netr_DatabaseSync2(b, mem_ctx,
                                                           logon_server,
                                                           computername,
                                                           &credential,
@@ -246,28 +257,38 @@ static NTSTATUS libnet_samsync_delta(TALLOC_CTX *mem_ctx,
                                                           restart_state,
                                                           &sync_context,
                                                           &delta_enum_array,
-                                                          0xffff);
+                                                          0xffff,
+                                                          &result);
                }
 
-               if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) {
-                       return result;
+               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,
@@ -395,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;
        }