This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[samba.git] / source3 / rpc_parse / parse_misc.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  *  
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *  
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *  
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include "includes.h"
24
25 /****************************************************************************
26  A temporary TALLOC context for things like unistrs, that is valid for
27  the life of a complete RPC call.
28 ****************************************************************************/
29
30 static TALLOC_CTX *current_rpc_talloc = NULL;
31
32 TALLOC_CTX *get_current_rpc_talloc(void)
33 {
34     return current_rpc_talloc;
35 }
36
37 void set_current_rpc_talloc( TALLOC_CTX *ctx)
38 {
39         current_rpc_talloc = ctx;
40 }
41
42 static TALLOC_CTX *main_loop_talloc = NULL;
43
44 /*******************************************************************
45 free up temporary memory - called from the main loop
46 ********************************************************************/
47
48 void main_loop_talloc_free(void)
49 {
50     if (!main_loop_talloc)
51         return;
52     talloc_destroy(main_loop_talloc);
53     main_loop_talloc = NULL;
54 }
55
56 /*******************************************************************
57  Get a talloc context that is freed in the main loop...
58 ********************************************************************/
59
60 TALLOC_CTX *main_loop_talloc_get(void)
61 {
62     if (!main_loop_talloc) {
63         main_loop_talloc = talloc_init_named("main loop talloc (mainly parse_misc)");
64         if (!main_loop_talloc)
65             smb_panic("main_loop_talloc: malloc fail\n");
66     }
67
68     return main_loop_talloc;
69 }
70
71 /*******************************************************************
72  Try and get a talloc context. Get the rpc one if possible, else
73  get the main loop one. The main loop one is more dangerous as it
74  goes away between packets, the rpc one will stay around for as long
75  as a current RPC lasts.
76 ********************************************************************/ 
77
78 TALLOC_CTX *get_talloc_ctx(void)
79 {
80         TALLOC_CTX *tc = get_current_rpc_talloc();
81
82         if (tc)
83                 return tc;
84         return main_loop_talloc_get();
85 }
86
87 /*******************************************************************
88  Reads or writes a UTIME type.
89 ********************************************************************/
90
91 static BOOL smb_io_utime(char *desc, UTIME *t, prs_struct *ps, int depth)
92 {
93         if (t == NULL)
94                 return False;
95
96         prs_debug(ps, depth, desc, "smb_io_utime");
97         depth++;
98
99         if(!prs_align(ps))
100                 return False;
101         
102         if(!prs_uint32 ("time", ps, depth, &t->time))
103                 return False;
104
105         return True;
106 }
107
108 /*******************************************************************
109  Reads or writes an NTTIME structure.
110 ********************************************************************/
111
112 BOOL smb_io_time(char *desc, NTTIME *nttime, prs_struct *ps, int depth)
113 {
114         if (nttime == NULL)
115                 return False;
116
117         prs_debug(ps, depth, desc, "smb_io_time");
118         depth++;
119
120         if(!prs_align(ps))
121                 return False;
122         
123         if(!prs_uint32("low ", ps, depth, &nttime->low)) /* low part */
124                 return False;
125         if(!prs_uint32("high", ps, depth, &nttime->high)) /* high part */
126                 return False;
127
128         return True;
129 }
130
131 /*******************************************************************
132  Reads or writes a LOOKUP_LEVEL structure.
133 ********************************************************************/
134
135 BOOL smb_io_lookup_level(char *desc, LOOKUP_LEVEL *level, prs_struct *ps, int depth)
136 {
137         if (level == NULL)
138                 return False;
139
140         prs_debug(ps, depth, desc, "smb_io_lookup_level");
141         depth++;
142
143         if(!prs_align(ps))
144                 return False;
145         if(!prs_uint16("value", ps, depth, &level->value))
146                 return False;
147         if(!prs_align(ps))
148                 return False;
149
150         return True;
151 }
152
153 /*******************************************************************
154  Gets an enumeration handle from an ENUM_HND structure.
155 ********************************************************************/
156
157 uint32 get_enum_hnd(ENUM_HND *enh)
158 {
159         return (enh && enh->ptr_hnd != 0) ? enh->handle : 0;
160 }
161
162 /*******************************************************************
163  Inits an ENUM_HND structure.
164 ********************************************************************/
165
166 void init_enum_hnd(ENUM_HND *enh, uint32 hnd)
167 {
168         DEBUG(5,("smb_io_enum_hnd\n"));
169
170         enh->ptr_hnd = (hnd != 0) ? 1 : 0;
171         enh->handle = hnd;
172 }
173
174 /*******************************************************************
175  Reads or writes an ENUM_HND structure.
176 ********************************************************************/
177
178 BOOL smb_io_enum_hnd(char *desc, ENUM_HND *hnd, prs_struct *ps, int depth)
179 {
180         if (hnd == NULL)
181                 return False;
182
183         prs_debug(ps, depth, desc, "smb_io_enum_hnd");
184         depth++;
185
186         if(!prs_align(ps))
187                 return False;
188         
189         if(!prs_uint32("ptr_hnd", ps, depth, &hnd->ptr_hnd)) /* pointer */
190                 return False;
191
192         if (hnd->ptr_hnd != 0) {
193                 if(!prs_uint32("handle ", ps, depth, &hnd->handle )) /* enum handle */
194                         return False;
195         }
196
197         return True;
198 }
199
200 /*******************************************************************
201  Reads or writes a DOM_SID structure.
202 ********************************************************************/
203
204 BOOL smb_io_dom_sid(char *desc, DOM_SID *sid, prs_struct *ps, int depth)
205 {
206         int i;
207
208         if (sid == NULL)
209                 return False;
210
211         prs_debug(ps, depth, desc, "smb_io_dom_sid");
212         depth++;
213
214         if(!prs_align(ps))
215                 return False;
216         
217         if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num))
218                 return False;
219         if(!prs_uint8 ("num_auths  ", ps, depth, &sid->num_auths))
220                 return False;
221
222         for (i = 0; i < 6; i++)
223         {
224                 fstring tmp;
225                 slprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i);
226                 if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i]))
227                         return False;
228         }
229
230         /* oops! XXXX should really issue a warning here... */
231         if (sid->num_auths > MAXSUBAUTHS)
232                 sid->num_auths = MAXSUBAUTHS;
233
234         if(!prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths))
235                 return False;
236
237         return True;
238 }
239
240 /*******************************************************************
241  Inits a DOM_SID structure.
242
243  BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 
244  identauth >= 2^32 can be detected because it will be specified in hex
245 ********************************************************************/
246
247 void init_dom_sid(DOM_SID *sid, char *str_sid)
248 {
249         pstring domsid;
250         int identauth;
251         char *p;
252
253         if (str_sid == NULL)
254         {
255                 DEBUG(4,("netlogon domain SID: none\n"));
256                 sid->sid_rev_num = 0;
257                 sid->num_auths = 0;
258                 return;
259         }
260                 
261         pstrcpy(domsid, str_sid);
262
263         DEBUG(4,("init_dom_sid %d SID:  %s\n", __LINE__, domsid));
264
265         /* assume, but should check, that domsid starts "S-" */
266         p = strtok(domsid+2,"-");
267         sid->sid_rev_num = atoi(p);
268
269         /* identauth in decimal should be <  2^32 */
270         /* identauth in hex     should be >= 2^32 */
271         identauth = atoi(strtok(0,"-"));
272
273         DEBUG(4,("netlogon rev %d\n", sid->sid_rev_num));
274         DEBUG(4,("netlogon %s ia %d\n", p, identauth));
275
276         sid->id_auth[0] = 0;
277         sid->id_auth[1] = 0;
278         sid->id_auth[2] = (identauth & 0xff000000) >> 24;
279         sid->id_auth[3] = (identauth & 0x00ff0000) >> 16;
280         sid->id_auth[4] = (identauth & 0x0000ff00) >> 8;
281         sid->id_auth[5] = (identauth & 0x000000ff);
282
283         sid->num_auths = 0;
284
285         while ((p = strtok(0, "-")) != NULL && sid->num_auths < MAXSUBAUTHS)
286                 sid->sub_auths[sid->num_auths++] = atoi(p);
287
288         DEBUG(4,("init_dom_sid: %d SID:  %s\n", __LINE__, domsid));
289 }
290
291 /*******************************************************************
292  Inits a DOM_SID2 structure.
293 ********************************************************************/
294
295 void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid)
296 {
297         sid2->sid = *sid;
298         sid2->num_auths = sid2->sid.num_auths;
299 }
300
301 /*******************************************************************
302  Reads or writes a DOM_SID2 structure.
303 ********************************************************************/
304
305 BOOL smb_io_dom_sid2(char *desc, DOM_SID2 *sid, prs_struct *ps, int depth)
306 {
307         if (sid == NULL)
308                 return False;
309
310         prs_debug(ps, depth, desc, "smb_io_dom_sid2");
311         depth++;
312
313         if(!prs_align(ps))
314                 return False;
315         
316         if(!prs_uint32("num_auths", ps, depth, &sid->num_auths))
317                 return False;
318
319         if(!smb_io_dom_sid("sid", &sid->sid, ps, depth))
320                 return False;
321
322         return True;
323 }
324
325 /*******************************************************************
326 creates a STRHDR structure.
327 ********************************************************************/
328
329 void init_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer)
330 {
331         hdr->str_max_len = max_len;
332         hdr->str_str_len = len;
333         hdr->buffer      = buffer;
334 }
335
336 /*******************************************************************
337  Reads or writes a STRHDR structure.
338 ********************************************************************/
339
340 BOOL smb_io_strhdr(char *desc,  STRHDR *hdr, prs_struct *ps, int depth)
341 {
342         if (hdr == NULL)
343                 return False;
344
345         prs_debug(ps, depth, desc, "smb_io_strhdr");
346         depth++;
347
348         prs_align(ps);
349         
350         if(!prs_uint16("str_str_len", ps, depth, &hdr->str_str_len))
351                 return False;
352         if(!prs_uint16("str_max_len", ps, depth, &hdr->str_max_len))
353                 return False;
354         if(!prs_uint32("buffer     ", ps, depth, &hdr->buffer))
355                 return False;
356
357         return True;
358 }
359
360 /*******************************************************************
361  Inits a UNIHDR structure.
362 ********************************************************************/
363
364 void init_uni_hdr(UNIHDR *hdr, int len)
365 {
366         hdr->uni_str_len = 2 * len;
367         hdr->uni_max_len = 2 * len;
368         hdr->buffer      = len != 0 ? 1 : 0;
369 }
370
371 /*******************************************************************
372  Reads or writes a UNIHDR structure.
373 ********************************************************************/
374
375 BOOL smb_io_unihdr(char *desc, UNIHDR *hdr, prs_struct *ps, int depth)
376 {
377         if (hdr == NULL)
378                 return False;
379
380         prs_debug(ps, depth, desc, "smb_io_unihdr");
381         depth++;
382
383         if(!prs_align(ps))
384                 return False;
385         
386         if(!prs_uint16("uni_str_len", ps, depth, &hdr->uni_str_len))
387                 return False;
388         if(!prs_uint16("uni_max_len", ps, depth, &hdr->uni_max_len))
389                 return False;
390         if(!prs_uint32("buffer     ", ps, depth, &hdr->buffer))
391                 return False;
392
393         return True;
394 }
395
396 /*******************************************************************
397  Inits a BUFHDR structure.
398 ********************************************************************/
399
400 void init_buf_hdr(BUFHDR *hdr, int max_len, int len)
401 {
402         hdr->buf_max_len = max_len;
403         hdr->buf_len     = len;
404 }
405
406 /*******************************************************************
407  prs_uint16 wrapper. Call this and it sets up a pointer to where the
408  uint16 should be stored, or gets the size if reading.
409  ********************************************************************/
410
411 BOOL smb_io_hdrbuf_pre(char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset)
412 {
413         (*offset) = prs_offset(ps);
414         if (ps->io) {
415
416                 /* reading. */
417
418                 if(!smb_io_hdrbuf(desc, hdr, ps, depth))
419                         return False;
420
421         } else {
422
423                 /* writing. */
424
425                 if(!prs_set_offset(ps, prs_offset(ps) + (sizeof(uint32) * 2)))
426                         return False;
427         }
428
429         return True;
430 }
431
432 /*******************************************************************
433  smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
434  Does nothing on reading, as that is already handled by ...._pre()
435  ********************************************************************/
436
437 BOOL smb_io_hdrbuf_post(char *desc, BUFHDR *hdr, prs_struct *ps, int depth, 
438                                 uint32 ptr_hdrbuf, uint32 max_len, uint32 len)
439 {
440         if (!ps->io) {
441                 /* writing: go back and do a retrospective job.  i hate this */
442
443                 uint32 old_offset = prs_offset(ps);
444
445                 init_buf_hdr(hdr, max_len, len);
446                 if(!prs_set_offset(ps, ptr_hdrbuf))
447                         return False;
448                 if(!smb_io_hdrbuf(desc, hdr, ps, depth))
449                         return False;
450
451                 if(!prs_set_offset(ps, old_offset))
452                         return False;
453         }
454
455         return True;
456 }
457
458 /*******************************************************************
459  Reads or writes a BUFHDR structure.
460 ********************************************************************/
461
462 BOOL smb_io_hdrbuf(char *desc, BUFHDR *hdr, prs_struct *ps, int depth)
463 {
464         if (hdr == NULL)
465                 return False;
466
467         prs_debug(ps, depth, desc, "smb_io_hdrbuf");
468         depth++;
469
470         if(!prs_align(ps))
471                 return False;
472         
473         if(!prs_uint32("buf_max_len", ps, depth, &hdr->buf_max_len))
474                 return False;
475         if(!prs_uint32("buf_len    ", ps, depth, &hdr->buf_len))
476                 return False;
477
478         return True;
479 }
480
481 /*******************************************************************
482 creates a UNIHDR2 structure.
483 ********************************************************************/
484
485 void init_uni_hdr2(UNIHDR2 *hdr, int len)
486 {
487         init_uni_hdr(&hdr->unihdr, len);
488         hdr->buffer = (len > 0) ? 1 : 0;
489 }
490
491 /*******************************************************************
492  Reads or writes a UNIHDR2 structure.
493 ********************************************************************/
494
495 BOOL smb_io_unihdr2(char *desc, UNIHDR2 *hdr2, prs_struct *ps, int depth)
496 {
497         if (hdr2 == NULL)
498                 return False;
499
500         prs_debug(ps, depth, desc, "smb_io_unihdr2");
501         depth++;
502
503         if(!prs_align(ps))
504                 return False;
505
506         if(!smb_io_unihdr("hdr", &hdr2->unihdr, ps, depth))
507                 return False;
508         if(!prs_uint32("buffer", ps, depth, &hdr2->buffer))
509                 return False;
510
511         return True;
512 }
513
514 /*******************************************************************
515  Inits a UNISTR structure.
516 ********************************************************************/
517
518 void init_unistr(UNISTR *str, const char *buf)
519 {
520         size_t len;
521
522         if (buf == NULL) {
523                 str->buffer = NULL;
524                 return;
525         }
526                 
527
528         len = strlen(buf) + 1;
529
530         if (len < MAX_UNISTRLEN)
531                 len = MAX_UNISTRLEN;
532         len *= sizeof(uint16);
533
534         str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
535         if (str->buffer == NULL)
536                 smb_panic("init_unistr: malloc fail\n");
537
538         rpcstr_push(str->buffer, buf, len, STR_TERMINATE);
539 }
540
541 /*******************************************************************
542 reads or writes a UNISTR structure.
543 XXXX NOTE: UNISTR structures NEED to be null-terminated.
544 ********************************************************************/
545
546 BOOL smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
547 {
548         if (uni == NULL)
549                 return False;
550
551         prs_debug(ps, depth, desc, "smb_io_unistr");
552         depth++;
553
554         if(!prs_align(ps))
555                 return False;
556         if(!prs_unistr("unistr", ps, depth, uni))
557                 return False;
558
559         return True;
560 }
561
562 /*******************************************************************
563  Allocate the BUFFER3 memory.
564 ********************************************************************/
565
566 static void create_buffer3(BUFFER3 *str, size_t len)
567 {
568         if (len < MAX_BUFFERLEN)
569                 len = MAX_BUFFERLEN;
570
571     str->buffer = talloc_zero(get_talloc_ctx(), len);
572         if (str->buffer == NULL)
573                 smb_panic("create_buffer3: talloc fail\n");
574
575 }
576
577 /*******************************************************************
578  Inits a BUFFER3 structure from a uint32
579 ********************************************************************/
580
581 void init_buffer3_uint32(BUFFER3 *str, uint32 val)
582 {
583         ZERO_STRUCTP(str);
584
585         /* set up string lengths. */
586         str->buf_max_len = sizeof(uint32);
587         str->buf_len     = sizeof(uint32);
588
589         create_buffer3(str, sizeof(uint32));
590         SIVAL(str->buffer, 0, val);
591 }
592
593 /*******************************************************************
594  Inits a BUFFER3 structure.
595 ********************************************************************/
596
597 void init_buffer3_str(BUFFER3 *str, char *buf, int len)
598 {
599         ZERO_STRUCTP(str);
600
601         /* set up string lengths. */
602         str->buf_max_len = len * 2;
603         str->buf_len = len * 2;
604
605         create_buffer3(str, str->buf_max_len);
606
607         rpcstr_push(str->buffer, buf, str->buf_max_len, STR_TERMINATE);
608         
609 }
610
611 /*******************************************************************
612  Inits a BUFFER3 structure from a hex string.
613 ********************************************************************/
614
615 void init_buffer3_hex(BUFFER3 *str, char *buf)
616 {
617         ZERO_STRUCTP(str);
618         create_buffer3(str, strlen(buf));
619         str->buf_max_len = str->buf_len = strhex_to_str((char *)str->buffer, sizeof(str->buffer), buf);
620 }
621
622 /*******************************************************************
623  Inits a BUFFER3 structure.
624 ********************************************************************/
625
626 void init_buffer3_bytes(BUFFER3 *str, uint8 *buf, int len)
627 {
628         ZERO_STRUCTP(str);
629
630         /* max buffer size (allocated size) */
631         str->buf_max_len = len;
632         if (buf != NULL) {
633                 create_buffer3(str, len);
634                 memcpy(str->buffer, buf, len);
635         }
636         str->buf_len = buf != NULL ? len : 0;
637 }
638
639 /*******************************************************************
640  Reads or writes a BUFFER3 structure.
641    the uni_max_len member tells you how large the buffer is.
642    the uni_str_len member tells you how much of the buffer is really used.
643 ********************************************************************/
644
645 BOOL smb_io_buffer3(char *desc, BUFFER3 *buf3, prs_struct *ps, int depth)
646 {
647         if (buf3 == NULL)
648                 return False;
649
650         prs_debug(ps, depth, desc, "smb_io_buffer3");
651         depth++;
652
653         if(!prs_align(ps))
654                 return False;
655         
656         if(!prs_uint32("uni_max_len", ps, depth, &buf3->buf_max_len))
657                 return False;
658
659         if (UNMARSHALLING(ps)) {
660                 buf3->buffer = (unsigned char *)prs_alloc_mem(ps, buf3->buf_max_len);
661                 if (buf3->buffer == NULL)
662                         return False;
663         }
664
665         if(!prs_uint8s(True, "buffer     ", ps, depth, buf3->buffer, buf3->buf_max_len))
666                 return False;
667
668         if(!prs_uint32("buf_len    ", ps, depth, &buf3->buf_len))
669                 return False;
670
671         return True;
672 }
673
674 /*******************************************************************
675 reads or writes a BUFFER5 structure.
676 the buf_len member tells you how large the buffer is.
677 ********************************************************************/
678 BOOL smb_io_buffer5(char *desc, BUFFER5 *buf5, prs_struct *ps, int depth)
679 {
680         prs_debug(ps, depth, desc, "smb_io_buffer5");
681         depth++;
682
683         if (buf5 == NULL) return False;
684
685         if(!prs_align(ps))
686                 return False;
687         if(!prs_uint32("buf_len", ps, depth, &buf5->buf_len))
688                 return False;
689
690
691         if(!prs_buffer5(True, "buffer" , ps, depth, buf5))
692                 return False;
693
694         return True;
695 }
696
697 /*******************************************************************
698  Inits a BUFFER2 structure.
699 ********************************************************************/
700
701 void init_buffer2(BUFFER2 *str, uint8 *buf, int len)
702 {
703         ZERO_STRUCTP(str);
704
705         /* max buffer size (allocated size) */
706         str->buf_max_len = len;
707         str->undoc       = 0;
708         str->buf_len = buf != NULL ? len : 0;
709
710         if (buf != NULL) {
711                 if (len < MAX_BUFFERLEN)
712                         len = MAX_BUFFERLEN;
713                 str->buffer = talloc_zero(get_talloc_ctx(), len);
714                 if (str->buffer == NULL)
715                         smb_panic("init_buffer2: talloc fail\n");
716                 memcpy(str->buffer, buf, MIN(str->buf_len, len));
717         }
718 }
719
720 /*******************************************************************
721  Reads or writes a BUFFER2 structure.
722    the uni_max_len member tells you how large the buffer is.
723    the uni_str_len member tells you how much of the buffer is really used.
724 ********************************************************************/
725
726 BOOL smb_io_buffer2(char *desc, BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth)
727 {
728         if (buf2 == NULL)
729                 return False;
730
731         if (buffer) {
732
733                 prs_debug(ps, depth, desc, "smb_io_buffer2");
734                 depth++;
735
736                 if(!prs_align(ps))
737                         return False;
738                 
739                 if(!prs_uint32("uni_max_len", ps, depth, &buf2->buf_max_len))
740                         return False;
741                 if(!prs_uint32("undoc      ", ps, depth, &buf2->undoc))
742                         return False;
743                 if(!prs_uint32("buf_len    ", ps, depth, &buf2->buf_len))
744                         return False;
745
746                 /* buffer advanced by indicated length of string
747                    NOT by searching for null-termination */
748
749                 if(!prs_buffer2(True, "buffer     ", ps, depth, buf2))
750                         return False;
751
752         } else {
753
754                 prs_debug(ps, depth, desc, "smb_io_buffer2 - NULL");
755                 depth++;
756                 memset((char *)buf2, '\0', sizeof(*buf2));
757
758         }
759         return True;
760 }
761
762 /*******************************************************************
763 creates a UNISTR2 structure: sets up the buffer, too
764 ********************************************************************/
765
766 void init_buf_unistr2(UNISTR2 *str, uint32 *ptr, const char *buf)
767 {
768         if (buf != NULL) {
769
770                 *ptr = 1;
771                 init_unistr2(str, buf, strlen(buf)+1);
772
773         } else {
774
775                 *ptr = 0;
776                 init_unistr2(str, "", 0);
777
778         }
779 }
780
781 /*******************************************************************
782  Copies a UNISTR2 structure.
783 ********************************************************************/
784
785 void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
786 {
787
788         /* set up string lengths. add one if string is not null-terminated */
789         str->uni_max_len = from->uni_max_len;
790         str->undoc       = from->undoc;
791         str->uni_str_len = from->uni_str_len;
792
793         if (from->buffer == NULL)
794                 return;
795                 
796         /* the string buffer is allocated to the maximum size
797            (the the length of the source string) to prevent
798            reallocation of memory. */
799         if (str->buffer == NULL) {
800                 size_t len = from->uni_max_len * sizeof(uint16);
801
802                 if (len < MAX_UNISTRLEN)
803                         len = MAX_UNISTRLEN;
804                 len *= sizeof(uint16);
805
806                 str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
807                 if ((str->buffer == NULL) && (len > 0 ))
808                 {
809                         smb_panic("copy_unistr2: talloc fail\n");
810                         return;
811                 }
812         }
813
814         /* copy the string */
815         memcpy(str->buffer, from->buffer, from->uni_max_len*sizeof(uint16));
816 }
817
818 /*******************************************************************
819  Creates a STRING2 structure.
820 ********************************************************************/
821
822 void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
823 {
824         int alloc_len = 0;
825
826         /* set up string lengths. */
827         str->str_max_len = max_len;
828         str->undoc       = 0;
829         str->str_str_len = str_len;
830
831         /* store the string */
832         if(str_len != 0) {
833                 if (str_len < MAX_STRINGLEN)
834                         alloc_len = MAX_STRINGLEN;
835                 str->buffer = talloc_zero(get_talloc_ctx(), alloc_len);
836                 if (str->buffer == NULL)
837                         smb_panic("init_string2: malloc fail\n");
838                 memcpy(str->buffer, buf, str_len);
839   }
840 }
841
842 /*******************************************************************
843  Reads or writes a STRING2 structure.
844  XXXX NOTE: STRING2 structures need NOT be null-terminated.
845    the str_str_len member tells you how long the string is;
846    the str_max_len member tells you how large the buffer is.
847 ********************************************************************/
848
849 BOOL smb_io_string2(char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
850 {
851         if (str2 == NULL)
852                 return False;
853
854         if (buffer) {
855
856                 prs_debug(ps, depth, desc, "smb_io_string2");
857                 depth++;
858
859                 if(!prs_align(ps))
860                         return False;
861                 
862                 if(!prs_uint32("str_max_len", ps, depth, &str2->str_max_len))
863                         return False;
864                 if(!prs_uint32("undoc      ", ps, depth, &str2->undoc))
865                         return False;
866                 if(!prs_uint32("str_str_len", ps, depth, &str2->str_str_len))
867                         return False;
868
869                 /* buffer advanced by indicated length of string
870                    NOT by searching for null-termination */
871                 if(!prs_string2(True, "buffer     ", ps, depth, str2))
872                         return False;
873
874         } else {
875
876                 prs_debug(ps, depth, desc, "smb_io_string2 - NULL");
877                 depth++;
878                 memset((char *)str2, '\0', sizeof(*str2));
879
880         }
881
882         return True;
883 }
884
885 /*******************************************************************
886  Inits a UNISTR2 structure.
887 ********************************************************************/
888
889 void init_unistr2(UNISTR2 *str, const char *buf, size_t len)
890 {
891         ZERO_STRUCTP(str);
892
893         /* set up string lengths. */
894         str->uni_max_len = (uint32)len;
895         str->undoc       = 0;
896         str->uni_str_len = (uint32)len;
897
898         if (len < MAX_UNISTRLEN)
899                 len = MAX_UNISTRLEN;
900         len *= sizeof(uint16);
901
902         str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
903         if ((str->buffer == NULL) && (len > 0))
904         {
905                 smb_panic("init_unistr2: malloc fail\n");
906                 return;
907         }
908
909         /*
910          * don't move this test above ! The UNISTR2 must be initialized !!!
911          * jfm, 7/7/2001.
912          */
913         if (buf==NULL)
914                 return;
915
916         rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
917 }
918
919 /*******************************************************************
920  Inits a UNISTR2 structure from a UNISTR
921 ********************************************************************/
922 void init_unistr2_from_unistr (UNISTR2 *to, UNISTR *from)
923 {
924
925         uint32 i;
926
927         /* the destination UNISTR2 should never be NULL.
928            if it is it is a programming error */
929
930         /* if the source UNISTR is NULL, then zero out
931            the destination string and return */
932         ZERO_STRUCTP (to);
933         if ((from == NULL) || (from->buffer == NULL))
934                 return;
935
936         /* get the length; UNISTR must be NULL terminated */
937         i = 0;
938         while ((from->buffer)[i]!='\0')
939                 i++;
940         i++;    /* one more to catch the terminating NULL */
941                 /* is this necessary -- jerry?  I need to think */
942
943         /* set up string lengths; uni_max_len is set to i+1
944            because we need to account for the final NULL termination */
945         to->uni_max_len = i;
946         to->undoc       = 0;
947         to->uni_str_len = i;
948
949         /* allocate the space and copy the string buffer */
950         to->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), sizeof(uint16)*(to->uni_str_len));
951         if (to->buffer == NULL)
952                 smb_panic("init_unistr2_from_unistr: malloc fail\n");
953         memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16));
954                 
955         return;
956 }
957
958
959 /*******************************************************************
960  Reads or writes a UNISTR2 structure.
961  XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
962    the uni_str_len member tells you how long the string is;
963    the uni_max_len member tells you how large the buffer is.
964 ********************************************************************/
965
966 BOOL smb_io_unistr2(char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
967 {
968         if (uni2 == NULL)
969                 return False;
970
971         if (buffer) {
972
973                 prs_debug(ps, depth, desc, "smb_io_unistr2");
974                 depth++;
975
976                 if(!prs_align(ps))
977                         return False;
978                 
979                 if(!prs_uint32("uni_max_len", ps, depth, &uni2->uni_max_len))
980                         return False;
981                 if(!prs_uint32("undoc      ", ps, depth, &uni2->undoc))
982                         return False;
983                 if(!prs_uint32("uni_str_len", ps, depth, &uni2->uni_str_len))
984                         return False;
985
986                 /* buffer advanced by indicated length of string
987                    NOT by searching for null-termination */
988                 if(!prs_unistr2(True, "buffer     ", ps, depth, uni2))
989                         return False;
990
991         } else {
992
993                 prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");
994                 depth++;
995                 memset((char *)uni2, '\0', sizeof(*uni2));
996
997         }
998
999         return True;
1000 }
1001
1002 /*******************************************************************
1003  Inits a DOM_RID2 structure.
1004 ********************************************************************/
1005
1006 void init_dom_rid2(DOM_RID2 *rid2, uint32 rid, uint8 type, uint32 idx)
1007 {
1008         rid2->type    = type;
1009         rid2->rid     = rid;
1010         rid2->rid_idx = idx;
1011 }
1012
1013 /*******************************************************************
1014  Reads or writes a DOM_RID2 structure.
1015 ********************************************************************/
1016
1017 BOOL smb_io_dom_rid2(char *desc, DOM_RID2 *rid2, prs_struct *ps, int depth)
1018 {
1019         if (rid2 == NULL)
1020                 return False;
1021
1022         prs_debug(ps, depth, desc, "smb_io_dom_rid2");
1023         depth++;
1024
1025         if(!prs_align(ps))
1026                 return False;
1027    
1028         if(!prs_uint8("type   ", ps, depth, &rid2->type))
1029                 return False;
1030         if(!prs_align(ps))
1031                 return False;
1032         if(!prs_uint32("rid    ", ps, depth, &rid2->rid))
1033                 return False;
1034         if(!prs_uint32("rid_idx", ps, depth, &rid2->rid_idx))
1035                 return False;
1036
1037         return True;
1038 }
1039
1040 /*******************************************************************
1041 creates a DOM_RID3 structure.
1042 ********************************************************************/
1043
1044 void init_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type)
1045 {
1046     rid3->rid      = rid;
1047     rid3->type1    = type;
1048     rid3->ptr_type = 0x1; /* non-zero, basically. */
1049     rid3->type2    = 0x1;
1050     rid3->unk      = type;
1051 }
1052
1053 /*******************************************************************
1054 reads or writes a DOM_RID3 structure.
1055 ********************************************************************/
1056
1057 BOOL smb_io_dom_rid3(char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth)
1058 {
1059         if (rid3 == NULL)
1060                 return False;
1061
1062         prs_debug(ps, depth, desc, "smb_io_dom_rid3");
1063         depth++;
1064
1065         if(!prs_align(ps))
1066                 return False;
1067
1068         if(!prs_uint32("rid     ", ps, depth, &rid3->rid))
1069                 return False;
1070         if(!prs_uint32("type1   ", ps, depth, &rid3->type1))
1071                 return False;
1072         if(!prs_uint32("ptr_type", ps, depth, &rid3->ptr_type))
1073                 return False;
1074         if(!prs_uint32("type2   ", ps, depth, &rid3->type2))
1075                 return False;
1076         if(!prs_uint32("unk     ", ps, depth, &rid3->unk))
1077                 return False;
1078
1079         return True;
1080 }
1081
1082 /*******************************************************************
1083  Inits a DOM_RID4 structure.
1084 ********************************************************************/
1085
1086 void init_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
1087 {
1088     rid4->unknown = unknown;
1089     rid4->attr    = attr;
1090     rid4->rid     = rid;
1091 }
1092
1093 /*******************************************************************
1094  Inits a DOM_CLNT_SRV structure.
1095 ********************************************************************/
1096
1097 static void init_clnt_srv(DOM_CLNT_SRV *log, char *logon_srv, char *comp_name)
1098 {
1099         DEBUG(5,("init_clnt_srv: %d\n", __LINE__));
1100
1101         if (logon_srv != NULL) {
1102                 log->undoc_buffer = 1;
1103                 init_unistr2(&log->uni_logon_srv, logon_srv, strlen(logon_srv)+1);
1104         } else {
1105                 log->undoc_buffer = 0;
1106         }
1107
1108         if (comp_name != NULL) {
1109                 log->undoc_buffer2 = 1;
1110                 init_unistr2(&log->uni_comp_name, comp_name, strlen(comp_name)+1);
1111         } else {
1112                 log->undoc_buffer2 = 0;
1113         }
1114 }
1115
1116 /*******************************************************************
1117  Inits or writes a DOM_CLNT_SRV structure.
1118 ********************************************************************/
1119
1120 static BOOL smb_io_clnt_srv(char *desc, DOM_CLNT_SRV *log, prs_struct *ps, int depth)
1121 {
1122         if (log == NULL)
1123                 return False;
1124
1125         prs_debug(ps, depth, desc, "smb_io_clnt_srv");
1126         depth++;
1127
1128         if(!prs_align(ps))
1129                 return False;
1130         
1131         if(!prs_uint32("undoc_buffer ", ps, depth, &log->undoc_buffer))
1132                 return False;
1133
1134         if (log->undoc_buffer != 0) {
1135                 if(!smb_io_unistr2("unistr2", &log->uni_logon_srv, log->undoc_buffer, ps, depth))
1136                         return False;
1137         }
1138
1139         if(!prs_align(ps))
1140                 return False;
1141
1142         if(!prs_uint32("undoc_buffer2", ps, depth, &log->undoc_buffer2))
1143                 return False;
1144
1145         if (log->undoc_buffer2 != 0) {
1146                 if(!smb_io_unistr2("unistr2", &log->uni_comp_name, log->undoc_buffer2, ps, depth))
1147                         return False;
1148         }
1149
1150         return True;
1151 }
1152
1153 /*******************************************************************
1154  Inits a DOM_LOG_INFO structure.
1155 ********************************************************************/
1156
1157 void init_log_info(DOM_LOG_INFO *log, const char *logon_srv, const char *acct_name,
1158                 uint16 sec_chan, const char *comp_name)
1159 {
1160         DEBUG(5,("make_log_info %d\n", __LINE__));
1161
1162         log->undoc_buffer = 1;
1163
1164         init_unistr2(&log->uni_logon_srv, logon_srv, strlen(logon_srv)+1);
1165         init_unistr2(&log->uni_acct_name, acct_name, strlen(acct_name)+1);
1166
1167         log->sec_chan = sec_chan;
1168
1169         init_unistr2(&log->uni_comp_name, comp_name, strlen(comp_name)+1);
1170 }
1171
1172 /*******************************************************************
1173  Reads or writes a DOM_LOG_INFO structure.
1174 ********************************************************************/
1175
1176 BOOL smb_io_log_info(char *desc, DOM_LOG_INFO *log, prs_struct *ps, int depth)
1177 {
1178         if (log == NULL)
1179                 return False;
1180
1181         prs_debug(ps, depth, desc, "smb_io_log_info");
1182         depth++;
1183
1184         if(!prs_align(ps))
1185                 return False;
1186         
1187         if(!prs_uint32("undoc_buffer", ps, depth, &log->undoc_buffer))
1188                 return False;
1189
1190         if(!smb_io_unistr2("unistr2", &log->uni_logon_srv, True, ps, depth))
1191                 return False;
1192         if(!smb_io_unistr2("unistr2", &log->uni_acct_name, True, ps, depth))
1193                 return False;
1194
1195         if(!prs_uint16("sec_chan", ps, depth, &log->sec_chan))
1196                 return False;
1197
1198         if(!smb_io_unistr2("unistr2", &log->uni_comp_name, True, ps, depth))
1199                 return False;
1200
1201         return True;
1202 }
1203
1204 /*******************************************************************
1205  Reads or writes a DOM_CHAL structure.
1206 ********************************************************************/
1207
1208 BOOL smb_io_chal(char *desc, DOM_CHAL *chal, prs_struct *ps, int depth)
1209 {
1210         if (chal == NULL)
1211                 return False;
1212
1213         prs_debug(ps, depth, desc, "smb_io_chal");
1214         depth++;
1215
1216         if(!prs_align(ps))
1217                 return False;
1218         
1219         if(!prs_uint8s (False, "data", ps, depth, chal->data, 8))
1220                 return False;
1221
1222         return True;
1223 }
1224
1225 /*******************************************************************
1226  Reads or writes a DOM_CRED structure.
1227 ********************************************************************/
1228
1229 BOOL smb_io_cred(char *desc,  DOM_CRED *cred, prs_struct *ps, int depth)
1230 {
1231         if (cred == NULL)
1232                 return False;
1233
1234         prs_debug(ps, depth, desc, "smb_io_cred");
1235         depth++;
1236
1237         if(!prs_align(ps))
1238                 return False;
1239
1240         if(!smb_io_chal ("", &cred->challenge, ps, depth))
1241                 return False;
1242
1243         if(!smb_io_utime("", &cred->timestamp, ps, depth))
1244                 return False;
1245
1246         return True;
1247 }
1248
1249 /*******************************************************************
1250  Inits a DOM_CLNT_INFO2 structure.
1251 ********************************************************************/
1252
1253 void init_clnt_info2(DOM_CLNT_INFO2 *clnt,
1254                                 char *logon_srv, char *comp_name,
1255                                 DOM_CRED *clnt_cred)
1256 {
1257         DEBUG(5,("make_clnt_info: %d\n", __LINE__));
1258
1259         init_clnt_srv(&(clnt->login), logon_srv, comp_name);
1260
1261         if (clnt_cred != NULL) {
1262                 clnt->ptr_cred = 1;
1263                 memcpy(&(clnt->cred), clnt_cred, sizeof(clnt->cred));
1264         } else {
1265                 clnt->ptr_cred = 0;
1266         }
1267 }
1268
1269 /*******************************************************************
1270  Reads or writes a DOM_CLNT_INFO2 structure.
1271 ********************************************************************/
1272
1273 BOOL smb_io_clnt_info2(char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
1274 {
1275         if (clnt == NULL)
1276                 return False;
1277
1278         prs_debug(ps, depth, desc, "smb_io_clnt_info2");
1279         depth++;
1280
1281         if(!prs_align(ps))
1282                 return False;
1283         
1284         if(!smb_io_clnt_srv("", &clnt->login, ps, depth))
1285                 return False;
1286
1287         if(!prs_align(ps))
1288                 return False;
1289         
1290         if(!prs_uint32("ptr_cred", ps, depth, &clnt->ptr_cred))
1291                 return False;
1292         if(!smb_io_cred("", &clnt->cred, ps, depth))
1293                 return False;
1294
1295         return True;
1296 }
1297
1298 /*******************************************************************
1299  Inits a DOM_CLNT_INFO structure.
1300 ********************************************************************/
1301
1302 void init_clnt_info(DOM_CLNT_INFO *clnt,
1303                 char *logon_srv, char *acct_name,
1304                 uint16 sec_chan, char *comp_name,
1305                                 DOM_CRED *cred)
1306 {
1307         DEBUG(5,("make_clnt_info\n"));
1308
1309         init_log_info(&clnt->login, logon_srv, acct_name, sec_chan, comp_name);
1310         memcpy(&clnt->cred, cred, sizeof(clnt->cred));
1311 }
1312
1313 /*******************************************************************
1314  Reads or writes a DOM_CLNT_INFO structure.
1315 ********************************************************************/
1316
1317 BOOL smb_io_clnt_info(char *desc,  DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
1318 {
1319         if (clnt == NULL)
1320                 return False;
1321
1322         prs_debug(ps, depth, desc, "smb_io_clnt_info");
1323         depth++;
1324
1325         if(!prs_align(ps))
1326                 return False;
1327         
1328         if(!smb_io_log_info("", &clnt->login, ps, depth))
1329                 return False;
1330         if(!smb_io_cred("", &clnt->cred, ps, depth))
1331                 return False;
1332
1333         return True;
1334 }
1335
1336 /*******************************************************************
1337  Inits a DOM_LOGON_ID structure.
1338 ********************************************************************/
1339
1340 void init_logon_id(DOM_LOGON_ID *log, uint32 log_id_low, uint32 log_id_high)
1341 {
1342         DEBUG(5,("make_logon_id: %d\n", __LINE__));
1343
1344         log->low  = log_id_low;
1345         log->high = log_id_high;
1346 }
1347
1348 /*******************************************************************
1349  Reads or writes a DOM_LOGON_ID structure.
1350 ********************************************************************/
1351
1352 BOOL smb_io_logon_id(char *desc, DOM_LOGON_ID *log, prs_struct *ps, int depth)
1353 {
1354         if (log == NULL)
1355                 return False;
1356
1357         prs_debug(ps, depth, desc, "smb_io_logon_id");
1358         depth++;
1359
1360         if(!prs_align(ps))
1361                 return False;
1362         
1363         if(!prs_uint32("low ", ps, depth, &log->low ))
1364                 return False;
1365         if(!prs_uint32("high", ps, depth, &log->high))
1366                 return False;
1367
1368         return True;
1369 }
1370
1371 /*******************************************************************
1372  Inits an OWF_INFO structure.
1373 ********************************************************************/
1374
1375 void init_owf_info(OWF_INFO *hash, uint8 data[16])
1376 {
1377         DEBUG(5,("init_owf_info: %d\n", __LINE__));
1378         
1379         if (data != NULL)
1380                 memcpy(hash->data, data, sizeof(hash->data));
1381         else
1382                 memset((char *)hash->data, '\0', sizeof(hash->data));
1383 }
1384
1385 /*******************************************************************
1386  Reads or writes an OWF_INFO structure.
1387 ********************************************************************/
1388
1389 BOOL smb_io_owf_info(char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
1390 {
1391         if (hash == NULL)
1392                 return False;
1393
1394         prs_debug(ps, depth, desc, "smb_io_owf_info");
1395         depth++;
1396
1397         if(!prs_align(ps))
1398                 return False;
1399         
1400         if(!prs_uint8s (False, "data", ps, depth, hash->data, 16))
1401                 return False;
1402
1403         return True;
1404 }
1405
1406 /*******************************************************************
1407  Reads or writes a DOM_GID structure.
1408 ********************************************************************/
1409
1410 BOOL smb_io_gid(char *desc,  DOM_GID *gid, prs_struct *ps, int depth)
1411 {
1412         if (gid == NULL)
1413                 return False;
1414
1415         prs_debug(ps, depth, desc, "smb_io_gid");
1416         depth++;
1417
1418         if(!prs_align(ps))
1419                 return False;
1420         
1421         if(!prs_uint32("g_rid", ps, depth, &gid->g_rid))
1422                 return False;
1423         if(!prs_uint32("attr ", ps, depth, &gid->attr))
1424                 return False;
1425
1426         return True;
1427 }
1428
1429 /*******************************************************************
1430  Reads or writes an POLICY_HND structure.
1431 ********************************************************************/
1432
1433 BOOL smb_io_pol_hnd(char *desc, POLICY_HND *pol, prs_struct *ps, int depth)
1434 {
1435         if (pol == NULL)
1436                 return False;
1437
1438         prs_debug(ps, depth, desc, "smb_io_pol_hnd");
1439         depth++;
1440
1441         if(!prs_align(ps))
1442                 return False;
1443
1444         if(UNMARSHALLING(ps))
1445                 ZERO_STRUCTP(pol);
1446         
1447         if (!prs_uint32("data1", ps, depth, &pol->data1))
1448                 return False;
1449         if (!prs_uint32("data2", ps, depth, &pol->data2))
1450                 return False;
1451         if (!prs_uint16("data3", ps, depth, &pol->data3))
1452                 return False;
1453         if (!prs_uint16("data4", ps, depth, &pol->data4))
1454                 return False;
1455         if(!prs_uint8s (False, "data5", ps, depth, pol->data5, sizeof(pol->data5)))
1456                 return False;
1457
1458         return True;
1459 }
1460
1461 /*******************************************************************
1462  Create a UNISTR3.
1463 ********************************************************************/
1464
1465 void init_unistr3(UNISTR3 *str, const char *buf)
1466 {
1467         size_t len;
1468
1469         if (buf == NULL) {
1470                 str->uni_str_len=0;
1471                 str->str.buffer = NULL;
1472                 return;
1473         }
1474
1475         len = strlen(buf) + 1;
1476
1477         str->uni_str_len=len;
1478
1479         if (len < MAX_UNISTRLEN)
1480                 len = MAX_UNISTRLEN;
1481
1482         len *= sizeof(uint16);
1483
1484         str->str.buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
1485         if (str->str.buffer == NULL)
1486                 smb_panic("init_unistr3: malloc fail\n");
1487
1488         rpcstr_push((char *)str->str.buffer, buf, len, STR_TERMINATE);
1489 }
1490
1491 /*******************************************************************
1492  Reads or writes a UNISTR3 structure.
1493 ********************************************************************/
1494
1495 BOOL smb_io_unistr3(char *desc, UNISTR3 *name, prs_struct *ps, int depth)
1496 {
1497         if (name == NULL)
1498                 return False;
1499
1500         prs_debug(ps, depth, desc, "smb_io_unistr3");
1501         depth++;
1502
1503         if(!prs_align(ps))
1504                 return False;
1505         
1506         if(!prs_uint32("uni_str_len", ps, depth, &name->uni_str_len))
1507                 return False;
1508
1509         /* don't know if len is specified by uni_str_len member... */
1510         /* assume unicode string is unicode-null-terminated, instead */
1511
1512         if(!prs_unistr3(True, "unistr", name, ps, depth))
1513                 return False;
1514
1515         return True;
1516 }
1517
1518
1519 /*******************************************************************
1520  Stream a uint64_struct
1521  ********************************************************************/
1522 BOOL prs_uint64(char *name, prs_struct *ps, int depth, UINT64_S *data64)
1523 {
1524         return prs_uint32(name, ps, depth+1, &data64->low) &&
1525                 prs_uint32(name, ps, depth+1, &data64->high);
1526 }
1527
1528 /*******************************************************************
1529 reads or writes a BUFHDR2 structure.
1530 ********************************************************************/
1531 BOOL smb_io_bufhdr2(char *desc, BUFHDR2 *hdr, prs_struct *ps, int depth)
1532 {
1533         prs_debug(ps, depth, desc, "smb_io_bufhdr2");
1534         depth++;
1535
1536         prs_align(ps);
1537         prs_uint32("info_level", ps, depth, &(hdr->info_level));
1538         prs_uint32("length    ", ps, depth, &(hdr->length    ));
1539         prs_uint32("buffer    ", ps, depth, &(hdr->buffer    ));
1540
1541         return True;
1542 }
1543
1544 /*******************************************************************
1545 reads or writes a BUFFER4 structure.
1546 ********************************************************************/
1547 BOOL smb_io_buffer4(char *desc, BUFFER4 *buf4, uint32 buffer, prs_struct *ps, int depth)
1548 {
1549         prs_debug(ps, depth, desc, "smb_io_buffer4");
1550         depth++;
1551
1552         prs_align(ps);
1553         prs_uint32("buf_len", ps, depth, &(buf4->buf_len));
1554
1555         if (buf4->buf_len > MAX_BUFFERLEN)
1556         {
1557                 buf4->buf_len = MAX_BUFFERLEN;
1558         }
1559
1560         prs_uint8s(True, "buffer", ps, depth, buf4->buffer, buf4->buf_len);
1561
1562         return True;
1563 }
1564
1565 /*******************************************************************
1566 creates a UNIHDR structure.
1567 ********************************************************************/
1568
1569 BOOL make_uni_hdr(UNIHDR *hdr, int len)
1570 {
1571         if (hdr == NULL)
1572         {
1573                 return False;
1574         }
1575         hdr->uni_str_len = 2 * len;
1576         hdr->uni_max_len = 2 * len;
1577         hdr->buffer      = len != 0 ? 1 : 0;
1578
1579         return True;
1580 }
1581
1582 /*******************************************************************
1583 creates a BUFHDR2 structure.
1584 ********************************************************************/
1585 BOOL make_bufhdr2(BUFHDR2 *hdr, uint32 info_level, uint32 length, uint32 buffer)
1586 {
1587         hdr->info_level = info_level;
1588         hdr->length     = length;
1589         hdr->buffer     = buffer;
1590
1591         return True;
1592 }