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
)
336 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_rb");
339 if(!smb_io_rpc_hdr_bba("", &rpc
->bba
, ps
, depth
))
342 if(!prs_uint32("num_elements", ps
, depth
, &rpc
->num_elements
))
344 if(!prs_uint16("context_id ", ps
, depth
, &rpc
->context_id
))
346 if(!prs_uint8 ("num_syntaxes", ps
, depth
, &rpc
->num_syntaxes
))
349 if(!smb_io_rpc_iface("", &rpc
->abstract
, ps
, depth
))
351 if(!smb_io_rpc_iface("", &rpc
->transfer
, ps
, depth
))
354 /* just chew through extra context id's for now */
356 for ( i
=1; i
<rpc
->num_elements
; i
++ ) {
357 if(!prs_uint16("context_id ", ps
, depth
, &rpc2
.context_id
))
359 if(!prs_uint8 ("num_syntaxes", ps
, depth
, &rpc2
.num_syntaxes
))
362 if(!smb_io_rpc_iface("", &rpc2
.abstract
, ps
, depth
))
364 if(!smb_io_rpc_iface("", &rpc2
.transfer
, ps
, depth
))
371 /*******************************************************************
372 Inits an RPC_RESULTS structure.
374 lkclXXXX only one reason at the moment!
375 ********************************************************************/
377 static void init_rpc_results(RPC_RESULTS
*res
,
378 uint8 num_results
, uint16 result
, uint16 reason
)
380 res
->num_results
= num_results
; /* the number of results (0x01) */
381 res
->result
= result
; /* result (0x00 = accept) */
382 res
->reason
= reason
; /* reason (0x00 = no reason specified) */
385 /*******************************************************************
386 Reads or writes an RPC_RESULTS structure.
388 lkclXXXX only one reason at the moment!
389 ********************************************************************/
391 static BOOL
smb_io_rpc_results(char *desc
, RPC_RESULTS
*res
, prs_struct
*ps
, int depth
)
396 prs_debug(ps
, depth
, desc
, "smb_io_rpc_results");
402 if(!prs_uint8 ("num_results", ps
, depth
, &res
->num_results
))
408 if(!prs_uint16("result ", ps
, depth
, &res
->result
))
410 if(!prs_uint16("reason ", ps
, depth
, &res
->reason
))
415 /*******************************************************************
416 Init an RPC_HDR_BA structure.
418 lkclXXXX only one reason at the moment!
420 ********************************************************************/
422 void init_rpc_hdr_ba(RPC_HDR_BA
*rpc
,
423 uint16 max_tsize
, uint16 max_rsize
, uint32 assoc_gid
,
425 uint8 num_results
, uint16 result
, uint16 reason
,
428 init_rpc_hdr_bba (&rpc
->bba
, max_tsize
, max_rsize
, assoc_gid
);
429 init_rpc_addr_str(&rpc
->addr
, pipe_addr
);
430 init_rpc_results (&rpc
->res
, num_results
, result
, reason
);
432 /* the transfer syntax from the request */
433 memcpy(&rpc
->transfer
, transfer
, sizeof(rpc
->transfer
));
436 /*******************************************************************
437 Reads or writes an RPC_HDR_BA structure.
438 ********************************************************************/
440 BOOL
smb_io_rpc_hdr_ba(char *desc
, RPC_HDR_BA
*rpc
, prs_struct
*ps
, int depth
)
445 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_ba");
448 if(!smb_io_rpc_hdr_bba("", &rpc
->bba
, ps
, depth
))
450 if(!smb_io_rpc_addr_str("", &rpc
->addr
, ps
, depth
))
452 if(!smb_io_rpc_results("", &rpc
->res
, ps
, depth
))
454 if(!smb_io_rpc_iface("", &rpc
->transfer
, ps
, depth
))
459 /*******************************************************************
460 Init an RPC_HDR_REQ structure.
461 ********************************************************************/
463 void init_rpc_hdr_req(RPC_HDR_REQ
*hdr
, uint32 alloc_hint
, uint16 opnum
)
465 hdr
->alloc_hint
= alloc_hint
; /* allocation hint */
466 hdr
->context_id
= 0; /* presentation context identifier */
467 hdr
->opnum
= opnum
; /* opnum */
470 /*******************************************************************
471 Reads or writes an RPC_HDR_REQ structure.
472 ********************************************************************/
474 BOOL
smb_io_rpc_hdr_req(char *desc
, RPC_HDR_REQ
*rpc
, prs_struct
*ps
, int depth
)
479 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_req");
482 if(!prs_uint32("alloc_hint", ps
, depth
, &rpc
->alloc_hint
))
484 if(!prs_uint16("context_id", ps
, depth
, &rpc
->context_id
))
486 if(!prs_uint16("opnum ", ps
, depth
, &rpc
->opnum
))
491 /*******************************************************************
492 Reads or writes an RPC_HDR_RESP structure.
493 ********************************************************************/
495 BOOL
smb_io_rpc_hdr_resp(char *desc
, RPC_HDR_RESP
*rpc
, prs_struct
*ps
, int depth
)
500 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_resp");
503 if(!prs_uint32("alloc_hint", ps
, depth
, &rpc
->alloc_hint
))
505 if(!prs_uint16("context_id", ps
, depth
, &rpc
->context_id
))
507 if(!prs_uint8 ("cancel_ct ", ps
, depth
, &rpc
->cancel_count
))
509 if(!prs_uint8 ("reserved ", ps
, depth
, &rpc
->reserved
))
514 /*******************************************************************
515 Reads or writes an RPC_HDR_FAULT structure.
516 ********************************************************************/
518 BOOL
smb_io_rpc_hdr_fault(char *desc
, RPC_HDR_FAULT
*rpc
, prs_struct
*ps
, int depth
)
523 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_fault");
526 if(!prs_uint32("status ", ps
, depth
, &rpc
->status
))
528 if(!prs_uint32("reserved", ps
, depth
, &rpc
->reserved
))
534 /*******************************************************************
535 Init an RPC_HDR_AUTHA structure.
536 ********************************************************************/
538 void init_rpc_hdr_autha(RPC_HDR_AUTHA
*rai
,
539 uint16 max_tsize
, uint16 max_rsize
,
540 uint8 auth_type
, uint8 auth_level
,
543 rai
->max_tsize
= max_tsize
; /* maximum transmission fragment size (0x1630) */
544 rai
->max_rsize
= max_rsize
; /* max receive fragment size (0x1630) */
546 rai
->auth_type
= auth_type
; /* nt lm ssp 0x0a */
547 rai
->auth_level
= auth_level
; /* 0x06 */
548 rai
->stub_type_len
= stub_type_len
; /* 0x00 */
549 rai
->padding
= 0; /* padding 0x00 */
551 rai
->unknown
= 0x0014a0c0; /* non-zero pointer to something */
554 /*******************************************************************
555 Reads or writes an RPC_HDR_AUTHA structure.
556 ********************************************************************/
558 BOOL
smb_io_rpc_hdr_autha(char *desc
, RPC_HDR_AUTHA
*rai
, prs_struct
*ps
, int depth
)
563 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_autha");
566 if(!prs_uint16("max_tsize ", ps
, depth
, &rai
->max_tsize
))
568 if(!prs_uint16("max_rsize ", ps
, depth
, &rai
->max_rsize
))
571 if(!prs_uint8 ("auth_type ", ps
, depth
, &rai
->auth_type
)) /* 0x0a nt lm ssp */
573 if(!prs_uint8 ("auth_level ", ps
, depth
, &rai
->auth_level
)) /* 0x06 */
575 if(!prs_uint8 ("stub_type_len", ps
, depth
, &rai
->stub_type_len
))
577 if(!prs_uint8 ("padding ", ps
, depth
, &rai
->padding
))
580 if(!prs_uint32("unknown ", ps
, depth
, &rai
->unknown
)) /* 0x0014a0c0 */
586 /*******************************************************************
587 Checks an RPC_HDR_AUTH structure.
588 ********************************************************************/
590 BOOL
rpc_hdr_auth_chk(RPC_HDR_AUTH
*rai
)
592 return (rai
->auth_type
== NTLMSSP_AUTH_TYPE
&& rai
->auth_level
== NTLMSSP_AUTH_LEVEL
);
595 /*******************************************************************
596 Inits an RPC_HDR_AUTH structure.
597 ********************************************************************/
599 void init_rpc_hdr_auth(RPC_HDR_AUTH
*rai
,
600 uint8 auth_type
, uint8 auth_level
,
604 rai
->auth_type
= auth_type
; /* nt lm ssp 0x0a */
605 rai
->auth_level
= auth_level
; /* 0x06 */
606 rai
->stub_type_len
= stub_type_len
; /* 0x00 */
607 rai
->padding
= 0; /* padding 0x00 */
609 rai
->unknown
= ptr
; /* non-zero pointer to something */
612 /*******************************************************************
613 Reads or writes an RPC_HDR_AUTH structure.
614 ********************************************************************/
616 BOOL
smb_io_rpc_hdr_auth(char *desc
, RPC_HDR_AUTH
*rai
, prs_struct
*ps
, int depth
)
621 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_auth");
627 if(!prs_uint8 ("auth_type ", ps
, depth
, &rai
->auth_type
)) /* 0x0a nt lm ssp */
629 if(!prs_uint8 ("auth_level ", ps
, depth
, &rai
->auth_level
)) /* 0x06 */
631 if(!prs_uint8 ("stub_type_len", ps
, depth
, &rai
->stub_type_len
))
633 if(!prs_uint8 ("padding ", ps
, depth
, &rai
->padding
))
636 if(!prs_uint32("unknown ", ps
, depth
, &rai
->unknown
)) /* 0x0014a0c0 */
642 /*******************************************************************
643 Checks an RPC_AUTH_VERIFIER structure.
644 ********************************************************************/
646 BOOL
rpc_auth_verifier_chk(RPC_AUTH_VERIFIER
*rav
,
647 char *signature
, uint32 msg_type
)
649 return (strequal(rav
->signature
, signature
) && rav
->msg_type
== msg_type
);
652 /*******************************************************************
653 Inits an RPC_AUTH_VERIFIER structure.
654 ********************************************************************/
656 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER
*rav
,
657 char *signature
, uint32 msg_type
)
659 fstrcpy(rav
->signature
, signature
); /* "NTLMSSP" */
660 rav
->msg_type
= msg_type
; /* NTLMSSP_MESSAGE_TYPE */
663 /*******************************************************************
664 Reads or writes an RPC_AUTH_VERIFIER structure.
665 ********************************************************************/
667 BOOL
smb_io_rpc_auth_verifier(char *desc
, RPC_AUTH_VERIFIER
*rav
, prs_struct
*ps
, int depth
)
672 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_verifier");
676 if(!prs_string("signature", ps
, depth
, rav
->signature
, strlen("NTLMSSP"),
677 sizeof(rav
->signature
)))
679 if(!prs_uint32("msg_type ", ps
, depth
, &rav
->msg_type
)) /* NTLMSSP_MESSAGE_TYPE */
685 /*******************************************************************
686 Inits an RPC_AUTH_NTLMSSP_NEG structure.
687 ********************************************************************/
689 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG
*neg
,
691 fstring myname
, fstring domain
)
693 int len_myname
= strlen(myname
);
694 int len_domain
= strlen(domain
);
696 neg
->neg_flgs
= neg_flgs
; /* 0x00b2b3 */
698 init_str_hdr(&neg
->hdr_domain
, len_domain
, len_domain
, 0x20 + len_myname
);
699 init_str_hdr(&neg
->hdr_myname
, len_myname
, len_myname
, 0x20);
701 fstrcpy(neg
->myname
, myname
);
702 fstrcpy(neg
->domain
, domain
);
705 /*******************************************************************
706 Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
708 *** lkclXXXX HACK ALERT! ***
709 ********************************************************************/
711 BOOL
smb_io_rpc_auth_ntlmssp_neg(char *desc
, RPC_AUTH_NTLMSSP_NEG
*neg
, prs_struct
*ps
, int depth
)
713 uint32 start_offset
= prs_offset(ps
);
717 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_neg");
720 if(!prs_uint32("neg_flgs ", ps
, depth
, &neg
->neg_flgs
))
725 uint32 old_neg_flags
= neg
->neg_flgs
;
731 neg
->neg_flgs
= old_neg_flags
;
733 if(!smb_io_strhdr("hdr_domain", &neg
->hdr_domain
, ps
, depth
))
735 if(!smb_io_strhdr("hdr_myname", &neg
->hdr_myname
, ps
, depth
))
738 old_offset
= prs_offset(ps
);
740 if(!prs_set_offset(ps
, neg
->hdr_myname
.buffer
+ start_offset
- 12))
743 if(!prs_uint8s(True
, "myname", ps
, depth
, (uint8
*)neg
->myname
,
744 MIN(neg
->hdr_myname
.str_str_len
, sizeof(neg
->myname
))))
747 old_offset
+= neg
->hdr_myname
.str_str_len
;
749 if(!prs_set_offset(ps
, neg
->hdr_domain
.buffer
+ start_offset
- 12))
752 if(!prs_uint8s(True
, "domain", ps
, depth
, (uint8
*)neg
->domain
,
753 MIN(neg
->hdr_domain
.str_str_len
, sizeof(neg
->domain
))))
756 old_offset
+= neg
->hdr_domain
.str_str_len
;
758 if(!prs_set_offset(ps
, old_offset
))
762 if(!smb_io_strhdr("hdr_domain", &neg
->hdr_domain
, ps
, depth
))
764 if(!smb_io_strhdr("hdr_myname", &neg
->hdr_myname
, ps
, depth
))
767 if(!prs_uint8s(True
, "myname", ps
, depth
, (uint8
*)neg
->myname
,
768 MIN(neg
->hdr_myname
.str_str_len
, sizeof(neg
->myname
))))
770 if(!prs_uint8s(True
, "domain", ps
, depth
, (uint8
*)neg
->domain
,
771 MIN(neg
->hdr_domain
.str_str_len
, sizeof(neg
->domain
))))
778 /*******************************************************************
779 creates an RPC_AUTH_NTLMSSP_CHAL structure.
780 ********************************************************************/
782 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL
*chl
,
786 chl
->unknown_1
= 0x0;
787 chl
->unknown_2
= 0x00000028;
788 chl
->neg_flags
= neg_flags
; /* 0x0082b1 */
790 memcpy(chl
->challenge
, challenge
, sizeof(chl
->challenge
));
791 memset((char *)chl
->reserved
, '\0', sizeof(chl
->reserved
));
794 /*******************************************************************
795 Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
796 ********************************************************************/
798 BOOL
smb_io_rpc_auth_ntlmssp_chal(char *desc
, RPC_AUTH_NTLMSSP_CHAL
*chl
, prs_struct
*ps
, int depth
)
803 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_chal");
806 if(!prs_uint32("unknown_1", ps
, depth
, &chl
->unknown_1
)) /* 0x0000 0000 */
808 if(!prs_uint32("unknown_2", ps
, depth
, &chl
->unknown_2
)) /* 0x0000 b2b3 */
810 if(!prs_uint32("neg_flags", ps
, depth
, &chl
->neg_flags
)) /* 0x0000 82b1 */
813 if(!prs_uint8s (False
, "challenge", ps
, depth
, chl
->challenge
, sizeof(chl
->challenge
)))
815 if(!prs_uint8s (False
, "reserved ", ps
, depth
, chl
->reserved
, sizeof(chl
->reserved
)))
821 /*******************************************************************
822 Inits an RPC_AUTH_NTLMSSP_RESP structure.
824 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
825 *** lkclXXXX the actual offset is at the start of the auth verifier ***
826 ********************************************************************/
828 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP
*rsp
,
829 uchar lm_resp
[24], uchar nt_resp
[24],
830 char *domain
, char *user
, char *wks
,
834 int dom_len
= strlen(domain
);
835 int wks_len
= strlen(wks
);
836 int usr_len
= strlen(user
);
837 int lm_len
= (lm_resp
!= NULL
) ? 24 : 0;
838 int nt_len
= (nt_resp
!= NULL
) ? 24 : 0;
840 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
842 #ifdef DEBUG_PASSWORD
843 DEBUG(100,("lm_resp\n"));
844 dump_data(100, (char *)lm_resp
, 24);
845 DEBUG(100,("nt_resp\n"));
846 dump_data(100, (char *)nt_resp
, 24);
849 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
850 domain
, user
, wks
, neg_flags
));
854 if (IS_BITS_SET_ALL(neg_flags
, NTLMSSP_NEGOTIATE_UNICODE
))
861 init_str_hdr(&rsp
->hdr_domain
, dom_len
, dom_len
, offset
);
864 init_str_hdr(&rsp
->hdr_usr
, usr_len
, usr_len
, offset
);
867 init_str_hdr(&rsp
->hdr_wks
, wks_len
, wks_len
, offset
);
870 init_str_hdr(&rsp
->hdr_lm_resp
, lm_len
, lm_len
, offset
);
873 init_str_hdr(&rsp
->hdr_nt_resp
, nt_len
, nt_len
, offset
);
876 init_str_hdr(&rsp
->hdr_sess_key
, 0, 0, offset
);
878 rsp
->neg_flags
= neg_flags
;
880 memcpy(rsp
->lm_resp
, lm_resp
, 24);
881 memcpy(rsp
->nt_resp
, nt_resp
, 24);
883 if (IS_BITS_SET_ALL(neg_flags
, NTLMSSP_NEGOTIATE_UNICODE
)) {
884 dos_struni2(rsp
->domain
, domain
, sizeof(rsp
->domain
));
885 dos_struni2(rsp
->user
, user
, sizeof(rsp
->user
));
886 dos_struni2(rsp
->wks
, wks
, sizeof(rsp
->wks
));
888 fstrcpy(rsp
->domain
, domain
);
889 fstrcpy(rsp
->user
, user
);
890 fstrcpy(rsp
->wks
, wks
);
892 rsp
->sess_key
[0] = 0;
895 /*******************************************************************
896 Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
898 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
899 *** lkclXXXX the actual offset is at the start of the auth verifier ***
900 ********************************************************************/
902 BOOL
smb_io_rpc_auth_ntlmssp_resp(char *desc
, RPC_AUTH_NTLMSSP_RESP
*rsp
, prs_struct
*ps
, int depth
)
907 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_resp");
917 if(!smb_io_strhdr("hdr_lm_resp ", &rsp
->hdr_lm_resp
, ps
, depth
))
919 if(!smb_io_strhdr("hdr_nt_resp ", &rsp
->hdr_nt_resp
, ps
, depth
))
921 if(!smb_io_strhdr("hdr_domain ", &rsp
->hdr_domain
, ps
, depth
))
923 if(!smb_io_strhdr("hdr_user ", &rsp
->hdr_usr
, ps
, depth
))
925 if(!smb_io_strhdr("hdr_wks ", &rsp
->hdr_wks
, ps
, depth
))
927 if(!smb_io_strhdr("hdr_sess_key", &rsp
->hdr_sess_key
, ps
, depth
))
930 if(!prs_uint32("neg_flags", ps
, depth
, &rsp
->neg_flags
)) /* 0x0000 82b1 */
933 old_offset
= prs_offset(ps
);
935 if(!prs_set_offset(ps
, rsp
->hdr_domain
.buffer
+ 0xc))
938 if(!prs_uint8s(True
, "domain ", ps
, depth
, (uint8
*)rsp
->domain
,
939 MIN(rsp
->hdr_domain
.str_str_len
, sizeof(rsp
->domain
))))
942 old_offset
+= rsp
->hdr_domain
.str_str_len
;
944 if(!prs_set_offset(ps
, rsp
->hdr_usr
.buffer
+ 0xc))
947 if(!prs_uint8s(True
, "user ", ps
, depth
, (uint8
*)rsp
->user
,
948 MIN(rsp
->hdr_usr
.str_str_len
, sizeof(rsp
->user
))))
951 old_offset
+= rsp
->hdr_usr
.str_str_len
;
953 if(!prs_set_offset(ps
, rsp
->hdr_wks
.buffer
+ 0xc))
956 if(!prs_uint8s(True
, "wks ", ps
, depth
, (uint8
*)rsp
->wks
,
957 MIN(rsp
->hdr_wks
.str_str_len
, sizeof(rsp
->wks
))))
960 old_offset
+= rsp
->hdr_wks
.str_str_len
;
962 if(!prs_set_offset(ps
, rsp
->hdr_lm_resp
.buffer
+ 0xc))
965 if(!prs_uint8s(False
, "lm_resp ", ps
, depth
, (uint8
*)rsp
->lm_resp
,
966 MIN(rsp
->hdr_lm_resp
.str_str_len
, sizeof(rsp
->lm_resp
))))
969 old_offset
+= rsp
->hdr_lm_resp
.str_str_len
;
971 if(!prs_set_offset(ps
, rsp
->hdr_nt_resp
.buffer
+ 0xc))
974 if(!prs_uint8s(False
, "nt_resp ", ps
, depth
, (uint8
*)rsp
->nt_resp
,
975 MIN(rsp
->hdr_nt_resp
.str_str_len
, sizeof(rsp
->nt_resp
))))
978 old_offset
+= rsp
->hdr_nt_resp
.str_str_len
;
980 if (rsp
->hdr_sess_key
.str_str_len
!= 0) {
982 if(!prs_set_offset(ps
, rsp
->hdr_sess_key
.buffer
+ 0x10))
985 old_offset
+= rsp
->hdr_sess_key
.str_str_len
;
987 if(!prs_uint8s(False
, "sess_key", ps
, depth
, (uint8
*)rsp
->sess_key
,
988 MIN(rsp
->hdr_sess_key
.str_str_len
, sizeof(rsp
->sess_key
))))
992 if(!prs_set_offset(ps
, old_offset
))
996 if(!smb_io_strhdr("hdr_lm_resp ", &rsp
->hdr_lm_resp
, ps
, depth
))
998 if(!smb_io_strhdr("hdr_nt_resp ", &rsp
->hdr_nt_resp
, ps
, depth
))
1000 if(!smb_io_strhdr("hdr_domain ", &rsp
->hdr_domain
, ps
, depth
))
1002 if(!smb_io_strhdr("hdr_user ", &rsp
->hdr_usr
, ps
, depth
))
1004 if(!smb_io_strhdr("hdr_wks ", &rsp
->hdr_wks
, ps
, depth
))
1006 if(!smb_io_strhdr("hdr_sess_key", &rsp
->hdr_sess_key
, ps
, depth
))
1009 if(!prs_uint32("neg_flags", ps
, depth
, &rsp
->neg_flags
)) /* 0x0000 82b1 */
1012 if(!prs_uint8s(True
, "domain ", ps
, depth
, (uint8
*)rsp
->domain
,
1013 MIN(rsp
->hdr_domain
.str_str_len
, sizeof(rsp
->domain
))))
1016 if(!prs_uint8s(True
, "user ", ps
, depth
, (uint8
*)rsp
->user
,
1017 MIN(rsp
->hdr_usr
.str_str_len
, sizeof(rsp
->user
))))
1020 if(!prs_uint8s(True
, "wks ", ps
, depth
, (uint8
*)rsp
->wks
,
1021 MIN(rsp
->hdr_wks
.str_str_len
, sizeof(rsp
->wks
))))
1023 if(!prs_uint8s(False
, "lm_resp ", ps
, depth
, (uint8
*)rsp
->lm_resp
,
1024 MIN(rsp
->hdr_lm_resp
.str_str_len
, sizeof(rsp
->lm_resp
))))
1026 if(!prs_uint8s(False
, "nt_resp ", ps
, depth
, (uint8
*)rsp
->nt_resp
,
1027 MIN(rsp
->hdr_nt_resp
.str_str_len
, sizeof(rsp
->nt_resp
))))
1029 if(!prs_uint8s(False
, "sess_key", ps
, depth
, (uint8
*)rsp
->sess_key
,
1030 MIN(rsp
->hdr_sess_key
.str_str_len
, sizeof(rsp
->sess_key
))))
1037 /*******************************************************************
1038 Checks an RPC_AUTH_NTLMSSP_CHK structure.
1039 ********************************************************************/
1041 BOOL
rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK
*chk
, uint32 crc32
, uint32 seq_num
)
1046 if (chk
->crc32
!= crc32
||
1047 chk
->ver
!= NTLMSSP_SIGN_VERSION
||
1048 chk
->seq_num
!= seq_num
)
1050 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1051 crc32
, NTLMSSP_SIGN_VERSION
, seq_num
));
1052 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1053 chk
->crc32
, chk
->ver
, chk
->seq_num
));
1059 /*******************************************************************
1060 Inits an RPC_AUTH_NTLMSSP_CHK structure.
1061 ********************************************************************/
1063 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK
*chk
,
1064 uint32 ver
, uint32 crc32
, uint32 seq_num
)
1067 chk
->reserved
= 0x0;
1069 chk
->seq_num
= seq_num
;
1072 /*******************************************************************
1073 Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1074 ********************************************************************/
1076 BOOL
smb_io_rpc_auth_ntlmssp_chk(char *desc
, RPC_AUTH_NTLMSSP_CHK
*chk
, prs_struct
*ps
, int depth
)
1081 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_chk");
1087 if(!prs_uint32("ver ", ps
, depth
, &chk
->ver
))
1089 if(!prs_uint32("reserved", ps
, depth
, &chk
->reserved
))
1091 if(!prs_uint32("crc32 ", ps
, depth
, &chk
->crc32
))
1093 if(!prs_uint32("seq_num ", ps
, depth
, &chk
->seq_num
))