s3:utils: Handle the domain before username and password
authorAndreas Schneider <asn@samba.org>
Fri, 15 Dec 2023 08:41:06 +0000 (09:41 +0100)
committerJule Anger <janger@samba.org>
Mon, 8 Jan 2024 12:50:18 +0000 (12:50 +0000)
The cli_credentials_get_password*() function will interactively ask the
user for a password if none has been supplied via another ways. To show
the correct domain and username in the prompt, we need handle domain
and user first.

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 25021b836f74d3d247bce44c6c02a2d8b2cc39ea)

source3/utils/smbget.c

index 598607ea3917ea16b9f1f6340a6689c12feb1b7d..9247ded33d00e7fa9e84c4b07a4b737486bdf90b 100644 (file)
@@ -116,22 +116,22 @@ static void get_auth_data_with_context_fn(SMBCCTX *ctx,
        const char *domain = NULL;
        enum credentials_obtained obtained = CRED_UNINITIALISED;
 
-       username = cli_credentials_get_username_and_obtained(creds, &obtained);
-       if (username != NULL) {
+       domain = cli_credentials_get_domain_and_obtained(creds, &obtained);
+       if (domain != NULL) {
                bool overwrite = false;
-               if (usr[0] == '\0') {
+               if (dom[0] == '\0') {
                        overwrite = true;
                }
                if (obtained >= CRED_CALLBACK_RESULT) {
                        overwrite = true;
                }
                if (overwrite) {
-                       strncpy(usr, username, usr_len - 1);
+                       strncpy(dom, domain, dom_len - 1);
                }
        }
 
-       password = cli_credentials_get_password_and_obtained(creds, &obtained);
-       if (password != NULL) {
+       username = cli_credentials_get_username_and_obtained(creds, &obtained);
+       if (username != NULL) {
                bool overwrite = false;
                if (usr[0] == '\0') {
                        overwrite = true;
@@ -140,21 +140,21 @@ static void get_auth_data_with_context_fn(SMBCCTX *ctx,
                        overwrite = true;
                }
                if (overwrite) {
-                       strncpy(pwd, password, pwd_len - 1);
+                       strncpy(usr, username, usr_len - 1);
                }
        }
 
-       domain = cli_credentials_get_domain_and_obtained(creds, &obtained);
-       if (domain != NULL) {
+       password = cli_credentials_get_password_and_obtained(creds, &obtained);
+       if (password != NULL) {
                bool overwrite = false;
-               if (usr[0] == '\0') {
+               if (pwd[0] == '\0') {
                        overwrite = true;
                }
                if (obtained >= CRED_CALLBACK_RESULT) {
                        overwrite = true;
                }
                if (overwrite) {
-                       strncpy(dom, domain, dom_len - 1);
+                       strncpy(pwd, password, pwd_len - 1);
                }
        }