xref: /illumos-gate/usr/src/lib/libmlrpc/common/ndr.h (revision ce8560ee)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Copyright 2020 Tintri by DDN, Inc. All rights reserved.
26  */
27 
28 #ifndef _SMBSRV_NDR_H
29 #define	_SMBSRV_NDR_H
30 
31 /*
32  * Network Data Representation (NDR) is a compatible subset of DCE RPC
33  * and MSRPC NDR.  NDR is used to move parameters consisting of
34  * complicated trees of data constructs between an RPC client and server.
35  *
36  * CAE Specification (1997)
37  * DCE 1.1: Remote Procedure Call
38  * Document Number: C706
39  * The Open Group
40  * ogspecs@opengroup.org
41  */
42 
43 #include <sys/types.h>
44 #include <sys/uio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 
48 #include <smb/wintypes.h>
49 #include <libmlrpc/ndrtypes.ndl>
50 #include <libmlrpc/rpcpdu.ndl>
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /*
57  * Normal sequence:
58  *	- Application calls client-side stub w/ TOP-MOST arg structure
59  *	- client stub performs NDR_M_OP_MARSHALL+NDR_DIR_IN
60  *	- PDU conveyed (request, aka call, aka query)
61  *	- server stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_IN
62  *	- server function called w/ TOP-MOST arg structure
63  *	- server function returns w/ TOP-MOST arg structure modified
64  *	- server stub performs NDR_M_OP_MARSHALL+NDR_DIR_OUT
65  *	- PDU conveyed (reply, aka result, aka response)
66  *	- client stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_OUT
67  *	- return to Application w/ TOP-MOST arg structure modified
68  *
69  * An interface is a sequence of top-most constructs.  Each top-most
70  * construct corresponds to one parameter, either argument or return
71  * value.
72  *
73  * A top-most construct is a sequence of outer constructs.  The first
74  * outer construct is the referent of the argument, and the subsequent
75  * outer constructs are descendents referenced by pointers from prior
76  * constructs.
77  *
78  * An outer construct is a sequence of variable-sized info, fixed-sized
79  * data, and variable-sized data.
80  */
81 
82 /*
83  * Terminology
84  *
85  * The ALL UPPER CASE terms recur in the DCE/RPC documentation.
86  * The mixed-case names have been introduced as a reading aid.
87  *
88  * Size		The size of an array in elements. Think of this
89  *		as the amount to malloc().
90  *
91  * Length	The number of elements of an array which are significant
92  *		Think of this as the amount to bcopy().
93  *
94  * Known	Size/length is known at build time.
95  *
96  * Determined	Size/length is determined at run time.
97  *
98  * FIXED	The Size and Length are Known.
99  *		Think of this as a string constant or a DOS 8.3 file name.
100  *		char array[] = "A Constant Size/Length";
101  *
102  * CONFORMANT	The Size is Determined. Length is the same as Size.
103  *		Think of this as strdup().
104  *		char *array = strdup("Something");
105  *
106  * VARYING	The Size is Known. The Length is determined.
107  *		Think of this as a strcpy() of a variable length string
108  *		into a fixed length buffer:
109  *		char array[100];
110  *		strcpy(array, "very short string");
111  *
112  * VARYING/CONFORMANT
113  *		The Size is Determined. The Length is separately Determined.
114  *		Think of this like:
115  *		char *array = malloc(size);
116  *		strcpy(array, "short string");
117  *
118  * STRING	Strings can be CONFORMANT, VARYING, or CONFORMANT/VARYING.
119  *		A string is fundamentally an array with the last
120  *		significant element some sort of NULL.
121  */
122 
123 #define	NDR_F_NONE		0x0000	/* no flags */
124 #define	NDR_F_PARAMS_MASK	0x00FF
125 #define	NDR_F_SIZE_IS		0x0001	/* [size_is(X)] required/given */
126 #define	NDR_F_LENGTH_IS		0x0002	/* not implemented */
127 #define	NDR_F_SWITCH_IS		0x0004	/* [switch_is(X)] req./given */
128 #define	NDR_F_IS_STRING		0x0008	/* [string] req./given */
129 #define	NDR_F_IS_POINTER	0x0010	/* TYPE * ... req./given */
130 #define	NDR_F_IS_REFERENCE	0x0020	/* TYPE & ... req./given */
131 #define	NDR_F_DIMENSION_IS	0x0040	/* TYPE [N] req./given */
132 
133 #define	NDR_F_WHENCE_MASK	0x00F0
134 #define	NDR_F_BACKPTR		0x0010	/* ref cause by pointer */
135 #define	NDR_F_OUTER		0x0020	/* ref caused by outer */
136 #define	NDR_F_TOPMOST		0x0040	/* ref caused by topmost */
137 
138 #define	NDR_F_TYPEOP_MASK	0x0F00
139 #define	NDR_F_ARRAY		0x0100	/* type is array of somethings */
140 #define	NDR_F_POINTER		0x0200	/* type is pointer to something(s) */
141 #define	NDR_F_STRING		0x0300	/* type is string of somethings */
142 #define	NDR_F_UNION		0x0400	/* type is a union */
143 #define	NDR_F_STRUCT		0x0500	/* type is a structure */
144 #define	NDR_F_OPERATION		0x0600	/* type is a structure, special */
145 #define	NDR_F_INTERFACE		0x0700	/* type is a union, special */
146 #define	NDR_F_CONFORMANT	0x1000	/* struct conforming (var-size tail) */
147 #define	NDR_F_VARYING		0x2000	/* not implemented */
148 #define	NDR_F_FAKE		0x4000	/* not a real struct */
149 
150 struct ndr_heap;
151 struct ndr_stream;
152 struct ndr_reference;
153 
154 typedef uint16_t ndr_wchar_t;
155 
156 typedef struct ndr_typeinfo {
157 	unsigned char		version;	/* sanity check */
158 	unsigned char		alignment;	/* mask */
159 	unsigned short		type_flags;	/* NDR_F_... */
160 	int			(*ndr_func)(struct ndr_reference *);
161 	unsigned short		pdu_size_fixed_part;
162 	unsigned short		pdu_size_variable_part;
163 	unsigned short		c_size_fixed_part;
164 	unsigned short		c_size_variable_part;
165 } ndr_typeinfo_t;
166 
167 typedef struct ndr_reference {
168 	struct ndr_reference	*next;		/* queue list (outer only) */
169 	struct ndr_reference	*enclosing;	/* e.g. struct for this memb */
170 	struct ndr_stream	*stream;	/* root of NDR */
171 	ndr_typeinfo_t		*ti;		/* type of data referenced */
172 	char			*name;		/* name of this member */
173 	unsigned long		pdu_offset;	/* referent in stub data */
174 	char			*datum;		/* referent in local memory */
175 	char			**backptr;	/* referer to set */
176 	unsigned short		outer_flags;	/* XXX_is() from top level */
177 	unsigned short		inner_flags;	/* XXX_is() in encapsulated */
178 	unsigned short		type_flags;	/* "requires" */
179 	unsigned short		packed_alignment;
180 	unsigned long		size_is;	/* conforming constructs */
181 	unsigned long		strlen_is;	/* strings */
182 	unsigned long		switch_is;	/* union arg selector */
183 	unsigned long		dimension_is;	/* fixed-len array size */
184 	unsigned long		pdu_end_offset;	/* offset for limit of PDU */
185 } ndr_ref_t;
186 
187 /*
188  * For all operations, the ndr_stream, which is the root of NDR processing,
189  * is the primary object.  When available, the appropriate ndr_ref_t
190  * is passed, NULL otherwise.  Functions that return 'int' should return
191  * TRUE (!0) or FALSE (0).  When functions return FALSE, including
192  * ndo_malloc() returning NULL, they should set the stream->error to an
193  * appropriate indicator of what went wrong.
194  *
195  * Functions ndo_get_pdu(), ndo_put_pdu(), and ndo_pad_pdu() must
196  * never grow the PDU data.  A request for out-of-bounds data is an error.
197  * The swap_bytes flag is 1 if NDR knows that the byte-order in the PDU
198  * is different from the local system.  ndo_pad_pdu() advised that the
199  * affected bytes should be zero filled.
200  */
201 typedef struct ndr_stream_ops {
202 	char *(*ndo_malloc)(struct ndr_stream *, unsigned, ndr_ref_t *);
203 	int (*ndo_free)(struct ndr_stream *, char *, ndr_ref_t *);
204 	int (*ndo_grow_pdu)(struct ndr_stream *, unsigned long, ndr_ref_t *);
205 	int (*ndo_pad_pdu)(struct ndr_stream *, unsigned long,
206 	    unsigned long, ndr_ref_t *);
207 	int (*ndo_get_pdu)(struct ndr_stream *, unsigned long,
208 	    unsigned long, char *, int, ndr_ref_t *);
209 	int (*ndo_put_pdu)(struct ndr_stream *, unsigned long,
210 	    unsigned long, char *, int, ndr_ref_t *);
211 	void (*ndo_tattle)(struct ndr_stream *, char *, ndr_ref_t *);
212 	void (*ndo_tattle_error)(struct ndr_stream *, ndr_ref_t *);
213 	int (*ndo_reset)(struct ndr_stream *);
214 	void (*ndo_destruct)(struct ndr_stream *);
215 } ndr_stream_ops_t;
216 
217 #define	NDS_MALLOC(NDS, LEN, REF) \
218 	(*(NDS)->ndo->ndo_malloc)(NDS, LEN, REF)
219 #define	NDS_GROW_PDU(NDS, WANT_END_OFF, REF) \
220 	(*(NDS)->ndo->ndo_grow_pdu)(NDS, WANT_END_OFF, REF)
221 #define	NDS_PAD_PDU(NDS, PDU_OFFSET, N_BYTES, REF) \
222 	(*(NDS)->ndo->ndo_pad_pdu)(NDS, PDU_OFFSET, N_BYTES, REF)
223 #define	NDS_GET_PDU(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF) \
224 	(*(NDS)->ndo->ndo_get_pdu)(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF)
225 #define	NDS_PUT_PDU(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF) \
226 	(*(NDS)->ndo->ndo_put_pdu)(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF)
227 #define	NDS_TATTLE(NDS, WHAT, REF) \
228 	(*(NDS)->ndo->ndo_tattle)(NDS, WHAT, REF)
229 #define	NDS_TATTLE_ERROR(NDS, WHAT, REF) \
230 	(*(NDS)->ndo->ndo_tattle_error)(NDS, REF)
231 #define	NDS_RESET(NDS)		(*(NDS)->ndo->ndo_reset)(NDS)
232 #define	NDS_DESTRUCT(NDS)	(*(NDS)->ndo->ndo_destruct)(NDS)
233 
234 /*
235  * The ndr_stream_t tracks the state for a particular RPC call or response.
236  * A single call/response may be transmitted as multiple fragments, where
237  * each fragment has its own header and sec_trailer. For the layout of
238  * a fragment, see the comment at the top of ndr_marshal.c.
239  *
240  * pdu_base_addr is the buffer in which marshalled/received data is stored.
241  *
242  * pdu_base_offset is pdu_base_addr with a different type.
243  *
244  * pdu_max_size is the size of the buffer in pdu_base_addr.
245  *
246  * pdu_size represents the total amount of data stored in pdu_base_addr.
247  * It is typically less than pdu_max_size, and may contain more than one
248  * fragment (when reconstructing fragmented calls/responses, for example).
249  *
250  * pdu_body_offset points to the offset from pdu_base_addr of the PDU body
251  * of the currently encoded/decoded fragment.
252  *
253  * pdu_body_size is the size of the PDU body in the currently encoded/decoded
254  * fragment.
255  * For what constitutes the PDU Body, see ndr_marshal.c.
256  *
257  * pdu_hdr_size is the size of the header for the currently encoded/decoded
258  * fragment.
259  *
260  * pdu_scan_offset points to the next valid byte in pdu_base_addr
261  * (the next free space for encode, and the next unread byte for decode).
262  */
263 typedef struct ndr_stream {
264 	unsigned long		pdu_size;
265 	unsigned long		pdu_max_size;
266 	unsigned long		pdu_base_offset;
267 	unsigned long		pdu_scan_offset;
268 	unsigned long		pdu_body_offset;
269 	unsigned long		pdu_body_size;
270 	unsigned long		pdu_hdr_size;
271 	unsigned char		*pdu_base_addr;
272 
273 	ndr_stream_ops_t	*ndo;
274 
275 	unsigned char		m_op;
276 	unsigned char		dir;
277 	unsigned char		swap;		/* native/net endian swap */
278 	unsigned char		flags;
279 	short			error;
280 	short			error_ref;
281 
282 	ndr_ref_t *outer_queue_head;
283 	ndr_ref_t **outer_queue_tailp;
284 	ndr_ref_t *outer_current;
285 	struct ndr_heap *heap;
286 } ndr_stream_t;
287 
288 #define	NDR_M_OP_NONE		0x00
289 #define	NDR_M_OP_MARSHALL	0x01	/* data moving from datum to PDU */
290 #define	NDR_M_OP_UNMARSHALL	0x02	/* data moving from PDU to datum */
291 
292 #define	NDR_DIR_NONE		0x00
293 #define	NDR_DIR_IN		0x10	/* data moving from caller to callee */
294 #define	NDR_DIR_OUT		0x20	/* data moving from callee to caller */
295 
296 #define	NDR_MODE_CALL_SEND	(NDR_M_OP_MARSHALL + NDR_DIR_IN)
297 #define	NDR_MODE_CALL_RECV	(NDR_M_OP_UNMARSHALL + NDR_DIR_IN)
298 #define	NDR_MODE_RETURN_SEND	(NDR_M_OP_MARSHALL + NDR_DIR_OUT)
299 #define	NDR_MODE_RETURN_RECV	(NDR_M_OP_UNMARSHALL + NDR_DIR_OUT)
300 #define	NDR_MODE_BUF_ENCODE	NDR_MODE_CALL_SEND
301 #define	NDR_MODE_BUF_DECODE	NDR_MODE_RETURN_RECV
302 
303 #define	NDR_MODE_TO_M_OP(MODE)	((MODE) & 0x0F)
304 #define	NDR_MODE_TO_DIR(MODE)	((MODE) & 0xF0)
305 #define	NDR_M_OP_AND_DIR_TO_MODE(M_OP, DIR)	((M_OP)|(DIR))
306 
307 #define	NDR_MODE_MATCH(NDS, MODE) \
308 	(NDR_M_OP_AND_DIR_TO_MODE((NDS)->m_op, (NDS)->dir) == (MODE))
309 
310 #define	NDR_IS_FIRST_FRAG(F)	((F) & NDR_PFC_FIRST_FRAG)
311 #define	NDR_IS_LAST_FRAG(F)	((F) & NDR_PFC_LAST_FRAG)
312 #define	NDR_IS_SINGLE_FRAG(F)	\
313 	(NDR_IS_FIRST_FRAG((F)) && NDR_IS_LAST_FRAG((F)))
314 
315 #define	NDS_F_NONE		0x00
316 #define	NDS_F_NOTERM		0x01	/* strings are not null terminated */
317 #define	NDS_F_NONULL		0x02	/* strings: no null on size_is */
318 #define	NDS_SETF(S, F)		((S)->flags |= (F))
319 #define	NDS_CLEARF(S, F)	((S)->flags &= ~(F))
320 
321 #define	NDR_ERR_MALLOC_FAILED		-1
322 #define	NDR_ERR_M_OP_INVALID		-2
323 #define	NDR_ERR_UNDERFLOW		-3
324 #define	NDR_ERR_GROW_FAILED		-4	/* overflow */
325 #define	NDR_ERR_PAD_FAILED		-5	/* couldn't possibly happen */
326 #define	NDR_ERR_OUTER_HEADER_BAD	-6
327 #define	NDR_ERR_SWITCH_VALUE_ILLEGAL	-7
328 #define	NDR_ERR_SWITCH_VALUE_INVALID	-8
329 #define	NDR_ERR_SWITCH_VALUE_MISSING	-9
330 #define	NDR_ERR_SIZE_IS_MISMATCH_PDU	-10
331 #define	NDR_ERR_SIZE_IS_MISMATCH_AFTER	-11
332 #define	NDR_ERR_SIZE_IS_UNEXPECTED	-12
333 #define	NDR_ERR_SIZE_IS_DUPLICATED	-13
334 #define	NDR_ERR_OUTER_PARAMS_MISMATCH	-14
335 #define	NDR_ERR_ARRAY_VARLEN_ILLEGAL	-15
336 #define	NDR_ERR_ARRAY_UNION_ILLEGAL	-16
337 #define	NDR_ERR_OUTER_PARAMS_BAD	-17
338 #define	NDR_ERR_OUTER_UNION_ILLEGAL	-18
339 #define	NDR_ERR_TOPMOST_UNION_ILLEGAL	-19
340 #define	NDR_ERR_TOPMOST_VARLEN_ILLEGAL	-20
341 #define	NDR_ERR_INNER_PARAMS_BAD	-21
342 #define	NDR_ERR_UNIMPLEMENTED		-22
343 #define	NDR_ERR_NOT_AN_INTERFACE	-23
344 #define	NDR_ERR_STRLEN			-24
345 #define	NDR_ERR_STRING_SIZING		-25
346 #define	NDR_ERR_BOUNDS_CHECK		-26
347 
348 #define	NDR_SET_ERROR(REF, ERROR)			\
349 	((REF)->stream->error = (ERROR),		\
350 	(REF)->stream->error_ref = __LINE__,		\
351 	NDS_TATTLE_ERROR((REF)->stream, 0, REF))
352 
353 #define	NDR_TATTLE(REF, WHAT) \
354 	(*(REF)->stream->ndo->ndo_tattle)((REF)->stream, WHAT, REF)
355 
356 #define	MEMBER_STR(MEMBER) #MEMBER
357 
358 #define	NDR_DIR_IS_IN  (encl_ref->stream->dir == NDR_DIR_IN)
359 #define	NDR_DIR_IS_OUT (encl_ref->stream->dir == NDR_DIR_OUT)
360 
361 #define	NDR_MEMBER_PTR_WITH_ARG(TYPE, MEMBER, OFFSET, \
362 		ARGFLAGS, ARGMEM, ARGVAL) { \
363 		myref.pdu_offset = encl_ref->pdu_offset + (OFFSET);	\
364 		myref.name = MEMBER_STR(MEMBER);			\
365 		myref.datum = (char *)val->MEMBER;			\
366 		myref.inner_flags = ARGFLAGS;				\
367 		myref.ti = &ndt_##TYPE;					\
368 		myref.ARGMEM = ARGVAL;					\
369 		if (!ndr_inner(&myref))					\
370 			return (0);					\
371 	}
372 
373 #define	NDR_MEMBER_PTR_WITH_DIMENSION(TYPE, MEMBER, OFFSET, SIZE_IS)	\
374 	NDR_MEMBER_PTR_WITH_ARG(TYPE, MEMBER, OFFSET, \
375 		NDR_F_DIMENSION_IS, dimension_is, SIZE_IS)
376 
377 #define	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
378 		ARGFLAGS, ARGMEM, ARGVAL) { \
379 		myref.pdu_offset = encl_ref->pdu_offset + (OFFSET);	\
380 		myref.name = MEMBER_STR(MEMBER);			\
381 		myref.datum = (char *)&val->MEMBER;			\
382 		myref.inner_flags = ARGFLAGS;				\
383 		myref.ti = &ndt_##TYPE;					\
384 		myref.ARGMEM = ARGVAL;					\
385 		if (!ndr_inner(&myref))					\
386 			return (0);					\
387 	}
388 
389 #define	NDR_MEMBER(TYPE, MEMBER, OFFSET) \
390 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
391 		NDR_F_NONE, size_is, 0)
392 
393 #define	NDR_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
394 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
395 		NDR_F_SIZE_IS, size_is, SIZE_IS)
396 
397 #define	NDR_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, OFFSET, SIZE_IS) \
398 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
399 		NDR_F_DIMENSION_IS, dimension_is, SIZE_IS)
400 
401 #define	NDR_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
402 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
403 		NDR_F_SIZE_IS+NDR_F_IS_POINTER, size_is, SIZE_IS)
404 
405 #define	NDR_MEMBER_PTR(TYPE, MEMBER, OFFSET)		\
406 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET,	\
407 		NDR_F_IS_POINTER, size_is, 0)
408 
409 #define	NDR_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, OFFSET, SWITCH_IS)	\
410 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET,			\
411 		NDR_F_SWITCH_IS, switch_is, SWITCH_IS)
412 
413 
414 #define	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
415 		ARGFLAGS, ARGMEM, ARGVAL) { \
416 		myref.pdu_offset = -1;					\
417 		myref.name = MEMBER_STR(MEMBER);			\
418 		myref.datum = (char *)&val->MEMBER;			\
419 		myref.inner_flags = ARGFLAGS;				\
420 		myref.ti = &ndt_##TYPE;					\
421 		myref.ARGMEM = ARGVAL;					\
422 		if (!ndr_topmost(&myref))				\
423 			return (0);					\
424 	}
425 
426 #define	NDR_TOPMOST_MEMBER(TYPE, MEMBER)				\
427 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
428 		NDR_F_NONE, size_is, 0)
429 
430 #define	NDR_TOPMOST_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS)	\
431 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
432 		NDR_F_SIZE_IS, size_is, SIZE_IS)
433 
434 #define	NDR_TOPMOST_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, SIZE_IS)	\
435 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
436 		NDR_F_DIMENSION_IS, dimension_is, SIZE_IS)
437 
438 #define	NDR_TOPMOST_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS)	\
439 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
440 		NDR_F_SIZE_IS+NDR_F_IS_POINTER, size_is, SIZE_IS)
441 
442 #define	NDR_TOPMOST_MEMBER_PTR(TYPE, MEMBER)		\
443 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,	\
444 		NDR_F_IS_POINTER, size_is, 0)
445 
446 #define	NDR_TOPMOST_MEMBER_REF(TYPE, MEMBER)		\
447 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,	\
448 		NDR_F_IS_REFERENCE, size_is, 0)
449 
450 #define	NDR_TOPMOST_MEMBER_REF_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS)	\
451 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
452 		NDR_F_SIZE_IS+NDR_F_IS_REFERENCE, size_is, SIZE_IS)
453 
454 #define	NDR_TOPMOST_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, SWITCH_IS)	\
455 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
456 		NDR_F_SWITCH_IS, switch_is, SWITCH_IS)
457 
458 /* this is assuming offset+0 */
459 #define	NDR_PARAMS_MEMBER_WITH_ARG(TYPE, MEMBER, ARGFLAGS, \
460 	ARGMEM, ARGVAL) { \
461 		myref.pdu_offset = encl_ref->pdu_offset;		\
462 		myref.name = MEMBER_STR(MEMBER);			\
463 		myref.datum = (char *)&val->MEMBER;			\
464 		myref.inner_flags = ARGFLAGS;				\
465 		myref.ti = &ndt_##TYPE;					\
466 		myref.ARGMEM = ARGVAL;					\
467 		if (!ndr_params(&myref))				\
468 			return (0);					\
469 	}
470 
471 #define	NDR_PARAMS_MEMBER(TYPE, MEMBER)			\
472 	NDR_PARAMS_MEMBER_WITH_ARG(TYPE, MEMBER,	\
473 	NDR_F_NONE, size_is, 0)
474 
475 #define	NDR_STRING_DIM		1
476 #define	NDR_ANYSIZE_DIM		1
477 
478 int ndo_process(struct ndr_stream *, ndr_typeinfo_t *, char *);
479 int ndo_operation(struct ndr_stream *, ndr_typeinfo_t *, int opnum, char *);
480 void ndo_printf(struct ndr_stream *, ndr_ref_t *, const char *, ...);
481 void ndo_trace(const char *);
482 void ndo_fmt(struct ndr_stream *, ndr_ref_t *, char *);
483 
484 int ndr_params(ndr_ref_t *);
485 int ndr_topmost(ndr_ref_t *);
486 int ndr_run_outer_queue(struct ndr_stream *);
487 int ndr_outer(ndr_ref_t *);
488 int ndr_outer_fixed(ndr_ref_t *);
489 int ndr_outer_fixed_array(ndr_ref_t *);
490 int ndr_outer_conformant_array(ndr_ref_t *);
491 int ndr_outer_conformant_construct(ndr_ref_t *);
492 int ndr_size_is(ndr_ref_t *);
493 int ndr_outer_string(ndr_ref_t *);
494 int ndr_outer_peek_sizing(ndr_ref_t *, unsigned, unsigned long *);
495 int ndr_outer_poke_sizing(ndr_ref_t *, unsigned, unsigned long *);
496 int ndr_outer_align(ndr_ref_t *);
497 int ndr_outer_grow(ndr_ref_t *, unsigned);
498 int ndr_inner(ndr_ref_t *);
499 int ndr_inner_pointer(ndr_ref_t *);
500 int ndr_inner_reference(ndr_ref_t *);
501 int ndr_inner_array(ndr_ref_t *);
502 
503 size_t ndr_mbstowcs(struct ndr_stream *, ndr_wchar_t *, const char *, size_t);
504 
505 void nds_bswap(void *src, void *dst, size_t len);
506 
507 #ifdef __cplusplus
508 }
509 #endif
510 
511 #endif /* _SMBSRV_NDR_H */
512