ndr.h revision 8d7e41661dc4633488e93b13363137523ce59977
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
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 * CDDL HEADER END
19d41fcc9d25d65db5db7c75dc9bbb68550868d2amw * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
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 * CAE Specification (1997)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * DCE 1.1: Remote Procedure Call
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Document Number: C706
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The Open Group
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ogspecs@opengroup.org
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern "C" {
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 * An interface is a sequence of top-most constructs. Each top-most
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * construct corresponds to one parameter, either argument or return
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 * An outer construct is a sequence of variable-sized info, fixed-sized
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * data, and variable-sized data.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Terminology
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 * Size The size of an array in elements. Think of this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * as the amount to malloc().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Length The number of elements of an array which are significant
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Think of this as the amount to bcopy().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Known Size/length is known at build time.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Determined Size/length is determined at run time.
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 * CONFORMANT The Size is Determined. Length is the same as Size.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Think of this as strdup().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * char *array = strdup("Something");
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 * 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 * 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#define NDR_F_SIZE_IS 0x0001 /* [size_is(X)] required/given */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_F_SWITCH_IS 0x0004 /* [switch_is(X)] 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#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_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) */
8d7e41661dc4633488e93b13363137523ce59977jose borregotypedef struct ndr_typeinfo {
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 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 ndr_typeinfo_t *ti; /* type of data referenced */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short outer_flags; /* XXX_is() from top level */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short inner_flags; /* XXX_is() in encapsulated */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short packed_alignment;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned long pdu_end_offset; /* offset for limit of PDU */
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.
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.
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 (*(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_RESET(NDS) (*(NDS)->ndo->ndo_reset)(NDS)
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_DESTRUCT(NDS) (*(NDS)->ndo->ndo_destruct)(NDS)
19d41fcc9d25d65db5db7c75dc9bbb68550868d2amwtypedef struct ndr_frag {
3db3f65c6274eb042354801a308c8e9bc4994553amwtypedef struct ndr_fraglist {
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 unsigned char m_op;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char dir;
55bf511df53aad0fdb7eb3fa349f0308cc05234cas unsigned char flags;
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#define NDR_DIR_IN 0x10 /* data moving from caller to callee */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_DIR_OUT 0x20 /* data moving from callee to caller */
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)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_M_OP_AND_DIR_TO_MODE(M_OP, DIR) ((M_OP)|(DIR))
8d7e41661dc4633488e93b13363137523ce59977jose borrego (NDR_M_OP_AND_DIR_TO_MODE((NDS)->m_op, (NDS)->dir) == (MODE))
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define NDS_F_NOTERM 0x01 /* strings are not null terminated */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_ERR_PAD_FAILED -5 /* couldn't possibly happen */
8d7e41661dc4633488e93b13363137523ce59977jose borrego (*(REF)->stream->ndo->ndo_tattle)((REF)->stream, WHAT, REF)
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 return (0); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, OFFSET, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, OFFSET, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, OFFSET, SWITCH_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0); \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_ARR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_ARR_WITH_DIMENSION(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_PTR_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_REF_WITH_SIZE_IS(TYPE, MEMBER, SIZE_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_TOPMOST_MEMBER_WITH_SWITCH_IS(TYPE, MEMBER, SWITCH_IS) \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* this is assuming offset+0 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NDR_PARAMS_MEMBER_WITH_ARG(TYPE, MEMBER, ARGFLAGS, \
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0); \
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 borregoint ndr_outer_conformant_construct(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 borregosize_t ndr_mbstowcs(struct ndr_stream *, mts_wchar_t *, const char *, size_t);
8d7e41661dc4633488e93b13363137523ce59977jose borregoint ndr_mbtowc(struct ndr_stream *, mts_wchar_t *, const char *, size_t);
8d7e41661dc4633488e93b13363137523ce59977jose borregovoid nds_bswap(void *src, void *dst, size_t len);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif /* _SMBSRV_NDR_H */