xref: /onnv-gate/usr/src/uts/common/smbsrv/ndr.h (revision 5331:3047ad28a67b)
1*5331Samw /*
2*5331Samw  * CDDL HEADER START
3*5331Samw  *
4*5331Samw  * The contents of this file are subject to the terms of the
5*5331Samw  * Common Development and Distribution License (the "License").
6*5331Samw  * You may not use this file except in compliance with the License.
7*5331Samw  *
8*5331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5331Samw  * or http://www.opensolaris.org/os/licensing.
10*5331Samw  * See the License for the specific language governing permissions
11*5331Samw  * and limitations under the License.
12*5331Samw  *
13*5331Samw  * When distributing Covered Code, include this CDDL HEADER in each
14*5331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5331Samw  * If applicable, add the following below this CDDL HEADER, with the
16*5331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
17*5331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5331Samw  *
19*5331Samw  * CDDL HEADER END
20*5331Samw  */
21*5331Samw /*
22*5331Samw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*5331Samw  * Use is subject to license terms.
24*5331Samw  */
25*5331Samw 
26*5331Samw #ifndef _SMBSRV_NDR_H
27*5331Samw #define	_SMBSRV_NDR_H
28*5331Samw 
29*5331Samw #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*5331Samw 
31*5331Samw /*
32*5331Samw  * Network Data Representation (NDR) is a compatible subset of DCE RPC
33*5331Samw  * and MSRPC NDR.  NDR is used to move parameters consisting of
34*5331Samw  * complicated trees of data constructs between an RPC client and server.
35*5331Samw  *
36*5331Samw  * CAE Specification (1997)
37*5331Samw  * DCE 1.1: Remote Procedure Call
38*5331Samw  * Document Number: C706
39*5331Samw  * The Open Group
40*5331Samw  * ogspecs@opengroup.org
41*5331Samw  */
42*5331Samw 
43*5331Samw #ifndef _KERNEL
44*5331Samw #include <syslog.h>
45*5331Samw #include <stdlib.h>
46*5331Samw #include <string.h>
47*5331Samw #endif
48*5331Samw 
49*5331Samw #ifdef __cplusplus
50*5331Samw extern "C" {
51*5331Samw #endif
52*5331Samw 
53*5331Samw /*
54*5331Samw  * Normal sequence:
55*5331Samw  *	- Application calls client-side stub w/ TOP-MOST arg structure
56*5331Samw  *	- client stub performs NDR_M_OP_MARSHALL+NDR_DIR_IN
57*5331Samw  *	- PDU conveyed (request, aka call, aka query)
58*5331Samw  *	- server stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_IN
59*5331Samw  *	- server function called w/ TOP-MOST arg structure
60*5331Samw  *	- server function returns w/ TOP-MOST arg structure modified
61*5331Samw  *	- server stub performs NDR_M_OP_MARSHALL+NDR_DIR_OUT
62*5331Samw  *	- PDU conveyed (reply, aka result, aka response)
63*5331Samw  *	- client stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_OUT
64*5331Samw  *	- return to Application w/ TOP-MOST arg structure modified
65*5331Samw  *
66*5331Samw  * An interface is a sequence of top-most constructs.  Each top-most
67*5331Samw  * construct corresponds to one parameter, either argument or return
68*5331Samw  * value.
69*5331Samw  *
70*5331Samw  * A top-most construct is a sequence of outer constructs.  The first
71*5331Samw  * outer construct is the referent of the argument, and the subsequent
72*5331Samw  * outer constructs are descendents referenced by pointers from prior
73*5331Samw  * constructs.
74*5331Samw  *
75*5331Samw  * An outer construct is a sequence of variable-sized info, fixed-sized
76*5331Samw  * data, and variable-sized data.
77*5331Samw  */
78*5331Samw 
79*5331Samw /*
80*5331Samw  * Terminology
81*5331Samw  *
82*5331Samw  * The ALL UPPER CASE terms recur in the DCE/RPC documentation.
83*5331Samw  * The mixed-case names have been introduced as a reading aid.
84*5331Samw  *
85*5331Samw  * Size		The size of an array in elements. Think of this
86*5331Samw  *		as the amount to malloc().
87*5331Samw  *
88*5331Samw  * Length	The number of elements of an array which are significant
89*5331Samw  *		Think of this as the amount to bcopy().
90*5331Samw  *
91*5331Samw  * Known	Size/length is known at build time.
92*5331Samw  *
93*5331Samw  * Determined	Size/length is determined at run time.
94*5331Samw  *
95*5331Samw  * FIXED	The Size and Length are Known.
96*5331Samw  *		Think of this as a string constant or a DOS 8.3 file name.
97*5331Samw  *		char array[] = "A Constant Size/Length";
98*5331Samw  *
99*5331Samw  * CONFORMANT	The Size is Determined. Length is the same as Size.
100*5331Samw  *		Think of this as strdup().
101*5331Samw  *		char *array = strdup("Something");
102*5331Samw  *
103*5331Samw  * VARYING	The Size is Known. The Length is determined.
104*5331Samw  *		Think of this as a strcpy() of a variable length string
105*5331Samw  *		into a fixed length buffer:
106*5331Samw  *		char array[100];
107*5331Samw  *		strcpy(array, "very short string");
108*5331Samw  *
109*5331Samw  * VARYING/CONFORMANT
110*5331Samw  *		The Size is Determined. The Length is separately Determined.
111*5331Samw  *		Think of this like:
112*5331Samw  *		char *array = malloc(size);
113*5331Samw  *		strcpy(array, "short string");
114*5331Samw  *
115*5331Samw  * STRING	Strings can be CONFORMANT, VARYING, or CONFORMANT/VARYING.
116*5331Samw  *		A string is fundamentally an array with the last
117*5331Samw  *		significant element some sort of NULL.
118*5331Samw  */
119*5331Samw 
120*5331Samw #define	NDR_F_NONE		0x0000	/* no flags */
121*5331Samw #define	NDR_F_PARAMS_MASK	0x00FF
122*5331Samw #define	NDR_F_SIZE_IS		0x0001	/* [size_is(X)] required/given */
123*5331Samw #define	NDR_F_LENGTH_IS		0x0002	/* not implemented */
124*5331Samw #define	NDR_F_SWITCH_IS		0x0004	/* [switch_is(X)] req./given */
125*5331Samw #define	NDR_F_IS_STRING		0x0008	/* [string] req./given */
126*5331Samw #define	NDR_F_IS_POINTER	0x0010	/* TYPE * ... req./given */
127*5331Samw #define	NDR_F_IS_REFERENCE	0x0020	/* TYPE & ... req./given */
128*5331Samw #define	NDR_F_DIMENSION_IS	0x0040	/* TYPE [N] req./given */
129*5331Samw 
130*5331Samw #define	NDR_F_WHENCE_MASK	0x00F0
131*5331Samw #define	NDR_F_BACKPTR		0x0010	/* ref cause by pointer */
132*5331Samw #define	NDR_F_OUTER		0x0020	/* ref caused by outer */
133*5331Samw #define	NDR_F_TOPMOST		0x0040	/* ref caused by topmost */
134*5331Samw 
135*5331Samw #define	NDR_F_TYPEOP_MASK	0x0F00
136*5331Samw #define	NDR_F_ARRAY		0x0100	/* type is array of somethings */
137*5331Samw #define	NDR_F_POINTER		0x0200	/* type is pointer to something(s) */
138*5331Samw #define	NDR_F_STRING		0x0300	/* type is string of somethings */
139*5331Samw #define	NDR_F_UNION		0x0400	/* type is a union */
140*5331Samw #define	NDR_F_STRUCT		0x0500	/* type is a structure */
141*5331Samw #define	NDR_F_OPERATION		0x0600	/* type is a structure, special */
142*5331Samw #define	NDR_F_INTERFACE		0x0700	/* type is a union, special */
143*5331Samw #define	NDR_F_CONFORMANT	0x1000	/* struct conforming (var-size tail) */
144*5331Samw #define	NDR_F_VARYING		0x2000	/* not implemented */
145*5331Samw 
146*5331Samw struct mlrpc_heap;
147*5331Samw struct mlndr_stream;
148*5331Samw struct ndr_reference;
149*5331Samw struct ndr_typeinfo;
150*5331Samw 
151*5331Samw struct ndr_typeinfo {
152*5331Samw 	unsigned char		version;	/* sanity check */
153*5331Samw 	unsigned char		alignment;	/* mask */
154*5331Samw 	unsigned short		type_flags;	/* NDR_F_... */
155*5331Samw 	int			(*ndr_func)(struct ndr_reference *encl_ref);
156*5331Samw 	unsigned short		pdu_size_fixed_part;
157*5331Samw 	unsigned short		pdu_size_variable_part;
158*5331Samw 	unsigned short		c_size_fixed_part;
159*5331Samw 	unsigned short		c_size_variable_part;
160*5331Samw };
161*5331Samw 
162*5331Samw struct ndr_reference {
163*5331Samw 	struct ndr_reference	*next;		/* queue list (outer only) */
164*5331Samw 	struct ndr_reference	*enclosing;	/* e.g. struct for this memb */
165*5331Samw 	struct mlndr_stream	*stream;	/* root of NDR */
166*5331Samw 	struct ndr_typeinfo	*ti;		/* type of data referenced */
167*5331Samw 	char			*name;		/* name of this member */
168*5331Samw 	unsigned long		pdu_offset;	/* referent in stub data */
169*5331Samw 	char			*datum;		/* referent in local memory */
170*5331Samw 	char			**backptr;	/* referer to set */
171*5331Samw 	unsigned short		outer_flags;	/* XXX_is() from top level */
172*5331Samw 	unsigned short		inner_flags;	/* XXX_is() in encapsulated */
173*5331Samw 	unsigned short		type_flags;	/* "requires" */
174*5331Samw 	unsigned short		packed_alignment;
175*5331Samw 	unsigned long		size_is;	/* conforming constructs */
176*5331Samw 	unsigned long		strlen_is;	/* strings */
177*5331Samw 	unsigned long		switch_is;	/* union arg selector */
178*5331Samw 	unsigned long		dimension_is;	/* fixed-len array size */
179*5331Samw 	unsigned long		pdu_end_offset;	/* offset for limit of PDU */
180*5331Samw };
181*5331Samw 
182*5331Samw /*
183*5331Samw  * For all operations, the mlndr_stream, which is the root of NDR processing,
184*5331Samw  * is the primary object.  When available, the appropriate ndr_reference
185*5331Samw  * is passed, NULL otherwise.  Functions that return 'int' should return
186*5331Samw  * TRUE (!0) or FALSE (0).  When functions return FALSE, including
187*5331Samw  * mlndo_malloc() returning NULL, they should set the stream->error to an
188*5331Samw  * appropriate indicator of what went wrong.
189*5331Samw  *
190*5331Samw  * Functions mlndo_get_pdu(), mlndo_put_pdu(), and mlndo_pad_pdu() must
191*5331Samw  * never grow the PDU data.  A request for out-of-bounds data is an error.
192*5331Samw  * The swap_bytes flag is 1 if NDR knows that the byte-order in the PDU
193*5331Samw  * is different from the local system.  mlndo_pad_pdu() advised that the
194*5331Samw  * affected bytes should be zero filled.
195*5331Samw  */
196*5331Samw struct mlndr_stream_ops {
197*5331Samw 	char *(*mlndo_malloc)(struct mlndr_stream *, unsigned,
198*5331Samw 	    struct ndr_reference *);
199*5331Samw 
200*5331Samw 	int (*mlndo_free)(struct mlndr_stream *, char *,
201*5331Samw 	    struct ndr_reference *);
202*5331Samw 
203*5331Samw 	int (*mlndo_grow_pdu)(struct mlndr_stream *, unsigned long,
204*5331Samw 	    struct ndr_reference *);
205*5331Samw 
206*5331Samw 	int (*mlndo_pad_pdu)(struct mlndr_stream *, unsigned long,
207*5331Samw 	    unsigned long, struct ndr_reference *);
208*5331Samw 
209*5331Samw 	int (*mlndo_get_pdu)(struct mlndr_stream *, unsigned long,
210*5331Samw 	    unsigned long, char *, int, struct ndr_reference *);
211*5331Samw 
212*5331Samw 	int (*mlndo_put_pdu)(struct mlndr_stream *, unsigned long,
213*5331Samw 	    unsigned long, char *, int, struct ndr_reference *);
214*5331Samw 
215*5331Samw 	void (*mlndo_tattle)(struct mlndr_stream *, char *,
216*5331Samw 	    struct ndr_reference *);
217*5331Samw 
218*5331Samw 	void (*mlndo_tattle_error)(struct mlndr_stream *,
219*5331Samw 	    struct ndr_reference *);
220*5331Samw 
221*5331Samw 	int (*mlndo_reset)(struct mlndr_stream *);
222*5331Samw 	void (*mlndo_destruct)(struct mlndr_stream *);
223*5331Samw };
224*5331Samw 
225*5331Samw #define	MLNDS_MALLOC(MLNDS, LEN, REF) \
226*5331Samw 	(*(MLNDS)->mlndo->mlndo_malloc)(MLNDS, LEN, REF)
227*5331Samw 
228*5331Samw #define	MLNDS_GROW_PDU(MLNDS, WANT_END_OFF, REF) \
229*5331Samw 	(*(MLNDS)->mlndo->mlndo_grow_pdu)(MLNDS, WANT_END_OFF, REF)
230*5331Samw #define	MLNDS_PAD_PDU(MLNDS, PDU_OFFSET, N_BYTES, REF) \
231*5331Samw 	(*(MLNDS)->mlndo->mlndo_pad_pdu)(MLNDS, PDU_OFFSET, N_BYTES, REF)
232*5331Samw #define	MLNDS_GET_PDU(MLNDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF) \
233*5331Samw 	(*(MLNDS)->mlndo->mlndo_get_pdu)(MLNDS, PDU_OFFSET, N_BYTES, BUF, \
234*5331Samw 	SWAP, REF)
235*5331Samw #define	MLNDS_PUT_PDU(MLNDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF) \
236*5331Samw 	(*(MLNDS)->mlndo->mlndo_put_pdu)(MLNDS, PDU_OFFSET, N_BYTES, BUF, \
237*5331Samw 	SWAP, REF)
238*5331Samw 
239*5331Samw #define	MLNDS_TATTLE(MLNDS, WHAT, REF) \
240*5331Samw 	(*(MLNDS)->mlndo->mlndo_tattle)(MLNDS, WHAT, REF)
241*5331Samw #define	MLNDS_TATTLE_ERROR(MLNDS, WHAT, REF) \
242*5331Samw 	(*(MLNDS)->mlndo->mlndo_tattle_error)(MLNDS, REF)
243*5331Samw #define	MLNDS_RESET(MLNDS) \
244*5331Samw 	(*(MLNDS)->mlndo->mlndo_reset)(MLNDS)
245*5331Samw #define	MLNDS_DESTRUCT(MLNDS) \
246*5331Samw 	(*(MLNDS)->mlndo->mlndo_destruct)(MLNDS)
247*5331Samw 
248*5331Samw struct mlndr_stream {
249*5331Samw 	unsigned long		pdu_size;
250*5331Samw 	unsigned long		pdu_size_with_rpc_hdrs;
251*5331Samw 	unsigned long		pdu_max_size;
252*5331Samw 	unsigned long		pdu_base_offset;
253*5331Samw 	unsigned long		pdu_scan_offset;
254*5331Samw 	unsigned char		*pdu_base_addr;
255*5331Samw 	unsigned char		*pdu_base_addr_with_rpc_hdrs;
256*5331Samw 
257*5331Samw 	struct mlndr_stream_ops *mlndo;
258*5331Samw 
259*5331Samw 	unsigned char		m_op;
260*5331Samw 	unsigned char		dir;
261*5331Samw 	unsigned char		swap;		/* native/net endian swap */
262*5331Samw 	short			error;
263*5331Samw 	short			error_ref;
264*5331Samw 
265*5331Samw 	struct ndr_reference *outer_queue_head;
266*5331Samw 	struct ndr_reference **outer_queue_tailp;
267*5331Samw 	struct ndr_reference *outer_current;
268*5331Samw 	struct mlrpc_heap *heap;
269*5331Samw };
270*5331Samw 
271*5331Samw 
272*5331Samw #define	NDR_M_OP_NONE		0x00
273*5331Samw #define	NDR_M_OP_MARSHALL	0x01	/* data moving from datum to PDU */
274*5331Samw #define	NDR_M_OP_UNMARSHALL	0x02	/* data moving from PDU to datum */
275*5331Samw 
276*5331Samw #define	NDR_DIR_NONE		0x00
277*5331Samw #define	NDR_DIR_IN		0x10	/* data moving from caller to callee */
278*5331Samw #define	NDR_DIR_OUT		0x20	/* data moving from callee to caller */
279*5331Samw 
280*5331Samw #define	NDR_MODE_CALL_SEND	(NDR_M_OP_MARSHALL + NDR_DIR_IN)
281*5331Samw #define	NDR_MODE_CALL_RECV	(NDR_M_OP_UNMARSHALL + NDR_DIR_IN)
282*5331Samw #define	NDR_MODE_RETURN_SEND	(NDR_M_OP_MARSHALL + NDR_DIR_OUT)
283*5331Samw #define	NDR_MODE_RETURN_RECV	(NDR_M_OP_UNMARSHALL + NDR_DIR_OUT)
284*5331Samw 
285*5331Samw #define	NDR_MODE_TO_M_OP(MODE)	((MODE)&0x0F)
286*5331Samw #define	NDR_MODE_TO_DIR(MODE)	((MODE)&0xF0)
287*5331Samw #define	NDR_M_OP_AND_DIR_TO_MODE(M_OP, DIR)	((M_OP)|(DIR))
288*5331Samw 
289*5331Samw #define	NDR_MODE_MATCH(MLNDS, MODE) \
290*5331Samw 	(NDR_M_OP_AND_DIR_TO_MODE((MLNDS)->m_op, (MLNDS)->dir) == (MODE))
291*5331Samw 
292*5331Samw 
293*5331Samw #define	NDR_ERR_MALLOC_FAILED		-1
294*5331Samw #define	NDR_ERR_M_OP_INVALID		-2
295*5331Samw #define	NDR_ERR_UNDERFLOW		-3
296*5331Samw #define	NDR_ERR_GROW_FAILED		-4	/* overflow */
297*5331Samw #define	NDR_ERR_PAD_FAILED		-5	/* couldn't possibly happen */
298*5331Samw #define	NDR_ERR_OUTER_HEADER_BAD	-6
299*5331Samw #define	NDR_ERR_SWITCH_VALUE_ILLEGAL	-7
300*5331Samw #define	NDR_ERR_SWITCH_VALUE_INVALID	-8
301*5331Samw #define	NDR_ERR_SWITCH_VALUE_MISSING	-9
302*5331Samw #define	NDR_ERR_SIZE_IS_MISMATCH_PDU	-10
303*5331Samw #define	NDR_ERR_SIZE_IS_MISMATCH_AFTER	-11
304*5331Samw #define	NDR_ERR_SIZE_IS_UNEXPECTED	-12
305*5331Samw #define	NDR_ERR_SIZE_IS_DUPLICATED	-13
306*5331Samw #define	NDR_ERR_OUTER_PARAMS_MISMATCH	-14
307*5331Samw #define	NDR_ERR_ARRAY_VARLEN_ILLEGAL	-15
308*5331Samw #define	NDR_ERR_ARRAY_UNION_ILLEGAL	-16
309*5331Samw #define	NDR_ERR_OUTER_PARAMS_BAD	-17
310*5331Samw #define	NDR_ERR_OUTER_UNION_ILLEGAL	-18
311*5331Samw #define	NDR_ERR_TOPMOST_UNION_ILLEGAL	-19
312*5331Samw #define	NDR_ERR_TOPMOST_VARLEN_ILLEGAL	-20
313*5331Samw #define	NDR_ERR_INNER_PARAMS_BAD	-21
314*5331Samw #define	NDR_ERR_UNIMPLEMENTED		-22
315*5331Samw #define	NDR_ERR_NOT_AN_INTERFACE	-23
316*5331Samw #define	NDR_ERR_STRLEN			-24
317*5331Samw #define	NDR_ERR_STRING_SIZING		-25
318*5331Samw #define	NDR_ERR_BOUNDS_CHECK		-26
319*5331Samw 
320*5331Samw #define	NDR_SET_ERROR(REF, ERROR)			\
321*5331Samw 	((REF)->stream->error = (ERROR),		\
322*5331Samw 	(REF)->stream->error_ref = __LINE__,		\
323*5331Samw 	MLNDS_TATTLE_ERROR((REF)->stream, 0, REF))
324*5331Samw 
325*5331Samw #define	NDR_TATTLE(REF, WHAT) \
326*5331Samw 	(*(REF)->stream->mlndo->mlndo_tattle)((REF)->stream, WHAT, REF)
327*5331Samw 
328*5331Samw #define	MEMBER_STR(MEMBER) #MEMBER
329*5331Samw 
330*5331Samw #define	NDR_DIR_IS_IN  (encl_ref->stream->dir == NDR_DIR_IN)
331*5331Samw #define	NDR_DIR_IS_OUT (encl_ref->stream->dir == NDR_DIR_OUT)
332*5331Samw 
333*5331Samw #define	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
334*5331Samw 		ARGFLAGS, ARGMEM, ARGVAL) { \
335*5331Samw 		myref.pdu_offset = encl_ref->pdu_offset + (OFFSET);	\
336*5331Samw 		myref.name = MEMBER_STR(MEMBER);			\
337*5331Samw 		myref.datum = (char *)&val->MEMBER;			\
338*5331Samw 		myref.inner_flags = ARGFLAGS;				\
339*5331Samw 		myref.ti = &ndt_##TYPE;					\
340*5331Samw 		myref.ARGMEM = ARGVAL;					\
341*5331Samw 		if (!mlndr_inner(&myref))				\
342*5331Samw 			return (0);					\
343*5331Samw 	}
344*5331Samw 
345*5331Samw #define	NDR_MEMBER(TYPE, MEMBER, OFFSET) \
346*5331Samw 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
347*5331Samw 		NDR_F_NONE, size_is, 0)
348*5331Samw 
349*5331Samw #define	NDR_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
350*5331Samw 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
351*5331Samw 		NDR_F_SIZE_IS, size_is, SIZE_IS)
352*5331Samw 
353*5331Samw #define	NDR_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, OFFSET, SIZE_IS) \
354*5331Samw 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
355*5331Samw 		NDR_F_DIMENSION_IS, dimension_is, SIZE_IS)
356*5331Samw 
357*5331Samw #define	NDR_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
358*5331Samw 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
359*5331Samw 		NDR_F_SIZE_IS+NDR_F_IS_POINTER, size_is, SIZE_IS)
360*5331Samw 
361*5331Samw #define	NDR_MEMBER_PTR(TYPE, MEMBER, OFFSET)		\
362*5331Samw 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET,	\
363*5331Samw 		NDR_F_IS_POINTER, size_is, 0)
364*5331Samw 
365*5331Samw #define	NDR_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, OFFSET, SWITCH_IS)	\
366*5331Samw 	NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET,			\
367*5331Samw 		NDR_F_SWITCH_IS, switch_is, SWITCH_IS)
368*5331Samw 
369*5331Samw 
370*5331Samw #define	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
371*5331Samw 		ARGFLAGS, ARGMEM, ARGVAL) { \
372*5331Samw 		myref.pdu_offset = -1;					\
373*5331Samw 		myref.name = MEMBER_STR(MEMBER);			\
374*5331Samw 		myref.datum = (char *)&val->MEMBER;			\
375*5331Samw 		myref.inner_flags = ARGFLAGS;				\
376*5331Samw 		myref.ti = &ndt_##TYPE;					\
377*5331Samw 		myref.ARGMEM = ARGVAL;					\
378*5331Samw 		if (!mlndr_topmost(&myref))				\
379*5331Samw 			return (0);					\
380*5331Samw 	}
381*5331Samw 
382*5331Samw #define	NDR_TOPMOST_MEMBER(TYPE, MEMBER)	   			\
383*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
384*5331Samw 		NDR_F_NONE, size_is, 0)
385*5331Samw 
386*5331Samw #define	NDR_TOPMOST_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS)	\
387*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,		    	\
388*5331Samw 		NDR_F_SIZE_IS, size_is, SIZE_IS)
389*5331Samw 
390*5331Samw #define	NDR_TOPMOST_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, SIZE_IS)	\
391*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,		      	\
392*5331Samw 		NDR_F_DIMENSION_IS, dimension_is, SIZE_IS)
393*5331Samw 
394*5331Samw #define	NDR_TOPMOST_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS)	\
395*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
396*5331Samw 		NDR_F_SIZE_IS+NDR_F_IS_POINTER, size_is, SIZE_IS)
397*5331Samw 
398*5331Samw #define	NDR_TOPMOST_MEMBER_PTR(TYPE, MEMBER)		\
399*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,	\
400*5331Samw 		NDR_F_IS_POINTER, size_is, 0)
401*5331Samw 
402*5331Samw #define	NDR_TOPMOST_MEMBER_REF(TYPE, MEMBER)		\
403*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,	\
404*5331Samw 		NDR_F_IS_REFERENCE, size_is, 0)
405*5331Samw 
406*5331Samw #define	NDR_TOPMOST_MEMBER_REF_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS)	\
407*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
408*5331Samw 		NDR_F_SIZE_IS+NDR_F_IS_REFERENCE, size_is, SIZE_IS)
409*5331Samw 
410*5331Samw #define	NDR_TOPMOST_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, SWITCH_IS)	\
411*5331Samw 	NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER,			\
412*5331Samw 		NDR_F_SWITCH_IS, switch_is, SWITCH_IS)
413*5331Samw 
414*5331Samw /* this is assuming offset+0 */
415*5331Samw #define	NDR_PARAMS_MEMBER_WITH_ARG(TYPE, MEMBER, ARGFLAGS, \
416*5331Samw 	ARGMEM, ARGVAL) { \
417*5331Samw 		myref.pdu_offset = encl_ref->pdu_offset;		\
418*5331Samw 		myref.name = MEMBER_STR(MEMBER);			\
419*5331Samw 		myref.datum = (char *)&val->MEMBER;			\
420*5331Samw 		myref.inner_flags = ARGFLAGS;				\
421*5331Samw 		myref.ti = &ndt_##TYPE;					\
422*5331Samw 		myref.ARGMEM = ARGVAL;					\
423*5331Samw 		if (!mlndr_params(&myref))				\
424*5331Samw 			return (0);					\
425*5331Samw 	}
426*5331Samw 
427*5331Samw #define	NDR_PARAMS_MEMBER(TYPE, MEMBER)			\
428*5331Samw 	NDR_PARAMS_MEMBER_WITH_ARG(TYPE, MEMBER,	\
429*5331Samw 	NDR_F_NONE, size_is, 0)
430*5331Samw 
431*5331Samw #define	NDR_STRING_DIM		1
432*5331Samw #define	NDR_ANYSIZE_DIM		1
433*5331Samw 
434*5331Samw int mlndo_process(struct mlndr_stream *, struct ndr_typeinfo *, char *);
435*5331Samw int mlndo_operation(struct mlndr_stream *, struct ndr_typeinfo *,
436*5331Samw     int opnum, char *);
437*5331Samw void mlndo_printf(struct mlndr_stream *, struct ndr_reference *,
438*5331Samw     const char *, ...);
439*5331Samw void mlndo_trace(const char *);
440*5331Samw void mlndo_fmt(struct mlndr_stream *, struct ndr_reference *, char *);
441*5331Samw 
442*5331Samw int mlndr_params(struct ndr_reference *);
443*5331Samw int mlndr_topmost(struct ndr_reference *);
444*5331Samw int mlndr_run_outer_queue(struct mlndr_stream *);
445*5331Samw int mlndr_outer(struct ndr_reference *);
446*5331Samw int mlndr_outer_fixed(struct ndr_reference *);
447*5331Samw int mlndr_outer_fixed_array(struct ndr_reference *);
448*5331Samw int mlndr_outer_conformant_array(struct ndr_reference *);
449*5331Samw int mlndr_outer_conformant_construct(struct ndr_reference *);
450*5331Samw int mlndr_size_is(struct ndr_reference *);
451*5331Samw int mlndr_outer_string(struct ndr_reference *);
452*5331Samw int mlndr_outer_peek_sizing(struct ndr_reference *, unsigned,
453*5331Samw     unsigned long *);
454*5331Samw int mlndr_outer_poke_sizing(struct ndr_reference *, unsigned,
455*5331Samw     unsigned long *);
456*5331Samw int mlndr_outer_align(struct ndr_reference *);
457*5331Samw int mlndr_outer_grow(struct ndr_reference *, unsigned);
458*5331Samw int mlndr_inner(struct ndr_reference *);
459*5331Samw int mlndr_inner_pointer(struct ndr_reference *);
460*5331Samw int mlndr_inner_reference(struct ndr_reference *);
461*5331Samw int mlndr_inner_array(struct ndr_reference *);
462*5331Samw void mlnds_bswap(void *src, void *dst, size_t len);
463*5331Samw 
464*5331Samw #ifdef __cplusplus
465*5331Samw }
466*5331Samw #endif
467*5331Samw 
468*5331Samw #endif /* _SMBSRV_NDR_H */
469