s3:utils: Fix auth callback with smburl
authorAndreas Schneider <asn@samba.org>
Wed, 6 Dec 2023 12:16:53 +0000 (13:16 +0100)
committerJule Anger <janger@samba.org>
Tue, 12 Dec 2023 10:01:36 +0000 (10:01 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15532

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit f2f7ed419e03e5ae8cc85f42af5b2bcf91abefe2)

Autobuild-User(v4-19-test): Jule Anger <janger@samba.org>
Autobuild-Date(v4-19-test): Tue Dec 12 10:01:36 UTC 2023 on atb-devel-224

source3/utils/smbget.c

index 8d98ba24602cfb9bd6b470d1b4b845918526b475..598607ea3917ea16b9f1f6340a6689c12feb1b7d 100644 (file)
@@ -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);