3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1999,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1999,
8 * Copyright (C) Paul Ashton 1997-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.
28 extern int DEBUGLEVEL;
31 /*******************************************************************
32 interface/version dce/rpc pipe identification
33 ********************************************************************/
35 #define TRANS_SYNT_V2 \
38 0x04, 0x5d, 0x88, 0x8a, \
39 0xeb, 0x1c, 0xc9, 0x11, \
40 0x9f, 0xe8, 0x08, 0x00, \
41 0x2b, 0x10, 0x48, 0x60 \
45 #define SYNT_SVCCTL_V2 \
48 0x81, 0xbb, 0x7a, 0x36, \
49 0x44, 0x98, 0xf1, 0x35, \
50 0xad, 0x32, 0x98, 0xf0, \
51 0x38, 0x00, 0x10, 0x03 \
55 #define SYNT_NETLOGON_V2 \
58 0x04, 0x5d, 0x88, 0x8a, \
59 0xeb, 0x1c, 0xc9, 0x11, \
60 0x9f, 0xe8, 0x08, 0x00, \
61 0x2b, 0x10, 0x48, 0x60 \
65 #define SYNT_WKSSVC_V1 \
68 0x98, 0xd0, 0xff, 0x6b, \
69 0x12, 0xa1, 0x10, 0x36, \
70 0x98, 0x33, 0x46, 0xc3, \
71 0xf8, 0x7e, 0x34, 0x5a \
75 #define SYNT_SRVSVC_V3 \
78 0xc8, 0x4f, 0x32, 0x4b, \
79 0x70, 0x16, 0xd3, 0x01, \
80 0x12, 0x78, 0x5a, 0x47, \
81 0xbf, 0x6e, 0xe1, 0x88 \
85 #define SYNT_LSARPC_V0 \
88 0x78, 0x57, 0x34, 0x12, \
89 0x34, 0x12, 0xcd, 0xab, \
90 0xef, 0x00, 0x01, 0x23, \
91 0x45, 0x67, 0x89, 0xab \
95 #define SYNT_SAMR_V1 \
98 0x78, 0x57, 0x34, 0x12, \
99 0x34, 0x12, 0xcd, 0xab, \
100 0xef, 0x00, 0x01, 0x23, \
101 0x45, 0x67, 0x89, 0xac \
105 #define SYNT_NETLOGON_V1 \
108 0x78, 0x56, 0x34, 0x12, \
109 0x34, 0x12, 0xcd, 0xab, \
110 0xef, 0x00, 0x01, 0x23, \
111 0x45, 0x67, 0xcf, 0xfb \
115 #define SYNT_WINREG_V1 \
118 0x01, 0xd0, 0x8c, 0x33, \
119 0x44, 0x22, 0xf1, 0x31, \
120 0xaa, 0xaa, 0x90, 0x00, \
121 0x38, 0x00, 0x10, 0x03 \
125 #define SYNT_ATSVC_V1 \
128 0x82, 0x06, 0xf7, 0x1f, \
129 0x51, 0x0a, 0xe8, 0x30, \
130 0x07, 0x6d, 0x74, 0x0b, \
131 0xe8, 0xce, 0xe9, 0x8b \
135 #define SYNT_SPOOLSS_V1 \
138 0x78, 0x56, 0x34, 0x12, \
139 0x34, 0x12, 0xcd, 0xab, \
140 0xef, 0x00, 0x01, 0x23, \
141 0x45, 0x67, 0x89, 0xab \
145 #define SYNT_NONE_V0 \
148 0x00, 0x00, 0x00, 0x00, \
149 0x00, 0x00, 0x00, 0x00, \
150 0x00, 0x00, 0x00, 0x00, \
151 0x00, 0x00, 0x00, 0x00 \
155 #define SYNT_EVENTLOG_V0 \
158 0xdc, 0x3f, 0x27, 0x82, \
159 0x2a, 0xe3, 0xc3, 0x18, \
160 0x3f, 0x78, 0x82, 0x79, \
161 0x29, 0xdc, 0x23, 0xea \
165 struct pipe_id_info pipe_names [] =
167 /* client pipe , abstract syntax , server pipe , transfer syntax */
168 { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 },
169 { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 },
170 { PIPE_NETLOGON, SYNT_NETLOGON_V1, PIPE_LSASS , TRANS_SYNT_V2 },
171 { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 },
172 { PIPE_SVCCTL , SYNT_SVCCTL_V2 , PIPE_NTSVCS , TRANS_SYNT_V2 },
173 { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 },
174 { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 },
175 { PIPE_ATSVC , SYNT_ATSVC_V1 , PIPE_ATSVC , TRANS_SYNT_V2 },
176 { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 },
177 { PIPE_EVENTLOG, SYNT_EVENTLOG_V0, PIPE_EVENTLOG , TRANS_SYNT_V2 },
178 { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }
181 /*******************************************************************
182 creates an RPC_HDR structure.
183 ********************************************************************/
184 BOOL make_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
185 uint32 call_id, int data_len, int auth_len)
187 if (hdr == NULL) return False;
189 hdr->major = 5; /* RPC version 5 */
190 hdr->minor = 0; /* minor version 0 */
191 hdr->pkt_type = pkt_type; /* RPC packet type */
192 hdr->flags = flags; /* dce/rpc flags */
193 hdr->pack_type = 0x10; /* packed data representation */
194 hdr->frag_len = data_len; /* fragment length, fill in later */
195 hdr->auth_len = auth_len; /* authentication length */
196 hdr->call_id = call_id; /* call identifier - match incoming RPC */
201 /*******************************************************************
202 reads or writes an RPC_HDR structure.
203 ********************************************************************/
204 BOOL smb_io_rpc_hdr(char *desc, RPC_HDR *rpc, prs_struct *ps, int depth)
206 if (rpc == NULL) return False;
208 prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
211 prs_uint8 ("major ", ps, depth, &(rpc->major));
212 prs_uint8 ("minor ", ps, depth, &(rpc->minor));
213 prs_uint8 ("pkt_type ", ps, depth, &(rpc->pkt_type));
214 prs_uint8 ("flags ", ps, depth, &(rpc->flags));
215 prs_uint32("pack_type ", ps, depth, &(rpc->pack_type));
216 prs_uint16("frag_len ", ps, depth, &(rpc->frag_len));
217 prs_uint16("auth_len ", ps, depth, &(rpc->auth_len));
218 prs_uint32("call_id ", ps, depth, &(rpc->call_id));
223 /*******************************************************************
224 reads or writes an RPC_IFACE structure.
225 ********************************************************************/
226 static BOOL smb_io_rpc_iface(char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
228 if (ifc == NULL) return False;
230 prs_debug(ps, depth, desc, "smb_io_rpc_iface");
235 prs_uint8s (False, "data ", ps, depth, ifc->data, sizeof(ifc->data));
236 prs_uint32 ( "version", ps, depth, &(ifc->version));
241 /*******************************************************************
242 creates an RPC_ADDR_STR structure.
244 The name can be null (RPC Alter-Context)
245 ********************************************************************/
246 static BOOL make_rpc_addr_str(RPC_ADDR_STR *str, char *name)
248 if (str == NULL ) return False;
252 fstrcpy(str->str, "");
256 str->len = strlen(name) + 1;
257 fstrcpy(str->str, name);
263 /*******************************************************************
264 reads or writes an RPC_ADDR_STR structure.
265 ********************************************************************/
266 static BOOL smb_io_rpc_addr_str(char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth)
268 if (str == NULL) return False;
270 prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
274 prs_uint16 ( "len", ps, depth, &(str->len));
275 prs_uint8s (True, "str", ps, depth, (uchar*)str->str, str->len);
280 /*******************************************************************
281 creates an RPC_HDR_BBA structure.
282 ********************************************************************/
283 static BOOL make_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
285 if (bba == NULL) return False;
287 bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
288 bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
289 bba->assoc_gid = assoc_gid; /* associated group id (0x0) */
294 /*******************************************************************
295 reads or writes an RPC_HDR_BBA structure.
296 ********************************************************************/
297 static BOOL smb_io_rpc_hdr_bba(char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
299 if (rpc == NULL) return False;
301 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
304 prs_uint16("max_tsize", ps, depth, &(rpc->max_tsize));
305 prs_uint16("max_rsize", ps, depth, &(rpc->max_rsize));
306 prs_uint32("assoc_gid", ps, depth, &(rpc->assoc_gid));
311 /*******************************************************************
312 creates an RPC_HDR_RB structure.
313 ********************************************************************/
314 BOOL make_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 if (rpc == NULL) return False;
321 make_rpc_hdr_bba(&(rpc->bba), max_tsize, max_rsize, assoc_gid);
323 rpc->num_elements = num_elements ; /* the number of elements (0x1) */
324 rpc->context_id = context_id ; /* presentation context identifier (0x0) */
325 rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */
327 /* num and vers. of interface client is using */
328 memcpy(&(rpc->abstract), abstract, sizeof(rpc->abstract));
330 /* num and vers. of interface to use for replies */
331 memcpy(&(rpc->transfer), transfer, sizeof(rpc->transfer));
336 /*******************************************************************
337 reads or writes an RPC_HDR_RB structure.
338 ********************************************************************/
339 BOOL smb_io_rpc_hdr_rb(char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
341 if (rpc == NULL) return False;
343 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
346 smb_io_rpc_hdr_bba("", &(rpc->bba), ps, depth);
348 prs_uint32("num_elements", ps, depth, &(rpc->num_elements));
349 prs_uint16("context_id ", ps, depth, &(rpc->context_id ));
350 prs_uint8 ("num_syntaxes", ps, depth, &(rpc->num_syntaxes));
352 smb_io_rpc_iface("", &(rpc->abstract), ps, depth);
353 smb_io_rpc_iface("", &(rpc->transfer), ps, depth);
358 /*******************************************************************
359 creates an RPC_RESULTS structure.
361 lkclXXXX only one reason at the moment!
363 ********************************************************************/
364 static BOOL make_rpc_results(RPC_RESULTS *res,
365 uint8 num_results, uint16 result, uint16 reason)
367 if (res == NULL) return False;
369 res->num_results = num_results; /* the number of results (0x01) */
370 res->result = result ; /* result (0x00 = accept) */
371 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!
381 ********************************************************************/
382 static BOOL smb_io_rpc_results(char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
384 if (res == NULL) return False;
386 prs_debug(ps, depth, desc, "smb_io_rpc_results");
391 prs_uint8 ("num_results", ps, depth, &(res->num_results));
395 prs_uint16("result ", ps, depth, &(res->result ));
396 prs_uint16("reason ", ps, depth, &(res->reason ));
401 /*******************************************************************
402 creates an RPC_HDR_BA structure.
404 lkclXXXX only one reason at the moment!
405 jfm: nope two ! The pipe_addr can be NULL !
407 ********************************************************************/
408 BOOL make_rpc_hdr_ba(RPC_HDR_BA *rpc,
409 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
411 uint8 num_results, uint16 result, uint16 reason,
414 if (rpc == NULL || transfer == NULL) return False;
416 make_rpc_hdr_bba (&(rpc->bba ), max_tsize, max_rsize, assoc_gid);
417 make_rpc_addr_str(&(rpc->addr), pipe_addr);
418 make_rpc_results (&(rpc->res ), num_results, result, reason);
420 /* the transfer syntax from the request */
421 memcpy(&(rpc->transfer), transfer, sizeof(rpc->transfer));
426 /*******************************************************************
427 reads or writes an RPC_HDR_BA structure.
428 ********************************************************************/
429 BOOL smb_io_rpc_hdr_ba(char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
431 if (rpc == NULL) return False;
433 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
436 smb_io_rpc_hdr_bba ("", &(rpc->bba) , ps, depth);
437 smb_io_rpc_addr_str("", &(rpc->addr) , ps, depth);
438 smb_io_rpc_results ("", &(rpc->res) , ps, depth);
439 smb_io_rpc_iface ("", &(rpc->transfer), ps, depth);
444 /*******************************************************************
445 creates an RPC_HDR_REQ structure.
446 ********************************************************************/
447 BOOL make_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
449 if (hdr == NULL) return False;
451 hdr->alloc_hint = alloc_hint; /* allocation hint */
452 hdr->context_id = 0; /* presentation context identifier */
453 hdr->opnum = opnum; /* opnum */
458 /*******************************************************************
459 reads or writes an RPC_HDR_REQ structure.
460 ********************************************************************/
461 BOOL smb_io_rpc_hdr_req(char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
463 if (rpc == NULL) return False;
465 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
468 prs_uint32("alloc_hint", ps, depth, &(rpc->alloc_hint));
469 prs_uint16("context_id", ps, depth, &(rpc->context_id));
470 prs_uint16("opnum ", ps, depth, &(rpc->opnum));
475 /*******************************************************************
476 reads or writes an RPC_HDR_RESP structure.
477 ********************************************************************/
478 BOOL smb_io_rpc_hdr_resp(char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
480 if (rpc == NULL) return False;
482 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
485 prs_uint32("alloc_hint", ps, depth, &(rpc->alloc_hint));
486 prs_uint16("context_id", ps, depth, &(rpc->context_id));
487 prs_uint8 ("cancel_ct ", ps, depth, &(rpc->cancel_count));
488 prs_uint8 ("reserved ", ps, depth, &(rpc->reserved));
493 /*******************************************************************
494 creates an RPC_HDR_AUTHA structure.
495 ********************************************************************/
496 BOOL make_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
497 uint16 max_tsize, uint16 max_rsize,
498 uint8 auth_type, uint8 auth_level,
501 if (rai == NULL) return False;
503 rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
504 rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */
506 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
507 rai->auth_level = auth_level; /* 0x06 */
508 rai->stub_type_len = stub_type_len; /* 0x00 */
509 rai->padding = 0; /* padding 0x00 */
511 rai->unknown = 0x0014a0c0; /* non-zero pointer to something */
516 /*******************************************************************
517 reads or writes an RPC_HDR_AUTHA structure.
518 ********************************************************************/
519 BOOL smb_io_rpc_hdr_autha(char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
521 if (rai == NULL) return False;
523 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
526 prs_uint16("max_tsize ", ps, depth, &(rai->max_tsize));
527 prs_uint16("max_rsize ", ps, depth, &(rai->max_rsize));
529 prs_uint8 ("auth_type ", ps, depth, &(rai->auth_type )); /* 0x0a nt lm ssp */
530 prs_uint8 ("auth_level ", ps, depth, &(rai->auth_level ));/* 0x06 */
531 prs_uint8 ("stub_type_len", ps, depth, &(rai->stub_type_len));
532 prs_uint8 ("padding ", ps, depth, &(rai->padding ));
534 prs_uint32("unknown ", ps, depth, &(rai->unknown )); /* 0x0014a0c0 */
539 /*******************************************************************
540 checks an RPC_HDR_AUTH structure.
541 ********************************************************************/
542 BOOL rpc_hdr_auth_chk(RPC_HDR_AUTH *rai)
544 return ((rai->auth_type == 0x0a || rai->auth_type == 0x44) &&
545 rai->auth_level == 0x06);
550 /*******************************************************************
551 creates an RPC_HDR_AUTH structure.
552 ********************************************************************/
553 BOOL make_rpc_hdr_auth(RPC_HDR_AUTH *rai,
554 uint8 auth_type, uint8 auth_level,
558 if (rai == NULL) return False;
560 rai->auth_type = auth_type; /* nt lm ssp 0x0a */
561 rai->auth_level = auth_level; /* 0x06 */
562 rai->stub_type_len = stub_type_len; /* 0x00 */
563 rai->padding = 0; /* padding 0x00 */
565 rai->unknown = ptr; /* non-zero pointer to something */
570 /*******************************************************************
571 reads or writes an RPC_HDR_AUTH structure.
572 ********************************************************************/
573 BOOL smb_io_rpc_hdr_auth(char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
575 if (rai == NULL) return False;
577 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
580 prs_uint8 ("auth_type ", ps, depth, &(rai->auth_type )); /* 0x0a nt lm ssp */
581 prs_uint8 ("auth_level ", ps, depth, &(rai->auth_level ));/* 0x06 */
582 prs_uint8 ("stub_type_len", ps, depth, &(rai->stub_type_len));
583 prs_uint8 ("padding ", ps, depth, &(rai->padding ));
585 prs_uint32("unknown ", ps, depth, &(rai->unknown )); /* 0x0014a0c0 */
590 /*******************************************************************
591 checks an RPC_AUTH_NTLMSSP_VERIFIER structure.
592 ********************************************************************/
593 BOOL rpc_auth_ntlmssp_verifier_chk(RPC_AUTH_NTLMSSP_VERIFIER *rav,
594 char *signature, uint32 msg_type)
596 return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
601 /*******************************************************************
602 creates an RPC_AUTH_NTLMSSP_VERIFIER structure.
603 ********************************************************************/
604 BOOL make_rpc_auth_ntlmssp_verifier(RPC_AUTH_NTLMSSP_VERIFIER *rav,
605 char *signature, uint32 msg_type)
607 if (rav == NULL) return False;
609 fstrcpy(rav->signature, signature); /* "NTLMSSP" */
610 rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
615 /*******************************************************************
616 reads or writes an RPC_AUTH_NTLMSSP_VERIFIER structure.
617 ********************************************************************/
618 BOOL smb_io_rpc_auth_ntlmssp_verifier(char *desc, RPC_AUTH_NTLMSSP_VERIFIER *rav, prs_struct *ps, int depth)
620 if (rav == NULL) return False;
622 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
625 prs_string("signature", ps, depth, rav->signature, 0, sizeof(rav->signature)); /* "NTLMSSP" */
626 prs_uint32("msg_type ", ps, depth, &(rav->msg_type )); /* NTLMSSP_MESSAGE_TYPE */
631 /*******************************************************************
632 creates an RPC_AUTH_NTLMSSP_NEG structure.
633 ********************************************************************/
634 BOOL make_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
636 fstring myname, fstring domain)
638 int len_myname = strlen(myname);
639 int len_domain = strlen(domain);
641 if (neg == NULL) return False;
643 neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
645 make_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname);
646 make_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20);
648 fstrcpy(neg->myname, myname);
649 fstrcpy(neg->domain, domain);
654 /*******************************************************************
655 reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
657 *** lkclXXXX HACK ALERT! ***
659 ********************************************************************/
660 BOOL smb_io_rpc_auth_ntlmssp_neg(char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
662 if (neg == NULL) return False;
664 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
667 prs_uint32("neg_flgs ", ps, depth, &(neg->neg_flgs));
677 smb_io_strhdr("hdr_domain", &(neg->hdr_domain), ps, depth);
678 smb_io_strhdr("hdr_myname", &(neg->hdr_myname), ps, depth);
680 old_offset = ps->offset;
682 ps->offset = neg->hdr_myname .buffer + 0x50; /* lkclXXXX HACK! */
683 prs_uint8s(True , "myname", ps, depth, (uint8*)neg->myname , MIN(neg->hdr_myname .str_str_len, sizeof(neg->myname )));
684 old_offset += neg->hdr_myname .str_str_len;
686 ps->offset = neg->hdr_domain .buffer + 0x50; /* lkclXXXX HACK! */
687 prs_uint8s(True , "domain", ps, depth, (uint8*)neg->domain , MIN(neg->hdr_domain .str_str_len, sizeof(neg->domain )));
688 old_offset += neg->hdr_domain .str_str_len;
690 ps->offset = old_offset;
695 smb_io_strhdr("hdr_domain", &(neg->hdr_domain), ps, depth);
696 smb_io_strhdr("hdr_myname", &(neg->hdr_myname), ps, depth);
698 prs_uint8s(True , "myname", ps, depth, (uint8*)neg->myname , MIN(neg->hdr_myname .str_str_len, sizeof(neg->myname )));
699 prs_uint8s(True , "domain", ps, depth, (uint8*)neg->domain , MIN(neg->hdr_domain .str_str_len, sizeof(neg->domain )));
705 /*******************************************************************
706 creates an RPC_AUTH_NTLMSSP_CHAL structure.
707 ********************************************************************/
708 BOOL make_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
712 if (chl == NULL) return False;
714 chl->unknown_1 = 0x0;
715 chl->unknown_2 = 0x00000028;
716 chl->neg_flags = neg_flags; /* 0x0082b1 */
718 memcpy(chl->challenge, challenge, sizeof(chl->challenge));
719 bzero (chl->reserved , sizeof(chl->reserved));
724 /*******************************************************************
725 reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
726 ********************************************************************/
727 BOOL smb_io_rpc_auth_ntlmssp_chal(char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
729 if (chl == NULL) return False;
731 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
734 prs_uint32("unknown_1", ps, depth, &(chl->unknown_1)); /* 0x0000 0000 */
735 prs_uint32("unknown_2", ps, depth, &(chl->unknown_2)); /* 0x0000 b2b3 */
736 prs_uint32("neg_flags", ps, depth, &(chl->neg_flags)); /* 0x0000 82b1 */
738 prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge));
739 prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved ));
744 /*******************************************************************
745 creates an RPC_AUTH_NTLMSSP_RESP structure.
747 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
748 *** lkclXXXX the actual offset is at the start of the auth verifier ***
750 ********************************************************************/
751 BOOL make_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
753 uchar *nt_resp, size_t nt_len,
754 char *domain, char *user, char *wks,
758 int dom_len = strlen(domain);
759 int wks_len = strlen(wks );
760 int usr_len = strlen(user );
761 int lm_len = nt_len != 0 ? (lm_resp != NULL ? 24 : 0) : 1;
763 DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
765 if (rsp == NULL) return False;
767 #ifdef DEBUG_PASSWORD
768 DEBUG(100,("lm_resp\n"));
771 dump_data(100, lm_resp, lm_len);
773 DEBUG(100,("nt_resp\n"));
776 dump_data(100, nt_resp, nt_len);
780 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
781 domain, user, wks, neg_flags));
785 if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE))
792 make_str_hdr(&rsp->hdr_domain , dom_len, dom_len, offset);
795 make_str_hdr(&rsp->hdr_usr , usr_len, usr_len, offset);
798 make_str_hdr(&rsp->hdr_wks , wks_len, wks_len, offset);
801 make_str_hdr(&rsp->hdr_lm_resp, lm_len , lm_len , offset);
804 make_str_hdr(&rsp->hdr_nt_resp, nt_len , nt_len , offset);
807 make_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
809 rsp->neg_flags = neg_flags;
811 if (lm_resp != NULL && lm_len != 1)
813 memcpy(rsp->lm_resp, lm_resp, lm_len);
821 memcpy(rsp->nt_resp, nt_resp, nt_len);
828 if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE))
830 ascii_to_unibuf(rsp->domain, domain, sizeof(rsp->domain)-2);
831 ascii_to_unibuf(rsp->user , user , sizeof(rsp->user )-2);
832 ascii_to_unibuf(rsp->wks , wks , sizeof(rsp->wks )-2);
836 fstrcpy(rsp->domain, domain);
837 fstrcpy(rsp->user , user );
838 fstrcpy(rsp->wks , wks );
840 rsp->sess_key[0] = 0;
845 /*******************************************************************
846 reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
848 *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
849 *** lkclXXXX the actual offset is at the start of the auth verifier ***
851 ********************************************************************/
852 BOOL smb_io_rpc_auth_ntlmssp_resp(char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
854 if (rsp == NULL) return False;
856 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
867 smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp , ps, depth);
868 smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp , ps, depth);
869 smb_io_strhdr("hdr_domain ", &rsp->hdr_domain , ps, depth);
870 smb_io_strhdr("hdr_user ", &rsp->hdr_usr , ps, depth);
871 smb_io_strhdr("hdr_wks ", &rsp->hdr_wks , ps, depth);
872 smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth);
874 prs_uint32("neg_flags", ps, depth, &(rsp->neg_flags)); /* 0x0000 82b1 */
876 old_offset = ps->offset;
878 ps->offset = rsp->hdr_domain .buffer + 0x1c;
879 prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain , MIN(rsp->hdr_domain .str_str_len, sizeof(rsp->domain )));
880 old_offset += rsp->hdr_domain .str_str_len;
882 ps->offset = rsp->hdr_usr .buffer + 0x1c;
883 prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user , MIN(rsp->hdr_usr .str_str_len, sizeof(rsp->user )));
884 old_offset += rsp->hdr_usr .str_str_len;
886 ps->offset = rsp->hdr_wks .buffer + 0x1c;
887 prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks , MIN(rsp->hdr_wks .str_str_len, sizeof(rsp->wks )));
888 old_offset += rsp->hdr_wks .str_str_len;
890 ps->offset = rsp->hdr_lm_resp .buffer + 0x1c;
891 prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp , MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp )));
892 old_offset += rsp->hdr_lm_resp .str_str_len;
894 ps->offset = rsp->hdr_nt_resp .buffer + 0x1c;
895 prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp , MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp )));
896 old_offset += rsp->hdr_nt_resp .str_str_len;
898 if (rsp->hdr_sess_key.str_str_len != 0)
900 ps->offset = rsp->hdr_sess_key.buffer + 0x1c;
901 old_offset += rsp->hdr_sess_key.str_str_len;
902 prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key)));
905 ps->offset = old_offset;
910 smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp , ps, depth);
911 smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp , ps, depth);
912 smb_io_strhdr("hdr_domain ", &rsp->hdr_domain , ps, depth);
913 smb_io_strhdr("hdr_user ", &rsp->hdr_usr , ps, depth);
914 smb_io_strhdr("hdr_wks ", &rsp->hdr_wks , ps, depth);
915 smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth);
917 prs_uint32("neg_flags", ps, depth, &(rsp->neg_flags)); /* 0x0000 82b1 */
919 prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain , MIN(rsp->hdr_domain .str_str_len, sizeof(rsp->domain )));
920 prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user , MIN(rsp->hdr_usr .str_str_len, sizeof(rsp->user )));
921 prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks , MIN(rsp->hdr_wks .str_str_len, sizeof(rsp->wks )));
922 prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp , MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp )));
923 prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp , MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp )));
924 prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key)));
930 /*******************************************************************
931 checks an RPC_AUTH_NTLMSSP_CHK structure.
932 ********************************************************************/
933 BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num)
940 if (chk->crc32 != crc32 ||
941 chk->ver != NTLMSSP_SIGN_VERSION ||
942 chk->seq_num != seq_num)
944 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
945 crc32, NTLMSSP_SIGN_VERSION, seq_num));
946 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
947 chk->crc32, chk->ver, chk->seq_num));
955 /*******************************************************************
956 creates an RPC_AUTH_NTLMSSP_CHK structure.
957 ********************************************************************/
958 BOOL make_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
959 uint32 ver, uint32 crc32, uint32 seq_num)
961 if (chk == NULL) return False;
966 chk->seq_num = seq_num ;
971 /*******************************************************************
972 reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
973 ********************************************************************/
974 BOOL smb_io_rpc_auth_ntlmssp_chk(char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
976 if (chk == NULL) return False;
978 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
981 prs_uint32("ver ", ps, depth, &(chk->ver ));
982 prs_uint32("reserved", ps, depth, &(chk->reserved));
983 prs_uint32("crc32 ", ps, depth, &(chk->crc32 ));
984 prs_uint32("seq_num ", ps, depth, &(chk->seq_num ));