From: Stefan Metzmacher Date: Mon, 16 Dec 2024 13:46:19 +0000 (+0100) Subject: libcli/util: let nt_errstr() fallback to hresult_errstr() X-Git-Tag: tdb-1.4.13~272 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4fcdb01808ff55935490e6bce452d1706680425d;p=thirdparty%2Fsamba.git libcli/util: let nt_errstr() fallback to hresult_errstr() Sometimes NTSTATUS fields return things like HRES_SEC_E_WRONG_PRINCIPAL. Signed-off-by: Stefan Metzmacher Reviewed-by: Guenther Deschner Autobuild-User(master): Günther Deschner Autobuild-Date(master): Wed Dec 18 18:30:08 UTC 2024 on atb-devel-224 --- diff --git a/libcli/util/nterr.c b/libcli/util/nterr.c index cfe89f2d7ea..91042024c9d 100644 --- a/libcli/util/nterr.c +++ b/libcli/util/nterr.c @@ -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