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.
26 /*******************************************************************
27 interface/version dce/rpc pipe identification
28 ********************************************************************/
30 #define TRANS_SYNT_V2 \
33 0x8a885d04, 0x1ceb, 0x11c9, \
34 { 0x9f, 0xe8, 0x08, 0x00, \
35 0x2b, 0x10, 0x48, 0x60 } \
39 #define SYNT_NETLOGON_V2 \
42 0x8a885d04, 0x1ceb, 0x11c9, \
43 { 0x9f, 0xe8, 0x08, 0x00, \
44 0x2b, 0x10, 0x48, 0x60 } \
48 #define SYNT_WKSSVC_V1 \
51 0x6bffd098, 0xa112, 0x3610, \
52 { 0x98, 0x33, 0x46, 0xc3, \
53 0xf8, 0x7e, 0x34, 0x5a } \
57 #define SYNT_SRVSVC_V3 \
60 0x4b324fc8, 0x1670, 0x01d3, \
61 { 0x12, 0x78, 0x5a, 0x47, \
62 0xbf, 0x6e, 0xe1, 0x88 } \
66 #define SYNT_LSARPC_V0 \
69 0x12345778, 0x1234, 0xabcd, \
70 { 0xef, 0x00, 0x01, 0x23, \
71 0x45, 0x67, 0x89, 0xab } \
75 #define SYNT_SAMR_V1 \
78 0x12345778, 0x1234, 0xabcd, \
79 { 0xef, 0x00, 0x01, 0x23, \
80 0x45, 0x67, 0x89, 0xac } \
84 #define SYNT_NETLOGON_V1 \
87 0x12345678, 0x1234, 0xabcd, \
88 { 0xef, 0x00, 0x01, 0x23, \
89 0x45, 0x67, 0xcf, 0xfb } \
93 #define SYNT_WINREG_V1 \
96 0x338cd001, 0x2244, 0x31f1, \
97 { 0xaa, 0xaa, 0x90, 0x00, \
98 0x38, 0x00, 0x10, 0x03 } \
102 #define SYNT_SPOOLSS_V1 \
105 0x12345678, 0x1234, 0xabcd, \
106 { 0xef, 0x00, 0x01, 0x23, \
107 0x45, 0x67, 0x89, 0xab } \
111 #define SYNT_NONE_V0 \
115 { 0x00, 0x00, 0x00, 0x00, \
116 0x00, 0x00, 0x00, 0x00 } \
120 #define SYNT_NETDFS_V3 \
123 0x4fc742e0, 0x4a10, 0x11cf, \
124 { 0x82, 0x73, 0x00, 0xaa, \
125 0x00, 0x4a, 0xe6, 0x73 } \
129 struct pipe_id_info pipe_names [] =
131 /* client pipe , abstract syntax , server pipe , transfer syntax */
132 { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 },
133 { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
134 { PIPE_NETLOGON, SYNT_NETLOGON_V1, PIPE_LSASS , TRANS_SYNT_V2 },
135 { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 },
136 { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
137 { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 },
138 { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 },
139 { PIPE_NETDFS , SYNT_NETDFS_V3 , PIPE_NETDFS , TRANS_SYNT_V2 },
140 { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }
143 /*******************************************************************
144 Inits an RPC_HDR structure.
145 ********************************************************************/
147 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
148 uint32 call_id, int data_len, int auth_len)
150 hdr->major = 5; /* RPC version 5 */
151 hdr->minor = 0; /* minor version 0 */
152 hdr->pkt_type = pkt_type; /* RPC packet type */
153 hdr->flags = flags; /* dce/rpc flags */
154 hdr->pack_type[0] = 0x10; /* little-endian data representation */
155 hdr->pack_type[1] = 0; /* packed data representation */
156 hdr->pack_type[2] = 0; /* packed data representation */
157 hdr->pack_type[3] = 0; /* packed data representation */
158 hdr->frag_len = data_len; /* fragment length, fill in later */
159 hdr->auth_len = auth_len; /* authentication length */
160 hdr->call_id = call_id; /* call identifier - match incoming RPC */
163 /*******************************************************************
164 Reads or writes an RPC_HDR structure.
165 ********************************************************************/
167 BOOL smb_io_rpc_hdr(char *desc, RPC_HDR *rpc, prs_struct *ps, int depth)
172 prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
175 if(!prs_uint8 ("major ", ps, depth, &rpc->major))
178 if(!prs_uint8 ("minor ", ps, depth, &rpc->minor))
180 if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type))
182 if(!prs_uint8 ("flags ", ps, depth, &rpc->flags))
185 /* We always marshall in little endian format. */
187 rpc->pack_type[0] = 0x10;
189 if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
191 if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
193 if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
195 if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
199 * If reading and pack_type[0] == 0 then the data is in big-endian
200 * format. Set the flag in the prs_struct to specify reverse-endainness.
203 if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
204 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
205 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
208 if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len))
210 if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len))
212 if(!prs_uint32("call_id ", ps, depth, &rpc->call_id))
217 /*******************************************************************
218 Reads or writes an RPC_IFACE structure.
219 ********************************************************************/
221 static BOOL smb_io_rpc_iface(char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
226 prs_debug(ps, depth, desc, "smb_io_rpc_iface");
232 if(!prs_uint32 ("data ", ps, depth, &ifc->uuid.time_low))
234 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_mid))
236 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_hi_and_version))
239 if(!prs_uint8s (False, "data ", ps, depth, ifc->uuid.remaining, sizeof(ifc->uuid.remaining)))
241 if(!prs_uint32 ( "version", ps, depth, &ifc->version))
247 /*******************************************************************
248 Inits an RPC_ADDR_STR structure.
249 ********************************************************************/
251 static void init_rpc_addr_str(RPC_ADDR_STR *str, char *name)
253 str->len = strlen(name) + 1;
254 fstrcpy(str->str, name);
257 /*******************************************************************
258 Reads or writes an RPC_ADDR_STR structure.
259 ********************************************************************/
261 static BOOL smb_io_rpc_addr_str(char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth)
266 prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
271 if(!prs_uint16 ( "len", ps, depth, &str->len))
273 if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
278 /*******************************************************************
279 Inits an RPC_HDR_BBA structure.
280 ********************************************************************/
282 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
284 bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
285 bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
286 bba->assoc_gid = assoc_gid; /* associated group id (0x0) */
289 /*******************************************************************
290 Reads or writes an RPC_HDR_BBA structure.
291 ********************************************************************/
293 static BOOL smb_io_rpc_hdr_bba(char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
298 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
301 if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
303 if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
305 if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
310 /*******************************************************************
311 Inits an RPC_HDR_RB structure.
312 ********************************************************************/
314 void init_rpc_hdr_rb(RPC_HDR_RB *rpc,
315 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
316 uint32 num_elements, uint16 context_id, uint8 num_syntaxes,
317 RPC_IFACE *abstract, RPC_IFACE *transfer)
319 init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
321 rpc->num_elements = num_elements ; /* the number of elements (0x1) */
322 rpc->context_id = context_id ; /* presentation context identifier (0x0) */
323 rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */
325 /* num and vers. of interface client is using */
326 rpc->abstract = *abstract;
328 /* num and vers. of interface to use for replies */
329 rpc->transfer = *transfer;
332 /*******************************************************************
333 Reads or writes an RPC_HDR_RB structure.
334 ********************************************************************/
336 BOOL smb_io_rpc_hdr_rb(char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
341 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
344 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
347 if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements))
349 if(!prs_uint16("context_id ", ps, depth, &rpc->context_id ))
351 if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes))
354 if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth))
356 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
362 /*******************************************************************
363 Inits an RPC_RESULTS structure.
365 lkclXXXX only one reason at the moment!
366 ********************************************************************/
368 static void init_rpc_results(RPC_RESULTS *res,
369 uint8 num_results, uint16 result, uint16 reason)
371 res->num_results = num_results; /* the number of results (0x01) */
372 res->result = result ; /* result (0x00 = accept) */
373 res->reason = reason ; /* reason (0x00 = no reason specified) */
376 /*******************************************************************
377 Reads or writes an RPC_RESULTS structure.
379 lkclXXXX only one reason at the moment!
380 ********************************************************************/
382 static BOOL smb_io_rpc_results(char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
387 prs_debug(ps, depth, desc, "smb_io_rpc_results");
393 if(!prs_uint8 ("num_results", ps, depth, &res->num_results))
399 if(!prs_uint16("result ", ps, depth, &res->result))
401 if(!prs_uint16("reason ", ps, depth, &res->reason))
406 /*******************************************************************
407 Init an RPC_HDR_BA structure.
409 lkclXXXX only one reason at the moment!
411 ********************************************************************/
413 void init_rpc_hdr_ba(RPC_HDR_BA *rpc,
414 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
416 uint8 num_results, uint16 result, uint16 reason,
419 init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
420 init_rpc_addr_str(&rpc->addr, pipe_addr);
421 init_rpc_results (&rpc->res, num_results, result, reason);
423 /* the transfer syntax from the request */
424 memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
427 /*******************************************************************
428 Reads or writes an RPC_HDR_BA structure.
429 ********************************************************************/
431 BOOL smb_io_rpc_hdr_ba(char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
436 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
439 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
441 if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
443 if(!smb_io_rpc_results("", &rpc->res, ps, depth))
445 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
450 /*******************************************************************
451 Init an RPC_HDR_REQ structure.
452 ********************************************************************/
454 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
456 hdr->alloc_hint = alloc_hint; /* allocation hint */
457 hdr->context_id = 0; /* presentation context identifier */
458 hdr->opnum = opnum; /* opnum */
461 /*******************************************************************
462 Reads or writes an RPC_HDR_REQ structure.
463 ********************************************************************/
465 BOOL smb_io_rpc_hdr_req(char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
470 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
473 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
475 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
477 if(!prs_uint16("opnum ", ps, depth, &rpc->opnum))
482 /*******************************************************************
483 Reads or writes an RPC_HDR_RESP structure.
484 ********************************************************************/
486 BOOL smb_io_rpc_hdr_resp(char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
491 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
494 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
496 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
498 if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
500 if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved))
505 /*******************************************************************
506 Reads or writes an RPC_HDR_FAULT structure.
507 ********************************************************************/
509 BOOL smb_io_rpc_hdr_fault(char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
514 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
517 if(!prs_ntstatus("status ", ps, depth, &rpc->status))
519 if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
525 /*******************************************************************
526 Init an RPC_HDR_AUTHA structure.
527 ********************************************************************/
529 void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
530 uint16 max_tsize, uint16 max_rsize,
531 uint8 auth_type, uint8 auth_level,
534 rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
535 rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
537 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
538 rai->auth_level = auth_level; /* 0x06 */
539 rai->stub_type_len = stub_type_len; /* 0x00 */
540 rai->padding = 0; /* padding 0x00 */
542 rai->unknown = 0x0014a0c0; /* non-zero pointer to something */
545 /*******************************************************************
546 Reads or writes an RPC_HDR_AUTHA structure.
547 ********************************************************************/
549 BOOL smb_io_rpc_hdr_autha(char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
554 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
557 if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize))
559 if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize))
562 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
564 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
566 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
568 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
571 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
577 /*******************************************************************
578 Checks an RPC_HDR_AUTH structure.
579 ********************************************************************/
581 BOOL rpc_hdr_auth_chk(RPC_HDR_AUTH *rai)
583 return (rai->auth_type == NTLMSSP_AUTH_TYPE && rai->auth_level == NTLMSSP_AUTH_LEVEL);
586 /*******************************************************************
587 Inits an RPC_HDR_AUTH structure.
588 ********************************************************************/
590 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
591 uint8 auth_type, uint8 auth_level,
595 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
596 rai->auth_level = auth_level; /* 0x06 */
597 rai->stub_type_len = stub_type_len; /* 0x00 */
598 rai->padding = 0; /* padding 0x00 */
600 rai->unknown = ptr; /* non-zero pointer to something */
603 /*******************************************************************
604 Reads or writes an RPC_HDR_AUTH structure.
605 ********************************************************************/
607 BOOL smb_io_rpc_hdr_auth(char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
612 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
618 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
620 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
622 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
624 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
627 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
633 /*******************************************************************
634 Checks an RPC_AUTH_VERIFIER structure.
635 ********************************************************************/
637 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
638 char *signature, uint32 msg_type)
640 return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
643 /*******************************************************************
644 Inits an RPC_AUTH_VERIFIER structure.
645 ********************************************************************/
647 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
648 char *signature, uint32 msg_type)
650 fstrcpy(rav->signature, signature); /* "NTLMSSP" */
651 rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
654 /*******************************************************************
655 Reads or writes an RPC_AUTH_VERIFIER structure.
656 ********************************************************************/
658 BOOL smb_io_rpc_auth_verifier(char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
663 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
667 if(!prs_string("signature", ps, depth, rav->signature, strlen("NTLMSSP"),
668 sizeof(rav->signature)))
670 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
676 /*******************************************************************
677 Inits an RPC_AUTH_NTLMSSP_NEG structure.
678 ********************************************************************/
680 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
682 fstring myname, fstring domain)
684 int len_myname = strlen(myname);
685 int len_domain = strlen(domain);
687 neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
689 init_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname);
690 init_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20);
692 fstrcpy(neg->myname, myname);
693 fstrcpy(neg->domain, domain);
696 /*******************************************************************
697 Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
699 *** lkclXXXX HACK ALERT! ***
700 ********************************************************************/
702 BOOL smb_io_rpc_auth_ntlmssp_neg(char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
704 uint32 start_offset = prs_offset(ps);
708 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
711 if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs))
716 uint32 old_neg_flags = neg->neg_flgs;
722 neg->neg_flgs = old_neg_flags;
724 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
726 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
729 old_offset = prs_offset(ps);
731 if(!prs_set_offset(ps, neg->hdr_myname.buffer + start_offset - 12))
734 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
735 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
738 old_offset += neg->hdr_myname.str_str_len;
740 if(!prs_set_offset(ps, neg->hdr_domain.buffer + start_offset - 12))
743 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
744 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
747 old_offset += neg->hdr_domain .str_str_len;
749 if(!prs_set_offset(ps, old_offset))
753 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
755 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
758 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
759 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
761 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
762 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
769 /*******************************************************************
770 creates an RPC_AUTH_NTLMSSP_CHAL structure.
771 ********************************************************************/
773 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
777 chl->unknown_1 = 0x0;
778 chl->unknown_2 = 0x00000028;
779 chl->neg_flags = neg_flags; /* 0x0082b1 */
781 memcpy(chl->challenge, challenge, sizeof(chl->challenge));
782 memset((char *)chl->reserved , '\0', sizeof(chl->reserved));
785 /*******************************************************************
786 Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
787 ********************************************************************/
789 BOOL smb_io_rpc_auth_ntlmssp_chal(char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
794 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
797 if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */
799 if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */
801 if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */
804 if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)))
806 if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )))
812 /*******************************************************************
813 Inits an RPC_AUTH_NTLMSSP_RESP structure.
815 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
816 *** lkclXXXX the actual offset is at the start of the auth verifier ***
817 ********************************************************************/
819 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
820 uchar lm_resp[24], uchar nt_resp[24],
821 char *domain, char *user, char *wks,
825 int dom_len = strlen(domain);
826 int wks_len = strlen(wks);
827 int usr_len = strlen(user);
828 int lm_len = (lm_resp != NULL) ? 24 : 0;
829 int nt_len = (nt_resp != NULL) ? 24 : 0;
831 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
833 #ifdef DEBUG_PASSWORD
834 DEBUG(100,("lm_resp\n"));
835 dump_data(100, (char *)lm_resp, 24);
836 DEBUG(100,("nt_resp\n"));
837 dump_data(100, (char *)nt_resp, 24);
840 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
841 domain, user, wks, neg_flags));
845 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
851 init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset);
854 init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset);
857 init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset);
860 init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset);
863 init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset);
866 init_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
868 rsp->neg_flags = neg_flags;
870 memcpy(rsp->lm_resp, lm_resp, 24);
871 memcpy(rsp->nt_resp, nt_resp, 24);
873 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
874 rpcstr_push(rsp->domain, domain, sizeof(rsp->domain), 0);
875 rpcstr_push(rsp->user, user, sizeof(rsp->user), 0);
876 rpcstr_push(rsp->wks, wks, sizeof(rsp->wks), 0);
878 fstrcpy(rsp->domain, domain);
879 fstrcpy(rsp->user, user);
880 fstrcpy(rsp->wks, wks);
883 rsp->sess_key[0] = 0;
886 /*******************************************************************
887 Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
889 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
890 *** lkclXXXX the actual offset is at the start of the auth verifier ***
891 ********************************************************************/
893 BOOL smb_io_rpc_auth_ntlmssp_resp(char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
898 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
908 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
910 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
912 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
914 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
916 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
918 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
921 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
924 old_offset = prs_offset(ps);
926 if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0xc))
929 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
930 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
933 old_offset += rsp->hdr_domain.str_str_len;
935 if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0xc))
938 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
939 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
942 old_offset += rsp->hdr_usr.str_str_len;
944 if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0xc))
947 if(!prs_uint8s(True, "wks ", ps, depth, (uint8*)rsp->wks,
948 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
951 old_offset += rsp->hdr_wks.str_str_len;
953 if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0xc))
956 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
957 MIN(rsp->hdr_lm_resp.str_str_len, sizeof(rsp->lm_resp ))))
960 old_offset += rsp->hdr_lm_resp.str_str_len;
962 if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0xc))
965 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
966 MIN(rsp->hdr_nt_resp.str_str_len, sizeof(rsp->nt_resp ))))
969 old_offset += rsp->hdr_nt_resp.str_str_len;
971 if (rsp->hdr_sess_key.str_str_len != 0) {
973 if(!prs_set_offset(ps, rsp->hdr_sess_key.buffer + 0x10))
976 old_offset += rsp->hdr_sess_key.str_str_len;
978 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
979 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
983 if(!prs_set_offset(ps, old_offset))
987 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
989 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
991 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
993 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
995 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
997 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1000 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1003 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
1004 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1007 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
1008 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1011 if(!prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks,
1012 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1014 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
1015 MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp))))
1017 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1018 MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))))
1020 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1021 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1028 /*******************************************************************
1029 Checks an RPC_AUTH_NTLMSSP_CHK structure.
1030 ********************************************************************/
1032 BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num)
1037 if (chk->crc32 != crc32 ||
1038 chk->ver != NTLMSSP_SIGN_VERSION ||
1039 chk->seq_num != seq_num)
1041 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1042 crc32, NTLMSSP_SIGN_VERSION, seq_num));
1043 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1044 chk->crc32, chk->ver, chk->seq_num));
1050 /*******************************************************************
1051 Inits an RPC_AUTH_NTLMSSP_CHK structure.
1052 ********************************************************************/
1054 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
1055 uint32 ver, uint32 crc32, uint32 seq_num)
1058 chk->reserved = 0x0;
1060 chk->seq_num = seq_num;
1063 /*******************************************************************
1064 Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1065 ********************************************************************/
1067 BOOL smb_io_rpc_auth_ntlmssp_chk(char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
1072 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
1078 if(!prs_uint32("ver ", ps, depth, &chk->ver))
1080 if(!prs_uint32("reserved", ps, depth, &chk->reserved))
1082 if(!prs_uint32("crc32 ", ps, depth, &chk->crc32))
1084 if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num))