]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli/util: let nt_errstr() fallback to hresult_errstr()
authorStefan Metzmacher <metze@samba.org>
Mon, 16 Dec 2024 13:46:19 +0000 (14:46 +0100)
committerGünther Deschner <gd@samba.org>
Wed, 18 Dec 2024 18:30:08 +0000 (18:30 +0000)
Sometimes NTSTATUS fields return things like
HRES_SEC_E_WRONG_PRINCIPAL.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
Autobuild-User(master): Günther Deschner <gd@samba.org>
Autobuild-Date(master): Wed Dec 18 18:30:08 UTC 2024 on atb-devel-224

libcli/util/nterr.c

index cfe89f2d7ea28d5b458525889a549df3a9c22353..91042024c9d482903306722adb1abc8a7a70e9b0 100644 (file)
@@ -346,6 +346,21 @@ const char *nt_errstr(NTSTATUS nt_code)
                idx++;
        }
 
+       /*
+        * NTSTATUS codes have 0xC000 in the upper 16-bit, if the
+        * upper 16-bit are not 0 and not 0xC000, it's likely
+        * an HRESULT.
+        *
+        * E.g. we should display HRES_SEC_E_WRONG_PRINCIPAL instead of
+        * 'NT code 0x80090322'
+        */
+       if ((NT_STATUS_V(nt_code) & 0xFFFF0000) != 0 &&
+           (NT_STATUS_V(nt_code) & 0xFFFF0000) != 0xC0000000)
+       {
+               HRESULT hres = HRES_ERROR(NT_STATUS_V(nt_code));
+               return hresult_errstr(hres);
+       }
+
        /*
         * This should not really happen, we should have all error codes
         * available. We have a problem that this might get wrongly