4 .\" The contents of this file are subject to the terms of the
5 .\" Common Development and Distribution License (the "License").
6 .\" You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 .\" or http://www.opensolaris.org/os/licensing.
10 .\" See the License for the specific language governing permissions
11 .\" and limitations under the License.
13 .\" When distributing Covered Code, include this CDDL HEADER in each
14 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 .\" If applicable, add the following below this CDDL HEADER, with the
16 .\" fields enclosed by brackets "[]" replaced with your own identifying
17 .\" information: Portions Copyright [yyyy] [name of copyright owner]
21 .\" Copyright 2007 Sun Microsystems, Inc. All rights reserved.
22 .\" Use is subject to license terms.
25 .TH NDRGEN 1ONBLD "Oct 22, 2007"
27 ndrgen \- NDL RPC protocol compiler
31 \fBndrgen\fR [ -Y \fIcpp-path\fR ] \fIfile\fR [ \fIfile\fR ] \&.\|.\|.
36 The \fBndrgen\fR utility is a tool that generates C code to implement a DCERPC/MSRPC Network Data Representation (NDR) protocol. The input to \fBndrgen\fR is a language similar to C known as Network Data Language (NDL).
39 The \fBndrgen\fR utility takes an input protocol definition file and generates an output C source file that contains the marshalling routines to implement the RPC protocol. If the input file is named \fBproto.ndl\fR, \fBndrgen\fR generates NDR routines in \fBproto_ndr.c\fR. Applications must define the service definition and server-side stub table for use with the RPC protocol.
42 The following is an example stub table and service definition:
46 static stub_table_t net_svc_stub_table[] = {
47 { svc_close, SVC_CLOSE },
48 { svc_open, SVC_OPEN },
49 { svc_read, SVC_READ },
50 { svc_write, SVC_WRITE },
54 static service_t net_svc = {
56 "Network Service", /* description */
57 "\e\enetsvc", /* endpoint */
58 "\e\epipe\e\enetsvc", /* secondary address port */
59 "12345678-1234-abcd-ef0001234567abcd", 1, /* abstract syntax */
60 "8a885d04-1ceb-11c9-9fe808002b104860", 2, /* transfer syntax */
61 0, /* bind_instance_size */
63 0, /* unbind_and_close() */
65 &TYPEINFO(svc_interface), /* interface ti */
66 net_svc_stub_table /* stub_table */
73 The C preprocessor, which can be specified in the \fBCC\fR environment variable or on the command line, is run on the input file before it is interpreted by \fBndrgen\fR. The \fBNDRGEN\fR preprocessor symbol is defined by \fBndrgen\fR for use by the \fBndrgen\fR programmer.
76 The NDR generated by \fBndrgen\fR is an MSRPC compatible implementation of OSF DCE NDR. This implementation is based on the X/Open DCE: Remote Procedure Call specification (CAE Specification (1997), DCE 1.1: Remote Procedure Call Document Number: C706), enhanced for compatibility with MSRPC Unicode (UCS-2) strings.
79 The following table shows the DCE RPC layering compared against ONC RPC.
83 DCE RPC Layers ONC RPC Layers Remark
84 +---------------+ +---------------+ +----------------+
85 +---------------+ +---------------+
86 | Application | | Application | The application
87 +---------------+ +---------------+
88 | Hand coded | | RPCGEN gen'd |
89 | client/server | | client/server | Generated stubs
90 | proto.ndl | | *_svc.c *_clnt|
92 +---------------+ +---------------+
94 | RPC Library | | RPC Library | Calls/Return
95 +---------------+ +---------------+
96 | RPC Protocol | | RPC Protocol | Headers
97 | rpcpdu.ndl | | | Authentication
98 +---------------+ +---------------+
99 | NDRGEN gen'd | | RPCGEN gen'd | Aggregation
100 | NDR stubs | | XDR stubs | Composition
101 | *__ndr.c | | *_xdr.c |
102 +---------------+ +---------------+
103 | NDR | | XDR | Byte order, padding
104 +---------------+ +---------------+
105 | | | Network Conn | Large difference:
106 | Heap | | clnt_tcp | see below.
107 | Management | | clnt_udp |
108 +---------------+ +---------------+
114 There are two major differences between the DCE RPC and ONC RPC:
118 DCE RPC only generates or processes packets from buffers. Other layers must take care of packet transmission and reception. The packet heaps are managed through a simple interface provided by NDR streams.
120 ONC RPC communicates directly with the network. The programmer must do specific setup for the RPC packet to be placed in a buffer rather than sent to the wire.
125 DCE RPC uses application provided heaps to support operations. A heap is a managed chunk of memory that NDR manages as it allocates. When the operation and its result are complete, the heap is disposed of as a single item. Transactions, which are the anchor of most operations, perform heap bookkeeping.
127 ONC RPC uses \fBmalloc()\fR liberally throughout its run-time system. To free results, ONC RPC supports an \fBXDR_FREE\fR operation that traverses data structures freeing memory as it goes.
131 The following terminology is used in the subsequent discussion of NDR.
139 The size of an array in elements, such as the amount to \fBmalloc()\fR.
149 The number of significant elements of an array.
159 Size or Length is known at build time.
169 Size or Length is determined at run time.
179 The Size and Length are Known, such as a string constant:
183 char array[] = "A constant Size/Length";
191 The following DCE RPC terminology is used in the subsequent discussion.
199 The Size is Determined. The Length is the same as Size.
211 The Size is Known. The Length is Determined, such as a \fBstrcpy()\fR of a variable length string into a fixed length buffer:
216 strcpy(array, "very short string");
225 \fBVarying and Conformant\fR
229 The Size is Determined. The Length is separately Determined, such as:
233 char *array = malloc(size);
234 strcpy(array, "short string");
242 DCE RPC strings are represented as varying or varying and conformant one-dimensional arrays. Characters can be single-byte or multi-byte as long as all characters conform to a fixed element size. For instance, UCS-2 is valid, but UTF-8 is not a valid DCE RPC string format. The string is terminated by a null character of the appropriate element size.
245 MSRPC strings are always varying and conformant format and not null terminated. This format uses the \fIsize_is\fR, \fIfirst_is\fR, and \fIlength_is\fR attributes:
249 typedef struct string {
253 wchar_t string[ANY_SIZE_ARRAY];
260 The \fIsize_is\fR attribute is used to specify the number of data elements in each dimension of an array.
263 The \fIfirst_is\fR attribute is used to define the lower bound for significant elements in each dimension of an array. For strings, this value is always zero.
266 The \fIlength_is\fR attribute is used to define the number of significant elements in each dimension of an array. For strings, this value is typically the same as \fIsize_is\fR, although it might be (\fIsize_is\fR - 1) if the string is null terminated.
269 MSRPC Unicode strings are not null terminated, which means that the recipient must manually null-terminate the string after it has been received. Note that there is often a wide-char pad following a string, which might contain zero but this situation is not guaranteed.
273 4 bytes 4 bytes 4 bytes 2bytes 2bytes 2bytes 2bytes
274 +---------+---------+---------+------+------+------+------+
275 |size_is |first_is |length_is| char | char | char | char |
276 +---------+---------+---------+------+------+------+------+
282 Despite the general rule, some MSRPC services use null-terminated Unicode strings. To compensate, MSRPC uses the following additional string wrapper with two additional fields. Note that LPTSTR is automatically converted to \fBstring_t\fR by the NDR library.
286 typedef struct msrpc_string {
296 Here, \fIlength\fR is the array length in bytes excluding any terminating null bytes and \fImaxlen\fR is the array length in bytes including the terminating null bytes.
299 The \fBndrgen\fR input must be a valid C header file. Thus, NDL is defined by using macros to map to DCE RPC IDL. The following shows the mappings:
303 NDRGEN NDL DCE RPC IDL
304 ================================
305 OPERATION(X) [operation(X)]
310 SIZE_IS(X) [size_is(X)]
311 SWITCH(X) [switch_is(X)]
314 INTERFACE(X) [interface(X)]
316 ARG_IS(X) [arg_is(X)]
317 REFERENCE [reference]
319 IMPORT_EXTERN [extern]
325 The following shows the C data type associated with the NDRGEN NDL:
329 NDRGEN NDL C Data Type
330 ==============================
335 LPBYTE unsigned char *
336 LPWORD unsigned short *
337 LPDWORD unsigned long *
343 The \fBsmbutil\fR command supports the following global option:
350 Specifies the path to the \fBcpp\fR program.
355 The following is an example NDL header file:
362 #include "ndrtypes.ndl"
365 * Opnums: note that ndrgen does not automatically number
366 * operations and the values do not have to be sequential.
368 #define SVC_CLOSE 0x00
369 #define SVC_OPEN 0x01
370 #define SVC_READ 0x02
371 #define SVC_WRITE 0x03
374 * Define a file handle - choice of UUID format is
375 * arbitrary. Note that typedef's cannot be declared
376 * with the struct definition.
384 typedef struct svc_uuid svc_handle_t;
389 SIZE_IS(nbytes) BYTE *data;
391 typedef struct xferbuf xferbuf_t;
394 * Define the RPC operations.
398 IN svc_handle_t handle;
404 IN LPTSTR servername;
406 OUT svc_handle_t handle;
412 IN svc_handle_t handle;
421 IN svc_handle_t handle;
428 * Define the interface.
431 union svc_interface {
433 struct svc_close net_close;
435 struct svc_open net_open;
437 struct svc_read net_read;
439 struct svc_write net_write;
441 typedef union svc_interface svc_interface_t;
442 EXTERNTYPEINFO(svc_interface)
444 #endif /* _SVC_NDL_ */
450 The following exit values are returned:
457 Successful operation.
470 See the \fBattributes\fR(5) man page for descriptions of the following attributes:
478 ATTRIBUTE TYPE ATTRIBUTE VALUE
480 Availability SUNWbtool
485 \fBcpp\fR(1), \fBrpcgen\fR(1), \fBcc\fR(1B), \fBattributes\fR(5)
488 Some \fBcpp\fR(1) macros used by \fBndrgen\fR are not understood by \fB/usr/bin/cpp\fR or \fB/usr/sfw/bin/cpp\fR. Simple NDL files generally do not pose a problem. If problems occur, for example, when using unions, use \fB/usr/libexec/cpp\fR or \fBcw\fR.