]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
auth:creds: Allow to reset the realm by passing NULL
authorAndreas Schneider <asn@samba.org>
Wed, 6 Aug 2025 12:40:34 +0000 (14:40 +0200)
committerAlexander Bokovoy <ab@samba.org>
Mon, 25 Aug 2025 11:03:38 +0000 (11:03 +0000)
This is e.g. done by cli_credentials_set_anonymous().

We can't call TALLOC_FREE(cred->realm), as this would break
cli_credentials_shallow_copy().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15893

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
auth/credentials/credentials.c

index c31470a81d20ab389e8b86c9e06e126e04cf705a..5588a355c744630449aed3049f9051fa9002055d 100644 (file)
@@ -933,7 +933,14 @@ _PUBLIC_ bool cli_credentials_set_realm(struct cli_credentials *cred,
                               enum credentials_obtained obtained)
 {
        if (obtained >= cred->realm_obtained) {
-               cred->realm = strupper_talloc(cred, val);
+               /* If `val = NULL` is passed, realm is reset */
+               cred->realm = NULL;
+               if (val != NULL) {
+                       cred->realm = strupper_talloc(cred, val);
+                       if (cred->realm == NULL) {
+                               return false;
+                       }
+               }
                cred->realm_obtained = obtained;
                cli_credentials_invalidate_ccache(cred, cred->realm_obtained);
                return true;