summaryrefslogtreecommitdiff
path: root/source4/libcli/rpc/rpc_basic.c
blob: 5ff17f9d991f484121108c9843c8858dc4ef1ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* 
   Unix SMB/CIFS implementation.

   routines for marshalling/unmarshalling basic types

   Copyright (C) Andrew Tridgell 2003
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"

#define NDR_NEED_BYTES(ndr, n) do { \
	if ((n) > ndr->data_size || ndr->offset + (n) > ndr->data_size) { \
		return NT_STATUS_BUFFER_TOO_SMALL; \
	} \
} while(0)

#define NDR_ALIGN(ndr, n) do { \
	ndr->offset = (ndr->offset + (n-1)) & ~(n-1); \
	if (ndr->offset >= ndr->data_size) { \
		return NT_STATUS_BUFFER_TOO_SMALL; \
	} \
} while(0)

/*
  parse a GUID
*/
NTSTATUS ndr_parse_guid(struct ndr_parse *ndr, GUID *guid)
{
	int i;
	NDR_NEED_BYTES(ndr, GUID_SIZE);
	for (i=0;i<GUID_SIZE;i++) {
		guid->info[i] = CVAL(ndr->data, ndr->offset + i);
	}
	ndr->offset += i;
	return NT_STATUS_OK;
}


/*
  parse a u8
*/
NTSTATUS ndr_parse_u8(struct ndr_parse *ndr, uint8 *v)
{
	NDR_NEED_BYTES(ndr, 1);
	*v = CVAL(ndr->data, ndr->offset);
	ndr->offset += 1;
	return NT_STATUS_OK;
}


/*
  parse a u16
*/
NTSTATUS ndr_parse_u16(struct ndr_parse *ndr, uint16 *v)
{
	NDR_ALIGN(ndr, 2);
	NDR_NEED_BYTES(ndr, 2);
	if (ndr->flags & LIBNDR_FLAG_BIGENDIAN) {
		*v = RSVAL(ndr->data, ndr->offset);
	} else {
		*v = SVAL(ndr->data, ndr->offset);
	}
	ndr->offset += 2;
	return NT_STATUS_OK;
}


/*
  parse a u32
*/
NTSTATUS ndr_parse_u32(struct ndr_parse *ndr, uint32 *v)
{
	NDR_ALIGN(ndr, 4);
	NDR_NEED_BYTES(ndr, 4);
	if (ndr->flags & LIBNDR_FLAG_BIGENDIAN) {
		*v = RIVAL(ndr->data, ndr->offset);
	} else {
		*v = IVAL(ndr->data, ndr->offset);
	}
	ndr->offset += 2;
	return NT_STATUS_OK;
}