s3:utils: Fix auth callback with smburl
authorAndreas Schneider <asn@samba.org>
Wed, 6 Dec 2023 12:16:53 +0000 (13:16 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 10 Dec 2023 22:22:51 +0000 (22:22 +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>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Sun Dec 10 22:22:51 UTC 2023 on atb-devel-224

source3/utils/smbget.c

index dc8dace8a55988a6dbbe94999660746840c0d09b..70b3685c89fb1c7d24011430b0f7b784b04458df 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);