libcli/util: let win_errstr() fallback to hresult_errstr()
authorStefan Metzmacher <metze@samba.org>
Fri, 18 Aug 2023 08:59:00 +0000 (10:59 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 17 Oct 2023 19:20:38 +0000 (19:20 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
libcli/util/doserr.c
python/samba/tests/blackbox/ndrdump.py

index b9553dfac5e7fb6a1a137393ab97c6cc08d0c1c4..c30abc8df3650ddd431d679f0f5fdb707048214f 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "replace.h"
 #include "libcli/util/werror.h"
+#include "libcli/util/hresult.h"
 
 struct werror_code_struct {
         const char *dos_errstr;
@@ -112,6 +113,19 @@ const char *win_errstr(WERROR werror)
                break;
        }
 
+       /*
+        * WERROR codes are 16-bit only, if the
+        * upper 16-bit are not 0, it's likely
+        * an HRESULT.
+        *
+        * E.g. we should display HRES_SEC_E_WRONG_PRINCIPAL instead of
+        * 'DOS code 0x80090322'
+        */
+       if ((W_ERROR_V(werror) & 0xFFFF0000) != 0) {
+               HRESULT hres = HRES_ERROR(W_ERROR_V(werror));
+               return hresult_errstr(hres);
+       }
+
        slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
 
         return msg;
index c3b7ff70ac297333ed6490638a08cfab06090c98..b7bdae68ee99f148d4bc42233a0ae131ba095ef6 100644 (file)
@@ -356,7 +356,7 @@ WARNING! 2 unread bytes
                         info                     : union spoolss_FormInfo(case 0)
             needed                   : *
                 needed                   : 0x00000000 (0)
-            result                   : DOS code 0xa9a9a900
+            result                   : HRES code 0xa9a9a900
 dump OK
 '''
         try: