From 25e49da1bf07946f28039e42c86023a9f4ac1d9c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 15 Dec 2023 09:41:06 +0100 Subject: [PATCH 1/2] s3:utils: Handle the domain before username and password 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 Reviewed-by: Volker Lendecke (cherry picked from commit 25021b836f74d3d247bce44c6c02a2d8b2cc39ea) --- source3/utils/smbget.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c index 598607ea391..9247ded33d0 100644 --- a/source3/utils/smbget.c +++ b/source3/utils/smbget.c @@ -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); } } -- 2.43.0 From 4140a8ba7649677875c8659225abba63a6b7f1a7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 15 Dec 2023 08:23:25 +0100 Subject: [PATCH 2/2] s3:utils: Fix the auth function to print correct values to the user 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 Reviewed-by: Volker Lendecke (cherry picked from commit 1134c4f3a63c9618c3fb79abefb40a798c7c1701) --- source3/utils/smbget.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c index 9247ded33d0..f7f83b06496 100644 --- a/source3/utils/smbget.c +++ b/source3/utils/smbget.c @@ -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); } } } -- 2.43.0