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_NONE_V0 \
112 { 0x00, 0x00, 0x00, 0x00, \
113 0x00, 0x00, 0x00, 0x00 } \
117 /* pipe string names */
118 #define PIPE_SRVSVC "\\PIPE\\srvsvc"
119 #define PIPE_SAMR "\\PIPE\\samr"
120 #define PIPE_WINREG "\\PIPE\\winreg"
121 #define PIPE_WKSSVC "\\PIPE\\wkssvc"
122 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
123 #define PIPE_NTLSA "\\PIPE\\ntlsa"
124 #define PIPE_NTSVCS "\\PIPE\\ntsvcs"
125 #define PIPE_LSASS "\\PIPE\\lsass"
126 #define PIPE_LSARPC "\\PIPE\\lsarpc"
128 struct pipe_id_info pipe_names [] =
130 /* client pipe , abstract syntax , server pipe , transfer syntax */
131 { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 },
132 { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
133 { PIPE_NETLOGON, SYNT_NETLOGON_V1, PIPE_LSASS , TRANS_SYNT_V2 },
134 { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 },
135 { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
136 { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 },
137 { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }
140 /*******************************************************************
141 Inits an RPC_HDR structure.
142 ********************************************************************/
144 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
145 uint32 call_id, int data_len, int auth_len)
147 hdr->major = 5; /* RPC version 5 */
148 hdr->minor = 0; /* minor version 0 */
149 hdr->pkt_type = pkt_type; /* RPC packet type */
150 hdr->flags = flags; /* dce/rpc flags */
151 hdr->pack_type[0] = 0x10; /* little-endian data representation */
152 hdr->pack_type[1] = 0; /* packed data representation */
153 hdr->pack_type[2] = 0; /* packed data representation */
154 hdr->pack_type[3] = 0; /* packed data representation */
155 hdr->frag_len = data_len; /* fragment length, fill in later */
156 hdr->auth_len = auth_len; /* authentication length */
157 hdr->call_id = call_id; /* call identifier - match incoming RPC */
160 /*******************************************************************
161 Reads or writes an RPC_HDR structure.
162 ********************************************************************/
164 BOOL smb_io_rpc_hdr(char *desc, RPC_HDR *rpc, prs_struct *ps, int depth)
169 prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
172 if(!prs_uint8 ("major ", ps, depth, &rpc->major))
175 if(!prs_uint8 ("minor ", ps, depth, &rpc->minor))
177 if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type))
179 if(!prs_uint8 ("flags ", ps, depth, &rpc->flags))
181 if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
183 if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
185 if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
187 if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
191 * If reading and pack_type[0] == 0 then the data is in big-endian
192 * format. Set the flag in the prs_struct to specify reverse-endainness.
195 if (ps->io && rpc->pack_type[0] == 0) {
196 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
197 prs_set_bigendian_data(ps);
200 if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len))
202 if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len))
204 if(!prs_uint32("call_id ", ps, depth, &rpc->call_id))
209 /*******************************************************************
210 Reads or writes an RPC_IFACE structure.
211 ********************************************************************/
213 static BOOL smb_io_rpc_iface(char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
218 prs_debug(ps, depth, desc, "smb_io_rpc_iface");
224 if(!prs_uint32 ("data ", ps, depth, &ifc->uuid.time_low))
226 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_mid))
228 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_hi_and_version))
231 if(!prs_uint8s (False, "data ", ps, depth, ifc->uuid.remaining, sizeof(ifc->uuid.remaining)))
233 if(!prs_uint32 ( "version", ps, depth, &(ifc->version)))
239 /*******************************************************************
240 Inits an RPC_ADDR_STR structure.
241 ********************************************************************/
243 static void init_rpc_addr_str(RPC_ADDR_STR *str, char *name)
245 str->len = strlen(name) + 1;
246 fstrcpy(str->str, name);
249 /*******************************************************************
250 Reads or writes an RPC_ADDR_STR structure.
251 ********************************************************************/
253 static BOOL smb_io_rpc_addr_str(char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth)
258 prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
263 if(!prs_uint16 ( "len", ps, depth, &str->len))
265 if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
270 /*******************************************************************
271 Inits an RPC_HDR_BBA structure.
272 ********************************************************************/
274 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
276 bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
277 bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
278 bba->assoc_gid = assoc_gid; /* associated group id (0x0) */
281 /*******************************************************************
282 Reads or writes an RPC_HDR_BBA structure.
283 ********************************************************************/
285 static BOOL smb_io_rpc_hdr_bba(char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
290 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
293 if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
295 if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
297 if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
302 /*******************************************************************
303 Inits an RPC_HDR_RB structure.
304 ********************************************************************/
306 void init_rpc_hdr_rb(RPC_HDR_RB *rpc,
307 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
308 uint32 num_elements, uint16 context_id, uint8 num_syntaxes,
309 RPC_IFACE *abstract, RPC_IFACE *transfer)
311 init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
313 rpc->num_elements = num_elements ; /* the number of elements (0x1) */
314 rpc->context_id = context_id ; /* presentation context identifier (0x0) */
315 rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */
317 /* num and vers. of interface client is using */
318 rpc->abstract = *abstract;
320 /* num and vers. of interface to use for replies */
321 rpc->transfer = *transfer;
324 /*******************************************************************
325 Reads or writes an RPC_HDR_RB structure.
326 ********************************************************************/
328 BOOL smb_io_rpc_hdr_rb(char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
333 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
336 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
339 if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements))
341 if(!prs_uint16("context_id ", ps, depth, &rpc->context_id ))
343 if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes))
346 if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth))
348 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
354 /*******************************************************************
355 Inits an RPC_RESULTS structure.
357 lkclXXXX only one reason at the moment!
358 ********************************************************************/
360 static void init_rpc_results(RPC_RESULTS *res,
361 uint8 num_results, uint16 result, uint16 reason)
363 res->num_results = num_results; /* the number of results (0x01) */
364 res->result = result ; /* result (0x00 = accept) */
365 res->reason = reason ; /* reason (0x00 = no reason specified) */
368 /*******************************************************************
369 Reads or writes an RPC_RESULTS structure.
371 lkclXXXX only one reason at the moment!
372 ********************************************************************/
374 static BOOL smb_io_rpc_results(char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
379 prs_debug(ps, depth, desc, "smb_io_rpc_results");
385 if(!prs_uint8 ("num_results", ps, depth, &res->num_results))
391 if(!prs_uint16("result ", ps, depth, &res->result))
393 if(!prs_uint16("reason ", ps, depth, &res->reason))
398 /*******************************************************************
399 Init an RPC_HDR_BA structure.
401 lkclXXXX only one reason at the moment!
403 ********************************************************************/
405 void init_rpc_hdr_ba(RPC_HDR_BA *rpc,
406 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
408 uint8 num_results, uint16 result, uint16 reason,
411 init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
412 init_rpc_addr_str(&rpc->addr, pipe_addr);
413 init_rpc_results (&rpc->res, num_results, result, reason);
415 /* the transfer syntax from the request */
416 memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
419 /*******************************************************************
420 Reads or writes an RPC_HDR_BA structure.
421 ********************************************************************/
423 BOOL smb_io_rpc_hdr_ba(char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
428 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
431 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
433 if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
435 if(!smb_io_rpc_results("", &rpc->res, ps, depth))
437 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
442 /*******************************************************************
443 Init an RPC_HDR_REQ structure.
444 ********************************************************************/
446 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
448 hdr->alloc_hint = alloc_hint; /* allocation hint */
449 hdr->context_id = 0; /* presentation context identifier */
450 hdr->opnum = opnum; /* opnum */
453 /*******************************************************************
454 Reads or writes an RPC_HDR_REQ structure.
455 ********************************************************************/
457 BOOL smb_io_rpc_hdr_req(char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
462 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
465 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
467 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
469 if(!prs_uint16("opnum ", ps, depth, &rpc->opnum))
474 /*******************************************************************
475 Reads or writes an RPC_HDR_RESP structure.
476 ********************************************************************/
478 BOOL smb_io_rpc_hdr_resp(char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
483 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
486 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
488 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
490 if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
492 if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved))
497 /*******************************************************************
498 Init an RPC_HDR_AUTHA structure.
499 ********************************************************************/
501 void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
502 uint16 max_tsize, uint16 max_rsize,
503 uint8 auth_type, uint8 auth_level,
506 rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
507 rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
509 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
510 rai->auth_level = auth_level; /* 0x06 */
511 rai->stub_type_len = stub_type_len; /* 0x00 */
512 rai->padding = 0; /* padding 0x00 */
514 rai->unknown = 0x0014a0c0; /* non-zero pointer to something */
517 /*******************************************************************
518 Reads or writes an RPC_HDR_AUTHA structure.
519 ********************************************************************/
521 BOOL smb_io_rpc_hdr_autha(char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
526 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
529 if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize))
531 if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize))
534 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
536 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
538 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
540 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
543 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
549 /*******************************************************************
550 Checks an RPC_HDR_AUTH structure.
551 ********************************************************************/
553 BOOL rpc_hdr_auth_chk(RPC_HDR_AUTH *rai)
555 return (rai->auth_type == NTLMSSP_AUTH_TYPE && rai->auth_level == NTLMSSP_AUTH_LEVEL);
558 /*******************************************************************
559 Inits an RPC_HDR_AUTH structure.
560 ********************************************************************/
562 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
563 uint8 auth_type, uint8 auth_level,
567 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
568 rai->auth_level = auth_level; /* 0x06 */
569 rai->stub_type_len = stub_type_len; /* 0x00 */
570 rai->padding = 0; /* padding 0x00 */
572 rai->unknown = ptr; /* non-zero pointer to something */
575 /*******************************************************************
576 Reads or writes an RPC_HDR_AUTH structure.
577 ********************************************************************/
579 BOOL smb_io_rpc_hdr_auth(char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
584 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
590 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
592 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
594 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
596 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
599 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
605 /*******************************************************************
606 Checks an RPC_AUTH_VERIFIER structure.
607 ********************************************************************/
609 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
610 char *signature, uint32 msg_type)
612 return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
615 /*******************************************************************
616 Inits an RPC_AUTH_VERIFIER structure.
617 ********************************************************************/
619 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
620 char *signature, uint32 msg_type)
622 fstrcpy(rav->signature, signature); /* "NTLMSSP" */
623 rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
626 /*******************************************************************
627 Reads or writes an RPC_AUTH_VERIFIER structure.
628 ********************************************************************/
630 BOOL smb_io_rpc_auth_verifier(char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
635 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
639 if(!prs_string("signature", ps, depth, rav->signature, strlen("NTLMSSP"),
640 sizeof(rav->signature)))
642 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
648 /*******************************************************************
649 Inits an RPC_AUTH_NTLMSSP_NEG structure.
650 ********************************************************************/
652 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
654 fstring myname, fstring domain)
656 int len_myname = strlen(myname);
657 int len_domain = strlen(domain);
659 neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
661 init_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname);
662 init_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20);
664 fstrcpy(neg->myname, myname);
665 fstrcpy(neg->domain, domain);
668 /*******************************************************************
669 Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
671 *** lkclXXXX HACK ALERT! ***
672 ********************************************************************/
674 BOOL smb_io_rpc_auth_ntlmssp_neg(char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
679 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
682 if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs))
687 uint32 old_neg_flags = neg->neg_flgs;
693 neg->neg_flgs = old_neg_flags;
695 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
697 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
700 old_offset = prs_offset(ps);
703 if(!prs_set_offset(ps, neg->hdr_myname.buffer + 0x50))
706 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
707 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
710 old_offset += neg->hdr_myname.str_str_len;
713 if(!prs_set_offset(ps, neg->hdr_domain.buffer + 0x50))
716 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
717 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
720 old_offset += neg->hdr_domain .str_str_len;
722 if(!prs_set_offset(ps, old_offset))
726 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
728 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
731 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
732 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
734 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
735 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
742 /*******************************************************************
743 creates an RPC_AUTH_NTLMSSP_CHAL structure.
744 ********************************************************************/
746 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
750 chl->unknown_1 = 0x0;
751 chl->unknown_2 = 0x00000028;
752 chl->neg_flags = neg_flags; /* 0x0082b1 */
754 memcpy(chl->challenge, challenge, sizeof(chl->challenge));
755 memset((char *)chl->reserved , '\0', sizeof(chl->reserved));
758 /*******************************************************************
759 Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
760 ********************************************************************/
762 BOOL smb_io_rpc_auth_ntlmssp_chal(char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
767 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
770 if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */
772 if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */
774 if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */
777 if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)))
779 if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )))
785 /*******************************************************************
786 Inits an RPC_AUTH_NTLMSSP_RESP structure.
788 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
789 *** lkclXXXX the actual offset is at the start of the auth verifier ***
790 ********************************************************************/
792 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
793 uchar lm_resp[24], uchar nt_resp[24],
794 char *domain, char *user, char *wks,
798 int dom_len = strlen(domain);
799 int wks_len = strlen(wks);
800 int usr_len = strlen(user);
801 int lm_len = (lm_resp != NULL) ? 24 : 0;
802 int nt_len = (nt_resp != NULL) ? 24 : 0;
804 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
806 #ifdef DEBUG_PASSWORD
807 DEBUG(100,("lm_resp\n"));
808 dump_data(100, (char *)lm_resp, 24);
809 DEBUG(100,("nt_resp\n"));
810 dump_data(100, (char *)nt_resp, 24);
813 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
814 domain, user, wks, neg_flags));
818 if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE))
825 init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset);
828 init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset);
831 init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset);
834 init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset);
837 init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset);
840 init_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
842 rsp->neg_flags = neg_flags;
844 memcpy(rsp->lm_resp, lm_resp, 24);
845 memcpy(rsp->nt_resp, nt_resp, 24);
847 if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE)) {
848 dos_struni2(rsp->domain, domain, sizeof(rsp->domain));
849 dos_struni2(rsp->user, user, sizeof(rsp->user));
850 dos_struni2(rsp->wks, wks, sizeof(rsp->wks));
852 fstrcpy(rsp->domain, domain);
853 fstrcpy(rsp->user, user);
854 fstrcpy(rsp->wks, wks);
856 rsp->sess_key[0] = 0;
859 /*******************************************************************
860 Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
862 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
863 *** lkclXXXX the actual offset is at the start of the auth verifier ***
864 ********************************************************************/
866 BOOL smb_io_rpc_auth_ntlmssp_resp(char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
871 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
881 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
883 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
885 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
887 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
889 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
891 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
894 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
897 old_offset = prs_offset(ps);
899 if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0x1c))
902 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
903 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
906 old_offset += rsp->hdr_domain.str_str_len;
908 if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0x1c))
911 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
912 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
915 old_offset += rsp->hdr_usr.str_str_len;
917 if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0x1c))
920 if(!prs_uint8s(True, "wks ", ps, depth, (uint8*)rsp->wks,
921 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
924 old_offset += rsp->hdr_wks.str_str_len;
926 if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0x1c))
929 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
930 MIN(rsp->hdr_lm_resp.str_str_len, sizeof(rsp->lm_resp ))))
933 old_offset += rsp->hdr_lm_resp.str_str_len;
935 if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0x1c))
938 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
939 MIN(rsp->hdr_nt_resp.str_str_len, sizeof(rsp->nt_resp ))))
942 old_offset += rsp->hdr_nt_resp.str_str_len;
944 if (rsp->hdr_sess_key.str_str_len != 0) {
946 if(!prs_set_offset(ps, rsp->hdr_sess_key.buffer + 0x1c))
949 old_offset += rsp->hdr_sess_key.str_str_len;
951 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
952 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
956 if(!prs_set_offset(ps, old_offset))
960 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
962 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
964 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
966 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
968 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
970 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
973 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
976 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
977 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
980 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
981 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
984 if(!prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks,
985 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
987 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
988 MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp))))
990 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
991 MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))))
993 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
994 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1001 /*******************************************************************
1002 Checks an RPC_AUTH_NTLMSSP_CHK structure.
1003 ********************************************************************/
1005 BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num)
1010 if (chk->crc32 != crc32 ||
1011 chk->ver != NTLMSSP_SIGN_VERSION ||
1012 chk->seq_num != seq_num)
1014 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1015 crc32, NTLMSSP_SIGN_VERSION, seq_num));
1016 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1017 chk->crc32, chk->ver, chk->seq_num));
1023 /*******************************************************************
1024 Inits an RPC_AUTH_NTLMSSP_CHK structure.
1025 ********************************************************************/
1027 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
1028 uint32 ver, uint32 crc32, uint32 seq_num)
1031 chk->reserved = 0x0;
1033 chk->seq_num = seq_num;
1036 /*******************************************************************
1037 Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1038 ********************************************************************/
1040 BOOL smb_io_rpc_auth_ntlmssp_chk(char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
1045 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
1051 if(!prs_uint32("ver ", ps, depth, &chk->ver))
1053 if(!prs_uint32("reserved", ps, depth, &chk->reserved))
1055 if(!prs_uint32("crc32 ", ps, depth, &chk->crc32))
1057 if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num))