]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:pyrpc: allow connections with raise_result_exceptions=False
authorStefan Metzmacher <metze@samba.org>
Tue, 28 Jan 2025 13:57:53 +0000 (14:57 +0100)
committerJule Anger <janger@samba.org>
Mon, 3 Feb 2025 14:53:10 +0000 (14:53 +0000)
This is needed in order to do useful tests with
specific error codes and still checking all other
out parameters.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
(cherry picked from commit 6b1ff9a38fcddbe72b00e28960414526a42bde14)

pidl/lib/Parse/Pidl/Samba4/Python.pm
source4/librpc/rpc/pyrpc.h
source4/librpc/rpc/pyrpc_util.c
source4/librpc/rpc/pyrpc_util.h

index 7a415c99c3abf1676ed265af380a9e5306a69868..285e4321b19684dff3da092bf8b9f091ad03a477 100644 (file)
@@ -967,10 +967,9 @@ sub PythonFunctionUnpackOut($$$)
        my $env = GenerateFunctionOutEnv($fn, "r->");
        my $result_size = 0;
 
-       $self->pidl("static PyObject *$outfnname(struct $fn->{NAME} *r)");
+       $self->pidl("static PyObject *$outfnname(struct $fn->{NAME} *r, bool raise_result_exception)");
        $self->pidl("{");
        $self->indent;
-       $self->pidl("_UNUSED_ bool raise_result_exception = true;");
        foreach my $e (@{$fn->{ELEMENTS}}) {
                next unless (grep(/out/,@{$e->{DIRECTION}}));
                next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or
index 390e01a11967119dfab3c4811be9c9b1adba462c..09f4a1abd7ed72dc09b137f6dd6569da6f6871d2 100644 (file)
@@ -50,6 +50,7 @@ typedef struct {
        struct dcerpc_pipe *pipe;
        struct dcerpc_binding_handle *binding_handle;
        struct tevent_context *ev;
+       bool raise_result_exceptions;
 } dcerpc_InterfaceObject;
 
 
index 43c29af0e76ab636eb32b599c94b7f08f65b674f..a0910b4f802dca2814b6ee516d5250e2e6476b11 100644 (file)
@@ -102,11 +102,29 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, Py
        PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None, *py_basis = Py_None;
        NTSTATUS status;
        unsigned int timeout = (unsigned int)-1;
+       int raise_result_exceptions = 1;
        const char *kwnames[] = {
-               "binding", "lp_ctx", "credentials", "timeout", "basis_connection", NULL
+               "binding",
+               "lp_ctx",
+               "credentials",
+               "timeout",
+               "basis_connection",
+               "raise_result_exceptions",
+               NULL
        };
-
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOIO:samr", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials, &timeout, &py_basis)) {
+       bool ok;
+
+       ok = PyArg_ParseTupleAndKeywords(args,
+                                        kwargs,
+                                        "s|OOIOp",
+                                        discard_const_p(char *, kwnames),
+                                        &binding_string,
+                                        &py_lp_ctx,
+                                        &py_credentials,
+                                        &timeout,
+                                        &py_basis,
+                                        &raise_result_exceptions);
+       if (!ok) {
                return NULL;
        }
 
@@ -122,6 +140,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, Py
                return NULL;
        }
 
+       ret->raise_result_exceptions = (raise_result_exceptions != 0);
        ret->pipe = NULL;
        ret->binding_handle = NULL;
        ret->ev = NULL;
@@ -300,7 +319,7 @@ static PyObject *py_dcerpc_run_function(dcerpc_InterfaceObject *iface,
                return NULL;
        }
 
-       result = md->unpack_out_data(r);
+       result = md->unpack_out_data(r, iface->raise_result_exceptions);
 
        talloc_free(mem_ctx);
        return result;
index 73157fcba1c2d6ea9f4f5aa377ca6f209fc3f3e3..8da68a3555a11ef9aa89a7bdeac3a842ecb00547 100644 (file)
@@ -34,7 +34,7 @@ void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status);
 
 typedef NTSTATUS (*py_dcerpc_call_fn) (struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
 typedef bool (*py_data_pack_fn) (PyObject *args, PyObject *kwargs, void *r);
-typedef PyObject *(*py_data_unpack_fn) (void *r);
+typedef PyObject *(*py_data_unpack_fn) (void *r, bool raise_result_exception);
 
 struct PyNdrRpcMethodDef {
        const char *name;