s4-libnet: Raise NTSTATUSError not RuntimeError in keytab export
authorAndrew Bartlett <abartlet@samba.org>
Thu, 7 Mar 2024 02:34:37 +0000 (15:34 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 14 Mar 2024 22:06:39 +0000 (22:06 +0000)
We should never raise RuntimeError if we have a better option.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
source4/libnet/py_net_dckeytab.c

index 597b30b42fdd7c54d0e2397add741262d43c9d2e..a50f575679d8601137d797248acbefb14def6965 100644 (file)
@@ -27,6 +27,7 @@
 #include "py_net.h"
 #include "libnet_export_keytab.h"
 #include "pyldb.h"
+#include "libcli/util/pyerrors.h"
 
 void initdckeytab(void);
 
@@ -72,9 +73,12 @@ static PyObject *py_net_export_keytab(py_net_Object *self, PyObject *args, PyObj
        }
 
        status = libnet_export_keytab(self->libnet_ctx, mem_ctx, &r);
-       if (NT_STATUS_IS_ERR(status)) {
-               PyErr_SetString(PyExc_RuntimeError,
-                               r.out.error_string?r.out.error_string:nt_errstr(status));
+
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_SetNTSTATUS_and_string(status,
+                                            r.out.error_string
+                                            ? r.out.error_string
+                                            : nt_errstr(status));
                talloc_free(mem_ctx);
                return NULL;
        }