From 1b6096a1dff7e9ba67fa0e5a0932959f0f3ae0b6 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 6 Dec 2023 13:16:53 +0100 Subject: [PATCH] s3:utils: Fix auth callback with smburl BUG: https://bugzilla.samba.org/show_bug.cgi?id=15532 Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett (cherry picked from commit f2f7ed419e03e5ae8cc85f42af5b2bcf91abefe2) Autobuild-User(v4-19-test): Jule Anger Autobuild-Date(v4-19-test): Tue Dec 12 10:01:36 UTC 2023 on atb-devel-224 --- source3/utils/smbget.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c index 8d98ba24602..598607ea391 100644 --- a/source3/utils/smbget.c +++ b/source3/utils/smbget.c @@ -114,20 +114,48 @@ static void get_auth_data_with_context_fn(SMBCCTX *ctx, const char *username = NULL; const char *password = NULL; const char *domain = NULL; + enum credentials_obtained obtained = CRED_UNINITIALISED; - username = cli_credentials_get_username(creds); + username = cli_credentials_get_username_and_obtained(creds, &obtained); if (username != NULL) { - strncpy(usr, username, usr_len - 1); + bool overwrite = false; + if (usr[0] == '\0') { + overwrite = true; + } + if (obtained >= CRED_CALLBACK_RESULT) { + overwrite = true; + } + if (overwrite) { + strncpy(usr, username, usr_len - 1); + } } - password = cli_credentials_get_password(creds); + password = cli_credentials_get_password_and_obtained(creds, &obtained); if (password != NULL) { - strncpy(pwd, password, pwd_len - 1); + bool overwrite = false; + if (usr[0] == '\0') { + overwrite = true; + } + if (obtained >= CRED_CALLBACK_RESULT) { + overwrite = true; + } + if (overwrite) { + strncpy(pwd, password, pwd_len - 1); + } } - domain = cli_credentials_get_domain(creds); + domain = cli_credentials_get_domain_and_obtained(creds, &obtained); if (domain != NULL) { - strncpy(dom, domain, dom_len - 1); + bool overwrite = false; + if (usr[0] == '\0') { + overwrite = true; + } + if (obtained >= CRED_CALLBACK_RESULT) { + overwrite = true; + } + if (overwrite) { + strncpy(dom, domain, dom_len - 1); + } } smbc_set_credentials_with_fallback(ctx, domain, username, password); -- 2.11.4.GIT