summaryrefslogtreecommitdiff
path: root/source4/librpc/ndr/ndr_misc.c
blob: 31f501e614e452d8c6bb825d0cb6cb19d66b9d3a (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* parser auto-generated by pidl */

#include "includes.h"

NTSTATUS ndr_push_dom_sid(struct ndr_push *ndr, int ndr_flags, struct dom_sid *r)
{
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_push_struct_start(ndr));
	NDR_CHECK(ndr_push_align(ndr, 4));
	NDR_CHECK(ndr_push_uint8(ndr, r->sid_rev_num));
	NDR_CHECK(ndr_push_uint8(ndr, r->num_auths));
		NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->id_auth, 6));
		NDR_CHECK(ndr_push_array_uint32(ndr, NDR_SCALARS, r->sub_auths, r->num_auths));
	ndr_push_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
		NDR_CHECK(ndr_push_array_uint8(ndr, NDR_BUFFERS, r->id_auth, 6));
		NDR_CHECK(ndr_push_array_uint32(ndr, NDR_BUFFERS, r->sub_auths, r->num_auths));
done:
	return NT_STATUS_OK;
}

NTSTATUS ndr_push_security_ace(struct ndr_push *ndr, int ndr_flags, struct security_ace *r)
{
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_push_struct_start(ndr));
	NDR_CHECK(ndr_push_align(ndr, 4));
	NDR_CHECK(ndr_push_uint8(ndr, r->type));
	NDR_CHECK(ndr_push_uint8(ndr, r->flags));
	NDR_CHECK(ndr_push_uint32(ndr, r->access_mask));
	NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->trustee));
	ndr_push_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
		NDR_CHECK(ndr_push_dom_sid(ndr, NDR_BUFFERS, &r->trustee));
done:
	return NT_STATUS_OK;
}

NTSTATUS ndr_push_security_acl(struct ndr_push *ndr, int ndr_flags, struct security_acl *r)
{
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_push_struct_start(ndr));
	NDR_CHECK(ndr_push_align(ndr, 4));
	NDR_CHECK(ndr_push_uint16(ndr, r->revision));
	NDR_CHECK(ndr_push_uint32(ndr, r->num_aces));
		NDR_CHECK(ndr_push_array(ndr, NDR_SCALARS, r->aces, sizeof(r->aces[0]), r->num_aces, (ndr_push_flags_fn_t)ndr_push_security_ace));
	ndr_push_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
		NDR_CHECK(ndr_push_array(ndr, NDR_BUFFERS, r->aces, sizeof(r->aces[0]), r->num_aces, (ndr_push_flags_fn_t)ndr_push_security_ace));
done:
	return NT_STATUS_OK;
}

NTSTATUS ndr_push_security_descriptor(struct ndr_push *ndr, int ndr_flags, struct security_descriptor *r)
{
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_push_struct_start(ndr));
	NDR_CHECK(ndr_push_align(ndr, 4));
	NDR_CHECK(ndr_push_uint8(ndr, r->revision));
	NDR_CHECK(ndr_push_uint16(ndr, r->type));
	NDR_CHECK(ndr_push_relative(ndr, NDR_SCALARS, r->owner_sid, (ndr_push_const_fn_t) ndr_push_dom_sid));
	NDR_CHECK(ndr_push_relative(ndr, NDR_SCALARS, r->group_sid, (ndr_push_const_fn_t) ndr_push_dom_sid));
	NDR_CHECK(ndr_push_relative(ndr, NDR_SCALARS, r->sacl, (ndr_push_const_fn_t) ndr_push_security_acl));
	NDR_CHECK(ndr_push_relative(ndr, NDR_SCALARS, r->dacl, (ndr_push_const_fn_t) ndr_push_security_acl));
	ndr_push_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
	if (r->owner_sid) {
	NDR_CHECK(ndr_push_relative(ndr, NDR_BUFFERS, r->owner_sid, (ndr_push_const_fn_t) ndr_push_dom_sid));
	}
	if (r->group_sid) {
	NDR_CHECK(ndr_push_relative(ndr, NDR_BUFFERS, r->group_sid, (ndr_push_const_fn_t) ndr_push_dom_sid));
	}
	if (r->sacl) {
	NDR_CHECK(ndr_push_relative(ndr, NDR_BUFFERS, r->sacl, (ndr_push_const_fn_t) ndr_push_security_acl));
	}
	if (r->dacl) {
	NDR_CHECK(ndr_push_relative(ndr, NDR_BUFFERS, r->dacl, (ndr_push_const_fn_t) ndr_push_security_acl));
	}
done:
	return NT_STATUS_OK;
}

NTSTATUS ndr_pull_dom_sid(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *r)
{
	NDR_CHECK(ndr_pull_struct_start(ndr));
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_pull_align(ndr, 4));
	NDR_CHECK(ndr_pull_uint8(ndr, &r->sid_rev_num));
	NDR_CHECK(ndr_pull_uint8(ndr, &r->num_auths));
		NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->id_auth, 6));
		NDR_ALLOC_N_SIZE(ndr, r->sub_auths, r->num_auths, sizeof(r->sub_auths[0]));
		NDR_CHECK(ndr_pull_array_uint32(ndr, NDR_SCALARS, r->sub_auths, r->num_auths));
	ndr_pull_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
		NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_BUFFERS, r->id_auth, 6));
		NDR_CHECK(ndr_pull_array_uint32(ndr, NDR_BUFFERS, r->sub_auths, r->num_auths));
done:
	return NT_STATUS_OK;
}

NTSTATUS ndr_pull_security_ace(struct ndr_pull *ndr, int ndr_flags, struct security_ace *r)
{
	NDR_CHECK(ndr_pull_struct_start(ndr));
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_pull_align(ndr, 4));
	NDR_CHECK(ndr_pull_uint8(ndr, &r->type));
	NDR_CHECK(ndr_pull_uint8(ndr, &r->flags));
	NDR_CHECK(ndr_pull_uint32(ndr, &r->access_mask));
	NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->trustee));
	ndr_pull_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
		NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_BUFFERS, &r->trustee));
done:
	return NT_STATUS_OK;
}

NTSTATUS ndr_pull_security_acl(struct ndr_pull *ndr, int ndr_flags, struct security_acl *r)
{
	NDR_CHECK(ndr_pull_struct_start(ndr));
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_pull_align(ndr, 4));
	NDR_CHECK(ndr_pull_uint16(ndr, &r->revision));
	NDR_CHECK(ndr_pull_uint32(ndr, &r->num_aces));
		NDR_ALLOC_N_SIZE(ndr, r->aces, r->num_aces, sizeof(r->aces[0]));
		NDR_CHECK(ndr_pull_array(ndr, NDR_SCALARS, (void **)r->aces, sizeof(r->aces[0]), r->num_aces, (ndr_pull_flags_fn_t)ndr_pull_security_ace));
	ndr_pull_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
		NDR_CHECK(ndr_pull_array(ndr, NDR_BUFFERS, (void **)r->aces, sizeof(r->aces[0]), r->num_aces, (ndr_pull_flags_fn_t)ndr_pull_security_ace));
done:
	return NT_STATUS_OK;
}

NTSTATUS ndr_pull_security_descriptor(struct ndr_pull *ndr, int ndr_flags, struct security_descriptor *r)
{
	NDR_CHECK(ndr_pull_struct_start(ndr));
	if (!(ndr_flags & NDR_SCALARS)) goto buffers;
	NDR_CHECK(ndr_pull_align(ndr, 4));
	NDR_CHECK(ndr_pull_uint8(ndr, &r->revision));
	NDR_CHECK(ndr_pull_uint16(ndr, &r->type));
	NDR_CHECK(ndr_pull_relative(ndr, (const void **)&r->owner_sid, sizeof(*r->owner_sid), (ndr_pull_flags_fn_t)ndr_pull_dom_sid));
	NDR_CHECK(ndr_pull_relative(ndr, (const void **)&r->group_sid, sizeof(*r->group_sid), (ndr_pull_flags_fn_t)ndr_pull_dom_sid));
	NDR_CHECK(ndr_pull_relative(ndr, (const void **)&r->sacl, sizeof(*r->sacl), (ndr_pull_flags_fn_t)ndr_pull_security_acl));
	NDR_CHECK(ndr_pull_relative(ndr, (const void **)&r->dacl, sizeof(*r->dacl), (ndr_pull_flags_fn_t)ndr_pull_security_acl));
	ndr_pull_struct_end(ndr);
buffers:
	if (!(ndr_flags & NDR_BUFFERS)) goto done;
done:
	return NT_STATUS_OK;
}

void ndr_print_security_ace(struct ndr_print *ndr, const char *name, struct security_ace *r)
{
	ndr_print_struct(ndr, name, "security_ace");
	ndr->depth++;
	ndr_print_uint8(ndr, "type", r->type);
	ndr_print_uint8(ndr, "flags", r->flags);
	ndr_print_uint32(ndr, "access_mask", r->access_mask);
	ndr_print_dom_sid(ndr, "trustee", &r->trustee);
	ndr->depth--;
}

void ndr_print_security_acl(struct ndr_print *ndr, const char *name, struct security_acl *r)
{
	ndr_print_struct(ndr, name, "security_acl");
	ndr->depth++;
	ndr_print_uint16(ndr, "revision", r->revision);
	ndr_print_uint32(ndr, "num_aces", r->num_aces);
	ndr_print_ptr(ndr, "aces", r->aces);
	ndr->depth++;
		ndr_print_array(ndr, "aces", r->aces, sizeof(r->aces[0]), r->num_aces, (ndr_print_fn_t)ndr_print_security_ace);
	ndr->depth--;
	ndr->depth--;
}

void ndr_print_security_descriptor(struct ndr_print *ndr, const char *name, struct security_descriptor *r)
{
	ndr_print_struct(ndr, name, "security_descriptor");
	ndr->depth++;
	ndr_print_uint8(ndr, "revision", r->revision);
	ndr_print_uint16(ndr, "type", r->type);
	ndr_print_ptr(ndr, "owner_sid", r->owner_sid);
	ndr->depth++;
	if (r->owner_sid) {
		ndr_print_dom_sid(ndr, "owner_sid", r->owner_sid);
	}
	ndr->depth--;
	ndr_print_ptr(ndr, "group_sid", r->group_sid);
	ndr->depth++;
	if (r->group_sid) {
		ndr_print_dom_sid(ndr, "group_sid", r->group_sid);
	}
	ndr->depth--;
	ndr_print_ptr(ndr, "sacl", r->sacl);
	ndr->depth++;
	if (r->sacl) {
		ndr_print_security_acl(ndr, "sacl", r->sacl);
	}
	ndr->depth--;
	ndr_print_ptr(ndr, "dacl", r->dacl);
	ndr->depth++;
	if (r->dacl) {
		ndr_print_security_acl(ndr, "dacl", r->dacl);
	}
	ndr->depth--;
	ndr->depth--;
}