From: Andreas Schneider Date: Wed, 6 Dec 2023 12:16:53 +0000 (+0100) Subject: s3:utils: Fix auth callback with smburl X-Git-Tag: talloc-2.4.2~353 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2f7ed419e03e5ae8cc85f42af5b2bcf91abefe2;p=thirdparty%2Fsamba.git 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 Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Sun Dec 10 22:22:51 UTC 2023 on atb-devel-224 --- diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c index dc8dace8a55..70b3685c89f 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);