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)
committerVolker Lendecke <vl@samba.org>
Thu, 4 Jan 2024 10:29:32 +0000 (10:29 +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>
source3/utils/smbget.c

index 70b3685c89fb1c7d24011430b0f7b784b04458df..1deda744581dcf20015cce0f833b0c1cfdf10698 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);
                }
        }