r22704: Implement three step method for enumerating domain trusts.
[Samba.git] / source / rpc_parse / parse_rpc.c
blob39156d5ef8d387bcfe800fb2aff08f3367d741a4
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.
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.
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.
24 #include "includes.h"
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_RPC_PARSE
29 /*******************************************************************
30 interface/version dce/rpc pipe identification
31 ********************************************************************/
33 #define TRANS_SYNT_V2 \
34 { \
35 { \
36 0x8a885d04, 0x1ceb, 0x11c9, \
37 { 0x9f, 0xe8 }, \
38 { 0x08, 0x00, \
39 0x2b, 0x10, 0x48, 0x60 } \
40 }, 0x02 \
43 #define SYNT_NETLOGON_V2 \
44 { \
45 { \
46 0x8a885d04, 0x1ceb, 0x11c9, \
47 { 0x9f, 0xe8 }, \
48 { 0x08, 0x00, \
49 0x2b, 0x10, 0x48, 0x60 } \
50 }, 0x02 \
53 #define SYNT_WKSSVC_V1 \
54 { \
55 { \
56 0x6bffd098, 0xa112, 0x3610, \
57 { 0x98, 0x33 }, \
58 { 0x46, 0xc3, \
59 0xf8, 0x7e, 0x34, 0x5a } \
60 }, 0x01 \
63 #define SYNT_SRVSVC_V3 \
64 { \
65 { \
66 0x4b324fc8, 0x1670, 0x01d3, \
67 { 0x12, 0x78 }, \
68 { 0x5a, 0x47, \
69 0xbf, 0x6e, 0xe1, 0x88 } \
70 }, 0x03 \
73 #define SYNT_LSARPC_V0 \
74 { \
75 { \
76 0x12345778, 0x1234, 0xabcd, \
77 { 0xef, 0x00 }, \
78 { 0x01, 0x23, \
79 0x45, 0x67, 0x89, 0xab } \
80 }, 0x00 \
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 \
93 #define SYNT_SAMR_V1 \
94 { \
95 { \
96 0x12345778, 0x1234, 0xabcd, \
97 { 0xef, 0x00 }, \
98 { 0x01, 0x23, \
99 0x45, 0x67, 0x89, 0xac } \
100 }, 0x01 \
103 #define SYNT_NETLOGON_V1 \
106 0x12345678, 0x1234, 0xabcd, \
107 { 0xef, 0x00 }, \
108 { 0x01, 0x23, \
109 0x45, 0x67, 0xcf, 0xfb } \
110 }, 0x01 \
113 #define SYNT_WINREG_V1 \
116 0x338cd001, 0x2244, 0x31f1, \
117 { 0xaa, 0xaa }, \
118 { 0x90, 0x00, \
119 0x38, 0x00, 0x10, 0x03 } \
120 }, 0x01 \
123 #define SYNT_SPOOLSS_V1 \
126 0x12345678, 0x1234, 0xabcd, \
127 { 0xef, 0x00 }, \
128 { 0x01, 0x23, \
129 0x45, 0x67, 0x89, 0xab } \
130 }, 0x01 \
133 #define SYNT_NONE_V0 \
136 0x0, 0x0, 0x0, \
137 { 0x00, 0x00 }, \
138 { 0x00, 0x00, \
139 0x00, 0x00, 0x00, 0x00 } \
140 }, 0x00 \
143 #define SYNT_NETDFS_V3 \
146 0x4fc742e0, 0x4a10, 0x11cf, \
147 { 0x82, 0x73 }, \
148 { 0x00, 0xaa, \
149 0x00, 0x4a, 0xe6, 0x73 } \
150 }, 0x03 \
153 #define SYNT_ECHO_V1 \
156 0x60a15ec5, 0x4de8, 0x11d7, \
157 { 0xa6, 0x37 }, \
158 { 0x00, 0x50, \
159 0x56, 0xa2, 0x01, 0x82 } \
160 }, 0x01 \
163 #define SYNT_SHUTDOWN_V1 \
166 0x894de0c0, 0x0d55, 0x11d3, \
167 { 0xa3, 0x22 }, \
168 { 0x00, 0xc0, \
169 0x4f, 0xa3, 0x21, 0xa1 } \
170 }, 0x01 \
173 #define SYNT_SVCCTL_V2 \
176 0x367abb81, 0x9844, 0x35f1, \
177 { 0xad, 0x32 }, \
178 { 0x98, 0xf0, \
179 0x38, 0x00, 0x10, 0x03 } \
180 }, 0x02 \
184 #define SYNT_EVENTLOG_V0 \
187 0x82273fdc, 0xe32a, 0x18c3, \
188 { 0x3f, 0x78 }, \
189 { 0x82, 0x79, \
190 0x29, 0xdc, 0x23, 0xea } \
191 }, 0x00 \
194 #define SYNT_UNIXINFO_V0 \
197 0x9c54e310, 0xa955, 0x4885, \
198 { 0xbd, 0x31 }, \
199 { 0x78, 0x78, \
200 0x71, 0x47, 0xdf, 0xa6 } \
201 }, 0x00 \
204 #define SYNT_NTSVCS_V1 \
207 0x8d9f4e40, 0xa03d, 0x11ce, \
208 { 0x8f, 0x69}, \
209 { 0x08, 0x00, \
210 0x3e, 0x30, 0x05, 0x1b } \
211 }, 0x01 \
214 #define SYNT_EPMAPPER_V3 \
217 0xe1af8308, 0x5d1f,0x11c9, \
218 { 0x91,0xa4}, \
219 {0x08,0x00, \
220 0x2b,0x14,0xa0,0xfa} \
221 }, 0x03 \
225 * IMPORTANT!! If you update this structure, make sure to
226 * update the index #defines in smb.h.
229 const struct pipe_id_info pipe_names [] =
231 /* client pipe , abstract syntax , server pipe , transfer syntax */
232 { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 },
233 { PIPE_LSARPC , SYNT_LSARPC_V0_DS , PIPE_LSASS , TRANS_SYNT_V2 },
234 { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
235 { PIPE_NETLOGON, SYNT_NETLOGON_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
236 { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 },
237 { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
238 { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 },
239 { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 },
240 { PIPE_NETDFS , SYNT_NETDFS_V3 , PIPE_NETDFS , TRANS_SYNT_V2 },
241 { PIPE_ECHO , SYNT_ECHO_V1 , PIPE_ECHO , TRANS_SYNT_V2 },
242 { PIPE_SHUTDOWN, SYNT_SHUTDOWN_V1 , PIPE_SHUTDOWN , TRANS_SYNT_V2 },
243 { PIPE_SVCCTL , SYNT_SVCCTL_V2 , PIPE_NTSVCS , TRANS_SYNT_V2 },
244 { PIPE_EVENTLOG, SYNT_EVENTLOG_V0 , PIPE_EVENTLOG , TRANS_SYNT_V2 },
245 { PIPE_UNIXINFO, SYNT_UNIXINFO_V0 , PIPE_UNIXINFO , TRANS_SYNT_V2 },
246 { PIPE_NTSVCS , SYNT_NTSVCS_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
247 { PIPE_EPMAPPER, SYNT_EPMAPPER_V3 , PIPE_EPMAPPER , TRANS_SYNT_V2 },
248 { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }
251 /****************************************************************************
252 Return the pipe name from the index.
253 ****************************************************************************/
255 const char *cli_get_pipe_name(int pipe_idx)
257 return &pipe_names[pipe_idx].client_pipe[5];
260 /*******************************************************************
261 Inits an RPC_HDR structure.
262 ********************************************************************/
264 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
265 uint32 call_id, int data_len, int auth_len)
267 hdr->major = 5; /* RPC version 5 */
268 hdr->minor = 0; /* minor version 0 */
269 hdr->pkt_type = pkt_type; /* RPC packet type */
270 hdr->flags = flags; /* dce/rpc flags */
271 hdr->pack_type[0] = 0x10; /* little-endian data representation */
272 hdr->pack_type[1] = 0; /* packed data representation */
273 hdr->pack_type[2] = 0; /* packed data representation */
274 hdr->pack_type[3] = 0; /* packed data representation */
275 hdr->frag_len = data_len; /* fragment length, fill in later */
276 hdr->auth_len = auth_len; /* authentication length */
277 hdr->call_id = call_id; /* call identifier - match incoming RPC */
280 /*******************************************************************
281 Reads or writes an RPC_HDR structure.
282 ********************************************************************/
284 BOOL smb_io_rpc_hdr(const char *desc, RPC_HDR *rpc, prs_struct *ps, int depth)
286 if (rpc == NULL)
287 return False;
289 prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
290 depth++;
292 if(!prs_uint8 ("major ", ps, depth, &rpc->major))
293 return False;
295 if(!prs_uint8 ("minor ", ps, depth, &rpc->minor))
296 return False;
297 if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type))
298 return False;
299 if(!prs_uint8 ("flags ", ps, depth, &rpc->flags))
300 return False;
302 /* We always marshall in little endian format. */
303 if (MARSHALLING(ps))
304 rpc->pack_type[0] = 0x10;
306 if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
307 return False;
308 if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
309 return False;
310 if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
311 return False;
312 if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
313 return False;
316 * If reading and pack_type[0] == 0 then the data is in big-endian
317 * format. Set the flag in the prs_struct to specify reverse-endainness.
320 if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
321 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
322 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
325 if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len))
326 return False;
327 if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len))
328 return False;
329 if(!prs_uint32("call_id ", ps, depth, &rpc->call_id))
330 return False;
331 return True;
334 /*******************************************************************
335 Reads or writes an RPC_IFACE structure.
336 ********************************************************************/
338 static BOOL smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
340 if (ifc == NULL)
341 return False;
343 prs_debug(ps, depth, desc, "smb_io_rpc_iface");
344 depth++;
346 if (!prs_align(ps))
347 return False;
349 if (!smb_io_uuid( "uuid", &ifc->uuid, ps, depth))
350 return False;
352 if(!prs_uint32 ("version", ps, depth, &ifc->version))
353 return False;
355 return True;
358 /*******************************************************************
359 Inits an RPC_ADDR_STR structure.
360 ********************************************************************/
362 static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name)
364 str->len = strlen(name) + 1;
365 fstrcpy(str->str, name);
368 /*******************************************************************
369 Reads or writes an RPC_ADDR_STR structure.
370 ********************************************************************/
372 static BOOL smb_io_rpc_addr_str(const char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth)
374 if (str == NULL)
375 return False;
377 prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
378 depth++;
379 if(!prs_align(ps))
380 return False;
382 if(!prs_uint16 ( "len", ps, depth, &str->len))
383 return False;
384 if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
385 return False;
386 return True;
389 /*******************************************************************
390 Inits an RPC_HDR_BBA structure.
391 ********************************************************************/
393 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
395 bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
396 bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
397 bba->assoc_gid = assoc_gid; /* associated group id (0x0) */
400 /*******************************************************************
401 Reads or writes an RPC_HDR_BBA structure.
402 ********************************************************************/
404 static BOOL smb_io_rpc_hdr_bba(const char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
406 if (rpc == NULL)
407 return False;
409 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
410 depth++;
412 if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
413 return False;
414 if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
415 return False;
416 if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
417 return False;
418 return True;
421 /*******************************************************************
422 Inits an RPC_CONTEXT structure.
423 Note the transfer pointer must remain valid until this is marshalled.
424 ********************************************************************/
426 void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, RPC_IFACE *abstract, RPC_IFACE *transfer)
428 rpc_ctx->context_id = context_id ; /* presentation context identifier (0x0) */
429 rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */
431 /* num and vers. of interface client is using */
432 rpc_ctx->abstract = *abstract;
434 /* vers. of interface to use for replies */
435 rpc_ctx->transfer = transfer;
438 /*******************************************************************
439 Inits an RPC_HDR_RB structure.
440 Note the context pointer must remain valid until this is marshalled.
441 ********************************************************************/
443 void init_rpc_hdr_rb(RPC_HDR_RB *rpc,
444 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
445 RPC_CONTEXT *context)
447 init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
449 rpc->num_contexts = 1;
450 rpc->rpc_context = context;
453 /*******************************************************************
454 Reads or writes an RPC_CONTEXT structure.
455 ********************************************************************/
457 BOOL smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth)
459 int i;
461 if (rpc_ctx == NULL)
462 return False;
464 if(!prs_align(ps))
465 return False;
466 if(!prs_uint16("context_id ", ps, depth, &rpc_ctx->context_id ))
467 return False;
468 if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))
469 return False;
471 /* num_transfer_syntaxes must not be zero. */
472 if (rpc_ctx->num_transfer_syntaxes == 0)
473 return False;
475 if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))
476 return False;
478 if (UNMARSHALLING(ps)) {
479 if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {
480 return False;
484 for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {
485 if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))
486 return False;
488 return True;
491 /*******************************************************************
492 Reads or writes an RPC_HDR_RB structure.
493 ********************************************************************/
495 BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
497 int i;
499 if (rpc == NULL)
500 return False;
502 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
503 depth++;
505 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
506 return False;
508 if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts))
509 return False;
511 /* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */
513 /* num_contexts must not be zero. */
514 if (rpc->num_contexts == 0)
515 return False;
517 if (UNMARSHALLING(ps)) {
518 if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {
519 return False;
523 for (i = 0; i < rpc->num_contexts; i++ ) {
524 if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))
525 return False;
528 return True;
531 /*******************************************************************
532 Inits an RPC_RESULTS structure.
534 lkclXXXX only one reason at the moment!
535 ********************************************************************/
537 static void init_rpc_results(RPC_RESULTS *res,
538 uint8 num_results, uint16 result, uint16 reason)
540 res->num_results = num_results; /* the number of results (0x01) */
541 res->result = result ; /* result (0x00 = accept) */
542 res->reason = reason ; /* reason (0x00 = no reason specified) */
545 /*******************************************************************
546 Reads or writes an RPC_RESULTS structure.
548 lkclXXXX only one reason at the moment!
549 ********************************************************************/
551 static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
553 if (res == NULL)
554 return False;
556 prs_debug(ps, depth, desc, "smb_io_rpc_results");
557 depth++;
559 if(!prs_align(ps))
560 return False;
562 if(!prs_uint8 ("num_results", ps, depth, &res->num_results))
563 return False;
565 if(!prs_align(ps))
566 return False;
568 if(!prs_uint16("result ", ps, depth, &res->result))
569 return False;
570 if(!prs_uint16("reason ", ps, depth, &res->reason))
571 return False;
572 return True;
575 /*******************************************************************
576 Init an RPC_HDR_BA structure.
578 lkclXXXX only one reason at the moment!
580 ********************************************************************/
582 void init_rpc_hdr_ba(RPC_HDR_BA *rpc,
583 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
584 const char *pipe_addr,
585 uint8 num_results, uint16 result, uint16 reason,
586 RPC_IFACE *transfer)
588 init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
589 init_rpc_addr_str(&rpc->addr, pipe_addr);
590 init_rpc_results (&rpc->res, num_results, result, reason);
592 /* the transfer syntax from the request */
593 memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
596 /*******************************************************************
597 Reads or writes an RPC_HDR_BA structure.
598 ********************************************************************/
600 BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
602 if (rpc == NULL)
603 return False;
605 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
606 depth++;
608 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
609 return False;
610 if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
611 return False;
612 if(!smb_io_rpc_results("", &rpc->res, ps, depth))
613 return False;
614 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
615 return False;
616 return True;
619 /*******************************************************************
620 Init an RPC_HDR_REQ structure.
621 ********************************************************************/
623 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
625 hdr->alloc_hint = alloc_hint; /* allocation hint */
626 hdr->context_id = 0; /* presentation context identifier */
627 hdr->opnum = opnum; /* opnum */
630 /*******************************************************************
631 Reads or writes an RPC_HDR_REQ structure.
632 ********************************************************************/
634 BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
636 if (rpc == NULL)
637 return False;
639 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
640 depth++;
642 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
643 return False;
644 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
645 return False;
646 if(!prs_uint16("opnum ", ps, depth, &rpc->opnum))
647 return False;
648 return True;
651 /*******************************************************************
652 Reads or writes an RPC_HDR_RESP structure.
653 ********************************************************************/
655 BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
657 if (rpc == NULL)
658 return False;
660 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
661 depth++;
663 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
664 return False;
665 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
666 return False;
667 if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
668 return False;
669 if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved))
670 return False;
671 return True;
674 /*******************************************************************
675 Reads or writes an RPC_HDR_FAULT structure.
676 ********************************************************************/
678 BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
680 if (rpc == NULL)
681 return False;
683 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
684 depth++;
686 if(!prs_dcerpc_status("status ", ps, depth, &rpc->status))
687 return False;
688 if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
689 return False;
691 return True;
694 /*******************************************************************
695 Inits an RPC_HDR_AUTH structure.
696 ********************************************************************/
698 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
699 uint8 auth_type, uint8 auth_level,
700 uint8 auth_pad_len,
701 uint32 auth_context_id)
703 rai->auth_type = auth_type;
704 rai->auth_level = auth_level;
705 rai->auth_pad_len = auth_pad_len;
706 rai->auth_reserved = 0;
707 rai->auth_context_id = auth_context_id;
710 /*******************************************************************
711 Reads or writes an RPC_HDR_AUTH structure.
712 ********************************************************************/
714 BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
716 if (rai == NULL)
717 return False;
719 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
720 depth++;
722 if(!prs_align(ps))
723 return False;
725 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type))
726 return False;
727 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level))
728 return False;
729 if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len))
730 return False;
731 if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved))
732 return False;
733 if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id))
734 return False;
736 return True;
739 /*******************************************************************
740 Checks an RPC_AUTH_VERIFIER structure.
741 ********************************************************************/
743 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
744 const char *signature, uint32 msg_type)
746 return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
749 /*******************************************************************
750 Inits an RPC_AUTH_VERIFIER structure.
751 ********************************************************************/
753 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
754 const char *signature, uint32 msg_type)
756 fstrcpy(rav->signature, signature); /* "NTLMSSP" */
757 rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
760 /*******************************************************************
761 Reads or writes an RPC_AUTH_VERIFIER structure.
762 ********************************************************************/
764 BOOL smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
766 if (rav == NULL)
767 return False;
769 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
770 depth++;
772 /* "NTLMSSP" */
773 if(!prs_string("signature", ps, depth, rav->signature,
774 sizeof(rav->signature)))
775 return False;
776 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
777 return False;
779 return True;
782 /*******************************************************************
783 This parses an RPC_AUTH_VERIFIER for schannel. I think
784 ********************************************************************/
786 BOOL smb_io_rpc_schannel_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
788 if (rav == NULL)
789 return False;
791 prs_debug(ps, depth, desc, "smb_io_rpc_schannel_verifier");
792 depth++;
794 if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
795 return False;
796 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
797 return False;
799 return True;
802 /*******************************************************************
803 creates an RPC_AUTH_SCHANNEL_NEG structure.
804 ********************************************************************/
806 void init_rpc_auth_schannel_neg(RPC_AUTH_SCHANNEL_NEG *neg,
807 const char *domain, const char *myname)
809 neg->type1 = 0;
810 neg->type2 = 0x3;
811 fstrcpy(neg->domain, domain);
812 fstrcpy(neg->myname, myname);
815 /*******************************************************************
816 Reads or writes an RPC_AUTH_SCHANNEL_NEG structure.
817 ********************************************************************/
819 BOOL smb_io_rpc_auth_schannel_neg(const char *desc, RPC_AUTH_SCHANNEL_NEG *neg,
820 prs_struct *ps, int depth)
822 if (neg == NULL)
823 return False;
825 prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_neg");
826 depth++;
828 if(!prs_align(ps))
829 return False;
831 if(!prs_uint32("type1", ps, depth, &neg->type1))
832 return False;
833 if(!prs_uint32("type2", ps, depth, &neg->type2))
834 return False;
835 if(!prs_string("domain ", ps, depth, neg->domain, sizeof(neg->domain)))
836 return False;
837 if(!prs_string("myname ", ps, depth, neg->myname, sizeof(neg->myname)))
838 return False;
840 return True;
843 /*******************************************************************
844 reads or writes an RPC_AUTH_SCHANNEL_CHK structure.
845 ********************************************************************/
847 BOOL smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len,
848 RPC_AUTH_SCHANNEL_CHK * chk,
849 prs_struct *ps, int depth)
851 if (chk == NULL)
852 return False;
854 prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_chk");
855 depth++;
857 if ( !prs_uint8s(False, "sig ", ps, depth, chk->sig, sizeof(chk->sig)) )
858 return False;
860 if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )
861 return False;
863 if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )
864 return False;
866 if ( auth_len == RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ) {
867 if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )
868 return False;
871 return True;