preparing for release of 3.0-alpha13
[Samba.git] / source / rpc_parse / parse_rpc.c
blobf4a84adee3978030586239cfb201e30672821d4f
1 /*
2 * Unix SMB/Netbios implementation.
3 * Version 1.9.
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.
9 *
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.
25 #include "includes.h"
27 /*******************************************************************
28 interface/version dce/rpc pipe identification
29 ********************************************************************/
31 #define TRANS_SYNT_V2 \
32 { \
33 { \
34 0x8a885d04, 0x1ceb, 0x11c9, \
35 { 0x9f, 0xe8, 0x08, 0x00, \
36 0x2b, 0x10, 0x48, 0x60 } \
37 }, 0x02 \
40 #define SYNT_NETLOGON_V2 \
41 { \
42 { \
43 0x8a885d04, 0x1ceb, 0x11c9, \
44 { 0x9f, 0xe8, 0x08, 0x00, \
45 0x2b, 0x10, 0x48, 0x60 } \
46 }, 0x02 \
49 #define SYNT_WKSSVC_V1 \
50 { \
51 { \
52 0x6bffd098, 0xa112, 0x3610, \
53 { 0x98, 0x33, 0x46, 0xc3, \
54 0xf8, 0x7e, 0x34, 0x5a } \
55 }, 0x01 \
58 #define SYNT_SRVSVC_V3 \
59 { \
60 { \
61 0x4b324fc8, 0x1670, 0x01d3, \
62 { 0x12, 0x78, 0x5a, 0x47, \
63 0xbf, 0x6e, 0xe1, 0x88 } \
64 }, 0x03 \
67 #define SYNT_LSARPC_V0 \
68 { \
69 { \
70 0x12345778, 0x1234, 0xabcd, \
71 { 0xef, 0x00, 0x01, 0x23, \
72 0x45, 0x67, 0x89, 0xab } \
73 }, 0x00 \
76 #define SYNT_SAMR_V1 \
77 { \
78 { \
79 0x12345778, 0x1234, 0xabcd, \
80 { 0xef, 0x00, 0x01, 0x23, \
81 0x45, 0x67, 0x89, 0xac } \
82 }, 0x01 \
85 #define SYNT_NETLOGON_V1 \
86 { \
87 { \
88 0x12345678, 0x1234, 0xabcd, \
89 { 0xef, 0x00, 0x01, 0x23, \
90 0x45, 0x67, 0xcf, 0xfb } \
91 }, 0x01 \
94 #define SYNT_WINREG_V1 \
95 { \
96 { \
97 0x338cd001, 0x2244, 0x31f1, \
98 { 0xaa, 0xaa, 0x90, 0x00, \
99 0x38, 0x00, 0x10, 0x03 } \
100 }, 0x01 \
103 #define SYNT_SPOOLSS_V1 \
106 0x12345678, 0x1234, 0xabcd, \
107 { 0xef, 0x00, 0x01, 0x23, \
108 0x45, 0x67, 0x89, 0xab } \
109 }, 0x01 \
112 #define SYNT_NONE_V0 \
115 0x0, 0x0, 0x0, \
116 { 0x00, 0x00, 0x00, 0x00, \
117 0x00, 0x00, 0x00, 0x00 } \
118 }, 0x00 \
121 #define SYNT_NETDFS_V3 \
124 0x4fc742e0, 0x4a10, 0x11cf, \
125 { 0x82, 0x73, 0x00, 0xaa, \
126 0x00, 0x4a, 0xe6, 0x73 } \
127 }, 0x03 \
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)
170 if (rpc == NULL)
171 return False;
173 prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
174 depth++;
176 if(!prs_uint8 ("major ", ps, depth, &rpc->major))
177 return False;
179 if(!prs_uint8 ("minor ", ps, depth, &rpc->minor))
180 return False;
181 if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type))
182 return False;
183 if(!prs_uint8 ("flags ", ps, depth, &rpc->flags))
184 return False;
186 /* We always marshall in little endian format. */
187 if (MARSHALLING(ps))
188 rpc->pack_type[0] = 0x10;
190 if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
191 return False;
192 if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
193 return False;
194 if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
195 return False;
196 if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
197 return False;
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))
210 return False;
211 if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len))
212 return False;
213 if(!prs_uint32("call_id ", ps, depth, &rpc->call_id))
214 return False;
215 return True;
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)
224 if (ifc == NULL)
225 return False;
227 prs_debug(ps, depth, desc, "smb_io_rpc_iface");
228 depth++;
230 if(!prs_align(ps))
231 return False;
233 if(!prs_uint32 ("data ", ps, depth, &ifc->uuid.time_low))
234 return False;
235 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_mid))
236 return False;
237 if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_hi_and_version))
238 return False;
240 if(!prs_uint8s (False, "data ", ps, depth, ifc->uuid.remaining, sizeof(ifc->uuid.remaining)))
241 return False;
242 if(!prs_uint32 ( "version", ps, depth, &ifc->version))
243 return False;
245 return True;
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)
264 if (str == NULL)
265 return False;
267 prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
268 depth++;
269 if(!prs_align(ps))
270 return False;
272 if(!prs_uint16 ( "len", ps, depth, &str->len))
273 return False;
274 if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
275 return False;
276 return True;
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)
296 if (rpc == NULL)
297 return False;
299 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
300 depth++;
302 if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
303 return False;
304 if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
305 return False;
306 if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
307 return False;
308 return True;
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)
339 if (rpc == NULL)
340 return False;
342 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
343 depth++;
345 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
346 return False;
348 if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements))
349 return False;
350 if(!prs_uint16("context_id ", ps, depth, &rpc->context_id ))
351 return False;
352 if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes))
353 return False;
355 if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth))
356 return False;
357 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
358 return False;
360 return True;
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)
385 if (res == NULL)
386 return False;
388 prs_debug(ps, depth, desc, "smb_io_rpc_results");
389 depth++;
391 if(!prs_align(ps))
392 return False;
394 if(!prs_uint8 ("num_results", ps, depth, &res->num_results))
395 return False;
397 if(!prs_align(ps))
398 return False;
400 if(!prs_uint16("result ", ps, depth, &res->result))
401 return False;
402 if(!prs_uint16("reason ", ps, depth, &res->reason))
403 return False;
404 return True;
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,
416 char *pipe_addr,
417 uint8 num_results, uint16 result, uint16 reason,
418 RPC_IFACE *transfer)
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)
434 if (rpc == NULL)
435 return False;
437 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
438 depth++;
440 if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
441 return False;
442 if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
443 return False;
444 if(!smb_io_rpc_results("", &rpc->res, ps, depth))
445 return False;
446 if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
447 return False;
448 return True;
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)
468 if (rpc == NULL)
469 return False;
471 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
472 depth++;
474 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
475 return False;
476 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
477 return False;
478 if(!prs_uint16("opnum ", ps, depth, &rpc->opnum))
479 return False;
480 return True;
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)
489 if (rpc == NULL)
490 return False;
492 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
493 depth++;
495 if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
496 return False;
497 if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
498 return False;
499 if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
500 return False;
501 if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved))
502 return False;
503 return True;
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)
512 if (rpc == NULL)
513 return False;
515 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
516 depth++;
518 if(!prs_ntstatus("status ", ps, depth, &rpc->status))
519 return False;
520 if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
521 return False;
523 return True;
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,
533 uint8 stub_type_len)
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)
552 if (rai == NULL)
553 return False;
555 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
556 depth++;
558 if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize))
559 return False;
560 if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize))
561 return False;
563 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
564 return False;
565 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
566 return False;
567 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
568 return False;
569 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
570 return False;
572 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
573 return False;
575 return True;
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,
593 uint8 stub_type_len,
594 uint32 ptr)
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)
610 if (rai == NULL)
611 return False;
613 prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
614 depth++;
616 if(!prs_align(ps))
617 return False;
619 if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
620 return False;
621 if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */
622 return False;
623 if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
624 return False;
625 if(!prs_uint8 ("padding ", ps, depth, &rai->padding))
626 return False;
628 if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
629 return False;
631 return True;
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)
661 if (rav == NULL)
662 return False;
664 prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
665 depth++;
667 /* "NTLMSSP" */
668 if(!prs_string("signature", ps, depth, rav->signature, strlen("NTLMSSP"),
669 sizeof(rav->signature)))
670 return False;
671 if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
672 return False;
674 return True;
677 /*******************************************************************
678 Inits an RPC_AUTH_NTLMSSP_NEG structure.
679 ********************************************************************/
681 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
682 uint32 neg_flgs,
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);
706 if (neg == NULL)
707 return False;
709 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
710 depth++;
712 if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs))
713 return False;
715 if (ps->io) {
716 uint32 old_offset;
717 uint32 old_neg_flags = neg->neg_flgs;
719 /* reading */
721 ZERO_STRUCTP(neg);
723 neg->neg_flgs = old_neg_flags;
725 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
726 return False;
727 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
728 return False;
730 old_offset = prs_offset(ps);
732 if(!prs_set_offset(ps, neg->hdr_myname.buffer + start_offset - 12))
733 return False;
735 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
736 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
737 return False;
739 old_offset += neg->hdr_myname.str_str_len;
741 if(!prs_set_offset(ps, neg->hdr_domain.buffer + start_offset - 12))
742 return False;
744 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
745 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
746 return False;
748 old_offset += neg->hdr_domain .str_str_len;
750 if(!prs_set_offset(ps, old_offset))
751 return False;
752 } else {
753 /* writing */
754 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
755 return False;
756 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
757 return False;
759 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname,
760 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
761 return False;
762 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain,
763 MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain ))))
764 return False;
767 return True;
770 /*******************************************************************
771 creates an RPC_AUTH_NTLMSSP_CHAL structure.
772 ********************************************************************/
774 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
775 uint32 neg_flags,
776 uint8 challenge[8])
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)
792 if (chl == NULL)
793 return False;
795 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
796 depth++;
798 if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */
799 return False;
800 if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */
801 return False;
802 if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */
803 return False;
805 if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)))
806 return False;
807 if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )))
808 return False;
810 return True;
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,
823 uint32 neg_flags)
825 uint32 offset;
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);
839 #endif
841 DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
842 domain, user, wks, neg_flags));
844 offset = 0x40;
846 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
847 dom_len *= 2;
848 wks_len *= 2;
849 usr_len *= 2;
852 init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset);
853 offset += dom_len;
855 init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset);
856 offset += usr_len;
858 init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset);
859 offset += wks_len;
861 init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset);
862 offset += lm_len;
864 init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset);
865 offset += nt_len;
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);
878 } else {
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)
896 if (rsp == NULL)
897 return False;
899 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
900 depth++;
902 if (ps->io) {
903 uint32 old_offset;
905 /* reading */
907 ZERO_STRUCTP(rsp);
909 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
910 return False;
911 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
912 return False;
913 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
914 return False;
915 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
916 return False;
917 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
918 return False;
919 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
920 return False;
922 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
923 return False;
925 old_offset = prs_offset(ps);
927 if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0xc))
928 return False;
930 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
931 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
932 return False;
934 old_offset += rsp->hdr_domain.str_str_len;
936 if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0xc))
937 return False;
939 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
940 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
941 return False;
943 old_offset += rsp->hdr_usr.str_str_len;
945 if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0xc))
946 return False;
948 if(!prs_uint8s(True, "wks ", ps, depth, (uint8*)rsp->wks,
949 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
950 return False;
952 old_offset += rsp->hdr_wks.str_str_len;
954 if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0xc))
955 return False;
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 ))))
959 return False;
961 old_offset += rsp->hdr_lm_resp.str_str_len;
963 if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0xc))
964 return False;
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 ))))
968 return False;
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))
975 return False;
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))))
981 return False;
984 if(!prs_set_offset(ps, old_offset))
985 return False;
986 } else {
987 /* writing */
988 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
989 return False;
990 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
991 return False;
992 if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth))
993 return False;
994 if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth))
995 return False;
996 if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth))
997 return False;
998 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
999 return False;
1001 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1002 return False;
1004 if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain,
1005 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1006 return False;
1008 if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user,
1009 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1010 return False;
1012 if(!prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks,
1013 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1014 return False;
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))))
1017 return False;
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 ))))
1020 return False;
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))))
1023 return False;
1026 return True;
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)
1035 if (chk == NULL)
1036 return False;
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));
1046 return False;
1048 return True;
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)
1058 chk->ver = ver;
1059 chk->reserved = 0x0;
1060 chk->crc32 = crc32;
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)
1070 if (chk == NULL)
1071 return False;
1073 prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
1074 depth++;
1076 if(!prs_align(ps))
1077 return False;
1079 if(!prs_uint32("ver ", ps, depth, &chk->ver))
1080 return False;
1081 if(!prs_uint32("reserved", ps, depth, &chk->reserved))
1082 return False;
1083 if(!prs_uint32("crc32 ", ps, depth, &chk->crc32))
1084 return False;
1085 if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num))
1086 return False;
1088 return True;