r10656: BIG merge from trunk. Features not copied over
[tprouty/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 #define SYNT_UNIXINFO_V0                    \
195 {                                           \
196         {                                   \
197                 0x9c54e310, 0xa955, 0x4885, \
198                 { 0xbd, 0x31 },             \
199                 { 0x78, 0x78,               \
200                   0x71, 0x47, 0xdf, 0xa6 }  \
201         }, 0x00                             \
202 }
203
204 #define SYNT_NTSVCS_V1                      \
205 {                                           \
206         {                                   \
207                 0x8d9f4e40, 0xa03d, 0x11ce, \
208                 { 0x8f, 0x69},              \
209                 { 0x08, 0x00,               \
210                   0x3e, 0x30, 0x05, 0x1b }  \
211         }, 0x01                             \
212 }
213
214 /*
215  * IMPORTANT!!  If you update this structure, make sure to
216  * update the index #defines in smb.h.
217  */
218
219 const struct pipe_id_info pipe_names [] =
220 {
221         /* client pipe , abstract syntax       , server pipe   , transfer syntax */
222         { PIPE_LSARPC  , SYNT_LSARPC_V0        , PIPE_LSASS    , TRANS_SYNT_V2 },
223         { PIPE_LSARPC  , SYNT_LSARPC_V0_DS     , PIPE_LSASS    , TRANS_SYNT_V2 },
224         { PIPE_SAMR    , SYNT_SAMR_V1          , PIPE_LSASS    , TRANS_SYNT_V2 },
225         { PIPE_NETLOGON, SYNT_NETLOGON_V1      , PIPE_LSASS    , TRANS_SYNT_V2 },
226         { PIPE_SRVSVC  , SYNT_SRVSVC_V3        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
227         { PIPE_WKSSVC  , SYNT_WKSSVC_V1        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
228         { PIPE_WINREG  , SYNT_WINREG_V1        , PIPE_WINREG   , TRANS_SYNT_V2 },
229         { PIPE_SPOOLSS , SYNT_SPOOLSS_V1       , PIPE_SPOOLSS  , TRANS_SYNT_V2 },
230         { PIPE_NETDFS  , SYNT_NETDFS_V3        , PIPE_NETDFS   , TRANS_SYNT_V2 },
231         { PIPE_ECHO    , SYNT_ECHO_V1          , PIPE_ECHO     , TRANS_SYNT_V2 },
232         { PIPE_SHUTDOWN, SYNT_SHUTDOWN_V1      , PIPE_SHUTDOWN , TRANS_SYNT_V2 },
233         { PIPE_SVCCTL  , SYNT_SVCCTL_V2        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
234         { PIPE_EVENTLOG, SYNT_EVENTLOG_V0      , PIPE_EVENTLOG , TRANS_SYNT_V2 },
235         { PIPE_NTSVCS  , SYNT_NTSVCS_V1        , PIPE_NTSVCS   , TRANS_SYNT_V2 },
236         { NULL         , SYNT_NONE_V0          , NULL          , SYNT_NONE_V0  }
237 };
238
239 /****************************************************************************
240  Return the pipe name from the index.
241  ****************************************************************************/
242
243 const char *cli_get_pipe_name(int pipe_idx)
244 {
245         return &pipe_names[pipe_idx].client_pipe[5];
246 }
247
248 /*******************************************************************
249  Inits an RPC_HDR structure.
250 ********************************************************************/
251
252 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
253                                 uint32 call_id, int data_len, int auth_len)
254 {
255         hdr->major        = 5;               /* RPC version 5 */
256         hdr->minor        = 0;               /* minor version 0 */
257         hdr->pkt_type     = pkt_type;        /* RPC packet type */
258         hdr->flags        = flags;           /* dce/rpc flags */
259         hdr->pack_type[0] = 0x10;            /* little-endian data representation */
260         hdr->pack_type[1] = 0;               /* packed data representation */
261         hdr->pack_type[2] = 0;               /* packed data representation */
262         hdr->pack_type[3] = 0;               /* packed data representation */
263         hdr->frag_len     = data_len;        /* fragment length, fill in later */
264         hdr->auth_len     = auth_len;        /* authentication length */
265         hdr->call_id      = call_id;         /* call identifier - match incoming RPC */
266 }
267
268 /*******************************************************************
269  Reads or writes an RPC_HDR structure.
270 ********************************************************************/
271
272 BOOL smb_io_rpc_hdr(const char *desc,  RPC_HDR *rpc, prs_struct *ps, int depth)
273 {
274         if (rpc == NULL)
275                 return False;
276
277         prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
278         depth++;
279
280         if(!prs_uint8 ("major     ", ps, depth, &rpc->major))
281                 return False;
282
283         if(!prs_uint8 ("minor     ", ps, depth, &rpc->minor))
284                 return False;
285         if(!prs_uint8 ("pkt_type  ", ps, depth, &rpc->pkt_type))
286                 return False;
287         if(!prs_uint8 ("flags     ", ps, depth, &rpc->flags))
288                 return False;
289
290         /* We always marshall in little endian format. */
291         if (MARSHALLING(ps))
292                 rpc->pack_type[0] = 0x10;
293
294         if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
295                 return False;
296         if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
297                 return False;
298         if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
299                 return False;
300         if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
301                 return False;
302
303         /*
304          * If reading and pack_type[0] == 0 then the data is in big-endian
305          * format. Set the flag in the prs_struct to specify reverse-endainness.
306          */
307
308         if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
309                 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
310                 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
311         }
312
313         if(!prs_uint16("frag_len  ", ps, depth, &rpc->frag_len))
314                 return False;
315         if(!prs_uint16("auth_len  ", ps, depth, &rpc->auth_len))
316                 return False;
317         if(!prs_uint32("call_id   ", ps, depth, &rpc->call_id))
318                 return False;
319         return True;
320 }
321
322 /*******************************************************************
323  Reads or writes an RPC_IFACE structure.
324 ********************************************************************/
325
326 static BOOL smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
327 {
328         if (ifc == NULL)
329                 return False;
330
331         prs_debug(ps, depth, desc, "smb_io_rpc_iface");
332         depth++;
333
334         if (!prs_align(ps))
335                 return False;
336
337         if (!smb_io_uuid(  "uuid", &ifc->uuid, ps, depth))
338                 return False;
339
340         if(!prs_uint32 ("version", ps, depth, &ifc->version))
341                 return False;
342
343         return True;
344 }
345
346 /*******************************************************************
347  Inits an RPC_ADDR_STR structure.
348 ********************************************************************/
349
350 static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name)
351 {
352         str->len = strlen(name) + 1;
353         fstrcpy(str->str, name);
354 }
355
356 /*******************************************************************
357  Reads or writes an RPC_ADDR_STR structure.
358 ********************************************************************/
359
360 static BOOL smb_io_rpc_addr_str(const char *desc,  RPC_ADDR_STR *str, prs_struct *ps, int depth)
361 {
362         if (str == NULL)
363                 return False;
364
365         prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
366         depth++;
367         if(!prs_align(ps))
368                 return False;
369
370         if(!prs_uint16 (      "len", ps, depth, &str->len))
371                 return False;
372         if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
373                 return False;
374         return True;
375 }
376
377 /*******************************************************************
378  Inits an RPC_HDR_BBA structure.
379 ********************************************************************/
380
381 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
382 {
383         bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
384         bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
385         bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ 
386 }
387
388 /*******************************************************************
389  Reads or writes an RPC_HDR_BBA structure.
390 ********************************************************************/
391
392 static BOOL smb_io_rpc_hdr_bba(const char *desc,  RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
393 {
394         if (rpc == NULL)
395                 return False;
396
397         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
398         depth++;
399
400         if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
401                 return False;
402         if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
403                 return False;
404         if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
405                 return False;
406         return True;
407 }
408
409 /*******************************************************************
410  Inits an RPC_CONTEXT structure.
411  Note the transfer pointer must remain valid until this is marshalled.
412 ********************************************************************/
413
414 void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, RPC_IFACE *abstract, RPC_IFACE *transfer)
415 {
416         rpc_ctx->context_id   = context_id   ; /* presentation context identifier (0x0) */
417         rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */
418
419         /* num and vers. of interface client is using */
420         rpc_ctx->abstract = *abstract;
421
422         /* vers. of interface to use for replies */
423         rpc_ctx->transfer = transfer;
424 }
425
426 /*******************************************************************
427  Inits an RPC_HDR_RB structure.
428  Note the context pointer must remain valid until this is marshalled.
429 ********************************************************************/
430
431 void init_rpc_hdr_rb(RPC_HDR_RB *rpc, 
432                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
433                                 RPC_CONTEXT *context)
434 {
435         init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
436
437         rpc->num_contexts = 1;
438         rpc->rpc_context = context;
439 }
440
441 /*******************************************************************
442  Reads or writes an RPC_CONTEXT structure.
443 ********************************************************************/
444
445 BOOL smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth)
446 {
447         int i;
448
449         if (rpc_ctx == NULL)
450                 return False;
451
452         if(!prs_align(ps))
453                 return False;
454         if(!prs_uint16("context_id  ", ps, depth, &rpc_ctx->context_id ))
455                 return False;
456         if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))
457                 return False;
458
459         /* num_transfer_syntaxes must not be zero. */
460         if (rpc_ctx->num_transfer_syntaxes == 0)
461                 return False;
462
463         if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))
464                 return False;
465
466         if (UNMARSHALLING(ps)) {
467                 if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {
468                         return False;
469                 }
470         }
471
472         for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {
473                 if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))
474                         return False;
475         }
476         return True;
477
478
479 /*******************************************************************
480  Reads or writes an RPC_HDR_RB structure.
481 ********************************************************************/
482
483 BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
484 {
485         int i;
486         
487         if (rpc == NULL)
488                 return False;
489
490         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
491         depth++;
492
493         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
494                 return False;
495
496         if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts))
497                 return False;
498
499         /* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */
500
501         /* num_contexts must not be zero. */
502         if (rpc->num_contexts == 0)
503                 return False;
504
505         if (UNMARSHALLING(ps)) {
506                 if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {
507                         return False;
508                 }
509         }
510
511         for (i = 0; i < rpc->num_contexts; i++ ) {
512                 if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))
513                         return False;
514         }
515
516         return True;
517 }
518
519 /*******************************************************************
520  Inits an RPC_RESULTS structure.
521
522  lkclXXXX only one reason at the moment!
523 ********************************************************************/
524
525 static void init_rpc_results(RPC_RESULTS *res, 
526                                 uint8 num_results, uint16 result, uint16 reason)
527 {
528         res->num_results = num_results; /* the number of results (0x01) */
529         res->result      = result     ;  /* result (0x00 = accept) */
530         res->reason      = reason     ;  /* reason (0x00 = no reason specified) */
531 }
532
533 /*******************************************************************
534  Reads or writes an RPC_RESULTS structure.
535
536  lkclXXXX only one reason at the moment!
537 ********************************************************************/
538
539 static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
540 {
541         if (res == NULL)
542                 return False;
543
544         prs_debug(ps, depth, desc, "smb_io_rpc_results");
545         depth++;
546
547         if(!prs_align(ps))
548                 return False;
549         
550         if(!prs_uint8 ("num_results", ps, depth, &res->num_results))    
551                 return False;
552
553         if(!prs_align(ps))
554                 return False;
555         
556         if(!prs_uint16("result     ", ps, depth, &res->result))
557                 return False;
558         if(!prs_uint16("reason     ", ps, depth, &res->reason))
559                 return False;
560         return True;
561 }
562
563 /*******************************************************************
564  Init an RPC_HDR_BA structure.
565
566  lkclXXXX only one reason at the moment!
567
568 ********************************************************************/
569
570 void init_rpc_hdr_ba(RPC_HDR_BA *rpc, 
571                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
572                                 const char *pipe_addr,
573                                 uint8 num_results, uint16 result, uint16 reason,
574                                 RPC_IFACE *transfer)
575 {
576         init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
577         init_rpc_addr_str(&rpc->addr, pipe_addr);
578         init_rpc_results (&rpc->res, num_results, result, reason);
579
580         /* the transfer syntax from the request */
581         memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
582 }
583
584 /*******************************************************************
585  Reads or writes an RPC_HDR_BA structure.
586 ********************************************************************/
587
588 BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
589 {
590         if (rpc == NULL)
591                 return False;
592
593         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
594         depth++;
595
596         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
597                 return False;
598         if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
599                 return False;
600         if(!smb_io_rpc_results("", &rpc->res, ps, depth))
601                 return False;
602         if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
603                 return False;
604         return True;
605 }
606
607 /*******************************************************************
608  Init an RPC_HDR_REQ structure.
609 ********************************************************************/
610
611 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
612 {
613         hdr->alloc_hint   = alloc_hint; /* allocation hint */
614         hdr->context_id   = 0;         /* presentation context identifier */
615         hdr->opnum        = opnum;     /* opnum */
616 }
617
618 /*******************************************************************
619  Reads or writes an RPC_HDR_REQ structure.
620 ********************************************************************/
621
622 BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
623 {
624         if (rpc == NULL)
625                 return False;
626
627         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
628         depth++;
629
630         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
631                 return False;
632         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
633                 return False;
634         if(!prs_uint16("opnum     ", ps, depth, &rpc->opnum))
635                 return False;
636         return True;
637 }
638
639 /*******************************************************************
640  Reads or writes an RPC_HDR_RESP structure.
641 ********************************************************************/
642
643 BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
644 {
645         if (rpc == NULL)
646                 return False;
647
648         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
649         depth++;
650
651         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
652                 return False;
653         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
654                 return False;
655         if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
656                 return False;
657         if(!prs_uint8 ("reserved  ", ps, depth, &rpc->reserved))
658                 return False;
659         return True;
660 }
661
662 /*******************************************************************
663  Reads or writes an RPC_HDR_FAULT structure.
664 ********************************************************************/
665
666 BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
667 {
668         if (rpc == NULL)
669                 return False;
670
671         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
672         depth++;
673
674         if(!prs_ntstatus("status  ", ps, depth, &rpc->status))
675                 return False;
676         if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
677                 return False;
678
679     return True;
680 }
681
682 /*******************************************************************
683  Inits an RPC_HDR_AUTH structure.
684 ********************************************************************/
685
686 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
687                                 uint8 auth_type, uint8 auth_level,
688                                 uint8 auth_pad_len,
689                                 uint32 auth_context_id)
690 {
691         rai->auth_type     = auth_type;
692         rai->auth_level    = auth_level;
693         rai->auth_pad_len  = auth_pad_len;
694         rai->auth_reserved = 0;
695         rai->auth_context_id = auth_context_id;
696 }
697
698 /*******************************************************************
699  Reads or writes an RPC_HDR_AUTH structure.
700 ********************************************************************/
701
702 BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
703 {
704         if (rai == NULL)
705                 return False;
706
707         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
708         depth++;
709
710         if(!prs_align(ps))
711                 return False;
712
713         if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type))
714                 return False;
715         if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level))
716                 return False;
717         if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len))
718                 return False;
719         if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved))
720                 return False;
721         if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id))
722                 return False;
723
724         return True;
725 }
726
727 /*******************************************************************
728  Checks an RPC_AUTH_VERIFIER structure.
729 ********************************************************************/
730
731 BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
732                                 const char *signature, uint32 msg_type)
733 {
734         return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
735 }
736
737 /*******************************************************************
738  Inits an RPC_AUTH_VERIFIER structure.
739 ********************************************************************/
740
741 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
742                                 const char *signature, uint32 msg_type)
743 {
744         fstrcpy(rav->signature, signature); /* "NTLMSSP" */
745         rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
746 }
747
748 /*******************************************************************
749  Reads or writes an RPC_AUTH_VERIFIER structure.
750 ********************************************************************/
751
752 BOOL smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
753 {
754         if (rav == NULL)
755                 return False;
756
757         prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
758         depth++;
759
760         /* "NTLMSSP" */
761         if(!prs_string("signature", ps, depth, rav->signature,
762                         sizeof(rav->signature)))
763                 return False;
764         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
765                 return False;
766
767         return True;
768 }
769
770 /*******************************************************************
771  This parses an RPC_AUTH_VERIFIER for schannel. I think
772 ********************************************************************/
773
774 BOOL smb_io_rpc_schannel_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
775 {
776         if (rav == NULL)
777                 return False;
778
779         prs_debug(ps, depth, desc, "smb_io_rpc_schannel_verifier");
780         depth++;
781
782         if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
783                 return False;
784         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
785                 return False;
786
787         return True;
788 }
789
790 /*******************************************************************
791 creates an RPC_AUTH_SCHANNEL_NEG structure.
792 ********************************************************************/
793
794 void init_rpc_auth_schannel_neg(RPC_AUTH_SCHANNEL_NEG *neg,
795                               const char *domain, const char *myname)
796 {
797         neg->type1 = 0;
798         neg->type2 = 0x3;
799         fstrcpy(neg->domain, domain);
800         fstrcpy(neg->myname, myname);
801 }
802
803 /*******************************************************************
804  Reads or writes an RPC_AUTH_SCHANNEL_NEG structure.
805 ********************************************************************/
806
807 BOOL smb_io_rpc_auth_schannel_neg(const char *desc, RPC_AUTH_SCHANNEL_NEG *neg,
808                                 prs_struct *ps, int depth)
809 {
810         if (neg == NULL)
811                 return False;
812
813         prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_neg");
814         depth++;
815
816         if(!prs_align(ps))
817                 return False;
818
819         if(!prs_uint32("type1", ps, depth, &neg->type1))
820                 return False;
821         if(!prs_uint32("type2", ps, depth, &neg->type2))
822                 return False;
823         if(!prs_string("domain  ", ps, depth, neg->domain, sizeof(neg->domain)))
824                 return False;
825         if(!prs_string("myname  ", ps, depth, neg->myname, sizeof(neg->myname)))
826                 return False;
827
828         return True;
829 }
830
831 /*******************************************************************
832 reads or writes an RPC_AUTH_SCHANNEL_CHK structure.
833 ********************************************************************/
834
835 BOOL smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len, 
836                                 RPC_AUTH_SCHANNEL_CHK * chk,
837                                 prs_struct *ps, int depth)
838 {
839         if (chk == NULL)
840                 return False;
841
842         prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_chk");
843         depth++;
844
845         if ( !prs_uint8s(False, "sig  ", ps, depth, chk->sig, sizeof(chk->sig)) )
846                 return False;
847                 
848         if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )
849                 return False;
850                 
851         if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )
852                 return False;
853         
854         if ( auth_len == RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ) {
855                 if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )
856                         return False;
857         }
858
859         return True;
860 }
861