r7385: Rewrite the RPC bind parsing functions to follow the spec. I haven't yet
[samba.git] / source / rpc_parse / parse_rpc.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997.
7  *  Copyright (C) Jeremy Allison                    1999.
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include "includes.h"
25
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_RPC_PARSE
28
29 /*******************************************************************
30 interface/version dce/rpc pipe identification
31 ********************************************************************/
32
33 #define TRANS_SYNT_V2                       \
34 {                                           \
35         {                                   \
36                 0x8a885d04, 0x1ceb, 0x11c9, \
37                 { 0x9f, 0xe8 },             \
38                 { 0x08, 0x00,               \
39                   0x2b, 0x10, 0x48, 0x60 }  \
40         }, 0x02                             \
41 }
42
43 #define SYNT_NETLOGON_V2                    \
44 {                                           \
45         {                                   \
46                 0x8a885d04, 0x1ceb, 0x11c9, \
47                 { 0x9f, 0xe8 },             \
48                 { 0x08, 0x00,               \
49                   0x2b, 0x10, 0x48, 0x60 }  \
50         }, 0x02                             \
51 }
52
53 #define SYNT_WKSSVC_V1                      \
54 {                                           \
55         {                                   \
56                 0x6bffd098, 0xa112, 0x3610, \
57                 { 0x98, 0x33 },             \
58                 { 0x46, 0xc3,               \
59                   0xf8, 0x7e, 0x34, 0x5a }  \
60         }, 0x01                             \
61 }
62
63 #define SYNT_SRVSVC_V3                      \
64 {                                           \
65         {                                   \
66                 0x4b324fc8, 0x1670, 0x01d3, \
67                 { 0x12, 0x78 },             \
68                 { 0x5a, 0x47,               \
69                   0xbf, 0x6e, 0xe1, 0x88 }  \
70         }, 0x03                             \
71 }
72
73 #define SYNT_LSARPC_V0                      \
74 {                                           \
75         {                                   \
76                 0x12345778, 0x1234, 0xabcd, \
77                 { 0xef, 0x00 },             \
78                 { 0x01, 0x23,               \
79                   0x45, 0x67, 0x89, 0xab }  \
80         }, 0x00                             \
81 }
82
83 #define SYNT_LSARPC_V0_DS                \
84 {                                           \
85         {                                   \
86                 0x3919286a, 0xb10c, 0x11d0, \
87                 { 0x9b, 0xa8 },             \
88                 { 0x00, 0xc0,               \
89                   0x4f, 0xd9, 0x2e, 0xf5 }  \
90         }, 0x00                             \
91 }
92
93 #define SYNT_SAMR_V1                        \
94 {                                           \
95         {                                   \
96                 0x12345778, 0x1234, 0xabcd, \
97                 { 0xef, 0x00 },             \
98                 { 0x01, 0x23,               \
99                   0x45, 0x67, 0x89, 0xac }  \
100         }, 0x01                             \
101 }
102
103 #define SYNT_NETLOGON_V1                    \
104 {                                           \
105         {                                   \
106                 0x12345678, 0x1234, 0xabcd, \
107                 { 0xef, 0x00 },             \
108                 { 0x01, 0x23,               \
109                   0x45, 0x67, 0xcf, 0xfb }  \
110         }, 0x01                             \
111 }
112
113 #define SYNT_WINREG_V1                      \
114 {                                           \
115         {                                   \
116                 0x338cd001, 0x2244, 0x31f1, \
117                 { 0xaa, 0xaa },             \
118                 { 0x90, 0x00,               \
119                   0x38, 0x00, 0x10, 0x03 }  \
120         }, 0x01                             \
121 }
122
123 #define SYNT_SPOOLSS_V1                     \
124 {                                           \
125         {                                   \
126                 0x12345678, 0x1234, 0xabcd, \
127                 { 0xef, 0x00 },             \
128                 { 0x01, 0x23,               \
129                   0x45, 0x67, 0x89, 0xab }  \
130         }, 0x01                             \
131 }
132
133 #define SYNT_NONE_V0                        \
134 {                                           \
135         {                                   \
136                 0x0, 0x0, 0x0,              \
137                 { 0x00, 0x00 },             \
138                 { 0x00, 0x00,               \
139                   0x00, 0x00, 0x00, 0x00 }  \
140         }, 0x00                             \
141 }
142
143 #define SYNT_NETDFS_V3                      \
144 {                                           \
145         {                                   \
146                 0x4fc742e0, 0x4a10, 0x11cf, \
147                 { 0x82, 0x73 },             \
148                 { 0x00, 0xaa,               \
149                   0x00, 0x4a, 0xe6, 0x73 }  \
150         }, 0x03                             \
151 }
152
153 #define SYNT_ECHO_V1                        \
154 {                                           \
155         {                                   \
156                 0x60a15ec5, 0x4de8, 0x11d7, \
157                 { 0xa6, 0x37 },             \
158                 { 0x00, 0x50,               \
159                   0x56, 0xa2, 0x01, 0x82 }  \
160         }, 0x01                             \
161 }
162
163 #define SYNT_SHUTDOWN_V1                    \
164 {                                           \
165         {                                   \
166                 0x894de0c0, 0x0d55, 0x11d3, \
167                 { 0xa3, 0x22 },             \
168                 { 0x00, 0xc0,               \
169                   0x4f, 0xa3, 0x21, 0xa1 }  \
170         }, 0x01                             \
171 }
172
173 #define SYNT_SVCCTL_V2                      \
174 {                                           \
175         {                                   \
176                 0x367abb81, 0x9844, 0x35f1, \
177                 { 0xad, 0x32 },             \
178                 { 0x98, 0xf0,               \
179                   0x38, 0x00, 0x10, 0x03 }  \
180         }, 0x02                             \
181 }
182
183
184 #define SYNT_EVENTLOG_V0                    \
185 {                                           \
186         {                                   \
187                 0x82273fdc, 0xe32a, 0x18c3, \
188                 { 0x3f, 0x78 },             \
189                 { 0x82, 0x79,               \
190                   0x29, 0xdc, 0x23, 0xea }  \
191         }, 0x00                             \
192 }
193
194 /*
195  * IMPORTANT!!  If you update this structure, make sure to
196  * update the index #defines in smb.h.
197  */
198
199 const struct pipe_id_info pipe_names [] =
200 {
201         /* client pipe , abstract syntax       , server pipe   , transfer syntax */
202         { PIPE_LSARPC  , SYNT_LSARPC_V0        , PIPE_LSASS    , TRANS_SYNT_V2 },
203         { PIPE_LSARPC  , SYNT_LSARPC_V0_DS     , PIPE_LSASS    , TRANS_SYNT_V2 },
204         { PIPE_SAMR    , SYNT_SAMR_V1          , PIPE_LSASS    , TRANS_SYNT_V2 },
205         { PIPE_NETLOGON, SYNT_NETLOGON_V1      , PIPE_LSASS    , TRANS_SYNT_V2 },
206         { PIPE_SRVSVC  , SYNT_SRVSVC_V3        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
207         { PIPE_WKSSVC  , SYNT_WKSSVC_V1        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
208         { PIPE_WINREG  , SYNT_WINREG_V1        , PIPE_WINREG   , TRANS_SYNT_V2 },
209         { PIPE_SPOOLSS , SYNT_SPOOLSS_V1       , PIPE_SPOOLSS  , TRANS_SYNT_V2 },
210         { PIPE_NETDFS  , SYNT_NETDFS_V3        , PIPE_NETDFS   , TRANS_SYNT_V2 },
211         { PIPE_ECHO    , SYNT_ECHO_V1          , PIPE_ECHO     , TRANS_SYNT_V2 },
212         { PIPE_SHUTDOWN, SYNT_SHUTDOWN_V1      , PIPE_SHUTDOWN , TRANS_SYNT_V2 },
213         { PIPE_SVCCTL  , SYNT_SVCCTL_V2        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
214         { PIPE_EVENTLOG, SYNT_EVENTLOG_V0      , PIPE_EVENTLOG , TRANS_SYNT_V2 },
215         { NULL         , SYNT_NONE_V0          , NULL          , SYNT_NONE_V0  }
216 };
217
218 /*******************************************************************
219  Inits an RPC_HDR structure.
220 ********************************************************************/
221
222 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
223                                 uint32 call_id, int data_len, int auth_len)
224 {
225         hdr->major        = 5;               /* RPC version 5 */
226         hdr->minor        = 0;               /* minor version 0 */
227         hdr->pkt_type     = pkt_type;        /* RPC packet type */
228         hdr->flags        = flags;           /* dce/rpc flags */
229         hdr->pack_type[0] = 0x10;            /* little-endian data representation */
230         hdr->pack_type[1] = 0;               /* packed data representation */
231         hdr->pack_type[2] = 0;               /* packed data representation */
232         hdr->pack_type[3] = 0;               /* packed data representation */
233         hdr->frag_len     = data_len;        /* fragment length, fill in later */
234         hdr->auth_len     = auth_len;        /* authentication length */
235         hdr->call_id      = call_id;         /* call identifier - match incoming RPC */
236 }
237
238 /*******************************************************************
239  Reads or writes an RPC_HDR structure.
240 ********************************************************************/
241
242 BOOL smb_io_rpc_hdr(const char *desc,  RPC_HDR *rpc, prs_struct *ps, int depth)
243 {
244         if (rpc == NULL)
245                 return False;
246
247         prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
248         depth++;
249
250         if(!prs_uint8 ("major     ", ps, depth, &rpc->major))
251                 return False;
252
253         if(!prs_uint8 ("minor     ", ps, depth, &rpc->minor))
254                 return False;
255         if(!prs_uint8 ("pkt_type  ", ps, depth, &rpc->pkt_type))
256                 return False;
257         if(!prs_uint8 ("flags     ", ps, depth, &rpc->flags))
258                 return False;
259
260         /* We always marshall in little endian format. */
261         if (MARSHALLING(ps))
262                 rpc->pack_type[0] = 0x10;
263
264         if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
265                 return False;
266         if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
267                 return False;
268         if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
269                 return False;
270         if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
271                 return False;
272
273         /*
274          * If reading and pack_type[0] == 0 then the data is in big-endian
275          * format. Set the flag in the prs_struct to specify reverse-endainness.
276          */
277
278         if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
279                 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
280                 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
281         }
282
283         if(!prs_uint16("frag_len  ", ps, depth, &rpc->frag_len))
284                 return False;
285         if(!prs_uint16("auth_len  ", ps, depth, &rpc->auth_len))
286                 return False;
287         if(!prs_uint32("call_id   ", ps, depth, &rpc->call_id))
288                 return False;
289         return True;
290 }
291
292 /*******************************************************************
293  Reads or writes an RPC_IFACE structure.
294 ********************************************************************/
295
296 static BOOL smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
297 {
298         if (ifc == NULL)
299                 return False;
300
301         prs_debug(ps, depth, desc, "smb_io_rpc_iface");
302         depth++;
303
304         if (!prs_align(ps))
305                 return False;
306
307         if (!smb_io_uuid(  "uuid", &ifc->uuid, ps, depth))
308                 return False;
309
310         if(!prs_uint32 ("version", ps, depth, &ifc->version))
311                 return False;
312
313         return True;
314 }
315
316 /*******************************************************************
317  Inits an RPC_ADDR_STR structure.
318 ********************************************************************/
319
320 static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name)
321 {
322         str->len = strlen(name) + 1;
323         fstrcpy(str->str, name);
324 }
325
326 /*******************************************************************
327  Reads or writes an RPC_ADDR_STR structure.
328 ********************************************************************/
329
330 static BOOL smb_io_rpc_addr_str(const char *desc,  RPC_ADDR_STR *str, prs_struct *ps, int depth)
331 {
332         if (str == NULL)
333                 return False;
334
335         prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
336         depth++;
337         if(!prs_align(ps))
338                 return False;
339
340         if(!prs_uint16 (      "len", ps, depth, &str->len))
341                 return False;
342         if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
343                 return False;
344         return True;
345 }
346
347 /*******************************************************************
348  Inits an RPC_HDR_BBA structure.
349 ********************************************************************/
350
351 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
352 {
353         bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
354         bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
355         bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ 
356 }
357
358 /*******************************************************************
359  Reads or writes an RPC_HDR_BBA structure.
360 ********************************************************************/
361
362 static BOOL smb_io_rpc_hdr_bba(const char *desc,  RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
363 {
364         if (rpc == NULL)
365                 return False;
366
367         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
368         depth++;
369
370         if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
371                 return False;
372         if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
373                 return False;
374         if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
375                 return False;
376         return True;
377 }
378
379 /*******************************************************************
380  Inits an RPC_CONTEXT structure.
381  Note the transfer pointer must remain valid until this is marshalled.
382 ********************************************************************/
383
384 void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, RPC_IFACE *abstract, RPC_IFACE *transfer)
385 {
386         rpc_ctx->context_id   = context_id   ; /* presentation context identifier (0x0) */
387         rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */
388
389         /* num and vers. of interface client is using */
390         rpc_ctx->abstract = *abstract;
391
392         /* vers. of interface to use for replies */
393         rpc_ctx->transfer = transfer;
394 }
395
396 /*******************************************************************
397  Inits an RPC_HDR_RB structure.
398  Note the context pointer must remain valid until this is marshalled.
399 ********************************************************************/
400
401 void init_rpc_hdr_rb(RPC_HDR_RB *rpc, 
402                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
403                                 RPC_CONTEXT *context)
404 {
405         init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
406
407         rpc->num_contexts = 1;
408         rpc->rpc_context = context;
409 }
410
411 /*******************************************************************
412  Reads or writes an RPC_CONTEXT structure.
413 ********************************************************************/
414
415 BOOL smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth)
416 {
417         int i;
418
419         if (rpc_ctx == NULL)
420                 return False;
421
422         if(!prs_align(ps))
423                 return False;
424         if(!prs_uint16("context_id  ", ps, depth, &rpc_ctx->context_id ))
425                 return False;
426         if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))
427                 return False;
428
429         /* num_transfer_syntaxes must not be zero. */
430         if (rpc_ctx->num_transfer_syntaxes == 0)
431                 return False;
432
433         if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))
434                 return False;
435
436         if (UNMARSHALLING(ps)) {
437                 if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {
438                         return False;
439                 }
440         }
441
442         for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {
443                 if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))
444                         return False;
445         }
446         return True;
447
448
449 /*******************************************************************
450  Reads or writes an RPC_HDR_RB structure.
451 ********************************************************************/
452
453 BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
454 {
455         int i;
456         
457         if (rpc == NULL)
458                 return False;
459
460         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
461         depth++;
462
463         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
464                 return False;
465
466         if(!prs_uint32("num_contexts", ps, depth, &rpc->num_contexts))
467                 return False;
468
469         rpc->num_contexts &= 0xff; /* Actually a 1 byte field.. */
470
471         /* num_contexts must not be zero. */
472         if (rpc->num_contexts == 0)
473                 return False;
474
475         if (UNMARSHALLING(ps)) {
476                 if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {
477                         return False;
478                 }
479         }
480
481         for (i = 0; i < rpc->num_contexts; i++ ) {
482                 if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))
483                         return False;
484         }
485
486         return True;
487 }
488
489 /*******************************************************************
490  Inits an RPC_RESULTS structure.
491
492  lkclXXXX only one reason at the moment!
493 ********************************************************************/
494
495 static void init_rpc_results(RPC_RESULTS *res, 
496                                 uint8 num_results, uint16 result, uint16 reason)
497 {
498         res->num_results = num_results; /* the number of results (0x01) */
499         res->result      = result     ;  /* result (0x00 = accept) */
500         res->reason      = reason     ;  /* reason (0x00 = no reason specified) */
501 }
502
503 /*******************************************************************
504  Reads or writes an RPC_RESULTS structure.
505
506  lkclXXXX only one reason at the moment!
507 ********************************************************************/
508
509 static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
510 {
511         if (res == NULL)
512                 return False;
513
514         prs_debug(ps, depth, desc, "smb_io_rpc_results");
515         depth++;
516
517         if(!prs_align(ps))
518                 return False;
519         
520         if(!prs_uint8 ("num_results", ps, depth, &res->num_results))    
521                 return False;
522
523         if(!prs_align(ps))
524                 return False;
525         
526         if(!prs_uint16("result     ", ps, depth, &res->result))
527                 return False;
528         if(!prs_uint16("reason     ", ps, depth, &res->reason))
529                 return False;
530         return True;
531 }
532
533 /*******************************************************************
534  Init an RPC_HDR_BA structure.
535
536  lkclXXXX only one reason at the moment!
537
538 ********************************************************************/
539
540 void init_rpc_hdr_ba(RPC_HDR_BA *rpc, 
541                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
542                                 const char *pipe_addr,
543                                 uint8 num_results, uint16 result, uint16 reason,
544                                 RPC_IFACE *transfer)
545 {
546         init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
547         init_rpc_addr_str(&rpc->addr, pipe_addr);
548         init_rpc_results (&rpc->res, num_results, result, reason);
549
550         /* the transfer syntax from the request */
551         memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
552 }
553
554 /*******************************************************************
555  Reads or writes an RPC_HDR_BA structure.
556 ********************************************************************/
557
558 BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
559 {
560         if (rpc == NULL)
561                 return False;
562
563         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
564         depth++;
565
566         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
567                 return False;
568         if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
569                 return False;
570         if(!smb_io_rpc_results("", &rpc->res, ps, depth))
571                 return False;
572         if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
573                 return False;
574         return True;
575 }
576
577 /*******************************************************************
578  Init an RPC_HDR_REQ structure.
579 ********************************************************************/
580
581 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
582 {
583         hdr->alloc_hint   = alloc_hint; /* allocation hint */
584         hdr->context_id   = 0;         /* presentation context identifier */
585         hdr->opnum        = opnum;     /* opnum */
586 }
587
588 /*******************************************************************
589  Reads or writes an RPC_HDR_REQ structure.
590 ********************************************************************/
591
592 BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
593 {
594         if (rpc == NULL)
595                 return False;
596
597         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
598         depth++;
599
600         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
601                 return False;
602         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
603                 return False;
604         if(!prs_uint16("opnum     ", ps, depth, &rpc->opnum))
605                 return False;
606         return True;
607 }
608
609 /*******************************************************************
610  Reads or writes an RPC_HDR_RESP structure.
611 ********************************************************************/
612
613 BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
614 {
615         if (rpc == NULL)
616                 return False;
617
618         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
619         depth++;
620
621         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
622                 return False;
623         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
624                 return False;
625         if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
626                 return False;
627         if(!prs_uint8 ("reserved  ", ps, depth, &rpc->reserved))
628                 return False;
629         return True;
630 }
631
632 /*******************************************************************
633  Reads or writes an RPC_HDR_FAULT structure.
634 ********************************************************************/
635
636 BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
637 {
638         if (rpc == NULL)
639                 return False;
640
641         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
642         depth++;
643
644         if(!prs_ntstatus("status  ", ps, depth, &rpc->status))
645                 return False;
646         if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
647                 return False;
648
649     return True;
650 }
651
652 /*******************************************************************
653  Init an RPC_HDR_AUTHA structure.
654 ********************************************************************/
655
656 void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
657                                 uint16 max_tsize, uint16 max_rsize,
658                                 uint8 auth_type, uint8 auth_level,
659                                 uint8 stub_type_len)
660 {
661         rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
662         rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
663
664         rai->auth_type     = auth_type; /* nt lm ssp 0x0a */
665         rai->auth_level    = auth_level; /* 0x06 */
666         rai->stub_type_len = stub_type_len; /* 0x00 */
667         rai->padding       = 0; /* padding 0x00 */
668
669         rai->unknown       = 0x0014a0c0; /* non-zero pointer to something */
670 }
671
672 /*******************************************************************
673  Reads or writes an RPC_HDR_AUTHA structure.
674 ********************************************************************/
675
676 BOOL smb_io_rpc_hdr_autha(const char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
677 {
678         if (rai == NULL)
679                 return False;
680
681         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
682         depth++;
683
684         if(!prs_uint16("max_tsize    ", ps, depth, &rai->max_tsize))
685                 return False;
686         if(!prs_uint16("max_rsize    ", ps, depth, &rai->max_rsize))
687                 return False;
688
689         if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
690                 return False;
691         if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level)) /* 0x06 */
692                 return False;
693         if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
694                 return False;
695         if(!prs_uint8 ("padding      ", ps, depth, &rai->padding))
696                 return False;
697
698         if(!prs_uint32("unknown      ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
699                 return False;
700
701         return True;
702 }
703
704 /*******************************************************************
705  Inits an RPC_HDR_AUTH structure.
706 ********************************************************************/
707
708 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
709                                 uint8 auth_type, uint8 auth_level,
710                                 uint8 padding,
711                                 uint32 ptr)
712 {
713         rai->auth_type     = auth_type; /* nt lm ssp 0x0a */
714         rai->auth_level    = auth_level; /* 0x06 */
715         rai->padding       = padding;
716         rai->reserved      = 0;
717
718         rai->auth_context  = ptr; /* non-zero pointer to something */
719 }
720
721 /*******************************************************************
722  Reads or writes an RPC_HDR_AUTH structure.
723 ********************************************************************/
724
725 BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
726 {
727         if (rai == NULL)
728                 return False;
729
730         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
731         depth++;
732
733         if(!prs_align(ps))
734                 return False;
735
736         if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
737                 return False;
738         if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level)) /* 0x06 */
739                 return False;
740         if(!prs_uint8 ("padding      ", ps, depth, &rai->padding))
741                 return False;
742         if(!prs_uint8 ("reserved     ", ps, depth, &rai->reserved))
743                 return False;
744         if(!prs_uint32("auth_context ", ps, depth, &rai->auth_context))
745                 return False;
746
747         return True;
748 }
749
750 /*******************************************************************
751  Checks an RPC_AUTH_VERIFIER structure.
752 ********************************************************************/
753
754 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
755                                 const char *signature, uint32 msg_type)
756 {
757         return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
758 }
759
760 /*******************************************************************
761  Inits an RPC_AUTH_VERIFIER structure.
762 ********************************************************************/
763
764 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
765                                 const char *signature, uint32 msg_type)
766 {
767         fstrcpy(rav->signature, signature); /* "NTLMSSP" */
768         rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
769 }
770
771 /*******************************************************************
772  Reads or writes an RPC_AUTH_VERIFIER structure.
773 ********************************************************************/
774
775 BOOL smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
776 {
777         if (rav == NULL)
778                 return False;
779
780         prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
781         depth++;
782
783         /* "NTLMSSP" */
784         if(!prs_string("signature", ps, depth, rav->signature,
785                         sizeof(rav->signature)))
786                 return False;
787         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
788                 return False;
789
790         return True;
791 }
792
793 /*******************************************************************
794  This parses an RPC_AUTH_VERIFIER for NETLOGON schannel. I think
795  assuming "NTLMSSP" in sm_io_rpc_auth_verifier is somewhat wrong.
796  I have to look at that later...
797 ********************************************************************/
798
799 BOOL smb_io_rpc_netsec_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
800 {
801         if (rav == NULL)
802                 return False;
803
804         prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
805         depth++;
806
807         if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
808                 return False;
809         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
810                 return False;
811
812         return True;
813 }
814
815 /*******************************************************************
816  Inits an RPC_AUTH_NTLMSSP_NEG structure.
817 ********************************************************************/
818
819 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
820                                 uint32 neg_flgs,
821                                 const char *myname, const char *domain)
822 {
823         int len_myname = strlen(myname);
824         int len_domain = strlen(domain);
825
826         neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
827
828         init_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname); 
829         init_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20); 
830
831         fstrcpy(neg->myname, myname);
832         fstrcpy(neg->domain, domain);
833 }
834
835 /*******************************************************************
836  Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
837
838  *** lkclXXXX HACK ALERT! ***
839 ********************************************************************/
840
841 BOOL smb_io_rpc_auth_ntlmssp_neg(const char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
842 {
843         uint32 start_offset = prs_offset(ps);
844         if (neg == NULL)
845                 return False;
846
847         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
848         depth++;
849
850         if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs))
851                 return False;
852
853         if (ps->io) {
854                 uint32 old_offset;
855                 uint32 old_neg_flags = neg->neg_flgs;
856
857                 /* reading */
858
859                 ZERO_STRUCTP(neg);
860
861                 neg->neg_flgs = old_neg_flags;
862
863                 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
864                         return False;
865                 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
866                         return False;
867
868                 old_offset = prs_offset(ps);
869
870                 if(!prs_set_offset(ps, neg->hdr_myname.buffer + start_offset - 12))
871                         return False;
872
873                 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname, 
874                                 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
875                         return False;
876
877                 old_offset += neg->hdr_myname.str_str_len;
878
879                 if(!prs_set_offset(ps, neg->hdr_domain.buffer + start_offset - 12))
880                         return False;
881
882                 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain, 
883                         MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain  ))))
884                         return False;
885
886                 old_offset += neg->hdr_domain  .str_str_len;
887
888                 if(!prs_set_offset(ps, old_offset))
889                         return False;
890         } else {
891                 /* writing */
892                 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
893                         return False;
894                 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
895                         return False;
896
897                 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname, 
898                                         MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
899                         return False;
900                 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain, 
901                                         MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain  ))))
902                         return False;
903         }
904
905         return True;
906 }
907
908 /*******************************************************************
909 creates an RPC_AUTH_NTLMSSP_CHAL structure.
910 ********************************************************************/
911
912 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
913                                 uint32 neg_flags,
914                                 uint8 challenge[8])
915 {
916         chl->unknown_1 = 0x0; 
917         chl->unknown_2 = 0x00000028;
918         chl->neg_flags = neg_flags; /* 0x0082b1 */
919
920         memcpy(chl->challenge, challenge, sizeof(chl->challenge)); 
921         memset((char *)chl->reserved , '\0', sizeof(chl->reserved)); 
922 }
923
924 /*******************************************************************
925  Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
926 ********************************************************************/
927
928 BOOL smb_io_rpc_auth_ntlmssp_chal(const char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
929 {
930         if (chl == NULL)
931                 return False;
932
933         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
934         depth++;
935
936         if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */
937                 return False;
938         if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */
939                 return False;
940         if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */
941                 return False;
942
943         if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)))
944                 return False;
945         if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )))
946                 return False;
947
948         return True;
949 }
950
951 /*******************************************************************
952  Inits an RPC_AUTH_NTLMSSP_RESP structure.
953
954  *** lkclXXXX FUDGE!  HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
955  *** lkclXXXX the actual offset is at the start of the auth verifier    ***
956 ********************************************************************/
957
958 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
959                                 uchar lm_resp[24], uchar nt_resp[24],
960                                 const char *domain, const char *user, const char *wks,
961                                 uint32 neg_flags)
962 {
963         uint32 offset;
964         int dom_len = strlen(domain);
965         int wks_len = strlen(wks);
966         int usr_len = strlen(user);
967         int lm_len  = (lm_resp != NULL) ? 24 : 0;
968         int nt_len  = (nt_resp != NULL) ? 24 : 0;
969
970         DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
971
972 #ifdef DEBUG_PASSWORD
973         DEBUG(100,("lm_resp\n"));
974         dump_data(100, (char *)lm_resp, 24);
975         DEBUG(100,("nt_resp\n"));
976         dump_data(100, (char *)nt_resp, 24);
977 #endif
978
979         DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
980                   domain, user, wks, neg_flags));
981
982         offset = 0x40;
983
984         if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
985                 dom_len *= 2;
986                 wks_len *= 2;
987                 usr_len *= 2;
988         }
989
990         init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset);
991         offset += dom_len;
992
993         init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset);
994         offset += usr_len;
995
996         init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset);
997         offset += wks_len;
998
999         init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset);
1000         offset += lm_len;
1001
1002         init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset);
1003         offset += nt_len;
1004
1005         init_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
1006
1007         rsp->neg_flags = neg_flags;
1008
1009         memcpy(rsp->lm_resp, lm_resp, 24);
1010         memcpy(rsp->nt_resp, nt_resp, 24);
1011
1012         if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
1013                 rpcstr_push(rsp->domain, domain, sizeof(rsp->domain), 0);
1014                 rpcstr_push(rsp->user, user, sizeof(rsp->user), 0);
1015                 rpcstr_push(rsp->wks, wks, sizeof(rsp->wks), 0);
1016         } else {
1017                 fstrcpy(rsp->domain, domain);
1018                 fstrcpy(rsp->user, user);
1019                 fstrcpy(rsp->wks, wks);
1020         }
1021         
1022         rsp->sess_key[0] = 0;
1023 }
1024
1025 /*******************************************************************
1026  Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
1027
1028  *** lkclXXXX FUDGE!  HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
1029  *** lkclXXXX the actual offset is at the start of the auth verifier    ***
1030 ********************************************************************/
1031
1032 BOOL smb_io_rpc_auth_ntlmssp_resp(const char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
1033 {
1034         if (rsp == NULL)
1035                 return False;
1036
1037         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
1038         depth++;
1039
1040         if (ps->io) {
1041                 uint32 old_offset;
1042
1043                 /* reading */
1044
1045                 ZERO_STRUCTP(rsp);
1046
1047                 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
1048                         return False;
1049                 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
1050                         return False;
1051                 if(!smb_io_strhdr("hdr_domain  ", &rsp->hdr_domain, ps, depth))
1052                         return False;
1053                 if(!smb_io_strhdr("hdr_user    ", &rsp->hdr_usr, ps, depth))
1054                         return False;
1055                 if(!smb_io_strhdr("hdr_wks     ", &rsp->hdr_wks, ps, depth)) 
1056                         return False;
1057                 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1058                         return False;
1059
1060                 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1061                         return False;
1062
1063                 old_offset = prs_offset(ps);
1064
1065                 if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0xc))
1066                         return False;
1067
1068                 if(!prs_uint8s(True , "domain  ", ps, depth, (uint8*)rsp->domain,
1069                                 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1070                         return False;
1071
1072                 old_offset += rsp->hdr_domain.str_str_len;
1073
1074                 if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0xc))
1075                         return False;
1076
1077                 if(!prs_uint8s(True , "user    ", ps, depth, (uint8*)rsp->user,
1078                                 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1079                         return False;
1080
1081                 old_offset += rsp->hdr_usr.str_str_len;
1082
1083                 if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0xc))
1084                         return False;
1085
1086                 if(!prs_uint8s(True, "wks     ", ps, depth, (uint8*)rsp->wks,
1087                                 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1088                         return False;
1089
1090                 old_offset += rsp->hdr_wks.str_str_len;
1091
1092                 if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0xc))
1093                         return False;
1094
1095                 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
1096                                 MIN(rsp->hdr_lm_resp.str_str_len, sizeof(rsp->lm_resp ))))
1097                         return False;
1098
1099                 old_offset += rsp->hdr_lm_resp.str_str_len;
1100
1101                 if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0xc))
1102                         return False;
1103
1104                 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1105                                 MIN(rsp->hdr_nt_resp.str_str_len, sizeof(rsp->nt_resp ))))
1106                         return False;
1107
1108                 old_offset += rsp->hdr_nt_resp.str_str_len;
1109
1110                 if (rsp->hdr_sess_key.str_str_len != 0) {
1111
1112                         if(!prs_set_offset(ps, rsp->hdr_sess_key.buffer + 0x10))
1113                                 return False;
1114
1115                         old_offset += rsp->hdr_sess_key.str_str_len;
1116
1117                         if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1118                                         MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1119                                 return False;
1120                 }
1121
1122                 if(!prs_set_offset(ps, old_offset))
1123                         return False;
1124         } else {
1125                 /* writing */
1126                 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
1127                         return False;
1128                 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
1129                         return False;
1130                 if(!smb_io_strhdr("hdr_domain  ", &rsp->hdr_domain, ps, depth))
1131                         return False;
1132                 if(!smb_io_strhdr("hdr_user    ", &rsp->hdr_usr, ps, depth))
1133                         return False;
1134                 if(!smb_io_strhdr("hdr_wks     ", &rsp->hdr_wks, ps, depth))
1135                         return False;
1136                 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1137                         return False;
1138
1139                 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1140                         return False;
1141
1142                 if(!prs_uint8s(True , "domain  ", ps, depth, (uint8*)rsp->domain,
1143                                 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1144                         return False;
1145
1146                 if(!prs_uint8s(True , "user    ", ps, depth, (uint8*)rsp->user,
1147                                 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1148                         return False;
1149
1150                 if(!prs_uint8s(True , "wks     ", ps, depth, (uint8*)rsp->wks,
1151                                 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1152                         return False;
1153                 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
1154                                 MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp))))
1155                         return False;
1156                 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1157                                 MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))))
1158                         return False;
1159                 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1160                                 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1161                         return False;
1162         }
1163
1164         return True;
1165 }
1166
1167 /*******************************************************************
1168  Checks an RPC_AUTH_NTLMSSP_CHK structure.
1169 ********************************************************************/
1170
1171 BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num)
1172 {
1173         if (chk == NULL)
1174                 return False;
1175
1176         if (chk->crc32 != crc32 ||
1177             chk->ver   != NTLMSSP_SIGN_VERSION ||
1178             chk->seq_num != seq_num)
1179         {
1180                 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1181                          chk->crc32, chk->ver, chk->seq_num));
1182                         
1183                 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1184                         crc32, NTLMSSP_SIGN_VERSION, seq_num));
1185                 return False;
1186         }
1187         return True;
1188 }
1189
1190 /*******************************************************************
1191  Inits an RPC_AUTH_NTLMSSP_CHK structure.
1192 ********************************************************************/
1193
1194 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
1195                                 uint32 ver, uint32 crc32, uint32 seq_num)
1196 {
1197         chk->ver      = ver;
1198         chk->reserved = 0x0;
1199         chk->crc32    = crc32;
1200         chk->seq_num  = seq_num;
1201 }
1202
1203 /*******************************************************************
1204  Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1205 ********************************************************************/
1206
1207 BOOL smb_io_rpc_auth_ntlmssp_chk(const char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
1208 {
1209         if (chk == NULL)
1210                 return False;
1211
1212         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
1213         depth++;
1214
1215         if(!prs_align(ps))
1216                 return False;
1217
1218         if(!prs_uint32("ver     ", ps, depth, &chk->ver))
1219                 return False;
1220         if(!prs_uint32("reserved", ps, depth, &chk->reserved))
1221                 return False;
1222         if(!prs_uint32("crc32   ", ps, depth, &chk->crc32))
1223                 return False;
1224         if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num))
1225                 return False;
1226
1227         return True;
1228 }
1229
1230 /*******************************************************************
1231 creates an RPC_AUTH_NETSEC_NEG structure.
1232 ********************************************************************/
1233 void init_rpc_auth_netsec_neg(RPC_AUTH_NETSEC_NEG *neg,
1234                               const char *domain, const char *myname)
1235 {
1236         neg->type1 = 0;
1237         neg->type2 = 0x3;
1238         fstrcpy(neg->domain, domain);
1239         fstrcpy(neg->myname, myname);
1240 }
1241
1242 /*******************************************************************
1243  Reads or writes an RPC_AUTH_NETSEC_NEG structure.
1244 ********************************************************************/
1245
1246 BOOL smb_io_rpc_auth_netsec_neg(const char *desc, RPC_AUTH_NETSEC_NEG *neg,
1247                                 prs_struct *ps, int depth)
1248 {
1249         if (neg == NULL)
1250                 return False;
1251
1252         prs_debug(ps, depth, desc, "smb_io_rpc_auth_netsec_neg");
1253         depth++;
1254
1255         if(!prs_align(ps))
1256                 return False;
1257
1258         if(!prs_uint32("type1", ps, depth, &neg->type1))
1259                 return False;
1260         if(!prs_uint32("type2", ps, depth, &neg->type2))
1261                 return False;
1262         if(!prs_string("domain  ", ps, depth, neg->domain, sizeof(neg->domain)))
1263                 return False;
1264         if(!prs_string("myname  ", ps, depth, neg->myname, sizeof(neg->myname)))
1265                 return False;
1266
1267         return True;
1268 }
1269
1270 /*******************************************************************
1271 reads or writes an RPC_AUTH_NETSEC_CHK structure.
1272 ********************************************************************/
1273 BOOL smb_io_rpc_auth_netsec_chk(const char *desc, int auth_len, 
1274                                 RPC_AUTH_NETSEC_CHK * chk,
1275                                 prs_struct *ps, int depth)
1276 {
1277         if (chk == NULL)
1278                 return False;
1279
1280         prs_debug(ps, depth, desc, "smb_io_rpc_auth_netsec_chk");
1281         depth++;
1282
1283         if ( !prs_uint8s(False, "sig  ", ps, depth, chk->sig, sizeof(chk->sig)) )
1284                 return False;
1285                 
1286         if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )
1287                 return False;
1288                 
1289         if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )
1290                 return False;
1291         
1292         if ( auth_len == RPC_AUTH_NETSEC_SIGN_OR_SEAL_CHK_LEN ) {
1293                 if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )
1294                         return False;
1295         }
1296
1297         return True;
1298 }
1299