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.
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.
27 #define DBGC_CLASS DBGC_RPC_PARSE
29 /*******************************************************************
30 interface/version dce/rpc pipe identification
31 ********************************************************************/
33 #define TRANS_SYNT_V2 \
36 0x8a885d04, 0x1ceb, 0x11c9, \
39 0x2b, 0x10, 0x48, 0x60 } \
43 #define SYNT_NETLOGON_V2 \
46 0x8a885d04, 0x1ceb, 0x11c9, \
49 0x2b, 0x10, 0x48, 0x60 } \
53 #define SYNT_WKSSVC_V1 \
56 0x6bffd098, 0xa112, 0x3610, \
59 0xf8, 0x7e, 0x34, 0x5a } \
63 #define SYNT_SRVSVC_V3 \
66 0x4b324fc8, 0x1670, 0x01d3, \
69 0xbf, 0x6e, 0xe1, 0x88 } \
73 #define SYNT_LSARPC_V0 \
76 0x12345778, 0x1234, 0xabcd, \
79 0x45, 0x67, 0x89, 0xab } \
83 #define SYNT_LSARPC_V0_DS \
86 0x3919286a, 0xb10c, 0x11d0, \
89 0x4f, 0xd9, 0x2e, 0xf5 } \
93 #define SYNT_SAMR_V1 \
96 0x12345778, 0x1234, 0xabcd, \
99 0x45, 0x67, 0x89, 0xac } \
103 #define SYNT_NETLOGON_V1 \
106 0x12345678, 0x1234, 0xabcd, \
109 0x45, 0x67, 0xcf, 0xfb } \
113 #define SYNT_WINREG_V1 \
116 0x338cd001, 0x2244, 0x31f1, \
119 0x38, 0x00, 0x10, 0x03 } \
123 #define SYNT_SPOOLSS_V1 \
126 0x12345678, 0x1234, 0xabcd, \
129 0x45, 0x67, 0x89, 0xab } \
133 #define SYNT_NONE_V0 \
139 0x00, 0x00, 0x00, 0x00 } \
143 #define SYNT_NETDFS_V3 \
146 0x4fc742e0, 0x4a10, 0x11cf, \
149 0x00, 0x4a, 0xe6, 0x73 } \
153 #define SYNT_ECHO_V1 \
156 0x60a15ec5, 0x4de8, 0x11d7, \
159 0x56, 0xa2, 0x01, 0x82 } \
163 #define SYNT_SHUTDOWN_V1 \
166 0x894de0c0, 0x0d55, 0x11d3, \
169 0x4f, 0xa3, 0x21, 0xa1 } \
173 #define SYNT_EPM_V3 \
176 0xe1af8308, 0x5d1f, 0x11c9, \
179 0x2b, 0x14, 0xa0, 0xfa } \
184 * IMPORTANT!! If you update this structure, make sure to
185 * update the index #defines in smb.h.
188 const struct pipe_id_info pipe_names [] =
190 /* client pipe , abstract syntax , server pipe , transfer syntax */
191 { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 },
192 { PIPE_LSARPC , SYNT_LSARPC_V0_DS , PIPE_LSASS , TRANS_SYNT_V2 },
193 { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
194 { PIPE_NETLOGON, SYNT_NETLOGON_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
195 { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 },
196 { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
197 { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 },
198 { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 },
199 { PIPE_NETDFS , SYNT_NETDFS_V3 , PIPE_NETDFS , TRANS_SYNT_V2 },
200 { PIPE_ECHO , SYNT_ECHO_V1 , PIPE_ECHO , TRANS_SYNT_V2 },
201 { PIPE_SHUTDOWN, SYNT_SHUTDOWN_V1 , PIPE_SHUTDOWN , TRANS_SYNT_V2 },
202 { PIPE_EPM , SYNT_EPM_V3 , PIPE_EPM , TRANS_SYNT_V2 },
203 { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }
206 /*******************************************************************
207 Inits an RPC_HDR structure.
208 ********************************************************************/
210 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
211 uint32 call_id, int data_len, int auth_len)
213 hdr->major = 5; /* RPC version 5 */
214 hdr->minor = 0; /* minor version 0 */
215 hdr->pkt_type = pkt_type; /* RPC packet type */
216 hdr->flags = flags; /* dce/rpc flags */
217 hdr->pack_type[0] = 0x10; /* little-endian data representation */
218 hdr->pack_type[1] = 0; /* packed data representation */
219 hdr->pack_type[2] = 0; /* packed data representation */
220 hdr->pack_type[3] = 0; /* packed data representation */
221 hdr->frag_len = data_len; /* fragment length, fill in later */
222 hdr->auth_len = auth_len; /* authentication length */
223 hdr->call_id = call_id; /* call identifier - match incoming RPC */
226 /*******************************************************************
227 Reads or writes an RPC_HDR structure.
228 ********************************************************************/
230 BOOL smb_io_rpc_hdr(const char *desc, RPC_HDR *rpc, prs_struct *ps, int depth)
235 prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
238 if(!prs_uint8 ("major ", ps, depth, &rpc->major))
241 if(!prs_uint8 ("minor ", ps, depth, &rpc->minor))
243 if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type))
245 if(!prs_uint8 ("flags ", ps, depth, &rpc->flags))
248 /* We always marshall in little endian format. */
250 rpc->pack_type[0] = 0x10;
252 if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
254 if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
256 if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
258 if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
262 * If reading and pack_type[0] == 0 then the data is in big-endian
263 * format. Set the flag in the prs_struct to specify reverse-endainness.
266 if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
267 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
268 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
271 if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len))
273 if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len))
275 if(!prs_uint32("call_id ", ps, depth, &rpc->call_id))
280 /*******************************************************************
281 Reads or writes a struct uuid
282 ********************************************************************/
284 BOOL smb_io_uuid(const char *desc, struct uuid *uuid,
285 prs_struct *ps, int depth)
290 prs_debug(ps, depth, desc, "smb_io_uuid");
293 if(!prs_uint32 ("data ", ps, depth, &uuid->time_low))
295 if(!prs_uint16 ("data ", ps, depth, &uuid->time_mid))
297 if(!prs_uint16 ("data ", ps, depth, &uuid->time_hi_and_version))
300 if(!prs_uint8s (False, "data ", ps, depth, uuid->clock_seq, sizeof(uuid->clock_seq)))
302 if(!prs_uint8s (False, "data ", ps, depth, uuid->node, sizeof(uuid->node)))
308 /*******************************************************************
309 Reads or writes an RPC_IFACE structure.
310 ********************************************************************/
312 static BOOL smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
317 prs_debug(ps, depth, desc, "smb_io_rpc_iface");
323 if (!smb_io_uuid( "uuid", &ifc->uuid, ps, depth))
326 if(!prs_uint32 ("version", ps, depth, &ifc->version))
332 /*******************************************************************
333 Inits an RPC_ADDR_STR structure.
334 ********************************************************************/
336 static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name)
338 str->len = strlen(name) + 1;
339 fstrcpy(str->str, name);
342 /*******************************************************************
343 Reads or writes an RPC_ADDR_STR structure.
344 ********************************************************************/
346 static BOOL smb_io_rpc_addr_str(const char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth)
351 prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
356 if(!prs_uint16 ( "len", ps, depth, &str->len))
358 if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
363 /*******************************************************************
364 Inits an RPC_HDR_BBA structure.
365 ********************************************************************/
367 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
369 bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
370 bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
371 bba->assoc_gid = assoc_gid; /* associated group id (0x0) */
374 /*******************************************************************
375 Reads or writes an RPC_HDR_BBA structure.
376 ********************************************************************/
378 static BOOL smb_io_rpc_hdr_bba(const char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
383 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
386 if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
388 if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
390 if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
395 /*******************************************************************
396 Inits an RPC_HDR_RB structure.
397 ********************************************************************/
399 void init_rpc_hdr_rb(RPC_HDR_RB *rpc,
400 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
401 uint32 num_elements, uint16 context_id, uint8 num_syntaxes,
402 RPC_IFACE *abstract, RPC_IFACE *transfer)
404 init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
406 rpc->num_elements = num_elements ; /* the number of elements (0x1) */
407 rpc->context_id = context_id ; /* presentation context identifier (0x0) */
408 rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */
410 /* num and vers. of interface client is using */
411 rpc->abstract = *abstract;
413 /* num and vers. of interface to use for replies */
414 rpc->transfer = *transfer;
417 /*******************************************************************
418 Reads or writes an RPC_HDR_RB structure.
419 ********************************************************************/
421 BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
426 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
429 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
432 if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements))
434 if(!prs_uint16("context_id ", ps, depth, &rpc->context_id ))
436 if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes))
439 if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth))
441 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
447 /*******************************************************************
448 Inits an RPC_RESULTS structure.
450 lkclXXXX only one reason at the moment!
451 ********************************************************************/
453 static void init_rpc_results(RPC_RESULTS *res,
454 uint8 num_results, uint16 result, uint16 reason)
456 res->num_results = num_results; /* the number of results (0x01) */
457 res->result = result ; /* result (0x00 = accept) */
458 res->reason = reason ; /* reason (0x00 = no reason specified) */
461 /*******************************************************************
462 Reads or writes an RPC_RESULTS structure.
464 lkclXXXX only one reason at the moment!
465 ********************************************************************/
467 static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
472 prs_debug(ps, depth, desc, "smb_io_rpc_results");
478 if(!prs_uint8 ("num_results", ps, depth, &res->num_results))
484 if(!prs_uint16("result ", ps, depth, &res->result))
486 if(!prs_uint16("reason ", ps, depth, &res->reason))
491 /*******************************************************************
492 Init an RPC_HDR_BA structure.
494 lkclXXXX only one reason at the moment!
496 ********************************************************************/
498 void init_rpc_hdr_ba(RPC_HDR_BA *rpc,
499 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
500 const char *pipe_addr,
501 uint8 num_results, uint16 result, uint16 reason,
504 init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
505 init_rpc_addr_str(&rpc->addr, pipe_addr);
506 init_rpc_results (&rpc->res, num_results, result, reason);
508 /* the transfer syntax from the request */
509 memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
512 /*******************************************************************
513 Reads or writes an RPC_HDR_BA structure.
514 ********************************************************************/
516 BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
521 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
524 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
526 if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
528 if(!smb_io_rpc_results("", &rpc->res, ps, depth))
530 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
535 /*******************************************************************
536 Init an RPC_HDR_REQ structure.
537 ********************************************************************/
539 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
541 hdr->alloc_hint = alloc_hint; /* allocation hint */
542 hdr->context_id = 0; /* presentation context identifier */
543 hdr->opnum = opnum; /* opnum */
546 /*******************************************************************
547 Reads or writes an RPC_HDR_REQ structure.
548 ********************************************************************/
550 BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
555 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
558 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
560 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
562 if(!prs_uint16("opnum ", ps, depth, &rpc->opnum))
567 /*******************************************************************
568 Reads or writes an RPC_HDR_RESP structure.
569 ********************************************************************/
571 BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
576 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
579 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
581 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
583 if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
585 if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved))
590 /*******************************************************************
591 Reads or writes an RPC_HDR_FAULT structure.
592 ********************************************************************/
594 BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
599 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
602 if(!prs_ntstatus("status ", ps, depth, &rpc->status))
604 if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
610 /*******************************************************************
611 Init an RPC_HDR_AUTHA structure.
612 ********************************************************************/
614 void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
615 uint16 max_tsize, uint16 max_rsize,
616 uint8 auth_type, uint8 auth_level,
619 rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
620 rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
622 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
623 rai->auth_level = auth_level; /* 0x06 */
624 rai->stub_type_len = stub_type_len; /* 0x00 */
625 rai->padding = 0; /* padding 0x00 */
627 rai->unknown = 0x0014a0c0; /* non-zero pointer to something */
630 /*******************************************************************
631 Reads or writes an RPC_HDR_AUTHA structure.
632 ********************************************************************/
634 BOOL smb_io_rpc_hdr_autha(const char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
639 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
642 if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize))
644 if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize))
647 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
649 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
651 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
653 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
656 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
662 /*******************************************************************
663 Inits an RPC_HDR_AUTH structure.
664 ********************************************************************/
666 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
667 uint8 auth_type, uint8 auth_level,
671 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
672 rai->auth_level = auth_level; /* 0x06 */
673 rai->padding = padding;
676 rai->auth_context = ptr; /* non-zero pointer to something */
679 /*******************************************************************
680 Reads or writes an RPC_HDR_AUTH structure.
681 ********************************************************************/
683 BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
688 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
694 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
696 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
698 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
700 if(!prs_uint8 ("reserved ", ps, depth, &rai->reserved))
702 if(!prs_uint32("auth_context ", ps, depth, &rai->auth_context))
708 /*******************************************************************
709 Checks an RPC_AUTH_VERIFIER structure.
710 ********************************************************************/
712 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
713 const char *signature, uint32 msg_type)
715 return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
718 /*******************************************************************
719 Inits an RPC_AUTH_VERIFIER structure.
720 ********************************************************************/
722 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
723 const char *signature, uint32 msg_type)
725 fstrcpy(rav->signature, signature); /* "NTLMSSP" */
726 rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
729 /*******************************************************************
730 Reads or writes an RPC_AUTH_VERIFIER structure.
731 ********************************************************************/
733 BOOL smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
738 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
742 if(!prs_string("signature", ps, depth, rav->signature,
743 sizeof(rav->signature)))
745 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
751 /*******************************************************************
752 This parses an RPC_AUTH_VERIFIER for NETLOGON schannel. I think
753 assuming "NTLMSSP" in sm_io_rpc_auth_verifier is somewhat wrong.
754 I have to look at that later...
755 ********************************************************************/
757 BOOL smb_io_rpc_netsec_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
762 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
765 if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
767 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
773 /*******************************************************************
774 Inits an RPC_AUTH_NTLMSSP_NEG structure.
775 ********************************************************************/
777 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
779 const char *myname, const char *domain)
781 int len_myname = strlen(myname);
782 int len_domain = strlen(domain);
784 neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
786 init_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname);
787 init_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20);
789 fstrcpy(neg->myname, myname);
790 fstrcpy(neg->domain, domain);
793 /*******************************************************************
794 Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
796 *** lkclXXXX HACK ALERT! ***
797 ********************************************************************/
799 BOOL smb_io_rpc_auth_ntlmssp_neg(const char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
801 uint32 start_offset = prs_offset(ps);
805 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
808 if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs))
813 uint32 old_neg_flags = neg->neg_flgs;
819 neg->neg_flgs = old_neg_flags;
821 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
823 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
826 old_offset = prs_offset(ps);
828 if(!prs_set_offset(ps, neg->hdr_myname.buffer + start_offset - 12))
831 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
832 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
835 old_offset += neg->hdr_myname.str_str_len;
837 if(!prs_set_offset(ps, neg->hdr_domain.buffer + start_offset - 12))
840 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
841 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
844 old_offset += neg->hdr_domain .str_str_len;
846 if(!prs_set_offset(ps, old_offset))
850 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
852 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
855 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
856 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
858 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
859 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
866 /*******************************************************************
867 creates an RPC_AUTH_NTLMSSP_CHAL structure.
868 ********************************************************************/
870 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
874 chl->unknown_1 = 0x0;
875 chl->unknown_2 = 0x00000028;
876 chl->neg_flags = neg_flags; /* 0x0082b1 */
878 memcpy(chl->challenge, challenge, sizeof(chl->challenge));
879 memset((char *)chl->reserved , '\0', sizeof(chl->reserved));
882 /*******************************************************************
883 Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
884 ********************************************************************/
886 BOOL smb_io_rpc_auth_ntlmssp_chal(const char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
891 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
894 if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */
896 if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */
898 if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */
901 if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)))
903 if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )))
909 /*******************************************************************
910 Inits an RPC_AUTH_NTLMSSP_RESP structure.
912 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
913 *** lkclXXXX the actual offset is at the start of the auth verifier ***
914 ********************************************************************/
916 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
917 uchar lm_resp[24], uchar nt_resp[24],
918 const char *domain, const char *user, const char *wks,
922 int dom_len = strlen(domain);
923 int wks_len = strlen(wks);
924 int usr_len = strlen(user);
925 int lm_len = (lm_resp != NULL) ? 24 : 0;
926 int nt_len = (nt_resp != NULL) ? 24 : 0;
928 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
930 #ifdef DEBUG_PASSWORD
931 DEBUG(100,("lm_resp\n"));
932 dump_data(100, (char *)lm_resp, 24);
933 DEBUG(100,("nt_resp\n"));
934 dump_data(100, (char *)nt_resp, 24);
937 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
938 domain, user, wks, neg_flags));
942 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
948 init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset);
951 init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset);
954 init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset);
957 init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset);
960 init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset);
963 init_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
965 rsp->neg_flags = neg_flags;
967 memcpy(rsp->lm_resp, lm_resp, 24);
968 memcpy(rsp->nt_resp, nt_resp, 24);
970 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
971 rpcstr_push(rsp->domain, domain, sizeof(rsp->domain), 0);
972 rpcstr_push(rsp->user, user, sizeof(rsp->user), 0);
973 rpcstr_push(rsp->wks, wks, sizeof(rsp->wks), 0);
975 fstrcpy(rsp->domain, domain);
976 fstrcpy(rsp->user, user);
977 fstrcpy(rsp->wks, wks);
980 rsp->sess_key[0] = 0;
983 /*******************************************************************
984 Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
986 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
987 *** lkclXXXX the actual offset is at the start of the auth verifier ***
988 ********************************************************************/
990 BOOL smb_io_rpc_auth_ntlmssp_resp(const char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
995 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
1005 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
1007 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
1009 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
1011 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
1013 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
1015 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1018 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1021 old_offset = prs_offset(ps);
1023 if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0xc))
1026 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
1027 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1030 old_offset += rsp->hdr_domain.str_str_len;
1032 if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0xc))
1035 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
1036 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1039 old_offset += rsp->hdr_usr.str_str_len;
1041 if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0xc))
1044 if(!prs_uint8s(True, "wks ", ps, depth, (uint8*)rsp->wks,
1045 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1048 old_offset += rsp->hdr_wks.str_str_len;
1050 if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0xc))
1053 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
1054 MIN(rsp->hdr_lm_resp.str_str_len, sizeof(rsp->lm_resp ))))
1057 old_offset += rsp->hdr_lm_resp.str_str_len;
1059 if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0xc))
1062 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1063 MIN(rsp->hdr_nt_resp.str_str_len, sizeof(rsp->nt_resp ))))
1066 old_offset += rsp->hdr_nt_resp.str_str_len;
1068 if (rsp->hdr_sess_key.str_str_len != 0) {
1070 if(!prs_set_offset(ps, rsp->hdr_sess_key.buffer + 0x10))
1073 old_offset += rsp->hdr_sess_key.str_str_len;
1075 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1076 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1080 if(!prs_set_offset(ps, old_offset))
1084 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
1086 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
1088 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
1090 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
1092 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
1094 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1097 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1100 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
1101 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1104 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
1105 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1108 if(!prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks,
1109 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1111 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
1112 MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp))))
1114 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1115 MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))))
1117 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1118 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1125 /*******************************************************************
1126 Checks an RPC_AUTH_NTLMSSP_CHK structure.
1127 ********************************************************************/
1129 BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num)
1134 if (chk->crc32 != crc32 ||
1135 chk->ver != NTLMSSP_SIGN_VERSION ||
1136 chk->seq_num != seq_num)
1138 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1139 chk->crc32, chk->ver, chk->seq_num));
1141 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1142 crc32, NTLMSSP_SIGN_VERSION, seq_num));
1148 /*******************************************************************
1149 Inits an RPC_AUTH_NTLMSSP_CHK structure.
1150 ********************************************************************/
1152 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
1153 uint32 ver, uint32 crc32, uint32 seq_num)
1156 chk->reserved = 0x0;
1158 chk->seq_num = seq_num;
1161 /*******************************************************************
1162 Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1163 ********************************************************************/
1165 BOOL smb_io_rpc_auth_ntlmssp_chk(const char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
1170 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
1176 if(!prs_uint32("ver ", ps, depth, &chk->ver))
1178 if(!prs_uint32("reserved", ps, depth, &chk->reserved))
1180 if(!prs_uint32("crc32 ", ps, depth, &chk->crc32))
1182 if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num))
1188 /*******************************************************************
1189 creates an RPC_AUTH_NETSEC_NEG structure.
1190 ********************************************************************/
1191 void init_rpc_auth_netsec_neg(RPC_AUTH_NETSEC_NEG *neg,
1192 const char *domain, const char *myname)
1196 fstrcpy(neg->domain, domain);
1197 fstrcpy(neg->myname, myname);
1200 /*******************************************************************
1201 Reads or writes an RPC_AUTH_NETSEC_NEG structure.
1202 ********************************************************************/
1204 BOOL smb_io_rpc_auth_netsec_neg(const char *desc, RPC_AUTH_NETSEC_NEG *neg,
1205 prs_struct *ps, int depth)
1210 prs_debug(ps, depth, desc, "smb_io_rpc_auth_netsec_neg");
1216 if(!prs_uint32("type1", ps, depth, &neg->type1))
1218 if(!prs_uint32("type2", ps, depth, &neg->type2))
1220 if(!prs_string("domain ", ps, depth, neg->domain, sizeof(neg->domain)))
1222 if(!prs_string("myname ", ps, depth, neg->myname, sizeof(neg->myname)))
1228 /*******************************************************************
1229 reads or writes an RPC_AUTH_NETSEC_CHK structure.
1230 ********************************************************************/
1231 BOOL smb_io_rpc_auth_netsec_chk(const char *desc, RPC_AUTH_NETSEC_CHK * chk,
1232 prs_struct *ps, int depth)
1237 prs_debug(ps, depth, desc, "smb_io_rpc_auth_netsec_chk");
1240 prs_uint8s(False, "sig ", ps, depth, chk->sig, sizeof(chk->sig));
1241 prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num));
1242 prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest));
1243 prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder));