3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8 * Copyright (C) Paul Ashton 1997.
9 * Copyright (C) Jeremy Allison 1999.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 extern int DEBUGLEVEL;
32 /*******************************************************************
33 interface/version dce/rpc pipe identification
34 ********************************************************************/
36 #define TRANS_SYNT_V2 \
39 0x8a885d04, 0x1ceb, 0x11c9, \
40 { 0x9f, 0xe8, 0x08, 0x00, \
41 0x2b, 0x10, 0x48, 0x60 } \
45 #define SYNT_NETLOGON_V2 \
48 0x8a885d04, 0x1ceb, 0x11c9, \
49 { 0x9f, 0xe8, 0x08, 0x00, \
50 0x2b, 0x10, 0x48, 0x60 } \
54 #define SYNT_WKSSVC_V1 \
57 0x6bffd098, 0xa112, 0x3610, \
58 { 0x98, 0x33, 0x46, 0xc3, \
59 0xf8, 0x7e, 0x34, 0x5a } \
63 #define SYNT_SRVSVC_V3 \
66 0x4b324fc8, 0x1670, 0x01d3, \
67 { 0x12, 0x78, 0x5a, 0x47, \
68 0xbf, 0x6e, 0xe1, 0x88 } \
72 #define SYNT_LSARPC_V0 \
75 0x12345778, 0x1234, 0xabcd, \
76 { 0xef, 0x00, 0x01, 0x23, \
77 0x45, 0x67, 0x89, 0xab } \
81 #define SYNT_SAMR_V1 \
84 0x12345778, 0x1234, 0xabcd, \
85 { 0xef, 0x00, 0x01, 0x23, \
86 0x45, 0x67, 0x89, 0xac } \
90 #define SYNT_NETLOGON_V1 \
93 0x12345678, 0x1234, 0xabcd, \
94 { 0xef, 0x00, 0x01, 0x23, \
95 0x45, 0x67, 0xcf, 0xfb } \
99 #define SYNT_WINREG_V1 \
102 0x338cd001, 0x2244, 0x31f1, \
103 { 0xaa, 0xaa, 0x90, 0x00, \
104 0x38, 0x00, 0x10, 0x03 } \
108 #define SYNT_SPOOLSS_V1 \
111 0x12345678, 0x1234, 0xabcd, \
112 { 0xef, 0x00, 0x01, 0x23, \
113 0x45, 0x67, 0x89, 0xab } \
117 #define SYNT_NONE_V0 \
121 { 0x00, 0x00, 0x00, 0x00, \
122 0x00, 0x00, 0x00, 0x00 } \
126 #define SYNT_NETDFS_V3 \
129 0x4fc742e0, 0x4a10, 0x11cf, \
130 { 0x82, 0x73, 0x00, 0xaa, \
131 0x00, 0x4a, 0xe6, 0x73 } \
135 struct pipe_id_info pipe_names [] =
137 /* client pipe , abstract syntax , server pipe , transfer syntax */
138 { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 },
139 { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
140 { PIPE_NETLOGON, SYNT_NETLOGON_V1, PIPE_LSASS , TRANS_SYNT_V2 },
141 { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 },
142 { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
143 { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 },
144 { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 },
145 { PIPE_NETDFS , SYNT_NETDFS_V3 , PIPE_NETDFS , TRANS_SYNT_V2 },
146 { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }
149 /*******************************************************************
150 Inits an RPC_HDR structure.
151 ********************************************************************/
153 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
154 uint32 call_id, int data_len, int auth_len)
156 hdr->major = 5; /* RPC version 5 */
157 hdr->minor = 0; /* minor version 0 */
158 hdr->pkt_type = pkt_type; /* RPC packet type */
159 hdr->flags = flags; /* dce/rpc flags */
160 hdr->pack_type[0] = 0x10; /* little-endian data representation */
161 hdr->pack_type[1] = 0; /* packed data representation */
162 hdr->pack_type[2] = 0; /* packed data representation */
163 hdr->pack_type[3] = 0; /* packed data representation */
164 hdr->frag_len = data_len; /* fragment length, fill in later */
165 hdr->auth_len = auth_len; /* authentication length */
166 hdr->call_id = call_id; /* call identifier - match incoming RPC */
169 /*******************************************************************
170 Reads or writes an RPC_HDR structure.
171 ********************************************************************/
173 BOOL smb_io_rpc_hdr(char *desc, RPC_HDR *rpc, prs_struct *ps, int depth)
178 prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
181 if(!prs_uint8 ("major ", ps, depth, &rpc->major))
184 if(!prs_uint8 ("minor ", ps, depth, &rpc->minor))
186 if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type))
188 if(!prs_uint8 ("flags ", ps, depth, &rpc->flags))
191 /* We always marshall in little endian format. */
193 rpc->pack_type[0] = 0x10;
195 if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
197 if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
199 if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
201 if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
205 * If reading and pack_type[0] == 0 then the data is in big-endian
206 * format. Set the flag in the prs_struct to specify reverse-endainness.
209 if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
210 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
211 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
214 if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len))
216 if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len))
218 if(!prs_uint32("call_id ", ps, depth, &rpc->call_id))
223 /*******************************************************************
224 Reads or writes an RPC_IFACE structure.
225 ********************************************************************/
227 static BOOL smb_io_rpc_iface(char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
232 prs_debug(ps, depth, desc, "smb_io_rpc_iface");
238 if(!prs_uint32 ("data ", ps, depth, &ifc->uuid.time_low))
240 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_mid))
242 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_hi_and_version))
245 if(!prs_uint8s (False, "data ", ps, depth, ifc->uuid.remaining, sizeof(ifc->uuid.remaining)))
247 if(!prs_uint32 ( "version", ps, depth, &ifc->version))
253 /*******************************************************************
254 Inits an RPC_ADDR_STR structure.
255 ********************************************************************/
257 static void init_rpc_addr_str(RPC_ADDR_STR *str, char *name)
259 str->len = strlen(name) + 1;
260 fstrcpy(str->str, name);
263 /*******************************************************************
264 Reads or writes an RPC_ADDR_STR structure.
265 ********************************************************************/
267 static BOOL smb_io_rpc_addr_str(char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth)
272 prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
277 if(!prs_uint16 ( "len", ps, depth, &str->len))
279 if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
284 /*******************************************************************
285 Inits an RPC_HDR_BBA structure.
286 ********************************************************************/
288 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
290 bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
291 bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
292 bba->assoc_gid = assoc_gid; /* associated group id (0x0) */
295 /*******************************************************************
296 Reads or writes an RPC_HDR_BBA structure.
297 ********************************************************************/
299 static BOOL smb_io_rpc_hdr_bba(char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
304 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
307 if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
309 if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
311 if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
316 /*******************************************************************
317 Inits an RPC_HDR_RB structure.
318 ********************************************************************/
320 void init_rpc_hdr_rb(RPC_HDR_RB *rpc,
321 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
322 uint32 num_elements, uint16 context_id, uint8 num_syntaxes,
323 RPC_IFACE *abstract, RPC_IFACE *transfer)
325 init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
327 rpc->num_elements = num_elements ; /* the number of elements (0x1) */
328 rpc->context_id = context_id ; /* presentation context identifier (0x0) */
329 rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */
331 /* num and vers. of interface client is using */
332 rpc->abstract = *abstract;
334 /* num and vers. of interface to use for replies */
335 rpc->transfer = *transfer;
338 /*******************************************************************
339 Reads or writes an RPC_HDR_RB structure.
340 ********************************************************************/
342 BOOL smb_io_rpc_hdr_rb(char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
347 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
350 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
353 if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements))
355 if(!prs_uint16("context_id ", ps, depth, &rpc->context_id ))
357 if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes))
360 if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth))
362 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
368 /*******************************************************************
369 Inits an RPC_RESULTS structure.
371 lkclXXXX only one reason at the moment!
372 ********************************************************************/
374 static void init_rpc_results(RPC_RESULTS *res,
375 uint8 num_results, uint16 result, uint16 reason)
377 res->num_results = num_results; /* the number of results (0x01) */
378 res->result = result ; /* result (0x00 = accept) */
379 res->reason = reason ; /* reason (0x00 = no reason specified) */
382 /*******************************************************************
383 Reads or writes an RPC_RESULTS structure.
385 lkclXXXX only one reason at the moment!
386 ********************************************************************/
388 static BOOL smb_io_rpc_results(char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
393 prs_debug(ps, depth, desc, "smb_io_rpc_results");
399 if(!prs_uint8 ("num_results", ps, depth, &res->num_results))
405 if(!prs_uint16("result ", ps, depth, &res->result))
407 if(!prs_uint16("reason ", ps, depth, &res->reason))
412 /*******************************************************************
413 Init an RPC_HDR_BA structure.
415 lkclXXXX only one reason at the moment!
417 ********************************************************************/
419 void init_rpc_hdr_ba(RPC_HDR_BA *rpc,
420 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
422 uint8 num_results, uint16 result, uint16 reason,
425 init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
426 init_rpc_addr_str(&rpc->addr, pipe_addr);
427 init_rpc_results (&rpc->res, num_results, result, reason);
429 /* the transfer syntax from the request */
430 memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
433 /*******************************************************************
434 Reads or writes an RPC_HDR_BA structure.
435 ********************************************************************/
437 BOOL smb_io_rpc_hdr_ba(char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
442 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
445 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
447 if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
449 if(!smb_io_rpc_results("", &rpc->res, ps, depth))
451 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
456 /*******************************************************************
457 Init an RPC_HDR_REQ structure.
458 ********************************************************************/
460 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
462 hdr->alloc_hint = alloc_hint; /* allocation hint */
463 hdr->context_id = 0; /* presentation context identifier */
464 hdr->opnum = opnum; /* opnum */
467 /*******************************************************************
468 Reads or writes an RPC_HDR_REQ structure.
469 ********************************************************************/
471 BOOL smb_io_rpc_hdr_req(char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
476 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
479 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
481 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
483 if(!prs_uint16("opnum ", ps, depth, &rpc->opnum))
488 /*******************************************************************
489 Reads or writes an RPC_HDR_RESP structure.
490 ********************************************************************/
492 BOOL smb_io_rpc_hdr_resp(char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
497 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
500 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
502 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
504 if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
506 if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved))
511 /*******************************************************************
512 Reads or writes an RPC_HDR_FAULT structure.
513 ********************************************************************/
515 BOOL smb_io_rpc_hdr_fault(char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
520 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
523 if(!prs_uint32("status ", ps, depth, &rpc->status))
525 if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
531 /*******************************************************************
532 Init an RPC_HDR_AUTHA structure.
533 ********************************************************************/
535 void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
536 uint16 max_tsize, uint16 max_rsize,
537 uint8 auth_type, uint8 auth_level,
540 rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
541 rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
543 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
544 rai->auth_level = auth_level; /* 0x06 */
545 rai->stub_type_len = stub_type_len; /* 0x00 */
546 rai->padding = 0; /* padding 0x00 */
548 rai->unknown = 0x0014a0c0; /* non-zero pointer to something */
551 /*******************************************************************
552 Reads or writes an RPC_HDR_AUTHA structure.
553 ********************************************************************/
555 BOOL smb_io_rpc_hdr_autha(char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
560 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
563 if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize))
565 if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize))
568 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
570 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
572 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
574 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
577 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
583 /*******************************************************************
584 Checks an RPC_HDR_AUTH structure.
585 ********************************************************************/
587 BOOL rpc_hdr_auth_chk(RPC_HDR_AUTH *rai)
589 return (rai->auth_type == NTLMSSP_AUTH_TYPE && rai->auth_level == NTLMSSP_AUTH_LEVEL);
592 /*******************************************************************
593 Inits an RPC_HDR_AUTH structure.
594 ********************************************************************/
596 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
597 uint8 auth_type, uint8 auth_level,
601 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
602 rai->auth_level = auth_level; /* 0x06 */
603 rai->stub_type_len = stub_type_len; /* 0x00 */
604 rai->padding = 0; /* padding 0x00 */
606 rai->unknown = ptr; /* non-zero pointer to something */
609 /*******************************************************************
610 Reads or writes an RPC_HDR_AUTH structure.
611 ********************************************************************/
613 BOOL smb_io_rpc_hdr_auth(char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
618 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
624 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
626 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
628 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
630 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
633 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
639 /*******************************************************************
640 Checks an RPC_AUTH_VERIFIER structure.
641 ********************************************************************/
643 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
644 char *signature, uint32 msg_type)
646 return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
649 /*******************************************************************
650 Inits an RPC_AUTH_VERIFIER structure.
651 ********************************************************************/
653 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
654 char *signature, uint32 msg_type)
656 fstrcpy(rav->signature, signature); /* "NTLMSSP" */
657 rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
660 /*******************************************************************
661 Reads or writes an RPC_AUTH_VERIFIER structure.
662 ********************************************************************/
664 BOOL smb_io_rpc_auth_verifier(char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
669 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
673 if(!prs_string("signature", ps, depth, rav->signature, strlen("NTLMSSP"),
674 sizeof(rav->signature)))
676 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
682 /*******************************************************************
683 Inits an RPC_AUTH_NTLMSSP_NEG structure.
684 ********************************************************************/
686 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
688 fstring myname, fstring domain)
690 int len_myname = strlen(myname);
691 int len_domain = strlen(domain);
693 neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
695 init_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname);
696 init_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20);
698 fstrcpy(neg->myname, myname);
699 fstrcpy(neg->domain, domain);
702 /*******************************************************************
703 Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
705 *** lkclXXXX HACK ALERT! ***
706 ********************************************************************/
708 BOOL smb_io_rpc_auth_ntlmssp_neg(char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
710 uint32 start_offset = prs_offset(ps);
714 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
717 if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs))
722 uint32 old_neg_flags = neg->neg_flgs;
728 neg->neg_flgs = old_neg_flags;
730 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
732 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
735 old_offset = prs_offset(ps);
737 if(!prs_set_offset(ps, neg->hdr_myname.buffer + start_offset - 12))
740 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
741 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
744 old_offset += neg->hdr_myname.str_str_len;
746 if(!prs_set_offset(ps, neg->hdr_domain.buffer + start_offset - 12))
749 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
750 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
753 old_offset += neg->hdr_domain .str_str_len;
755 if(!prs_set_offset(ps, old_offset))
759 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
761 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
764 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
765 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
767 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
768 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
775 /*******************************************************************
776 creates an RPC_AUTH_NTLMSSP_CHAL structure.
777 ********************************************************************/
779 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
783 chl->unknown_1 = 0x0;
784 chl->unknown_2 = 0x00000028;
785 chl->neg_flags = neg_flags; /* 0x0082b1 */
787 memcpy(chl->challenge, challenge, sizeof(chl->challenge));
788 memset((char *)chl->reserved , '\0', sizeof(chl->reserved));
791 /*******************************************************************
792 Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
793 ********************************************************************/
795 BOOL smb_io_rpc_auth_ntlmssp_chal(char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
800 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
803 if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */
805 if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */
807 if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */
810 if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)))
812 if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )))
818 /*******************************************************************
819 Inits an RPC_AUTH_NTLMSSP_RESP structure.
821 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
822 *** lkclXXXX the actual offset is at the start of the auth verifier ***
823 ********************************************************************/
825 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
826 uchar lm_resp[24], uchar nt_resp[24],
827 char *domain, char *user, char *wks,
831 int dom_len = strlen(domain);
832 int wks_len = strlen(wks);
833 int usr_len = strlen(user);
834 int lm_len = (lm_resp != NULL) ? 24 : 0;
835 int nt_len = (nt_resp != NULL) ? 24 : 0;
837 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
839 #ifdef DEBUG_PASSWORD
840 DEBUG(100,("lm_resp\n"));
841 dump_data(100, (char *)lm_resp, 24);
842 DEBUG(100,("nt_resp\n"));
843 dump_data(100, (char *)nt_resp, 24);
846 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
847 domain, user, wks, neg_flags));
851 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
857 init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset);
860 init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset);
863 init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset);
866 init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset);
869 init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset);
872 init_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
874 rsp->neg_flags = neg_flags;
876 memcpy(rsp->lm_resp, lm_resp, 24);
877 memcpy(rsp->nt_resp, nt_resp, 24);
879 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
880 dos_struni2(rsp->domain, domain, sizeof(rsp->domain));
881 dos_struni2(rsp->user, user, sizeof(rsp->user));
882 dos_struni2(rsp->wks, wks, sizeof(rsp->wks));
884 fstrcpy(rsp->domain, domain);
885 fstrcpy(rsp->user, user);
886 fstrcpy(rsp->wks, wks);
888 rsp->sess_key[0] = 0;
891 /*******************************************************************
892 Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
894 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
895 *** lkclXXXX the actual offset is at the start of the auth verifier ***
896 ********************************************************************/
898 BOOL smb_io_rpc_auth_ntlmssp_resp(char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
903 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
913 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
915 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
917 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
919 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
921 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
923 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
926 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
929 old_offset = prs_offset(ps);
931 if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0xc))
934 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
935 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
938 old_offset += rsp->hdr_domain.str_str_len;
940 if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0xc))
943 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
944 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
947 old_offset += rsp->hdr_usr.str_str_len;
949 if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0xc))
952 if(!prs_uint8s(True, "wks ", ps, depth, (uint8*)rsp->wks,
953 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
956 old_offset += rsp->hdr_wks.str_str_len;
958 if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0xc))
961 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
962 MIN(rsp->hdr_lm_resp.str_str_len, sizeof(rsp->lm_resp ))))
965 old_offset += rsp->hdr_lm_resp.str_str_len;
967 if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0xc))
970 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
971 MIN(rsp->hdr_nt_resp.str_str_len, sizeof(rsp->nt_resp ))))
974 old_offset += rsp->hdr_nt_resp.str_str_len;
976 if (rsp->hdr_sess_key.str_str_len != 0) {
978 if(!prs_set_offset(ps, rsp->hdr_sess_key.buffer + 0x10))
981 old_offset += rsp->hdr_sess_key.str_str_len;
983 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
984 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
988 if(!prs_set_offset(ps, old_offset))
992 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
994 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
996 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
998 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
1000 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
1002 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1005 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1008 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
1009 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1012 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
1013 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1016 if(!prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks,
1017 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1019 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
1020 MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp))))
1022 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1023 MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))))
1025 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1026 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1033 /*******************************************************************
1034 Checks an RPC_AUTH_NTLMSSP_CHK structure.
1035 ********************************************************************/
1037 BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num)
1042 if (chk->crc32 != crc32 ||
1043 chk->ver != NTLMSSP_SIGN_VERSION ||
1044 chk->seq_num != seq_num)
1046 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1047 crc32, NTLMSSP_SIGN_VERSION, seq_num));
1048 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1049 chk->crc32, chk->ver, chk->seq_num));
1055 /*******************************************************************
1056 Inits an RPC_AUTH_NTLMSSP_CHK structure.
1057 ********************************************************************/
1059 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
1060 uint32 ver, uint32 crc32, uint32 seq_num)
1063 chk->reserved = 0x0;
1065 chk->seq_num = seq_num;
1068 /*******************************************************************
1069 Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1070 ********************************************************************/
1072 BOOL smb_io_rpc_auth_ntlmssp_chk(char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
1077 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
1083 if(!prs_uint32("ver ", ps, depth, &chk->ver))
1085 if(!prs_uint32("reserved", ps, depth, &chk->reserved))
1087 if(!prs_uint32("crc32 ", ps, depth, &chk->crc32))
1089 if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num))