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, \
37 { 0x9f, 0xe8, 0x08, 0x00, \
38 0x2b, 0x10, 0x48, 0x60 } \
42 #define SYNT_NETLOGON_V2 \
45 0x8a885d04, 0x1ceb, 0x11c9, \
46 { 0x9f, 0xe8, 0x08, 0x00, \
47 0x2b, 0x10, 0x48, 0x60 } \
51 #define SYNT_WKSSVC_V1 \
54 0x6bffd098, 0xa112, 0x3610, \
55 { 0x98, 0x33, 0x46, 0xc3, \
56 0xf8, 0x7e, 0x34, 0x5a } \
60 #define SYNT_SRVSVC_V3 \
63 0x4b324fc8, 0x1670, 0x01d3, \
64 { 0x12, 0x78, 0x5a, 0x47, \
65 0xbf, 0x6e, 0xe1, 0x88 } \
69 #define SYNT_LSARPC_V0 \
72 0x12345778, 0x1234, 0xabcd, \
73 { 0xef, 0x00, 0x01, 0x23, \
74 0x45, 0x67, 0x89, 0xab } \
78 #define SYNT_LSARPC_V0_DS \
81 0x3919286a, 0xb10c, 0x11d0, \
82 { 0x9b, 0xa8, 0x00, 0xc0, \
83 0x4f, 0xd9, 0x2e, 0xf5 } \
87 #define SYNT_SAMR_V1 \
90 0x12345778, 0x1234, 0xabcd, \
91 { 0xef, 0x00, 0x01, 0x23, \
92 0x45, 0x67, 0x89, 0xac } \
96 #define SYNT_NETLOGON_V1 \
99 0x12345678, 0x1234, 0xabcd, \
100 { 0xef, 0x00, 0x01, 0x23, \
101 0x45, 0x67, 0xcf, 0xfb } \
105 #define SYNT_WINREG_V1 \
108 0x338cd001, 0x2244, 0x31f1, \
109 { 0xaa, 0xaa, 0x90, 0x00, \
110 0x38, 0x00, 0x10, 0x03 } \
114 #define SYNT_SPOOLSS_V1 \
117 0x12345678, 0x1234, 0xabcd, \
118 { 0xef, 0x00, 0x01, 0x23, \
119 0x45, 0x67, 0x89, 0xab } \
123 #define SYNT_NONE_V0 \
127 { 0x00, 0x00, 0x00, 0x00, \
128 0x00, 0x00, 0x00, 0x00 } \
132 #define SYNT_NETDFS_V3 \
135 0x4fc742e0, 0x4a10, 0x11cf, \
136 { 0x82, 0x73, 0x00, 0xaa, \
137 0x00, 0x4a, 0xe6, 0x73 } \
142 * IMPORTANT!! If you update this structure, make sure to
143 * update the index #defines in smb.h.
146 const struct pipe_id_info pipe_names
[] =
148 /* client pipe , abstract syntax , server pipe , transfer syntax */
149 { PIPE_LSARPC
, SYNT_LSARPC_V0
, PIPE_LSASS
, TRANS_SYNT_V2
},
150 { PIPE_LSARPC
, SYNT_LSARPC_V0_DS
, PIPE_LSASS
, TRANS_SYNT_V2
},
151 { PIPE_SAMR
, SYNT_SAMR_V1
, PIPE_LSASS
, TRANS_SYNT_V2
},
152 { PIPE_NETLOGON
, SYNT_NETLOGON_V1
, PIPE_LSASS
, TRANS_SYNT_V2
},
153 { PIPE_SRVSVC
, SYNT_SRVSVC_V3
, PIPE_NTSVCS
, TRANS_SYNT_V2
},
154 { PIPE_WKSSVC
, SYNT_WKSSVC_V1
, PIPE_NTSVCS
, TRANS_SYNT_V2
},
155 { PIPE_WINREG
, SYNT_WINREG_V1
, PIPE_WINREG
, TRANS_SYNT_V2
},
156 { PIPE_SPOOLSS
, SYNT_SPOOLSS_V1
, PIPE_SPOOLSS
, TRANS_SYNT_V2
},
157 { PIPE_NETDFS
, SYNT_NETDFS_V3
, PIPE_NETDFS
, TRANS_SYNT_V2
},
158 { NULL
, SYNT_NONE_V0
, NULL
, SYNT_NONE_V0
}
161 /*******************************************************************
162 Inits an RPC_HDR structure.
163 ********************************************************************/
165 void init_rpc_hdr(RPC_HDR
*hdr
, enum RPC_PKT_TYPE pkt_type
, uint8 flags
,
166 uint32 call_id
, int data_len
, int auth_len
)
168 hdr
->major
= 5; /* RPC version 5 */
169 hdr
->minor
= 0; /* minor version 0 */
170 hdr
->pkt_type
= pkt_type
; /* RPC packet type */
171 hdr
->flags
= flags
; /* dce/rpc flags */
172 hdr
->pack_type
[0] = 0x10; /* little-endian data representation */
173 hdr
->pack_type
[1] = 0; /* packed data representation */
174 hdr
->pack_type
[2] = 0; /* packed data representation */
175 hdr
->pack_type
[3] = 0; /* packed data representation */
176 hdr
->frag_len
= data_len
; /* fragment length, fill in later */
177 hdr
->auth_len
= auth_len
; /* authentication length */
178 hdr
->call_id
= call_id
; /* call identifier - match incoming RPC */
181 /*******************************************************************
182 Reads or writes an RPC_HDR structure.
183 ********************************************************************/
185 BOOL
smb_io_rpc_hdr(const char *desc
, RPC_HDR
*rpc
, prs_struct
*ps
, int depth
)
190 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr");
193 if(!prs_uint8 ("major ", ps
, depth
, &rpc
->major
))
196 if(!prs_uint8 ("minor ", ps
, depth
, &rpc
->minor
))
198 if(!prs_uint8 ("pkt_type ", ps
, depth
, &rpc
->pkt_type
))
200 if(!prs_uint8 ("flags ", ps
, depth
, &rpc
->flags
))
203 /* We always marshall in little endian format. */
205 rpc
->pack_type
[0] = 0x10;
207 if(!prs_uint8("pack_type0", ps
, depth
, &rpc
->pack_type
[0]))
209 if(!prs_uint8("pack_type1", ps
, depth
, &rpc
->pack_type
[1]))
211 if(!prs_uint8("pack_type2", ps
, depth
, &rpc
->pack_type
[2]))
213 if(!prs_uint8("pack_type3", ps
, depth
, &rpc
->pack_type
[3]))
217 * If reading and pack_type[0] == 0 then the data is in big-endian
218 * format. Set the flag in the prs_struct to specify reverse-endainness.
221 if (UNMARSHALLING(ps
) && rpc
->pack_type
[0] == 0) {
222 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
223 prs_set_endian_data(ps
, RPC_BIG_ENDIAN
);
226 if(!prs_uint16("frag_len ", ps
, depth
, &rpc
->frag_len
))
228 if(!prs_uint16("auth_len ", ps
, depth
, &rpc
->auth_len
))
230 if(!prs_uint32("call_id ", ps
, depth
, &rpc
->call_id
))
235 /*******************************************************************
236 Reads or writes an RPC_IFACE structure.
237 ********************************************************************/
239 static BOOL
smb_io_rpc_iface(const char *desc
, RPC_IFACE
*ifc
, prs_struct
*ps
, int depth
)
244 prs_debug(ps
, depth
, desc
, "smb_io_rpc_iface");
250 if(!prs_uint32 ("data ", ps
, depth
, &ifc
->uuid
.time_low
))
252 if(!prs_uint16 ("data ", ps
, depth
, &ifc
->uuid
.time_mid
))
254 if(!prs_uint16 ("data ", ps
, depth
, &ifc
->uuid
.time_hi_and_version
))
257 if(!prs_uint8s (False
, "data ", ps
, depth
, ifc
->uuid
.remaining
, sizeof(ifc
->uuid
.remaining
)))
259 if(!prs_uint32 ( "version", ps
, depth
, &ifc
->version
))
265 /*******************************************************************
266 Inits an RPC_ADDR_STR structure.
267 ********************************************************************/
269 static void init_rpc_addr_str(RPC_ADDR_STR
*str
, const char *name
)
271 str
->len
= strlen(name
) + 1;
272 fstrcpy(str
->str
, name
);
275 /*******************************************************************
276 Reads or writes an RPC_ADDR_STR structure.
277 ********************************************************************/
279 static BOOL
smb_io_rpc_addr_str(const char *desc
, RPC_ADDR_STR
*str
, prs_struct
*ps
, int depth
)
284 prs_debug(ps
, depth
, desc
, "smb_io_rpc_addr_str");
289 if(!prs_uint16 ( "len", ps
, depth
, &str
->len
))
291 if(!prs_uint8s (True
, "str", ps
, depth
, (uchar
*)str
->str
, MIN(str
->len
, sizeof(str
->str
)) ))
296 /*******************************************************************
297 Inits an RPC_HDR_BBA structure.
298 ********************************************************************/
300 static void init_rpc_hdr_bba(RPC_HDR_BBA
*bba
, uint16 max_tsize
, uint16 max_rsize
, uint32 assoc_gid
)
302 bba
->max_tsize
= max_tsize
; /* maximum transmission fragment size (0x1630) */
303 bba
->max_rsize
= max_rsize
; /* max receive fragment size (0x1630) */
304 bba
->assoc_gid
= assoc_gid
; /* associated group id (0x0) */
307 /*******************************************************************
308 Reads or writes an RPC_HDR_BBA structure.
309 ********************************************************************/
311 static BOOL
smb_io_rpc_hdr_bba(const char *desc
, RPC_HDR_BBA
*rpc
, prs_struct
*ps
, int depth
)
316 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_bba");
319 if(!prs_uint16("max_tsize", ps
, depth
, &rpc
->max_tsize
))
321 if(!prs_uint16("max_rsize", ps
, depth
, &rpc
->max_rsize
))
323 if(!prs_uint32("assoc_gid", ps
, depth
, &rpc
->assoc_gid
))
328 /*******************************************************************
329 Inits an RPC_HDR_RB structure.
330 ********************************************************************/
332 void init_rpc_hdr_rb(RPC_HDR_RB
*rpc
,
333 uint16 max_tsize
, uint16 max_rsize
, uint32 assoc_gid
,
334 uint32 num_elements
, uint16 context_id
, uint8 num_syntaxes
,
335 RPC_IFACE
*abstract
, RPC_IFACE
*transfer
)
337 init_rpc_hdr_bba(&rpc
->bba
, max_tsize
, max_rsize
, assoc_gid
);
339 rpc
->num_elements
= num_elements
; /* the number of elements (0x1) */
340 rpc
->context_id
= context_id
; /* presentation context identifier (0x0) */
341 rpc
->num_syntaxes
= num_syntaxes
; /* the number of syntaxes (has always been 1?)(0x1) */
343 /* num and vers. of interface client is using */
344 rpc
->abstract
= *abstract
;
346 /* num and vers. of interface to use for replies */
347 rpc
->transfer
= *transfer
;
350 /*******************************************************************
351 Reads or writes an RPC_HDR_RB structure.
352 ********************************************************************/
354 BOOL
smb_io_rpc_hdr_rb(const char *desc
, RPC_HDR_RB
*rpc
, prs_struct
*ps
, int depth
)
359 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_rb");
362 if(!smb_io_rpc_hdr_bba("", &rpc
->bba
, ps
, depth
))
365 if(!prs_uint32("num_elements", ps
, depth
, &rpc
->num_elements
))
367 if(!prs_uint16("context_id ", ps
, depth
, &rpc
->context_id
))
369 if(!prs_uint8 ("num_syntaxes", ps
, depth
, &rpc
->num_syntaxes
))
372 if(!smb_io_rpc_iface("", &rpc
->abstract
, ps
, depth
))
374 if(!smb_io_rpc_iface("", &rpc
->transfer
, ps
, depth
))
380 /*******************************************************************
381 Inits an RPC_RESULTS structure.
383 lkclXXXX only one reason at the moment!
384 ********************************************************************/
386 static void init_rpc_results(RPC_RESULTS
*res
,
387 uint8 num_results
, uint16 result
, uint16 reason
)
389 res
->num_results
= num_results
; /* the number of results (0x01) */
390 res
->result
= result
; /* result (0x00 = accept) */
391 res
->reason
= reason
; /* reason (0x00 = no reason specified) */
394 /*******************************************************************
395 Reads or writes an RPC_RESULTS structure.
397 lkclXXXX only one reason at the moment!
398 ********************************************************************/
400 static BOOL
smb_io_rpc_results(const char *desc
, RPC_RESULTS
*res
, prs_struct
*ps
, int depth
)
405 prs_debug(ps
, depth
, desc
, "smb_io_rpc_results");
411 if(!prs_uint8 ("num_results", ps
, depth
, &res
->num_results
))
417 if(!prs_uint16("result ", ps
, depth
, &res
->result
))
419 if(!prs_uint16("reason ", ps
, depth
, &res
->reason
))
424 /*******************************************************************
425 Init an RPC_HDR_BA structure.
427 lkclXXXX only one reason at the moment!
429 ********************************************************************/
431 void init_rpc_hdr_ba(RPC_HDR_BA
*rpc
,
432 uint16 max_tsize
, uint16 max_rsize
, uint32 assoc_gid
,
433 const char *pipe_addr
,
434 uint8 num_results
, uint16 result
, uint16 reason
,
437 init_rpc_hdr_bba (&rpc
->bba
, max_tsize
, max_rsize
, assoc_gid
);
438 init_rpc_addr_str(&rpc
->addr
, pipe_addr
);
439 init_rpc_results (&rpc
->res
, num_results
, result
, reason
);
441 /* the transfer syntax from the request */
442 memcpy(&rpc
->transfer
, transfer
, sizeof(rpc
->transfer
));
445 /*******************************************************************
446 Reads or writes an RPC_HDR_BA structure.
447 ********************************************************************/
449 BOOL
smb_io_rpc_hdr_ba(const char *desc
, RPC_HDR_BA
*rpc
, prs_struct
*ps
, int depth
)
454 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_ba");
457 if(!smb_io_rpc_hdr_bba("", &rpc
->bba
, ps
, depth
))
459 if(!smb_io_rpc_addr_str("", &rpc
->addr
, ps
, depth
))
461 if(!smb_io_rpc_results("", &rpc
->res
, ps
, depth
))
463 if(!smb_io_rpc_iface("", &rpc
->transfer
, ps
, depth
))
468 /*******************************************************************
469 Init an RPC_HDR_REQ structure.
470 ********************************************************************/
472 void init_rpc_hdr_req(RPC_HDR_REQ
*hdr
, uint32 alloc_hint
, uint16 opnum
)
474 hdr
->alloc_hint
= alloc_hint
; /* allocation hint */
475 hdr
->context_id
= 0; /* presentation context identifier */
476 hdr
->opnum
= opnum
; /* opnum */
479 /*******************************************************************
480 Reads or writes an RPC_HDR_REQ structure.
481 ********************************************************************/
483 BOOL
smb_io_rpc_hdr_req(const char *desc
, RPC_HDR_REQ
*rpc
, prs_struct
*ps
, int depth
)
488 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_req");
491 if(!prs_uint32("alloc_hint", ps
, depth
, &rpc
->alloc_hint
))
493 if(!prs_uint16("context_id", ps
, depth
, &rpc
->context_id
))
495 if(!prs_uint16("opnum ", ps
, depth
, &rpc
->opnum
))
500 /*******************************************************************
501 Reads or writes an RPC_HDR_RESP structure.
502 ********************************************************************/
504 BOOL
smb_io_rpc_hdr_resp(const char *desc
, RPC_HDR_RESP
*rpc
, prs_struct
*ps
, int depth
)
509 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_resp");
512 if(!prs_uint32("alloc_hint", ps
, depth
, &rpc
->alloc_hint
))
514 if(!prs_uint16("context_id", ps
, depth
, &rpc
->context_id
))
516 if(!prs_uint8 ("cancel_ct ", ps
, depth
, &rpc
->cancel_count
))
518 if(!prs_uint8 ("reserved ", ps
, depth
, &rpc
->reserved
))
523 /*******************************************************************
524 Reads or writes an RPC_HDR_FAULT structure.
525 ********************************************************************/
527 BOOL
smb_io_rpc_hdr_fault(const char *desc
, RPC_HDR_FAULT
*rpc
, prs_struct
*ps
, int depth
)
532 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_fault");
535 if(!prs_ntstatus("status ", ps
, depth
, &rpc
->status
))
537 if(!prs_uint32("reserved", ps
, depth
, &rpc
->reserved
))
543 /*******************************************************************
544 Init an RPC_HDR_AUTHA structure.
545 ********************************************************************/
547 void init_rpc_hdr_autha(RPC_HDR_AUTHA
*rai
,
548 uint16 max_tsize
, uint16 max_rsize
,
549 uint8 auth_type
, uint8 auth_level
,
552 rai
->max_tsize
= max_tsize
; /* maximum transmission fragment size (0x1630) */
553 rai
->max_rsize
= max_rsize
; /* max receive fragment size (0x1630) */
555 rai
->auth_type
= auth_type
; /* nt lm ssp 0x0a */
556 rai
->auth_level
= auth_level
; /* 0x06 */
557 rai
->stub_type_len
= stub_type_len
; /* 0x00 */
558 rai
->padding
= 0; /* padding 0x00 */
560 rai
->unknown
= 0x0014a0c0; /* non-zero pointer to something */
563 /*******************************************************************
564 Reads or writes an RPC_HDR_AUTHA structure.
565 ********************************************************************/
567 BOOL
smb_io_rpc_hdr_autha(const char *desc
, RPC_HDR_AUTHA
*rai
, prs_struct
*ps
, int depth
)
572 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_autha");
575 if(!prs_uint16("max_tsize ", ps
, depth
, &rai
->max_tsize
))
577 if(!prs_uint16("max_rsize ", ps
, depth
, &rai
->max_rsize
))
580 if(!prs_uint8 ("auth_type ", ps
, depth
, &rai
->auth_type
)) /* 0x0a nt lm ssp */
582 if(!prs_uint8 ("auth_level ", ps
, depth
, &rai
->auth_level
)) /* 0x06 */
584 if(!prs_uint8 ("stub_type_len", ps
, depth
, &rai
->stub_type_len
))
586 if(!prs_uint8 ("padding ", ps
, depth
, &rai
->padding
))
589 if(!prs_uint32("unknown ", ps
, depth
, &rai
->unknown
)) /* 0x0014a0c0 */
595 /*******************************************************************
596 Checks an RPC_HDR_AUTH structure.
597 ********************************************************************/
599 BOOL
rpc_hdr_auth_chk(RPC_HDR_AUTH
*rai
)
601 return (rai
->auth_type
== NTLMSSP_AUTH_TYPE
&& rai
->auth_level
== NTLMSSP_AUTH_LEVEL
);
604 /*******************************************************************
605 Inits an RPC_HDR_AUTH structure.
606 ********************************************************************/
608 void init_rpc_hdr_auth(RPC_HDR_AUTH
*rai
,
609 uint8 auth_type
, uint8 auth_level
,
613 rai
->auth_type
= auth_type
; /* nt lm ssp 0x0a */
614 rai
->auth_level
= auth_level
; /* 0x06 */
615 rai
->stub_type_len
= stub_type_len
; /* 0x00 */
616 rai
->padding
= 0; /* padding 0x00 */
618 rai
->unknown
= ptr
; /* non-zero pointer to something */
621 /*******************************************************************
622 Reads or writes an RPC_HDR_AUTH structure.
623 ********************************************************************/
625 BOOL
smb_io_rpc_hdr_auth(const char *desc
, RPC_HDR_AUTH
*rai
, prs_struct
*ps
, int depth
)
630 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_auth");
636 if(!prs_uint8 ("auth_type ", ps
, depth
, &rai
->auth_type
)) /* 0x0a nt lm ssp */
638 if(!prs_uint8 ("auth_level ", ps
, depth
, &rai
->auth_level
)) /* 0x06 */
640 if(!prs_uint8 ("stub_type_len", ps
, depth
, &rai
->stub_type_len
))
642 if(!prs_uint8 ("padding ", ps
, depth
, &rai
->padding
))
645 if(!prs_uint32("unknown ", ps
, depth
, &rai
->unknown
)) /* 0x0014a0c0 */
651 /*******************************************************************
652 Checks an RPC_AUTH_VERIFIER structure.
653 ********************************************************************/
655 BOOL
rpc_auth_verifier_chk(RPC_AUTH_VERIFIER
*rav
,
656 const char *signature
, uint32 msg_type
)
658 return (strequal(rav
->signature
, signature
) && rav
->msg_type
== msg_type
);
661 /*******************************************************************
662 Inits an RPC_AUTH_VERIFIER structure.
663 ********************************************************************/
665 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER
*rav
,
666 const char *signature
, uint32 msg_type
)
668 fstrcpy(rav
->signature
, signature
); /* "NTLMSSP" */
669 rav
->msg_type
= msg_type
; /* NTLMSSP_MESSAGE_TYPE */
672 /*******************************************************************
673 Reads or writes an RPC_AUTH_VERIFIER structure.
674 ********************************************************************/
676 BOOL
smb_io_rpc_auth_verifier(const char *desc
, RPC_AUTH_VERIFIER
*rav
, prs_struct
*ps
, int depth
)
681 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_verifier");
685 if(!prs_string("signature", ps
, depth
, rav
->signature
, strlen("NTLMSSP"),
686 sizeof(rav
->signature
)))
688 if(!prs_uint32("msg_type ", ps
, depth
, &rav
->msg_type
)) /* NTLMSSP_MESSAGE_TYPE */
694 /*******************************************************************
695 Inits an RPC_AUTH_NTLMSSP_NEG structure.
696 ********************************************************************/
698 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG
*neg
,
700 const char *myname
, const char *domain
)
702 int len_myname
= strlen(myname
);
703 int len_domain
= strlen(domain
);
705 neg
->neg_flgs
= neg_flgs
; /* 0x00b2b3 */
707 init_str_hdr(&neg
->hdr_domain
, len_domain
, len_domain
, 0x20 + len_myname
);
708 init_str_hdr(&neg
->hdr_myname
, len_myname
, len_myname
, 0x20);
710 fstrcpy(neg
->myname
, myname
);
711 fstrcpy(neg
->domain
, domain
);
714 /*******************************************************************
715 Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
717 *** lkclXXXX HACK ALERT! ***
718 ********************************************************************/
720 BOOL
smb_io_rpc_auth_ntlmssp_neg(const char *desc
, RPC_AUTH_NTLMSSP_NEG
*neg
, prs_struct
*ps
, int depth
)
722 uint32 start_offset
= prs_offset(ps
);
726 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_neg");
729 if(!prs_uint32("neg_flgs ", ps
, depth
, &neg
->neg_flgs
))
734 uint32 old_neg_flags
= neg
->neg_flgs
;
740 neg
->neg_flgs
= old_neg_flags
;
742 if(!smb_io_strhdr("hdr_domain", &neg
->hdr_domain
, ps
, depth
))
744 if(!smb_io_strhdr("hdr_myname", &neg
->hdr_myname
, ps
, depth
))
747 old_offset
= prs_offset(ps
);
749 if(!prs_set_offset(ps
, neg
->hdr_myname
.buffer
+ start_offset
- 12))
752 if(!prs_uint8s(True
, "myname", ps
, depth
, (uint8
*)neg
->myname
,
753 MIN(neg
->hdr_myname
.str_str_len
, sizeof(neg
->myname
))))
756 old_offset
+= neg
->hdr_myname
.str_str_len
;
758 if(!prs_set_offset(ps
, neg
->hdr_domain
.buffer
+ start_offset
- 12))
761 if(!prs_uint8s(True
, "domain", ps
, depth
, (uint8
*)neg
->domain
,
762 MIN(neg
->hdr_domain
.str_str_len
, sizeof(neg
->domain
))))
765 old_offset
+= neg
->hdr_domain
.str_str_len
;
767 if(!prs_set_offset(ps
, old_offset
))
771 if(!smb_io_strhdr("hdr_domain", &neg
->hdr_domain
, ps
, depth
))
773 if(!smb_io_strhdr("hdr_myname", &neg
->hdr_myname
, ps
, depth
))
776 if(!prs_uint8s(True
, "myname", ps
, depth
, (uint8
*)neg
->myname
,
777 MIN(neg
->hdr_myname
.str_str_len
, sizeof(neg
->myname
))))
779 if(!prs_uint8s(True
, "domain", ps
, depth
, (uint8
*)neg
->domain
,
780 MIN(neg
->hdr_domain
.str_str_len
, sizeof(neg
->domain
))))
787 /*******************************************************************
788 creates an RPC_AUTH_NTLMSSP_CHAL structure.
789 ********************************************************************/
791 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL
*chl
,
795 chl
->unknown_1
= 0x0;
796 chl
->unknown_2
= 0x00000028;
797 chl
->neg_flags
= neg_flags
; /* 0x0082b1 */
799 memcpy(chl
->challenge
, challenge
, sizeof(chl
->challenge
));
800 memset((char *)chl
->reserved
, '\0', sizeof(chl
->reserved
));
803 /*******************************************************************
804 Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
805 ********************************************************************/
807 BOOL
smb_io_rpc_auth_ntlmssp_chal(const char *desc
, RPC_AUTH_NTLMSSP_CHAL
*chl
, prs_struct
*ps
, int depth
)
812 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_chal");
815 if(!prs_uint32("unknown_1", ps
, depth
, &chl
->unknown_1
)) /* 0x0000 0000 */
817 if(!prs_uint32("unknown_2", ps
, depth
, &chl
->unknown_2
)) /* 0x0000 b2b3 */
819 if(!prs_uint32("neg_flags", ps
, depth
, &chl
->neg_flags
)) /* 0x0000 82b1 */
822 if(!prs_uint8s (False
, "challenge", ps
, depth
, chl
->challenge
, sizeof(chl
->challenge
)))
824 if(!prs_uint8s (False
, "reserved ", ps
, depth
, chl
->reserved
, sizeof(chl
->reserved
)))
830 /*******************************************************************
831 Inits an RPC_AUTH_NTLMSSP_RESP structure.
833 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
834 *** lkclXXXX the actual offset is at the start of the auth verifier ***
835 ********************************************************************/
837 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP
*rsp
,
838 uchar lm_resp
[24], uchar nt_resp
[24],
839 const char *domain
, const char *user
, const char *wks
,
843 int dom_len
= strlen(domain
);
844 int wks_len
= strlen(wks
);
845 int usr_len
= strlen(user
);
846 int lm_len
= (lm_resp
!= NULL
) ? 24 : 0;
847 int nt_len
= (nt_resp
!= NULL
) ? 24 : 0;
849 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
851 #ifdef DEBUG_PASSWORD
852 DEBUG(100,("lm_resp\n"));
853 dump_data(100, (char *)lm_resp
, 24);
854 DEBUG(100,("nt_resp\n"));
855 dump_data(100, (char *)nt_resp
, 24);
858 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
859 domain
, user
, wks
, neg_flags
));
863 if (neg_flags
& NTLMSSP_NEGOTIATE_UNICODE
) {
869 init_str_hdr(&rsp
->hdr_domain
, dom_len
, dom_len
, offset
);
872 init_str_hdr(&rsp
->hdr_usr
, usr_len
, usr_len
, offset
);
875 init_str_hdr(&rsp
->hdr_wks
, wks_len
, wks_len
, offset
);
878 init_str_hdr(&rsp
->hdr_lm_resp
, lm_len
, lm_len
, offset
);
881 init_str_hdr(&rsp
->hdr_nt_resp
, nt_len
, nt_len
, offset
);
884 init_str_hdr(&rsp
->hdr_sess_key
, 0, 0, offset
);
886 rsp
->neg_flags
= neg_flags
;
888 memcpy(rsp
->lm_resp
, lm_resp
, 24);
889 memcpy(rsp
->nt_resp
, nt_resp
, 24);
891 if (neg_flags
& NTLMSSP_NEGOTIATE_UNICODE
) {
892 rpcstr_push(rsp
->domain
, domain
, sizeof(rsp
->domain
), 0);
893 rpcstr_push(rsp
->user
, user
, sizeof(rsp
->user
), 0);
894 rpcstr_push(rsp
->wks
, wks
, sizeof(rsp
->wks
), 0);
896 fstrcpy(rsp
->domain
, domain
);
897 fstrcpy(rsp
->user
, user
);
898 fstrcpy(rsp
->wks
, wks
);
901 rsp
->sess_key
[0] = 0;
904 /*******************************************************************
905 Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
907 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
908 *** lkclXXXX the actual offset is at the start of the auth verifier ***
909 ********************************************************************/
911 BOOL
smb_io_rpc_auth_ntlmssp_resp(const char *desc
, RPC_AUTH_NTLMSSP_RESP
*rsp
, prs_struct
*ps
, int depth
)
916 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_resp");
926 if(!smb_io_strhdr("hdr_lm_resp ", &rsp
->hdr_lm_resp
, ps
, depth
))
928 if(!smb_io_strhdr("hdr_nt_resp ", &rsp
->hdr_nt_resp
, ps
, depth
))
930 if(!smb_io_strhdr("hdr_domain ", &rsp
->hdr_domain
, ps
, depth
))
932 if(!smb_io_strhdr("hdr_user ", &rsp
->hdr_usr
, ps
, depth
))
934 if(!smb_io_strhdr("hdr_wks ", &rsp
->hdr_wks
, ps
, depth
))
936 if(!smb_io_strhdr("hdr_sess_key", &rsp
->hdr_sess_key
, ps
, depth
))
939 if(!prs_uint32("neg_flags", ps
, depth
, &rsp
->neg_flags
)) /* 0x0000 82b1 */
942 old_offset
= prs_offset(ps
);
944 if(!prs_set_offset(ps
, rsp
->hdr_domain
.buffer
+ 0xc))
947 if(!prs_uint8s(True
, "domain ", ps
, depth
, (uint8
*)rsp
->domain
,
948 MIN(rsp
->hdr_domain
.str_str_len
, sizeof(rsp
->domain
))))
951 old_offset
+= rsp
->hdr_domain
.str_str_len
;
953 if(!prs_set_offset(ps
, rsp
->hdr_usr
.buffer
+ 0xc))
956 if(!prs_uint8s(True
, "user ", ps
, depth
, (uint8
*)rsp
->user
,
957 MIN(rsp
->hdr_usr
.str_str_len
, sizeof(rsp
->user
))))
960 old_offset
+= rsp
->hdr_usr
.str_str_len
;
962 if(!prs_set_offset(ps
, rsp
->hdr_wks
.buffer
+ 0xc))
965 if(!prs_uint8s(True
, "wks ", ps
, depth
, (uint8
*)rsp
->wks
,
966 MIN(rsp
->hdr_wks
.str_str_len
, sizeof(rsp
->wks
))))
969 old_offset
+= rsp
->hdr_wks
.str_str_len
;
971 if(!prs_set_offset(ps
, rsp
->hdr_lm_resp
.buffer
+ 0xc))
974 if(!prs_uint8s(False
, "lm_resp ", ps
, depth
, (uint8
*)rsp
->lm_resp
,
975 MIN(rsp
->hdr_lm_resp
.str_str_len
, sizeof(rsp
->lm_resp
))))
978 old_offset
+= rsp
->hdr_lm_resp
.str_str_len
;
980 if(!prs_set_offset(ps
, rsp
->hdr_nt_resp
.buffer
+ 0xc))
983 if(!prs_uint8s(False
, "nt_resp ", ps
, depth
, (uint8
*)rsp
->nt_resp
,
984 MIN(rsp
->hdr_nt_resp
.str_str_len
, sizeof(rsp
->nt_resp
))))
987 old_offset
+= rsp
->hdr_nt_resp
.str_str_len
;
989 if (rsp
->hdr_sess_key
.str_str_len
!= 0) {
991 if(!prs_set_offset(ps
, rsp
->hdr_sess_key
.buffer
+ 0x10))
994 old_offset
+= rsp
->hdr_sess_key
.str_str_len
;
996 if(!prs_uint8s(False
, "sess_key", ps
, depth
, (uint8
*)rsp
->sess_key
,
997 MIN(rsp
->hdr_sess_key
.str_str_len
, sizeof(rsp
->sess_key
))))
1001 if(!prs_set_offset(ps
, old_offset
))
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 if(!prs_uint8s(True
, "domain ", ps
, depth
, (uint8
*)rsp
->domain
,
1022 MIN(rsp
->hdr_domain
.str_str_len
, sizeof(rsp
->domain
))))
1025 if(!prs_uint8s(True
, "user ", ps
, depth
, (uint8
*)rsp
->user
,
1026 MIN(rsp
->hdr_usr
.str_str_len
, sizeof(rsp
->user
))))
1029 if(!prs_uint8s(True
, "wks ", ps
, depth
, (uint8
*)rsp
->wks
,
1030 MIN(rsp
->hdr_wks
.str_str_len
, sizeof(rsp
->wks
))))
1032 if(!prs_uint8s(False
, "lm_resp ", ps
, depth
, (uint8
*)rsp
->lm_resp
,
1033 MIN(rsp
->hdr_lm_resp
.str_str_len
, sizeof(rsp
->lm_resp
))))
1035 if(!prs_uint8s(False
, "nt_resp ", ps
, depth
, (uint8
*)rsp
->nt_resp
,
1036 MIN(rsp
->hdr_nt_resp
.str_str_len
, sizeof(rsp
->nt_resp
))))
1038 if(!prs_uint8s(False
, "sess_key", ps
, depth
, (uint8
*)rsp
->sess_key
,
1039 MIN(rsp
->hdr_sess_key
.str_str_len
, sizeof(rsp
->sess_key
))))
1046 /*******************************************************************
1047 Checks an RPC_AUTH_NTLMSSP_CHK structure.
1048 ********************************************************************/
1050 BOOL
rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK
*chk
, uint32 crc32
, uint32 seq_num
)
1055 if (chk
->crc32
!= crc32
||
1056 chk
->ver
!= NTLMSSP_SIGN_VERSION
||
1057 chk
->seq_num
!= seq_num
)
1059 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1060 crc32
, NTLMSSP_SIGN_VERSION
, seq_num
));
1061 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1062 chk
->crc32
, chk
->ver
, chk
->seq_num
));
1068 /*******************************************************************
1069 Inits an RPC_AUTH_NTLMSSP_CHK structure.
1070 ********************************************************************/
1072 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK
*chk
,
1073 uint32 ver
, uint32 crc32
, uint32 seq_num
)
1076 chk
->reserved
= 0x0;
1078 chk
->seq_num
= seq_num
;
1081 /*******************************************************************
1082 Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1083 ********************************************************************/
1085 BOOL
smb_io_rpc_auth_ntlmssp_chk(const char *desc
, RPC_AUTH_NTLMSSP_CHK
*chk
, prs_struct
*ps
, int depth
)
1090 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_chk");
1096 if(!prs_uint32("ver ", ps
, depth
, &chk
->ver
))
1098 if(!prs_uint32("reserved", ps
, depth
, &chk
->reserved
))
1100 if(!prs_uint32("crc32 ", ps
, depth
, &chk
->crc32
))
1102 if(!prs_uint32("seq_num ", ps
, depth
, &chk
->seq_num
))