2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1997,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7 * Copyright (C) Paul Ashton 1997.
8 * Copyright (C) Jeremy Allison 1999.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*******************************************************************
28 interface/version dce/rpc pipe identification
29 ********************************************************************/
31 #define TRANS_SYNT_V2 \
34 0x8a885d04, 0x1ceb, 0x11c9, \
35 { 0x9f, 0xe8, 0x08, 0x00, \
36 0x2b, 0x10, 0x48, 0x60 } \
40 #define SYNT_NETLOGON_V2 \
43 0x8a885d04, 0x1ceb, 0x11c9, \
44 { 0x9f, 0xe8, 0x08, 0x00, \
45 0x2b, 0x10, 0x48, 0x60 } \
49 #define SYNT_WKSSVC_V1 \
52 0x6bffd098, 0xa112, 0x3610, \
53 { 0x98, 0x33, 0x46, 0xc3, \
54 0xf8, 0x7e, 0x34, 0x5a } \
58 #define SYNT_SRVSVC_V3 \
61 0x4b324fc8, 0x1670, 0x01d3, \
62 { 0x12, 0x78, 0x5a, 0x47, \
63 0xbf, 0x6e, 0xe1, 0x88 } \
67 #define SYNT_LSARPC_V0 \
70 0x12345778, 0x1234, 0xabcd, \
71 { 0xef, 0x00, 0x01, 0x23, \
72 0x45, 0x67, 0x89, 0xab } \
76 #define SYNT_SAMR_V1 \
79 0x12345778, 0x1234, 0xabcd, \
80 { 0xef, 0x00, 0x01, 0x23, \
81 0x45, 0x67, 0x89, 0xac } \
85 #define SYNT_NETLOGON_V1 \
88 0x12345678, 0x1234, 0xabcd, \
89 { 0xef, 0x00, 0x01, 0x23, \
90 0x45, 0x67, 0xcf, 0xfb } \
94 #define SYNT_WINREG_V1 \
97 0x338cd001, 0x2244, 0x31f1, \
98 { 0xaa, 0xaa, 0x90, 0x00, \
99 0x38, 0x00, 0x10, 0x03 } \
103 #define SYNT_SPOOLSS_V1 \
106 0x12345678, 0x1234, 0xabcd, \
107 { 0xef, 0x00, 0x01, 0x23, \
108 0x45, 0x67, 0x89, 0xab } \
112 #define SYNT_NONE_V0 \
116 { 0x00, 0x00, 0x00, 0x00, \
117 0x00, 0x00, 0x00, 0x00 } \
121 #define SYNT_NETDFS_V3 \
124 0x4fc742e0, 0x4a10, 0x11cf, \
125 { 0x82, 0x73, 0x00, 0xaa, \
126 0x00, 0x4a, 0xe6, 0x73 } \
130 struct pipe_id_info pipe_names
[] =
132 /* client pipe , abstract syntax , server pipe , transfer syntax */
133 { PIPE_LSARPC
, SYNT_LSARPC_V0
, PIPE_LSASS
, TRANS_SYNT_V2
},
134 { PIPE_SAMR
, SYNT_SAMR_V1
, PIPE_LSASS
, TRANS_SYNT_V2
},
135 { PIPE_NETLOGON
, SYNT_NETLOGON_V1
, PIPE_LSASS
, TRANS_SYNT_V2
},
136 { PIPE_SRVSVC
, SYNT_SRVSVC_V3
, PIPE_NTSVCS
, TRANS_SYNT_V2
},
137 { PIPE_WKSSVC
, SYNT_WKSSVC_V1
, PIPE_NTSVCS
, TRANS_SYNT_V2
},
138 { PIPE_WINREG
, SYNT_WINREG_V1
, PIPE_WINREG
, TRANS_SYNT_V2
},
139 { PIPE_SPOOLSS
, SYNT_SPOOLSS_V1
, PIPE_SPOOLSS
, TRANS_SYNT_V2
},
140 { PIPE_NETDFS
, SYNT_NETDFS_V3
, PIPE_NETDFS
, TRANS_SYNT_V2
},
141 { NULL
, SYNT_NONE_V0
, NULL
, SYNT_NONE_V0
}
144 /*******************************************************************
145 Inits an RPC_HDR structure.
146 ********************************************************************/
148 void init_rpc_hdr(RPC_HDR
*hdr
, enum RPC_PKT_TYPE pkt_type
, uint8 flags
,
149 uint32 call_id
, int data_len
, int auth_len
)
151 hdr
->major
= 5; /* RPC version 5 */
152 hdr
->minor
= 0; /* minor version 0 */
153 hdr
->pkt_type
= pkt_type
; /* RPC packet type */
154 hdr
->flags
= flags
; /* dce/rpc flags */
155 hdr
->pack_type
[0] = 0x10; /* little-endian data representation */
156 hdr
->pack_type
[1] = 0; /* packed data representation */
157 hdr
->pack_type
[2] = 0; /* packed data representation */
158 hdr
->pack_type
[3] = 0; /* packed data representation */
159 hdr
->frag_len
= data_len
; /* fragment length, fill in later */
160 hdr
->auth_len
= auth_len
; /* authentication length */
161 hdr
->call_id
= call_id
; /* call identifier - match incoming RPC */
164 /*******************************************************************
165 Reads or writes an RPC_HDR structure.
166 ********************************************************************/
168 BOOL
smb_io_rpc_hdr(char *desc
, RPC_HDR
*rpc
, prs_struct
*ps
, int depth
)
173 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr");
176 if(!prs_uint8 ("major ", ps
, depth
, &rpc
->major
))
179 if(!prs_uint8 ("minor ", ps
, depth
, &rpc
->minor
))
181 if(!prs_uint8 ("pkt_type ", ps
, depth
, &rpc
->pkt_type
))
183 if(!prs_uint8 ("flags ", ps
, depth
, &rpc
->flags
))
186 /* We always marshall in little endian format. */
188 rpc
->pack_type
[0] = 0x10;
190 if(!prs_uint8("pack_type0", ps
, depth
, &rpc
->pack_type
[0]))
192 if(!prs_uint8("pack_type1", ps
, depth
, &rpc
->pack_type
[1]))
194 if(!prs_uint8("pack_type2", ps
, depth
, &rpc
->pack_type
[2]))
196 if(!prs_uint8("pack_type3", ps
, depth
, &rpc
->pack_type
[3]))
200 * If reading and pack_type[0] == 0 then the data is in big-endian
201 * format. Set the flag in the prs_struct to specify reverse-endainness.
204 if (UNMARSHALLING(ps
) && rpc
->pack_type
[0] == 0) {
205 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
206 prs_set_endian_data(ps
, RPC_BIG_ENDIAN
);
209 if(!prs_uint16("frag_len ", ps
, depth
, &rpc
->frag_len
))
211 if(!prs_uint16("auth_len ", ps
, depth
, &rpc
->auth_len
))
213 if(!prs_uint32("call_id ", ps
, depth
, &rpc
->call_id
))
218 /*******************************************************************
219 Reads or writes an RPC_IFACE structure.
220 ********************************************************************/
222 static BOOL
smb_io_rpc_iface(char *desc
, RPC_IFACE
*ifc
, prs_struct
*ps
, int depth
)
227 prs_debug(ps
, depth
, desc
, "smb_io_rpc_iface");
233 if(!prs_uint32 ("data ", ps
, depth
, &ifc
->uuid
.time_low
))
235 if(!prs_uint16 ("data ", ps
, depth
, &ifc
->uuid
.time_mid
))
237 if(!prs_uint16 ("data ", ps
, depth
, &ifc
->uuid
.time_hi_and_version
))
240 if(!prs_uint8s (False
, "data ", ps
, depth
, ifc
->uuid
.remaining
, sizeof(ifc
->uuid
.remaining
)))
242 if(!prs_uint32 ( "version", ps
, depth
, &ifc
->version
))
248 /*******************************************************************
249 Inits an RPC_ADDR_STR structure.
250 ********************************************************************/
252 static void init_rpc_addr_str(RPC_ADDR_STR
*str
, char *name
)
254 str
->len
= strlen(name
) + 1;
255 fstrcpy(str
->str
, name
);
258 /*******************************************************************
259 Reads or writes an RPC_ADDR_STR structure.
260 ********************************************************************/
262 static BOOL
smb_io_rpc_addr_str(char *desc
, RPC_ADDR_STR
*str
, prs_struct
*ps
, int depth
)
267 prs_debug(ps
, depth
, desc
, "smb_io_rpc_addr_str");
272 if(!prs_uint16 ( "len", ps
, depth
, &str
->len
))
274 if(!prs_uint8s (True
, "str", ps
, depth
, (uchar
*)str
->str
, MIN(str
->len
, sizeof(str
->str
)) ))
279 /*******************************************************************
280 Inits an RPC_HDR_BBA structure.
281 ********************************************************************/
283 static void init_rpc_hdr_bba(RPC_HDR_BBA
*bba
, uint16 max_tsize
, uint16 max_rsize
, uint32 assoc_gid
)
285 bba
->max_tsize
= max_tsize
; /* maximum transmission fragment size (0x1630) */
286 bba
->max_rsize
= max_rsize
; /* max receive fragment size (0x1630) */
287 bba
->assoc_gid
= assoc_gid
; /* associated group id (0x0) */
290 /*******************************************************************
291 Reads or writes an RPC_HDR_BBA structure.
292 ********************************************************************/
294 static BOOL
smb_io_rpc_hdr_bba(char *desc
, RPC_HDR_BBA
*rpc
, prs_struct
*ps
, int depth
)
299 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_bba");
302 if(!prs_uint16("max_tsize", ps
, depth
, &rpc
->max_tsize
))
304 if(!prs_uint16("max_rsize", ps
, depth
, &rpc
->max_rsize
))
306 if(!prs_uint32("assoc_gid", ps
, depth
, &rpc
->assoc_gid
))
311 /*******************************************************************
312 Inits an RPC_HDR_RB structure.
313 ********************************************************************/
315 void init_rpc_hdr_rb(RPC_HDR_RB
*rpc
,
316 uint16 max_tsize
, uint16 max_rsize
, uint32 assoc_gid
,
317 uint32 num_elements
, uint16 context_id
, uint8 num_syntaxes
,
318 RPC_IFACE
*abstract
, RPC_IFACE
*transfer
)
320 init_rpc_hdr_bba(&rpc
->bba
, max_tsize
, max_rsize
, assoc_gid
);
322 rpc
->num_elements
= num_elements
; /* the number of elements (0x1) */
323 rpc
->context_id
= context_id
; /* presentation context identifier (0x0) */
324 rpc
->num_syntaxes
= num_syntaxes
; /* the number of syntaxes (has always been 1?)(0x1) */
326 /* num and vers. of interface client is using */
327 rpc
->abstract
= *abstract
;
329 /* num and vers. of interface to use for replies */
330 rpc
->transfer
= *transfer
;
333 /*******************************************************************
334 Reads or writes an RPC_HDR_RB structure.
335 ********************************************************************/
337 BOOL
smb_io_rpc_hdr_rb(char *desc
, RPC_HDR_RB
*rpc
, prs_struct
*ps
, int depth
)
342 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_rb");
345 if(!smb_io_rpc_hdr_bba("", &rpc
->bba
, ps
, depth
))
348 if(!prs_uint32("num_elements", ps
, depth
, &rpc
->num_elements
))
350 if(!prs_uint16("context_id ", ps
, depth
, &rpc
->context_id
))
352 if(!prs_uint8 ("num_syntaxes", ps
, depth
, &rpc
->num_syntaxes
))
355 if(!smb_io_rpc_iface("", &rpc
->abstract
, ps
, depth
))
357 if(!smb_io_rpc_iface("", &rpc
->transfer
, ps
, depth
))
363 /*******************************************************************
364 Inits an RPC_RESULTS structure.
366 lkclXXXX only one reason at the moment!
367 ********************************************************************/
369 static void init_rpc_results(RPC_RESULTS
*res
,
370 uint8 num_results
, uint16 result
, uint16 reason
)
372 res
->num_results
= num_results
; /* the number of results (0x01) */
373 res
->result
= result
; /* result (0x00 = accept) */
374 res
->reason
= reason
; /* reason (0x00 = no reason specified) */
377 /*******************************************************************
378 Reads or writes an RPC_RESULTS structure.
380 lkclXXXX only one reason at the moment!
381 ********************************************************************/
383 static BOOL
smb_io_rpc_results(char *desc
, RPC_RESULTS
*res
, prs_struct
*ps
, int depth
)
388 prs_debug(ps
, depth
, desc
, "smb_io_rpc_results");
394 if(!prs_uint8 ("num_results", ps
, depth
, &res
->num_results
))
400 if(!prs_uint16("result ", ps
, depth
, &res
->result
))
402 if(!prs_uint16("reason ", ps
, depth
, &res
->reason
))
407 /*******************************************************************
408 Init an RPC_HDR_BA structure.
410 lkclXXXX only one reason at the moment!
412 ********************************************************************/
414 void init_rpc_hdr_ba(RPC_HDR_BA
*rpc
,
415 uint16 max_tsize
, uint16 max_rsize
, uint32 assoc_gid
,
417 uint8 num_results
, uint16 result
, uint16 reason
,
420 init_rpc_hdr_bba (&rpc
->bba
, max_tsize
, max_rsize
, assoc_gid
);
421 init_rpc_addr_str(&rpc
->addr
, pipe_addr
);
422 init_rpc_results (&rpc
->res
, num_results
, result
, reason
);
424 /* the transfer syntax from the request */
425 memcpy(&rpc
->transfer
, transfer
, sizeof(rpc
->transfer
));
428 /*******************************************************************
429 Reads or writes an RPC_HDR_BA structure.
430 ********************************************************************/
432 BOOL
smb_io_rpc_hdr_ba(char *desc
, RPC_HDR_BA
*rpc
, prs_struct
*ps
, int depth
)
437 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_ba");
440 if(!smb_io_rpc_hdr_bba("", &rpc
->bba
, ps
, depth
))
442 if(!smb_io_rpc_addr_str("", &rpc
->addr
, ps
, depth
))
444 if(!smb_io_rpc_results("", &rpc
->res
, ps
, depth
))
446 if(!smb_io_rpc_iface("", &rpc
->transfer
, ps
, depth
))
451 /*******************************************************************
452 Init an RPC_HDR_REQ structure.
453 ********************************************************************/
455 void init_rpc_hdr_req(RPC_HDR_REQ
*hdr
, uint32 alloc_hint
, uint16 opnum
)
457 hdr
->alloc_hint
= alloc_hint
; /* allocation hint */
458 hdr
->context_id
= 0; /* presentation context identifier */
459 hdr
->opnum
= opnum
; /* opnum */
462 /*******************************************************************
463 Reads or writes an RPC_HDR_REQ structure.
464 ********************************************************************/
466 BOOL
smb_io_rpc_hdr_req(char *desc
, RPC_HDR_REQ
*rpc
, prs_struct
*ps
, int depth
)
471 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_req");
474 if(!prs_uint32("alloc_hint", ps
, depth
, &rpc
->alloc_hint
))
476 if(!prs_uint16("context_id", ps
, depth
, &rpc
->context_id
))
478 if(!prs_uint16("opnum ", ps
, depth
, &rpc
->opnum
))
483 /*******************************************************************
484 Reads or writes an RPC_HDR_RESP structure.
485 ********************************************************************/
487 BOOL
smb_io_rpc_hdr_resp(char *desc
, RPC_HDR_RESP
*rpc
, prs_struct
*ps
, int depth
)
492 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_resp");
495 if(!prs_uint32("alloc_hint", ps
, depth
, &rpc
->alloc_hint
))
497 if(!prs_uint16("context_id", ps
, depth
, &rpc
->context_id
))
499 if(!prs_uint8 ("cancel_ct ", ps
, depth
, &rpc
->cancel_count
))
501 if(!prs_uint8 ("reserved ", ps
, depth
, &rpc
->reserved
))
506 /*******************************************************************
507 Reads or writes an RPC_HDR_FAULT structure.
508 ********************************************************************/
510 BOOL
smb_io_rpc_hdr_fault(char *desc
, RPC_HDR_FAULT
*rpc
, prs_struct
*ps
, int depth
)
515 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_fault");
518 if(!prs_ntstatus("status ", ps
, depth
, &rpc
->status
))
520 if(!prs_uint32("reserved", ps
, depth
, &rpc
->reserved
))
526 /*******************************************************************
527 Init an RPC_HDR_AUTHA structure.
528 ********************************************************************/
530 void init_rpc_hdr_autha(RPC_HDR_AUTHA
*rai
,
531 uint16 max_tsize
, uint16 max_rsize
,
532 uint8 auth_type
, uint8 auth_level
,
535 rai
->max_tsize
= max_tsize
; /* maximum transmission fragment size (0x1630) */
536 rai
->max_rsize
= max_rsize
; /* max receive fragment size (0x1630) */
538 rai
->auth_type
= auth_type
; /* nt lm ssp 0x0a */
539 rai
->auth_level
= auth_level
; /* 0x06 */
540 rai
->stub_type_len
= stub_type_len
; /* 0x00 */
541 rai
->padding
= 0; /* padding 0x00 */
543 rai
->unknown
= 0x0014a0c0; /* non-zero pointer to something */
546 /*******************************************************************
547 Reads or writes an RPC_HDR_AUTHA structure.
548 ********************************************************************/
550 BOOL
smb_io_rpc_hdr_autha(char *desc
, RPC_HDR_AUTHA
*rai
, prs_struct
*ps
, int depth
)
555 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_autha");
558 if(!prs_uint16("max_tsize ", ps
, depth
, &rai
->max_tsize
))
560 if(!prs_uint16("max_rsize ", ps
, depth
, &rai
->max_rsize
))
563 if(!prs_uint8 ("auth_type ", ps
, depth
, &rai
->auth_type
)) /* 0x0a nt lm ssp */
565 if(!prs_uint8 ("auth_level ", ps
, depth
, &rai
->auth_level
)) /* 0x06 */
567 if(!prs_uint8 ("stub_type_len", ps
, depth
, &rai
->stub_type_len
))
569 if(!prs_uint8 ("padding ", ps
, depth
, &rai
->padding
))
572 if(!prs_uint32("unknown ", ps
, depth
, &rai
->unknown
)) /* 0x0014a0c0 */
578 /*******************************************************************
579 Checks an RPC_HDR_AUTH structure.
580 ********************************************************************/
582 BOOL
rpc_hdr_auth_chk(RPC_HDR_AUTH
*rai
)
584 return (rai
->auth_type
== NTLMSSP_AUTH_TYPE
&& rai
->auth_level
== NTLMSSP_AUTH_LEVEL
);
587 /*******************************************************************
588 Inits an RPC_HDR_AUTH structure.
589 ********************************************************************/
591 void init_rpc_hdr_auth(RPC_HDR_AUTH
*rai
,
592 uint8 auth_type
, uint8 auth_level
,
596 rai
->auth_type
= auth_type
; /* nt lm ssp 0x0a */
597 rai
->auth_level
= auth_level
; /* 0x06 */
598 rai
->stub_type_len
= stub_type_len
; /* 0x00 */
599 rai
->padding
= 0; /* padding 0x00 */
601 rai
->unknown
= ptr
; /* non-zero pointer to something */
604 /*******************************************************************
605 Reads or writes an RPC_HDR_AUTH structure.
606 ********************************************************************/
608 BOOL
smb_io_rpc_hdr_auth(char *desc
, RPC_HDR_AUTH
*rai
, prs_struct
*ps
, int depth
)
613 prs_debug(ps
, depth
, desc
, "smb_io_rpc_hdr_auth");
619 if(!prs_uint8 ("auth_type ", ps
, depth
, &rai
->auth_type
)) /* 0x0a nt lm ssp */
621 if(!prs_uint8 ("auth_level ", ps
, depth
, &rai
->auth_level
)) /* 0x06 */
623 if(!prs_uint8 ("stub_type_len", ps
, depth
, &rai
->stub_type_len
))
625 if(!prs_uint8 ("padding ", ps
, depth
, &rai
->padding
))
628 if(!prs_uint32("unknown ", ps
, depth
, &rai
->unknown
)) /* 0x0014a0c0 */
634 /*******************************************************************
635 Checks an RPC_AUTH_VERIFIER structure.
636 ********************************************************************/
638 BOOL
rpc_auth_verifier_chk(RPC_AUTH_VERIFIER
*rav
,
639 char *signature
, uint32 msg_type
)
641 return (strequal(rav
->signature
, signature
) && rav
->msg_type
== msg_type
);
644 /*******************************************************************
645 Inits an RPC_AUTH_VERIFIER structure.
646 ********************************************************************/
648 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER
*rav
,
649 char *signature
, uint32 msg_type
)
651 fstrcpy(rav
->signature
, signature
); /* "NTLMSSP" */
652 rav
->msg_type
= msg_type
; /* NTLMSSP_MESSAGE_TYPE */
655 /*******************************************************************
656 Reads or writes an RPC_AUTH_VERIFIER structure.
657 ********************************************************************/
659 BOOL
smb_io_rpc_auth_verifier(char *desc
, RPC_AUTH_VERIFIER
*rav
, prs_struct
*ps
, int depth
)
664 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_verifier");
668 if(!prs_string("signature", ps
, depth
, rav
->signature
, strlen("NTLMSSP"),
669 sizeof(rav
->signature
)))
671 if(!prs_uint32("msg_type ", ps
, depth
, &rav
->msg_type
)) /* NTLMSSP_MESSAGE_TYPE */
677 /*******************************************************************
678 Inits an RPC_AUTH_NTLMSSP_NEG structure.
679 ********************************************************************/
681 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG
*neg
,
683 fstring myname
, fstring domain
)
685 int len_myname
= strlen(myname
);
686 int len_domain
= strlen(domain
);
688 neg
->neg_flgs
= neg_flgs
; /* 0x00b2b3 */
690 init_str_hdr(&neg
->hdr_domain
, len_domain
, len_domain
, 0x20 + len_myname
);
691 init_str_hdr(&neg
->hdr_myname
, len_myname
, len_myname
, 0x20);
693 fstrcpy(neg
->myname
, myname
);
694 fstrcpy(neg
->domain
, domain
);
697 /*******************************************************************
698 Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
700 *** lkclXXXX HACK ALERT! ***
701 ********************************************************************/
703 BOOL
smb_io_rpc_auth_ntlmssp_neg(char *desc
, RPC_AUTH_NTLMSSP_NEG
*neg
, prs_struct
*ps
, int depth
)
705 uint32 start_offset
= prs_offset(ps
);
709 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_neg");
712 if(!prs_uint32("neg_flgs ", ps
, depth
, &neg
->neg_flgs
))
717 uint32 old_neg_flags
= neg
->neg_flgs
;
723 neg
->neg_flgs
= old_neg_flags
;
725 if(!smb_io_strhdr("hdr_domain", &neg
->hdr_domain
, ps
, depth
))
727 if(!smb_io_strhdr("hdr_myname", &neg
->hdr_myname
, ps
, depth
))
730 old_offset
= prs_offset(ps
);
732 if(!prs_set_offset(ps
, neg
->hdr_myname
.buffer
+ start_offset
- 12))
735 if(!prs_uint8s(True
, "myname", ps
, depth
, (uint8
*)neg
->myname
,
736 MIN(neg
->hdr_myname
.str_str_len
, sizeof(neg
->myname
))))
739 old_offset
+= neg
->hdr_myname
.str_str_len
;
741 if(!prs_set_offset(ps
, neg
->hdr_domain
.buffer
+ start_offset
- 12))
744 if(!prs_uint8s(True
, "domain", ps
, depth
, (uint8
*)neg
->domain
,
745 MIN(neg
->hdr_domain
.str_str_len
, sizeof(neg
->domain
))))
748 old_offset
+= neg
->hdr_domain
.str_str_len
;
750 if(!prs_set_offset(ps
, old_offset
))
754 if(!smb_io_strhdr("hdr_domain", &neg
->hdr_domain
, ps
, depth
))
756 if(!smb_io_strhdr("hdr_myname", &neg
->hdr_myname
, ps
, depth
))
759 if(!prs_uint8s(True
, "myname", ps
, depth
, (uint8
*)neg
->myname
,
760 MIN(neg
->hdr_myname
.str_str_len
, sizeof(neg
->myname
))))
762 if(!prs_uint8s(True
, "domain", ps
, depth
, (uint8
*)neg
->domain
,
763 MIN(neg
->hdr_domain
.str_str_len
, sizeof(neg
->domain
))))
770 /*******************************************************************
771 creates an RPC_AUTH_NTLMSSP_CHAL structure.
772 ********************************************************************/
774 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL
*chl
,
778 chl
->unknown_1
= 0x0;
779 chl
->unknown_2
= 0x00000028;
780 chl
->neg_flags
= neg_flags
; /* 0x0082b1 */
782 memcpy(chl
->challenge
, challenge
, sizeof(chl
->challenge
));
783 memset((char *)chl
->reserved
, '\0', sizeof(chl
->reserved
));
786 /*******************************************************************
787 Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
788 ********************************************************************/
790 BOOL
smb_io_rpc_auth_ntlmssp_chal(char *desc
, RPC_AUTH_NTLMSSP_CHAL
*chl
, prs_struct
*ps
, int depth
)
795 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_chal");
798 if(!prs_uint32("unknown_1", ps
, depth
, &chl
->unknown_1
)) /* 0x0000 0000 */
800 if(!prs_uint32("unknown_2", ps
, depth
, &chl
->unknown_2
)) /* 0x0000 b2b3 */
802 if(!prs_uint32("neg_flags", ps
, depth
, &chl
->neg_flags
)) /* 0x0000 82b1 */
805 if(!prs_uint8s (False
, "challenge", ps
, depth
, chl
->challenge
, sizeof(chl
->challenge
)))
807 if(!prs_uint8s (False
, "reserved ", ps
, depth
, chl
->reserved
, sizeof(chl
->reserved
)))
813 /*******************************************************************
814 Inits an RPC_AUTH_NTLMSSP_RESP structure.
816 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
817 *** lkclXXXX the actual offset is at the start of the auth verifier ***
818 ********************************************************************/
820 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP
*rsp
,
821 uchar lm_resp
[24], uchar nt_resp
[24],
822 char *domain
, char *user
, char *wks
,
826 int dom_len
= strlen(domain
);
827 int wks_len
= strlen(wks
);
828 int usr_len
= strlen(user
);
829 int lm_len
= (lm_resp
!= NULL
) ? 24 : 0;
830 int nt_len
= (nt_resp
!= NULL
) ? 24 : 0;
832 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
834 #ifdef DEBUG_PASSWORD
835 DEBUG(100,("lm_resp\n"));
836 dump_data(100, (char *)lm_resp
, 24);
837 DEBUG(100,("nt_resp\n"));
838 dump_data(100, (char *)nt_resp
, 24);
841 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
842 domain
, user
, wks
, neg_flags
));
846 if (neg_flags
& NTLMSSP_NEGOTIATE_UNICODE
) {
852 init_str_hdr(&rsp
->hdr_domain
, dom_len
, dom_len
, offset
);
855 init_str_hdr(&rsp
->hdr_usr
, usr_len
, usr_len
, offset
);
858 init_str_hdr(&rsp
->hdr_wks
, wks_len
, wks_len
, offset
);
861 init_str_hdr(&rsp
->hdr_lm_resp
, lm_len
, lm_len
, offset
);
864 init_str_hdr(&rsp
->hdr_nt_resp
, nt_len
, nt_len
, offset
);
867 init_str_hdr(&rsp
->hdr_sess_key
, 0, 0, offset
);
869 rsp
->neg_flags
= neg_flags
;
871 memcpy(rsp
->lm_resp
, lm_resp
, 24);
872 memcpy(rsp
->nt_resp
, nt_resp
, 24);
874 if (neg_flags
& NTLMSSP_NEGOTIATE_UNICODE
) {
875 rpcstr_push(rsp
->domain
, domain
, sizeof(rsp
->domain
), 0);
876 rpcstr_push(rsp
->user
, user
, sizeof(rsp
->user
), 0);
877 rpcstr_push(rsp
->wks
, wks
, sizeof(rsp
->wks
), 0);
879 fstrcpy(rsp
->domain
, domain
);
880 fstrcpy(rsp
->user
, user
);
881 fstrcpy(rsp
->wks
, wks
);
884 rsp
->sess_key
[0] = 0;
887 /*******************************************************************
888 Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
890 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
891 *** lkclXXXX the actual offset is at the start of the auth verifier ***
892 ********************************************************************/
894 BOOL
smb_io_rpc_auth_ntlmssp_resp(char *desc
, RPC_AUTH_NTLMSSP_RESP
*rsp
, prs_struct
*ps
, int depth
)
899 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_resp");
909 if(!smb_io_strhdr("hdr_lm_resp ", &rsp
->hdr_lm_resp
, ps
, depth
))
911 if(!smb_io_strhdr("hdr_nt_resp ", &rsp
->hdr_nt_resp
, ps
, depth
))
913 if(!smb_io_strhdr("hdr_domain ", &rsp
->hdr_domain
, ps
, depth
))
915 if(!smb_io_strhdr("hdr_user ", &rsp
->hdr_usr
, ps
, depth
))
917 if(!smb_io_strhdr("hdr_wks ", &rsp
->hdr_wks
, ps
, depth
))
919 if(!smb_io_strhdr("hdr_sess_key", &rsp
->hdr_sess_key
, ps
, depth
))
922 if(!prs_uint32("neg_flags", ps
, depth
, &rsp
->neg_flags
)) /* 0x0000 82b1 */
925 old_offset
= prs_offset(ps
);
927 if(!prs_set_offset(ps
, rsp
->hdr_domain
.buffer
+ 0xc))
930 if(!prs_uint8s(True
, "domain ", ps
, depth
, (uint8
*)rsp
->domain
,
931 MIN(rsp
->hdr_domain
.str_str_len
, sizeof(rsp
->domain
))))
934 old_offset
+= rsp
->hdr_domain
.str_str_len
;
936 if(!prs_set_offset(ps
, rsp
->hdr_usr
.buffer
+ 0xc))
939 if(!prs_uint8s(True
, "user ", ps
, depth
, (uint8
*)rsp
->user
,
940 MIN(rsp
->hdr_usr
.str_str_len
, sizeof(rsp
->user
))))
943 old_offset
+= rsp
->hdr_usr
.str_str_len
;
945 if(!prs_set_offset(ps
, rsp
->hdr_wks
.buffer
+ 0xc))
948 if(!prs_uint8s(True
, "wks ", ps
, depth
, (uint8
*)rsp
->wks
,
949 MIN(rsp
->hdr_wks
.str_str_len
, sizeof(rsp
->wks
))))
952 old_offset
+= rsp
->hdr_wks
.str_str_len
;
954 if(!prs_set_offset(ps
, rsp
->hdr_lm_resp
.buffer
+ 0xc))
957 if(!prs_uint8s(False
, "lm_resp ", ps
, depth
, (uint8
*)rsp
->lm_resp
,
958 MIN(rsp
->hdr_lm_resp
.str_str_len
, sizeof(rsp
->lm_resp
))))
961 old_offset
+= rsp
->hdr_lm_resp
.str_str_len
;
963 if(!prs_set_offset(ps
, rsp
->hdr_nt_resp
.buffer
+ 0xc))
966 if(!prs_uint8s(False
, "nt_resp ", ps
, depth
, (uint8
*)rsp
->nt_resp
,
967 MIN(rsp
->hdr_nt_resp
.str_str_len
, sizeof(rsp
->nt_resp
))))
970 old_offset
+= rsp
->hdr_nt_resp
.str_str_len
;
972 if (rsp
->hdr_sess_key
.str_str_len
!= 0) {
974 if(!prs_set_offset(ps
, rsp
->hdr_sess_key
.buffer
+ 0x10))
977 old_offset
+= rsp
->hdr_sess_key
.str_str_len
;
979 if(!prs_uint8s(False
, "sess_key", ps
, depth
, (uint8
*)rsp
->sess_key
,
980 MIN(rsp
->hdr_sess_key
.str_str_len
, sizeof(rsp
->sess_key
))))
984 if(!prs_set_offset(ps
, old_offset
))
988 if(!smb_io_strhdr("hdr_lm_resp ", &rsp
->hdr_lm_resp
, ps
, depth
))
990 if(!smb_io_strhdr("hdr_nt_resp ", &rsp
->hdr_nt_resp
, ps
, depth
))
992 if(!smb_io_strhdr("hdr_domain ", &rsp
->hdr_domain
, ps
, depth
))
994 if(!smb_io_strhdr("hdr_user ", &rsp
->hdr_usr
, ps
, depth
))
996 if(!smb_io_strhdr("hdr_wks ", &rsp
->hdr_wks
, ps
, depth
))
998 if(!smb_io_strhdr("hdr_sess_key", &rsp
->hdr_sess_key
, ps
, depth
))
1001 if(!prs_uint32("neg_flags", ps
, depth
, &rsp
->neg_flags
)) /* 0x0000 82b1 */
1004 if(!prs_uint8s(True
, "domain ", ps
, depth
, (uint8
*)rsp
->domain
,
1005 MIN(rsp
->hdr_domain
.str_str_len
, sizeof(rsp
->domain
))))
1008 if(!prs_uint8s(True
, "user ", ps
, depth
, (uint8
*)rsp
->user
,
1009 MIN(rsp
->hdr_usr
.str_str_len
, sizeof(rsp
->user
))))
1012 if(!prs_uint8s(True
, "wks ", ps
, depth
, (uint8
*)rsp
->wks
,
1013 MIN(rsp
->hdr_wks
.str_str_len
, sizeof(rsp
->wks
))))
1015 if(!prs_uint8s(False
, "lm_resp ", ps
, depth
, (uint8
*)rsp
->lm_resp
,
1016 MIN(rsp
->hdr_lm_resp
.str_str_len
, sizeof(rsp
->lm_resp
))))
1018 if(!prs_uint8s(False
, "nt_resp ", ps
, depth
, (uint8
*)rsp
->nt_resp
,
1019 MIN(rsp
->hdr_nt_resp
.str_str_len
, sizeof(rsp
->nt_resp
))))
1021 if(!prs_uint8s(False
, "sess_key", ps
, depth
, (uint8
*)rsp
->sess_key
,
1022 MIN(rsp
->hdr_sess_key
.str_str_len
, sizeof(rsp
->sess_key
))))
1029 /*******************************************************************
1030 Checks an RPC_AUTH_NTLMSSP_CHK structure.
1031 ********************************************************************/
1033 BOOL
rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK
*chk
, uint32 crc32
, uint32 seq_num
)
1038 if (chk
->crc32
!= crc32
||
1039 chk
->ver
!= NTLMSSP_SIGN_VERSION
||
1040 chk
->seq_num
!= seq_num
)
1042 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1043 crc32
, NTLMSSP_SIGN_VERSION
, seq_num
));
1044 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1045 chk
->crc32
, chk
->ver
, chk
->seq_num
));
1051 /*******************************************************************
1052 Inits an RPC_AUTH_NTLMSSP_CHK structure.
1053 ********************************************************************/
1055 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK
*chk
,
1056 uint32 ver
, uint32 crc32
, uint32 seq_num
)
1059 chk
->reserved
= 0x0;
1061 chk
->seq_num
= seq_num
;
1064 /*******************************************************************
1065 Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1066 ********************************************************************/
1068 BOOL
smb_io_rpc_auth_ntlmssp_chk(char *desc
, RPC_AUTH_NTLMSSP_CHK
*chk
, prs_struct
*ps
, int depth
)
1073 prs_debug(ps
, depth
, desc
, "smb_io_rpc_auth_ntlmssp_chk");
1079 if(!prs_uint32("ver ", ps
, depth
, &chk
->ver
))
1081 if(!prs_uint32("reserved", ps
, depth
, &chk
->reserved
))
1083 if(!prs_uint32("crc32 ", ps
, depth
, &chk
->crc32
))
1085 if(!prs_uint32("seq_num ", ps
, depth
, &chk
->seq_num
))