summaryrefslogtreecommitdiff
path: root/pidl/lib/Parse/Pidl/Samba4
diff options
context:
space:
mode:
Diffstat (limited to 'pidl/lib/Parse/Pidl/Samba4')
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/Header.pm12
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm17
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm42
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/Python.pm46
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/TDR.pm8
5 files changed, 80 insertions, 45 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/Header.pm b/pidl/lib/Parse/Pidl/Samba4/Header.pm
index 5315957946..be1df4b118 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Header.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Header.pm
@@ -120,10 +120,20 @@ sub HeaderEnum($$;$)
pidl " {\n";
$tab_depth++;
foreach my $e (@{$enum->{ELEMENTS}}) {
+ my @enum_els = ();
unless ($first) { pidl ",\n"; }
$first = 0;
pidl tabs();
- pidl $e;
+ @enum_els = split(/=/, $e);
+ if (@enum_els == 2) {
+ pidl $enum_els[0];
+ pidl "=(int)";
+ pidl "(";
+ pidl $enum_els[1];
+ pidl ")";
+ } else {
+ pidl $e;
+ }
}
pidl "\n";
$tab_depth--;
diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
index f2a96a3037..9d3ccaf8c8 100644
--- a/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
@@ -34,8 +34,9 @@ sub ParseFunctionSend($$$)
if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
NDR_PRINT_IN_DEBUG($name, r);
}
-
- return dcerpc_ndr_request_send(p, NULL, &ndr_table_$interface->{NAME}, NDR_$uname, mem_ctx, r);
+
+ return dcerpc_ndr_request_send(p, NULL, &ndr_table_$interface->{NAME},
+ NDR_$uname, true, mem_ctx, r);
";
}
@@ -45,6 +46,7 @@ sub ParseFunctionSend($$$)
sub ParseFunctionSync($$$)
{
my ($interface, $fn, $name) = @_;
+ my $uname = uc $name;
my $proto = "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)";
@@ -55,13 +57,14 @@ sub ParseFunctionSync($$$)
$res .= "\treturn NT_STATUS_NOT_IMPLEMENTED;\n";
} else {
$res .= "
- struct rpc_request *req;
NTSTATUS status;
-
- req = dcerpc_$name\_send(p, mem_ctx, r);
- if (req == NULL) return NT_STATUS_NO_MEMORY;
- status = dcerpc_ndr_request_recv(req);
+ if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
+ NDR_PRINT_IN_DEBUG($name, r);
+ }
+
+ status = dcerpc_ndr_request(p, NULL, &ndr_table_$interface->{NAME},
+ NDR_$uname, mem_ctx, r);
if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) {
NDR_PRINT_OUT_DEBUG($name, r);
diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
index c822d6746e..da536beef4 100644
--- a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
@@ -204,12 +204,12 @@ sub ParseArrayPushHeader($$$$$$)
}
if ((!$l->{IS_SURROUNDING}) and $l->{IS_CONFORMANT}) {
- $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $size));");
+ $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, $size));");
}
if ($l->{IS_VARYING}) {
- $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, 0));"); # array offset
- $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $length));");
+ $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, 0));"); # array offset
+ $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, $length));");
}
return $length;
@@ -326,7 +326,7 @@ sub ParseArrayPullHeader($$$$$$)
if ($l->{IS_CONFORMANT}) {
$length = $size = "ndr_get_array_size($ndr, " . get_pointer_to($var_name) . ")";
- } elsif ($l->{IS_ZERO_TERMINATED}) { # Noheader arrays
+ } elsif ($l->{IS_ZERO_TERMINATED} and $l->{SIZE_IS} == 0 and $l->{LENGTH_IS} == 0) { # Noheader arrays
$length = $size = "ndr_get_string_size($ndr, sizeof(*$var_name))";
} else {
$length = $size = ParseExprExt($l->{SIZE_IS}, $env, $e->{ORIGINAL},
@@ -1069,6 +1069,10 @@ sub ParseElementPullLevel
my $counter = "cntr_$e->{NAME}_$l->{LEVEL_INDEX}";
my $array_name = $var_name;
+ if ($l->{IS_VARYING}) {
+ $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")";
+ }
+
$var_name = get_array_element($var_name, $counter);
$self->ParseMemCtxPullStart($e, $l, $ndr, $array_name);
@@ -1220,9 +1224,9 @@ sub ParseStructPushPrimitives($$$$$)
$size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e->{ORIGINAL});
}
- $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $size));");
+ $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, $size));");
} else {
- $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, ndr_string_array_size($ndr, $varname->$e->{NAME})));");
+ $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, ndr_string_array_size($ndr, $varname->$e->{NAME})));");
}
}
@@ -1235,6 +1239,8 @@ sub ParseStructPushPrimitives($$$$$)
}
$self->ParseElementPush($_, $ndr, $env, 1, 0) foreach (@{$struct->{ELEMENTS}});
+
+ $self->pidl("NDR_CHECK(ndr_push_trailer_align($ndr, $struct->{ALIGN}));");
}
sub ParseStructPushDeferred($$$$)
@@ -1287,7 +1293,7 @@ sub ParseEnumPush($$$$)
my($type_fn) = $enum->{BASE_TYPE};
$self->start_flags($enum, $ndr);
- $self->pidl("NDR_CHECK(ndr_push_$type_fn($ndr, NDR_SCALARS, $varname));");
+ $self->pidl("NDR_CHECK(ndr_push_enum_$type_fn($ndr, NDR_SCALARS, $varname));");
$self->end_flags($enum, $ndr);
}
@@ -1301,7 +1307,7 @@ sub ParseEnumPull($$$$)
$self->pidl("$type_v_decl v;");
$self->start_flags($enum, $ndr);
- $self->pidl("NDR_CHECK(ndr_pull_$type_fn($ndr, NDR_SCALARS, &v));");
+ $self->pidl("NDR_CHECK(ndr_pull_enum_$type_fn($ndr, NDR_SCALARS, &v));");
$self->pidl("*$varname = v;");
$self->end_flags($enum, $ndr);
@@ -1533,6 +1539,8 @@ sub ParseStructPullPrimitives($$$$$)
$self->ParseElementPull($_, $ndr, $env, 1, 0) foreach (@{$struct->{ELEMENTS}});
$self->add_deferred();
+
+ $self->pidl("NDR_CHECK(ndr_pull_trailer_align($ndr, $struct->{ALIGN}));");
}
sub ParseStructPullDeferred($$$$$)
@@ -1644,6 +1652,10 @@ sub ParseUnionPushPrimitives($$$$)
$self->pidl("NDR_CHECK(ndr_push_$e->{SWITCH_TYPE}($ndr, NDR_SCALARS, level));");
}
+ if (defined($e->{ALIGN})) {
+ $self->pidl("NDR_CHECK(ndr_push_union_align($ndr, $e->{ALIGN}));");
+ }
+
$self->pidl("switch (level) {");
$self->indent;
foreach my $el (@{$e->{ELEMENTS}}) {
@@ -1669,7 +1681,7 @@ sub ParseUnionPushPrimitives($$$$)
}
if (! $have_default) {
$self->pidl("default:");
- $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+ $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
}
$self->deindent;
$self->pidl("}");
@@ -1705,7 +1717,7 @@ sub ParseUnionPushDeferred($$$$)
}
if (! $have_default) {
$self->pidl("default:");
- $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+ $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
}
$self->deindent;
$self->pidl("}");
@@ -1784,10 +1796,14 @@ sub ParseUnionPullPrimitives($$$$$)
if (defined($switch_type)) {
$self->pidl("NDR_CHECK(ndr_pull_$switch_type($ndr, NDR_SCALARS, &_level));");
$self->pidl("if (_level != level) {");
- $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u for $varname\", _level);");
+ $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u for $varname at \%s\", _level, __location__);");
$self->pidl("}");
}
+ if (defined($e->{ALIGN})) {
+ $self->pidl("NDR_CHECK(ndr_pull_union_align($ndr, $e->{ALIGN}));");
+ }
+
$self->pidl("switch (level) {");
$self->indent;
foreach my $el (@{$e->{ELEMENTS}}) {
@@ -1814,7 +1830,7 @@ sub ParseUnionPullPrimitives($$$$$)
}
if (! $have_default) {
$self->pidl("default:");
- $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+ $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
}
$self->deindent;
$self->pidl("}");
@@ -1848,7 +1864,7 @@ sub ParseUnionPullDeferred($$$$)
}
if (! $have_default) {
$self->pidl("default:");
- $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+ $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
}
$self->deindent;
$self->pidl("}");
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 6099fe5cae..c785619adb 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -431,7 +431,7 @@ sub PythonFunctionUnpackOut($$$)
} elsif (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "WERROR") {
$self->handle_werror("r->out.result", "NULL", undef);
} elsif (defined($fn->{RETURN_TYPE})) {
- my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result");
+ my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result", $fn);
if ($result_size > 1) {
$self->pidl("PyTuple_SetItem(result, $i, $conv);");
} else {
@@ -766,6 +766,11 @@ sub register_module_import($$)
sub use_type_variable($$)
{
my ($self, $orig_ctype) = @_;
+ # FIXME: Have a global lookup table for types that look different on the
+ # wire than they are named in C?
+ if ($orig_ctype->{NAME} eq "dom_sid2") {
+ $orig_ctype->{NAME} = "dom_sid";
+ }
my $ctype = resolveType($orig_ctype);
unless (defined($ctype->{BASEFILE})) {
return undef;
@@ -815,11 +820,11 @@ sub assign($$$)
}
}
-sub ConvertObjectFromPythonData($$$$$$)
+sub ConvertObjectFromPythonData($$$$$$;$)
{
- my ($self, $mem_ctx, $cvar, $ctype, $target, $fail) = @_;
+ my ($self, $mem_ctx, $cvar, $ctype, $target, $fail, $location) = @_;
- die("undef type for $cvar") unless(defined($ctype));
+ fatal($location, "undef type for $cvar") unless(defined($ctype));
$ctype = resolveType($ctype);
@@ -839,13 +844,12 @@ sub ConvertObjectFromPythonData($$$$$$)
if ($actual_ctype->{TYPE} eq "STRUCT" or $actual_ctype->{TYPE} eq "INTERFACE") {
my $ctype_name = $self->use_type_variable($ctype);
unless (defined ($ctype_name)) {
- error(undef, "Unable to determine origin of type " . mapTypeName($ctype));
- $self->assign($target, "NULL");
- # FIXME:
+ error($location, "Unable to determine origin of type `" . mapTypeName($ctype) . "'");
+ $self->pidl("PyErr_SetString(PyExc_TypeError, \"Can not convert C Type " . mapTypeName($ctype) . " to Python\");");
return;
}
$self->pidl("PY_CHECK_TYPE($ctype_name, $cvar, $fail);");
- $self->assign($target, "talloc_ptrtype(py_talloc_get_ptr($cvar), $target)");
+ $self->assign($target, "py_talloc_get_ptr($cvar)");
return;
}
@@ -886,7 +890,7 @@ sub ConvertObjectFromPythonData($$$$$$)
return;
}
- fatal($ctype, "unknown type $actual_ctype->{TYPE} for ".mapTypeName($ctype) . ": $cvar");
+ fatal($location, "unknown type `$actual_ctype->{TYPE}' for ".mapTypeName($ctype) . ": $cvar");
}
@@ -946,7 +950,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) {
$var_name = get_pointer_to($var_name);
}
- $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail);
+ $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail, $e->{ORIGINAL});
} elsif ($l->{TYPE} eq "SWITCH") {
$var_name = get_pointer_to($var_name);
my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e);
@@ -954,7 +958,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
} elsif ($l->{TYPE} eq "SUBCONTEXT") {
$self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail);
} else {
- die("unknown level type $l->{TYPE}");
+ fatal($e->{ORIGINAL}, "unknown level type $l->{TYPE}");
}
}
@@ -994,18 +998,18 @@ sub ConvertScalarToPython($$$)
}
# Not yet supported
- if ($ctypename eq "string_array") { return "PyCObject_FromVoidPtr($cvar)"; }
+ if ($ctypename eq "string_array") { return "PyCObject_FromTallocPtr($cvar)"; }
if ($ctypename eq "ipv4address") { return "PyString_FromString($cvar)"; }
if ($ctypename eq "pointer") {
- return "PyCObject_FromVoidPtr($cvar, talloc_free)";
+ return "PyCObject_FromTallocPtr($cvar)";
}
die("Unknown scalar type $ctypename");
}
-sub ConvertObjectToPythonData($$$$$)
+sub ConvertObjectToPythonData($$$$$;$)
{
- my ($self, $mem_ctx, $ctype, $cvar) = @_;
+ my ($self, $mem_ctx, $ctype, $cvar, $location) = @_;
die("undef type for $cvar") unless(defined($ctype));
@@ -1027,13 +1031,13 @@ sub ConvertObjectToPythonData($$$$$)
} elsif ($actual_ctype->{TYPE} eq "STRUCT" or $actual_ctype->{TYPE} eq "INTERFACE") {
my $ctype_name = $self->use_type_variable($ctype);
unless (defined($ctype_name)) {
- error(undef, "Unable to determine origin of type " . mapTypeName($ctype));
+ error($location, "Unable to determine origin of type `" . mapTypeName($ctype) . "'");
return "NULL"; # FIXME!
}
- return "py_talloc_import_ex($ctype_name, $mem_ctx, $cvar)";
+ return "py_talloc_reference_ex($ctype_name, $mem_ctx, $cvar)";
}
- fatal($ctype, "unknown type $actual_ctype->{TYPE} for ".mapTypeName($ctype) . ": $cvar");
+ fatal($location, "unknown type $actual_ctype->{TYPE} for ".mapTypeName($ctype) . ": $cvar");
}
sub fail_on_null($$$)
@@ -1113,12 +1117,12 @@ sub ConvertObjectToPythonLevel($$$$$$)
if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) {
$var_name = get_pointer_to($var_name);
}
- my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name);
+ my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name, $e->{ORIGINAL});
$self->pidl("$py_var = $conv;");
} elsif ($l->{TYPE} eq "SUBCONTEXT") {
$self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var, $fail);
} else {
- die("Unknown level type $l->{TYPE} $var_name");
+ fatal($e->{ORIGINAL}, "Unknown level type $l->{TYPE} $var_name");
}
}
@@ -1223,7 +1227,7 @@ sub Parse($$$$$)
} elsif ($cvar =~ /^".*"$/) {
$py_obj = "PyString_FromString($cvar)";
} else {
- $py_obj = $self->ConvertObjectToPythonData("NULL", expandAlias($ctype), $cvar);
+ $py_obj = $self->ConvertObjectToPythonData("NULL", expandAlias($ctype), $cvar, undef);
}
$self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);");
diff --git a/pidl/lib/Parse/Pidl/Samba4/TDR.pm b/pidl/lib/Parse/Pidl/Samba4/TDR.pm
index 568dff5adf..c0749304ef 100644
--- a/pidl/lib/Parse/Pidl/Samba4/TDR.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/TDR.pm
@@ -7,6 +7,7 @@ package Parse::Pidl::Samba4::TDR;
use Parse::Pidl qw(fatal);
use Parse::Pidl::Util qw(has_property ParseExpr is_constant);
use Parse::Pidl::Samba4 qw(is_intree choose_header);
+use Parse::Pidl::Typelist qw(mapTypeName);
use Exporter;
@ISA = qw(Exporter);
@@ -195,15 +196,16 @@ sub ParserEnum($$$$)
{
my ($self,$e,$t,$p) = @_;
my $bt = Parse::Pidl::Typelist::enum_type_fn($e);
+ my $mt = mapTypeName($bt);
$self->fn_declare($p, "NTSTATUS tdr_$t\_$e->{NAME} (struct tdr_$t *tdr".typearg($t).", enum $e->{NAME} *v)");
$self->pidl("{");
if ($t eq "pull") {
- $self->pidl("\t$bt\_t r;");
+ $self->pidl("\t$mt r;");
$self->pidl("\tTDR_CHECK(tdr_$t\_$bt(tdr, mem_ctx, \&r));");
$self->pidl("\t*v = r;");
} elsif ($t eq "push") {
- $self->pidl("\tTDR_CHECK(tdr_$t\_$bt(tdr, ($bt\_t *)v));");
+ $self->pidl("\tTDR_CHECK(tdr_$t\_$bt(tdr, ($mt *)v));");
} elsif ($t eq "print") {
$self->pidl("\t/* FIXME */");
}
@@ -271,7 +273,7 @@ sub Parser($$$$)
$self->pidl("");
$self->pidl_hdr("/* autogenerated by pidl */");
$self->pidl_hdr("#include \"$baseheader\"");
- $self->pidl_hdr(choose_header("tdr/tdr.h", "tdr.h"));
+ $self->pidl_hdr(choose_header("lib/tdr/tdr.h", "tdr.h"));
$self->pidl_hdr("");
foreach (@$idl) { $self->ParserInterface($_) if ($_->{TYPE} eq "INTERFACE"); }