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)
committerVolker Lendecke <vl@samba.org>
Thu, 4 Jan 2024 11:26:52 +0000 (11:26 +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>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Jan  4 11:26:52 UTC 2024 on atb-devel-224

source3/utils/smbget.c

index 1deda744581dcf20015cce0f833b0c1cfdf10698..67ea259afb8463250aac34ed615d832c580f5614 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);
                }
        }
 }