net: fix credentials in trustdom establish
authorRalph Boehme <slow@samba.org>
Wed, 10 Jan 2024 14:06:14 +0000 (15:06 +0100)
committerStefan Metzmacher <metze@samba.org>
Sat, 20 Jan 2024 13:20:37 +0000 (13:20 +0000)
This was broken by ea071d278a614f17b5417d3ff98e1b8d1fd8970d. I guess the whole
opt_user_specified dance should be ripped out, but that's a fix for another day.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15533

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/utils/net_rpc.c

index 2a563a85d11a97ac63cd6a5613620dfc1ce0737a..2a12b1a1335e3286d6268bd13e4d15ed4b209f56 100644 (file)
@@ -6544,6 +6544,7 @@ static int rpc_trustdom_establish(struct net_context *c, int argc,
        struct dom_sid *domain_sid;
        char* domain_name;
        char* acct_name;
+       const char *pwd = NULL;
        fstring pdc_name;
        union lsa_PolicyInformation *info = NULL;
        struct dcerpc_binding_handle *b;
@@ -6580,6 +6581,7 @@ static int rpc_trustdom_establish(struct net_context *c, int argc,
                SAFE_FREE(acct_name);
                return -1;
        }
+       cli_credentials_set_username(c->creds, acct_name, CRED_SPECIFIED);
 
        /*
         * opt_workgroup will be used by connection functions further,
@@ -6589,9 +6591,6 @@ static int rpc_trustdom_establish(struct net_context *c, int argc,
                c->opt_workgroup = smb_xstrdup(domain_name);
        };
 
-       c->opt_user_name = acct_name;
-       c->opt_user_specified = true;
-
        /* find the domain controller */
        if (!net_find_pdc(&server_ss, pdc_name, domain_name)) {
                DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
@@ -6704,7 +6703,9 @@ static int rpc_trustdom_establish(struct net_context *c, int argc,
         * Store the password in secrets db
         */
 
-       if (!pdb_set_trusteddom_pw(domain_name, c->opt_password, domain_sid)) {
+       pwd = cli_credentials_get_password(c->creds);
+
+       if (!pdb_set_trusteddom_pw(domain_name, pwd, domain_sid)) {
                DEBUG(0, ("Storing password for trusted domain failed.\n"));
                cli_shutdown(cli);
                talloc_destroy(mem_ctx);