diff options
author | Jörg Mayer <jmayer@loplof.de> | 2013-11-06 22:48:50 +0000 |
---|---|---|
committer | Jörg Mayer <jmayer@loplof.de> | 2013-11-06 22:48:50 +0000 |
commit | 02fe7ff23a82034fdde5d0c1d0c3bd433559ac6a (patch) | |
tree | 7456539e9cb063cef287cd9edc3ce11cc5b7f638 /tools/pidl | |
parent | f9e5c14dde5b06b7a92c31babd0213c7a5a0ebcc (diff) |
Copy over the current WIP from samba.org::ftp/unpacked/samba_4_0_test/pidl
- As the pidl in Wireshark doesn't work anyway we can just mirror the WIP
so that patches to our code base are against the current code.
svn path=/trunk/; revision=53120
Diffstat (limited to 'tools/pidl')
-rw-r--r-- | tools/pidl/TODO | 2 | ||||
-rw-r--r-- | tools/pidl/idl.yp | 4 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/IDL.pm | 4 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/NDR.pm | 10 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/ODL.pm | 2 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba4/Header.pm | 2 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 221 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba4/Python.pm | 80 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Typelist.pm | 1 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm | 2 | ||||
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 128 | ||||
-rwxr-xr-x | tools/pidl/pidl | 2 | ||||
-rwxr-xr-x | tools/pidl/tests/ndr.pl | 39 | ||||
-rwxr-xr-x | tools/pidl/tests/samba-ndr.pl | 6 | ||||
-rwxr-xr-x | tools/pidl/tests/typelist.pl | 4 | ||||
-rwxr-xr-x | tools/pidl/tests/wireshark-ndr.pl | 2 | ||||
-rwxr-xr-x | tools/pidl/wscript | 40 |
18 files changed, 360 insertions, 191 deletions
diff --git a/tools/pidl/TODO b/tools/pidl/TODO index 87ae0c5fd3..36ae5e9632 100644 --- a/tools/pidl/TODO +++ b/tools/pidl/TODO @@ -14,7 +14,7 @@ - --explain-ndr option that dumps out parse tree ? -- seperate tables for NDR and DCE/RPC +- separate tables for NDR and DCE/RPC - maybe no tables for NDR at all? we only need them for ndrdump and that can use dlsym() diff --git a/tools/pidl/idl.yp b/tools/pidl/idl.yp index b5c5185fbe..c8a65f6f62 100644 --- a/tools/pidl/idl.yp +++ b/tools/pidl/idl.yp @@ -610,7 +610,9 @@ again: for ($parser->YYData->{INPUT}) { if (/^\#/) { - if (s/^\# (\d+) \"(.*?)\"( \d+|)//) { + # Linemarker format is described at + # http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html + if (s/^\# (\d+) \"(.*?)\"(( \d+){1,4}|)//) { $parser->YYData->{LINE} = $1-1; $parser->YYData->{FILE} = $2; goto again; diff --git a/tools/pidl/lib/Parse/Pidl/IDL.pm b/tools/pidl/lib/Parse/Pidl/IDL.pm index d4820ffe92..6927c89255 100644 --- a/tools/pidl/lib/Parse/Pidl/IDL.pm +++ b/tools/pidl/lib/Parse/Pidl/IDL.pm @@ -2576,7 +2576,9 @@ again: for ($parser->YYData->{INPUT}) { if (/^\#/) { - if (s/^\# (\d+) \"(.*?)\"( \d+|)//) { + # Linemarker format is described at + # http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html + if (s/^\# (\d+) \"(.*?)\"(( \d+){1,4}|)//) { $parser->YYData->{LINE} = $1-1; $parser->YYData->{FILE} = $2; goto again; diff --git a/tools/pidl/lib/Parse/Pidl/NDR.pm b/tools/pidl/lib/Parse/Pidl/NDR.pm index db776ae3ef..682715227f 100644 --- a/tools/pidl/lib/Parse/Pidl/NDR.pm +++ b/tools/pidl/lib/Parse/Pidl/NDR.pm @@ -171,6 +171,7 @@ sub GetElementLevelTable($$$) my $is_string = 0; my $is_fixed = 0; my $is_inline = 0; + my $is_to_null = 0; if ($d eq "*") { $is_conformant = 1; @@ -208,6 +209,10 @@ sub GetElementLevelTable($$$) delete($e->{PROPERTIES}->{string}); } + if (has_property($e, "to_null")) { + $is_to_null = 1; + } + push (@$order, { TYPE => "ARRAY", SIZE_IS => $size, @@ -218,7 +223,8 @@ sub GetElementLevelTable($$$) IS_VARYING => $is_varying, IS_CONFORMANT => $is_conformant, IS_FIXED => $is_fixed, - IS_INLINE => $is_inline + IS_INLINE => $is_inline, + IS_TO_NULL => $is_to_null }); } @@ -1067,6 +1073,7 @@ my %property_list = ( "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT", "PIPE"], "nopython" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"], "todo" => ["FUNCTION"], + "skip" => ["ELEMENT"], # union "switch_is" => ["ELEMENT"], @@ -1102,6 +1109,7 @@ my %property_list = ( "noheader" => ["ELEMENT"], "charset" => ["ELEMENT"], "length_is" => ["ELEMENT"], + "to_null" => ["ELEMENT"], ); ##################################################################### diff --git a/tools/pidl/lib/Parse/Pidl/ODL.pm b/tools/pidl/lib/Parse/Pidl/ODL.pm index 74d9ac7c04..14e77fa93f 100644 --- a/tools/pidl/lib/Parse/Pidl/ODL.pm +++ b/tools/pidl/lib/Parse/Pidl/ODL.pm @@ -70,7 +70,7 @@ sub ODL2IDL next; } my $podl = Parse::Pidl::IDL::parse_file($idl_path, $opt_incdirs); - if (defined(@$podl)) { + if (defined($podl)) { require Parse::Pidl::Typelist; my $basename = basename($idl_path, ".idl"); diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index c4374baf7c..d433f60eb7 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -183,7 +183,7 @@ sub ParseFunction($$) ); pidl ""; - pidl "if (p->rng_fault_state) {"; + pidl "if (p->fault_state) {"; pidl "\ttalloc_free(r);"; pidl "\t/* Return true here, srv_pipe_hnd.c will take care */"; pidl "\treturn true;"; diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm b/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm index 3736315120..49c5afabba 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -142,7 +142,7 @@ sub HeaderEnum($$;$) my $count = 0; my $with_val = 0; my $without_val = 0; - pidl " { __donnot_use_enum_$name=0x7FFFFFFF}\n"; + pidl " { __do_not_use_enum_$name=0x7FFFFFFF}\n"; foreach my $e (@{$enum->{ELEMENTS}}) { my $t = "$e"; my $name; diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 3d31366abf..3deab2ec95 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -261,7 +261,7 @@ sub check_fully_dereferenced($$) $nump = $_->{POINTER_INDEX}+1; } } - warning($element->{ORIGINAL}, "Got pointer for `$e->{NAME}', expected fully derefenced variable") if ($nump > length($ptr)); + warning($element->{ORIGINAL}, "Got pointer for `$e->{NAME}', expected fully dereferenced variable") if ($nump > length($ptr)); return ($origvar); } } @@ -321,39 +321,99 @@ sub check_null_pointer($$$$) } } -##################################################################### -# parse an array - pull side -sub ParseArrayPullHeader($$$$$$) +sub ParseArrayPullGetSize($$$$$$) { my ($self,$e,$l,$ndr,$var_name,$env) = @_; - my $length; my $size; if ($l->{IS_CONFORMANT}) { - $length = $size = "ndr_get_array_size($ndr, " . get_pointer_to($var_name) . ")"; + $size = "ndr_get_array_size($ndr, " . get_pointer_to($var_name) . ")"; } 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))"; + $size = "ndr_get_string_size($ndr, sizeof(*$var_name))"; } else { - $length = $size = ParseExprExt($l->{SIZE_IS}, $env, $e->{ORIGINAL}, + $size = ParseExprExt($l->{SIZE_IS}, $env, $e->{ORIGINAL}, check_null_pointer($e, $env, sub { $self->pidl(shift); }, "return ndr_pull_error($ndr, NDR_ERR_INVALID_POINTER, \"NULL Pointer for size_is()\");"), check_fully_dereferenced($e, $env)); } + $self->pidl("size_$e->{NAME}_$l->{LEVEL_INDEX} = $size;"); + my $array_size = "size_$e->{NAME}_$l->{LEVEL_INDEX}"; + + if (my $range = has_property($e, "range")) { + my ($low, $high) = split(/,/, $range, 2); + if ($low < 0) { + warning(0, "$low is invalid for the range of an array size"); + } + if ($low == 0) { + $self->pidl("if ($array_size > $high) {"); + } else { + $self->pidl("if ($array_size < $low || $array_size > $high) {"); + } + $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");"); + $self->pidl("}"); + } + + return $array_size; +} + +##################################################################### +# parse an array - pull side +sub ParseArrayPullGetLength($$$$$$;$) +{ + my ($self,$e,$l,$ndr,$var_name,$env,$array_size) = @_; + + if (not defined($array_size)) { + $array_size = $self->ParseArrayPullGetSize($e, $l, $ndr, $var_name, $env); + } + + if (not $l->{IS_VARYING}) { + return $array_size; + } + + my $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")"; + $self->pidl("length_$e->{NAME}_$l->{LEVEL_INDEX} = $length;"); + my $array_length = "length_$e->{NAME}_$l->{LEVEL_INDEX}"; + + if (my $range = has_property($e, "range")) { + my ($low, $high) = split(/,/, $range, 2); + if ($low < 0) { + warning(0, "$low is invalid for the range of an array size"); + } + if ($low == 0) { + $self->pidl("if ($array_length > $high) {"); + } else { + $self->pidl("if ($array_length < $low || $array_length > $high) {"); + } + $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");"); + $self->pidl("}"); + } + + return $array_length; +} + +##################################################################### +# parse an array - pull side +sub ParseArrayPullHeader($$$$$$) +{ + my ($self,$e,$l,$ndr,$var_name,$env) = @_; + if ((!$l->{IS_SURROUNDING}) and $l->{IS_CONFORMANT}) { $self->pidl("NDR_CHECK(ndr_pull_array_size($ndr, " . get_pointer_to($var_name) . "));"); } if ($l->{IS_VARYING}) { $self->pidl("NDR_CHECK(ndr_pull_array_length($ndr, " . get_pointer_to($var_name) . "));"); - $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")"; } - if ($length ne $size) { - $self->pidl("if ($length > $size) {"); + my $array_size = $self->ParseArrayPullGetSize($e, $l, $ndr, $var_name, $env); + my $array_length = $self->ParseArrayPullGetLength($e, $l, $ndr, $var_name, $env, $array_size); + + if ($array_length ne $array_size) { + $self->pidl("if ($array_length > $array_size) {"); $self->indent; - $self->pidl("return ndr_pull_error($ndr, NDR_ERR_ARRAY_SIZE, \"Bad array size %u should exceed array length %u\", $size, $length);"); + $self->pidl("return ndr_pull_error($ndr, NDR_ERR_ARRAY_SIZE, \"Bad array size %u should exceed array length %u\", $array_size, $array_length);"); $self->deindent; $self->pidl("}"); } @@ -383,10 +443,10 @@ sub ParseArrayPullHeader($$$$$$) } if (ArrayDynamicallyAllocated($e,$l) and not is_charset_array($e,$l)) { - $self->AllocateArrayLevel($e,$l,$ndr,$var_name,$size); + $self->AllocateArrayLevel($e,$l,$ndr,$var_name,$array_size); } - return $length; + return $array_length; } sub compression_alg($$) @@ -572,7 +632,9 @@ sub ParseElementPushLevel } } - if ($l->{TYPE} eq "POINTER" and $deferred) { + if ($l->{TYPE} eq "POINTER" and $l->{POINTER_TYPE} eq "ignore") { + $self->pidl("/* [ignore] '$e->{NAME}' */"); + } elsif ($l->{TYPE} eq "POINTER" and $deferred) { my $rel_var_name = $var_name; if ($l->{POINTER_TYPE} ne "ref") { $self->pidl("if ($var_name) {"); @@ -753,6 +815,8 @@ sub ParseElementPrint($$$$$) my($self, $e, $ndr, $var_name, $env) = @_; return if (has_property($e, "noprint")); + my $cur_depth = 0; + my $ignore_depth = 0xFFFF; if ($e->{REPRESENTATION_TYPE} ne $e->{TYPE}) { $self->pidl("ndr_print_$e->{REPRESENTATION_TYPE}($ndr, \"$e->{NAME}\", $var_name);"); @@ -766,8 +830,19 @@ sub ParseElementPrint($$$$$) } foreach my $l (@{$e->{LEVELS}}) { + $cur_depth += 1; + + if ($cur_depth > $ignore_depth) { + next; + } + if ($l->{TYPE} eq "POINTER") { $self->pidl("ndr_print_ptr($ndr, \"$e->{NAME}\", $var_name);"); + if ($l->{POINTER_TYPE} eq "ignore") { + $self->pidl("/* [ignore] '$e->{NAME}' */"); + $ignore_depth = $cur_depth; + last; + } $self->pidl("$ndr->depth++;"); if ($l->{POINTER_TYPE} ne "ref") { $self->pidl("if ($var_name) {"); @@ -815,7 +890,17 @@ sub ParseElementPrint($$$$$) } foreach my $l (reverse @{$e->{LEVELS}}) { + $cur_depth -= 1; + + if ($cur_depth > $ignore_depth) { + next; + } + if ($l->{TYPE} eq "POINTER") { + if ($l->{POINTER_TYPE} eq "ignore") { + next; + } + if ($l->{POINTER_TYPE} ne "ref") { $self->deindent; $self->pidl("}"); @@ -873,7 +958,11 @@ sub ParseDataPull($$$$$$$) $var_name = get_pointer_to($var_name); - $self->pidl("NDR_CHECK(".TypeFunctionName("ndr_pull", $l->{DATA_TYPE})."($ndr, $ndr_flags, $var_name));"); + if (has_property($e, "skip")) { + $self->pidl("/* [skip] '$var_name' */"); + } else { + $self->pidl("NDR_CHECK(".TypeFunctionName("ndr_pull", $l->{DATA_TYPE})."($ndr, $ndr_flags, $var_name));"); + } my $pl = GetPrevLevel($e, $l); @@ -911,7 +1000,11 @@ sub ParseDataPush($$$$$$$) $var_name = get_pointer_to($var_name); } - $self->pidl("NDR_CHECK(".TypeFunctionName("ndr_push", $l->{DATA_TYPE})."($ndr, $ndr_flags, $var_name));"); + if (has_property($e, "skip")) { + $self->pidl("/* [skip] '$var_name' */"); + } else { + $self->pidl("NDR_CHECK(".TypeFunctionName("ndr_push", $l->{DATA_TYPE})."($ndr, $ndr_flags, $var_name));"); + } } else { $self->ParseTypePush($l->{DATA_TYPE}, $ndr, $var_name, $primitives, $deferred); } @@ -947,6 +1040,7 @@ sub ParseMemCtxPullFlags($$$$) my ($self, $e, $l) = @_; return undef unless ($l->{TYPE} eq "POINTER" or $l->{TYPE} eq "ARRAY"); + return undef if (($l->{TYPE} eq "POINTER") and ($l->{POINTER_TYPE} eq "ignore")); return undef unless ($l->{TYPE} ne "ARRAY" or ArrayDynamicallyAllocated($e,$l)); return undef if has_fast_array($e, $l); @@ -1008,6 +1102,7 @@ sub ParseElementPullLevel my($self,$e,$l,$ndr,$var_name,$env,$primitives,$deferred) = @_; my $ndr_flags = CalcNdrFlags($l, $primitives, $deferred); + my $array_length = undef; if ($l->{TYPE} eq "ARRAY" and ($l->{IS_VARYING} or $l->{IS_CONFORMANT})) { $var_name = get_pointer_to($var_name); @@ -1021,20 +1116,7 @@ sub ParseElementPullLevel $self->ParseSubcontextPullEnd($e, $l, $ndr, $env); } elsif ($l->{TYPE} eq "ARRAY") { my $length = $self->ParseArrayPullHeader($e, $l, $ndr, $var_name, $env); - - if (my $range = has_property($e, "range")) { - my ($low, $high) = split(/,/, $range, 2); - if ($low < 0) { - warning(0, "$low is invalid for the range of an array size"); - } - if ($low == 0) { - $self->pidl("if ($length > $high) {"); - } else { - $self->pidl("if ($length < $low || $length > $high) {"); - } - $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");"); - $self->pidl("}"); - } + $array_length = $length; my $nl = GetNextLevel($e, $l); @@ -1042,7 +1124,11 @@ sub ParseElementPullLevel if ($l->{IS_ZERO_TERMINATED}) { $self->CheckStringTerminator($ndr, $e, $l, $length); } - $self->pidl("NDR_CHECK(ndr_pull_charset($ndr, $ndr_flags, ".get_pointer_to($var_name).", $length, sizeof(" . mapTypeName($nl->{DATA_TYPE}) . "), CH_$e->{PROPERTIES}->{charset}));"); + if ($l->{IS_TO_NULL}) { + $self->pidl("NDR_CHECK(ndr_pull_charset_to_null($ndr, $ndr_flags, ".get_pointer_to($var_name).", $length, sizeof(" . mapTypeName($nl->{DATA_TYPE}) . "), CH_$e->{PROPERTIES}->{charset}));"); + } else { + $self->pidl("NDR_CHECK(ndr_pull_charset($ndr, $ndr_flags, ".get_pointer_to($var_name).", $length, sizeof(" . mapTypeName($nl->{DATA_TYPE}) . "), CH_$e->{PROPERTIES}->{charset}));"); + } return; } elsif (has_fast_array($e, $l)) { if ($l->{IS_ZERO_TERMINATED}) { @@ -1063,7 +1149,9 @@ sub ParseElementPullLevel } # add additional constructions - if ($l->{TYPE} eq "POINTER" and $deferred) { + if ($l->{TYPE} eq "POINTER" and $l->{POINTER_TYPE} eq "ignore") { + $self->pidl("/* [ignore] '$e->{NAME}' */"); + } elsif ($l->{TYPE} eq "POINTER" and $deferred) { if ($l->{POINTER_TYPE} ne "ref") { $self->pidl("if ($var_name) {"); $self->indent; @@ -1083,7 +1171,7 @@ sub ParseElementPullLevel $self->ParseMemCtxPullEnd($e, $l, $ndr); if ($l->{POINTER_TYPE} ne "ref") { - if ($l->{POINTER_TYPE} eq "relative") { + if ($l->{POINTER_TYPE} eq "relative" or $l->{POINTER_TYPE} eq "relative_short") { $self->pidl("if ($ndr->offset > $ndr->relative_highest_offset) {"); $self->indent; $self->pidl("$ndr->relative_highest_offset = $ndr->offset;"); @@ -1096,26 +1184,12 @@ sub ParseElementPullLevel } } elsif ($l->{TYPE} eq "ARRAY" and not has_fast_array($e,$l) and not is_charset_array($e, $l)) { - my $length = ParseExpr($l->{LENGTH_IS}, $env, $e->{ORIGINAL}); + my $length = $array_length; 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) .")"; - } - - if (my $range = has_property($e, "range")) { - my ($low, $high) = split(/,/, $range, 2); - if ($low < 0) { - warning(0, "$low is invalid for the range of an array size"); - } - if ($low == 0) { - $self->pidl("if ($length > $high) {"); - } else { - $self->pidl("if ($length < $low || $length > $high) {"); - } - $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");"); - $self->pidl("}"); + if (not defined($length)) { + $length = $self->ParseArrayPullGetLength($e, $l, $ndr, $var_name, $env); } $var_name = get_array_element($var_name, $counter); @@ -1332,6 +1406,7 @@ sub ParseStructPush($$$$) $self->start_flags($struct, $ndr); + $self->pidl("NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);"); $self->pidl("if (ndr_flags & NDR_SCALARS) {"); $self->indent; $self->ParseStructPushPrimitives($struct, $ndr, $varname, $env); @@ -1545,16 +1620,21 @@ sub DeclarePtrVariables($$) } } -sub DeclareArrayVariables($$) +sub DeclareArrayVariables($$;$) { - my ($self,$e) = @_; + my ($self,$e,$pull) = @_; foreach my $l (@{$e->{LEVELS}}) { + next if ($l->{TYPE} ne "ARRAY"); + if (defined($pull)) { + $self->pidl("uint32_t size_$e->{NAME}_$l->{LEVEL_INDEX} = 0;"); + if ($l->{IS_VARYING}) { + $self->pidl("uint32_t length_$e->{NAME}_$l->{LEVEL_INDEX} = 0;"); + } + } next if has_fast_array($e,$l); next if is_charset_array($e,$l); - if ($l->{TYPE} eq "ARRAY") { - $self->pidl("uint32_t cntr_$e->{NAME}_$l->{LEVEL_INDEX};"); - } + $self->pidl("uint32_t cntr_$e->{NAME}_$l->{LEVEL_INDEX};"); } } @@ -1563,15 +1643,14 @@ sub DeclareArrayVariablesNoZero($$$) my ($self,$e,$env) = @_; foreach my $l (@{$e->{LEVELS}}) { + next if ($l->{TYPE} ne "ARRAY"); next if has_fast_array($e,$l); next if is_charset_array($e,$l); - if ($l->{TYPE} eq "ARRAY") { - my $length = ParseExpr($l->{LENGTH_IS}, $env, $e->{ORIGINAL}); - if ($length eq "0") { + my $length = ParseExpr($l->{LENGTH_IS}, $env, $e->{ORIGINAL}); + if ($length eq "0") { warning($e->{ORIGINAL}, "pointless array cntr: 'cntr_$e->{NAME}_$l->{LEVEL_INDEX}': length=$length"); - } else { + } else { $self->pidl("uint32_t cntr_$e->{NAME}_$l->{LEVEL_INDEX};"); - } } } } @@ -1581,6 +1660,11 @@ sub DeclareMemCtxVariables($$) my ($self,$e) = @_; foreach my $l (@{$e->{LEVELS}}) { my $mem_flags = $self->ParseMemCtxPullFlags($e, $l); + + if (($l->{TYPE} eq "POINTER") and ($l->{POINTER_TYPE} eq "ignore")) { + last; + } + if (defined($mem_flags)) { $self->pidl("TALLOC_CTX *_mem_save_$e->{NAME}_$l->{LEVEL_INDEX};"); } @@ -1637,7 +1721,7 @@ sub ParseStructPull($$$$) # declare any internal pointers we need foreach my $e (@{$struct->{ELEMENTS}}) { $self->DeclarePtrVariables($e); - $self->DeclareArrayVariables($e); + $self->DeclareArrayVariables($e, "pull"); $self->DeclareMemCtxVariables($e); } @@ -1645,6 +1729,7 @@ sub ParseStructPull($$$$) my $env = GenerateStructEnv($struct, $varname); + $self->pidl("NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);"); $self->pidl("if (ndr_flags & NDR_SCALARS) {"); $self->indent; $self->ParseStructPullPrimitives($struct,$ndr,$varname,$env); @@ -1808,6 +1893,7 @@ sub ParseUnionPush($$$$) $self->start_flags($e, $ndr); + $self->pidl("NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);"); $self->pidl("if (ndr_flags & NDR_SCALARS) {"); $self->indent; $self->ParseUnionPushPrimitives($e, $ndr, $varname); @@ -1900,8 +1986,6 @@ sub ParseUnionPullPrimitives($$$$$) if ($el->{TYPE} ne "EMPTY") { $self->indent; - $self->DeclarePtrVariables($el); - $self->DeclareArrayVariables($el); if (defined($e->{PROPERTIES}{relative_base})) { $self->pidl("NDR_CHECK(ndr_pull_align($ndr, $el->{ALIGN}));"); # set the current offset as base for relative pointers @@ -1978,6 +2062,8 @@ sub ParseUnionPull($$$$) next if ($el->{TYPE} eq "EMPTY"); next if ($double_cases{"$el->{NAME}"}); $self->DeclareMemCtxVariables($el); + $self->DeclarePtrVariables($el); + $self->DeclareArrayVariables($el, "pull"); $double_cases{"$el->{NAME}"} = 1; } @@ -1985,6 +2071,7 @@ sub ParseUnionPull($$$$) $self->pidl("level = ndr_pull_get_switch_value($ndr, $varname);"); + $self->pidl("NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);"); $self->pidl("if (ndr_flags & NDR_SCALARS) {"); $self->indent; $self->ParseUnionPullPrimitives($e,$ndr,$varname,$switch_type); @@ -2267,6 +2354,8 @@ sub ParseFunctionPush($$) $self->DeclareArrayVariables($e); } + $self->pidl("NDR_PUSH_CHECK_FN_FLAGS(ndr, flags);"); + $self->pidl("if (flags & NDR_IN) {"); $self->indent; @@ -2343,7 +2432,7 @@ sub ParseFunctionPull($$) # declare any internal pointers we need foreach my $e (@{$fn->{ELEMENTS}}) { $self->DeclarePtrVariables($e); - $self->DeclareArrayVariables($e); + $self->DeclareArrayVariables($e, "pull"); } my %double_cases = (); @@ -2354,6 +2443,8 @@ sub ParseFunctionPull($$) $double_cases{"$e->{NAME}"} = 1; } + $self->pidl("NDR_PULL_CHECK_FN_FLAGS(ndr, flags);"); + $self->pidl("if (flags & NDR_IN) {"); $self->indent; diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm index db2d79d2f6..39884ab278 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -200,9 +200,9 @@ sub PythonStruct($$$$$$) $self->pidl("static PyObject *py_$name\_get_$e->{NAME}(PyObject *obj, void *closure)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(obj);"); + $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(obj);"); $self->pidl("PyObject *py_$e->{NAME};"); - $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;"); + $self->ConvertObjectToPython("pytalloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;"); $self->pidl("return py_$e->{NAME};"); $self->deindent; $self->pidl("}"); @@ -211,14 +211,14 @@ sub PythonStruct($$$$$$) $self->pidl("static int py_$name\_set_$e->{NAME}(PyObject *py_obj, PyObject *value, void *closure)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);"); - my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; + $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); + my $mem_ctx = "pytalloc_get_mem_ctx(py_obj)"; my $l = $e->{LEVELS}[0]; my $nl = GetNextLevel($e, $l); if ($l->{TYPE} eq "POINTER" and not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and not ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}))) { - $self->pidl("talloc_unlink(py_talloc_get_mem_ctx(py_obj), $varname);"); + $self->pidl("talloc_unlink(pytalloc_get_mem_ctx(py_obj), $varname);"); } $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); $self->pidl("return 0;"); @@ -242,7 +242,7 @@ sub PythonStruct($$$$$$) $self->pidl("static PyObject *py_$name\_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; - $self->pidl("return py_talloc_new($cname, type);"); + $self->pidl("return pytalloc_new($cname, type);"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -255,10 +255,10 @@ sub PythonStruct($$$$$$) $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);"); + $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); $self->pidl("DATA_BLOB blob;"); $self->pidl("enum ndr_err_code err;"); - $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_push_flags_fn_t)ndr_push_$name);"); + $self->pidl("err = ndr_push_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_push_flags_fn_t)ndr_push_$name);"); $self->pidl("if (err != NDR_ERR_SUCCESS) {"); $self->indent; $self->pidl("PyErr_SetNdrError(err);"); @@ -271,16 +271,44 @@ sub PythonStruct($$$$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); + $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);"); + $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); $self->pidl("DATA_BLOB blob;"); + $self->pidl("int blob_length = 0;"); $self->pidl("enum ndr_err_code err;"); - $self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob.length))"); - $self->pidl("\treturn NULL;"); + $self->pidl("const char * const kwnames[] = { \"data_blob\", \"allow_remaining\", NULL };"); + $self->pidl("PyObject *allow_remaining_obj = NULL;"); + $self->pidl("bool allow_remaining = false;"); $self->pidl(""); - $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|O:__ndr_unpack__\","); + $self->indent; + $self->pidl("discard_const_p(char *, kwnames),"); + $self->pidl("&blob.data, &blob_length,"); + $self->pidl("&allow_remaining_obj)) {"); + $self->deindent; + $self->indent; + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl("blob.length = blob_length;"); + $self->pidl(""); + $self->pidl("if (allow_remaining_obj && PyObject_IsTrue(allow_remaining_obj)) {"); + $self->indent; + $self->pidl("allow_remaining = true;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("if (allow_remaining) {"); + $self->indent; + $self->pidl("err = ndr_pull_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; + $self->pidl("err = ndr_pull_struct_blob_all(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); + $self->deindent; + $self->pidl("}"); $self->pidl("if (err != NDR_ERR_SUCCESS) {"); $self->indent; $self->pidl("PyErr_SetNdrError(err);"); @@ -296,11 +324,11 @@ sub PythonStruct($$$$$$) $self->pidl("static PyObject *py_$name\_ndr_print(PyObject *py_obj)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);"); + $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); $self->pidl("PyObject *ret;"); $self->pidl("char *retstr;"); $self->pidl(""); - $self->pidl("retstr = ndr_print_struct_string(py_talloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_$name, \"$name\", object);"); + $self->pidl("retstr = ndr_print_struct_string(pytalloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_$name, \"$name\", object);"); $self->pidl("ret = PyString_FromString(retstr);"); $self->pidl("talloc_free(retstr);"); $self->pidl(""); @@ -313,7 +341,7 @@ sub PythonStruct($$$$$$) $self->pidl("static PyMethodDef $py_methods\[] = {"); $self->indent; $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.ndr_pack(object) -> blob\\nNDR pack\" },"); - $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.ndr_unpack(class, blob) -> None\\nNDR unpack\" },"); + $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS|METH_KEYWORDS, \"S.ndr_unpack(class, blob, allow_remaining=False) -> None\\nNDR unpack\" },"); $self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.ndr_print(object) -> None\\nNDR print\" },"); $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; @@ -335,7 +363,7 @@ sub PythonStruct($$$$$$) } $self->pidl(".tp_methods = $py_methods,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); - $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),"); + $self->pidl(".tp_basicsize = sizeof(pytalloc_Object),"); $self->pidl(".tp_new = py_$name\_new,"); $self->deindent; $self->pidl("};"); @@ -798,9 +826,15 @@ 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" or $orig_ctype->{NAME} eq "dom_sid28") { + if ($orig_ctype->{NAME} eq "dom_sid2" or + $orig_ctype->{NAME} eq "dom_sid28" or + $orig_ctype->{NAME} eq "dom_sid0") { $orig_ctype->{NAME} = "dom_sid"; } + if ($orig_ctype->{NAME} eq "spoolss_security_descriptor") { + $orig_ctype->{NAME} = "security_descriptor"; + } + my $ctype = resolveType($orig_ctype); unless (defined($ctype->{BASEFILE})) { return undef; @@ -919,13 +953,13 @@ sub ConvertObjectFromPythonData($$$$$$;$) return; } $self->pidl("PY_CHECK_TYPE($ctype_name, $cvar, $fail);"); - $self->pidl("if (talloc_reference($mem_ctx, py_talloc_get_mem_ctx($cvar)) == NULL) {"); + $self->pidl("if (talloc_reference($mem_ctx, pytalloc_get_mem_ctx($cvar)) == NULL) {"); $self->indent; $self->pidl("PyErr_NoMemory();"); $self->pidl("$fail"); $self->deindent; $self->pidl("}"); - $self->assign($target, "(".mapTypeName($ctype)." *)py_talloc_get_ptr($cvar)"); + $self->assign($target, "(".mapTypeName($ctype)." *)pytalloc_get_ptr($cvar)"); return; } @@ -1137,13 +1171,13 @@ sub ConvertScalarToPython($$$) } # Not yet supported - if ($ctypename eq "string_array") { return "PyCObject_FromTallocPtr($cvar)"; } + if ($ctypename eq "string_array") { return "pytalloc_CObject_FromTallocPtr($cvar)"; } if ($ctypename eq "ipv4address") { return "PyString_FromStringOrNULL($cvar)"; } if ($ctypename eq "ipv6address") { return "PyString_FromStringOrNULL($cvar)"; } if ($ctypename eq "dnsp_name") { return "PyString_FromStringOrNULL($cvar)"; } if ($ctypename eq "dnsp_string") { return "PyString_FromStringOrNULL($cvar)"; } if ($ctypename eq "pointer") { - return "PyCObject_FromTallocPtr($cvar)"; + return "pytalloc_CObject_FromTallocPtr($cvar)"; } die("Unknown scalar type $ctypename"); @@ -1176,7 +1210,7 @@ sub ConvertObjectToPythonData($$$$$;$) error($location, "Unable to determine origin of type `" . mapTypeName($ctype) . "'"); return "NULL"; # FIXME! } - return "py_talloc_reference_ex($ctype_name, $mem_ctx, $cvar)"; + return "pytalloc_reference_ex($ctype_name, $mem_ctx, $cvar)"; } fatal($location, "unknown type $actual_ctype->{TYPE} for ".mapTypeName($ctype) . ": $cvar"); diff --git a/tools/pidl/lib/Parse/Pidl/Typelist.pm b/tools/pidl/lib/Parse/Pidl/Typelist.pm index 4f26a92ed2..06c0d58d91 100644 --- a/tools/pidl/lib/Parse/Pidl/Typelist.pm +++ b/tools/pidl/lib/Parse/Pidl/Typelist.pm @@ -84,6 +84,7 @@ my %aliases = ( "short" => "int16", "HYPER_T" => "hyper", "HRESULT" => "COMRESULT", + "mode_t" => "uint32", ); sub expandAlias($) diff --git a/tools/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm b/tools/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm index 1dec647d87..fbdaa9ab19 100644 --- a/tools/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm +++ b/tools/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm @@ -21,7 +21,7 @@ files. Conformance files are simple text files with a single command on each line. Empty lines and lines starting with a '#' character are ignored. -Arguments to commands are seperated by spaces. +Arguments to commands are separated by spaces. The following commands are currently supported: diff --git a/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index d34a14054c..91ef118351 100644 --- a/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -150,7 +150,7 @@ sub Enum($$$$) } $self->pidl_hdr("extern const value_string $valsstring\[];"); - $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_);"); + $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_);"); $self->pidl_def("const value_string ".$valsstring."[] = {"); foreach (@{$e->{ELEMENTS}}) { @@ -163,7 +163,7 @@ sub Enum($$$$) $self->pidl_fn_start($dissectorname); $self->pidl_code("int"); - $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)"); $self->pidl_code("{"); $self->indent; $self->pidl_code("g$e->{BASE_TYPE} parameter=0;"); @@ -172,7 +172,7 @@ sub Enum($$$$) $self->pidl_code("parameter=(g$e->{BASE_TYPE})*param;"); $self->deindent; $self->pidl_code("}"); - $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, di, drep, hf_index, ¶meter);"); + $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, ¶meter);"); $self->pidl_code("if(param){"); $self->indent; $self->pidl_code("*param=(guint32)parameter;"); @@ -185,7 +185,7 @@ sub Enum($$$$) my $enum_size = $e->{BASE_TYPE}; $enum_size =~ s/uint//g; - $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8); + $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8); } sub Bitmap($$$$) @@ -195,11 +195,11 @@ sub Bitmap($$$$) $self->register_ett("ett_$ifname\_$name"); - $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"); + $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"); $self->pidl_fn_start($dissectorname); $self->pidl_code("int"); - $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); $self->pidl_code("{"); $self->indent; $self->pidl_code("proto_item *item = NULL;"); @@ -215,12 +215,12 @@ sub Bitmap($$$$) $self->pidl_code("if (parent_tree) {"); $self->indent; - $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);"); + $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, DREP_ENC_INTEGER(drep));"); $self->pidl_code("tree = proto_item_add_subtree(item,ett_$ifname\_$name);"); $self->deindent; $self->pidl_code("}\n"); - $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, di, drep, -1, &flags);"); + $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);"); $self->pidl_code("proto_item_append_text(item, \": \");\n"); $self->pidl_code("if (!flags)"); @@ -267,7 +267,7 @@ sub Bitmap($$$$) my $size = $e->{BASE_TYPE}; $size =~ s/uint//g; - $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8); + $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8); } sub ElementLevel($$$$$$$$) @@ -285,26 +285,26 @@ sub ElementLevel($$$$$$$$) } elsif ($l->{LEVEL} eq "EMBEDDED") { $type = "embedded"; } - $self->pidl_code("offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, di, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes})) . " ($e->{TYPE})\",$hf);"); + $self->pidl_code("offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes})) . " ($e->{TYPE})\",$hf);"); } elsif ($l->{TYPE} eq "ARRAY") { if ($l->{IS_INLINE}) { error($e->{ORIGINAL}, "Inline arrays not supported"); } elsif ($l->{IS_FIXED}) { $self->pidl_code("int i;"); $self->pidl_code("for (i = 0; i < $l->{SIZE_IS}; i++)"); - $self->pidl_code("\toffset = $myname\_(tvb, offset, pinfo, tree, di, drep);"); + $self->pidl_code("\toffset = $myname\_(tvb, offset, pinfo, tree, drep);"); } else { my $type = ""; $type .= "c" if ($l->{IS_CONFORMANT}); $type .= "v" if ($l->{IS_VARYING}); unless ($l->{IS_ZERO_TERMINATED}) { - $self->pidl_code("offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, di, drep, $myname\_);"); + $self->pidl_code("offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);"); } else { my $nl = GetNextLevel($e,$l); $self->pidl_code("char *data;"); $self->pidl_code(""); - $self->pidl_code("offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, di, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);"); + $self->pidl_code("offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);"); $self->pidl_code("proto_item_append_text(tree, \": %s\", data);"); } } @@ -317,10 +317,10 @@ sub ElementLevel($$$$$$$$) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) { $self->pidl_code("char *data;\n"); - $self->pidl_code("offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, di, drep, $bs, $hf, FALSE, &data);"); + $self->pidl_code("offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);"); $self->pidl_code("proto_item_append_text(tree, \": %s\", data);"); } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) { - $self->pidl_code("offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, di, drep, $bs, $hf, FALSE, NULL);"); + $self->pidl_code("offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);"); } elsif (property_matches($e, "flag", ".*STR_NULLTERM.*")) { if ($bs == 2) { $self->pidl_code("offset = dissect_null_term_wstring(tvb, offset, pinfo, tree, drep, $hf , 0);") @@ -333,7 +333,7 @@ sub ElementLevel($$$$$$$$) } elsif ($l->{DATA_TYPE} eq "DATA_BLOB") { my $remain = 0; $remain = 1 if (property_matches($e->{ORIGINAL}, "flag", ".*LIBNDR_FLAG_REMAINING.*")); - $self->pidl_code("offset = dissect_ndr_datablob(tvb, offset, pinfo, tree, di, drep, $hf, $remain);"); + $self->pidl_code("offset = dissect_ndr_datablob(tvb, offset, pinfo, tree, drep, $hf, $remain);"); } else { my $call; @@ -348,7 +348,7 @@ sub ElementLevel($$$$$$$$) $call= $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME}; $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{USED} = 1; } else { - $self->pidl_code("offset = $ifname\_dissect_struct_" . $l->{DATA_TYPE} . "(tvb,offset,pinfo,tree,di,drep,$hf,$param);"); + $self->pidl_code("offset = $ifname\_dissect_struct_" . $l->{DATA_TYPE} . "(tvb,offset,pinfo,tree,drep,$hf,$param);"); return; } @@ -364,7 +364,9 @@ sub ElementLevel($$$$$$$$) } my $num_bits = ($l->{HEADER_SIZE}*8); my $hf2 = $self->register_hf_field($hf."_", "Subcontext length", "$ifname.$pn.$_->{NAME}subcontext", "FT_UINT$num_bits", "BASE_HEX", "NULL", 0, ""); + $num_bits = 3264 if ($num_bits == 32); $self->{hf_used}->{$hf2} = 1; + $self->pidl_code("dcerpc_info *di = (dcerpc_info*)pinfo->private_data;"); $self->pidl_code("guint$num_bits size;"); $self->pidl_code("int conformant = di->conformant_run;"); $self->pidl_code("tvbuff_t *subtvb;"); @@ -373,7 +375,12 @@ sub ElementLevel($$$$$$$$) # and conformant run skips the dissections of scalars ... $self->pidl_code("if (!conformant) {"); $self->indent; - $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, di, drep, $hf2, &size);"); + $self->pidl_code("guint32 saved_flags = di->call_data->flags;"); + $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf2, &size);"); + # This is a subcontext, there is normally no such thing as + # 64 bit NDR is subcontext so we clear the flag so that we can + # continue to dissect handmarshalled stuff with pidl + $self->pidl_code("di->call_data->flags &= ~DCERPC_IS_NDR64;"); $self->pidl_code("subtvb = tvb_new_subset(tvb, offset, size, -1);"); if ($param ne 0) { @@ -382,6 +389,7 @@ sub ElementLevel($$$$$$$$) $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep);"); } $self->pidl_code("offset += size;"); + $self->pidl_code("di->call_data->flags = saved_flags;"); $self->deindent; $self->pidl_code("}"); } else { @@ -410,10 +418,10 @@ sub Element($$$$$) } $moreparam = ", $switch_type *".$name; $param = $name; - $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, &$name);"; + $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep, &$name);"; } else { $moreparam = ""; - $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep);"; + $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);"; } @@ -455,10 +463,10 @@ sub Element($$$$$) $param = "*$param"; } next if ($_->{TYPE} eq "SWITCH"); - $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_$moreparam);"); + $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_$moreparam);"); $self->pidl_fn_start("$dissectorname$add"); $self->pidl_code("static int"); - $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_$moreparam)"); + $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_$moreparam)"); $self->pidl_code("{"); $self->indent; @@ -495,7 +503,7 @@ sub Function($$$) $self->PrintIdl(DumpFunction($fn->{ORIGINAL})); $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_response"); $self->pidl_code("static int"); - $self->pidl_code("$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_)"); + $self->pidl_code("$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"); $self->pidl_code("{"); $self->indent; if ( not defined($fn->{RETURN_TYPE})) { @@ -518,19 +526,19 @@ sub Function($$$) foreach (@{$fn->{ELEMENTS}}) { if (grep(/out/,@{$_->{DIRECTION}})) { $self->pidl_code("$dissectornames{$_->{NAME}}"); - $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, di, drep);"); + $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"); $self->pidl_code(""); } } if (not defined($fn->{RETURN_TYPE})) { } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { - $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_status, &status);\n"); + $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n"); $self->pidl_code("if (status != 0)"); $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n"); $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"]; } elsif ($fn->{RETURN_TYPE} eq "WERROR") { - $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_werror, &status);\n"); + $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"); $self->pidl_code("if (status != 0)"); $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n"); @@ -540,12 +548,12 @@ sub Function($$$) my $return_type = "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}); my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type->{DATA}); - $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); + $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); $self->pidl_code("if (status != 0)"); $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %s\", val_to_str(status, $ifname\_$fn->{RETURN_TYPE}\_vals, \"Unknown " . $fn->{RETURN_TYPE} . " error 0x%08x\"));\n"); $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; } elsif ($type->{DATA}->{TYPE} eq "SCALAR") { - $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); + $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); $self->pidl_code("if (status != 0)"); $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n"); $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; @@ -559,14 +567,14 @@ sub Function($$$) $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_request"); $self->pidl_code("static int"); - $self->pidl_code("$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_)"); + $self->pidl_code("$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"); $self->pidl_code("{"); $self->indent; $self->pidl_code("pinfo->dcerpc_procedure_name=\"${fn_name}\";"); foreach (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$_->{DIRECTION}})) { $self->pidl_code("$dissectornames{$_->{NAME}}"); - $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, di, drep);"); + $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"); } } @@ -622,16 +630,19 @@ sub Struct($$$$) $res.="\t".$self->Element($_, $name, $ifname, $switch_info)."\n\n"; } - $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"); + $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"); $self->pidl_fn_start($dissectorname); $self->pidl_code("int"); - $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); $self->pidl_code("{"); $self->indent; $self->pidl_code($_) foreach (@$vars); $self->pidl_code("proto_item *item = NULL;"); $self->pidl_code("proto_tree *tree = NULL;"); + if ($e->{ALIGN} > 1) { + $self->pidl_code("dcerpc_info *di = (dcerpc_info *)pinfo->private_data;"); + } $self->pidl_code("int old_offset;"); $self->pidl_code(""); @@ -644,7 +655,7 @@ sub Struct($$$$) $self->pidl_code(""); $self->pidl_code("if (parent_tree) {"); $self->indent; - $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);"); + $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);"); $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);"); $self->deindent; $self->pidl_code("}"); @@ -666,7 +677,7 @@ sub Struct($$$$) $self->pidl_code("}\n"); $self->pidl_fn_end($dissectorname); - $self->register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,di,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); + $self->register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); } sub Union($$$$) @@ -701,7 +712,7 @@ sub Union($$$$) $self->pidl_fn_start($dissectorname); $self->pidl_code("static int"); - $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); $self->pidl_code("{"); $self->indent; $self->pidl_code("proto_item *item = NULL;"); @@ -725,7 +736,7 @@ sub Union($$$$) $self->pidl_code(""); if (defined $switch_type) { - $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, di, drep, hf_index, &level);"); + $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);"); if ($e->{ALIGN} > 1) { $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); @@ -743,7 +754,7 @@ sub Union($$$$) $self->pidl_code("}"); $self->pidl_fn_end($dissectorname); - $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); + $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); } sub Const($$$) @@ -964,31 +975,34 @@ sub Initialize($$) foreach my $bytes (qw(1 2 4 8)) { my $bits = $bytes * 8; - $self->register_type("uint$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes); - $self->register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); + $self->register_type("uint$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes); + $self->register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); } - $self->register_type("hyper", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 8); - $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4); - $self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); - $self->register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); - $self->register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4); - $self->register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8); - $self->register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4); - $self->register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); - $self->register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); - $self->register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); - $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, di, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); - $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); + $self->register_type("uint3264", "offset = dissect_ndr_uint3264(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT32", "BASE_DEC", 0, "NULL", 8); + $self->register_type("hyper", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 8); + $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4); + $self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + $self->register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + $self->register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4); + $self->register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8); + $self->register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4); + $self->register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); + $self->register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); + $self->register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); + $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); + $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); $self->register_type("SID", " + dcerpc_info *di = (dcerpc_info *)pinfo->private_data; + di->hf_index = \@HF\@; - offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, di, drep, param); + offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param); ","FT_STRING", "BASE_NONE", 0, "NULL", 4); $self->register_type("WERROR", - "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4); + "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4); $self->register_type("NTSTATUS", - "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); + "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); } @@ -1007,9 +1021,9 @@ sub Parse($$$$$) This filter was automatically generated from $idl_file and $cnf_file. - Pidl is a perl based IDL compiler for DCE/RPC idl files. + Pidl is a perl based IDL compiler for DCE/RPC idl files. It is maintained by the Samba team, not the Wireshark team. - Instructions on how to download and install Pidl can be + Instructions on how to download and install Pidl can be found at http://wiki.wireshark.org/Pidl \$Id\$ @@ -1178,7 +1192,7 @@ sub DumpHfList($) foreach (values %{$self->{conformance}->{header_fields}}) { - $res .= "\t{ &$_->{INDEX}, + $res .= "\t{ &$_->{INDEX}, { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str_or_null($_->{BLURB}).", HFILL }}, "; } diff --git a/tools/pidl/pidl b/tools/pidl/pidl index 2a46e92925..c65092ee9a 100755 --- a/tools/pidl/pidl +++ b/tools/pidl/pidl @@ -605,7 +605,7 @@ sub process_file($) require Parse::Pidl::IDL; $pidl = Parse::Pidl::IDL::parse_file($idl_file, \@opt_incdirs); - defined @$pidl || die "Failed to parse $idl_file"; + defined $pidl || die "Failed to parse $idl_file"; } require Parse::Pidl::Typelist; diff --git a/tools/pidl/tests/ndr.pl b/tools/pidl/tests/ndr.pl index 9c301892ae..b6fd4899b0 100755 --- a/tools/pidl/tests/ndr.pl +++ b/tools/pidl/tests/ndr.pl @@ -22,7 +22,7 @@ my $e = { 'PARENT' => { TYPE => 'STRUCT' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { 'IS_DEFERRED' => 0, 'LEVEL_INDEX' => 0, @@ -33,7 +33,7 @@ is_deeply(GetElementLevelTable($e, "unique"), [ } ]); -my $ne = ParseElement($e, "unique"); +my $ne = ParseElement($e, "unique", 0); is($ne->{ORIGINAL}, $e); is($ne->{NAME}, "v"); is($ne->{ALIGN}, 1); @@ -60,7 +60,7 @@ $e = { 'TYPE' => 'uint8', 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -90,7 +90,7 @@ $e = { 'PARENT' => { TYPE => 'STRUCT' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -128,7 +128,7 @@ $e = { 'PARENT' => { TYPE => 'STRUCT' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -158,7 +158,7 @@ $e = { 'PARENT' => { TYPE => 'STRUCT' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -204,7 +204,7 @@ $e = { 'PARENT' => { TYPE => 'STRUCT' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "ref"), [ +is_deeply(GetElementLevelTable($e, "ref", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -250,7 +250,7 @@ $e = { 'PARENT' => { TYPE => 'FUNCTION' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -280,7 +280,7 @@ $e = { 'PARENT' => { TYPE => 'FUNCTION' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -326,7 +326,7 @@ $e = { 'PARENT' => { TYPE => 'FUNCTION' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "unique"), [ +is_deeply(GetElementLevelTable($e, "unique", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -372,7 +372,7 @@ $e = { 'PARENT' => { TYPE => 'FUNCTION' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "ref"), [ +is_deeply(GetElementLevelTable($e, "ref", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -418,7 +418,7 @@ $e = { 'PARENT' => { TYPE => 'FUNCTION' }, 'LINE' => 42 }; -is_deeply(GetElementLevelTable($e, "ref"), [ +is_deeply(GetElementLevelTable($e, "ref", 0), [ { LEVEL_INDEX => 0, IS_DEFERRED => 0, @@ -463,7 +463,7 @@ $e = { 'PARENT' => { TYPE => 'STRUCT' }, 'LINE' => 42 }; -$ne = ParseElement($e, undef); +$ne = ParseElement($e, undef, 0); is($ne->{REPRESENTATION_TYPE}, "bar"); # representation_type @@ -476,7 +476,7 @@ $e = { 'PARENT' => { TYPE => 'STRUCT' }, 'LINE' => 42 }; -$ne = ParseElement($e, undef); +$ne = ParseElement($e, undef, 0); is($ne->{REPRESENTATION_TYPE}, "uint8"); is(align_type("hyper"), 8); @@ -521,7 +521,7 @@ $t = { }, ALIGN => undef }; -is_deeply(ParseType($t->{ORIGINAL}, "ref"), $t); +is_deeply(ParseType($t->{ORIGINAL}, "ref", 0), $t); $t = { TYPE => "UNION", @@ -530,13 +530,14 @@ $t = { ELEMENTS => undef, PROPERTIES => undef, HAS_DEFAULT => 0, + IS_MS_UNION => 0, ORIGINAL => { TYPE => "UNION", NAME => "foo" }, ALIGN => undef }; -is_deeply(ParseType($t->{ORIGINAL}, "ref"), $t); +is_deeply(ParseType($t->{ORIGINAL}, "ref", 0), $t); ok(not can_contain_deferred("uint32")); ok(can_contain_deferred("some_unknown_type")); @@ -553,8 +554,8 @@ ok(not can_contain_deferred({ TYPE => "TYPEDEF", ok(can_contain_deferred({ TYPE => "STRUCT", ELEMENTS => [ { TYPE => "someunknowntype" } ]})); # Make sure the elements for a enum without body aren't filled in -ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref")->{ELEMENTS})); +ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref", 0)->{ELEMENTS})); # Make sure the elements for a bitmap without body aren't filled in -ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref")->{ELEMENTS})); +ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref", 0)->{ELEMENTS})); # Make sure the elements for a union without body aren't filled in -ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, "ref")->{ELEMENTS})); +ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, "ref", 0)->{ELEMENTS})); diff --git a/tools/pidl/tests/samba-ndr.pl b/tools/pidl/tests/samba-ndr.pl index e257817809..7c53cbc76f 100755 --- a/tools/pidl/tests/samba-ndr.pl +++ b/tools/pidl/tests/samba-ndr.pl @@ -221,7 +221,8 @@ $generator->ParseStructPush({ PROPERTIES => {}, ALIGN => 4, ELEMENTS => [ ]}, "ndr", "x"); -is($generator->{res}, "if (ndr_flags & NDR_SCALARS) { +is($generator->{res}, "NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); +if (ndr_flags & NDR_SCALARS) { NDR_CHECK(ndr_push_align(ndr, 4)); NDR_CHECK(ndr_push_trailer_align(ndr, 4)); } @@ -245,7 +246,8 @@ $generator->ParseStructPush({ ALIGN => 4, SURROUNDING_ELEMENT => $e, ELEMENTS => [ $e ]}, "ndr", "x"); -is($generator->{res}, "if (ndr_flags & NDR_SCALARS) { +is($generator->{res}, "NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); +if (ndr_flags & NDR_SCALARS) { NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, ndr_string_array_size(ndr, x->el1))); NDR_CHECK(ndr_push_align(ndr, 4)); NDR_CHECK(ndr_push_mytype(ndr, NDR_SCALARS, &x->el1)); diff --git a/tools/pidl/tests/typelist.pl b/tools/pidl/tests/typelist.pl index e99b016487..681c0eacfd 100755 --- a/tools/pidl/tests/typelist.pl +++ b/tools/pidl/tests/typelist.pl @@ -52,14 +52,14 @@ is(1, typeIs("uint32", "SCALAR")); is(0, typeIs("uint32", "ENUM")); is(1, hasType("foo")); -is(0, hasType("nonexistant")); +is(0, hasType("nonexistent")); is(0, hasType({TYPE => "ENUM", NAME => "someUnknownType"})); is(1, hasType({TYPE => "ENUM", NAME => "foo"})); is(1, hasType({TYPE => "ENUM"})); is(1, hasType({TYPE => "STRUCT"})); is(1, is_scalar("uint32")); -is(0, is_scalar("nonexistant")); +is(0, is_scalar("nonexistent")); is(1, is_scalar({TYPE => "ENUM"})); is(0, is_scalar({TYPE => "STRUCT"})); is(1, is_scalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM" }})); diff --git a/tools/pidl/tests/wireshark-ndr.pl b/tools/pidl/tests/wireshark-ndr.pl index 8c2cd47584..49ecc5c035 100755 --- a/tools/pidl/tests/wireshark-ndr.pl +++ b/tools/pidl/tests/wireshark-ndr.pl @@ -227,7 +227,7 @@ $x->{conformance} = { }; is($x->DumpHfList(), "\tstatic hf_register_info hf[] = { - { &hf_bla, + { &hf_bla, { \"Bla\", \"bla.field\", FT_UINT32, BASE_DEC, NULL, 255, \"NULL\", HFILL }}, }; "); diff --git a/tools/pidl/wscript b/tools/pidl/wscript index 8cb0c6f5b3..7a25734663 100755 --- a/tools/pidl/wscript +++ b/tools/pidl/wscript @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os +import os, sys, Logs from samba_utils import MODE_755 def set_options(opt): @@ -46,26 +46,40 @@ def build(bld): blib_bld = os.path.join(bld.srcnode.abspath(bld.env), 'pidl/blib') - link_command = 'rm -rf blib && ln -fs blib %s' % blib_bld - bld.SET_BUILD_GROUP('final') if 'POD2MAN' in bld.env and bld.env['POD2MAN'] != '': for src, manpage in pidl_manpages.iteritems(): - bld(rule='${PERL} ${POD2MAN} -c "Samba Documentation" ${SRC} ${TGT}', + bld(rule='${POD2MAN} -c "Samba Documentation" ${SRC} ${TGT}', shell=True, source=src, install_path=os.path.dirname(bld.EXPAND_VARIABLES('${MANDIR}/'+manpage)), target=os.path.basename(manpage)) - # we want to prefer the git version of the parsers if we can. Only if the - # source has changed do we want to re-run yapp - need_yapp_build = ('YAPP' in bld.env and ( + # we want to prefer the git version of the parsers if we can. + # Only if the source has changed do we want to re-run yapp + # But we force the developer to use the pidl standalone build + # to regenerate the files. + # TODO: only warn in developer mode and if 'git diff HEAD' + # shows a difference + warn_about_grammar_changes = ('PIDL_BUILD_WARNINGS' in bld.env and ( bld.IS_NEWER('idl.yp', 'lib/Parse/Pidl/IDL.pm') or bld.IS_NEWER('expr.yp', 'lib/Parse/Pidl/Expr.pm'))) - if need_yapp_build: - t = bld.SAMBA_GENERATOR('pidl_parser', - source='idl.yp expr.yp', - target='lib/Parse/Pidl/IDL.pm lib/Parse/Pidl/Expr.pm Makefile.PL', - rule='cd ${pidl_srcdir} && ${LINK_COMMAND} && ${PERL} Makefile.PL && make lib/Parse/Pidl/IDL.pm lib/Parse/Pidl/Expr.pm && rm -f Makefile Makefile.old && rm -f blib') - t.env.LINK_COMMAND = link_command + if warn_about_grammar_changes: + Logs.warn(''' +Pidl grammar files have changed. Please use the pidl standalone build +to regenerate them with yapp. + +$ cd ../pidl +$ perl Makefile.PL +$ make lib/Parse/Pidl/IDL.pm lib/Parse/Pidl/Expr.pm +$ git add lib/Parse/Pidl/IDL.pm lib/Parse/Pidl/Expr.pm +$ git commit +$ cd - + +If your 100% sure you haven't changed idl.yp and expr.yp +try this to avoid this message: + +$ touch ../pidl/lib/Parse/Pidl/IDL.pm ../pidl/lib/Parse/Pidl/Expr.pm +''') + |