summaryrefslogtreecommitdiff
path: root/source4/pidl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-01-14 05:16:51 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-01-14 19:53:06 +0100
commit3b16c532f21202696d54ef87f8fa74d066812898 (patch)
treeefe40b4053cc286332387545ccb4ef8a1d42802f /source4/pidl
parentda72bff5b72658c6cfb1980ac97475ebbc21b6f5 (diff)
downloadsamba-3b16c532f21202696d54ef87f8fa74d066812898.tar.gz
samba-3b16c532f21202696d54ef87f8fa74d066812898.tar.bz2
samba-3b16c532f21202696d54ef87f8fa74d066812898.zip
pidl/python: Pass credentials and loadparm context when connecting using DCE/RPC.
(This used to be commit 4c87af95310e4aaee3f2e2da02d0ea70ed1ec25b)
Diffstat (limited to 'source4/pidl')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/Python.pm59
1 files changed, 48 insertions, 11 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 266a092788..04649d3668 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -264,7 +264,7 @@ sub PythonFunction($$$)
$self->pidl("NTSTATUS status;");
$self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);");
$self->pidl("struct $fn->{NAME} r;");
- $self->pidl("PyObject *result;");
+ $self->pidl("PyObject *result = Py_None;");
my $env = GenerateFunctionInEnv($fn, "r.");
my $result_size = 0;
@@ -313,21 +313,33 @@ sub PythonFunction($$$)
$self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);");
$self->handle_ntstatus("status", "NULL", "mem_ctx");
- $self->pidl("result = PyTuple_New($result_size);");
-
$env = GenerateFunctionOutEnv($fn, "r.");
my $i = 0;
+ if ($result_size > 1) {
+ $self->pidl("result = PyTuple_New($result_size);");
+ }
+
foreach my $e (@{$fn->{ELEMENTS}}) {
+ my $py_name = "py_$e->{NAME}";
if (grep(/out/,@{$e->{DIRECTION}})) {
- $self->ConvertObjectToPython($env, $e, "r.out.$e->{NAME}", "py_$e->{NAME}");
- $self->pidl("PyTuple_SetItem(result, $i, py_$e->{NAME});");
- $i++;
+ $self->ConvertObjectToPython($env, $e, "r.out.$e->{NAME}", $py_name);
+ if ($result_size > 1) {
+ $self->pidl("PyTuple_SetItem(result, $i, $py_name);");
+ $i++;
+ } else {
+ $self->pidl("result = $py_name;");
+ }
}
}
if (defined($fn->{RETURN_TYPE})) {
- $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPythonData($fn->{RETURN_TYPE}, "r.out.result") . ");");
+ my $conv = $self->ConvertObjectToPythonData($fn->{RETURN_TYPE}, "r.out.result");
+ if ($result_size > 1) {
+ $self->pidl("PyTuple_SetItem(result, $i, $conv);");
+ } else {
+ $self->pidl("result = $conv;");
+ }
}
$self->pidl("talloc_free(mem_ctx);");
@@ -446,6 +458,7 @@ sub Interface($$$)
my $fn_name = $d->{NAME};
$fn_name =~ s/^$interface->{NAME}_//;
+ $fn_name =~ s/^$basename\_//;
$self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },");
}
@@ -491,25 +504,47 @@ sub Interface($$$)
$self->indent;
$self->pidl("$interface->{NAME}_InterfaceObject *ret;");
$self->pidl("const char *binding_string;");
- $self->pidl("struct cli_credentials *credentials = NULL;");
+ $self->pidl("struct cli_credentials *credentials;");
$self->pidl("struct loadparm_context *lp_ctx = NULL;");
+ $self->pidl("PyObject *py_lp_ctx = NULL, *py_credentials = Py_None;");
$self->pidl("TALLOC_CTX *mem_ctx = NULL;");
$self->pidl("NTSTATUS status;");
$self->pidl("");
$self->pidl("const char *kwnames[] = {");
$self->indent;
- $self->pidl("\"binding\", NULL");
+ $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", NULL");
$self->deindent;
$self->pidl("};");
+ $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);");
+ $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);");
+ $self->pidl("");
+ $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"sO|O:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {");
+ $self->indent;
+ $self->pidl("return NULL;");
+ $self->deindent;
+ $self->pidl("}");
$self->pidl("");
- $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string)) {");
+ $self->pidl("if (py_lp_ctx != NULL) {");
+ $self->indent;
+ $self->pidl("lp_ctx = lp_from_py_object(py_lp_ctx);");
+ $self->pidl("if (lp_ctx == NULL) {");
$self->indent;
+ $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected loadparm context\");");
$self->pidl("return NULL;");
$self->deindent;
$self->pidl("}");
+ $self->deindent;
+ $self->pidl("}");
$self->pidl("");
- # FIXME: Arguments: binding string, credentials, loadparm context
+ $self->pidl("credentials = cli_credentials_from_py_object(py_credentials);");
+ $self->pidl("if (credentials == NULL) {");
+ $self->indent;
+ $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected credentials\");");
+ $self->pidl("return NULL;");
+ $self->deindent;
+ $self->pidl("}");
+
$self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);");
$self->pidl("");
@@ -517,6 +552,8 @@ sub Interface($$$)
$self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);");
$self->handle_ntstatus("status", "NULL", "mem_ctx");
+ $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;");
+
$self->pidl("return (PyObject *)ret;");
$self->deindent;
$self->pidl("}");