s3:libnet: create a cli_credential context libnet_join_joindomain_rpc_unsecure()
authorStefan Metzmacher <metze@samba.org>
Tue, 17 Sep 2013 04:13:53 +0000 (06:13 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 11 Apr 2018 07:01:11 +0000 (09:01 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/libnet/libnet_join.c

index bbe604b729ee2688fe9ec076f9ae859714712bd3..2c2eef19d9965da850c72e27d19d4e23b80299a2 100644 (file)
@@ -43,6 +43,7 @@
 #include "libcli/auth/netlogon_creds_cli.h"
 #include "auth/credentials/credentials.h"
 #include "krb5_env.h"
+#include "lib/param/param.h"
 
 /****************************************************************
 ****************************************************************/
@@ -1132,6 +1133,7 @@ static NTSTATUS libnet_join_joindomain_rpc_unsecure(TALLOC_CTX *mem_ctx,
                                                    struct cli_state *cli)
 {
        TALLOC_CTX *frame = talloc_stackframe();
+<<<<<<< HEAD
        struct rpc_pipe_client *authenticate_pipe = NULL;
        struct rpc_pipe_client *passwordset_pipe = NULL;
        struct cli_credentials *cli_creds;
@@ -1141,7 +1143,15 @@ static NTSTATUS libnet_join_joindomain_rpc_unsecure(TALLOC_CTX *mem_ctx,
        size_t len = 0;
        bool ok;
        DATA_BLOB new_trust_blob = data_blob_null;
+=======
+       struct loadparm_context *lp_ctx;
+       struct rpc_pipe_client *netlogon_pipe = NULL;
+       struct netlogon_creds_cli_context *netlogon_creds = NULL;
+       const char *account_name = NULL;
+       struct cli_credentials *cli_creds = NULL;
+>>>>>>> f2c349b... s3:libnet: create a cli_credential context libnet_join_joindomain_rpc_unsecure()
        NTSTATUS status;
+       bool ok;
 
        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon,
                                          &authenticate_pipe);
@@ -1162,6 +1172,7 @@ static NTSTATUS libnet_join_joindomain_rpc_unsecure(TALLOC_CTX *mem_ctx,
                }
        }
 
+<<<<<<< HEAD
        cli_creds = cli_credentials_init(talloc_tos());
        if (cli_creds == NULL) {
                TALLOC_FREE(frame);
@@ -1184,19 +1195,81 @@ static NTSTATUS libnet_join_joindomain_rpc_unsecure(TALLOC_CTX *mem_ctx,
                cli_creds, authenticate_pipe->desthost, r->in.msg_ctx,
                frame, &netlogon_creds);
        if (!NT_STATUS_IS_OK(status)) {
+=======
+       account_name = talloc_asprintf(frame, "%s$",
+                                      r->in.machine_name);
+       if (account_name == NULL) {
+>>>>>>> f2c349b... s3:libnet: create a cli_credential context libnet_join_joindomain_rpc_unsecure()
                TALLOC_FREE(frame);
                return status;
        }
 
+<<<<<<< HEAD
        status = rpccli_setup_netlogon_creds(
                cli, NCACN_NP, netlogon_creds, true /* force_reauth */,
                cli_creds);
+=======
+       lp_ctx = loadparm_init_s3(frame, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DEBUG(1, ("loadparm_init_s3 failed\n"));
+               TALLOC_FREE(frame);
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+       cli_creds = cli_credentials_init(frame);
+       if (cli_creds == NULL) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       cli_credentials_set_conf(cli_creds, lp_ctx);
+
+       cli_credentials_set_secure_channel_type(cli_creds,
+                                               r->in.secure_channel_type);
+
+       ok = cli_credentials_set_domain(cli_creds, r->in.domain_name,
+                                       CRED_SPECIFIED);
+       if (!ok) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       ok = cli_credentials_set_username(cli_creds, account_name,
+                                         CRED_SPECIFIED);
+       if (!ok) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       /* according to WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED */
+       ok = cli_credentials_set_password(cli_creds, r->in.admin_password,
+                                         CRED_SPECIFIED);
+       if (!ok) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = rpccli_create_netlogon_creds(netlogon_pipe->desthost,
+                                             r->in.domain_name,
+                                             account_name,
+                                             r->in.secure_channel_type,
+                                             r->in.msg_ctx,
+                                             frame,
+                                             &netlogon_creds);
+>>>>>>> f2c349b... s3:libnet: create a cli_credential context libnet_join_joindomain_rpc_unsecure()
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(frame);
                return status;
        }
 
+<<<<<<< HEAD
        status = netlogon_creds_cli_get(netlogon_creds, frame, &creds);
+=======
+       status = rpccli_setup_netlogon_creds(cli, NCACN_NP,
+                                            netlogon_creds,
+                                            true, /* force_reauth */
+                                            cli_creds);
+>>>>>>> f2c349b... s3:libnet: create a cli_credential context libnet_join_joindomain_rpc_unsecure()
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(frame);
                return status;