cli_netlogon: Factor out rpccli_setup_netlogon_creds_locked
authorVolker Lendecke <vl@samba.org>
Sun, 17 Sep 2017 14:31:28 +0000 (07:31 -0700)
committerVolker Lendecke <vl@samba.org>
Mon, 25 Sep 2017 07:43:13 +0000 (09:43 +0200)
This does the reqchallenge/serverauth while assuming we have the
netlogon_creds_cli_lck already held. The _locked flavor will be called
from a routine that covers more under one single lock.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/rpc_client/cli_netlogon.c
source3/rpc_client/cli_netlogon.h

index ccbba960a5270e7af777a18b41867d444e75ad77..8a866fe8aa5fdd071ba553bef9725acaaf149508 100644 (file)
@@ -153,7 +153,7 @@ NTSTATUS rpccli_create_netlogon_creds_ctx(
                                            creds_ctx);
 }
 
-NTSTATUS rpccli_setup_netlogon_creds(
+NTSTATUS rpccli_setup_netlogon_creds_locked(
        struct cli_state *cli,
        enum dcerpc_transport_t transport,
        struct netlogon_creds_cli_context *creds_ctx,
@@ -166,19 +166,8 @@ NTSTATUS rpccli_setup_netlogon_creds(
        uint8_t num_nt_hashes = 0;
        const struct samr_Password *nt_hashes[2] = { NULL, NULL };
        uint8_t idx_nt_hashes = 0;
-       struct netlogon_creds_cli_lck *lck = NULL;
        NTSTATUS status;
 
-       status = netlogon_creds_cli_lck(
-               creds_ctx, NETLOGON_CREDS_CLI_LCK_EXCLUSIVE,
-               frame, &lck);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_WARNING("netlogon_creds_cli_lck failed: %s\n",
-                           nt_errstr(status));
-               TALLOC_FREE(frame);
-               return status;
-       }
-
        status = netlogon_creds_cli_get(creds_ctx, frame, &creds);
        if (NT_STATUS_IS_OK(status)) {
                const char *action = "using";
@@ -241,8 +230,6 @@ NTSTATUS rpccli_setup_netlogon_creds(
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       TALLOC_FREE(lck);
-
        DEBUG(5,("%s: using new netlogon_creds cli[%s/%s] to %s\n",
                 __FUNCTION__,
                 creds->account_name, creds->computer_name,
@@ -252,6 +239,35 @@ NTSTATUS rpccli_setup_netlogon_creds(
        return NT_STATUS_OK;
 }
 
+NTSTATUS rpccli_setup_netlogon_creds(
+       struct cli_state *cli,
+       enum dcerpc_transport_t transport,
+       struct netlogon_creds_cli_context *creds_ctx,
+       bool force_reauth,
+       struct cli_credentials *cli_creds)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct netlogon_creds_cli_lck *lck;
+       NTSTATUS status;
+
+       status = netlogon_creds_cli_lck(
+               creds_ctx, NETLOGON_CREDS_CLI_LCK_EXCLUSIVE,
+               frame, &lck);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_WARNING("netlogon_creds_cli_lck failed: %s\n",
+                           nt_errstr(status));
+               TALLOC_FREE(frame);
+               return status;
+       }
+
+       status = rpccli_setup_netlogon_creds_locked(
+               cli, transport, creds_ctx, force_reauth, cli_creds);
+
+       TALLOC_FREE(frame);
+
+       return status;
+}
+
 static NTSTATUS map_validation_to_info3(TALLOC_CTX *mem_ctx,
                                        uint16_t validation_level,
                                        union netr_Validation *validation,
index 04a370fba888075154198c931ee1f0df439ab61f..63db4762fb6605cc72e6b536e756b0e1008d5aa8 100644 (file)
@@ -39,6 +39,12 @@ NTSTATUS rpccli_create_netlogon_creds_ctx(
        struct messaging_context *msg_ctx,
        TALLOC_CTX *mem_ctx,
        struct netlogon_creds_cli_context **creds_ctx);
+NTSTATUS rpccli_setup_netlogon_creds_locked(
+       struct cli_state *cli,
+       enum dcerpc_transport_t transport,
+       struct netlogon_creds_cli_context *creds_ctx,
+       bool force_reauth,
+       struct cli_credentials *cli_creds);
 NTSTATUS rpccli_setup_netlogon_creds(
        struct cli_state *cli,
        enum dcerpc_transport_t transport,