/src/samba/librpc/ndr/ndr_nbt.c
Line | Count | Source |
1 | | /* |
2 | | Unix SMB/CIFS implementation. |
3 | | |
4 | | CLDAP server structures |
5 | | |
6 | | Copyright (C) Andrew Tridgell 2005 |
7 | | Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008 |
8 | | |
9 | | This program is free software; you can redistribute it and/or modify |
10 | | it under the terms of the GNU General Public License as published by |
11 | | the Free Software Foundation; either version 3 of the License, or |
12 | | (at your option) any later version. |
13 | | |
14 | | This program is distributed in the hope that it will be useful, |
15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | GNU General Public License for more details. |
18 | | |
19 | | You should have received a copy of the GNU General Public License |
20 | | along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | /* parser auto-generated by pidl, then hand-modified by abartlet */ |
24 | | |
25 | | #include "includes.h" |
26 | | #include "../libcli/nbt/libnbt.h" |
27 | | #include "../libcli/netlogon/netlogon.h" |
28 | | #include "ndr_dns_utils.h" |
29 | | |
30 | | |
31 | | /** |
32 | | print a nbt string |
33 | | */ |
34 | | _PUBLIC_ void ndr_print_nbt_string(struct ndr_print *ndr, const char *name, const char *s) |
35 | 1.34k | { |
36 | 1.34k | ndr_print_string(ndr, name, s); |
37 | 1.34k | } |
38 | | |
39 | | /** |
40 | | pull a nbt_string from the wire |
41 | | */ |
42 | | _PUBLIC_ enum ndr_err_code ndr_pull_nbt_string(struct ndr_pull *ndr, ndr_flags_type ndr_flags, const char **s) |
43 | 844k | { |
44 | 844k | return ndr_pull_dns_string_list(ndr, |
45 | 844k | ndr_flags, |
46 | 844k | s, |
47 | 844k | true); |
48 | 844k | } |
49 | | |
50 | | /** |
51 | | push a nbt string to the wire |
52 | | */ |
53 | | _PUBLIC_ enum ndr_err_code ndr_push_nbt_string(struct ndr_push *ndr, ndr_flags_type ndr_flags, const char *s) |
54 | 691k | { |
55 | 691k | return ndr_push_dns_string_list(ndr, |
56 | 691k | &ndr->dns_string_list, |
57 | 691k | ndr_flags, |
58 | 691k | s, |
59 | 691k | true); |
60 | 691k | } |
61 | | |
62 | | |
63 | | /* Manually modified to handle the dom_sid being optional based on if it is present or all zero */ |
64 | | enum ndr_err_code ndr_push_NETLOGON_SAM_LOGON_REQUEST(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct NETLOGON_SAM_LOGON_REQUEST *r) |
65 | 230 | { |
66 | 230 | if (ndr_flags & NDR_SCALARS) { |
67 | 115 | NDR_CHECK(ndr_push_align(ndr, 4)); |
68 | 115 | NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->request_count)); |
69 | 115 | { |
70 | 115 | libndr_flags _flags_save_string = ndr->flags; |
71 | 115 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); |
72 | 115 | NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->computer_name)); |
73 | 115 | ndr->flags = _flags_save_string; |
74 | 115 | } |
75 | 0 | { |
76 | 115 | libndr_flags _flags_save_string = ndr->flags; |
77 | 115 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); |
78 | 115 | NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->user_name)); |
79 | 115 | ndr->flags = _flags_save_string; |
80 | 115 | } |
81 | 0 | { |
82 | 115 | libndr_flags _flags_save_string = ndr->flags; |
83 | 115 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM); |
84 | 115 | NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->mailslot_name)); |
85 | 115 | ndr->flags = _flags_save_string; |
86 | 115 | } |
87 | 115 | NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->acct_control)); |
88 | 115 | NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_size_dom_sid0(&r->sid, ndr->flags))); |
89 | 115 | if (ndr_size_dom_sid0(&r->sid, ndr->flags)) { |
90 | 100 | struct ndr_push *_ndr_sid; |
91 | 100 | libndr_flags _flags_save_DATA_BLOB = ndr->flags; |
92 | 100 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_ALIGN4); |
93 | 100 | NDR_CHECK(ndr_push_DATA_BLOB(ndr, NDR_SCALARS, r->_pad)); |
94 | 100 | ndr->flags = _flags_save_DATA_BLOB; |
95 | 100 | NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_sid, 0, ndr_size_dom_sid0(&r->sid, ndr->flags))); |
96 | 100 | NDR_CHECK(ndr_push_dom_sid0(_ndr_sid, NDR_SCALARS|NDR_BUFFERS, &r->sid)); |
97 | 100 | NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_sid, 0, ndr_size_dom_sid0(&r->sid, ndr->flags))); |
98 | 100 | } |
99 | 115 | NDR_CHECK(ndr_push_netlogon_nt_version_flags(ndr, NDR_SCALARS, r->nt_version)); |
100 | 115 | NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->lmnt_token)); |
101 | 115 | NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->lm20_token)); |
102 | 115 | } |
103 | 230 | if (ndr_flags & NDR_BUFFERS) { |
104 | 115 | } |
105 | 230 | return NDR_ERR_SUCCESS; |
106 | 230 | } |
107 | | |
108 | | /* Manually modified to handle the dom_sid being optional based on if it is present (size is non-zero) or not */ |
109 | | enum ndr_err_code ndr_pull_NETLOGON_SAM_LOGON_REQUEST(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct NETLOGON_SAM_LOGON_REQUEST *r) |
110 | 441 | { |
111 | 441 | if (ndr_flags & NDR_SCALARS) { |
112 | 326 | NDR_CHECK(ndr_pull_align(ndr, 4)); |
113 | 326 | NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->request_count)); |
114 | 325 | { |
115 | 325 | libndr_flags _flags_save_string = ndr->flags; |
116 | 325 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); |
117 | 325 | NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->computer_name)); |
118 | 322 | ndr->flags = _flags_save_string; |
119 | 322 | } |
120 | 0 | { |
121 | 322 | libndr_flags _flags_save_string = ndr->flags; |
122 | 322 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); |
123 | 322 | NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->user_name)); |
124 | 320 | ndr->flags = _flags_save_string; |
125 | 320 | } |
126 | 0 | { |
127 | 320 | libndr_flags _flags_save_string = ndr->flags; |
128 | 320 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM); |
129 | 320 | NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->mailslot_name)); |
130 | 315 | ndr->flags = _flags_save_string; |
131 | 315 | } |
132 | 315 | NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->acct_control)); |
133 | 309 | NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->sid_size)); |
134 | 295 | if (r->sid_size) { |
135 | 277 | libndr_flags _flags_save_DATA_BLOB = ndr->flags; |
136 | 277 | struct ndr_pull *_ndr_sid; |
137 | 277 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_ALIGN4); |
138 | 277 | NDR_CHECK(ndr_pull_DATA_BLOB(ndr, NDR_SCALARS, &r->_pad)); |
139 | 277 | ndr->flags = _flags_save_DATA_BLOB; |
140 | 277 | NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_sid, 0, r->sid_size)); |
141 | 168 | NDR_CHECK(ndr_pull_dom_sid0(_ndr_sid, NDR_SCALARS|NDR_BUFFERS, &r->sid)); |
142 | 144 | NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_sid, 0, r->sid_size)); |
143 | 144 | } else { |
144 | 18 | ZERO_STRUCT(r->sid); |
145 | 18 | } |
146 | 162 | NDR_CHECK(ndr_pull_netlogon_nt_version_flags(ndr, NDR_SCALARS, &r->nt_version)); |
147 | 122 | NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->lmnt_token)); |
148 | 116 | NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->lm20_token)); |
149 | 116 | } |
150 | 230 | if (ndr_flags & NDR_BUFFERS) { |
151 | 115 | } |
152 | 230 | return NDR_ERR_SUCCESS; |
153 | 441 | } |
154 | | |
155 | | /* Manually modified to only push some parts of the structure if certain flags are set */ |
156 | | enum ndr_err_code ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct NETLOGON_SAM_LOGON_RESPONSE_EX *r) |
157 | 56 | { |
158 | 56 | { |
159 | 56 | libndr_flags _flags_save_STRUCT = ndr->flags; |
160 | 56 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN); |
161 | 56 | if (ndr_flags & NDR_SCALARS) { |
162 | 56 | NDR_CHECK(ndr_push_align(ndr, 4)); |
163 | 56 | NDR_CHECK(ndr_push_netlogon_command(ndr, NDR_SCALARS, r->command)); |
164 | 56 | NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->sbz)); |
165 | 56 | NDR_CHECK(ndr_push_nbt_server_type(ndr, NDR_SCALARS, r->server_type)); |
166 | 56 | NDR_CHECK(ndr_push_GUID(ndr, NDR_SCALARS, &r->domain_uuid)); |
167 | 56 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->forest)); |
168 | 55 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->dns_domain)); |
169 | 54 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->pdc_dns_name)); |
170 | 53 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->domain_name)); |
171 | 52 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->pdc_name)); |
172 | 51 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->user_name)); |
173 | 49 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->server_site)); |
174 | 48 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->client_site)); |
175 | 47 | if (r->nt_version & NETLOGON_NT_VERSION_5EX_WITH_IP) { |
176 | 7 | NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, ndr_size_nbt_sockaddr(&r->sockaddr, ndr->flags))); |
177 | 7 | { |
178 | 7 | struct ndr_push *_ndr_sockaddr; |
179 | 7 | NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_sockaddr, 0, ndr_size_nbt_sockaddr(&r->sockaddr, ndr->flags))); |
180 | 7 | NDR_CHECK(ndr_push_nbt_sockaddr(_ndr_sockaddr, NDR_SCALARS|NDR_BUFFERS, &r->sockaddr)); |
181 | 7 | NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_sockaddr, 0, ndr_size_nbt_sockaddr(&r->sockaddr, ndr->flags))); |
182 | 7 | } |
183 | 7 | } |
184 | 47 | if (r->nt_version & NETLOGON_NT_VERSION_WITH_CLOSEST_SITE) { |
185 | 4 | NDR_CHECK(ndr_push_nbt_string(ndr, NDR_SCALARS, r->next_closest_site)); |
186 | 4 | } |
187 | 46 | NDR_CHECK(ndr_push_netlogon_nt_version_flags(ndr, NDR_SCALARS, r->nt_version)); |
188 | 46 | NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->lmnt_token)); |
189 | 46 | NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->lm20_token)); |
190 | 46 | } |
191 | 46 | if (ndr_flags & NDR_BUFFERS) { |
192 | 46 | NDR_CHECK(ndr_push_GUID(ndr, NDR_BUFFERS, &r->domain_uuid)); |
193 | 46 | } |
194 | 46 | ndr->flags = _flags_save_STRUCT; |
195 | 46 | } |
196 | 0 | return NDR_ERR_SUCCESS; |
197 | 46 | } |
198 | | |
199 | | /* Manually modified to only pull some parts of the structure if certain flags provided */ |
200 | | enum ndr_err_code ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct NETLOGON_SAM_LOGON_RESPONSE_EX *r, |
201 | | uint32_t nt_version_flags) |
202 | 167 | { |
203 | 167 | { |
204 | 167 | libndr_flags _flags_save_STRUCT = ndr->flags; |
205 | 167 | ZERO_STRUCTP(r); |
206 | 167 | ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN); |
207 | 167 | if (ndr_flags & NDR_SCALARS) { |
208 | 167 | NDR_CHECK(ndr_pull_align(ndr, 4)); |
209 | 167 | NDR_CHECK(ndr_pull_netlogon_command(ndr, NDR_SCALARS, &r->command)); |
210 | 167 | NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->sbz)); |
211 | 167 | NDR_CHECK(ndr_pull_nbt_server_type(ndr, NDR_SCALARS, &r->server_type)); |
212 | 167 | NDR_CHECK(ndr_pull_GUID(ndr, NDR_SCALARS, &r->domain_uuid)); |
213 | 152 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->forest)); |
214 | 149 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->dns_domain)); |
215 | 148 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->pdc_dns_name)); |
216 | 147 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->domain_name)); |
217 | 146 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->pdc_name)); |
218 | 144 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->user_name)); |
219 | 143 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->server_site)); |
220 | 142 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->client_site)); |
221 | 141 | if (nt_version_flags & NETLOGON_NT_VERSION_5EX_WITH_IP) { |
222 | 31 | NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->sockaddr_size)); |
223 | 30 | { |
224 | 30 | struct ndr_pull *_ndr_sockaddr; |
225 | 30 | NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_sockaddr, 0, r->sockaddr_size)); |
226 | 29 | NDR_CHECK(ndr_pull_nbt_sockaddr(_ndr_sockaddr, NDR_SCALARS|NDR_BUFFERS, &r->sockaddr)); |
227 | 28 | NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_sockaddr, 0, r->sockaddr_size)); |
228 | 28 | } |
229 | 28 | } |
230 | 138 | if (nt_version_flags & NETLOGON_NT_VERSION_WITH_CLOSEST_SITE) { |
231 | 20 | NDR_CHECK(ndr_pull_nbt_string(ndr, NDR_SCALARS, &r->next_closest_site)); |
232 | 20 | } |
233 | 133 | NDR_CHECK(ndr_pull_netlogon_nt_version_flags(ndr, NDR_SCALARS, &r->nt_version)); |
234 | 130 | if (r->nt_version != nt_version_flags) { |
235 | 49 | return NDR_ERR_VALIDATE; |
236 | 49 | } |
237 | 81 | NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->lmnt_token)); |
238 | 80 | NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->lm20_token)); |
239 | 80 | } |
240 | 79 | if (ndr_flags & NDR_BUFFERS) { |
241 | 79 | NDR_CHECK(ndr_pull_GUID(ndr, NDR_BUFFERS, &r->domain_uuid)); |
242 | 79 | } |
243 | 79 | ndr->flags = _flags_save_STRUCT; |
244 | 79 | } |
245 | 0 | return NDR_ERR_SUCCESS; |
246 | 79 | } |
247 | | |
248 | | _PUBLIC_ enum ndr_err_code ndr_push_netlogon_samlogon_response(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct netlogon_samlogon_response *r) |
249 | 74 | { |
250 | 74 | if (r->ntver == NETLOGON_NT_VERSION_1) { |
251 | 1 | NDR_CHECK(ndr_push_NETLOGON_SAM_LOGON_RESPONSE_NT40( |
252 | 1 | ndr, ndr_flags, &r->data.nt4)); |
253 | 73 | } else if (r->ntver & NETLOGON_NT_VERSION_5EX) { |
254 | 56 | NDR_CHECK(ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags( |
255 | 56 | ndr, ndr_flags, &r->data.nt5_ex)); |
256 | 56 | } else if (r->ntver & NETLOGON_NT_VERSION_5) { |
257 | 17 | NDR_CHECK(ndr_push_NETLOGON_SAM_LOGON_RESPONSE( |
258 | 17 | ndr, ndr_flags, &r->data.nt5)); |
259 | 17 | } else { |
260 | 0 | return NDR_ERR_BAD_SWITCH; |
261 | 0 | } |
262 | | |
263 | 59 | return NDR_ERR_SUCCESS; |
264 | 74 | } |
265 | | |
266 | | _PUBLIC_ enum ndr_err_code ndr_pull_netlogon_samlogon_response(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct netlogon_samlogon_response *r) |
267 | 290 | { |
268 | 290 | if (ndr->data_size < 8) { |
269 | 5 | return NDR_ERR_BUFSIZE; |
270 | 5 | } |
271 | | |
272 | | /* lmnttoken */ |
273 | 285 | if (SVAL(ndr->data, ndr->data_size - 4) != 0xffff) { |
274 | 24 | return NDR_ERR_TOKEN; |
275 | 24 | } |
276 | | /* lm20token */ |
277 | 261 | if (SVAL(ndr->data, ndr->data_size - 2) != 0xffff) { |
278 | 22 | return NDR_ERR_TOKEN; |
279 | 22 | } |
280 | | |
281 | 239 | r->ntver = IVAL(ndr->data, ndr->data_size - 8); |
282 | | |
283 | 239 | if (r->ntver == NETLOGON_NT_VERSION_1) { |
284 | 4 | NDR_CHECK(ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_NT40( |
285 | 4 | ndr, ndr_flags, &r->data.nt4)); |
286 | 235 | } else if (r->ntver & NETLOGON_NT_VERSION_5EX) { |
287 | 167 | NDR_CHECK(ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags( |
288 | 167 | ndr, ndr_flags, &r->data.nt5_ex, r->ntver)); |
289 | 79 | if (ndr->offset < ndr->data_size) { |
290 | 23 | return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES, |
291 | 23 | "not all bytes consumed ofs[%"PRIu32"] size[%"PRIu32"]", |
292 | 23 | ndr->offset, ndr->data_size); |
293 | 23 | } |
294 | 79 | } else if (r->ntver & NETLOGON_NT_VERSION_5) { |
295 | 50 | NDR_CHECK(ndr_pull_NETLOGON_SAM_LOGON_RESPONSE( |
296 | 50 | ndr, ndr_flags, &r->data.nt5)); |
297 | 50 | } else { |
298 | 18 | return NDR_ERR_BAD_SWITCH; |
299 | 18 | } |
300 | | |
301 | 74 | return NDR_ERR_SUCCESS; |
302 | 239 | } |
303 | | |
304 | | _PUBLIC_ void ndr_print_netlogon_samlogon_response(struct ndr_print *ndr, const char *name, const struct netlogon_samlogon_response *r) |
305 | 74 | { |
306 | 74 | ndr_print_struct(ndr, name, "netlogon_samlogon_response"); |
307 | 74 | if (r == NULL) { ndr_print_null(ndr); return; } |
308 | 74 | if (r->ntver == NETLOGON_NT_VERSION_1) { |
309 | 1 | ndr_print_NETLOGON_SAM_LOGON_RESPONSE_NT40(ndr, "data.nt4", &r->data.nt4); |
310 | 73 | } else if (r->ntver & NETLOGON_NT_VERSION_5EX) { |
311 | 56 | ndr_print_NETLOGON_SAM_LOGON_RESPONSE_EX(ndr, "data.nt5_ex", &r->data.nt5_ex); |
312 | 56 | } else if (r->ntver & NETLOGON_NT_VERSION_5) { |
313 | 17 | ndr_print_NETLOGON_SAM_LOGON_RESPONSE(ndr, "data.nt5", &r->data.nt5); |
314 | 17 | } |
315 | 74 | } |