[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[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 3 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, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "includes.h"
24
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_PARSE
27
28 /*******************************************************************
29 interface/version dce/rpc pipe identification
30 ********************************************************************/
31
32 #define TRANS_SYNT_V2                       \
33 {                                           \
34         {                                   \
35                 0x8a885d04, 0x1ceb, 0x11c9, \
36                 { 0x9f, 0xe8 },             \
37                 { 0x08, 0x00,               \
38                   0x2b, 0x10, 0x48, 0x60 }  \
39         }, 0x02                             \
40 }
41
42 #define SYNT_NETLOGON_V2                    \
43 {                                           \
44         {                                   \
45                 0x8a885d04, 0x1ceb, 0x11c9, \
46                 { 0x9f, 0xe8 },             \
47                 { 0x08, 0x00,               \
48                   0x2b, 0x10, 0x48, 0x60 }  \
49         }, 0x02                             \
50 }
51
52 #define SYNT_WKSSVC_V1                      \
53 {                                           \
54         {                                   \
55                 0x6bffd098, 0xa112, 0x3610, \
56                 { 0x98, 0x33 },             \
57                 { 0x46, 0xc3,               \
58                   0xf8, 0x7e, 0x34, 0x5a }  \
59         }, 0x01                             \
60 }
61
62 #define SYNT_SRVSVC_V3                      \
63 {                                           \
64         {                                   \
65                 0x4b324fc8, 0x1670, 0x01d3, \
66                 { 0x12, 0x78 },             \
67                 { 0x5a, 0x47,               \
68                   0xbf, 0x6e, 0xe1, 0x88 }  \
69         }, 0x03                             \
70 }
71
72 #define SYNT_LSARPC_V0                      \
73 {                                           \
74         {                                   \
75                 0x12345778, 0x1234, 0xabcd, \
76                 { 0xef, 0x00 },             \
77                 { 0x01, 0x23,               \
78                   0x45, 0x67, 0x89, 0xab }  \
79         }, 0x00                             \
80 }
81
82 #define SYNT_LSARPC_V0_DS                \
83 {                                           \
84         {                                   \
85                 0x3919286a, 0xb10c, 0x11d0, \
86                 { 0x9b, 0xa8 },             \
87                 { 0x00, 0xc0,               \
88                   0x4f, 0xd9, 0x2e, 0xf5 }  \
89         }, 0x00                             \
90 }
91
92 #define SYNT_SAMR_V1                        \
93 {                                           \
94         {                                   \
95                 0x12345778, 0x1234, 0xabcd, \
96                 { 0xef, 0x00 },             \
97                 { 0x01, 0x23,               \
98                   0x45, 0x67, 0x89, 0xac }  \
99         }, 0x01                             \
100 }
101
102 #define SYNT_NETLOGON_V1                    \
103 {                                           \
104         {                                   \
105                 0x12345678, 0x1234, 0xabcd, \
106                 { 0xef, 0x00 },             \
107                 { 0x01, 0x23,               \
108                   0x45, 0x67, 0xcf, 0xfb }  \
109         }, 0x01                             \
110 }
111
112 #define SYNT_WINREG_V1                      \
113 {                                           \
114         {                                   \
115                 0x338cd001, 0x2244, 0x31f1, \
116                 { 0xaa, 0xaa },             \
117                 { 0x90, 0x00,               \
118                   0x38, 0x00, 0x10, 0x03 }  \
119         }, 0x01                             \
120 }
121
122 #define SYNT_SPOOLSS_V1                     \
123 {                                           \
124         {                                   \
125                 0x12345678, 0x1234, 0xabcd, \
126                 { 0xef, 0x00 },             \
127                 { 0x01, 0x23,               \
128                   0x45, 0x67, 0x89, 0xab }  \
129         }, 0x01                             \
130 }
131
132 #define SYNT_NONE_V0                        \
133 {                                           \
134         {                                   \
135                 0x0, 0x0, 0x0,              \
136                 { 0x00, 0x00 },             \
137                 { 0x00, 0x00,               \
138                   0x00, 0x00, 0x00, 0x00 }  \
139         }, 0x00                             \
140 }
141
142 #define SYNT_NETDFS_V3                      \
143 {                                           \
144         {                                   \
145                 0x4fc742e0, 0x4a10, 0x11cf, \
146                 { 0x82, 0x73 },             \
147                 { 0x00, 0xaa,               \
148                   0x00, 0x4a, 0xe6, 0x73 }  \
149         }, 0x03                             \
150 }
151
152 #define SYNT_ECHO_V1                        \
153 {                                           \
154         {                                   \
155                 0x60a15ec5, 0x4de8, 0x11d7, \
156                 { 0xa6, 0x37 },             \
157                 { 0x00, 0x50,               \
158                   0x56, 0xa2, 0x01, 0x82 }  \
159         }, 0x01                             \
160 }
161
162 #define SYNT_SHUTDOWN_V1                    \
163 {                                           \
164         {                                   \
165                 0x894de0c0, 0x0d55, 0x11d3, \
166                 { 0xa3, 0x22 },             \
167                 { 0x00, 0xc0,               \
168                   0x4f, 0xa3, 0x21, 0xa1 }  \
169         }, 0x01                             \
170 }
171
172 #define SYNT_SVCCTL_V2                      \
173 {                                           \
174         {                                   \
175                 0x367abb81, 0x9844, 0x35f1, \
176                 { 0xad, 0x32 },             \
177                 { 0x98, 0xf0,               \
178                   0x38, 0x00, 0x10, 0x03 }  \
179         }, 0x02                             \
180 }
181
182
183 #define SYNT_EVENTLOG_V0                    \
184 {                                           \
185         {                                   \
186                 0x82273fdc, 0xe32a, 0x18c3, \
187                 { 0x3f, 0x78 },             \
188                 { 0x82, 0x79,               \
189                   0x29, 0xdc, 0x23, 0xea }  \
190         }, 0x00                             \
191 }
192
193 #define SYNT_NTSVCS_V1                      \
194 {                                           \
195         {                                   \
196                 0x8d9f4e40, 0xa03d, 0x11ce, \
197                 { 0x8f, 0x69},              \
198                 { 0x08, 0x00,               \
199                   0x3e, 0x30, 0x05, 0x1b }  \
200         }, 0x01                             \
201 }
202
203 /*
204  * IMPORTANT!!  If you update this structure, make sure to
205  * update the index #defines in smb.h.
206  */
207
208 const struct pipe_id_info pipe_names [] =
209 {
210         /* client pipe , abstract syntax       , server pipe   , transfer syntax */
211         { PIPE_LSARPC  , SYNT_LSARPC_V0        , PIPE_LSASS    , TRANS_SYNT_V2 },
212         { PIPE_LSARPC  , SYNT_LSARPC_V0_DS     , PIPE_LSASS    , TRANS_SYNT_V2 },
213         { PIPE_SAMR    , SYNT_SAMR_V1          , PIPE_LSASS    , TRANS_SYNT_V2 },
214         { PIPE_NETLOGON, SYNT_NETLOGON_V1      , PIPE_LSASS    , TRANS_SYNT_V2 },
215         { PIPE_SRVSVC  , SYNT_SRVSVC_V3        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
216         { PIPE_WKSSVC  , SYNT_WKSSVC_V1        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
217         { PIPE_WINREG  , SYNT_WINREG_V1        , PIPE_WINREG   , TRANS_SYNT_V2 },
218         { PIPE_SPOOLSS , SYNT_SPOOLSS_V1       , PIPE_SPOOLSS  , TRANS_SYNT_V2 },
219         { PIPE_NETDFS  , SYNT_NETDFS_V3        , PIPE_NETDFS   , TRANS_SYNT_V2 },
220         { PIPE_ECHO    , SYNT_ECHO_V1          , PIPE_ECHO     , TRANS_SYNT_V2 },
221         { PIPE_SHUTDOWN, SYNT_SHUTDOWN_V1      , PIPE_SHUTDOWN , TRANS_SYNT_V2 },
222         { PIPE_SVCCTL  , SYNT_SVCCTL_V2        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
223         { PIPE_EVENTLOG, SYNT_EVENTLOG_V0      , PIPE_EVENTLOG , TRANS_SYNT_V2 },
224         { PIPE_NTSVCS  , SYNT_NTSVCS_V1        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
225         { NULL         , SYNT_NONE_V0          , NULL          , SYNT_NONE_V0  }
226 };
227
228 /****************************************************************************
229  Return the pipe name from the index.
230  ****************************************************************************/
231
232 const char *cli_get_pipe_name(int pipe_idx)
233 {
234         return &pipe_names[pipe_idx].client_pipe[5];
235 }
236
237 /*******************************************************************
238  Inits an RPC_HDR structure.
239 ********************************************************************/
240
241 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
242                                 uint32 call_id, int data_len, int auth_len)
243 {
244         hdr->major        = 5;               /* RPC version 5 */
245         hdr->minor        = 0;               /* minor version 0 */
246         hdr->pkt_type     = pkt_type;        /* RPC packet type */
247         hdr->flags        = flags;           /* dce/rpc flags */
248         hdr->pack_type[0] = 0x10;            /* little-endian data representation */
249         hdr->pack_type[1] = 0;               /* packed data representation */
250         hdr->pack_type[2] = 0;               /* packed data representation */
251         hdr->pack_type[3] = 0;               /* packed data representation */
252         hdr->frag_len     = data_len;        /* fragment length, fill in later */
253         hdr->auth_len     = auth_len;        /* authentication length */
254         hdr->call_id      = call_id;         /* call identifier - match incoming RPC */
255 }
256
257 /*******************************************************************
258  Reads or writes an RPC_HDR structure.
259 ********************************************************************/
260
261 BOOL smb_io_rpc_hdr(const char *desc,  RPC_HDR *rpc, prs_struct *ps, int depth)
262 {
263         if (rpc == NULL)
264                 return False;
265
266         prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
267         depth++;
268
269         if(!prs_uint8 ("major     ", ps, depth, &rpc->major))
270                 return False;
271
272         if(!prs_uint8 ("minor     ", ps, depth, &rpc->minor))
273                 return False;
274         if(!prs_uint8 ("pkt_type  ", ps, depth, &rpc->pkt_type))
275                 return False;
276         if(!prs_uint8 ("flags     ", ps, depth, &rpc->flags))
277                 return False;
278
279         /* We always marshall in little endian format. */
280         if (MARSHALLING(ps))
281                 rpc->pack_type[0] = 0x10;
282
283         if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
284                 return False;
285         if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
286                 return False;
287         if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
288                 return False;
289         if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
290                 return False;
291
292         /*
293          * If reading and pack_type[0] == 0 then the data is in big-endian
294          * format. Set the flag in the prs_struct to specify reverse-endainness.
295          */
296
297         if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
298                 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
299                 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
300         }
301
302         if(!prs_uint16("frag_len  ", ps, depth, &rpc->frag_len))
303                 return False;
304         if(!prs_uint16("auth_len  ", ps, depth, &rpc->auth_len))
305                 return False;
306         if(!prs_uint32("call_id   ", ps, depth, &rpc->call_id))
307                 return False;
308         return True;
309 }
310
311 /*******************************************************************
312  Reads or writes an RPC_IFACE structure.
313 ********************************************************************/
314
315 static BOOL smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
316 {
317         if (ifc == NULL)
318                 return False;
319
320         prs_debug(ps, depth, desc, "smb_io_rpc_iface");
321         depth++;
322
323         if (!prs_align(ps))
324                 return False;
325
326         if (!smb_io_uuid(  "uuid", &ifc->uuid, ps, depth))
327                 return False;
328
329         if(!prs_uint32 ("version", ps, depth, &ifc->version))
330                 return False;
331
332         return True;
333 }
334
335 /*******************************************************************
336  Inits an RPC_ADDR_STR structure.
337 ********************************************************************/
338
339 static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name)
340 {
341         str->len = strlen(name) + 1;
342         fstrcpy(str->str, name);
343 }
344
345 /*******************************************************************
346  Reads or writes an RPC_ADDR_STR structure.
347 ********************************************************************/
348
349 static BOOL smb_io_rpc_addr_str(const char *desc,  RPC_ADDR_STR *str, prs_struct *ps, int depth)
350 {
351         if (str == NULL)
352                 return False;
353
354         prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
355         depth++;
356         if(!prs_align(ps))
357                 return False;
358
359         if(!prs_uint16 (      "len", ps, depth, &str->len))
360                 return False;
361         if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
362                 return False;
363         return True;
364 }
365
366 /*******************************************************************
367  Inits an RPC_HDR_BBA structure.
368 ********************************************************************/
369
370 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
371 {
372         bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
373         bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
374         bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ 
375 }
376
377 /*******************************************************************
378  Reads or writes an RPC_HDR_BBA structure.
379 ********************************************************************/
380
381 static BOOL smb_io_rpc_hdr_bba(const char *desc,  RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
382 {
383         if (rpc == NULL)
384                 return False;
385
386         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
387         depth++;
388
389         if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
390                 return False;
391         if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
392                 return False;
393         if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
394                 return False;
395         return True;
396 }
397
398 /*******************************************************************
399  Inits an RPC_CONTEXT structure.
400  Note the transfer pointer must remain valid until this is marshalled.
401 ********************************************************************/
402
403 void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, RPC_IFACE *abstract, RPC_IFACE *transfer)
404 {
405         rpc_ctx->context_id   = context_id   ; /* presentation context identifier (0x0) */
406         rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */
407
408         /* num and vers. of interface client is using */
409         rpc_ctx->abstract = *abstract;
410
411         /* vers. of interface to use for replies */
412         rpc_ctx->transfer = transfer;
413 }
414
415 /*******************************************************************
416  Inits an RPC_HDR_RB structure.
417  Note the context pointer must remain valid until this is marshalled.
418 ********************************************************************/
419
420 void init_rpc_hdr_rb(RPC_HDR_RB *rpc, 
421                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
422                                 RPC_CONTEXT *context)
423 {
424         init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
425
426         rpc->num_contexts = 1;
427         rpc->rpc_context = context;
428 }
429
430 /*******************************************************************
431  Reads or writes an RPC_CONTEXT structure.
432 ********************************************************************/
433
434 BOOL smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth)
435 {
436         int i;
437
438         if (rpc_ctx == NULL)
439                 return False;
440
441         if(!prs_align(ps))
442                 return False;
443         if(!prs_uint16("context_id  ", ps, depth, &rpc_ctx->context_id ))
444                 return False;
445         if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))
446                 return False;
447
448         /* num_transfer_syntaxes must not be zero. */
449         if (rpc_ctx->num_transfer_syntaxes == 0)
450                 return False;
451
452         if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))
453                 return False;
454
455         if (UNMARSHALLING(ps)) {
456                 if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {
457                         return False;
458                 }
459         }
460
461         for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {
462                 if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))
463                         return False;
464         }
465         return True;
466
467
468 /*******************************************************************
469  Reads or writes an RPC_HDR_RB structure.
470 ********************************************************************/
471
472 BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
473 {
474         int i;
475         
476         if (rpc == NULL)
477                 return False;
478
479         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
480         depth++;
481
482         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
483                 return False;
484
485         if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts))
486                 return False;
487
488         /* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */
489
490         /* num_contexts must not be zero. */
491         if (rpc->num_contexts == 0)
492                 return False;
493
494         if (UNMARSHALLING(ps)) {
495                 if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {
496                         return False;
497                 }
498         }
499
500         for (i = 0; i < rpc->num_contexts; i++ ) {
501                 if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))
502                         return False;
503         }
504
505         return True;
506 }
507
508 /*******************************************************************
509  Inits an RPC_RESULTS structure.
510
511  lkclXXXX only one reason at the moment!
512 ********************************************************************/
513
514 static void init_rpc_results(RPC_RESULTS *res, 
515                                 uint8 num_results, uint16 result, uint16 reason)
516 {
517         res->num_results = num_results; /* the number of results (0x01) */
518         res->result      = result     ;  /* result (0x00 = accept) */
519         res->reason      = reason     ;  /* reason (0x00 = no reason specified) */
520 }
521
522 /*******************************************************************
523  Reads or writes an RPC_RESULTS structure.
524
525  lkclXXXX only one reason at the moment!
526 ********************************************************************/
527
528 static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
529 {
530         if (res == NULL)
531                 return False;
532
533         prs_debug(ps, depth, desc, "smb_io_rpc_results");
534         depth++;
535
536         if(!prs_align(ps))
537                 return False;
538         
539         if(!prs_uint8 ("num_results", ps, depth, &res->num_results))    
540                 return False;
541
542         if(!prs_align(ps))
543                 return False;
544         
545         if(!prs_uint16("result     ", ps, depth, &res->result))
546                 return False;
547         if(!prs_uint16("reason     ", ps, depth, &res->reason))
548                 return False;
549         return True;
550 }
551
552 /*******************************************************************
553  Init an RPC_HDR_BA structure.
554
555  lkclXXXX only one reason at the moment!
556
557 ********************************************************************/
558
559 void init_rpc_hdr_ba(RPC_HDR_BA *rpc, 
560                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
561                                 const char *pipe_addr,
562                                 uint8 num_results, uint16 result, uint16 reason,
563                                 RPC_IFACE *transfer)
564 {
565         init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
566         init_rpc_addr_str(&rpc->addr, pipe_addr);
567         init_rpc_results (&rpc->res, num_results, result, reason);
568
569         /* the transfer syntax from the request */
570         memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
571 }
572
573 /*******************************************************************
574  Reads or writes an RPC_HDR_BA structure.
575 ********************************************************************/
576
577 BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
578 {
579         if (rpc == NULL)
580                 return False;
581
582         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
583         depth++;
584
585         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
586                 return False;
587         if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
588                 return False;
589         if(!smb_io_rpc_results("", &rpc->res, ps, depth))
590                 return False;
591         if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
592                 return False;
593         return True;
594 }
595
596 /*******************************************************************
597  Init an RPC_HDR_REQ structure.
598 ********************************************************************/
599
600 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
601 {
602         hdr->alloc_hint   = alloc_hint; /* allocation hint */
603         hdr->context_id   = 0;         /* presentation context identifier */
604         hdr->opnum        = opnum;     /* opnum */
605 }
606
607 /*******************************************************************
608  Reads or writes an RPC_HDR_REQ structure.
609 ********************************************************************/
610
611 BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
612 {
613         if (rpc == NULL)
614                 return False;
615
616         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
617         depth++;
618
619         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
620                 return False;
621         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
622                 return False;
623         if(!prs_uint16("opnum     ", ps, depth, &rpc->opnum))
624                 return False;
625         return True;
626 }
627
628 /*******************************************************************
629  Reads or writes an RPC_HDR_RESP structure.
630 ********************************************************************/
631
632 BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
633 {
634         if (rpc == NULL)
635                 return False;
636
637         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
638         depth++;
639
640         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
641                 return False;
642         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
643                 return False;
644         if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
645                 return False;
646         if(!prs_uint8 ("reserved  ", ps, depth, &rpc->reserved))
647                 return False;
648         return True;
649 }
650
651 /*******************************************************************
652  Reads or writes an RPC_HDR_FAULT structure.
653 ********************************************************************/
654
655 BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
656 {
657         if (rpc == NULL)
658                 return False;
659
660         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
661         depth++;
662
663         if(!prs_dcerpc_status("status  ", ps, depth, &rpc->status))
664                 return False;
665         if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
666                 return False;
667
668     return True;
669 }
670
671 /*******************************************************************
672  Inits an RPC_HDR_AUTH structure.
673 ********************************************************************/
674
675 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
676                                 uint8 auth_type, uint8 auth_level,
677                                 uint8 auth_pad_len,
678                                 uint32 auth_context_id)
679 {
680         rai->auth_type     = auth_type;
681         rai->auth_level    = auth_level;
682         rai->auth_pad_len  = auth_pad_len;
683         rai->auth_reserved = 0;
684         rai->auth_context_id = auth_context_id;
685 }
686
687 /*******************************************************************
688  Reads or writes an RPC_HDR_AUTH structure.
689 ********************************************************************/
690
691 BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
692 {
693         if (rai == NULL)
694                 return False;
695
696         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
697         depth++;
698
699         if(!prs_align(ps))
700                 return False;
701
702         if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type))
703                 return False;
704         if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level))
705                 return False;
706         if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len))
707                 return False;
708         if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved))
709                 return False;
710         if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id))
711                 return False;
712
713         return True;
714 }
715
716 /*******************************************************************
717  Checks an RPC_AUTH_VERIFIER structure.
718 ********************************************************************/
719
720 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
721                                 const char *signature, uint32 msg_type)
722 {
723         return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
724 }
725
726 /*******************************************************************
727  Inits an RPC_AUTH_VERIFIER structure.
728 ********************************************************************/
729
730 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
731                                 const char *signature, uint32 msg_type)
732 {
733         fstrcpy(rav->signature, signature); /* "NTLMSSP" */
734         rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
735 }
736
737 /*******************************************************************
738  Reads or writes an RPC_AUTH_VERIFIER structure.
739 ********************************************************************/
740
741 BOOL smb_io_rpc_auth_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         /* "NTLMSSP" */
750         if(!prs_string("signature", ps, depth, rav->signature,
751                         sizeof(rav->signature)))
752                 return False;
753         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
754                 return False;
755
756         return True;
757 }
758
759 /*******************************************************************
760  This parses an RPC_AUTH_VERIFIER for schannel. I think
761 ********************************************************************/
762
763 BOOL smb_io_rpc_schannel_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
764 {
765         if (rav == NULL)
766                 return False;
767
768         prs_debug(ps, depth, desc, "smb_io_rpc_schannel_verifier");
769         depth++;
770
771         if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
772                 return False;
773         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
774                 return False;
775
776         return True;
777 }
778
779 /*******************************************************************
780 creates an RPC_AUTH_SCHANNEL_NEG structure.
781 ********************************************************************/
782
783 void init_rpc_auth_schannel_neg(RPC_AUTH_SCHANNEL_NEG *neg,
784                               const char *domain, const char *myname)
785 {
786         neg->type1 = 0;
787         neg->type2 = 0x3;
788         fstrcpy(neg->domain, domain);
789         fstrcpy(neg->myname, myname);
790 }
791
792 /*******************************************************************
793  Reads or writes an RPC_AUTH_SCHANNEL_NEG structure.
794 ********************************************************************/
795
796 BOOL smb_io_rpc_auth_schannel_neg(const char *desc, RPC_AUTH_SCHANNEL_NEG *neg,
797                                 prs_struct *ps, int depth)
798 {
799         if (neg == NULL)
800                 return False;
801
802         prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_neg");
803         depth++;
804
805         if(!prs_align(ps))
806                 return False;
807
808         if(!prs_uint32("type1", ps, depth, &neg->type1))
809                 return False;
810         if(!prs_uint32("type2", ps, depth, &neg->type2))
811                 return False;
812         if(!prs_string("domain  ", ps, depth, neg->domain, sizeof(neg->domain)))
813                 return False;
814         if(!prs_string("myname  ", ps, depth, neg->myname, sizeof(neg->myname)))
815                 return False;
816
817         return True;
818 }
819
820 /*******************************************************************
821 reads or writes an RPC_AUTH_SCHANNEL_CHK structure.
822 ********************************************************************/
823
824 BOOL smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len, 
825                                 RPC_AUTH_SCHANNEL_CHK * chk,
826                                 prs_struct *ps, int depth)
827 {
828         if (chk == NULL)
829                 return False;
830
831         prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_chk");
832         depth++;
833
834         if ( !prs_uint8s(False, "sig  ", ps, depth, chk->sig, sizeof(chk->sig)) )
835                 return False;
836                 
837         if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )
838                 return False;
839                 
840         if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )
841                 return False;
842         
843         if ( auth_len == RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ) {
844                 if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )
845                         return False;
846         }
847
848         return True;
849 }