r6014: rather large change set....
[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_HDR_RB structure.
381 ********************************************************************/
382
383 void init_rpc_hdr_rb(RPC_HDR_RB *rpc, 
384                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
385                                 uint32 num_elements, uint16 context_id, uint8 num_syntaxes,
386                                 RPC_IFACE *abstract, RPC_IFACE *transfer)
387 {
388         init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
389
390         rpc->num_elements = num_elements ; /* the number of elements (0x1) */
391         rpc->context_id   = context_id   ; /* presentation context identifier (0x0) */
392         rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */
393
394         /* num and vers. of interface client is using */
395         rpc->abstract = *abstract;
396
397         /* num and vers. of interface to use for replies */
398         rpc->transfer = *transfer;
399 }
400
401 /*******************************************************************
402  Reads or writes an RPC_HDR_RB structure.
403 ********************************************************************/
404
405 BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
406 {
407         if (rpc == NULL)
408                 return False;
409
410         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
411         depth++;
412
413         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
414                 return False;
415
416         if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements))
417                 return False;
418         if(!prs_uint16("context_id  ", ps, depth, &rpc->context_id ))
419                 return False;
420         if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes))
421                 return False;
422
423         if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth))
424                 return False;
425         if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
426                 return False;
427
428         return True;
429 }
430
431 /*******************************************************************
432  Inits an RPC_RESULTS structure.
433
434  lkclXXXX only one reason at the moment!
435 ********************************************************************/
436
437 static void init_rpc_results(RPC_RESULTS *res, 
438                                 uint8 num_results, uint16 result, uint16 reason)
439 {
440         res->num_results = num_results; /* the number of results (0x01) */
441         res->result      = result     ;  /* result (0x00 = accept) */
442         res->reason      = reason     ;  /* reason (0x00 = no reason specified) */
443 }
444
445 /*******************************************************************
446  Reads or writes an RPC_RESULTS structure.
447
448  lkclXXXX only one reason at the moment!
449 ********************************************************************/
450
451 static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
452 {
453         if (res == NULL)
454                 return False;
455
456         prs_debug(ps, depth, desc, "smb_io_rpc_results");
457         depth++;
458
459         if(!prs_align(ps))
460                 return False;
461         
462         if(!prs_uint8 ("num_results", ps, depth, &res->num_results))    
463                 return False;
464
465         if(!prs_align(ps))
466                 return False;
467         
468         if(!prs_uint16("result     ", ps, depth, &res->result))
469                 return False;
470         if(!prs_uint16("reason     ", ps, depth, &res->reason))
471                 return False;
472         return True;
473 }
474
475 /*******************************************************************
476  Init an RPC_HDR_BA structure.
477
478  lkclXXXX only one reason at the moment!
479
480 ********************************************************************/
481
482 void init_rpc_hdr_ba(RPC_HDR_BA *rpc, 
483                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
484                                 const char *pipe_addr,
485                                 uint8 num_results, uint16 result, uint16 reason,
486                                 RPC_IFACE *transfer)
487 {
488         init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
489         init_rpc_addr_str(&rpc->addr, pipe_addr);
490         init_rpc_results (&rpc->res, num_results, result, reason);
491
492         /* the transfer syntax from the request */
493         memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
494 }
495
496 /*******************************************************************
497  Reads or writes an RPC_HDR_BA structure.
498 ********************************************************************/
499
500 BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
501 {
502         if (rpc == NULL)
503                 return False;
504
505         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
506         depth++;
507
508         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
509                 return False;
510         if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
511                 return False;
512         if(!smb_io_rpc_results("", &rpc->res, ps, depth))
513                 return False;
514         if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
515                 return False;
516         return True;
517 }
518
519 /*******************************************************************
520  Init an RPC_HDR_REQ structure.
521 ********************************************************************/
522
523 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
524 {
525         hdr->alloc_hint   = alloc_hint; /* allocation hint */
526         hdr->context_id   = 0;         /* presentation context identifier */
527         hdr->opnum        = opnum;     /* opnum */
528 }
529
530 /*******************************************************************
531  Reads or writes an RPC_HDR_REQ structure.
532 ********************************************************************/
533
534 BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
535 {
536         if (rpc == NULL)
537                 return False;
538
539         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
540         depth++;
541
542         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
543                 return False;
544         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
545                 return False;
546         if(!prs_uint16("opnum     ", ps, depth, &rpc->opnum))
547                 return False;
548         return True;
549 }
550
551 /*******************************************************************
552  Reads or writes an RPC_HDR_RESP structure.
553 ********************************************************************/
554
555 BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
556 {
557         if (rpc == NULL)
558                 return False;
559
560         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
561         depth++;
562
563         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
564                 return False;
565         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
566                 return False;
567         if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
568                 return False;
569         if(!prs_uint8 ("reserved  ", ps, depth, &rpc->reserved))
570                 return False;
571         return True;
572 }
573
574 /*******************************************************************
575  Reads or writes an RPC_HDR_FAULT structure.
576 ********************************************************************/
577
578 BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
579 {
580         if (rpc == NULL)
581                 return False;
582
583         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
584         depth++;
585
586         if(!prs_ntstatus("status  ", ps, depth, &rpc->status))
587                 return False;
588         if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
589                 return False;
590
591     return True;
592 }
593
594 /*******************************************************************
595  Init an RPC_HDR_AUTHA structure.
596 ********************************************************************/
597
598 void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai,
599                                 uint16 max_tsize, uint16 max_rsize,
600                                 uint8 auth_type, uint8 auth_level,
601                                 uint8 stub_type_len)
602 {
603         rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
604         rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
605
606         rai->auth_type     = auth_type; /* nt lm ssp 0x0a */
607         rai->auth_level    = auth_level; /* 0x06 */
608         rai->stub_type_len = stub_type_len; /* 0x00 */
609         rai->padding       = 0; /* padding 0x00 */
610
611         rai->unknown       = 0x0014a0c0; /* non-zero pointer to something */
612 }
613
614 /*******************************************************************
615  Reads or writes an RPC_HDR_AUTHA structure.
616 ********************************************************************/
617
618 BOOL smb_io_rpc_hdr_autha(const char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth)
619 {
620         if (rai == NULL)
621                 return False;
622
623         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha");
624         depth++;
625
626         if(!prs_uint16("max_tsize    ", ps, depth, &rai->max_tsize))
627                 return False;
628         if(!prs_uint16("max_rsize    ", ps, depth, &rai->max_rsize))
629                 return False;
630
631         if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
632                 return False;
633         if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level)) /* 0x06 */
634                 return False;
635         if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len))
636                 return False;
637         if(!prs_uint8 ("padding      ", ps, depth, &rai->padding))
638                 return False;
639
640         if(!prs_uint32("unknown      ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */
641                 return False;
642
643         return True;
644 }
645
646 /*******************************************************************
647  Inits an RPC_HDR_AUTH structure.
648 ********************************************************************/
649
650 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
651                                 uint8 auth_type, uint8 auth_level,
652                                 uint8 padding,
653                                 uint32 ptr)
654 {
655         rai->auth_type     = auth_type; /* nt lm ssp 0x0a */
656         rai->auth_level    = auth_level; /* 0x06 */
657         rai->padding       = padding;
658         rai->reserved      = 0;
659
660         rai->auth_context  = ptr; /* non-zero pointer to something */
661 }
662
663 /*******************************************************************
664  Reads or writes an RPC_HDR_AUTH structure.
665 ********************************************************************/
666
667 BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
668 {
669         if (rai == NULL)
670                 return False;
671
672         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
673         depth++;
674
675         if(!prs_align(ps))
676                 return False;
677
678         if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */
679                 return False;
680         if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level)) /* 0x06 */
681                 return False;
682         if(!prs_uint8 ("padding      ", ps, depth, &rai->padding))
683                 return False;
684         if(!prs_uint8 ("reserved     ", ps, depth, &rai->reserved))
685                 return False;
686         if(!prs_uint32("auth_context ", ps, depth, &rai->auth_context))
687                 return False;
688
689         return True;
690 }
691
692 /*******************************************************************
693  Checks an RPC_AUTH_VERIFIER structure.
694 ********************************************************************/
695
696 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
697                                 const char *signature, uint32 msg_type)
698 {
699         return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
700 }
701
702 /*******************************************************************
703  Inits an RPC_AUTH_VERIFIER structure.
704 ********************************************************************/
705
706 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
707                                 const char *signature, uint32 msg_type)
708 {
709         fstrcpy(rav->signature, signature); /* "NTLMSSP" */
710         rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
711 }
712
713 /*******************************************************************
714  Reads or writes an RPC_AUTH_VERIFIER structure.
715 ********************************************************************/
716
717 BOOL smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
718 {
719         if (rav == NULL)
720                 return False;
721
722         prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
723         depth++;
724
725         /* "NTLMSSP" */
726         if(!prs_string("signature", ps, depth, rav->signature,
727                         sizeof(rav->signature)))
728                 return False;
729         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
730                 return False;
731
732         return True;
733 }
734
735 /*******************************************************************
736  This parses an RPC_AUTH_VERIFIER for NETLOGON schannel. I think
737  assuming "NTLMSSP" in sm_io_rpc_auth_verifier is somewhat wrong.
738  I have to look at that later...
739 ********************************************************************/
740
741 BOOL smb_io_rpc_netsec_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
742 {
743         if (rav == NULL)
744                 return False;
745
746         prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
747         depth++;
748
749         if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
750                 return False;
751         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
752                 return False;
753
754         return True;
755 }
756
757 /*******************************************************************
758  Inits an RPC_AUTH_NTLMSSP_NEG structure.
759 ********************************************************************/
760
761 void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg,
762                                 uint32 neg_flgs,
763                                 const char *myname, const char *domain)
764 {
765         int len_myname = strlen(myname);
766         int len_domain = strlen(domain);
767
768         neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */
769
770         init_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname); 
771         init_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20); 
772
773         fstrcpy(neg->myname, myname);
774         fstrcpy(neg->domain, domain);
775 }
776
777 /*******************************************************************
778  Reads or writes an RPC_AUTH_NTLMSSP_NEG structure.
779
780  *** lkclXXXX HACK ALERT! ***
781 ********************************************************************/
782
783 BOOL smb_io_rpc_auth_ntlmssp_neg(const char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth)
784 {
785         uint32 start_offset = prs_offset(ps);
786         if (neg == NULL)
787                 return False;
788
789         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg");
790         depth++;
791
792         if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs))
793                 return False;
794
795         if (ps->io) {
796                 uint32 old_offset;
797                 uint32 old_neg_flags = neg->neg_flgs;
798
799                 /* reading */
800
801                 ZERO_STRUCTP(neg);
802
803                 neg->neg_flgs = old_neg_flags;
804
805                 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
806                         return False;
807                 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
808                         return False;
809
810                 old_offset = prs_offset(ps);
811
812                 if(!prs_set_offset(ps, neg->hdr_myname.buffer + start_offset - 12))
813                         return False;
814
815                 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname, 
816                                 MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
817                         return False;
818
819                 old_offset += neg->hdr_myname.str_str_len;
820
821                 if(!prs_set_offset(ps, neg->hdr_domain.buffer + start_offset - 12))
822                         return False;
823
824                 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain, 
825                         MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain  ))))
826                         return False;
827
828                 old_offset += neg->hdr_domain  .str_str_len;
829
830                 if(!prs_set_offset(ps, old_offset))
831                         return False;
832         } else {
833                 /* writing */
834                 if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth))
835                         return False;
836                 if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth))
837                         return False;
838
839                 if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname, 
840                                         MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname))))
841                         return False;
842                 if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain, 
843                                         MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain  ))))
844                         return False;
845         }
846
847         return True;
848 }
849
850 /*******************************************************************
851 creates an RPC_AUTH_NTLMSSP_CHAL structure.
852 ********************************************************************/
853
854 void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl,
855                                 uint32 neg_flags,
856                                 uint8 challenge[8])
857 {
858         chl->unknown_1 = 0x0; 
859         chl->unknown_2 = 0x00000028;
860         chl->neg_flags = neg_flags; /* 0x0082b1 */
861
862         memcpy(chl->challenge, challenge, sizeof(chl->challenge)); 
863         memset((char *)chl->reserved , '\0', sizeof(chl->reserved)); 
864 }
865
866 /*******************************************************************
867  Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure.
868 ********************************************************************/
869
870 BOOL smb_io_rpc_auth_ntlmssp_chal(const char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth)
871 {
872         if (chl == NULL)
873                 return False;
874
875         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal");
876         depth++;
877
878         if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */
879                 return False;
880         if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */
881                 return False;
882         if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */
883                 return False;
884
885         if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)))
886                 return False;
887         if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )))
888                 return False;
889
890         return True;
891 }
892
893 /*******************************************************************
894  Inits an RPC_AUTH_NTLMSSP_RESP structure.
895
896  *** lkclXXXX FUDGE!  HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
897  *** lkclXXXX the actual offset is at the start of the auth verifier    ***
898 ********************************************************************/
899
900 void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp,
901                                 uchar lm_resp[24], uchar nt_resp[24],
902                                 const char *domain, const char *user, const char *wks,
903                                 uint32 neg_flags)
904 {
905         uint32 offset;
906         int dom_len = strlen(domain);
907         int wks_len = strlen(wks);
908         int usr_len = strlen(user);
909         int lm_len  = (lm_resp != NULL) ? 24 : 0;
910         int nt_len  = (nt_resp != NULL) ? 24 : 0;
911
912         DEBUG(5,("make_rpc_auth_ntlmssp_resp\n"));
913
914 #ifdef DEBUG_PASSWORD
915         DEBUG(100,("lm_resp\n"));
916         dump_data(100, (char *)lm_resp, 24);
917         DEBUG(100,("nt_resp\n"));
918         dump_data(100, (char *)nt_resp, 24);
919 #endif
920
921         DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n",
922                   domain, user, wks, neg_flags));
923
924         offset = 0x40;
925
926         if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
927                 dom_len *= 2;
928                 wks_len *= 2;
929                 usr_len *= 2;
930         }
931
932         init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset);
933         offset += dom_len;
934
935         init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset);
936         offset += usr_len;
937
938         init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset);
939         offset += wks_len;
940
941         init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset);
942         offset += lm_len;
943
944         init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset);
945         offset += nt_len;
946
947         init_str_hdr(&rsp->hdr_sess_key, 0, 0, offset);
948
949         rsp->neg_flags = neg_flags;
950
951         memcpy(rsp->lm_resp, lm_resp, 24);
952         memcpy(rsp->nt_resp, nt_resp, 24);
953
954         if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
955                 rpcstr_push(rsp->domain, domain, sizeof(rsp->domain), 0);
956                 rpcstr_push(rsp->user, user, sizeof(rsp->user), 0);
957                 rpcstr_push(rsp->wks, wks, sizeof(rsp->wks), 0);
958         } else {
959                 fstrcpy(rsp->domain, domain);
960                 fstrcpy(rsp->user, user);
961                 fstrcpy(rsp->wks, wks);
962         }
963         
964         rsp->sess_key[0] = 0;
965 }
966
967 /*******************************************************************
968  Reads or writes an RPC_AUTH_NTLMSSP_RESP structure.
969
970  *** lkclXXXX FUDGE!  HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) ***
971  *** lkclXXXX the actual offset is at the start of the auth verifier    ***
972 ********************************************************************/
973
974 BOOL smb_io_rpc_auth_ntlmssp_resp(const char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth)
975 {
976         if (rsp == NULL)
977                 return False;
978
979         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp");
980         depth++;
981
982         if (ps->io) {
983                 uint32 old_offset;
984
985                 /* reading */
986
987                 ZERO_STRUCTP(rsp);
988
989                 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
990                         return False;
991                 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
992                         return False;
993                 if(!smb_io_strhdr("hdr_domain  ", &rsp->hdr_domain, ps, depth))
994                         return False;
995                 if(!smb_io_strhdr("hdr_user    ", &rsp->hdr_usr, ps, depth))
996                         return False;
997                 if(!smb_io_strhdr("hdr_wks     ", &rsp->hdr_wks, ps, depth)) 
998                         return False;
999                 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1000                         return False;
1001
1002                 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1003                         return False;
1004
1005                 old_offset = prs_offset(ps);
1006
1007                 if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0xc))
1008                         return False;
1009
1010                 if(!prs_uint8s(True , "domain  ", ps, depth, (uint8*)rsp->domain,
1011                                 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1012                         return False;
1013
1014                 old_offset += rsp->hdr_domain.str_str_len;
1015
1016                 if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0xc))
1017                         return False;
1018
1019                 if(!prs_uint8s(True , "user    ", ps, depth, (uint8*)rsp->user,
1020                                 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1021                         return False;
1022
1023                 old_offset += rsp->hdr_usr.str_str_len;
1024
1025                 if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0xc))
1026                         return False;
1027
1028                 if(!prs_uint8s(True, "wks     ", ps, depth, (uint8*)rsp->wks,
1029                                 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1030                         return False;
1031
1032                 old_offset += rsp->hdr_wks.str_str_len;
1033
1034                 if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0xc))
1035                         return False;
1036
1037                 if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp,
1038                                 MIN(rsp->hdr_lm_resp.str_str_len, sizeof(rsp->lm_resp ))))
1039                         return False;
1040
1041                 old_offset += rsp->hdr_lm_resp.str_str_len;
1042
1043                 if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0xc))
1044                         return False;
1045
1046                 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1047                                 MIN(rsp->hdr_nt_resp.str_str_len, sizeof(rsp->nt_resp ))))
1048                         return False;
1049
1050                 old_offset += rsp->hdr_nt_resp.str_str_len;
1051
1052                 if (rsp->hdr_sess_key.str_str_len != 0) {
1053
1054                         if(!prs_set_offset(ps, rsp->hdr_sess_key.buffer + 0x10))
1055                                 return False;
1056
1057                         old_offset += rsp->hdr_sess_key.str_str_len;
1058
1059                         if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1060                                         MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1061                                 return False;
1062                 }
1063
1064                 if(!prs_set_offset(ps, old_offset))
1065                         return False;
1066         } else {
1067                 /* writing */
1068                 if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth))
1069                         return False;
1070                 if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth))
1071                         return False;
1072                 if(!smb_io_strhdr("hdr_domain  ", &rsp->hdr_domain, ps, depth))
1073                         return False;
1074                 if(!smb_io_strhdr("hdr_user    ", &rsp->hdr_usr, ps, depth))
1075                         return False;
1076                 if(!smb_io_strhdr("hdr_wks     ", &rsp->hdr_wks, ps, depth))
1077                         return False;
1078                 if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth))
1079                         return False;
1080
1081                 if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */
1082                         return False;
1083
1084                 if(!prs_uint8s(True , "domain  ", ps, depth, (uint8*)rsp->domain,
1085                                 MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain))))
1086                         return False;
1087
1088                 if(!prs_uint8s(True , "user    ", ps, depth, (uint8*)rsp->user,
1089                                 MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user))))
1090                         return False;
1091
1092                 if(!prs_uint8s(True , "wks     ", ps, depth, (uint8*)rsp->wks,
1093                                 MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks))))
1094                         return False;
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                 if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp,
1099                                 MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))))
1100                         return False;
1101                 if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key,
1102                                 MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))))
1103                         return False;
1104         }
1105
1106         return True;
1107 }
1108
1109 /*******************************************************************
1110  Checks an RPC_AUTH_NTLMSSP_CHK structure.
1111 ********************************************************************/
1112
1113 BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num)
1114 {
1115         if (chk == NULL)
1116                 return False;
1117
1118         if (chk->crc32 != crc32 ||
1119             chk->ver   != NTLMSSP_SIGN_VERSION ||
1120             chk->seq_num != seq_num)
1121         {
1122                 DEBUG(5,("verify failed - crc %x ver %x seq %d\n",
1123                          chk->crc32, chk->ver, chk->seq_num));
1124                         
1125                 DEBUG(5,("verify expect - crc %x ver %x seq %d\n",
1126                         crc32, NTLMSSP_SIGN_VERSION, seq_num));
1127                 return False;
1128         }
1129         return True;
1130 }
1131
1132 /*******************************************************************
1133  Inits an RPC_AUTH_NTLMSSP_CHK structure.
1134 ********************************************************************/
1135
1136 void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk,
1137                                 uint32 ver, uint32 crc32, uint32 seq_num)
1138 {
1139         chk->ver      = ver;
1140         chk->reserved = 0x0;
1141         chk->crc32    = crc32;
1142         chk->seq_num  = seq_num;
1143 }
1144
1145 /*******************************************************************
1146  Reads or writes an RPC_AUTH_NTLMSSP_CHK structure.
1147 ********************************************************************/
1148
1149 BOOL smb_io_rpc_auth_ntlmssp_chk(const char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth)
1150 {
1151         if (chk == NULL)
1152                 return False;
1153
1154         prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk");
1155         depth++;
1156
1157         if(!prs_align(ps))
1158                 return False;
1159
1160         if(!prs_uint32("ver     ", ps, depth, &chk->ver))
1161                 return False;
1162         if(!prs_uint32("reserved", ps, depth, &chk->reserved))
1163                 return False;
1164         if(!prs_uint32("crc32   ", ps, depth, &chk->crc32))
1165                 return False;
1166         if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num))
1167                 return False;
1168
1169         return True;
1170 }
1171
1172 /*******************************************************************
1173 creates an RPC_AUTH_NETSEC_NEG structure.
1174 ********************************************************************/
1175 void init_rpc_auth_netsec_neg(RPC_AUTH_NETSEC_NEG *neg,
1176                               const char *domain, const char *myname)
1177 {
1178         neg->type1 = 0;
1179         neg->type2 = 0x3;
1180         fstrcpy(neg->domain, domain);
1181         fstrcpy(neg->myname, myname);
1182 }
1183
1184 /*******************************************************************
1185  Reads or writes an RPC_AUTH_NETSEC_NEG structure.
1186 ********************************************************************/
1187
1188 BOOL smb_io_rpc_auth_netsec_neg(const char *desc, RPC_AUTH_NETSEC_NEG *neg,
1189                                 prs_struct *ps, int depth)
1190 {
1191         if (neg == NULL)
1192                 return False;
1193
1194         prs_debug(ps, depth, desc, "smb_io_rpc_auth_netsec_neg");
1195         depth++;
1196
1197         if(!prs_align(ps))
1198                 return False;
1199
1200         if(!prs_uint32("type1", ps, depth, &neg->type1))
1201                 return False;
1202         if(!prs_uint32("type2", ps, depth, &neg->type2))
1203                 return False;
1204         if(!prs_string("domain  ", ps, depth, neg->domain, sizeof(neg->domain)))
1205                 return False;
1206         if(!prs_string("myname  ", ps, depth, neg->myname, sizeof(neg->myname)))
1207                 return False;
1208
1209         return True;
1210 }
1211
1212 /*******************************************************************
1213 reads or writes an RPC_AUTH_NETSEC_CHK structure.
1214 ********************************************************************/
1215 BOOL smb_io_rpc_auth_netsec_chk(const char *desc, int auth_len, 
1216                                 RPC_AUTH_NETSEC_CHK * chk,
1217                                 prs_struct *ps, int depth)
1218 {
1219         if (chk == NULL)
1220                 return False;
1221
1222         prs_debug(ps, depth, desc, "smb_io_rpc_auth_netsec_chk");
1223         depth++;
1224
1225         if ( !prs_uint8s(False, "sig  ", ps, depth, chk->sig, sizeof(chk->sig)) )
1226                 return False;
1227                 
1228         if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )
1229                 return False;
1230                 
1231         if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )
1232                 return False;
1233         
1234         if ( auth_len == RPC_AUTH_NETSEC_SIGN_OR_SEAL_CHK_LEN ) {
1235                 if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )
1236                         return False;
1237         }
1238
1239         return True;
1240 }
1241