示例#1
0
bool smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
{
	int i;
	
	if (rpc == NULL)
		return False;

	prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
	depth++;

	if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
		return False;

	if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts))
		return False;

	/* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */

	/* num_contexts must not be zero. */
	if (rpc->num_contexts == 0)
		return False;

	if (UNMARSHALLING(ps)) {
		if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {
			return False;
		}
	}

	for (i = 0; i < rpc->num_contexts; i++ ) {
		if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))
			return False;
	}

	return True;
}
示例#2
0
BOOL prs_rpcbuffer_p(const char *desc, prs_struct *ps, int depth, RPC_BUFFER **buffer)
{
	uint32 data_p;

	/* caputure the pointer value to stream */

	data_p = *buffer ? 0xf000baaa : 0;

	if ( !prs_uint32("ptr", ps, depth, &data_p ))
		return False;

	/* we're done if there is no data */

	if ( !data_p )
		return True;

	if ( UNMARSHALLING(ps) ) {
		if ( !(*buffer = PRS_ALLOC_MEM(ps, RPC_BUFFER, 1)) )
			return False;
	} else {
		/* Marshalling case. - coverity paranoia - should already be ok if data_p != 0 */
		if (!*buffer) {
			return True;
		}
	}

	return prs_rpcbuffer( desc, ps, depth, *buffer);
}
示例#3
0
bool smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth)
{
	int i;

	if (rpc_ctx == NULL)
		return False;

	if(!prs_align(ps))
		return False;
	if(!prs_uint16("context_id  ", ps, depth, &rpc_ctx->context_id ))
		return False;
	if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))
		return False;

	/* num_transfer_syntaxes must not be zero. */
	if (rpc_ctx->num_transfer_syntaxes == 0)
		return False;

	if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))
		return False;

	if (UNMARSHALLING(ps)) {
		if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {
			return False;
		}
	}

	for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {
		if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))
			return False;
	}
	return True;
} 
示例#4
0
BOOL prs_io_unistr2_p(const char *desc, prs_struct *ps, int depth, UNISTR2 **uni2)
{
	uint32 data_p;

	/* caputure the pointer value to stream */

	data_p = *uni2 ? 0xf000baaa : 0;

	if ( !prs_uint32("ptr", ps, depth, &data_p ))
		return False;

	/* we're done if there is no data */

	if ( !data_p )
		return True;

	if (UNMARSHALLING(ps)) {
		if ( !(*uni2 = PRS_ALLOC_MEM(ps, UNISTR2, 1)) )
			return False;
	}

	return True;
}
示例#5
0
BOOL smb_io_dom_sid2_p(const char *desc, prs_struct *ps, int depth, DOM_SID2 **sid2)
{
	uint32 data_p;

	/* caputure the pointer value to stream */

	data_p = *sid2 ? 0xf000baaa : 0;

	if ( !prs_uint32("dom_sid2_p", ps, depth, &data_p ))
		return False;

	/* we're done if there is no data */

	if ( !data_p )
		return True;

	if (UNMARSHALLING(ps)) {
		if ( !(*sid2 = PRS_ALLOC_MEM(ps, DOM_SID2, 1)) )
		return False;
	}

	return True;
}
示例#6
0
BOOL smb_io_rpc_blob(const char *desc, RPC_DATA_BLOB *blob, prs_struct *ps, int depth)
{
	prs_debug(ps, depth, desc, "smb_io_rpc_blob");
	depth++;

	prs_align(ps);
	if ( !prs_uint32("buf_len", ps, depth, &blob->buf_len) )
		return False;

	if ( blob->buf_len == 0 )
		return True;

	if (UNMARSHALLING(ps)) {
		blob->buffer = PRS_ALLOC_MEM(ps, uint8, blob->buf_len);
		if (!blob->buffer) {
			return False;
		}
	}

	if ( !prs_uint8s(True, "buffer", ps, depth, blob->buffer, blob->buf_len) )
		return False;

	return True;
}
示例#7
0
bool prs_unistr(const char *name, prs_struct *ps, int depth, UNISTR *str)
{
	unsigned int len = 0;
	unsigned char *p = (unsigned char *)str->buffer;
	uint8 *start;
	char *q;
	uint32 max_len;
	uint16* ptr;

	if (MARSHALLING(ps)) {

		for(len = 0; str->buffer[len] != 0; len++)
			;

		q = prs_mem_get(ps, (len+1)*2);
		if (q == NULL)
			return False;

		start = (uint8*)q;

		for(len = 0; str->buffer[len] != 0; len++) {
			if(ps->bigendian_data) {
				/* swap bytes - p is little endian, q is big endian. */
				q[0] = (char)p[1];
				q[1] = (char)p[0];
				p += 2;
				q += 2;
			} 
			else 
			{
				q[0] = (char)p[0];
				q[1] = (char)p[1];
				p += 2;
				q += 2;
			}
		}

		/*
		 * even if the string is 'empty' (only an \0 char)
		 * at this point the leading \0 hasn't been parsed.
		 * so parse it now
		 */

		q[0] = 0;
		q[1] = 0;
		q += 2;

		len++;

		DEBUGADD(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name));
		print_asc(5, (unsigned char*)start, 2*len);	
		DEBUGADD(5, ("\n"));
	}
	else { /* unmarshalling */
	
		uint32 alloc_len = 0;
		q = ps->data_p + prs_offset(ps);

		/*
		 * Work out how much space we need and talloc it.
		 */
		max_len = (ps->buffer_size - ps->data_offset)/sizeof(uint16);

		/* the test of the value of *ptr helps to catch the circumstance
		   where we have an emtpty (non-existent) string in the buffer */
		for ( ptr = (uint16 *)q; *ptr++ && (alloc_len <= max_len); alloc_len++)
			/* do nothing */ 
			;

		if (alloc_len < max_len)
			alloc_len += 1;

		/* should we allocate anything at all? */
		str->buffer = PRS_ALLOC_MEM(ps,uint16,alloc_len);
		if ((str->buffer == NULL) && (alloc_len > 0))
			return False;

		p = (unsigned char *)str->buffer;

		len = 0;
		/* the (len < alloc_len) test is to prevent us from overwriting
		   memory that is not ours...if we get that far, we have a non-null
		   terminated string in the buffer and have messed up somewhere */
		while ((len < alloc_len) && (*(uint16 *)q != 0)) {
			if(ps->bigendian_data) 
			{
				/* swap bytes - q is big endian, p is little endian. */
				p[0] = (unsigned char)q[1];
				p[1] = (unsigned char)q[0];
				p += 2;
				q += 2;
			} else {

				p[0] = (unsigned char)q[0];
				p[1] = (unsigned char)q[1];
				p += 2;
				q += 2;
			}

			len++;
		} 
		if (len < alloc_len) {
			/* NULL terminate the UNISTR */
			str->buffer[len++] = '\0';
		}

		DEBUGADD(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name));
		print_asc(5, (unsigned char*)str->buffer, 2*len);	
		DEBUGADD(5, ("\n"));
	}

	/* set the offset in the prs_struct; 'len' points to the
	   terminiating NULL in the UNISTR so we need to go one more
	   uint16 */
	ps->data_offset += (len)*2;
	
	return True;
}