6b4deb00cf1345a65510e44912e2769380b3392c
[samba.git] / source3 / rpc_parse / parse_rpc.c
1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
5  *  RPC Pipe client / server routines
6  *  Copyright (C) Andrew Tridgell              1992-1997,
7  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8  *  Copyright (C) Paul Ashton                       1997.
9  *  
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.
14  *  
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.
19  *  
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.
23  */
24
25
26 #include "includes.h"
27
28 extern int DEBUGLEVEL;
29
30
31 /*******************************************************************
32 interface/version dce/rpc pipe identification
33 ********************************************************************/
34
35 #define TRANS_SYNT_V2             \
36 {                                 \
37         {                             \
38                 0x04, 0x5d, 0x88, 0x8a,   \
39                 0xeb, 0x1c, 0xc9, 0x11,   \
40                 0x9f, 0xe8, 0x08, 0x00,   \
41                 0x2b, 0x10, 0x48, 0x60    \
42         }, 0x02                       \
43 }                                 \
44
45 #define SYNT_NETLOGON_V2          \
46 {                                 \
47         {                             \
48                 0x04, 0x5d, 0x88, 0x8a,   \
49                 0xeb, 0x1c, 0xc9, 0x11,   \
50                 0x9f, 0xe8, 0x08, 0x00,   \
51                 0x2b, 0x10, 0x48, 0x60    \
52         }, 0x02                       \
53 }                                 \
54
55 #define SYNT_WKSSVC_V1            \
56 {                                 \
57         {                             \
58                 0x98, 0xd0, 0xff, 0x6b,   \
59                 0x12, 0xa1, 0x10, 0x36,   \
60                 0x98, 0x33, 0x46, 0xc3,   \
61                 0xf8, 0x7e, 0x34, 0x5a    \
62         }, 0x01                       \
63 }                                 \
64
65 #define SYNT_SRVSVC_V3            \
66 {                                 \
67         {                             \
68                 0xc8, 0x4f, 0x32, 0x4b,   \
69                 0x70, 0x16, 0xd3, 0x01,   \
70                 0x12, 0x78, 0x5a, 0x47,   \
71                 0xbf, 0x6e, 0xe1, 0x88    \
72         }, 0x03                       \
73 }                                 \
74
75 #define SYNT_LSARPC_V0            \
76 {                                 \
77         {                             \
78                 0x78, 0x57, 0x34, 0x12,   \
79                 0x34, 0x12, 0xcd, 0xab,   \
80                 0xef, 0x00, 0x01, 0x23,   \
81                 0x45, 0x67, 0x89, 0xab    \
82         }, 0x00                       \
83 }                                 \
84
85 #define SYNT_SAMR_V1              \
86 {                                 \
87         {                             \
88                 0x78, 0x57, 0x34, 0x12,   \
89                 0x34, 0x12, 0xcd, 0xab,   \
90                 0xef, 0x00, 0x01, 0x23,   \
91                 0x45, 0x67, 0x89, 0xac    \
92         }, 0x01                       \
93 }                                 \
94
95 #define SYNT_NETLOGON_V1          \
96 {                                 \
97         {                             \
98                 0x78, 0x56, 0x34, 0x12,   \
99                 0x34, 0x12, 0xcd, 0xab,   \
100                 0xef, 0x00, 0x01, 0x23,   \
101                 0x45, 0x67, 0xcf, 0xfb    \
102         }, 0x01                       \
103 }                                 \
104
105 #define SYNT_WINREG_V1            \
106 {                                 \
107         {                             \
108                 0x01, 0xd0, 0x8c, 0x33,   \
109                 0x44, 0x22, 0xf1, 0x31,   \
110                 0xaa, 0xaa, 0x90, 0x00,   \
111                 0x38, 0x00, 0x10, 0x03    \
112         }, 0x01                       \
113 }                                 \
114
115 #define SYNT_NONE_V0              \
116 {                                 \
117         {                             \
118                 0x00, 0x00, 0x00, 0x00,   \
119                 0x00, 0x00, 0x00, 0x00,   \
120                 0x00, 0x00, 0x00, 0x00,   \
121                 0x00, 0x00, 0x00, 0x00    \
122         }, 0x00                       \
123 }                                 \
124
125 /* pipe string names */
126 #define PIPE_SRVSVC   "\\PIPE\\srvsvc"
127 #define PIPE_SAMR     "\\PIPE\\samr"
128 #define PIPE_WINREG   "\\PIPE\\winreg"
129 #define PIPE_WKSSVC   "\\PIPE\\wkssvc"
130 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
131 #define PIPE_NTLSA    "\\PIPE\\ntlsa"
132 #define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
133 #define PIPE_LSASS    "\\PIPE\\lsass"
134 #define PIPE_LSARPC   "\\PIPE\\lsarpc"
135
136 struct pipe_id_info pipe_names [] =
137 {
138         /* client pipe , abstract syntax , server pipe   , transfer syntax */
139         { PIPE_LSARPC  , SYNT_LSARPC_V0  , PIPE_LSASS    , TRANS_SYNT_V2 },
140         { PIPE_SAMR    , SYNT_SAMR_V1    , PIPE_LSASS    , TRANS_SYNT_V2 },
141         { PIPE_NETLOGON, SYNT_NETLOGON_V1, PIPE_LSASS    , TRANS_SYNT_V2 },
142         { PIPE_SRVSVC  , SYNT_SRVSVC_V3  , PIPE_NTSVCS   , TRANS_SYNT_V2 },
143         { PIPE_WKSSVC  , SYNT_WKSSVC_V1  , PIPE_NTSVCS   , TRANS_SYNT_V2 },
144         { PIPE_WINREG  , SYNT_WINREG_V1  , PIPE_WINREG   , TRANS_SYNT_V2 },
145         { NULL         , SYNT_NONE_V0    , NULL          , SYNT_NONE_V0  }
146 };
147
148 /*******************************************************************
149 creates an RPC_HDR structure.
150 ********************************************************************/
151 void make_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
152                                 uint32 call_id, int data_len, int auth_len)
153 {
154         if (hdr == NULL) return;
155
156         hdr->major        = 5;               /* RPC version 5 */
157         hdr->minor        = 0;               /* minor version 0 */
158         hdr->pkt_type     = pkt_type;        /* RPC packet type */
159         hdr->flags        = flags;           /* dce/rpc flags */
160         hdr->pack_type    = 0x10;            /* packed data representation */
161         hdr->frag_len     = data_len;        /* fragment length, fill in later */
162         hdr->auth_len     = auth_len;        /* authentication length */
163         hdr->call_id      = call_id;         /* call identifier - match incoming RPC */
164 }
165
166 /*******************************************************************
167 reads or writes an RPC_HDR structure.
168 ********************************************************************/
169 void smb_io_rpc_hdr(char *desc,  RPC_HDR *rpc, prs_struct *ps, int depth)
170 {
171         if (rpc == NULL) return;
172
173         prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
174         depth++;
175
176         prs_uint8 ("major     ", ps, depth, &(rpc->major));
177         prs_uint8 ("minor     ", ps, depth, &(rpc->minor));
178         prs_uint8 ("pkt_type  ", ps, depth, &(rpc->pkt_type));
179         prs_uint8 ("flags     ", ps, depth, &(rpc->flags));
180         prs_uint32("pack_type ", ps, depth, &(rpc->pack_type));
181         prs_uint16("frag_len  ", ps, depth, &(rpc->frag_len));
182         prs_uint16("auth_len  ", ps, depth, &(rpc->auth_len));
183         prs_uint32("call_id   ", ps, depth, &(rpc->call_id));
184 }
185
186 /*******************************************************************
187 reads or writes an RPC_IFACE structure.
188 ********************************************************************/
189 static void smb_io_rpc_iface(char *desc,  RPC_IFACE *ifc, prs_struct *ps, int depth)
190 {
191         if (ifc == NULL) return;
192
193         prs_debug(ps, depth, desc, "smb_io_rpc_iface");
194         depth++;
195
196         prs_align(ps);
197
198         prs_uint8s (False, "data   ", ps, depth, ifc->data, sizeof(ifc->data));
199         prs_uint32 (       "version", ps, depth, &(ifc->version));
200 }
201
202 /*******************************************************************
203 creates an RPC_ADDR_STR structure.
204 ********************************************************************/
205 static void make_rpc_addr_str(RPC_ADDR_STR *str, char *name)
206 {
207         if (str == NULL || name == NULL) return;
208
209         str->len = strlen(name) + 1;
210         fstrcpy(str->str, name);
211 }
212
213 /*******************************************************************
214 reads or writes an RPC_ADDR_STR structure.
215 ********************************************************************/
216 static void smb_io_rpc_addr_str(char *desc,  RPC_ADDR_STR *str, prs_struct *ps, int depth)
217 {
218         if (str == NULL) return;
219
220         prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
221         depth++;
222         prs_align(ps);
223
224         prs_uint16 (      "len", ps, depth, &(str->len));
225         prs_uint8s (True, "str", ps, depth, (uchar*)str->str, str->len);
226 }
227
228 /*******************************************************************
229 creates an RPC_HDR_BBA structure.
230 ********************************************************************/
231 static void make_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
232 {
233         if (bba == NULL) return;
234
235         bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
236         bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
237         bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ 
238 }
239
240 /*******************************************************************
241 reads or writes an RPC_HDR_BBA structure.
242 ********************************************************************/
243 static void smb_io_rpc_hdr_bba(char *desc,  RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
244 {
245         if (rpc == NULL) return;
246
247         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
248         depth++;
249
250         prs_uint16("max_tsize", ps, depth, &(rpc->max_tsize));
251         prs_uint16("max_rsize", ps, depth, &(rpc->max_rsize));
252         prs_uint32("assoc_gid", ps, depth, &(rpc->assoc_gid));
253 }
254
255 /*******************************************************************
256 creates an RPC_HDR_RB structure.
257 ********************************************************************/
258 void make_rpc_hdr_rb(RPC_HDR_RB *rpc, 
259                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
260                                 uint32 num_elements, uint16 context_id, uint8 num_syntaxes,
261                                 RPC_IFACE *abstract, RPC_IFACE *transfer)
262 {
263         if (rpc == NULL) return;
264
265         make_rpc_hdr_bba(&(rpc->bba), max_tsize, max_rsize, assoc_gid);
266
267         rpc->num_elements = num_elements ; /* the number of elements (0x1) */
268         rpc->context_id   = context_id   ; /* presentation context identifier (0x0) */
269         rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */
270
271         /* num and vers. of interface client is using */
272         memcpy(&(rpc->abstract), abstract, sizeof(rpc->abstract));
273
274         /* num and vers. of interface to use for replies */
275         memcpy(&(rpc->transfer), transfer, sizeof(rpc->transfer));
276 }
277
278 /*******************************************************************
279 reads or writes an RPC_HDR_RB structure.
280 ********************************************************************/
281 void smb_io_rpc_hdr_rb(char *desc,  RPC_HDR_RB *rpc, prs_struct *ps, int depth)
282 {
283         if (rpc == NULL) return;
284
285         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
286         depth++;
287
288         smb_io_rpc_hdr_bba("", &(rpc->bba), ps, depth);
289
290         prs_uint32("num_elements", ps, depth, &(rpc->num_elements));
291         prs_uint16("context_id  ", ps, depth, &(rpc->context_id  ));
292         prs_uint8 ("num_syntaxes", ps, depth, &(rpc->num_syntaxes));
293
294         smb_io_rpc_iface("", &(rpc->abstract), ps, depth);
295         smb_io_rpc_iface("", &(rpc->transfer), ps, depth);
296 }
297
298 /*******************************************************************
299 creates an RPC_RESULTS structure.
300
301 lkclXXXX only one reason at the moment!
302
303 ********************************************************************/
304 static void make_rpc_results(RPC_RESULTS *res, 
305                                 uint8 num_results, uint16 result, uint16 reason)
306 {
307         if (res == NULL) return;
308
309         res->num_results = num_results; /* the number of results (0x01) */
310         res->result      = result     ;  /* result (0x00 = accept) */
311         res->reason      = reason     ;  /* reason (0x00 = no reason specified) */
312 }
313
314 /*******************************************************************
315 reads or writes an RPC_RESULTS structure.
316
317 lkclXXXX only one reason at the moment!
318
319 ********************************************************************/
320 static void smb_io_rpc_results(char *desc,  RPC_RESULTS *res, prs_struct *ps, int depth)
321 {
322         if (res == NULL) return;
323
324         prs_debug(ps, depth, desc, "smb_io_rpc_results");
325         depth++;
326
327         prs_align(ps);
328         
329         prs_uint8 ("num_results", ps, depth, &(res->num_results));
330
331         prs_align(ps);
332         
333         prs_uint16("result     ", ps, depth, &(res->result     ));
334         prs_uint16("reason     ", ps, depth, &(res->reason     ));
335 }
336
337 /*******************************************************************
338 creates an RPC_HDR_BA structure.
339
340 lkclXXXX only one reason at the moment!
341
342 ********************************************************************/
343 void make_rpc_hdr_ba(RPC_HDR_BA *rpc, 
344                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
345                                 char *pipe_addr,
346                                 uint8 num_results, uint16 result, uint16 reason,
347                                 RPC_IFACE *transfer)
348 {
349         if (rpc == NULL || transfer == NULL || pipe_addr == NULL) return;
350
351         make_rpc_hdr_bba (&(rpc->bba ), max_tsize, max_rsize, assoc_gid);
352         make_rpc_addr_str(&(rpc->addr), pipe_addr);
353         make_rpc_results (&(rpc->res ), num_results, result, reason);
354
355         /* the transfer syntax from the request */
356         memcpy(&(rpc->transfer), transfer, sizeof(rpc->transfer));
357 }
358
359 /*******************************************************************
360 reads or writes an RPC_HDR_BA structure.
361 ********************************************************************/
362 void smb_io_rpc_hdr_ba(char *desc,  RPC_HDR_BA *rpc, prs_struct *ps, int depth)
363 {
364         if (rpc == NULL) return;
365
366         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
367         depth++;
368
369         smb_io_rpc_hdr_bba ("", &(rpc->bba)     , ps, depth);
370         smb_io_rpc_addr_str("", &(rpc->addr)    , ps, depth);
371         smb_io_rpc_results ("", &(rpc->res)     , ps, depth);
372         smb_io_rpc_iface   ("", &(rpc->transfer), ps, depth);
373 }
374
375 /*******************************************************************
376 creates an RPC_HDR_REQ structure.
377 ********************************************************************/
378 void make_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
379 {
380         if (hdr == NULL) return;
381
382         hdr->alloc_hint   = alloc_hint; /* allocation hint */
383         hdr->context_id   = 0;         /* presentation context identifier */
384         hdr->opnum        = opnum;     /* opnum */
385 }
386
387 /*******************************************************************
388 reads or writes an RPC_HDR_REQ structure.
389 ********************************************************************/
390 void smb_io_rpc_hdr_req(char *desc,  RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
391 {
392         if (rpc == NULL) return;
393
394         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
395         depth++;
396
397         prs_uint32("alloc_hint", ps, depth, &(rpc->alloc_hint));
398         prs_uint16("context_id", ps, depth, &(rpc->context_id));
399         prs_uint16("opnum     ", ps, depth, &(rpc->opnum));
400 }
401
402 /*******************************************************************
403 reads or writes an RPC_HDR_RESP structure.
404 ********************************************************************/
405 void smb_io_rpc_hdr_resp(char *desc,  RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
406 {
407         if (rpc == NULL) return;
408
409         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
410         depth++;
411
412         prs_uint32("alloc_hint", ps, depth, &(rpc->alloc_hint));
413         prs_uint16("context_id", ps, depth, &(rpc->context_id));
414         prs_uint8 ("cancel_ct ", ps, depth, &(rpc->cancel_count));
415         prs_uint8 ("reserved  ", ps, depth, &(rpc->reserved));
416 }
417
418 /*******************************************************************
419 creates an RPC_HDR_AUTHA structure.
420 ********************************************************************/
421 void make_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
422                                 uint16 max_tsize, uint16 max_rsize,
423                                 uint8 auth_type, uint8 auth_level,
424                                 uint8 stub_type_len)
425 {
426         if (rai == NULL) return;
427
428         rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
429         rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
430
431         rai->auth_type     = auth_type; /* nt lm ssp 0x0a */
432         rai->auth_level    = auth_level; /* 0x06 */
433         rai->stub_type_len = stub_type_len; /* 0x00 */
434         rai->padding       = 0; /* padding 0x00 */
435
436         rai->unknown       = 0x0014a0c0; /* non-zero pointer to something */
437 }
438
439 /*******************************************************************
440 reads or writes an RPC_HDR_AUTHA structure.
441 ********************************************************************/
442 void smb_io_rpc_hdr_autha(char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
443 {
444         if (rai == NULL) return;
445
446         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
447         depth++;
448
449         prs_uint16("max_tsize    ", ps, depth, &(rai->max_tsize));
450         prs_uint16("max_rsize    ", ps, depth, &(rai->max_rsize));
451
452         prs_uint8 ("auth_type    ", ps, depth, &(rai->auth_type    )); /* 0x0a nt lm ssp */
453         prs_uint8 ("auth_level   ", ps, depth, &(rai->auth_level   ));/* 0x06 */
454         prs_uint8 ("stub_type_len", ps, depth, &(rai->stub_type_len));
455         prs_uint8 ("padding      ", ps, depth, &(rai->padding      ));
456
457         prs_uint32("unknown      ", ps, depth, &(rai->unknown      )); /* 0x0014a0c0 */
458 }
459
460 /*******************************************************************
461 creates an RPC_HDR_AUTH structure.
462 ********************************************************************/
463 void make_rpc_hdr_auth(RPC_HDR_AUTH *rai,
464                                 uint8 auth_type, uint8 auth_level,
465                                 uint8 stub_type_len)
466 {
467         if (rai == NULL) return;
468
469         rai->auth_type     = auth_type; /* nt lm ssp 0x0a */
470         rai->auth_level    = auth_level; /* 0x06 */
471         rai->stub_type_len = stub_type_len; /* 0x00 */
472         rai->padding       = 0; /* padding 0x00 */
473
474         rai->unknown       = 0x0014a0c0; /* non-zero pointer to something */
475 }
476
477 /*******************************************************************
478 reads or writes an RPC_HDR_AUTH structure.
479 ********************************************************************/
480 void smb_io_rpc_hdr_auth(char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
481 {
482         if (rai == NULL) return;
483
484         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
485         depth++;
486
487         prs_uint8 ("auth_type    ", ps, depth, &(rai->auth_type    )); /* 0x0a nt lm ssp */
488         prs_uint8 ("auth_level   ", ps, depth, &(rai->auth_level   ));/* 0x06 */
489         prs_uint8 ("stub_type_len", ps, depth, &(rai->stub_type_len));
490         prs_uint8 ("padding      ", ps, depth, &(rai->padding      ));
491
492         prs_uint32("unknown      ", ps, depth, &(rai->unknown      )); /* 0x0014a0c0 */
493 }
494
495 /*******************************************************************
496 creates an RPC_AUTH_VERIFIER structure.
497 ********************************************************************/
498 void make_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
499                                 char *signature, uint32 msg_type)
500 {
501         if (rav == NULL) return;
502
503         fstrcpy(rav->signature, signature); /* "NTLMSSP" */
504         rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
505 }
506
507 /*******************************************************************
508 reads or writes an RPC_AUTH_VERIFIER structure.
509 ********************************************************************/
510 void smb_io_rpc_auth_verifier(char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
511 {
512         if (rav == NULL) return;
513
514         prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
515         depth++;
516
517         prs_string("signature", ps, depth, rav->signature, 0, sizeof(rav->signature)); /* "NTLMSSP" */
518         prs_uint32("msg_type ", ps, depth, &(rav->msg_type  )); /* NTLMSSP_MESSAGE_TYPE */
519 }
520
521 /*******************************************************************
522 creates an RPC_AUTH_NTLMSSP_NEG structure.
523 ********************************************************************/
524 void make_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
525                                 uint32 neg_flgs,
526                                 fstring myname, fstring domain)
527 {
528         int len_myname = strlen(myname);
529         int len_domain = strlen(domain);
530
531         if (neg == NULL) return;
532
533         neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
534
535         make_str_hdr(&neg->hdr_myname, len_myname+1, len_myname+1, 0x20); 
536         make_str_hdr(&neg->hdr_domain, len_domain+1, len_domain+1, 0x20 + len_myname+1); 
537
538         fstrcpy(neg->myname, myname);
539         fstrcpy(neg->domain, domain);
540 }
541
542 /*******************************************************************
543 reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
544 ********************************************************************/
545 void smb_io_rpc_auth_ntlmssp_neg(char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
546 {
547         if (neg == NULL) return;
548
549         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
550         depth++;
551
552         prs_uint32("neg_flgs ", ps, depth, &(neg->neg_flgs));
553
554         smb_io_strhdr("hdr_myname", &(neg->hdr_myname), ps, depth); 
555         smb_io_strhdr("hdr_domain", &(neg->hdr_domain), ps, depth); 
556
557         prs_string("domain", ps, depth, neg->domain, neg->hdr_domain.str_str_len-1, sizeof(neg->domain)); 
558         prs_string("myname", ps, depth, neg->myname, neg->hdr_myname.str_str_len-1, sizeof(neg->myname)); 
559 }
560
561 /*******************************************************************
562 creates an RPC_AUTH_NTLMSSP_CHAL structure.
563 ********************************************************************/
564 void make_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
565                                 uint32 neg_flags,
566                                 uint8 challenge[8])
567 {
568         if (chl == NULL) return;
569
570         chl->unknown_1 = 0x0; 
571         chl->unknown_2 = 0x00000028;
572         chl->neg_flags = neg_flags; /* 0x0082b1 */
573
574         memcpy(chl->challenge, challenge, sizeof(chl->challenge)); 
575         bzero (chl->reserved ,            sizeof(chl->reserved)); 
576 }
577
578 /*******************************************************************
579 reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
580 ********************************************************************/
581 void smb_io_rpc_auth_ntlmssp_chal(char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
582 {
583         if (chl == NULL) return;
584
585         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
586         depth++;
587
588         prs_uint32("unknown_1", ps, depth, &(chl->unknown_1)); /* 0x0000 0000 */
589         prs_uint32("unknown_2", ps, depth, &(chl->unknown_2)); /* 0x0000 b2b3 */
590         prs_uint32("neg_flags", ps, depth, &(chl->neg_flags)); /* 0x0000 82b1 */
591
592         prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge));
593         prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved ));
594 }
595
596 /*******************************************************************
597 creates an RPC_AUTH_NTLMSSP_RESP structure.
598
599 *** lkclXXXX FUDGE!  HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
600 *** lkclXXXX the actual offset is at the start of the auth verifier    ***
601
602 ********************************************************************/
603 void make_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
604                                 uchar lm_resp[24], uchar nt_resp[24],
605                                 char *domain, char *user, char *wks,
606                                 uint32 neg_flags)
607 {
608         uint32 offset;
609         int dom_len = strlen(domain);
610         int wks_len = strlen(wks   );
611         int usr_len = strlen(user  );
612         int lm_len  = lm_resp != NULL ? 24 : 0;
613         int nt_len  = nt_resp != NULL ? 24 : 0;
614
615         DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
616
617         if (rsp == NULL) return;
618
619 #ifdef DEBUG_PASSWORD
620         DEBUG(100,("lm_resp\n"));
621         dump_data(100, lm_resp, 24);
622         DEBUG(100,("nt_resp\n"));
623         dump_data(100, nt_resp, 24);
624 #endif
625
626         DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
627                   domain, user, wks, neg_flags));
628
629         offset = 0x40;
630
631         if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE))
632         {
633                 dom_len *= 2;
634                 wks_len *= 2;
635                 usr_len *= 2;
636         }
637
638         make_str_hdr(&rsp->hdr_domain , dom_len, dom_len, offset);
639         offset += dom_len;
640
641         make_str_hdr(&rsp->hdr_usr    , usr_len, usr_len, offset);
642         offset += usr_len;
643
644         make_str_hdr(&rsp->hdr_wks    , wks_len, wks_len, offset);
645         offset += wks_len;
646
647         make_str_hdr(&rsp->hdr_lm_resp, lm_len , lm_len , offset);
648         offset += lm_len;
649
650         make_str_hdr(&rsp->hdr_nt_resp, nt_len , nt_len , offset);
651         offset += nt_len;
652
653         make_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
654
655         rsp->neg_flags = neg_flags;
656
657         memcpy(&rsp->lm_resp, lm_resp, 24);
658         memcpy(&rsp->nt_resp, nt_resp, 24);
659
660         if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE))
661         {
662                 struni2((uint16*)rsp->domain, domain);
663                 struni2((uint16*)rsp->user  , user  );
664                 struni2((uint16*)rsp->wks   , wks   );
665         }
666         else
667         {
668                 fstrcpy(rsp->domain, domain);
669                 fstrcpy(rsp->user  , user  );
670                 fstrcpy(rsp->wks   , wks   );
671         }
672         rsp->sess_key[0] = 0;
673 }
674
675 /*******************************************************************
676 reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
677
678 *** lkclXXXX FUDGE!  HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
679 *** lkclXXXX the actual offset is at the start of the auth verifier    ***
680
681 ********************************************************************/
682 void smb_io_rpc_auth_ntlmssp_resp(char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
683 {
684         if (rsp == NULL) return;
685
686         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
687         depth++;
688
689         if (ps->io)
690         {
691                 uint32 old_offset;
692
693                 /* reading */
694
695                 ZERO_STRUCTP(rsp);
696
697                 smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp , ps, depth); 
698                 smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp , ps, depth); 
699                 smb_io_strhdr("hdr_domain  ", &rsp->hdr_domain  , ps, depth); 
700                 smb_io_strhdr("hdr_user    ", &rsp->hdr_usr     , ps, depth); 
701                 smb_io_strhdr("hdr_wks     ", &rsp->hdr_wks     , ps, depth); 
702                 smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth); 
703
704                 prs_uint32("neg_flags", ps, depth, &(rsp->neg_flags)); /* 0x0000 82b1 */
705
706                 old_offset = ps->offset;
707
708                 ps->offset = rsp->hdr_domain  .buffer + 0x1c;
709                 prs_uint8s(True , "domain  ", ps, depth, (uint8*)rsp->domain  , MIN(rsp->hdr_domain  .str_str_len, sizeof(rsp->domain  ))); 
710                 old_offset += rsp->hdr_domain  .str_str_len;
711
712                 ps->offset = rsp->hdr_usr     .buffer + 0x1c;
713                 prs_uint8s(True , "user    ", ps, depth, (uint8*)rsp->user    , MIN(rsp->hdr_usr     .str_str_len, sizeof(rsp->user    ))); 
714                 old_offset += rsp->hdr_usr     .str_str_len;
715
716                 ps->offset = rsp->hdr_wks     .buffer + 0x1c;
717                 prs_uint8s(True , "wks     ", ps, depth, (uint8*)rsp->wks     , MIN(rsp->hdr_wks     .str_str_len, sizeof(rsp->wks     ))); 
718                 old_offset += rsp->hdr_wks     .str_str_len;
719
720                 ps->offset = rsp->hdr_lm_resp .buffer + 0x1c;
721                 prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp , MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp ))); 
722                 old_offset += rsp->hdr_lm_resp .str_str_len;
723
724                 ps->offset = rsp->hdr_nt_resp .buffer + 0x1c;
725                 prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp , MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))); 
726                 old_offset += rsp->hdr_nt_resp .str_str_len;
727
728                 if (rsp->hdr_sess_key.str_str_len != 0)
729                 {
730                         ps->offset = rsp->hdr_sess_key.buffer + 0x1c;
731                         old_offset += rsp->hdr_sess_key.str_str_len;
732                         prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))); 
733                 }
734
735                 ps->offset = old_offset;
736         }
737         else
738         {
739                 /* writing */
740                 smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp , ps, depth); 
741                 smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp , ps, depth); 
742                 smb_io_strhdr("hdr_domain  ", &rsp->hdr_domain  , ps, depth); 
743                 smb_io_strhdr("hdr_user    ", &rsp->hdr_usr     , ps, depth); 
744                 smb_io_strhdr("hdr_wks     ", &rsp->hdr_wks     , ps, depth); 
745                 smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth); 
746
747                 prs_uint32("neg_flags", ps, depth, &(rsp->neg_flags)); /* 0x0000 82b1 */
748
749                 prs_uint8s(True , "domain  ", ps, depth, (uint8*)rsp->domain  , MIN(rsp->hdr_domain  .str_str_len, sizeof(rsp->domain  ))); 
750                 prs_uint8s(True , "user    ", ps, depth, (uint8*)rsp->user    , MIN(rsp->hdr_usr     .str_str_len, sizeof(rsp->user    ))); 
751                 prs_uint8s(True , "wks     ", ps, depth, (uint8*)rsp->wks     , MIN(rsp->hdr_wks     .str_str_len, sizeof(rsp->wks     ))); 
752                 prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp , MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp ))); 
753                 prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp , MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))); 
754                 prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))); 
755         }
756 }
757
758 /*******************************************************************
759 creates an RPC_AUTH_NTLMSSP_CHK structure.
760 ********************************************************************/
761 void make_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
762                                 uint32 ver, uint32 crc32, uint32 seq_num)
763 {
764         if (chk == NULL) return;
765
766         chk->ver      = ver     ;
767         chk->reserved = 0x0;
768         chk->crc32    = crc32   ;
769         chk->seq_num  = seq_num ;
770 }
771
772 /*******************************************************************
773 reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
774 ********************************************************************/
775 void smb_io_rpc_auth_ntlmssp_chk(char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
776 {
777         if (chk == NULL) return;
778
779         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
780         depth++;
781
782         prs_uint32("ver     ", ps, depth, &(chk->ver     )); 
783         prs_uint32("reserved", ps, depth, &(chk->reserved)); 
784         prs_uint32("crc32   ", ps, depth, &(chk->crc32   )); 
785         prs_uint32("seq_num ", ps, depth, &(chk->seq_num )); 
786 }
787