s3:utils: Fix the auth function to print correct values to the user
authorAndreas Schneider <asn@samba.org>
Fri, 15 Dec 2023 07:23:25 +0000 (08:23 +0100)
committerJule Anger <janger@samba.org>
Mon, 8 Jan 2024 12:50:18 +0000 (12:50 +0000)
In order to show correct values in the password prompt displayed by
cli_credentials_get_password*(). We need to set the domain and username
in the credentials system.

The credentials supplied via the SMB URL have a higher priority than the
command line options.

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

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit 1134c4f3a63c9618c3fb79abefb40a798c7c1701)

source3/utils/smbget.c

index 9247ded33d00e7fa9e84c4b07a4b737486bdf90b..f7f83b06496ec8b31dd25f1967fe233ce36782e7 100644 (file)
@@ -129,6 +129,7 @@ static void get_auth_data_with_context_fn(SMBCCTX *ctx,
                        strncpy(dom, domain, dom_len - 1);
                }
        }
+       cli_credentials_set_domain(creds, dom, obtained);
 
        username = cli_credentials_get_username_and_obtained(creds, &obtained);
        if (username != NULL) {
@@ -143,6 +144,7 @@ static void get_auth_data_with_context_fn(SMBCCTX *ctx,
                        strncpy(usr, username, usr_len - 1);
                }
        }
+       cli_credentials_set_username(creds, usr, obtained);
 
        password = cli_credentials_get_password_and_obtained(creds, &obtained);
        if (password != NULL) {
@@ -157,16 +159,17 @@ static void get_auth_data_with_context_fn(SMBCCTX *ctx,
                        strncpy(pwd, password, pwd_len - 1);
                }
        }
+       cli_credentials_set_password(creds, pwd, obtained);
 
-       smbc_set_credentials_with_fallback(ctx, domain, username, password);
+       smbc_set_credentials_with_fallback(ctx, dom, usr, pwd);
 
-       if (!opt.quiet && username != NULL) {
-               if (username[0] == '\0') {
+       if (!opt.quiet) {
+               if (usr[0] == '\0') {
                        printf("Using guest user\n");
+               } else if (dom[0] == '\0') {
+                       printf("Using user: %s\n", usr);
                } else {
-                       printf("Using domain: %s, user: %s\n",
-                               domain,
-                               username);
+                       printf("Using domain: %s, user: %s\n", dom, usr);
                }
        }
 }