Merge commit 'samba/v3-2-test' into wbc-test
[ira/wip.git] / source3 / 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 const struct ndr_syntax_id syntax_spoolss = {
33         {
34                 0x12345678, 0x1234, 0xabcd,
35                 { 0xef, 0x00 },
36                 { 0x01, 0x23,
37                   0x45, 0x67, 0x89, 0xab }
38         }, 0x01
39 };
40
41 /*
42  * IMPORTANT!!  If you update this structure, make sure to
43  * update the index #defines in smb.h.
44  */
45
46 const struct pipe_id_info pipe_names [] =
47 {
48         { PIPE_LSARPC  , &ndr_table_lsarpc.syntax_id, PIPE_LSASS    , &ndr_transfer_syntax },
49         { PIPE_LSARPC  , &ndr_table_dssetup.syntax_id, PIPE_LSASS    , &ndr_transfer_syntax },
50         { PIPE_SAMR    , &ndr_table_samr.syntax_id, PIPE_LSASS    , &ndr_transfer_syntax },
51         { PIPE_NETLOGON, &ndr_table_netlogon.syntax_id, PIPE_LSASS    , &ndr_transfer_syntax },
52         { PIPE_SRVSVC  , &ndr_table_srvsvc.syntax_id, PIPE_NTSVCS   , &ndr_transfer_syntax },
53         { PIPE_WKSSVC  , &ndr_table_wkssvc.syntax_id, PIPE_NTSVCS   , &ndr_transfer_syntax },
54         { PIPE_WINREG  , &ndr_table_winreg.syntax_id, PIPE_WINREG   , &ndr_transfer_syntax },
55         { PIPE_SPOOLSS , &syntax_spoolss        , PIPE_SPOOLSS  , &ndr_transfer_syntax },
56         { PIPE_NETDFS  , &ndr_table_netdfs.syntax_id, PIPE_NETDFS   , &ndr_transfer_syntax },
57         { PIPE_ECHO    , &ndr_table_rpcecho.syntax_id, PIPE_ECHO     , &ndr_transfer_syntax },
58         { PIPE_SHUTDOWN, &ndr_table_initshutdown.syntax_id, PIPE_SHUTDOWN , &ndr_transfer_syntax },
59         { PIPE_SVCCTL  , &ndr_table_svcctl.syntax_id, PIPE_NTSVCS   , &ndr_transfer_syntax },
60         { PIPE_EVENTLOG, &ndr_table_eventlog.syntax_id, PIPE_EVENTLOG , &ndr_transfer_syntax },
61         { PIPE_NTSVCS  , &ndr_table_ntsvcs.syntax_id, PIPE_NTSVCS   , &ndr_transfer_syntax },
62         { NULL         , NULL                  , NULL          , NULL }
63 };
64
65 /****************************************************************************
66  Return the pipe name from the index.
67  ****************************************************************************/
68
69 const char *cli_get_pipe_name(int pipe_idx)
70 {
71         return &pipe_names[pipe_idx].client_pipe[5];
72 }
73
74 /****************************************************************************
75  Return the pipe idx from the syntax.
76  ****************************************************************************/
77 int cli_get_pipe_idx(const RPC_IFACE *syntax)
78 {
79         int i;
80         for (i = 0; pipe_names[i].client_pipe; i++) {
81                 if (GUID_equal(&pipe_names[i].abstr_syntax->uuid, &syntax->uuid) &&
82                     pipe_names[i].abstr_syntax->if_version == syntax->if_version)
83                         return i;
84         }
85
86         return -1;
87 }
88
89 /*******************************************************************
90  Inits an RPC_HDR structure.
91 ********************************************************************/
92
93 void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags,
94                                 uint32 call_id, int data_len, int auth_len)
95 {
96         hdr->major        = 5;               /* RPC version 5 */
97         hdr->minor        = 0;               /* minor version 0 */
98         hdr->pkt_type     = pkt_type;        /* RPC packet type */
99         hdr->flags        = flags;           /* dce/rpc flags */
100         hdr->pack_type[0] = 0x10;            /* little-endian data representation */
101         hdr->pack_type[1] = 0;               /* packed data representation */
102         hdr->pack_type[2] = 0;               /* packed data representation */
103         hdr->pack_type[3] = 0;               /* packed data representation */
104         hdr->frag_len     = data_len;        /* fragment length, fill in later */
105         hdr->auth_len     = auth_len;        /* authentication length */
106         hdr->call_id      = call_id;         /* call identifier - match incoming RPC */
107 }
108
109 /*******************************************************************
110  Reads or writes an RPC_HDR structure.
111 ********************************************************************/
112
113 bool smb_io_rpc_hdr(const char *desc,  RPC_HDR *rpc, prs_struct *ps, int depth)
114 {
115         if (rpc == NULL)
116                 return False;
117
118         prs_debug(ps, depth, desc, "smb_io_rpc_hdr");
119         depth++;
120
121         if(!prs_uint8 ("major     ", ps, depth, &rpc->major))
122                 return False;
123
124         if(!prs_uint8 ("minor     ", ps, depth, &rpc->minor))
125                 return False;
126         if(!prs_uint8 ("pkt_type  ", ps, depth, &rpc->pkt_type))
127                 return False;
128         if(!prs_uint8 ("flags     ", ps, depth, &rpc->flags))
129                 return False;
130
131         /* We always marshall in little endian format. */
132         if (MARSHALLING(ps))
133                 rpc->pack_type[0] = 0x10;
134
135         if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0]))
136                 return False;
137         if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1]))
138                 return False;
139         if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2]))
140                 return False;
141         if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3]))
142                 return False;
143
144         /*
145          * If reading and pack_type[0] == 0 then the data is in big-endian
146          * format. Set the flag in the prs_struct to specify reverse-endainness.
147          */
148
149         if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) {
150                 DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n"));
151                 prs_set_endian_data(ps, RPC_BIG_ENDIAN);
152         }
153
154         if(!prs_uint16("frag_len  ", ps, depth, &rpc->frag_len))
155                 return False;
156         if(!prs_uint16("auth_len  ", ps, depth, &rpc->auth_len))
157                 return False;
158         if(!prs_uint32("call_id   ", ps, depth, &rpc->call_id))
159                 return False;
160         return True;
161 }
162
163 /*******************************************************************
164  Reads or writes an RPC_IFACE structure.
165 ********************************************************************/
166
167 static bool smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth)
168 {
169         if (ifc == NULL)
170                 return False;
171
172         prs_debug(ps, depth, desc, "smb_io_rpc_iface");
173         depth++;
174
175         if (!prs_align(ps))
176                 return False;
177
178         if (!smb_io_uuid(  "uuid", &ifc->uuid, ps, depth))
179                 return False;
180
181         if(!prs_uint32 ("version", ps, depth, &ifc->if_version))
182                 return False;
183
184         return True;
185 }
186
187 /*******************************************************************
188  Inits an RPC_ADDR_STR structure.
189 ********************************************************************/
190
191 static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name)
192 {
193         str->len = strlen(name) + 1;
194         fstrcpy(str->str, name);
195 }
196
197 /*******************************************************************
198  Reads or writes an RPC_ADDR_STR structure.
199 ********************************************************************/
200
201 static bool smb_io_rpc_addr_str(const char *desc,  RPC_ADDR_STR *str, prs_struct *ps, int depth)
202 {
203         if (str == NULL)
204                 return False;
205
206         prs_debug(ps, depth, desc, "smb_io_rpc_addr_str");
207         depth++;
208         if(!prs_align(ps))
209                 return False;
210
211         if(!prs_uint16 (      "len", ps, depth, &str->len))
212                 return False;
213         if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) ))
214                 return False;
215         return True;
216 }
217
218 /*******************************************************************
219  Inits an RPC_HDR_BBA structure.
220 ********************************************************************/
221
222 static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid)
223 {
224         bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */
225         bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */   
226         bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ 
227 }
228
229 /*******************************************************************
230  Reads or writes an RPC_HDR_BBA structure.
231 ********************************************************************/
232
233 static bool smb_io_rpc_hdr_bba(const char *desc,  RPC_HDR_BBA *rpc, prs_struct *ps, int depth)
234 {
235         if (rpc == NULL)
236                 return False;
237
238         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba");
239         depth++;
240
241         if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize))
242                 return False;
243         if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize))
244                 return False;
245         if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid))
246                 return False;
247         return True;
248 }
249
250 /*******************************************************************
251  Inits an RPC_CONTEXT structure.
252  Note the transfer pointer must remain valid until this is marshalled.
253 ********************************************************************/
254
255 void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, RPC_IFACE *abstract, RPC_IFACE *transfer)
256 {
257         rpc_ctx->context_id   = context_id   ; /* presentation context identifier (0x0) */
258         rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */
259
260         /* num and vers. of interface client is using */
261         rpc_ctx->abstract = *abstract;
262
263         /* vers. of interface to use for replies */
264         rpc_ctx->transfer = transfer;
265 }
266
267 /*******************************************************************
268  Inits an RPC_HDR_RB structure.
269  Note the context pointer must remain valid until this is marshalled.
270 ********************************************************************/
271
272 void init_rpc_hdr_rb(RPC_HDR_RB *rpc, 
273                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
274                                 RPC_CONTEXT *context)
275 {
276         init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);
277
278         rpc->num_contexts = 1;
279         rpc->rpc_context = context;
280 }
281
282 /*******************************************************************
283  Reads or writes an RPC_CONTEXT structure.
284 ********************************************************************/
285
286 bool smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth)
287 {
288         int i;
289
290         if (rpc_ctx == NULL)
291                 return False;
292
293         if(!prs_align(ps))
294                 return False;
295         if(!prs_uint16("context_id  ", ps, depth, &rpc_ctx->context_id ))
296                 return False;
297         if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))
298                 return False;
299
300         /* num_transfer_syntaxes must not be zero. */
301         if (rpc_ctx->num_transfer_syntaxes == 0)
302                 return False;
303
304         if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))
305                 return False;
306
307         if (UNMARSHALLING(ps)) {
308                 if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {
309                         return False;
310                 }
311         }
312
313         for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {
314                 if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))
315                         return False;
316         }
317         return True;
318
319
320 /*******************************************************************
321  Reads or writes an RPC_HDR_RB structure.
322 ********************************************************************/
323
324 bool smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth)
325 {
326         int i;
327         
328         if (rpc == NULL)
329                 return False;
330
331         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");
332         depth++;
333
334         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
335                 return False;
336
337         if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts))
338                 return False;
339
340         /* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */
341
342         /* num_contexts must not be zero. */
343         if (rpc->num_contexts == 0)
344                 return False;
345
346         if (UNMARSHALLING(ps)) {
347                 if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {
348                         return False;
349                 }
350         }
351
352         for (i = 0; i < rpc->num_contexts; i++ ) {
353                 if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))
354                         return False;
355         }
356
357         return True;
358 }
359
360 /*******************************************************************
361  Inits an RPC_RESULTS structure.
362
363  lkclXXXX only one reason at the moment!
364 ********************************************************************/
365
366 static void init_rpc_results(RPC_RESULTS *res, 
367                                 uint8 num_results, uint16 result, uint16 reason)
368 {
369         res->num_results = num_results; /* the number of results (0x01) */
370         res->result      = result     ;  /* result (0x00 = accept) */
371         res->reason      = reason     ;  /* reason (0x00 = no reason specified) */
372 }
373
374 /*******************************************************************
375  Reads or writes an RPC_RESULTS structure.
376
377  lkclXXXX only one reason at the moment!
378 ********************************************************************/
379
380 static bool smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth)
381 {
382         if (res == NULL)
383                 return False;
384
385         prs_debug(ps, depth, desc, "smb_io_rpc_results");
386         depth++;
387
388         if(!prs_align(ps))
389                 return False;
390         
391         if(!prs_uint8 ("num_results", ps, depth, &res->num_results))    
392                 return False;
393
394         if(!prs_align(ps))
395                 return False;
396         
397         if(!prs_uint16("result     ", ps, depth, &res->result))
398                 return False;
399         if(!prs_uint16("reason     ", ps, depth, &res->reason))
400                 return False;
401         return True;
402 }
403
404 /*******************************************************************
405  Init an RPC_HDR_BA structure.
406
407  lkclXXXX only one reason at the moment!
408
409 ********************************************************************/
410
411 void init_rpc_hdr_ba(RPC_HDR_BA *rpc, 
412                                 uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,
413                                 const char *pipe_addr,
414                                 uint8 num_results, uint16 result, uint16 reason,
415                                 RPC_IFACE *transfer)
416 {
417         init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);
418         init_rpc_addr_str(&rpc->addr, pipe_addr);
419         init_rpc_results (&rpc->res, num_results, result, reason);
420
421         /* the transfer syntax from the request */
422         memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));
423 }
424
425 /*******************************************************************
426  Reads or writes an RPC_HDR_BA structure.
427 ********************************************************************/
428
429 bool smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth)
430 {
431         if (rpc == NULL)
432                 return False;
433
434         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");
435         depth++;
436
437         if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))
438                 return False;
439         if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))
440                 return False;
441         if(!smb_io_rpc_results("", &rpc->res, ps, depth))
442                 return False;
443         if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))
444                 return False;
445         return True;
446 }
447
448 /*******************************************************************
449  Init an RPC_HDR_REQ structure.
450 ********************************************************************/
451
452 void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum)
453 {
454         hdr->alloc_hint   = alloc_hint; /* allocation hint */
455         hdr->context_id   = 0;         /* presentation context identifier */
456         hdr->opnum        = opnum;     /* opnum */
457 }
458
459 /*******************************************************************
460  Reads or writes an RPC_HDR_REQ structure.
461 ********************************************************************/
462
463 bool smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth)
464 {
465         if (rpc == NULL)
466                 return False;
467
468         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");
469         depth++;
470
471         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
472                 return False;
473         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
474                 return False;
475         if(!prs_uint16("opnum     ", ps, depth, &rpc->opnum))
476                 return False;
477         return True;
478 }
479
480 /*******************************************************************
481  Reads or writes an RPC_HDR_RESP structure.
482 ********************************************************************/
483
484 bool smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth)
485 {
486         if (rpc == NULL)
487                 return False;
488
489         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");
490         depth++;
491
492         if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))
493                 return False;
494         if(!prs_uint16("context_id", ps, depth, &rpc->context_id))
495                 return False;
496         if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))
497                 return False;
498         if(!prs_uint8 ("reserved  ", ps, depth, &rpc->reserved))
499                 return False;
500         return True;
501 }
502
503 /*******************************************************************
504  Reads or writes an RPC_HDR_FAULT structure.
505 ********************************************************************/
506
507 bool smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth)
508 {
509         if (rpc == NULL)
510                 return False;
511
512         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");
513         depth++;
514
515         if(!prs_dcerpc_status("status  ", ps, depth, &rpc->status))
516                 return False;
517         if(!prs_uint32("reserved", ps, depth, &rpc->reserved))
518                 return False;
519
520     return True;
521 }
522
523 /*******************************************************************
524  Inits an RPC_HDR_AUTH structure.
525 ********************************************************************/
526
527 void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,
528                                 uint8 auth_type, uint8 auth_level,
529                                 uint8 auth_pad_len,
530                                 uint32 auth_context_id)
531 {
532         rai->auth_type     = auth_type;
533         rai->auth_level    = auth_level;
534         rai->auth_pad_len  = auth_pad_len;
535         rai->auth_reserved = 0;
536         rai->auth_context_id = auth_context_id;
537 }
538
539 /*******************************************************************
540  Reads or writes an RPC_HDR_AUTH structure.
541 ********************************************************************/
542
543 bool smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth)
544 {
545         if (rai == NULL)
546                 return False;
547
548         prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");
549         depth++;
550
551         if(!prs_align(ps))
552                 return False;
553
554         if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type))
555                 return False;
556         if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level))
557                 return False;
558         if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len))
559                 return False;
560         if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved))
561                 return False;
562         if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id))
563                 return False;
564
565         return True;
566 }
567
568 /*******************************************************************
569  Checks an RPC_AUTH_VERIFIER structure.
570 ********************************************************************/
571
572 bool rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,
573                                 const char *signature, uint32 msg_type)
574 {
575         return (strequal(rav->signature, signature) && rav->msg_type == msg_type);
576 }
577
578 /*******************************************************************
579  Inits an RPC_AUTH_VERIFIER structure.
580 ********************************************************************/
581
582 void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,
583                                 const char *signature, uint32 msg_type)
584 {
585         fstrcpy(rav->signature, signature); /* "NTLMSSP" */
586         rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */
587 }
588
589 /*******************************************************************
590  Reads or writes an RPC_AUTH_VERIFIER structure.
591 ********************************************************************/
592
593 bool smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
594 {
595         if (rav == NULL)
596                 return False;
597
598         prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");
599         depth++;
600
601         /* "NTLMSSP" */
602         if(!prs_string("signature", ps, depth, rav->signature,
603                         sizeof(rav->signature)))
604                 return False;
605         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */
606                 return False;
607
608         return True;
609 }
610
611 /*******************************************************************
612  This parses an RPC_AUTH_VERIFIER for schannel. I think
613 ********************************************************************/
614
615 bool smb_io_rpc_schannel_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth)
616 {
617         if (rav == NULL)
618                 return False;
619
620         prs_debug(ps, depth, desc, "smb_io_rpc_schannel_verifier");
621         depth++;
622
623         if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))
624                 return False;
625         if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))
626                 return False;
627
628         return True;
629 }
630
631 /*******************************************************************
632 creates an RPC_AUTH_SCHANNEL_NEG structure.
633 ********************************************************************/
634
635 void init_rpc_auth_schannel_neg(RPC_AUTH_SCHANNEL_NEG *neg,
636                               const char *domain, const char *myname)
637 {
638         neg->type1 = 0;
639         neg->type2 = 0x3;
640         fstrcpy(neg->domain, domain);
641         fstrcpy(neg->myname, myname);
642 }
643
644 /*******************************************************************
645  Reads or writes an RPC_AUTH_SCHANNEL_NEG structure.
646 ********************************************************************/
647
648 bool smb_io_rpc_auth_schannel_neg(const char *desc, RPC_AUTH_SCHANNEL_NEG *neg,
649                                 prs_struct *ps, int depth)
650 {
651         if (neg == NULL)
652                 return False;
653
654         prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_neg");
655         depth++;
656
657         if(!prs_align(ps))
658                 return False;
659
660         if(!prs_uint32("type1", ps, depth, &neg->type1))
661                 return False;
662         if(!prs_uint32("type2", ps, depth, &neg->type2))
663                 return False;
664         if(!prs_string("domain  ", ps, depth, neg->domain, sizeof(neg->domain)))
665                 return False;
666         if(!prs_string("myname  ", ps, depth, neg->myname, sizeof(neg->myname)))
667                 return False;
668
669         return True;
670 }
671
672 /*******************************************************************
673 reads or writes an RPC_AUTH_SCHANNEL_CHK structure.
674 ********************************************************************/
675
676 bool smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len, 
677                                 RPC_AUTH_SCHANNEL_CHK * chk,
678                                 prs_struct *ps, int depth)
679 {
680         if (chk == NULL)
681                 return False;
682
683         prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_chk");
684         depth++;
685
686         if ( !prs_uint8s(False, "sig  ", ps, depth, chk->sig, sizeof(chk->sig)) )
687                 return False;
688                 
689         if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )
690                 return False;
691                 
692         if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )
693                 return False;
694         
695         if ( auth_len == RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ) {
696                 if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )
697                         return False;
698         }
699
700         return True;
701 }