/*
* 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
*/
/*
*/
/*
* Server-side NDR stream (PDU) operations. Stream operations should
* return TRUE (non-zero) on success or FALSE (zero or a null pointer)
* on failure. When an operation returns FALSE, including ndo_malloc()
* returning NULL, it should set the nds->error to indicate what went
* wrong.
*
* When available, the relevant ndr reference is passed to the
* operation but keep in mind that it may be a null pointer.
*
* 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.
*/
#include <stdarg.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <assert.h>
#define NDR_PDU_ALIGN(N) \
(((N) + NDR_PDU_BLOCK_SIZE) & ~NDR_PDU_BLOCK_MASK)
static int ndo_pad_pdu(ndr_stream_t *, unsigned long, unsigned long,
ndr_ref_t *);
static int ndo_get_pdu(ndr_stream_t *, unsigned long, unsigned long,
char *, int, ndr_ref_t *);
static int ndo_put_pdu(ndr_stream_t *, unsigned long, unsigned long,
char *, int, ndr_ref_t *);
static int ndo_reset(ndr_stream_t *);
static void ndo_destruct(ndr_stream_t *);
static void ndo_hexfmt(uint8_t *, int, int, char *, int);
/*
* The ndr stream operations table.
*/
};
/*
* nds_bswap
*
* Copies len bytes from src to dst such that dst contains the bytes
* from src in reverse order.
*
* We expect to be dealing with bytes, words, dwords etc. So the
* length must be non-zero and a power of 2.
*/
void
{
while (len--)
}
}
/*
* nds_initialize
*
* Initialize a stream. Sets up the PDU parameters and assigns the stream
* operations and the reference to the heap. An external heap is provided
* to the stream, rather than each stream creating its own heap.
*/
int
{
unsigned size;
if (pdu_size_hint > NDR_PDU_MAX_SIZE) {
return (NDR_DRC_FAULT_RESOURCE_1);
}
return (NDR_DRC_FAULT_OUT_OF_MEMORY);
}
return (0);
}
void
{
return;
return;
++iov;
}
}
/*
* nds_destruct
*
* Destroy a stream. This is an external interface to provide access to
* the stream's destruct operation.
*/
void
{
return;
}
/*
* Print NDR stream state.
*/
void
{
return;
}
}
/*
* ndo_malloc
*
* Allocate memory from the stream heap.
*/
/*ARGSUSED*/
static char *
{
}
/*
* ndo_free
*
* Always succeeds: cannot free individual stream allocations.
*/
/*ARGSUSED*/
static int
{
return (1);
}
/*
* ndo_grow_pdu
*
* This is the only place that should change the size of the PDU. If the
* desired offset is beyond the current PDU size, we realloc the PDU
* buffer to accommodate the request. For efficiency, the PDU is always
* extended to a NDR_PDU_BLOCK_SIZE boundary. Requests to grow the PDU
* beyond NDR_PDU_MAX_SIZE are rejected.
*
* Returns 1 to indicate success. Otherwise 0 to indicate failure.
*/
static int
{
unsigned char *pdu_addr;
unsigned pdu_max_size;
if (want_end_offset > pdu_max_size) {
if (pdu_max_size >= NDR_PDU_MAX_SIZE)
return (0);
if (pdu_addr == 0)
return (0);
}
return (1);
}
static int
{
unsigned char *data;
data += pdu_offset;
return (1);
}
/*
* ndo_get_pdu
*
* The swap flag is 1 if NDR knows that the byte-order in the PDU
* is different from the local system.
*
* Returns 1 on success or 0 to indicate failure.
*/
static int
{
unsigned char *data;
data += pdu_offset;
if (!swap_bytes)
else
return (1);
}
/*
* ndo_put_pdu
*
* This is a receiver makes right protocol. So we do not need
* to be concerned about the byte-order of an outgoing PDU.
*/
/*ARGSUSED*/
static int
{
unsigned char *data;
data += pdu_offset;
return (1);
}
static void
{
}
static void
{
unsigned char *data;
if (ref)
else
} else {
}
}
/*
* ndo_reset
*
* Reset a stream: zap the outer_queue. We don't need to tamper
* with the stream heap: it's handled externally to the stream.
*/
static int
{
nds->pdu_scan_offset = 0;
nds->outer_queue_head = 0;
nds->outer_current = 0;
return (1);
}
/*
* ndo_destruct
*
* Destruct a stream: zap the outer_queue.
* Note: heap management (creation/destruction) is external to the stream.
*/
static void
{
return;
nds->pdu_base_offset = 0;
}
}
nds->outer_queue_head = 0;
nds->outer_current = 0;
}
/*
* Printf style formatting for NDR operations.
*/
void
{
if (nds)
else
}
/*
* Main output formatter for NDR operations.
*
* UI 03 ... rpc_vers get 1@0 = 5 {05}
* UI 03 ... rpc_vers_minor get 1@1 = 0 {00}
*
* U Marshalling flag (M=marshal, U=unmarshal)
* I Direction flag (I=in, O=out)
* ... Field name
* get PDU operation (get or put)
* 1@0 Bytes @ offset (i.e. 1 byte at offset 0)
* {05} Value
*/
void
{
ndr_ref_t *p;
int indent;
case 0: m_op_c = '-'; break;
default: m_op_c = '?'; break;
}
case 0: dir_c = '-'; break;
default: dir_c = '?'; break;
}
indent++;
indent--;
} else {
}
} else {
}
"....+....+....+....+....+....",
}
/*ARGSUSED*/
void
ndo_trace(const char *s)
{
/*
* Temporary fbt for dtrace until user space sdt enabled.
*/
}
/*
* Format data as hex bytes (limit is 10 bytes):
*
* 1188689424 {10 f6 d9 46}
*
* If the input data is greater than 10 bytes, an ellipsis will
* be inserted before the closing brace.
*/
static void
{
char *p = buf;
uint32_t c;
int n;
int i;
if (n > len-1)
n = len-1;
switch (size) {
case 1:
break;
case 2:
if (swap_bytes == 0) /*LINTED E_BAD_PTR_CAST_ALIGN*/
else
break;
case 4:
if (swap_bytes == 0) { /*LINTED E_BAD_PTR_CAST_ALIGN*/
} else {
}
break;
default:
c = 0;
interp = 0;
break;
}
if (interp)
p += sprintf(p, "%4u {", c);
else
p += sprintf(p, " {");
for (i = 1; i < n; i++)
if (size > 10)
p += sprintf(p, " ...}");
else
p += sprintf(p, "}");
/*
* Show c if it's a printable character or wide-char.
*/
}