PIDL: Difference between revisions

From SambaWiki
(Needs information at least from the readmes)
m (/* changed layout :/)
Line 3: Line 3:
TO CLEANUP:
TO CLEANUP:


Pidl works by building a parse tree from a .pidl file (a simple
Pidl works by building a parse tree from a .pidl file (a simple dump of it's internal parse tree) or a .idl file (a file format mostly like the IDL file format midl uses). The IDL file parser is in idl.yp (a yacc file converted to perl code by yapp)
dump of it's internal parse tree) or a .idl file
(a file format mostly like the IDL file format midl uses).
The IDL file parser is in idl.yp (a yacc file converted to
perl code by yapp)


pidl is an IDL compiler written in Perl that aims to be somewhat
pidl is an IDL compiler written in Perl that aims to be somewhat compatible with the midl compiler. IDL is short for "Interface Definition Language".
compatible with the midl compiler. IDL is short for
"Interface Definition Language".


pidl can generate stubs for DCE/RPC server code, DCE/RPC
pidl can generate stubs for DCE/RPC server code, DCE/RPC client code and Wireshark dissectors for DCE/RPC traffic.
client code and Wireshark dissectors for DCE/RPC traffic.


IDL compilers like pidl take a description of an interface as their input and use it to generate C (though support for other languages may be added later) code that can use these interfaces, pretty print data sent using these interfaces, or even generate Wireshark dissectors that can parse data sent over the wire by these interfaces.
IDL compilers like pidl take a description
of an interface as their input and use it to generate C
(though support for other languages may be added later) code that
can use these interfaces, pretty print data sent
using these interfaces, or even generate Wireshark
dissectors that can parse data sent over the
wire by these interfaces.


pidl takes IDL files in the same format as is used by midl,
pidl takes IDL files in the same format as is used by midl,
Line 33: Line 20:
both marshalling/unmarshalling and debugging purposes).
both marshalling/unmarshalling and debugging purposes).


=head1 IDL SYNTAX
=IDL SYNTAX=


IDL files are always preprocessed using the C preprocessor.
IDL files are always preprocessed using the C preprocessor.


Pretty much everything in an interface (the interface itself, functions,
Pretty much everything in an interface (the interface itself, functions, parameters) can have attributes (or properties whatever name you give them). Attributes always prepend the element they apply to and are surrounded by square brackets ([]). Multiple attributes are separated by comma's; arguments to attributes are specified between parentheses.
parameters) can have attributes (or properties whatever name you give them).
Attributes always prepend the element they apply to and are surrounded
by square brackets ([]). Multiple attributes are separated by comma's;
arguments to attributes are specified between parentheses.


See the section COMPATIBILITY for the list of attributes that
See the section COMPATIBILITY for the list of attributes that pidl supports.
pidl supports.


C-style comments can be used.
C-style comments can be used.


=head2 CONFORMANT ARRAYS
==CONFORMANT ARRAYS==


A conformant array is one with that ends in [*] or []. The strange
A conformant array is one with that ends in [*] or []. The strange things about conformant arrays are that they can only appear as the last element of a structure (unless there is a pointer to the conformant array, of course) and the array size appears before the structure itself on the wire.
things about conformant arrays are that they can only appear as the last
element of a structure (unless there is a pointer to the conformant array,
of course) and the array size appears before the structure itself on the wire.


So, in this example:
So, in this example:


typedef struct {
typedef struct {
long abc;
long abc;
long count;
long count;
long foo;
long foo;
[size_is(count)] long s[*];
[size_is(count)] long s[*];
} Struct1;
} Struct1;


it appears like this:
it appears like this:
Line 68: Line 47:
[size_is] [abc] [count] [foo] [s...]
[size_is] [abc] [count] [foo] [s...]


the first [size_is] field is the allocation size of the array, and
the first [size_is] field is the allocation size of the array, and occurs before the array elements and even before the structure alignment.
occurs before the array elements and even before the structure
alignment.


Note that size_is() can refer to a constant, but that doesn't change
Note that size_is() can refer to a constant, but that doesn't change the wire representation. It does not make the array a fixed array.
the wire representation. It does not make the array a fixed array.


midl.exe would write the above array as the following C header:
midl.exe would write the above array as the following C header:


typedef struct {
typedef struct {
long abc;
long abc;
long count;
long count;
long foo;
long foo;
long s[1];
long s[1];
} Struct1;
} Struct1;


pidl takes a different approach, and writes it like this:
pidl takes a different approach, and writes it like this:


typedef struct {
typedef struct {
long abc;
long abc;
long count;
long count;
long foo;
long foo;
long *s;
long *s;
} Struct1;
} Struct1;


=head2 VARYING ARRAYS
==VARYING ARRAYS==


A varying array looks like this:
A varying array looks like this:


typedef struct {
typedef struct {
long abc;
long abc;
long count;
long count;
long foo;
long foo;
[size_is(count)] long *s;
[size_is(count)] long *s;
} Struct1;
} Struct1;


This will look like this on the wire:
This will look like this on the wire:
Line 108: Line 84:
[abc] [count] [foo] [PTR_s] [count] [s...]
[abc] [count] [foo] [PTR_s] [count] [s...]


=head2 FIXED ARRAYS
==FIXED ARRAYS==


A fixed array looks like this:
A fixed array looks like this:
Line 116: Line 92:
} Struct1;
} Struct1;


The NDR representation looks just like 10 separate long
The NDR representation looks just like 10 separate long declarations. The array size is not encoded on the wire.
declarations. The array size is not encoded on the wire.


pidl also supports "inline" arrays, which are not part of the IDL/NDR
pidl also supports "inline" arrays, which are not part of the IDL/NDR standard. These are declared like this:
standard. These are declared like this:


typedef struct {
typedef struct {
uint32 foo;
uint32 foo;
uint32 count;
uint32 count;
Line 133: Line 107:
[foo] [count] [bar] [s...]
[foo] [count] [bar] [s...]


Fixed arrays are an extension added to support some of the strange
Fixed arrays are an extension added to support some of the strange embedded structures in security descriptors and spoolss.
embedded structures in security descriptors and spoolss.


This section is by no means complete. See the OpenGroup and MSDN
This section is by no means complete. See the OpenGroup and MSDN documentation for additional information.
documentation for additional information.


=head1 COMPATIBILITY WITH MIDL
=COMPATIBILITY WITH MIDL=


=head2 Missing features in pidl
== Missing features in pidl==


The following MIDL features are not (yet) implemented in pidl
The following MIDL features are not (yet) implemented in pidl
Line 162: Line 134:
=back
=back


=head2 Supported attributes and statements
==Supported attributes and statements==


in, out, ref, length_is, switch_is, size_is, uuid, case, default, string,
in, out, ref, length_is, switch_is, size_is, uuid, case, default, string, unique, ptr, pointer_default, v1_enum, object, helpstring, range, local, call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as, transmit_as, import, include, cpp_quote.
unique, ptr, pointer_default, v1_enum, object, helpstring, range, local,
call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as,
transmit_as, import, include, cpp_quote.


=head2 PIDL Specific properties
==PIDL Specific properties==


*public
=over 4
:The [public] property on a structure or union is a pidl extension that forces the generated pull/push functions to be non-static. This allows you to declare types that can be used between modules. If you don't specify [public] then pull/push functions for other than top-level functions are declared static.


* noprint
=item public
:The [noprint] property is a pidl extension that allows you to specify that pidl should not generate a ndr_print_*() function for that structure or union. This is used when you wish to define your own print function that prints a structure in a nicer manner. A good example is the use of [noprint] on dom_sid, which allows the pretty-printing of SIDs.


* value
The [public] property on a structure or union is a pidl extension that
:The [value(expression)] property is a pidl extension that allows you to specify the value of a field when it is put on the wire. This
forces the generated pull/push functions to be non-static. This allows
allows fields that always have a well-known value to be automatically filled in, thus making the API more programmer friendly. The expression can be any C expression.
you to declare types that can be used between modules. If you don't
specify [public] then pull/push functions for other than top-level
functions are declared static.


*relative
=item noprint
:The [relative] property can be supplied on a pointer. When it is used it declares the pointer as a spoolss style "relative" pointer, which means it appears on the wire as an offset within the current encapsulating structure. This is not part of normal IDL/NDR, but it is a very useful extension as it avoids the manual encoding of many complex structures.


*subcontext(length)
The [noprint] property is a pidl extension that allows you to specify
:Specifies that a size of I<length> bytes should be read, followed by a blob of that size, which will be parsed as NDR.
that pidl should not generate a ndr_print_*() function for that
:subcontext() is deprecated now, and should not be used in new code. Instead, use represent_as() or transmit_as().
structure or union. This is used when you wish to define your own
print function that prints a structure in a nicer manner. A good
example is the use of [noprint] on dom_sid, which allows the
pretty-printing of SIDs.


*flag
=item value
:Specify boolean options, mostly used for low-level NDR options. Several options can be specified using the | character.
:Note that flags are inherited by substructures!


*nodiscriminant
The [value(expression)] property is a pidl extension that allows you
to specify the value of a field when it is put on the wire. This
:The [nodiscriminant] property on a union means that the usual uint16 discriminent field at the start of the union on the wire is
omitted. This is not normally allowed in IDL/NDR, but is used for some spoolss structures.
allows fields that always have a well-known value to be automatically
filled in, thus making the API more programmer friendly. The
expression can be any C expression.


=item relative
*item charset(name)
:Specify that the array or string uses the specified charset. If this attribute is specified, pidl will take care of converting the character data from this format to the host format. Commonly used values are UCS2, DOS and UTF8.


==Unsupported MIDL properties or statements==
The [relative] property can be supplied on a pointer. When it is used
it declares the pointer as a spoolss style "relative" pointer, which
means it appears on the wire as an offset within the current
encapsulating structure. This is not part of normal IDL/NDR, but it is
a very useful extension as it avoids the manual encoding of many
complex structures.

=item subcontext(length)

Specifies that a size of I<length>
bytes should be read, followed by a blob of that size,
which will be parsed as NDR.

subcontext() is deprecated now, and should not be used in new code.
Instead, use represent_as() or transmit_as().

=item flag

Specify boolean options, mostly used for
low-level NDR options. Several options
can be specified using the | character.
Note that flags are inherited by substructures!

=item nodiscriminant

The [nodiscriminant] property on a union means that the usual uint16
discriminent field at the start of the union on the wire is
omitted. This is not normally allowed in IDL/NDR, but is used for some
spoolss structures.

=item charset(name)

Specify that the array or string uses the specified
charset. If this attribute is specified, pidl will
take care of converting the character data from this format
to the host format. Commonly used values are UCS2, DOS and UTF8.

=back

=head2 Unsupported MIDL properties or statements


aggregatable, appobject, async_uuid, bindable, control,
aggregatable, appobject, async_uuid, bindable, control,
Line 251: Line 180:
usesgetlasterror, vararg, vi_progid, wire_marshal.
usesgetlasterror, vararg, vi_progid, wire_marshal.


=head1 EXAMPLES
=EXAMPLES=

# Generating an Wireshark parser
$ ./pidl --ws-parser -- atsvc.idl

# Generating a TDR parser and header
$ ./pidl --tdr-parser --header -- regf.idl

# Generating a Samba3 client and server
$ ./pidl --samba3-ndr-client --samba3-ndr-server -- dfs.idl


# Generating a Samba4 NDR parser, client and server
# Generating an Wireshark parser
$ ./pidl --ndr-parser --ndr-client --ndr-server -- samr.idl
$ ./pidl --ws-parser -- atsvc.idl
# Generating a TDR parser and header
$ ./pidl --tdr-parser --header -- regf.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


=head1 SEE ALSO
=SEE ALSO=


L<http://msdn.microsoft.com/library/en-us/rpc/rpc/field_attributes.asp>,
*http://msdn.microsoft.com/library/en-us/rpc/rpc/field_attributes.asp,
L<http://wiki.wireshark.org/DCE/RPC>,
*http://wiki.wireshark.org/DCE/RPC,
L<http://www.samba.org/>,
*http://www.samba.org/,
L<yapp(1)>
*yapp(1)

Revision as of 19:25, 21 December 2015

Pidl is a IDL compiler written in Perl, intended for use with DCE/RPC style IDL files. Pidl is currently used to generate client and server code for Samba 3 and Samba 4 and dissectors for Wireshark.

TO CLEANUP:

Pidl works by building a parse tree from a .pidl file (a simple dump of it's internal parse tree) or a .idl file (a file format mostly like the IDL file format midl uses). The IDL file parser is in idl.yp (a yacc file converted to perl code by yapp)

pidl is an IDL compiler written in Perl that aims to be somewhat compatible with the midl compiler. IDL is short for "Interface Definition Language".

pidl can generate stubs for DCE/RPC server code, DCE/RPC client code and Wireshark dissectors for DCE/RPC traffic.

IDL compilers like pidl take a description of an interface as their input and use it to generate C (though support for other languages may be added later) code that can use these interfaces, pretty print data sent using these interfaces, or even generate Wireshark dissectors that can parse data sent over the wire by these interfaces.

pidl takes IDL files in the same format as is used by midl, converts it to a .pidl file (which contains pidl's internal representation of the interface) and can then generate whatever output you need. .pidl files should be used for debugging purposes only. Write your interface definitions in .idl format.

The goal of pidl is to implement a IDL compiler that can be used while developing the RPC subsystem in Samba (for both marshalling/unmarshalling and debugging purposes).

IDL SYNTAX

IDL files are always preprocessed using the C preprocessor.

Pretty much everything in an interface (the interface itself, functions, parameters) can have attributes (or properties whatever name you give them). Attributes always prepend the element they apply to and are surrounded by square brackets ([]). Multiple attributes are separated by comma's; arguments to attributes are specified between parentheses.

See the section COMPATIBILITY for the list of attributes that pidl supports.

C-style comments can be used.

CONFORMANT ARRAYS

A conformant array is one with that ends in [*] or []. The strange things about conformant arrays are that they can only appear as the last element of a structure (unless there is a pointer to the conformant array, of course) and the array size appears before the structure itself on the wire.

So, in this example:

typedef struct {
long abc;
long count;
long foo;
[size_is(count)] long s[*];
} Struct1;

it appears like this:

[size_is] [abc] [count] [foo] [s...]

the first [size_is] field is the allocation size of the array, and occurs before the array elements and even before the structure alignment.

Note that size_is() can refer to a constant, but that doesn't change the wire representation. It does not make the array a fixed array.

midl.exe would write the above array as the following C header:

typedef struct {
  long abc;
  long count;
  long foo;
  long s[1];
 } Struct1;

pidl takes a different approach, and writes it like this:

typedef struct {
 long abc;
 long count;
 long foo;
 long *s;
} Struct1;

VARYING ARRAYS

A varying array looks like this:

typedef struct {
long abc;
long count;
long foo;
[size_is(count)] long *s;
} Struct1;

This will look like this on the wire:

[abc] [count] [foo] [PTR_s] [count] [s...]

FIXED ARRAYS

A fixed array looks like this:

   typedef struct {

long s[10];

   } Struct1;

The NDR representation looks just like 10 separate long declarations. The array size is not encoded on the wire.

pidl also supports "inline" arrays, which are not part of the IDL/NDR standard. These are declared like this:

typedef struct {

uint32 foo; uint32 count; uint32 bar; long s[count];

   } Struct1;

This appears like this:

[foo] [count] [bar] [s...]

Fixed arrays are an extension added to support some of the strange embedded structures in security descriptors and spoolss.

This section is by no means complete. See the OpenGroup and MSDN documentation for additional information.

COMPATIBILITY WITH MIDL

Missing features in pidl

The following MIDL features are not (yet) implemented in pidl or are implemented with an incompatible interface:

=over

=item *

Asynchronous communication

=item *

Typelibs (.tlb files)

=item *

Datagram support (ncadg_*)

=back

Supported attributes and statements

in, out, ref, length_is, switch_is, size_is, uuid, case, default, string, unique, ptr, pointer_default, v1_enum, object, helpstring, range, local, call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as, transmit_as, import, include, cpp_quote.

PIDL Specific properties

  • public
The [public] property on a structure or union is a pidl extension that forces the generated pull/push functions to be non-static. This allows you to declare types that can be used between modules. If you don't specify [public] then pull/push functions for other than top-level functions are declared static.
  • noprint
The [noprint] property is a pidl extension that allows you to specify that pidl should not generate a ndr_print_*() function for that structure or union. This is used when you wish to define your own print function that prints a structure in a nicer manner. A good example is the use of [noprint] on dom_sid, which allows the pretty-printing of SIDs.
  • value
The [value(expression)] property is a pidl extension that allows you to specify the value of a field when it is put on the wire. This

allows fields that always have a well-known value to be automatically filled in, thus making the API more programmer friendly. The expression can be any C expression.

  • relative
The [relative] property can be supplied on a pointer. When it is used it declares the pointer as a spoolss style "relative" pointer, which means it appears on the wire as an offset within the current encapsulating structure. This is not part of normal IDL/NDR, but it is a very useful extension as it avoids the manual encoding of many complex structures.
  • subcontext(length)
Specifies that a size of I<length> bytes should be read, followed by a blob of that size, which will be parsed as NDR.
subcontext() is deprecated now, and should not be used in new code. Instead, use represent_as() or transmit_as().
  • flag
Specify boolean options, mostly used for low-level NDR options. Several options can be specified using the | character.
Note that flags are inherited by substructures!
  • nodiscriminant
The [nodiscriminant] property on a union means that the usual uint16 discriminent field at the start of the union on the wire is

omitted. This is not normally allowed in IDL/NDR, but is used for some spoolss structures.

  • item charset(name)
Specify that the array or string uses the specified charset. If this attribute is specified, pidl will take care of converting the character data from this format to the host format. Commonly used values are UCS2, DOS and UTF8.

Unsupported MIDL properties or statements

aggregatable, appobject, async_uuid, bindable, control, defaultbind, defaultcollelem, defaultvalue, defaultvtable, dispinterface, displaybind, dual, entry, first_is, helpcontext, helpfile, helpstringcontext, helpstringdll, hidden, idl_module, idl_quote, id, immediatebind, importlib, includelib, last_is, lcid, licensed, max_is, module, ms_union, no_injected_text, nonbrowsable, noncreatable, nonextensible, odl, oleautomation, optional, pragma, propget, propputref, propput, readonly, requestedit, restricted, retval, source, uidefault, usesgetlasterror, vararg, vi_progid, wire_marshal.

EXAMPLES

# Generating an Wireshark parser
$ ./pidl --ws-parser -- atsvc.idl

# Generating a TDR parser and header
$ ./pidl --tdr-parser --header -- regf.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

SEE ALSO