da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
b1352070d318187b41b088da3533692976f3f225Alan Wright * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifndef _SMBSRV_NDR_H
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define _SMBSRV_NDR_H
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Network Data Representation (NDR) is a compatible subset of DCE RPC
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and MSRPC NDR. NDR is used to move parameters consisting of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * complicated trees of data constructs between an RPC client and server.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CAE Specification (1997)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * DCE 1.1: Remote Procedure Call
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Document Number: C706
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The Open Group
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ogspecs@opengroup.org
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#error "not used in kernel code"
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#else /* _KERNEL */
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <sys/types.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <sys/uio.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <syslog.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <string.h>
8d7e41661dc4633488e93b13363137523ce59977jose borrego#include <smbsrv/wintypes.h>
8d7e41661dc4633488e93b13363137523ce59977jose borrego#include <smbsrv/ndl/rpcpdu.ndl>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/string.h>
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif /* _KERNEL */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef __cplusplus
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern "C" {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Normal sequence:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - Application calls client-side stub w/ TOP-MOST arg structure
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - client stub performs NDR_M_OP_MARSHALL+NDR_DIR_IN
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - PDU conveyed (request, aka call, aka query)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - server stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_IN
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - server function called w/ TOP-MOST arg structure
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - server function returns w/ TOP-MOST arg structure modified
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - server stub performs NDR_M_OP_MARSHALL+NDR_DIR_OUT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - PDU conveyed (reply, aka result, aka response)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - client stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_OUT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - return to Application w/ TOP-MOST arg structure modified
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * An interface is a sequence of top-most constructs. Each top-most
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * construct corresponds to one parameter, either argument or return
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A top-most construct is a sequence of outer constructs. The first
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * outer construct is the referent of the argument, and the subsequent
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * outer constructs are descendents referenced by pointers from prior
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * constructs.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * An outer construct is a sequence of variable-sized info, fixed-sized
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * data, and variable-sized data.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Terminology
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The ALL UPPER CASE terms recur in the DCE/RPC documentation.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The mixed-case names have been introduced as a reading aid.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Size The size of an array in elements. Think of this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * as the amount to malloc().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Length The number of elements of an array which are significant
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Think of this as the amount to bcopy().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Known Size/length is known at build time.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Determined Size/length is determined at run time.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FIXED The Size and Length are Known.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Think of this as a string constant or a DOS 8.3 file name.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * char array[] = "A Constant Size/Length";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CONFORMANT The Size is Determined. Length is the same as Size.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Think of this as strdup().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * char *array = strdup("Something");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VARYING The Size is Known. The Length is determined.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Think of this as a strcpy() of a variable length string
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * into a fixed length buffer:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * char array[100];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * strcpy(array, "very short string");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VARYING/CONFORMANT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The Size is Determined. The Length is separately Determined.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Think of this like:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * char *array = malloc(size);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * strcpy(array, "short string");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING Strings can be CONFORMANT, VARYING, or CONFORMANT/VARYING.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A string is fundamentally an array with the last
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * significant element some sort of NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_NONE 0x0000 /* no flags */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_PARAMS_MASK 0x00FF
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_SIZE_IS 0x0001 /* [size_is(X)] required/given */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_LENGTH_IS 0x0002 /* not implemented */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_SWITCH_IS 0x0004 /* [switch_is(X)] req./given */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_IS_STRING 0x0008 /* [string] req./given */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_IS_POINTER 0x0010 /* TYPE * ... req./given */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_IS_REFERENCE 0x0020 /* TYPE & ... req./given */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_DIMENSION_IS 0x0040 /* TYPE [N] req./given */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_WHENCE_MASK 0x00F0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_BACKPTR 0x0010 /* ref cause by pointer */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_OUTER 0x0020 /* ref caused by outer */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_TOPMOST 0x0040 /* ref caused by topmost */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_TYPEOP_MASK 0x0F00
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_ARRAY 0x0100 /* type is array of somethings */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_POINTER 0x0200 /* type is pointer to something(s) */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_STRING 0x0300 /* type is string of somethings */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_UNION 0x0400 /* type is a union */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_STRUCT 0x0500 /* type is a structure */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_OPERATION 0x0600 /* type is a structure, special */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_INTERFACE 0x0700 /* type is a union, special */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_CONFORMANT 0x1000 /* struct conforming (var-size tail) */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_VARYING 0x2000 /* not implemented */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borregostruct ndr_heap;
8d7e41661dc4633488e93b13363137523ce59977jose borregostruct ndr_stream;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstruct ndr_reference;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wrighttypedef uint16_t ndr_wchar_t;
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright
8d7e41661dc4633488e93b13363137523ce59977jose borregotypedef struct ndr_typeinfo {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char version; /* sanity check */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char alignment; /* mask */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short type_flags; /* NDR_F_... */
8d7e41661dc4633488e93b13363137523ce59977jose borrego int (*ndr_func)(struct ndr_reference *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short pdu_size_fixed_part;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short pdu_size_variable_part;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short c_size_fixed_part;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short c_size_variable_part;
8d7e41661dc4633488e93b13363137523ce59977jose borrego} ndr_typeinfo_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borregotypedef struct ndr_reference {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct ndr_reference *next; /* queue list (outer only) */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct ndr_reference *enclosing; /* e.g. struct for this memb */
8d7e41661dc4633488e93b13363137523ce59977jose borrego struct ndr_stream *stream; /* root of NDR */
8d7e41661dc4633488e93b13363137523ce59977jose borrego ndr_typeinfo_t *ti; /* type of data referenced */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *name; /* name of this member */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long pdu_offset; /* referent in stub data */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *datum; /* referent in local memory */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char **backptr; /* referer to set */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short outer_flags; /* XXX_is() from top level */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short inner_flags; /* XXX_is() in encapsulated */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short type_flags; /* "requires" */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short packed_alignment;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long size_is; /* conforming constructs */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long strlen_is; /* strings */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long switch_is; /* union arg selector */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long dimension_is; /* fixed-len array size */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long pdu_end_offset; /* offset for limit of PDU */
8d7e41661dc4633488e93b13363137523ce59977jose borrego} ndr_ref_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
8d7e41661dc4633488e93b13363137523ce59977jose borrego * For all operations, the ndr_stream, which is the root of NDR processing,
8d7e41661dc4633488e93b13363137523ce59977jose borrego * is the primary object. When available, the appropriate ndr_ref_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is passed, NULL otherwise. Functions that return 'int' should return
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TRUE (!0) or FALSE (0). When functions return FALSE, including
8d7e41661dc4633488e93b13363137523ce59977jose borrego * ndo_malloc() returning NULL, they should set the stream->error to an
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * appropriate indicator of what went wrong.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Functions ndo_get_pdu(), ndo_put_pdu(), and ndo_pad_pdu() must
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * never grow the PDU data. A request for out-of-bounds data is an error.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The swap_bytes flag is 1 if NDR knows that the byte-order in the PDU
8d7e41661dc4633488e93b13363137523ce59977jose borrego * is different from the local system. ndo_pad_pdu() advised that the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * affected bytes should be zero filled.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
8d7e41661dc4633488e93b13363137523ce59977jose borregotypedef struct ndr_stream_ops {
8d7e41661dc4633488e93b13363137523ce59977jose borrego char *(*ndo_malloc)(struct ndr_stream *, unsigned, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego int (*ndo_free)(struct ndr_stream *, char *, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego int (*ndo_grow_pdu)(struct ndr_stream *, unsigned long, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego int (*ndo_pad_pdu)(struct ndr_stream *, unsigned long,
8d7e41661dc4633488e93b13363137523ce59977jose borrego unsigned long, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego int (*ndo_get_pdu)(struct ndr_stream *, unsigned long,
8d7e41661dc4633488e93b13363137523ce59977jose borrego unsigned long, char *, int, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego int (*ndo_put_pdu)(struct ndr_stream *, unsigned long,
8d7e41661dc4633488e93b13363137523ce59977jose borrego unsigned long, char *, int, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego void (*ndo_tattle)(struct ndr_stream *, char *, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego void (*ndo_tattle_error)(struct ndr_stream *, ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego int (*ndo_reset)(struct ndr_stream *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego void (*ndo_destruct)(struct ndr_stream *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego} ndr_stream_ops_t;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_MALLOC(NDS, LEN, REF) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(NDS)->ndo->ndo_malloc)(NDS, LEN, REF)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_GROW_PDU(NDS, WANT_END_OFF, REF) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(NDS)->ndo->ndo_grow_pdu)(NDS, WANT_END_OFF, REF)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_PAD_PDU(NDS, PDU_OFFSET, N_BYTES, REF) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(NDS)->ndo->ndo_pad_pdu)(NDS, PDU_OFFSET, N_BYTES, REF)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_GET_PDU(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(NDS)->ndo->ndo_get_pdu)(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_PUT_PDU(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(NDS)->ndo->ndo_put_pdu)(NDS, PDU_OFFSET, N_BYTES, BUF, SWAP, REF)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_TATTLE(NDS, WHAT, REF) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(NDS)->ndo->ndo_tattle)(NDS, WHAT, REF)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_TATTLE_ERROR(NDS, WHAT, REF) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(NDS)->ndo->ndo_tattle_error)(NDS, REF)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_RESET(NDS) (*(NDS)->ndo->ndo_reset)(NDS)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_DESTRUCT(NDS) (*(NDS)->ndo->ndo_destruct)(NDS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borregotypedef struct ndr_stream {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long pdu_size;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long pdu_max_size;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long pdu_base_offset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long pdu_scan_offset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *pdu_base_addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego ndr_stream_ops_t *ndo;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char m_op;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char dir;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char swap; /* native/net endian swap */
55bf511df53aad0fdb7eb3fa349f0308cc05234cas unsigned char flags;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw short error;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw short error_ref;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego ndr_ref_t *outer_queue_head;
8d7e41661dc4633488e93b13363137523ce59977jose borrego ndr_ref_t **outer_queue_tailp;
8d7e41661dc4633488e93b13363137523ce59977jose borrego ndr_ref_t *outer_current;
8d7e41661dc4633488e93b13363137523ce59977jose borrego struct ndr_heap *heap;
8d7e41661dc4633488e93b13363137523ce59977jose borrego} ndr_stream_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_M_OP_NONE 0x00
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_M_OP_MARSHALL 0x01 /* data moving from datum to PDU */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_M_OP_UNMARSHALL 0x02 /* data moving from PDU to datum */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_DIR_NONE 0x00
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_DIR_IN 0x10 /* data moving from caller to callee */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_DIR_OUT 0x20 /* data moving from callee to caller */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MODE_CALL_SEND (NDR_M_OP_MARSHALL + NDR_DIR_IN)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MODE_CALL_RECV (NDR_M_OP_UNMARSHALL + NDR_DIR_IN)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MODE_RETURN_SEND (NDR_M_OP_MARSHALL + NDR_DIR_OUT)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MODE_RETURN_RECV (NDR_M_OP_UNMARSHALL + NDR_DIR_OUT)
b1352070d318187b41b088da3533692976f3f225Alan Wright#define NDR_MODE_BUF_ENCODE NDR_MODE_CALL_SEND
b1352070d318187b41b088da3533692976f3f225Alan Wright#define NDR_MODE_BUF_DECODE NDR_MODE_RETURN_RECV
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDR_MODE_TO_M_OP(MODE) ((MODE) & 0x0F)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDR_MODE_TO_DIR(MODE) ((MODE) & 0xF0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_M_OP_AND_DIR_TO_MODE(M_OP, DIR) ((M_OP)|(DIR))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDR_MODE_MATCH(NDS, MODE) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (NDR_M_OP_AND_DIR_TO_MODE((NDS)->m_op, (NDS)->dir) == (MODE))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b1352070d318187b41b088da3533692976f3f225Alan Wright#define NDR_IS_FIRST_FRAG(F) ((F) & NDR_PFC_FIRST_FRAG)
b1352070d318187b41b088da3533692976f3f225Alan Wright#define NDR_IS_LAST_FRAG(F) ((F) & NDR_PFC_LAST_FRAG)
b1352070d318187b41b088da3533692976f3f225Alan Wright#define NDR_IS_SINGLE_FRAG(F) \
b1352070d318187b41b088da3533692976f3f225Alan Wright (NDR_IS_FIRST_FRAG((F)) && NDR_IS_LAST_FRAG((F)))
b1352070d318187b41b088da3533692976f3f225Alan Wright
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_F_NONE 0x00
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_F_NOTERM 0x01 /* strings are not null terminated */
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier#define NDS_F_NONULL 0x02 /* strings: no null on size_is */
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_SETF(S, F) ((S)->flags |= (F))
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_CLEARF(S, F) ((S)->flags &= ~(F))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_MALLOC_FAILED -1
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_M_OP_INVALID -2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_UNDERFLOW -3
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_GROW_FAILED -4 /* overflow */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_PAD_FAILED -5 /* couldn't possibly happen */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_OUTER_HEADER_BAD -6
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_SWITCH_VALUE_ILLEGAL -7
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_SWITCH_VALUE_INVALID -8
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_SWITCH_VALUE_MISSING -9
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_SIZE_IS_MISMATCH_PDU -10
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_SIZE_IS_MISMATCH_AFTER -11
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_SIZE_IS_UNEXPECTED -12
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_SIZE_IS_DUPLICATED -13
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_OUTER_PARAMS_MISMATCH -14
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_ARRAY_VARLEN_ILLEGAL -15
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_ARRAY_UNION_ILLEGAL -16
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_OUTER_PARAMS_BAD -17
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_OUTER_UNION_ILLEGAL -18
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_TOPMOST_UNION_ILLEGAL -19
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_TOPMOST_VARLEN_ILLEGAL -20
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_INNER_PARAMS_BAD -21
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_UNIMPLEMENTED -22
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_NOT_AN_INTERFACE -23
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_STRLEN -24
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_STRING_SIZING -25
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_BOUNDS_CHECK -26
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_SET_ERROR(REF, ERROR) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ((REF)->stream->error = (ERROR), \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (REF)->stream->error_ref = __LINE__, \
8d7e41661dc4633488e93b13363137523ce59977jose borrego NDS_TATTLE_ERROR((REF)->stream, 0, REF))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TATTLE(REF, WHAT) \
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(REF)->stream->ndo->ndo_tattle)((REF)->stream, WHAT, REF)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define MEMBER_STR(MEMBER) #MEMBER
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_DIR_IS_IN (encl_ref->stream->dir == NDR_DIR_IN)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_DIR_IS_OUT (encl_ref->stream->dir == NDR_DIR_OUT)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ARGFLAGS, ARGMEM, ARGVAL) { \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.pdu_offset = encl_ref->pdu_offset + (OFFSET); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.name = MEMBER_STR(MEMBER); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.datum = (char *)&val->MEMBER; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.inner_flags = ARGFLAGS; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.ti = &ndt_##TYPE; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.ARGMEM = ARGVAL; \
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (!ndr_inner(&myref)) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER(TYPE, MEMBER, OFFSET) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_NONE, size_is, 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_SIZE_IS, size_is, SIZE_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, OFFSET, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_DIMENSION_IS, dimension_is, SIZE_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_SIZE_IS+NDR_F_IS_POINTER, size_is, SIZE_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_PTR(TYPE, MEMBER, OFFSET) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_IS_POINTER, size_is, 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, OFFSET, SWITCH_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_MEMBER_WITH_ARG(TYPE, MEMBER, OFFSET, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_SWITCH_IS, switch_is, SWITCH_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ARGFLAGS, ARGMEM, ARGVAL) { \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.pdu_offset = -1; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.name = MEMBER_STR(MEMBER); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.datum = (char *)&val->MEMBER; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.inner_flags = ARGFLAGS; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.ti = &ndt_##TYPE; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.ARGMEM = ARGVAL; \
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (!ndr_topmost(&myref)) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER(TYPE, MEMBER) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_NONE, size_is, 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_SIZE_IS, size_is, SIZE_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_DIMENSION_IS, dimension_is, SIZE_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_SIZE_IS+NDR_F_IS_POINTER, size_is, SIZE_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_PTR(TYPE, MEMBER) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_IS_POINTER, size_is, 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_REF(TYPE, MEMBER) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_IS_REFERENCE, size_is, 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_REF_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_SIZE_IS+NDR_F_IS_REFERENCE, size_is, SIZE_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, SWITCH_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_TOPMOST_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_SWITCH_IS, switch_is, SWITCH_IS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* this is assuming offset+0 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_PARAMS_MEMBER_WITH_ARG(TYPE, MEMBER, ARGFLAGS, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ARGMEM, ARGVAL) { \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.pdu_offset = encl_ref->pdu_offset; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.name = MEMBER_STR(MEMBER); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.datum = (char *)&val->MEMBER; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.inner_flags = ARGFLAGS; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.ti = &ndt_##TYPE; \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw myref.ARGMEM = ARGVAL; \
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (!ndr_params(&myref)) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_PARAMS_MEMBER(TYPE, MEMBER) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_PARAMS_MEMBER_WITH_ARG(TYPE, MEMBER, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NDR_F_NONE, size_is, 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_STRING_DIM 1
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ANYSIZE_DIM 1
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndo_process(struct ndr_stream *, ndr_typeinfo_t *, char *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndo_operation(struct ndr_stream *, ndr_typeinfo_t *, int opnum, char *);
8d7e41661dc4633488e93b13363137523ce59977jose borregovoid ndo_printf(struct ndr_stream *, ndr_ref_t *, const char *, ...);
8d7e41661dc4633488e93b13363137523ce59977jose borregovoid ndo_trace(const char *);
8d7e41661dc4633488e93b13363137523ce59977jose borregovoid ndo_fmt(struct ndr_stream *, ndr_ref_t *, char *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_params(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_topmost(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_run_outer_queue(struct ndr_stream *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_fixed(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_fixed_array(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_conformant_array(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_conformant_construct(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_size_is(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_string(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_peek_sizing(ndr_ref_t *, unsigned, unsigned long *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_poke_sizing(ndr_ref_t *, unsigned, unsigned long *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_align(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_outer_grow(ndr_ref_t *, unsigned);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_inner(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_inner_pointer(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_inner_reference(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_inner_array(ndr_ref_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brownsize_t ndr_mbstowcs(struct ndr_stream *, smb_wchar_t *, const char *, size_t);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brownint ndr_mbtowc(struct ndr_stream *, smb_wchar_t *, const char *, size_t);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borregovoid nds_bswap(void *src, void *dst, size_t len);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef __cplusplus
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif /* _SMBSRV_NDR_H */