1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * RPC Pipe client / server routines
|
---|
4 | * Copyright (C) Andrew Tridgell 1992-1997,
|
---|
5 | * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
|
---|
6 | * Copyright (C) Paul Ashton 1997.
|
---|
7 | * Copyright (C) Jeremy Allison 1999.
|
---|
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 2 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, write to the Free Software
|
---|
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "includes.h"
|
---|
25 |
|
---|
26 | #undef DBGC_CLASS
|
---|
27 | #define DBGC_CLASS DBGC_RPC_PARSE
|
---|
28 |
|
---|
29 | /*******************************************************************
|
---|
30 | interface/version dce/rpc pipe identification
|
---|
31 | ********************************************************************/
|
---|
32 |
|
---|
33 | #define TRANS_SYNT_V2 \
|
---|
34 | { \
|
---|
35 | { \
|
---|
36 | 0x8a885d04, 0x1ceb, 0x11c9, \
|
---|
37 | { 0x9f, 0xe8 }, \
|
---|
38 | { 0x08, 0x00, \
|
---|
39 | 0x2b, 0x10, 0x48, 0x60 } \
|
---|
40 | }, 0x02 \
|
---|
41 | }
|
---|
42 |
|
---|
43 | #define SYNT_NETLOGON_V2 \
|
---|
44 | { \
|
---|
45 | { \
|
---|
46 | 0x8a885d04, 0x1ceb, 0x11c9, \
|
---|
47 | { 0x9f, 0xe8 }, \
|
---|
48 | { 0x08, 0x00, \
|
---|
49 | 0x2b, 0x10, 0x48, 0x60 } \
|
---|
50 | }, 0x02 \
|
---|
51 | }
|
---|
52 |
|
---|
53 | #define SYNT_WKSSVC_V1 \
|
---|
54 | { \
|
---|
55 | { \
|
---|
56 | 0x6bffd098, 0xa112, 0x3610, \
|
---|
57 | { 0x98, 0x33 }, \
|
---|
58 | { 0x46, 0xc3, \
|
---|
59 | 0xf8, 0x7e, 0x34, 0x5a } \
|
---|
60 | }, 0x01 \
|
---|
61 | }
|
---|
62 |
|
---|
63 | #define SYNT_SRVSVC_V3 \
|
---|
64 | { \
|
---|
65 | { \
|
---|
66 | 0x4b324fc8, 0x1670, 0x01d3, \
|
---|
67 | { 0x12, 0x78 }, \
|
---|
68 | { 0x5a, 0x47, \
|
---|
69 | 0xbf, 0x6e, 0xe1, 0x88 } \
|
---|
70 | }, 0x03 \
|
---|
71 | }
|
---|
72 |
|
---|
73 | #define SYNT_LSARPC_V0 \
|
---|
74 | { \
|
---|
75 | { \
|
---|
76 | 0x12345778, 0x1234, 0xabcd, \
|
---|
77 | { 0xef, 0x00 }, \
|
---|
78 | { 0x01, 0x23, \
|
---|
79 | 0x45, 0x67, 0x89, 0xab } \
|
---|
80 | }, 0x00 \
|
---|
81 | }
|
---|
82 |
|
---|
83 | #define SYNT_LSARPC_V0_DS \
|
---|
84 | { \
|
---|
85 | { \
|
---|
86 | 0x3919286a, 0xb10c, 0x11d0, \
|
---|
87 | { 0x9b, 0xa8 }, \
|
---|
88 | { 0x00, 0xc0, \
|
---|
89 | 0x4f, 0xd9, 0x2e, 0xf5 } \
|
---|
90 | }, 0x00 \
|
---|
91 | }
|
---|
92 |
|
---|
93 | #define SYNT_SAMR_V1 \
|
---|
94 | { \
|
---|
95 | { \
|
---|
96 | 0x12345778, 0x1234, 0xabcd, \
|
---|
97 | { 0xef, 0x00 }, \
|
---|
98 | { 0x01, 0x23, \
|
---|
99 | 0x45, 0x67, 0x89, 0xac } \
|
---|
100 | }, 0x01 \
|
---|
101 | }
|
---|
102 |
|
---|
103 | #define SYNT_NETLOGON_V1 \
|
---|
104 | { \
|
---|
105 | { \
|
---|
106 | 0x12345678, 0x1234, 0xabcd, \
|
---|
107 | { 0xef, 0x00 }, \
|
---|
108 | { 0x01, 0x23, \
|
---|
109 | 0x45, 0x67, 0xcf, 0xfb } \
|
---|
110 | }, 0x01 \
|
---|
111 | }
|
---|
112 |
|
---|
113 | #define SYNT_WINREG_V1 \
|
---|
114 | { \
|
---|
115 | { \
|
---|
116 | 0x338cd001, 0x2244, 0x31f1, \
|
---|
117 | { 0xaa, 0xaa }, \
|
---|
118 | { 0x90, 0x00, \
|
---|
119 | 0x38, 0x00, 0x10, 0x03 } \
|
---|
120 | }, 0x01 \
|
---|
121 | }
|
---|
122 |
|
---|
123 | #define SYNT_SPOOLSS_V1 \
|
---|
124 | { \
|
---|
125 | { \
|
---|
126 | 0x12345678, 0x1234, 0xabcd, \
|
---|
127 | { 0xef, 0x00 }, \
|
---|
128 | { 0x01, 0x23, \
|
---|
129 | 0x45, 0x67, 0x89, 0xab } \
|
---|
130 | }, 0x01 \
|
---|
131 | }
|
---|
132 |
|
---|
133 | #define SYNT_NONE_V0 \
|
---|
134 | { \
|
---|
135 | { \
|
---|
136 | 0x0, 0x0, 0x0, \
|
---|
137 | { 0x00, 0x00 }, \
|
---|
138 | { 0x00, 0x00, \
|
---|
139 | 0x00, 0x00, 0x00, 0x00 } \
|
---|
140 | }, 0x00 \
|
---|
141 | }
|
---|
142 |
|
---|
143 | #define SYNT_NETDFS_V3 \
|
---|
144 | { \
|
---|
145 | { \
|
---|
146 | 0x4fc742e0, 0x4a10, 0x11cf, \
|
---|
147 | { 0x82, 0x73 }, \
|
---|
148 | { 0x00, 0xaa, \
|
---|
149 | 0x00, 0x4a, 0xe6, 0x73 } \
|
---|
150 | }, 0x03 \
|
---|
151 | }
|
---|
152 |
|
---|
153 | #define SYNT_ECHO_V1 \
|
---|
154 | { \
|
---|
155 | { \
|
---|
156 | 0x60a15ec5, 0x4de8, 0x11d7, \
|
---|
157 | { 0xa6, 0x37 }, \
|
---|
158 | { 0x00, 0x50, \
|
---|
159 | 0x56, 0xa2, 0x01, 0x82 } \
|
---|
160 | }, 0x01 \
|
---|
161 | }
|
---|
162 |
|
---|
163 | #define SYNT_SHUTDOWN_V1 \
|
---|
164 | { \
|
---|
165 | { \
|
---|
166 | 0x894de0c0, 0x0d55, 0x11d3, \
|
---|
167 | { 0xa3, 0x22 }, \
|
---|
168 | { 0x00, 0xc0, \
|
---|
169 | 0x4f, 0xa3, 0x21, 0xa1 } \
|
---|
170 | }, 0x01 \
|
---|
171 | }
|
---|
172 |
|
---|
173 | #define SYNT_SVCCTL_V2 \
|
---|
174 | { \
|
---|
175 | { \
|
---|
176 | 0x367abb81, 0x9844, 0x35f1, \
|
---|
177 | { 0xad, 0x32 }, \
|
---|
178 | { 0x98, 0xf0, \
|
---|
179 | 0x38, 0x00, 0x10, 0x03 } \
|
---|
180 | }, 0x02 \
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 | #define SYNT_EVENTLOG_V0 \
|
---|
185 | { \
|
---|
186 | { \
|
---|
187 | 0x82273fdc, 0xe32a, 0x18c3, \
|
---|
188 | { 0x3f, 0x78 }, \
|
---|
189 | { 0x82, 0x79, \
|
---|
190 | 0x29, 0xdc, 0x23, 0xea } \
|
---|
191 | }, 0x00 \
|
---|
192 | }
|
---|
193 |
|
---|
194 | #define SYNT_NTSVCS_V1 \
|
---|
195 | { \
|
---|
196 | { \
|
---|
197 | 0x8d9f4e40, 0xa03d, 0x11ce, \
|
---|
198 | { 0x8f, 0x69}, \
|
---|
199 | { 0x08, 0x00, \
|
---|
200 | 0x3e, 0x30, 0x05, 0x1b } \
|
---|
201 | }, 0x01 \
|
---|
202 | }
|
---|
203 |
|
---|
204 | /*
|
---|
205 | * IMPORTANT!! If you update this structure, make sure to
|
---|
206 | * update the index #defines in smb.h.
|
---|
207 | */
|
---|
208 |
|
---|
209 | const struct pipe_id_info pipe_names [] =
|
---|
210 | {
|
---|
211 | /* client pipe , abstract syntax , server pipe , transfer syntax */
|
---|
212 | { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 },
|
---|
213 | { PIPE_LSARPC , SYNT_LSARPC_V0_DS , PIPE_LSASS , TRANS_SYNT_V2 },
|
---|
214 | { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
|
---|
215 | { PIPE_NETLOGON, SYNT_NETLOGON_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
|
---|
216 | { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 },
|
---|
217 | { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
|
---|
218 | { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 },
|
---|
219 | { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 },
|
---|
220 | { PIPE_NETDFS , SYNT_NETDFS_V3 , PIPE_NETDFS , TRANS_SYNT_V2 },
|
---|
221 | { PIPE_ECHO , SYNT_ECHO_V1 , PIPE_ECHO , TRANS_SYNT_V2 },
|
---|
222 | { PIPE_SHUTDOWN, SYNT_SHUTDOWN_V1 , PIPE_SHUTDOWN , TRANS_SYNT_V2 },
|
---|
223 | { PIPE_SVCCTL , SYNT_SVCCTL_V2 , PIPE_NTSVCS , TRANS_SYNT_V2 },
|
---|
224 | { PIPE_EVENTLOG, SYNT_EVENTLOG_V0 , PIPE_EVENTLOG , TRANS_SYNT_V2 },
|
---|
225 | { PIPE_NTSVCS , SYNT_NTSVCS_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
|
---|
226 | { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }
|
---|
227 | };
|
---|
228 |
|
---|
229 | /****************************************************************************
|
---|
230 | Return the pipe name from the index.
|
---|
231 | ****************************************************************************/
|
---|
232 |
|
---|
233 | const char *cli_get_pipe_name(int pipe_idx)
|
---|
234 | {
|
---|
235 | return &pipe_names[pipe_idx].client_pipe[5];
|
---|
236 | }
|
---|
237 |
|
---|
238 | /*******************************************************************
|
---|
239 | Inits an RPC_HDR structure.
|
---|
240 | ********************************************************************/
|
---|
241 |
|
---|
242 | void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
|
---|
243 | uint32 call_id, int data_len, int auth_len)
|
---|
244 | {
|
---|
245 | hdr->major = 5; /* RPC version 5 */
|
---|
246 | hdr->minor = 0; /* minor version 0 */
|
---|
247 | hdr->pkt_type = pkt_type; /* RPC packet type */
|
---|
248 | hdr->flags = flags; /* dce/rpc flags */
|
---|
249 | hdr->pack_type[0] = 0x10; /* little-endian data representation */
|
---|
250 | hdr->pack_type[1] = 0; /* packed data representation */
|
---|
251 | hdr->pack_type[2] = 0; /* packed data representation */
|
---|
252 | hdr->pack_type[3] = 0; /* packed data representation */
|
---|
253 | hdr->frag_len = data_len; /* fragment length, fill in later */
|
---|
254 | hdr->auth_len = auth_len; /* authentication length */
|
---|
255 | hdr->call_id = call_id; /* call identifier - match incoming RPC */
|
---|
256 | }
|
---|
257 |
|
---|
258 | /*******************************************************************
|
---|
259 | Reads or writes an RPC_HDR structure.
|
---|
260 | ********************************************************************/
|
---|
261 |
|
---|
262 | BOOL smb_io_rpc_hdr(const char *desc, RPC_HDR *rpc, prs_struct *ps, int depth)
|
---|
263 | {
|
---|
264 | if (rpc == NULL)
|
---|
265 | return False;
|
---|
266 |
|
---|
267 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
|
---|
268 | depth++;
|
---|
269 |
|
---|
270 | if(!prs_uint8 ("major ", ps, depth, &rpc->major))
|
---|
271 | return False;
|
---|
272 |
|
---|
273 | if(!prs_uint8 ("minor ", ps, depth, &rpc->minor))
|
---|
274 | return False;
|
---|
275 | if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type))
|
---|
276 | return False;
|
---|
277 | if(!prs_uint8 ("flags ", ps, depth, &rpc->flags))
|
---|
278 | return False;
|
---|
279 |
|
---|
280 | /* We always marshall in little endian format. */
|
---|
281 | if (MARSHALLING(ps))
|
---|
282 | rpc->pack_type[0] = 0x10;
|
---|
283 |
|
---|
284 | if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
|
---|
285 | return False;
|
---|
286 | if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
|
---|
287 | return False;
|
---|
288 | if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
|
---|
289 | return False;
|
---|
290 | if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
|
---|
291 | return False;
|
---|
292 |
|
---|
293 | /*
|
---|
294 | * If reading and pack_type[0] == 0 then the data is in big-endian
|
---|
295 | * format. Set the flag in the prs_struct to specify reverse-endainness.
|
---|
296 | */
|
---|
297 |
|
---|
298 | if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
|
---|
299 | DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
|
---|
300 | prs_set_endian_data(ps, RPC_BIG_ENDIAN);
|
---|
301 | }
|
---|
302 |
|
---|
303 | if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len))
|
---|
304 | return False;
|
---|
305 | if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len))
|
---|
306 | return False;
|
---|
307 | if(!prs_uint32("call_id ", ps, depth, &rpc->call_id))
|
---|
308 | return False;
|
---|
309 | return True;
|
---|
310 | }
|
---|
311 |
|
---|
312 | /*******************************************************************
|
---|
313 | Reads or writes an RPC_IFACE structure.
|
---|
314 | ********************************************************************/
|
---|
315 |
|
---|
316 | static BOOL smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
|
---|
317 | {
|
---|
318 | if (ifc == NULL)
|
---|
319 | return False;
|
---|
320 |
|
---|
321 | prs_debug(ps, depth, desc, "smb_io_rpc_iface");
|
---|
322 | depth++;
|
---|
323 |
|
---|
324 | if (!prs_align(ps))
|
---|
325 | return False;
|
---|
326 |
|
---|
327 | if (!smb_io_uuid( "uuid", &ifc->uuid, ps, depth))
|
---|
328 | return False;
|
---|
329 |
|
---|
330 | if(!prs_uint32 ("version", ps, depth, &ifc->version))
|
---|
331 | return False;
|
---|
332 |
|
---|
333 | return True;
|
---|
334 | }
|
---|
335 |
|
---|
336 | /*******************************************************************
|
---|
337 | Inits an RPC_ADDR_STR structure.
|
---|
338 | ********************************************************************/
|
---|
339 |
|
---|
340 | static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name)
|
---|
341 | {
|
---|
342 | str->len = strlen(name) + 1;
|
---|
343 | fstrcpy(str->str, name);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /*******************************************************************
|
---|
347 | Reads or writes an RPC_ADDR_STR structure.
|
---|
348 | ********************************************************************/
|
---|
349 |
|
---|
350 | static BOOL smb_io_rpc_addr_str(const char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth)
|
---|
351 | {
|
---|
352 | if (str == NULL)
|
---|
353 | return False;
|
---|
354 |
|
---|
355 | prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
|
---|
356 | depth++;
|
---|
357 | if(!prs_align(ps))
|
---|
358 | return False;
|
---|
359 |
|
---|
360 | if(!prs_uint16 ( "len", ps, depth, &str->len))
|
---|
361 | return False;
|
---|
362 | if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
|
---|
363 | return False;
|
---|
364 | return True;
|
---|
365 | }
|
---|
366 |
|
---|
367 | /*******************************************************************
|
---|
368 | Inits an RPC_HDR_BBA structure.
|
---|
369 | ********************************************************************/
|
---|
370 |
|
---|
371 | static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
|
---|
372 | {
|
---|
373 | bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
|
---|
374 | bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
|
---|
375 | bba->assoc_gid = assoc_gid; /* associated group id (0x0) */
|
---|
376 | }
|
---|
377 |
|
---|
378 | /*******************************************************************
|
---|
379 | Reads or writes an RPC_HDR_BBA structure.
|
---|
380 | ********************************************************************/
|
---|
381 |
|
---|
382 | static BOOL smb_io_rpc_hdr_bba(const char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
|
---|
383 | {
|
---|
384 | if (rpc == NULL)
|
---|
385 | return False;
|
---|
386 |
|
---|
387 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
|
---|
388 | depth++;
|
---|
389 |
|
---|
390 | if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
|
---|
391 | return False;
|
---|
392 | if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
|
---|
393 | return False;
|
---|
394 | if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
|
---|
395 | return False;
|
---|
396 | return True;
|
---|
397 | }
|
---|
398 |
|
---|
399 | /*******************************************************************
|
---|
400 | Inits an RPC_CONTEXT structure.
|
---|
401 | Note the transfer pointer must remain valid until this is marshalled.
|
---|
402 | ********************************************************************/
|
---|
403 |
|
---|
404 | void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, RPC_IFACE *abstract, RPC_IFACE *transfer)
|
---|
405 | {
|
---|
406 | rpc_ctx->context_id = context_id ; /* presentation context identifier (0x0) */
|
---|
407 | rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */
|
---|
408 |
|
---|
409 | /* num and vers. of interface client is using */
|
---|
410 | rpc_ctx->abstract = *abstract;
|
---|
411 |
|
---|
412 | /* vers. of interface to use for replies */
|
---|
413 | rpc_ctx->transfer = transfer;
|
---|
414 | }
|
---|
415 |
|
---|
416 | /*******************************************************************
|
---|
417 | Inits an RPC_HDR_RB structure.
|
---|
418 | Note the context pointer must remain valid until this is marshalled.
|
---|
419 | ********************************************************************/
|
---|
420 |
|
---|
421 | void init_rpc_hdr_rb(RPC_HDR_RB *rpc,
|
---|
422 | uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
|
---|
423 | RPC_CONTEXT *context)
|
---|
424 | {
|
---|
425 | init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
|
---|
426 |
|
---|
427 | rpc->num_contexts = 1;
|
---|
428 | rpc->rpc_context = context;
|
---|
429 | }
|
---|
430 |
|
---|
431 | /*******************************************************************
|
---|
432 | Reads or writes an RPC_CONTEXT structure.
|
---|
433 | ********************************************************************/
|
---|
434 |
|
---|
435 | BOOL smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth)
|
---|
436 | {
|
---|
437 | int i;
|
---|
438 |
|
---|
439 | if (rpc_ctx == NULL)
|
---|
440 | return False;
|
---|
441 |
|
---|
442 | if(!prs_align(ps))
|
---|
443 | return False;
|
---|
444 | if(!prs_uint16("context_id ", ps, depth, &rpc_ctx->context_id ))
|
---|
445 | return False;
|
---|
446 | if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))
|
---|
447 | return False;
|
---|
448 |
|
---|
449 | /* num_transfer_syntaxes must not be zero. */
|
---|
450 | if (rpc_ctx->num_transfer_syntaxes == 0)
|
---|
451 | return False;
|
---|
452 |
|
---|
453 | if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))
|
---|
454 | return False;
|
---|
455 |
|
---|
456 | if (UNMARSHALLING(ps)) {
|
---|
457 | if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {
|
---|
458 | return False;
|
---|
459 | }
|
---|
460 | }
|
---|
461 |
|
---|
462 | for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {
|
---|
463 | if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))
|
---|
464 | return False;
|
---|
465 | }
|
---|
466 | return True;
|
---|
467 | }
|
---|
468 |
|
---|
469 | /*******************************************************************
|
---|
470 | Reads or writes an RPC_HDR_RB structure.
|
---|
471 | ********************************************************************/
|
---|
472 |
|
---|
473 | BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
|
---|
474 | {
|
---|
475 | int i;
|
---|
476 |
|
---|
477 | if (rpc == NULL)
|
---|
478 | return False;
|
---|
479 |
|
---|
480 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
|
---|
481 | depth++;
|
---|
482 |
|
---|
483 | if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
|
---|
484 | return False;
|
---|
485 |
|
---|
486 | if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts))
|
---|
487 | return False;
|
---|
488 |
|
---|
489 | /* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */
|
---|
490 |
|
---|
491 | /* num_contexts must not be zero. */
|
---|
492 | if (rpc->num_contexts == 0)
|
---|
493 | return False;
|
---|
494 |
|
---|
495 | if (UNMARSHALLING(ps)) {
|
---|
496 | if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {
|
---|
497 | return False;
|
---|
498 | }
|
---|
499 | }
|
---|
500 |
|
---|
501 | for (i = 0; i < rpc->num_contexts; i++ ) {
|
---|
502 | if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))
|
---|
503 | return False;
|
---|
504 | }
|
---|
505 |
|
---|
506 | return True;
|
---|
507 | }
|
---|
508 |
|
---|
509 | /*******************************************************************
|
---|
510 | Inits an RPC_RESULTS structure.
|
---|
511 |
|
---|
512 | lkclXXXX only one reason at the moment!
|
---|
513 | ********************************************************************/
|
---|
514 |
|
---|
515 | static void init_rpc_results(RPC_RESULTS *res,
|
---|
516 | uint8 num_results, uint16 result, uint16 reason)
|
---|
517 | {
|
---|
518 | res->num_results = num_results; /* the number of results (0x01) */
|
---|
519 | res->result = result ; /* result (0x00 = accept) */
|
---|
520 | res->reason = reason ; /* reason (0x00 = no reason specified) */
|
---|
521 | }
|
---|
522 |
|
---|
523 | /*******************************************************************
|
---|
524 | Reads or writes an RPC_RESULTS structure.
|
---|
525 |
|
---|
526 | lkclXXXX only one reason at the moment!
|
---|
527 | ********************************************************************/
|
---|
528 |
|
---|
529 | static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
|
---|
530 | {
|
---|
531 | if (res == NULL)
|
---|
532 | return False;
|
---|
533 |
|
---|
534 | prs_debug(ps, depth, desc, "smb_io_rpc_results");
|
---|
535 | depth++;
|
---|
536 |
|
---|
537 | if(!prs_align(ps))
|
---|
538 | return False;
|
---|
539 |
|
---|
540 | if(!prs_uint8 ("num_results", ps, depth, &res->num_results))
|
---|
541 | return False;
|
---|
542 |
|
---|
543 | if(!prs_align(ps))
|
---|
544 | return False;
|
---|
545 |
|
---|
546 | if(!prs_uint16("result ", ps, depth, &res->result))
|
---|
547 | return False;
|
---|
548 | if(!prs_uint16("reason ", ps, depth, &res->reason))
|
---|
549 | return False;
|
---|
550 | return True;
|
---|
551 | }
|
---|
552 |
|
---|
553 | /*******************************************************************
|
---|
554 | Init an RPC_HDR_BA structure.
|
---|
555 |
|
---|
556 | lkclXXXX only one reason at the moment!
|
---|
557 |
|
---|
558 | ********************************************************************/
|
---|
559 |
|
---|
560 | void init_rpc_hdr_ba(RPC_HDR_BA *rpc,
|
---|
561 | uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
|
---|
562 | const char *pipe_addr,
|
---|
563 | uint8 num_results, uint16 result, uint16 reason,
|
---|
564 | RPC_IFACE *transfer)
|
---|
565 | {
|
---|
566 | init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
|
---|
567 | init_rpc_addr_str(&rpc->addr, pipe_addr);
|
---|
568 | init_rpc_results (&rpc->res, num_results, result, reason);
|
---|
569 |
|
---|
570 | /* the transfer syntax from the request */
|
---|
571 | memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
|
---|
572 | }
|
---|
573 |
|
---|
574 | /*******************************************************************
|
---|
575 | Reads or writes an RPC_HDR_BA structure.
|
---|
576 | ********************************************************************/
|
---|
577 |
|
---|
578 | BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
|
---|
579 | {
|
---|
580 | if (rpc == NULL)
|
---|
581 | return False;
|
---|
582 |
|
---|
583 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
|
---|
584 | depth++;
|
---|
585 |
|
---|
586 | if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
|
---|
587 | return False;
|
---|
588 | if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
|
---|
589 | return False;
|
---|
590 | if(!smb_io_rpc_results("", &rpc->res, ps, depth))
|
---|
591 | return False;
|
---|
592 | if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
|
---|
593 | return False;
|
---|
594 | return True;
|
---|
595 | }
|
---|
596 |
|
---|
597 | /*******************************************************************
|
---|
598 | Init an RPC_HDR_REQ structure.
|
---|
599 | ********************************************************************/
|
---|
600 |
|
---|
601 | void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
|
---|
602 | {
|
---|
603 | hdr->alloc_hint = alloc_hint; /* allocation hint */
|
---|
604 | hdr->context_id = 0; /* presentation context identifier */
|
---|
605 | hdr->opnum = opnum; /* opnum */
|
---|
606 | }
|
---|
607 |
|
---|
608 | /*******************************************************************
|
---|
609 | Reads or writes an RPC_HDR_REQ structure.
|
---|
610 | ********************************************************************/
|
---|
611 |
|
---|
612 | BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
|
---|
613 | {
|
---|
614 | if (rpc == NULL)
|
---|
615 | return False;
|
---|
616 |
|
---|
617 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
|
---|
618 | depth++;
|
---|
619 |
|
---|
620 | if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
|
---|
621 | return False;
|
---|
622 | if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
|
---|
623 | return False;
|
---|
624 | if(!prs_uint16("opnum ", ps, depth, &rpc->opnum))
|
---|
625 | return False;
|
---|
626 | return True;
|
---|
627 | }
|
---|
628 |
|
---|
629 | /*******************************************************************
|
---|
630 | Reads or writes an RPC_HDR_RESP structure.
|
---|
631 | ********************************************************************/
|
---|
632 |
|
---|
633 | BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
|
---|
634 | {
|
---|
635 | if (rpc == NULL)
|
---|
636 | return False;
|
---|
637 |
|
---|
638 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
|
---|
639 | depth++;
|
---|
640 |
|
---|
641 | if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
|
---|
642 | return False;
|
---|
643 | if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
|
---|
644 | return False;
|
---|
645 | if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
|
---|
646 | return False;
|
---|
647 | if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved))
|
---|
648 | return False;
|
---|
649 | return True;
|
---|
650 | }
|
---|
651 |
|
---|
652 | /*******************************************************************
|
---|
653 | Reads or writes an RPC_HDR_FAULT structure.
|
---|
654 | ********************************************************************/
|
---|
655 |
|
---|
656 | BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
|
---|
657 | {
|
---|
658 | if (rpc == NULL)
|
---|
659 | return False;
|
---|
660 |
|
---|
661 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
|
---|
662 | depth++;
|
---|
663 |
|
---|
664 | if(!prs_dcerpc_status("status ", ps, depth, &rpc->status))
|
---|
665 | return False;
|
---|
666 | if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
|
---|
667 | return False;
|
---|
668 |
|
---|
669 | return True;
|
---|
670 | }
|
---|
671 |
|
---|
672 | /*******************************************************************
|
---|
673 | Inits an RPC_HDR_AUTH structure.
|
---|
674 | ********************************************************************/
|
---|
675 |
|
---|
676 | void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
|
---|
677 | uint8 auth_type, uint8 auth_level,
|
---|
678 | uint8 auth_pad_len,
|
---|
679 | uint32 auth_context_id)
|
---|
680 | {
|
---|
681 | rai->auth_type = auth_type;
|
---|
682 | rai->auth_level = auth_level;
|
---|
683 | rai->auth_pad_len = auth_pad_len;
|
---|
684 | rai->auth_reserved = 0;
|
---|
685 | rai->auth_context_id = auth_context_id;
|
---|
686 | }
|
---|
687 |
|
---|
688 | /*******************************************************************
|
---|
689 | Reads or writes an RPC_HDR_AUTH structure.
|
---|
690 | ********************************************************************/
|
---|
691 |
|
---|
692 | BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
|
---|
693 | {
|
---|
694 | if (rai == NULL)
|
---|
695 | return False;
|
---|
696 |
|
---|
697 | prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
|
---|
698 | depth++;
|
---|
699 |
|
---|
700 | if(!prs_align(ps))
|
---|
701 | return False;
|
---|
702 |
|
---|
703 | if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type))
|
---|
704 | return False;
|
---|
705 | if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level))
|
---|
706 | return False;
|
---|
707 | if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len))
|
---|
708 | return False;
|
---|
709 | if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved))
|
---|
710 | return False;
|
---|
711 | if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id))
|
---|
712 | return False;
|
---|
713 |
|
---|
714 | return True;
|
---|
715 | }
|
---|
716 |
|
---|
717 | /*******************************************************************
|
---|
718 | Checks an RPC_AUTH_VERIFIER structure.
|
---|
719 | ********************************************************************/
|
---|
720 |
|
---|
721 | BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
|
---|
722 | const char *signature, uint32 msg_type)
|
---|
723 | {
|
---|
724 | return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
|
---|
725 | }
|
---|
726 |
|
---|
727 | /*******************************************************************
|
---|
728 | Inits an RPC_AUTH_VERIFIER structure.
|
---|
729 | ********************************************************************/
|
---|
730 |
|
---|
731 | void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
|
---|
732 | const char *signature, uint32 msg_type)
|
---|
733 | {
|
---|
734 | fstrcpy(rav->signature, signature); /* "NTLMSSP" */
|
---|
735 | rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
|
---|
736 | }
|
---|
737 |
|
---|
738 | /*******************************************************************
|
---|
739 | Reads or writes an RPC_AUTH_VERIFIER structure.
|
---|
740 | ********************************************************************/
|
---|
741 |
|
---|
742 | BOOL smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
|
---|
743 | {
|
---|
744 | if (rav == NULL)
|
---|
745 | return False;
|
---|
746 |
|
---|
747 | prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
|
---|
748 | depth++;
|
---|
749 |
|
---|
750 | /* "NTLMSSP" */
|
---|
751 | if(!prs_string("signature", ps, depth, rav->signature,
|
---|
752 | sizeof(rav->signature)))
|
---|
753 | return False;
|
---|
754 | if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
|
---|
755 | return False;
|
---|
756 |
|
---|
757 | return True;
|
---|
758 | }
|
---|
759 |
|
---|
760 | /*******************************************************************
|
---|
761 | This parses an RPC_AUTH_VERIFIER for schannel. I think
|
---|
762 | ********************************************************************/
|
---|
763 |
|
---|
764 | BOOL smb_io_rpc_schannel_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
|
---|
765 | {
|
---|
766 | if (rav == NULL)
|
---|
767 | return False;
|
---|
768 |
|
---|
769 | prs_debug(ps, depth, desc, "smb_io_rpc_schannel_verifier");
|
---|
770 | depth++;
|
---|
771 |
|
---|
772 | if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
|
---|
773 | return False;
|
---|
774 | if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
|
---|
775 | return False;
|
---|
776 |
|
---|
777 | return True;
|
---|
778 | }
|
---|
779 |
|
---|
780 | /*******************************************************************
|
---|
781 | creates an RPC_AUTH_SCHANNEL_NEG structure.
|
---|
782 | ********************************************************************/
|
---|
783 |
|
---|
784 | void init_rpc_auth_schannel_neg(RPC_AUTH_SCHANNEL_NEG *neg,
|
---|
785 | const char *domain, const char *myname)
|
---|
786 | {
|
---|
787 | neg->type1 = 0;
|
---|
788 | neg->type2 = 0x3;
|
---|
789 | fstrcpy(neg->domain, domain);
|
---|
790 | fstrcpy(neg->myname, myname);
|
---|
791 | }
|
---|
792 |
|
---|
793 | /*******************************************************************
|
---|
794 | Reads or writes an RPC_AUTH_SCHANNEL_NEG structure.
|
---|
795 | ********************************************************************/
|
---|
796 |
|
---|
797 | BOOL smb_io_rpc_auth_schannel_neg(const char *desc, RPC_AUTH_SCHANNEL_NEG *neg,
|
---|
798 | prs_struct *ps, int depth)
|
---|
799 | {
|
---|
800 | if (neg == NULL)
|
---|
801 | return False;
|
---|
802 |
|
---|
803 | prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_neg");
|
---|
804 | depth++;
|
---|
805 |
|
---|
806 | if(!prs_align(ps))
|
---|
807 | return False;
|
---|
808 |
|
---|
809 | if(!prs_uint32("type1", ps, depth, &neg->type1))
|
---|
810 | return False;
|
---|
811 | if(!prs_uint32("type2", ps, depth, &neg->type2))
|
---|
812 | return False;
|
---|
813 | if(!prs_string("domain ", ps, depth, neg->domain, sizeof(neg->domain)))
|
---|
814 | return False;
|
---|
815 | if(!prs_string("myname ", ps, depth, neg->myname, sizeof(neg->myname)))
|
---|
816 | return False;
|
---|
817 |
|
---|
818 | return True;
|
---|
819 | }
|
---|
820 |
|
---|
821 | /*******************************************************************
|
---|
822 | reads or writes an RPC_AUTH_SCHANNEL_CHK structure.
|
---|
823 | ********************************************************************/
|
---|
824 |
|
---|
825 | BOOL smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len,
|
---|
826 | RPC_AUTH_SCHANNEL_CHK * chk,
|
---|
827 | prs_struct *ps, int depth)
|
---|
828 | {
|
---|
829 | if (chk == NULL)
|
---|
830 | return False;
|
---|
831 |
|
---|
832 | prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_chk");
|
---|
833 | depth++;
|
---|
834 |
|
---|
835 | if ( !prs_uint8s(False, "sig ", ps, depth, chk->sig, sizeof(chk->sig)) )
|
---|
836 | return False;
|
---|
837 |
|
---|
838 | if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )
|
---|
839 | return False;
|
---|
840 |
|
---|
841 | if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )
|
---|
842 | return False;
|
---|
843 |
|
---|
844 | if ( auth_len == RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ) {
|
---|
845 | if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )
|
---|
846 | return False;
|
---|
847 | }
|
---|
848 |
|
---|
849 | return True;
|
---|
850 | }
|
---|