diff options
author | jmayer <jmayer@f5534014-38df-0310-8fa8-9805f1628bb7> | 2006-09-19 15:29:38 +0000 |
---|---|---|
committer | jmayer <jmayer@f5534014-38df-0310-8fa8-9805f1628bb7> | 2006-09-19 15:29:38 +0000 |
commit | dde92992b5c19577e8c06aa530ce8511ce592b4d (patch) | |
tree | af010c9f280b420aa76d7d4a1379b94b6f85538f /tools/pidl | |
parent | 69588c59efb343b88251ec5dfe34feae9507dfad (diff) |
Update from samba tree revision 18221 to 18675
============================ Samba log start ============
svn: When specifying working copy paths, only one target may be given
============================ Samba log end ==============
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@19258 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'tools/pidl')
-rw-r--r-- | tools/pidl/TODO | 5 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/NDR.pm | 39 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/Client.pm | 137 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/Header.pm | 223 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 603 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/Server.pm | 122 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 212 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/Template.pm | 82 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/Types.pm | 403 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba4.pm | 4 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba4/Header.pm | 6 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 85 | ||||
-rwxr-xr-x | tools/pidl/pidl | 106 | ||||
-rwxr-xr-x | tools/pidl/tests/ndr_string.pl | 31 |
15 files changed, 329 insertions, 1731 deletions
diff --git a/tools/pidl/TODO b/tools/pidl/TODO index bfbf5afc54..5b3610232c 100644 --- a/tools/pidl/TODO +++ b/tools/pidl/TODO @@ -1,3 +1,8 @@ +- EJS output backend shouldn't use the NDR levels stuff but instead + as the "C levels" and NDR levels don't necessarily match. + +- warn about [out] attributes on pointers (midl/samba3 compatibility) + - true multiple dimension array / strings in arrays support - compatibility mode for generating MIDL-readable data: diff --git a/tools/pidl/lib/Parse/Pidl/NDR.pm b/tools/pidl/lib/Parse/Pidl/NDR.pm index 21875a1297..cd8aa214ff 100644 --- a/tools/pidl/lib/Parse/Pidl/NDR.pm +++ b/tools/pidl/lib/Parse/Pidl/NDR.pm @@ -109,6 +109,15 @@ sub GetElementLevelTable($) @bracket_array = @{$e->{ARRAY_LEN}}; } + if (has_property($e, "out")) { + my $needptrs = 1; + + if (has_property($e, "string")) { $needptrs++; } + if ($#bracket_array >= 0) { $needptrs = 0; } + + nonfatal($e, "[out] argument `$e->{NAME}' not a pointer") if ($needptrs > $e->{POINTERS}); + } + # Parse the [][][][] style array stuff for my $i (0 .. $#bracket_array) { my $d = $bracket_array[$#bracket_array - $i]; @@ -195,7 +204,8 @@ sub GetElementLevelTable($) } } - if (scalar(@size_is) == 0 and has_property($e, "string")) { + if (scalar(@size_is) == 0 and has_property($e, "string") and + $i == $e->{POINTERS}) { $is_string = 1; $is_varying = $is_conformant = has_property($e, "noheader")?0:1; delete($e->{PROPERTIES}->{string}); @@ -543,10 +553,6 @@ sub ParseFunction($$$) push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in")); push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out")); - nonfatal($x, "`$e->{NAME}' is [out] argument but not a pointer") - if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") and - grep(/out/, @{$e->{DIRECTION}}); - push (@elements, $e); } @@ -580,23 +586,6 @@ sub CheckPointerTypes($$) } } -#FIXME: Remove when ref handling in Samba4 is fixed -sub AddKeepRef($) -{ - my $d = shift; - - if ($d->{TYPE} eq "FUNCTION") { - foreach (@{$d->{ELEMENTS}}) { - $_->{PROPERTIES}->{keepref} = 1; - } - } elsif ($d->{TYPE} eq "TYPEDEF" and ($d->{DATA}->{TYPE} eq "STRUCT" - or $d->{DATA}->{TYPE} eq "UNION")) { - foreach (@{$d->{DATA}->{ELEMENTS}}) { - $_->{PROPERTIES}->{keepref} = 1; - } - } -} - sub ParseInterface($) { my $idl = shift; @@ -622,12 +611,10 @@ sub ParseInterface($) if ($d->{TYPE} eq "DECLARE") { push (@declares, $d); } elsif ($d->{TYPE} eq "FUNCTION") { - AddKeepRef($d) if (has_property($idl, "keepref")); push (@functions, ParseFunction($idl, $d, \$opnum)); } elsif ($d->{TYPE} eq "CONST") { push (@consts, ParseConst($idl, $d)); } else { - AddKeepRef($d) if (has_property($idl, "keepref")); push (@types, ParseType($idl, $d)); } } @@ -849,10 +836,6 @@ my %property_list = ( "noheader" => ["ELEMENT"], "charset" => ["ELEMENT"], "length_is" => ["ELEMENT"], - - # temporary (should be removed once we've migrated away from - # relying on ref pointers being there in Samba4's code) - "keepref" => ["ELEMENT","INTERFACE"], ); ##################################################################### diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm deleted file mode 100644 index 9e26e9a21e..0000000000 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ /dev/null @@ -1,137 +0,0 @@ -################################################### -# Samba3 NDR client generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Client; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclLong); - -use vars qw($VERSION); -$VERSION = '0.01'; - -my $res = ""; -my $tabs = ""; -sub indent() { $tabs.="\t"; } -sub deindent() { $tabs = substr($tabs, 1); } -sub pidl($) { $res .= $tabs.(shift)."\n"; } -sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } -sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } - -sub CopyLevel($$$$) -{ - sub CopyLevel($$$$); - my ($e,$l,$argument,$member) = @_; - - if ($l->{TYPE} eq "DATA") { - pidl "*$argument = $member;"; - } elsif ($l->{TYPE} eq "POINTER") { - pidl "if (r.ptr$l->{POINTER_INDEX}_$e->{NAME}) {"; - indent; - pidl "*$argument = talloc_size(mem_ctx, sizeof(void *));"; - CopyLevel($e,GetNextLevel($e,$l),"*$argument", $member); - deindent; - pidl "}"; - } elsif ($l->{TYPE} eq "SWITCH") { - CopyLevel($e,GetNextLevel($e,$l),$argument,$member); - } elsif ($l->{TYPE} eq "ARRAY") { - pidl "*$argument = $member;"; - } -} - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - my $inargs = ""; - my $defargs = ""; - foreach (@{$fn->{ELEMENTS}}) { - $defargs .= ", " . DeclLong($_); - if (grep(/in/, @{$_->{DIRECTION}})) { - $inargs .= ", $_->{NAME}"; - } - } - - my $uif = uc($if->{NAME}); - my $ufn = uc($fn->{NAME}); - - pidl "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; - pidl "{"; - indent; - pidl "prs_struct qbuf, rbuf;"; - pidl "$uif\_Q_$ufn q;"; - pidl "$uif\_R_$ufn r;"; - pidl ""; - pidl "ZERO_STRUCT(q);"; - pidl "ZERO_STRUCT(r);"; - pidl ""; - pidl "/* Marshall data and send request */"; - pidl ""; - pidl "if (!init_$if->{NAME}_q_$fn->{NAME}(&q$inargs))"; - pidl "\treturn NT_STATUS_INVALID_PARAMETER;"; - pidl ""; - pidl "CLI_DO_RPC(cli, mem_ctx, PI_$uif, $ufn,"; - pidl "\tq, r,"; - pidl "\tqbuf, rbuf, "; - pidl "\t$if->{NAME}_io_q_$fn->{NAME},"; - pidl "\t$if->{NAME}_io_r_$fn->{NAME},"; - pidl "\tNT_STATUS_UNSUCCESSFUL);"; - pidl ""; - pidl "/* Return variables */"; - foreach my $e (@{$fn->{ELEMENTS}}) { - next unless (grep(/out/, @{$e->{DIRECTION}})); - - CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.$e->{NAME}"); - } - - pidl""; - pidl "/* Return result */"; - if (not $fn->{RETURN_TYPE}) { - pidl "return NT_STATUS_OK;"; - } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { - pidl "return r.status;"; - } elsif ($fn->{RETURN_TYPE} eq "WERROR") { - pidl "return werror_to_ntstatus(r.status);"; - } else { - pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */"; - pidl "return NT_STATUS_OK;"; - } - - deindent; - pidl "}"; - pidl ""; -} - -sub ParseInterface($) -{ - my $if = shift; - - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $res = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * client auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl ""; - - foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - - return $res; -} - -1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index fa629e6101..31ea73f7aa 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -61,7 +61,7 @@ sub ParseFunction($$) foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - fatal($e, "[out] argument is not a pointer") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER"); + fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); pidl "*$e->{NAME} = *r.out.$e->{NAME};"; } diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Header.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Header.pm deleted file mode 100644 index c479b14afa..0000000000 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ /dev/null @@ -1,223 +0,0 @@ -################################################### -# Samba3 NDR header generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Header; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclShort StringType); - -use vars qw($VERSION); -$VERSION = '0.01'; - -my $res = ""; -my $tabs = ""; -sub indent() { $tabs.="\t"; } -sub deindent() { $tabs = substr($tabs, 1); } -sub pidl($) { $res .= $tabs.(shift)."\n"; } -sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } -sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } - -sub ParseElement($) -{ - my $e = shift; - - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "POINTER") { - next if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP"); - pidl "\tuint32 ptr$l->{POINTER_INDEX}_$e->{NAME};"; - } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "DATA") { - my $n = DeclShort($e); - pidl "\t$n;" if ($n); - } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { - my ($t,$f) = StringType($e,$l); - pidl "\t" . uc($t) . " $e->{NAME};"; - return; - } elsif ($l->{TYPE} eq "ARRAY") { - if ($l->{IS_CONFORMANT}) { - pidl "\tuint32 size_$e->{NAME};"; - } - if ($l->{IS_VARYING}) { - pidl "\tuint32 length_$e->{NAME};"; - pidl "\tuint32 offset_$e->{NAME};"; - } - } - } -} - -sub CreateStruct($$$$) -{ - my ($if,$fn,$n,$t) = @_; - - pidl "typedef struct $n {"; - ParseElement($_) foreach (@$t); - - if (not @$t) { - # Some compilers don't like empty structs - pidl "\tuint32 dummy;"; - } - - pidl "} " . uc($n) . ";"; - pidl ""; -} - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - my @in = (); - my @out = (); - - foreach (@{$fn->{ELEMENTS}}) { - push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); - push (@out, $_) if (grep(/out/, @{$_->{DIRECTION}})); - } - - if (defined($fn->{RETURN_TYPE})) { - push (@out, { - NAME => "status", - TYPE => $fn->{RETURN_TYPE}, - LEVELS => [ - { - TYPE => "DATA", - DATA_TYPE => $fn->{RETURN_TYPE} - } - ] - } ); - } - - # define Q + R structures for functions - - CreateStruct($if, $fn, "$if->{NAME}_q_$fn->{NAME}", \@in); - CreateStruct($if, $fn, "$if->{NAME}_r_$fn->{NAME}", \@out); -} - -sub ParseStruct($$$) -{ - my ($if,$s,$n) = @_; - - CreateStruct($if, $s, "$if->{NAME}_$n", $s->{ELEMENTS}); -} - -sub ParseUnion($$$) -{ - my ($if,$u,$n) = @_; - - my $extra = { - switch_value => $u->{SWITCH_TYPE} - }; - - if (not defined($extra->{switch_value})) { - $extra->{switch_value} = "uint32"; - } - - foreach my $e (@{$u->{ELEMENTS}}) { - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "ARRAY") { - if ($l->{IS_CONFORMANT}) { - $extra->{"size"} = "uint32"; - } - if ($l->{IS_VARYING}) { - $extra->{"length"} = $extra->{"offset"} = "uint32"; - } - } elsif ($l->{TYPE} eq "POINTER") { - $extra->{"ptr$l->{POINTER_INDEX}"} = "uint32"; - } elsif ($l->{TYPE} eq "SWITCH") { - $extra->{"level"} = "uint32"; - } - } - } - - pidl "typedef struct $if->{NAME}_$n\_ctr {"; - indent; - pidl "$extra->{$_} $_;" foreach (keys %$extra); - pidl "union $if->{NAME}_$n {"; - indent; - foreach (@{$u->{ELEMENTS}}) { - next if ($_->{TYPE} eq "EMPTY"); - pidl "\t" . DeclShort($_) . ";"; - } - deindent; - pidl "} u;"; - deindent; - pidl "} ".uc("$if->{NAME}_$n\_ctr") .";"; - pidl ""; -} - -sub ParseEnum($$$) -{ - my ($if,$s,$n) = @_; - - pidl "typedef enum {"; - pidl "$_," foreach (@{$s->{ELEMENTS}}); - pidl "} $n;"; -} - -sub ParseBitmap($$$) -{ - my ($if,$s,$n) = @_; - - pidl "#define $_" foreach (@{$s->{ELEMENTS}}); -} - -sub ParseInterface($) -{ - my $if = shift; - - my $def = "_RPC_" . uc($if->{NAME}) . "_H"; - - pidl ""; - - pidl "\#ifndef $def"; - pidl "\#define $def"; - - pidl ""; - - foreach (@{$if->{FUNCTIONS}}) { - pidl "\#define " . uc($_->{NAME}) . " $_->{OPNUM}" ; - } - - pidl ""; - - foreach (@{$if->{TYPES}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); - ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "ENUM"); - ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "BITMAP"); - ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); - } - - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); - - foreach (@{$if->{CONSTS}}) { - pidl "$_->{NAME} ($_->{VALUE})"; - } - - pidl "\#endif /* $def */"; -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $res = ""; - $tabs = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * header auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - - # Loop over interfaces - foreach (@{$ndr}) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - return $res; -} - -1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm deleted file mode 100644 index 57fa3867f7..0000000000 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ /dev/null @@ -1,603 +0,0 @@ -################################################### -# Samba3 NDR parser generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Parser; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType StringType); - -use vars qw($VERSION); -$VERSION = '0.01'; - -use constant PRIMITIVES => 1; -use constant DEFERRED => 2; - -my $res = ""; -my $tabs = ""; -sub indent() { $tabs.="\t"; } -sub deindent() { $tabs = substr($tabs, 1); } -sub pidl($) { $res .= $tabs.(shift)."\n"; } -sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } - -#TODO: -# - Add some security checks (array sizes, memory alloc == NULL, etc) -# - Don't add seperate _p and _d functions if there is no deferred data -# - [string] with non-varying arrays and "surrounding" strings -# - subcontext() -# - DATA_BLOB - -sub Align($$) -{ - my ($a,$b) = @_; - - # Only align if previous element was smaller than current one - if ($$a < $b) { - pidl "if (!prs_align_custom(ps, $b))"; - pidl "\treturn False;"; - pidl ""; - } - - $$a = $b; -} - -sub DeclareArrayVariables -{ - my $es = shift; - my $what = shift; - - my $output = 0; - - foreach my $e (@$es) { - foreach my $l (@{$e->{LEVELS}}) { - if ($what) { - next if ($l->{IS_DEFERRED} and $what == PRIMITIVES); - next if (not $l->{IS_DEFERRED} and $what == DEFERRED); - } - if ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { - pidl "uint32 i_$e->{NAME}_$l->{LEVEL_INDEX};"; - $output = 1; - } - } - } - pidl "" if $output; -} - -sub ParseElementLevelData($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - my $c = DissectType($e,$l,$varname,$what,$align); - return if not $c; - - if (defined($e->{ALIGN})) { - Align($align, $e->{ALIGN}); - } else { - # Default to 4 - Align($align, 4); - } - - pidl "if (!$c)"; - pidl "\treturn False;"; -} - -sub ParseElementLevelArray($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - if ($l->{IS_ZERO_TERMINATED}) { - return if ($what == DEFERRED); - - my ($t,$f) = StringType($e,$l); - - Align($align, 4); - pidl "if (!smb_io_$t(\"$e->{NAME}\", &$varname, 1, ps, depth))"; - pidl "\treturn False;"; - - $$align = 0; - return; - } - - my $len = ParseExpr($l->{LENGTH_IS}, $env); - my $size = ParseExpr($l->{SIZE_IS}, $env); - - if ($what == PRIMITIVES) { - # Fetch headers - if ($l->{IS_CONFORMANT} and not $l->{IS_SURROUNDING}) { - Align($align, 4); - pidl "if (!prs_uint32(\"size_$e->{NAME}\", ps, depth, &" . ParseExpr("size_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - } - - if ($l->{IS_VARYING}) { - Align($align, 4); - pidl "if (!prs_uint32(\"offset_$e->{NAME}\", ps, depth, &" . ParseExpr("offset_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - - pidl "if (!prs_uint32(\"length_$e->{NAME}\", ps, depth, &" . ParseExpr("length_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - } - } - - # Everything but fixed arrays have to be allocated - if (!$l->{IS_FIXED} and $what == PRIMITIVES) { - pidl "if (UNMARSHALLING(ps)) {"; - indent; - pidl "$varname = (void *)PRS_ALLOC_MEM_VOID(ps,sizeof(*$varname)*$size);"; - deindent; - pidl "}"; - } - - return if ($what == DEFERRED and not ContainsDeferred($e,$l)); - - my $i = "i_$e->{NAME}_$l->{LEVEL_INDEX}"; - pidl "for ($i=0; $i<$len;$i++) {"; - indent; - ParseElementLevel($e,$nl,$env,$varname."[$i]",$what,$align); - deindent; - pidl "}"; -} - -sub ParseElementLevelSwitch($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - ParseElementLevel($e,$nl,$env,$varname,$what,$align); -} - -sub ParseElementLevelPtr($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - if ($what == PRIMITIVES) { - if (($l->{POINTER_TYPE} eq "ref") and ($l->{LEVEL} eq "EMBEDDED")) { - # Ref pointers always have to be non-NULL - pidl "if (MARSHALLING(ps) && !" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . ")"; - pidl "\treturn False;"; - pidl ""; - } - - unless ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") { - Align($align, 4); - pidl "if (!prs_uint32(\"ptr$l->{POINTER_INDEX}_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - } - } - - if ($l->{POINTER_TYPE} eq "relative") { - fatal($e, "relative pointers not supported for Samba 3"); - #FIXME - } - - if ($what == DEFERRED) { - if ($l->{POINTER_TYPE} ne "ref") { - pidl "if (" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . ") {"; - indent; - } - ParseElementLevel($e,$nl,$env,$varname,PRIMITIVES,$align); - ParseElementLevel($e,$nl,$env,$varname,DEFERRED,$align); - if ($l->{POINTER_TYPE} ne "ref") { - deindent; - pidl "}"; - } - $$align = 0; - } -} - -sub ParseElementLevelSubcontext($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - fatal($e, "subcontext() not supported for Samba 3"); - #FIXME -} - -sub ParseElementLevel($$$$$$) -{ - my ($e,$l,$env,$varname,$what,$align) = @_; - - { - DATA => \&ParseElementLevelData, - SUBCONTEXT => \&ParseElementLevelSubcontext, - POINTER => \&ParseElementLevelPtr, - SWITCH => \&ParseElementLevelSwitch, - ARRAY => \&ParseElementLevelArray - }->{$l->{TYPE}}->($e,$l,GetNextLevel($e,$l),$env,$varname,$what,$align); -} - -sub ParseElement($$$$) -{ - my ($e,$env,$what,$align) = @_; - - ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env), $what, $align); -} - -sub InitLevel($$$$) -{ - sub InitLevel($$$$); - my ($e,$l,$varname,$env) = @_; - - if ($l->{TYPE} eq "POINTER") { - if ($l->{POINTER_TYPE} eq "ref") { - pidl "if (!$varname)"; - pidl "\treturn False;"; - pidl ""; - } else { - pidl "if ($varname) {"; - indent; - } - - unless ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") { - pidl ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 1;"; - } - InitLevel($e, GetNextLevel($e,$l), "*$varname", $env); - - if ($l->{POINTER_TYPE} ne "ref") { - deindent; - pidl "} else {"; - pidl "\t" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 0;"; - pidl "}"; - } - } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { - my ($t,$f) = StringType($e,$l); - pidl "init_$t(&" . ParseExpr($e->{NAME}, $env) . ", ".substr($varname, 1) . ", $f);"; - } elsif ($l->{TYPE} eq "ARRAY") { - pidl ParseExpr($e->{NAME}, $env) . " = $varname;"; - } elsif ($l->{TYPE} eq "DATA") { - pidl InitType($e, $l, ParseExpr($e->{NAME}, $env), $varname); - } elsif ($l->{TYPE} eq "SWITCH") { - InitLevel($e, GetNextLevel($e,$l), $varname, $env); - pidl ParseExpr($e->{NAME}, $env) . ".switch_value = " . ParseExpr($l->{SWITCH_IS}, $env) . ";"; - } -} - -sub GenerateEnvElement($$) -{ - my ($e,$env) = @_; - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "DATA") { - $env->{$e->{NAME}} = "v->$e->{NAME}"; - } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}_$e->{NAME}"; - } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { - $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; - $env->{"size_$e->{NAME}"} = "v->size_$e->{NAME}"; - $env->{"offset_$e->{NAME}"} = "v->offset_$e->{NAME}"; - } - } -} - -sub ParseStruct($$$) -{ - my ($if,$s,$n) = @_; - - my $fn = "$if->{NAME}_io_$n"; - my $sn = uc("$if->{NAME}_$n"); - my $ifn = "init_$if->{NAME}_$n"; - - my $args = ""; - foreach (@{$s->{ELEMENTS}}) { - $args .= ", " . DeclLong($_); - } - - my $env = { "this" => "v" }; - GenerateEnvElement($_, $env) foreach (@{$s->{ELEMENTS}}); - - pidl "BOOL $ifn($sn *v$args)"; - pidl "{"; - indent; - pidl "DEBUG(5,(\"$ifn\\n\"));"; - pidl ""; - # Call init for all arguments - foreach (@{$s->{ELEMENTS}}) { - InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); - pidl ""; - } - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - my $pfn = "$fn\_p"; - my $dfn = "$fn\_d"; - - pidl "BOOL $pfn(const char *desc, $sn *v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($s->{ELEMENTS}, PRIMITIVES); - pidl "if (v == NULL)"; - pidl "\treturn False;"; - pidl ""; - pidl "prs_debug(ps, depth, desc, \"$pfn\");"; - pidl "depth++;"; - - my $align = 8; - if ($s->{SURROUNDING_ELEMENT}) { - pidl "if (!prs_uint32(\"size_$s->{SURROUNDING_ELEMENT}->{NAME}\", ps, depth, &" . ParseExpr("size_$s->{SURROUNDING_ELEMENT}->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - $align = 4; - - } - - foreach (@{$s->{ELEMENTS}}) { - ParseElement($_, $env, PRIMITIVES, \$align); - pidl ""; - } - - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - pidl "BOOL $dfn(const char *desc, $sn *v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($s->{ELEMENTS}, DEFERRED); - pidl "if (v == NULL)"; - pidl "\treturn False;"; - pidl ""; - pidl "prs_debug(ps, depth, desc, \"$dfn\");"; - pidl "depth++;"; - - $align = 0; - foreach (@{$s->{ELEMENTS}}) { - ParseElement($_, $env, DEFERRED, \$align); - pidl ""; - } - - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; -} - -sub UnionGenerateEnvElement($) -{ - my $e = shift; - my $env = {}; - - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "DATA") { - $env->{$e->{NAME}} = "v->u.$e->{NAME}"; - } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}"; - } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { - $env->{"length_$e->{NAME}"} = "v->length"; - $env->{"size_$e->{NAME}"} = "v->size"; - $env->{"offset_$e->{NAME}"} = "v->offset"; - } - } - - return $env; -} - -sub ParseUnion($$$) -{ - my ($if,$u,$n) = @_; - - my $fn = "$if->{NAME}_io_$n"; - my $sn = uc("$if->{NAME}_$n\_ctr"); - - my $pfn = "$fn\_p"; - my $dfn = "$fn\_d"; - - pidl "BOOL $pfn(const char *desc, $sn* v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($u->{ELEMENTS}); - - if (defined ($u->{SWITCH_TYPE})) { - pidl "if (!prs_$u->{SWITCH_TYPE}(\"switch_value\", ps, depth, &v->switch_value))"; - pidl "\treturn False;"; - pidl ""; - } - - # Maybe check here that level and v->switch_value are equal? - - pidl "switch (v->switch_value) {"; - indent; - - foreach (@{$u->{ELEMENTS}}) { - pidl "$_->{CASE}:"; - indent; - if ($_->{TYPE} ne "EMPTY") { - pidl "depth++;"; - my $env = UnionGenerateEnvElement($_); - my $align = 8; - ParseElement($_, $env, PRIMITIVES, \$align); - pidl "depth--;"; - } - pidl "break;"; - deindent; - pidl ""; - } - - unless ($u->{HAS_DEFAULT}) { - pidl "default:"; - pidl "\treturn False;"; - pidl ""; - } - - deindent; - pidl "}"; - pidl ""; - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - pidl "BOOL $dfn(const char *desc, $sn* v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($u->{ELEMENTS}); - - if (defined($u->{SWITCH_TYPE})) { - pidl "switch (v->switch_value) {"; - } else { - pidl "switch (level) {"; - } - indent; - - foreach (@{$u->{ELEMENTS}}) { - pidl "$_->{CASE}:"; - indent; - if ($_->{TYPE} ne "EMPTY") { - pidl "depth++;"; - my $env = UnionGenerateEnvElement($_); - my $align = 0; - ParseElement($_, $env, DEFERRED, \$align); - pidl "depth--;"; - } - pidl "break;"; - deindent; - pidl ""; - } - - deindent; - pidl "}"; - pidl ""; - pidl "return True;"; - deindent; - pidl "}"; - -} - -sub CreateFnDirection($$$$$) -{ - my ($fn,$ifn,$s,$all,$es) = @_; - - my $args = ""; - foreach (@$all) { $args .= ", " . DeclLong($_); } - - my $env = { }; - GenerateEnvElement($_, $env) foreach (@$es); - - pidl "BOOL $ifn($s *v$args)"; - pidl "{"; - indent; - pidl "DEBUG(5,(\"$ifn\\n\"));"; - pidl ""; - # Call init for all arguments - foreach (@$es) { - InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); - pidl ""; - } - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - pidl "BOOL $fn(const char *desc, $s *v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($es); - pidl "if (v == NULL)"; - pidl "\treturn False;"; - pidl ""; - pidl "prs_debug(ps, depth, desc, \"$fn\");"; - pidl "depth++;"; - - my $align = 8; - foreach (@$es) { - ParseElement($_, $env, PRIMITIVES, \$align); - ParseElement($_, $env, DEFERRED, \$align); - pidl ""; - } - - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; -} - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - my @in = (); - my @out = (); - my @all = @{$fn->{ELEMENTS}}; - - foreach (@{$fn->{ELEMENTS}}) { - push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); - push (@out, $_) if (grep(/out/, @{$_->{DIRECTION}})); - } - - if (defined($fn->{RETURN_TYPE})) { - my $status = { - NAME => "status", - TYPE => $fn->{RETURN_TYPE}, - LEVELS => [ - { - TYPE => "DATA", - DATA_TYPE => $fn->{RETURN_TYPE} - } - ] - }; - - push (@out, $status); - push (@all, $status); - } - - CreateFnDirection("$if->{NAME}_io_q_$fn->{NAME}", - "init_$if->{NAME}_q_$fn->{NAME}", - uc("$if->{NAME}_q_$fn->{NAME}"), - \@in, \@in); - CreateFnDirection("$if->{NAME}_io_r_$fn->{NAME}", - "init_$if->{NAME}_r_$fn->{NAME}", - uc("$if->{NAME}_r_$fn->{NAME}"), - \@all, \@out); -} - -sub ParseInterface($) -{ - my $if = shift; - - # Structures first - pidl "/* $if->{NAME} structures */"; - foreach (@{$if->{TYPES}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); - ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); - } - - pidl "/* $if->{NAME} functions */"; - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $tabs = ""; - $res = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * parser auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl ""; - pidl "#undef DBGC_CLASS"; - pidl "#define DBGC_CLASS DBGC_RPC_PARSE"; - pidl ""; - - foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - - return $res; -} - -1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Server.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Server.pm deleted file mode 100644 index 179ace7dbb..0000000000 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Server.pm +++ /dev/null @@ -1,122 +0,0 @@ -################################################### -# Samba3 NDR server generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Server; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); - -my $res = ""; -my $tabs = ""; - -sub indent() { $tabs.="\t"; } -sub deindent() { $tabs = substr($tabs, 1); } -sub pidl($) { $res .= $tabs.(shift)."\n"; } - -use vars qw($VERSION); -$VERSION = '0.01'; - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - pidl "/******************************************************************"; - pidl " api_$fn->{NAME}"; - pidl " *****************************************************************/"; - pidl ""; - pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; - pidl "{"; - indent; - pidl uc("$if->{NAME}_q_$fn->{NAME}") . " q_u;"; - pidl uc("$if->{NAME}_r_$fn->{NAME}") . " r_u;"; - pidl "prs_struct *data = &p->in_data.data;"; - pidl "prs_struct *rdata = &p->out_data.rdata;"; - pidl ""; - pidl "ZERO_STRUCT(q_u);"; - pidl "ZERO_STRUCT(r_u);"; - pidl ""; - pidl "if (!$if->{NAME}_io_q_$fn->{NAME}(\"\", &q_u, data, 0))"; - pidl "\treturn False;"; - pidl ""; - if ($fn->{RETURN_TYPE}) { - pidl "r_u.status = _$fn->{NAME}(p, &q_u, &r_u);"; - } else { - pidl "_$fn->{NAME}(p, &q_u, &r_u);"; - } - pidl ""; - pidl "if (!$if->{NAME}_io_r_$fn->{NAME}(\"\", &r_u, rdata, 0))"; - pidl "\treturn False;"; - pidl ""; - pidl "return True;"; - deindent; - pidl "}"; -} - -sub ParseInterface($) -{ - my $if = shift; - - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); - - pidl ""; - pidl "/* Tables */"; - pidl "static struct api_struct api_$if->{NAME}_cmds[] = "; - pidl "{"; - indent; - foreach (@{$if->{FUNCTIONS}}) { - pidl "{\"" . uc($_->{NAME}) . "\", " . uc($_->{NAME}) . ", api_$_->{NAME}},"; - } - deindent; - pidl "};"; - - pidl ""; - - pidl "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns)"; - pidl "{"; - indent; - pidl "*fns = api_$if->{NAME}_cmds;"; - pidl "*n_fns = sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct);"; - deindent; - pidl "}"; - - pidl ""; - - pidl "NTSTATUS rpc_$if->{NAME}_init(void)"; - pidl "{"; - indent; - pidl "return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; - deindent; - pidl "}"; -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $tabs = ""; - $res = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * server auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl "#include \"nterr.h\""; - pidl ""; - pidl "#undef DBGC_CLASS"; - pidl "#define DBGC_CLASS DBGC_RPC"; - pidl ""; - - foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - - return $res; -} - -1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm new file mode 100644 index 0000000000..4d3dba2e0e --- /dev/null +++ b/tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -0,0 +1,212 @@ +################################################### +# Samba3 server generator for IDL structures +# on top of Samba4 style NDR functions +# Copyright jelmer@samba.org 2005-2006 +# released under the GNU GPL + +package Parse::Pidl::Samba3::ServerNDR; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); +use Parse::Pidl::Util qw(has_property ParseExpr is_constant); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba4 qw(DeclLong); + +use vars qw($VERSION); +$VERSION = '0.01'; + +my $res; +my $res_hdr; +my $tabs = ""; +sub indent() { $tabs.="\t"; } +sub deindent() { $tabs = substr($tabs, 1); } +sub pidl($) { $res .= $tabs.(shift)."\n"; } +sub pidl_hdr($) { $res_hdr .= (shift)."\n"; } +sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } +sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } +sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } + +sub AllocOutVar($$$$) +{ + my ($e, $mem_ctx, $name, $env) = @_; + + my $l = $e->{LEVELS}[0]; + + if ($l->{TYPE} eq "POINTER") { + $l = GetNextLevel($e, $l); + } + + if ($l->{TYPE} eq "ARRAY") { + my $size = ParseExpr($l->{SIZE_IS}, $env); + pidl "$name = talloc_array_size($mem_ctx, sizeof(*$name), $size);"; + } else { + pidl "$name = talloc_size($mem_ctx, sizeof(*$name));"; + } + + pidl "if ($name == NULL) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; +} + +sub ParseFunction($$) +{ + my ($if,$fn) = @_; + + pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; + pidl "{"; + indent; + pidl "struct ndr_pull *pull;"; + pidl "struct ndr_push *push;"; + pidl "NTSTATUS status;"; + pidl "DATA_BLOB blob;"; + pidl "struct $fn->{NAME} r;"; + pidl "TALLOC_CTX *mem_ctx = talloc_init(\"api_$fn->{NAME}\");"; + pidl ""; + pidl "if (!prs_data_blob(&p->in_data.data, &blob, mem_ctx)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "pull = ndr_pull_init_blob(&blob, mem_ctx);"; + pidl "if (pull == NULL)"; + pidl "\treturn False;"; + pidl ""; + pidl "pull->flags |= LIBNDR_FLAG_REF_ALLOC;"; + pidl "status = ndr_pull_$fn->{NAME}(pull, NDR_IN, &r);"; + pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + + my %env = (); + foreach (@{$fn->{ELEMENTS}}) { + next unless (grep (/in/, @{$_->{DIRECTION}})); + $env{$_->{NAME}} = "r.in.$_->{NAME}"; + } + + my $proto = "_$fn->{NAME}(pipes_struct *p"; + my $ret = "_$fn->{NAME}(p"; + foreach (@{$fn->{ELEMENTS}}) { + my @dir = @{$_->{DIRECTION}}; + if (grep(/in/, @dir) and grep(/out/, @dir)) { + pidl "r.out.$_->{NAME} = r.in.$_->{NAME};"; + } elsif (grep(/out/, @dir)) { + AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", \%env); + } + if (grep(/in/, @dir)) { $ret .= ", r.in.$_->{NAME}"; } + else { $ret .= ", r.out.$_->{NAME}"; } + + $proto .= ", " . DeclLong($_); + } + $ret .= ")"; + $proto .= ");"; + + if ($fn->{RETURN_TYPE}) { + $ret = "r.out.result = $ret"; + $proto = "$fn->{RETURN_TYPE} $proto"; + } else { + $proto = "void $proto"; + } + + pidl_hdr "$proto"; + pidl "$ret;"; + + pidl ""; + pidl "push = ndr_push_init_ctx(mem_ctx);"; + pidl "if (push == NULL) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "status = ndr_push_$fn->{NAME}(push, NDR_OUT, &r);"; + pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "blob = ndr_push_blob(push);"; + pidl "if (!prs_init_data_blob(&p->out_data.rdata, &blob, p->mem_ctx)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "talloc_free(mem_ctx);"; + pidl ""; + pidl "return True;"; + deindent; + pidl "}"; + pidl ""; +} + +sub ParseInterface($) +{ + my $if = shift; + + my $uif = uc($if->{NAME}); + + pidl_hdr "#ifndef __SRV_$uif\__"; + pidl_hdr "#define __SRV_$uif\__"; + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + + pidl ""; + pidl "/* Tables */"; + pidl "static struct api_struct api_$if->{NAME}_cmds[] = "; + pidl "{"; + indent; + + foreach (@{$if->{FUNCTIONS}}) { + pidl "{\"" . uc($_->{NAME}) . "\", DCERPC_" . uc($_->{NAME}) . ", api_$_->{NAME}},"; + } + + deindent; + pidl "};"; + + pidl ""; + + pidl_hdr "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns);"; + pidl "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns)"; + pidl "{"; + indent; + pidl "*fns = api_$if->{NAME}_cmds;"; + pidl "*n_fns = sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct);"; + deindent; + pidl "}"; + pidl ""; + + pidl_hdr "NTSTATUS rpc_$if->{NAME}_init(void);"; + pidl "NTSTATUS rpc_$if->{NAME}_init(void)"; + pidl "{"; + pidl "\treturn rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; + pidl "}"; + + pidl_hdr "#endif /* __SRV_$uif\__ */"; +} + +sub Parse($$$) +{ + my($ndr,$header,$ndr_header) = @_; + + $res = ""; + $res_hdr = ""; + + pidl "/*"; + pidl " * Unix SMB/CIFS implementation."; + pidl " * server auto-generated by pidl. DO NOT MODIFY!"; + pidl " */"; + pidl ""; + pidl "#include \"includes.h\""; + pidl "#include \"$header\""; + pidl_hdr "#include \"$ndr_header\""; + pidl ""; + + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + + return ($res, $res_hdr); +} + +1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Template.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Template.pm deleted file mode 100644 index 47d565dce6..0000000000 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Template.pm +++ /dev/null @@ -1,82 +0,0 @@ -################################################### -# Samba3 NDR client generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Template; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); - -use vars qw($VERSION); -$VERSION = '0.01'; - -my $res; -sub pidl($) { my $x = shift; $res.="$x\n"; } - -sub ParseInterface($) -{ - my $if = shift; - - foreach (@{$if->{FUNCTIONS}}) { - my $ret = $_->{RETURN_TYPE}; - if (not $ret) { $ret = "void"; } - pidl "$ret _$_->{NAME}(pipes_struct *p, " . uc($if->{NAME}) . "_Q_" . uc($_->{NAME}) . " *q_u, " . uc($if->{NAME}) . "_R_" . uc($_->{NAME}) . " *r_u)"; - pidl "{"; - pidl "\t/* FIXME: Implement your code here */"; - if (not defined($_->{RETURN_TYPE})) { - } elsif ($_->{RETURN_TYPE} eq "WERROR") { - pidl "\treturn WERR_NOT_SUPPORTED;"; - } elsif ($_->{RETURN_TYPE} eq "NTSTATUS") { - pidl "\treturn NT_STATUS_NOT_IMPLEMENTED;"; - } elsif ($_->{RETURN_TYPE} eq "uint32") { - pidl "\treturn 0;"; - } - pidl "}"; - pidl ""; - } -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $res = ""; - - pidl "/* - * Unix SMB/CIFS implementation. - **** template auto-generated by pidl. Modify to your needs **** - * RPC Pipe client / server routines - * Copyright (C) YOUR NAME YEAR. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include \"includes.h\" - -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_MSRPC -"; - - foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - - return $res; -} - -1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Types.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Types.pm deleted file mode 100644 index 666d23e669..0000000000 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ /dev/null @@ -1,403 +0,0 @@ -################################################### -# Samba3 type-specific declarations / initialization / marshalling -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Types; - -require Exporter; -@ISA = qw(Exporter); -@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType StringType); - -use strict; -use Parse::Pidl::Util qw(has_property ParseExpr property_matches); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString); - -use vars qw($VERSION); -$VERSION = '0.01'; - -# TODO: Find external types somehow? - -sub warning($$) { my ($e,$s) = @_; print STDERR "$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"; } - -sub init_scalar($$$$) -{ - my ($e,$l,$n,$v) = @_; - - return "$n = $v;"; -} - -sub dissect_scalar($$$$$) -{ - my ($e,$l,$n,$w,$a) = @_; - - my $t = lc($e->{TYPE}); - - return "prs_$t(\"$e->{NAME}\", ps, depth, &$n)"; -} - -sub decl_string($) -{ - my $e = shift; - - my $is_conformant = property_matches($e, "flag", ".*STR_SIZE4.*"); - my $is_varying = property_matches($e, "flag", ".*STR_LEN4.*"); - my $is_ascii = property_matches($e, "flag", ".*STR_ASCII.*"); - - return "STRING2" if ($is_conformant and $is_varying and $is_ascii); - - return "UNISTR2" if ($is_conformant and $is_varying); - return "UNISTR3" if ($is_varying); - # We don't do UNISTR4, as we have lsa_String for that in Samba4's IDL - - die("Don't know what string type to use"); -} - -sub contains_pointer($) -{ - my $e = shift; - - foreach my $l (@{$e->{LEVELS}}) { - return 1 if ($l->{TYPE} eq "POINTER"); - } - - return 0; -} - -sub ext_decl_string($) -{ - my $e = shift; - - # One pointer is sufficient.. - return "const char" if (contains_pointer($e)); - return "const char *"; -} - -sub init_string($$$$) -{ - my ($e,$l,$n,$v) = @_; - - my $t = lc(decl_string($e)); - - my $flags; - if (property_matches($e, "flag", ".*STR_NULLTERM.*")) { - $flags = "UNI_STR_TERMINATE"; - } elsif (property_matches($e, "flag", ".*STR_NOTERM.*")) { - $flags = "UNI_STR_NOTERM"; - } else { - $flags = "UNI_FLAGS_NONE"; - } - - # One pointer is sufficient - if (substr($v, 0, 1) eq "*") { $v = substr($v, 1); } - - return "init_$t(&$n, $v, $flags);"; -} - -sub dissect_string($$$$$) -{ - my ($e,$l,$n,$w,$a) = @_; - - my $t = lc(decl_string($e)); - - $$a = 1; - return "smb_io_$t(\"$e->{NAME}\", &$n, 1, ps, depth)"; -} - -sub StringType($$) -{ - my ($e,$l) = @_; - my $nl = GetNextLevel($e,$l); - - if ($l->{IS_VARYING} and $l->{IS_CONFORMANT} and $nl->{DATA_TYPE} eq "uint16") { - return ("unistr2", "UNI_FLAGS_NONE"); - } elsif ($l->{IS_CONFORMANT} and $l->{IS_VARYING} and $nl->{DATA_TYPE} eq "uint8") { - return ("string2", 0); - } else { - fatal($e, "[string] non-varying string not supported for Samba3 yet"); - } -} - -my $known_types = -{ - uint8 => - { - DECL => "uint8", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - uint16 => - { - DECL => "uint16", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - uint32 => - { - DECL => "uint32", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - uint64 => - { - DECL => "uint64", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - int32 => - { - DECL => "int32", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - string => - { - DECL => \&decl_string, - EXT_DECL => \&ext_decl_string, - INIT => \&init_string, - DISSECT_P => \&dissect_string, - }, - NTSTATUS => - { - DECL => "NTSTATUS", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - WERROR => - { - DECL => "WERROR", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - GUID => - { - DECL => "struct uuid", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n) = @_; - return "smb_io_uuid(\"$e->{NAME}\", &$n, ps, depth)"; - } - }, - NTTIME => - { - DECL => "NTTIME", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "smb_io_nttime(\"$e->{NAME}\", &n, ps, depth)"; - } - }, - dom_sid => - { - DECL => "DOM_SID", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "smb_io_dom_sid(\"$e->{NAME}\", &n, ps, depth)"; - } - }, - policy_handle => - { - DECL => "POLICY_HND", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "smb_io_pol_hnd(\"$e->{NAME}\", &n, ps, depth)"; - } - }, - security_descriptor => - { - DECL => "SEC_DESC", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "sec_io_desc(\"$e->{NAME}\", &n, ps, depth)"; - } - }, - hyper => - { - DECL => "uint64", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "prs_uint64(\"$e->{NAME}\", ps, depth, &$n)"; - } - }, -}; - -sub AddType($$) -{ - my ($t,$d) = @_; - - warn("Reregistering type $t") if (defined($known_types->{$t})); - - $known_types->{$t} = $d; -} - -# Return type without special stuff, as used in -# declarations for internal structs -sub DeclShort($) -{ - my $e = shift; - - my $t = $known_types->{$e->{TYPE}}; - - if (not $t) { - warning($e, "Can't declare unknown type `$e->{TYPE}'"); - return undef; - } - - my $p; - - # DECL can be a function - if (ref($t->{DECL}) eq "CODE") { - $p = $t->{DECL}->($e); - } else { - $p = $t->{DECL}; - } - - my $prefixes = ""; - my $suffixes = ""; - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { - $prefixes = "*$prefixes"; - } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_FIXED}) { - $suffixes.="[$l->{SIZE_IS}]"; - } - } - - return "$p $prefixes$e->{NAME}$suffixes"; -} - -# Return type including special stuff (pointers, etc). -sub DeclLong($) -{ - my $e = shift; - - my $t = $known_types->{$e->{TYPE}}; - - if (not $t) { - warning($e, "Can't declare unknown type `$e->{TYPE}'"); - return undef; - } - - my $p; - - if (defined($t->{EXT_DECL})) { - $p = $t->{EXT_DECL} - } else { - $p = $t->{DECL}; - } - - if (ref($p) eq "CODE") { - $p = $p->($e); - } - - my $prefixes = ""; - my $suffixes = ""; - - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { - $p = "const char"; - last; - } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { - $prefixes = "*$prefixes"; - } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_FIXED}) { - $suffixes.="[$l->{SIZE_IS}]"; - } elsif ($l->{TYPE} eq "POINTER") { - $prefixes = "*$prefixes"; - } - } - - return "$p $prefixes$e->{NAME}$suffixes"; -} - -sub InitType($$$$) -{ - my ($e, $l, $varname, $value) = @_; - - my $t = $known_types->{$l->{DATA_TYPE}}; - - if (not $t) { - warning($e, "Don't know how to initialize type $l->{DATA_TYPE}"); - return undef; - } - - # INIT can be a function - if (ref($t->{INIT}) eq "CODE") { - return $t->{INIT}->($e, $l, $varname, $value); - } else { - return $t->{INIT}; - } -} - -sub DissectType($$$$$) -{ - my ($e,$l,$varname,$what,$align) = @_; - - my $t = $known_types->{$l->{DATA_TYPE}}; - - if (not $t) { - warning($e, "Don't know how to dissect type $l->{DATA_TYPE}"); - return undef; - } - - my $dissect; - if ($what == 1) { #primitives - $dissect = $t->{DISSECT_P}; - } elsif ($what == 2) { - $dissect = $t->{DISSECT_D}; - } - - return "" if not defined($dissect); - - # DISSECT can be a function - if (ref($dissect) eq "CODE") { - return $dissect->($e,$l,$varname,$what,$align); - } else { - return $dissect; - } -} - -sub LoadTypes($) -{ - my $ndr = shift; - foreach my $if (@{$ndr}) { - next unless ($if->{TYPE} eq "INTERFACE"); - - foreach my $td (@{$if->{TYPES}}) { - my $decl = uc("$if->{NAME}_$td->{NAME}"); - - my $init = sub { - my ($e,$l,$n,$v) = @_; - return "$n = $v;"; - }; - - my $dissect_d; - my $dissect_p; - if ($td->{DATA}->{TYPE} eq "UNION") { - $decl.="_CTR"; - } - - $dissect_p = sub { - my ($e,$l,$n,$w,$a) = @_; - - return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, ps, depth)"; - }; - $dissect_d = sub { - my ($e,$l,$n,$w,$a) = @_; - - return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, ps, depth)"; - }; - - AddType($td->{NAME}, { - DECL => $decl, - INIT => $init, - DISSECT_D => $dissect_d, - DISSECT_P => $dissect_p - }); - } - } -} - -1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba4.pm b/tools/pidl/lib/Parse/Pidl/Samba4.pm index 35456b1cfb..4ef2daa591 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4.pm @@ -18,7 +18,9 @@ $VERSION = '0.01'; sub is_intree() { - return -f "kdc/kdc.c"; + return 4 if (-f "kdc/kdc.c"); + return 3 if (-f "include/smb.h"); + return 0; } # Return an #include line depending on whether this build is an in-tree diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm b/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm index c9487115f5..6fb3ee2eec 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -60,11 +60,7 @@ sub HeaderElement($) } else { HeaderType($element, $element->{TYPE}, ""); pidl " "; - my $numstar = 0; - if (!has_property($element, "ref") or - has_property($element, "keepref")) { - $numstar += $element->{POINTERS}; - } + my $numstar = $element->{POINTERS}; if ($numstar >= 1) { $numstar-- if Parse::Pidl::Typelist::scalar_is_reference($element->{TYPE}); } diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index bf5e8fe441..6124935e67 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -7,6 +7,10 @@ package Parse::Pidl::Samba4::NDR::Parser; +require Exporter; +@ISA = qw(Exporter); +@EXPORT = qw(is_charset_array); + use strict; use Parse::Pidl::Typelist qw(hasType getType mapType); use Parse::Pidl::Util qw(has_property ParseExpr print_uuid); @@ -589,9 +593,7 @@ sub ParseElementPushLevel pidl "NDR_CHECK(ndr_push_relative_ptr2(ndr, $var_name));"; } } - if ($l->{POINTER_TYPE} ne "ref" or has_property($e, "keepref")) { - $var_name = get_value_of($var_name); - } + $var_name = get_value_of($var_name); ParseElementPushLevel($e, GetNextLevel($e, $l), $ndr, $var_name, $env, 1, 1); if ($l->{POINTER_TYPE} ne "ref") { @@ -671,9 +673,7 @@ sub ParsePtrPush($$$) my ($e,$l,$var_name) = @_; if ($l->{POINTER_TYPE} eq "ref") { - if (has_property($e, "keepref")) { - check_null_pointer(get_value_of($var_name)); - } + check_null_pointer(get_value_of($var_name)); if ($l->{LEVEL} eq "EMBEDDED") { pidl "NDR_CHECK(ndr_push_ref_ptr(ndr));"; } @@ -709,15 +709,13 @@ sub ParseElementPrint($$$) foreach my $l (@{$e->{LEVELS}}) { if ($l->{TYPE} eq "POINTER") { - if ($l->{POINTER_TYPE} ne "ref" or has_property($e, "keepref")) { pidl "ndr_print_ptr(ndr, \"$e->{NAME}\", $var_name);"; pidl "ndr->depth++;"; - if ($l->{POINTER_TYPE} ne "ref") { - pidl "if ($var_name) {"; - indent; - } - $var_name = get_value_of($var_name); + if ($l->{POINTER_TYPE} ne "ref") { + pidl "if ($var_name) {"; + indent; } + $var_name = get_value_of($var_name); } elsif ($l->{TYPE} eq "ARRAY") { my $length; @@ -766,13 +764,11 @@ sub ParseElementPrint($$$) foreach my $l (reverse @{$e->{LEVELS}}) { if ($l->{TYPE} eq "POINTER") { - if ($l->{POINTER_TYPE} ne "ref" or has_property($e, "keepref")) { - if ($l->{POINTER_TYPE} ne "ref") { - deindent; - pidl "}"; - } - pidl "ndr->depth--;"; + if ($l->{POINTER_TYPE} ne "ref") { + deindent; + pidl "}"; } + pidl "ndr->depth--;"; } elsif (($l->{TYPE} eq "ARRAY") and not is_charset_array($e,$l) and not has_fast_array($e,$l)) { @@ -886,7 +882,7 @@ sub ParseMemCtxPullStart($$$) my $next_is_array = ($nl->{TYPE} eq "ARRAY"); my $next_is_string = (($nl->{TYPE} eq "DATA") and ($nl->{DATA_TYPE} eq "string")); - if ($next_is_array or $next_is_string or not has_property($e, "keepref")) { + if ($next_is_array or $next_is_string) { return; } else { $mem_c_flags = "LIBNDR_FLAG_REF_ALLOC"; @@ -912,7 +908,7 @@ sub ParseMemCtxPullEnd($$) my $next_is_array = ($nl->{TYPE} eq "ARRAY"); my $next_is_string = (($nl->{TYPE} eq "DATA") and ($nl->{DATA_TYPE} eq "string")); - if ($next_is_array or $next_is_string or not has_property($e, "keepref")) { + if ($next_is_array or $next_is_string) { return; } else { $mem_r_flags = "LIBNDR_FLAG_REF_ALLOC"; @@ -989,9 +985,7 @@ sub ParseElementPullLevel ParseMemCtxPullStart($e,$l, $var_name); - if ($l->{POINTER_TYPE} ne "ref" or has_property($e, "keepref")) { - $var_name = get_value_of($var_name); - } + $var_name = get_value_of($var_name); ParseElementPullLevel($e,GetNextLevel($e,$l), $ndr, $var_name, $env, 1, 1); ParseMemCtxPullEnd($e,$l); @@ -1095,8 +1089,7 @@ sub ParsePtrPull($$$$) pidl "NDR_CHECK(ndr_pull_ref_ptr($ndr, &_ptr_$e->{NAME}));"; } - if (!$next_is_array and !$next_is_string and - has_property($e, "keepref")) { + if (!$next_is_array and !$next_is_string) { pidl "if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {"; pidl "\tNDR_PULL_ALLOC($ndr, $var_name);"; pidl "}"; @@ -1441,7 +1434,7 @@ sub need_decl_mem_ctx($$) my $next_is_array = ($nl->{TYPE} eq "ARRAY"); my $next_is_string = (($nl->{TYPE} eq "DATA") and ($nl->{DATA_TYPE} eq "string")); - return 0 if ($next_is_array or $next_is_string or not has_property($e, "keepref")); + return 0 if ($next_is_array or $next_is_string); } return 1 if ($l->{TYPE} eq "POINTER"); @@ -2107,7 +2100,6 @@ sub ParseFunctionPull($) next unless (grep(/out/, @{$e->{DIRECTION}})); next unless ($e->{LEVELS}[0]->{TYPE} eq "POINTER" and $e->{LEVELS}[0]->{POINTER_TYPE} eq "ref"); - next unless has_property($e, "keepref"); next if (($e->{LEVELS}[1]->{TYPE} eq "DATA") and ($e->{LEVELS}[1]->{DATA_TYPE} eq "string")); next if (($e->{LEVELS}[1]->{TYPE} eq "ARRAY") @@ -2359,6 +2351,29 @@ sub ParseInterface($$) pidl_hdr "#endif /* _HEADER_NDR_$interface->{NAME} */"; } +sub GenerateIncludes() +{ + if (is_intree()) { + pidl "#include \"includes.h\""; + } else { + pidl "#define _GNU_SOURCE"; + pidl "#include <stdint.h>"; + pidl "#include <stdlib.h>"; + pidl "#include <stdio.h>"; + pidl "#include <stdbool.h>"; + pidl "#include <stdarg.h>"; + pidl "#include <string.h>"; + } + + # Samba3 has everything in include/includes.h + if (is_intree() != 3) { + pidl choose_header("libcli/util/nterr.h", "core/nterr.h"); + pidl choose_header("librpc/gen_ndr/ndr_misc.h", "gen_ndr/ndr_misc.h"); + pidl choose_header("librpc/gen_ndr/ndr_dcerpc.h", "gen_ndr/ndr_dcerpc.h"); + pidl choose_header("librpc/rpc/dcerpc.h", "dcerpc.h"); #FIXME: This shouldn't be here! + } +} + ##################################################################### # parse a parsed IDL structure back into an IDL file sub Parse($$$) @@ -2376,22 +2391,8 @@ sub Parse($$$) pidl "/* parser auto-generated by pidl */"; pidl ""; - if (is_intree()) { - pidl "#include \"includes.h\""; - } else { - pidl "#define _GNU_SOURCE"; - pidl "#include <stdint.h>"; - pidl "#include <stdlib.h>"; - pidl "#include <stdio.h>"; - pidl "#include <stdbool.h>"; - pidl "#include <stdarg.h>"; - pidl "#include <string.h>"; - } - pidl choose_header("libcli/util/nterr.h", "core/nterr.h"); - pidl choose_header("librpc/gen_ndr/ndr_misc.h", "gen_ndr/ndr_misc.h"); - pidl choose_header("librpc/gen_ndr/ndr_dcerpc.h", "gen_ndr/ndr_dcerpc.h"); + GenerateIncludes(); pidl "#include \"$ndr_header\"" if ($ndr_header); - pidl choose_header("librpc/rpc/dcerpc.h", "dcerpc.h"); #FIXME: This shouldn't be here! pidl ""; my %needed = (); diff --git a/tools/pidl/pidl b/tools/pidl/pidl index 4d23060f6e..669ca270f8 100755 --- a/tools/pidl/pidl +++ b/tools/pidl/pidl @@ -17,7 +17,7 @@ pidl - An IDL compiler written in Perl pidl --help -pidl [--outputdir[=OUTNAME]] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--swig[=OUTPUT]] [--uint-enums] [--ndr-parser[=OUTPUT]] [--client] [--server] [--dcom-proxy] [--com-header] [--warn-compat] [--quiet] [--verbose] [--template] [--ws-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-header[=OUTPUT]] [--samba3-parser=[OUTPUT]] [--samba3-server=[OUTPUT]] [--samba3-template[=OUTPUT]] [--samba3-client[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [<idlfile>.idl]... +pidl [--outputdir[=OUTNAME]] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--swig[=OUTPUT]] [--uint-enums] [--ndr-parser[=OUTPUT]] [--client] [--server] [--dcom-proxy] [--com-header] [--warn-compat] [--quiet] [--verbose] [--template] [--ws-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [--samba3-ndr-server[=OUTPUT]] [<idlfile>.idl]... =head1 DESCRIPTION @@ -120,36 +120,18 @@ file the to disk. Useful for debugging pidl. Tell pidl to dump the internal NDR information tree it generated from the IDL file to disk. Useful for debugging pidl. -=item I<--samba3-header> - -Generate Samba3-style RPC header file. Filename defaults to rpc_BASENAME.h. - -=item I<--samba3-parser> - -Generate parser file for Samba3, to be placed in rpc_parse/. Filename defaults -to parse_BASENAME.c. - -=item I<--samba3-server> - -Generate server file for Samba3, to be placed in rpc_server/. Filename defaults -to srv_BASENAME.c. - -=item I<--samba3-template> - -Generate template for server-side implementation in Samba3, to be placed in -rpc_server/. Filename defaults to srv_BASENAME_nt.c - -=item I<--samba3-client> - -Generate client calls for Samba 3, to be placed in rpc_client/. Filename -defaults to cli_BASENAME.c. - =item I<--samba3-ndr-client> Generate client calls for Samba3, to be placed in rpc_client/. Instead of calling out to the code in Samba3's rpc_parse/, this will call out to Samba4's NDR code instead. +=item I<--samba3-ndr-server> + +Generate server calls for Samba3, to be placed in rpc_server/. Instead of +calling out to the code in Samba3's rpc_parse/, this will call out to +Samba4's NDR code instead. + =back =head1 IDL SYNTAX @@ -375,8 +357,8 @@ usesgetlasterror, vararg, vi_progid, wire_marshal. # Generating a TDR parser and header $ ./pidl --tdr-parser --header -- regf.idl - # Generating a Samba3 parser, client and server - $ ./pidl --samba3-parser --samba3-server --samba3-client -- dfs.idl + # Generating a Samba3 client and server + $ ./pidl --samba3-ndr-client --samba3-ndr-server -- dfs.idl # Generating a Samba4 NDR parser, client and server $ ./pidl --ndr-parser --ndr-client --ndr-server -- samr.idl @@ -469,9 +451,8 @@ my($opt_header); my($opt_samba3_header); my($opt_samba3_parser); my($opt_samba3_server); -my($opt_samba3_template); -my($opt_samba3_client); my($opt_samba3_ndr_client); +my($opt_samba3_ndr_server); my($opt_template) = 0; my($opt_client); my($opt_server); @@ -525,13 +506,10 @@ Samba 4 output: --com-header[=OUTFILE] create header for COM [com_BASENAME.h] Samba 3 output: - --samba3-header[=OUTF] create Samba3-style header [rpc_BASENAME.h] - --samba3-parser[=OUTF] create parser for Samba3 [parse_BASENAME.c] - --samba3-template[=OUTF]create template implementation [srv_BASENAME_nt.c] - --samba3-server[=OUTF] create server side wrappers for Samba3 [srv_BASENAME.c] - --samba3-client[=OUTF] create client calls for Samba3 [cli_BASENAME.c] --samba3-ndr-client[=OUTF] create client calls for Samba3 using Samba4's NDR code [cli_BASENAME.c] + --samba3-ndr-server[=OUTF] create server call wrapper for Samba3 + using Samba4's NDR code [srv_BASENAME.c] Wireshark parsers: --ws-parser[=OUTFILE] create Wireshark parser and header @@ -548,12 +526,8 @@ my $result = GetOptions ( 'parse-idl-tree' => \$opt_parse_idl_tree, 'dump-ndr-tree:s' => \$opt_dump_ndr_tree, 'uint-enums' => \$opt_uint_enums, - 'samba3-header:s' => \$opt_samba3_header, - 'samba3-parser:s' => \$opt_samba3_parser, - 'samba3-server:s' => \$opt_samba3_server, - 'samba3-template:s' => \$opt_samba3_template, - 'samba3-client:s' => \$opt_samba3_client, 'samba3-ndr-client:s' => \$opt_samba3_ndr_client, + 'samba3-ndr-server:s' => \$opt_samba3_ndr_server, 'header:s' => \$opt_header, 'server:s' => \$opt_server, 'tdr-parser:s' => \$opt_tdr_parser, @@ -580,11 +554,6 @@ if ($opt_help) { exit(0); } -if ($opt_samba3_client and $opt_samba3_ndr_client) { - print "--samba3-client and --samba3-ndr-client can not be used together\n"; - exit(1); -} - sub process_file($) { my $idl_file = shift; @@ -660,8 +629,8 @@ sub process_file($) defined($opt_ndr_parser) or defined($opt_ejs) or defined($opt_dump_ndr_tree) or defined($opt_samba3_header) or defined($opt_samba3_parser) or defined($opt_samba3_server) or - defined($opt_samba3_template) or defined($opt_samba3_client) or - defined($opt_swig) or defined($opt_samba3_ndr_client)) { + defined($opt_swig) or defined($opt_samba3_ndr_client) or + defined($opt_samba3_ndr_server)) { require Parse::Pidl::NDR; $ndr = Parse::Pidl::NDR::Parse($pidl); } @@ -772,43 +741,6 @@ $dcom print Parse::Pidl::Samba4::Template::Parse($pidl); } - if (defined($opt_samba3_header) or defined($opt_samba3_parser) or - defined($opt_samba3_server) or defined($opt_samba3_client) or - defined($opt_samba3_ndr_client) or defined($opt_samba3_template)) { - require Parse::Pidl::Samba3::Types; - Parse::Pidl::Samba3::Types::LoadTypes($ndr); - } - - if (defined($opt_samba3_header)) { - my $header = ($opt_samba3_header or "$outputdir/rpc_$basename.h"); - require Parse::Pidl::Samba3::Header; - FileSave($header, Parse::Pidl::Samba3::Header::Parse($ndr, $basename)); - } - - if (defined($opt_samba3_parser)) { - my $header = ($opt_samba3_parser or "$outputdir/parse_$basename.c"); - require Parse::Pidl::Samba3::Parser; - FileSave($header, Parse::Pidl::Samba3::Parser::Parse($ndr, $basename)); - } - - if (defined($opt_samba3_server)) { - my $header = ($opt_samba3_server or "$outputdir/srv_$basename.c"); - require Parse::Pidl::Samba3::Server; - FileSave($header, Parse::Pidl::Samba3::Server::Parse($ndr, $basename)); - } - - if (defined($opt_samba3_template)) { - my $header = ($opt_samba3_template or "$outputdir/srv_$basename\_nt.c"); - require Parse::Pidl::Samba3::Template; - FileSave($header, Parse::Pidl::Samba3::Template::Parse($ndr, $basename)); - } - - if (defined($opt_samba3_client)) { - my $header = ($opt_samba3_client or "$outputdir/cli_$basename.c"); - require Parse::Pidl::Samba3::Client; - FileSave($header, Parse::Pidl::Samba3::Client::Parse($ndr, $basename)); - } - if (defined($opt_samba3_ndr_client)) { my $client = ($opt_samba3_ndr_client or "$outputdir/cli_$basename.c"); my $header = $client; $header =~ s/\.c$/\.h/; @@ -818,6 +750,14 @@ $dcom FileSave($header, $h_code); } + if (defined($opt_samba3_ndr_server)) { + my $server = ($opt_samba3_ndr_server or "$outputdir/srv_$basename.c"); + my $header = $server; $header =~ s/\.c$/\.h/; + require Parse::Pidl::Samba3::ServerNDR; + my ($c_code,$h_code) = Parse::Pidl::Samba3::ServerNDR::Parse($ndr, $header, $h_filename); + FileSave($server, $c_code); + FileSave($header, $h_code); + } } diff --git a/tools/pidl/tests/ndr_string.pl b/tools/pidl/tests/ndr_string.pl index e8e37be8c1..00ccbb31bb 100755 --- a/tools/pidl/tests/ndr_string.pl +++ b/tools/pidl/tests/ndr_string.pl @@ -4,7 +4,7 @@ # Published under the GNU General Public License use strict; -use Test::More tests => 2 * 8; +use Test::More tests => 3 * 8; use FindBin qw($RealBin); use lib "$RealBin/../lib"; use lib "$RealBin"; @@ -53,3 +53,32 @@ test_samba4_ndr("string-ascii-pull", if (r.in.data[4] != 0) return 4; '); + +test_samba4_ndr("string-out", +' + [public] void TestString([out,string] uint8 **data); +', +' + uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, + \'f\', \'o\', \'o\', 0 }; + DATA_BLOB b = { data, 8 }; + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct TestString r; + char *str = NULL; + r.out.data = &str; + + if (NT_STATUS_IS_ERR(ndr_pull_TestString(ndr, NDR_IN, &r))) + return 1; + + if (r.out.data == NULL) + return 2; + + if (*r.out.data == NULL) + return 3; + + if (strncmp(r.out.data, "foo", 3) != 0) + return 3; + + if (r.in.data[4] != 0) + return 4; +'); |