ndr.h revision b1352070d318187b41b088da3533692976f3f225
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SMBSRV_NDR_H
#define _SMBSRV_NDR_H
/*
* Network Data Representation (NDR) is a compatible subset of DCE RPC
* and MSRPC NDR. NDR is used to move parameters consisting of
* complicated trees of data constructs between an RPC client and server.
*
* CAE Specification (1997)
* DCE 1.1: Remote Procedure Call
* Document Number: C706
* The Open Group
* ogspecs@opengroup.org
*/
#ifndef _KERNEL
#include <syslog.h>
#include <stdlib.h>
#include <string.h>
#include <smbsrv/wintypes.h>
#include <smbsrv/smb_i18n.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* Normal sequence:
* - Application calls client-side stub w/ TOP-MOST arg structure
* - client stub performs NDR_M_OP_MARSHALL+NDR_DIR_IN
* - PDU conveyed (request, aka call, aka query)
* - server stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_IN
* - server function called w/ TOP-MOST arg structure
* - server function returns w/ TOP-MOST arg structure modified
* - server stub performs NDR_M_OP_MARSHALL+NDR_DIR_OUT
* - PDU conveyed (reply, aka result, aka response)
* - client stub performs NDR_M_OP_UNMARSHALL+NDR_DIR_OUT
* - return to Application w/ TOP-MOST arg structure modified
*
* An interface is a sequence of top-most constructs. Each top-most
* construct corresponds to one parameter, either argument or return
* value.
*
* A top-most construct is a sequence of outer constructs. The first
* outer construct is the referent of the argument, and the subsequent
* outer constructs are descendents referenced by pointers from prior
* constructs.
*
* An outer construct is a sequence of variable-sized info, fixed-sized
* data, and variable-sized data.
*/
/*
* Terminology
*
* The mixed-case names have been introduced as a reading aid.
*
* Size The size of an array in elements. Think of this
* as the amount to malloc().
*
* Length The number of elements of an array which are significant
* Think of this as the amount to bcopy().
*
*
*
* FIXED The Size and Length are Known.
* Think of this as a string constant or a DOS 8.3 file name.
*
* CONFORMANT The Size is Determined. Length is the same as Size.
* Think of this as strdup().
* char *array = strdup("Something");
*
* VARYING The Size is Known. The Length is determined.
* Think of this as a strcpy() of a variable length string
* into a fixed length buffer:
* char array[100];
* strcpy(array, "very short string");
*
* The Size is Determined. The Length is separately Determined.
* Think of this like:
* char *array = malloc(size);
* strcpy(array, "short string");
*
* STRING Strings can be CONFORMANT, VARYING, or CONFORMANT/VARYING.
* A string is fundamentally an array with the last
* significant element some sort of NULL.
*/
#define NDR_F_PARAMS_MASK 0x00FF
#define NDR_F_WHENCE_MASK 0x00F0
#define NDR_F_TYPEOP_MASK 0x0F00
struct ndr_heap;
struct ndr_stream;
struct ndr_reference;
typedef struct ndr_typeinfo {
unsigned char version; /* sanity check */
unsigned char alignment; /* mask */
unsigned short type_flags; /* NDR_F_... */
int (*ndr_func)(struct ndr_reference *);
unsigned short pdu_size_fixed_part;
unsigned short pdu_size_variable_part;
unsigned short c_size_fixed_part;
unsigned short c_size_variable_part;
typedef struct ndr_reference {
char *name; /* name of this member */
unsigned long pdu_offset; /* referent in stub data */
char *datum; /* referent in local memory */
char **backptr; /* referer to set */
unsigned short outer_flags; /* XXX_is() from top level */
unsigned short inner_flags; /* XXX_is() in encapsulated */
unsigned short type_flags; /* "requires" */
unsigned short packed_alignment;
unsigned long size_is; /* conforming constructs */
unsigned long strlen_is; /* strings */
unsigned long switch_is; /* union arg selector */
unsigned long dimension_is; /* fixed-len array size */
unsigned long pdu_end_offset; /* offset for limit of PDU */
} ndr_ref_t;
/*
* For all operations, the ndr_stream, which is the root of NDR processing,
* is the primary object. When available, the appropriate ndr_ref_t
* is passed, NULL otherwise. Functions that return 'int' should return
* TRUE (!0) or FALSE (0). When functions return FALSE, including
* ndo_malloc() returning NULL, they should set the stream->error to an
* appropriate indicator of what went wrong.
*
* Functions ndo_get_pdu(), ndo_put_pdu(), and ndo_pad_pdu() must
* never grow the PDU data. A request for out-of-bounds data is an error.
* The swap_bytes flag is 1 if NDR knows that the byte-order in the PDU
* is different from the local system. ndo_pad_pdu() advised that the
* affected bytes should be zero filled.
*/
typedef struct ndr_stream_ops {
int (*ndo_pad_pdu)(struct ndr_stream *, unsigned long,
unsigned long, ndr_ref_t *);
int (*ndo_get_pdu)(struct ndr_stream *, unsigned long,
unsigned long, char *, int, ndr_ref_t *);
int (*ndo_put_pdu)(struct ndr_stream *, unsigned long,
unsigned long, char *, int, ndr_ref_t *);
int (*ndo_reset)(struct ndr_stream *);
void (*ndo_destruct)(struct ndr_stream *);
typedef struct ndr_frag {
} ndr_frag_t;
typedef struct ndr_fraglist {
typedef struct ndr_stream {
unsigned long pdu_size;
unsigned long pdu_max_size;
unsigned long pdu_base_offset;
unsigned long pdu_scan_offset;
unsigned char *pdu_base_addr;
unsigned char m_op;
unsigned char dir;
unsigned char flags;
short error;
short error_ref;
} ndr_stream_t;
#define NDR_M_OP_NONE 0x00
#define NDR_DIR_NONE 0x00
#define NDR_IS_FIRST_FRAG(F) ((F) & NDR_PFC_FIRST_FRAG)
#define NDR_IS_LAST_FRAG(F) ((F) & NDR_PFC_LAST_FRAG)
#define NDR_IS_SINGLE_FRAG(F) \
(NDR_IS_FIRST_FRAG((F)) && NDR_IS_LAST_FRAG((F)))
#define NDS_F_NONE 0x00
#define NDS_CLEARF(S, F) ((S)->flags &= ~(F))
#define NDR_ERR_MALLOC_FAILED -1
#define NDR_ERR_M_OP_INVALID -2
#define NDR_ERR_UNDERFLOW -3
#define NDR_ERR_OUTER_HEADER_BAD -6
#define NDR_ERR_SWITCH_VALUE_ILLEGAL -7
#define NDR_ERR_SWITCH_VALUE_INVALID -8
#define NDR_ERR_SWITCH_VALUE_MISSING -9
#define NDR_ERR_SIZE_IS_MISMATCH_PDU -10
#define NDR_ERR_SIZE_IS_MISMATCH_AFTER -11
#define NDR_ERR_SIZE_IS_UNEXPECTED -12
#define NDR_ERR_SIZE_IS_DUPLICATED -13
#define NDR_ERR_OUTER_PARAMS_MISMATCH -14
#define NDR_ERR_ARRAY_VARLEN_ILLEGAL -15
#define NDR_ERR_ARRAY_UNION_ILLEGAL -16
#define NDR_ERR_OUTER_PARAMS_BAD -17
#define NDR_ERR_OUTER_UNION_ILLEGAL -18
#define NDR_ERR_TOPMOST_UNION_ILLEGAL -19
#define NDR_ERR_TOPMOST_VARLEN_ILLEGAL -20
#define NDR_ERR_INNER_PARAMS_BAD -21
#define NDR_ERR_UNIMPLEMENTED -22
#define NDR_ERR_NOT_AN_INTERFACE -23
#define NDR_ERR_STRLEN -24
#define NDR_ERR_STRING_SIZING -25
#define NDR_ERR_BOUNDS_CHECK -26
return (0); \
}
NDR_F_NONE, size_is, 0)
NDR_F_IS_POINTER, size_is, 0)
if (!ndr_topmost(&myref)) \
return (0); \
}
NDR_F_NONE, size_is, 0)
NDR_F_IS_POINTER, size_is, 0)
/* this is assuming offset+0 */
if (!ndr_params(&myref)) \
return (0); \
}
NDR_F_NONE, size_is, 0)
#define NDR_STRING_DIM 1
#define NDR_ANYSIZE_DIM 1
void ndo_trace(const char *);
int ndr_params(ndr_ref_t *);
int ndr_topmost(ndr_ref_t *);
int ndr_run_outer_queue(struct ndr_stream *);
int ndr_outer_fixed(ndr_ref_t *);
int ndr_outer_fixed_array(ndr_ref_t *);
int ndr_outer_conformant_array(ndr_ref_t *);
int ndr_size_is(ndr_ref_t *);
int ndr_outer_string(ndr_ref_t *);
int ndr_outer_peek_sizing(ndr_ref_t *, unsigned, unsigned long *);
int ndr_outer_poke_sizing(ndr_ref_t *, unsigned, unsigned long *);
int ndr_outer_align(ndr_ref_t *);
int ndr_outer_grow(ndr_ref_t *, unsigned);
int ndr_inner_pointer(ndr_ref_t *);
int ndr_inner_reference(ndr_ref_t *);
int ndr_inner_array(ndr_ref_t *);
#ifdef __cplusplus
}
#endif
#endif /* _SMBSRV_NDR_H */