- lib/unix_sec_ctxt.c
[samba.git] / source3 / rpc_parse / parse_misc.c
1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
5  *  RPC Pipe client / server routines
6  *  Copyright (C) Andrew Tridgell              1992-1997,
7  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8  *  Copyright (C) Paul Ashton                       1997.
9  *  
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25
26 #include "includes.h"
27
28 extern int DEBUGLEVEL;
29
30
31
32 /*******************************************************************
33 reads or writes a UTIME type.
34 ********************************************************************/
35 static void smb_io_utime(char *desc,  UTIME *t, prs_struct *ps, int depth)
36 {
37         if (t == NULL) return;
38
39         prs_debug(ps, depth, desc, "smb_io_utime");
40         depth++;
41
42         prs_align(ps);
43         
44         prs_uint32 ("time", ps, depth, &(t->time));
45 }
46
47 /*******************************************************************
48 reads or writes an NTTIME structure.
49 ********************************************************************/
50 void smb_io_time(char *desc,  NTTIME *nttime, prs_struct *ps, int depth)
51 {
52         if (nttime == NULL) return;
53
54         prs_debug(ps, depth, desc, "smb_io_time");
55         depth++;
56
57         prs_align(ps);
58         
59         prs_uint32("low ", ps, depth, &(nttime->low )); /* low part */
60         prs_uint32("high", ps, depth, &(nttime->high)); /* high part */
61 }
62
63 /*******************************************************************
64 reads or writes a LOOKUP_LEVEL structure.
65 ********************************************************************/
66 void smb_io_lookup_level(char *desc, LOOKUP_LEVEL *level, prs_struct *ps, int depth)
67 {
68         if (level == NULL) return;
69
70         prs_debug(ps, depth, desc, "smb_io_lookup_level");
71         depth++;
72
73         prs_align(ps);
74         prs_uint16("value", ps, depth, &(level->value));
75         prs_align(ps);
76 }
77
78 /*******************************************************************
79 gets an enumeration handle from an ENUM_HND structure.
80 ********************************************************************/
81 uint32 get_enum_hnd(ENUM_HND *enh)
82 {
83         return (enh && enh->ptr_hnd != 0) ? enh->handle : 0;
84 }
85
86 /*******************************************************************
87 makes an ENUM_HND structure.
88 ********************************************************************/
89 void make_enum_hnd(ENUM_HND *enh, uint32 hnd)
90 {
91         if (enh == NULL) return;
92
93         DEBUG(5,("smb_io_enum_hnd\n"));
94
95         enh->ptr_hnd = (hnd != 0) ? 1 : 0;
96         enh->handle = hnd;
97 }
98
99 /*******************************************************************
100 reads or writes an ENUM_HND structure.
101 ********************************************************************/
102 void smb_io_enum_hnd(char *desc,  ENUM_HND *hnd, prs_struct *ps, int depth)
103 {
104         if (hnd == NULL) return;
105
106         prs_debug(ps, depth, desc, "smb_io_enum_hnd");
107         depth++;
108
109         prs_align(ps);
110         
111         prs_uint32("ptr_hnd", ps, depth, &(hnd->ptr_hnd)); /* pointer */
112         if (hnd->ptr_hnd != 0)
113         {
114                 prs_uint32("handle ", ps, depth, &(hnd->handle )); /* enum handle */
115         }
116 }
117
118 /*******************************************************************
119 reads or writes a DOM_SID structure.
120 ********************************************************************/
121 void smb_io_dom_sid(char *desc,  DOM_SID *sid, prs_struct *ps, int depth)
122 {
123         int i;
124
125         if (sid == NULL) return;
126
127         prs_debug(ps, depth, desc, "smb_io_dom_sid");
128         depth++;
129
130         prs_align(ps);
131         
132         prs_uint8 ("sid_rev_num", ps, depth, &(sid->sid_rev_num)); 
133         prs_uint8 ("num_auths  ", ps, depth, &(sid->num_auths));
134
135         for (i = 0; i < 6; i++)
136         {
137                 fstring tmp;
138                 slprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i);
139                 prs_uint8 (tmp, ps, depth, &(sid->id_auth[i]));
140         }
141
142         /* oops! XXXX should really issue a warning here... */
143         if (sid->num_auths > MAXSUBAUTHS) sid->num_auths = MAXSUBAUTHS;
144
145         prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths);
146 }
147
148 /*******************************************************************
149 creates a DOM_SID2 structure.
150 ********************************************************************/
151 void make_dom_sid2(DOM_SID2 *sid2, DOM_SID *sid)
152 {
153         sid_copy(&sid2->sid, sid);
154         sid2->num_auths = sid2->sid.num_auths;
155 }
156
157 /*******************************************************************
158 reads or writes a DOM_SID2 structure.
159 ********************************************************************/
160 void smb_io_dom_sid2(char *desc,  DOM_SID2 *sid, prs_struct *ps, int depth)
161 {
162         if (sid == NULL) return;
163
164         prs_debug(ps, depth, desc, "smb_io_dom_sid2");
165         depth++;
166
167         prs_align(ps);
168         
169         prs_uint32("num_auths", ps, depth, &(sid->num_auths));
170
171         smb_io_dom_sid("sid", &(sid->sid), ps, depth);
172 }
173
174 /*******************************************************************
175 creates a STRHDR structure.
176 ********************************************************************/
177 void make_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer)
178 {
179         hdr->str_max_len = max_len;
180         hdr->str_str_len = len;
181         hdr->buffer      = buffer;
182 }
183
184 /*******************************************************************
185 reads or writes a STRHDR structure.
186 ********************************************************************/
187 void smb_io_strhdr(char *desc,  STRHDR *hdr, prs_struct *ps, int depth)
188 {
189         if (hdr == NULL) return;
190
191         prs_debug(ps, depth, desc, "smb_io_strhdr");
192         depth++;
193
194         prs_align(ps);
195         
196         prs_uint16("str_str_len", ps, depth, &(hdr->str_str_len));
197         prs_uint16("str_max_len", ps, depth, &(hdr->str_max_len));
198         prs_uint32("buffer     ", ps, depth, &(hdr->buffer     ));
199
200         /* oops! XXXX maybe issue a warning that this is happening... */
201         if (hdr->str_max_len > MAX_STRINGLEN) hdr->str_max_len = MAX_STRINGLEN;
202         if (hdr->str_str_len > MAX_STRINGLEN) hdr->str_str_len = MAX_STRINGLEN;
203 }
204
205 /*******************************************************************
206 creates a UNIHDR structure.
207 ********************************************************************/
208 void make_uni_hdr(UNIHDR *hdr, int max_len, int len, uint32 buffer)
209 {
210         hdr->uni_str_len = 2 * len;
211         hdr->uni_max_len = 2 * max_len;
212         hdr->buffer      = buffer;
213 }
214
215 /*******************************************************************
216 reads or writes a UNIHDR structure.
217 ********************************************************************/
218 void smb_io_unihdr(char *desc,  UNIHDR *hdr, prs_struct *ps, int depth)
219 {
220         if (hdr == NULL) return;
221
222         prs_debug(ps, depth, desc, "smb_io_unihdr");
223         depth++;
224
225         prs_align(ps);
226         
227         prs_uint16("uni_str_len", ps, depth, &(hdr->uni_str_len));
228         prs_uint16("uni_max_len", ps, depth, &(hdr->uni_max_len));
229         prs_uint32("buffer     ", ps, depth, &(hdr->buffer     ));
230
231         /* oops! XXXX maybe issue a warning that this is happening... */
232         if (hdr->uni_max_len > MAX_UNISTRLEN) hdr->uni_max_len = MAX_UNISTRLEN;
233         if (hdr->uni_str_len > MAX_UNISTRLEN) hdr->uni_str_len = MAX_UNISTRLEN;
234 }
235
236 /*******************************************************************
237 creates a BUFHDR structure.
238 ********************************************************************/
239 void make_buf_hdr(BUFHDR *hdr, int max_len, int len)
240 {
241         hdr->buf_max_len = max_len;
242         hdr->buf_len     = len;
243 }
244
245 /*******************************************************************
246  prs_uint16 wrapper.  call this and it sets up a pointer to where the
247  uint16 should be stored, or gets the size if reading
248  ********************************************************************/
249 void smb_io_hdrbuf_pre(char *desc,  BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset)
250 {
251         (*offset) = ps->offset;
252         if (ps->io)
253         {
254                 /* reading. */
255                 smb_io_hdrbuf(desc, hdr, ps, depth);
256         }
257         else
258         {
259                 ps->offset += sizeof(uint32) * 2;
260         }
261 }
262
263 /*******************************************************************
264  smb_io_hdrbuf wrapper.  call this and it retrospectively stores the size.
265  does nothing on reading, as that is already handled by ...._pre()
266  ********************************************************************/
267 void smb_io_hdrbuf_post(char *desc,  BUFHDR *hdr, prs_struct *ps, int depth, 
268                                 uint32 ptr_hdrbuf, uint32 max_len, uint32 len)
269 {
270         if (!ps->io)
271         {
272                 /* storing: go back and do a retrospective job.  i hate this */
273                 uint32 old_offset = ps->offset;
274
275                 make_buf_hdr(hdr, max_len, len);
276                 ps->offset = ptr_hdrbuf;
277                 smb_io_hdrbuf(desc, hdr, ps, depth);
278                 ps->offset = old_offset;
279         }
280 }
281 /*******************************************************************
282 reads or writes a BUFHDR structure.
283 ********************************************************************/
284 void smb_io_hdrbuf(char *desc,  BUFHDR *hdr, prs_struct *ps, int depth)
285 {
286         if (hdr == NULL) return;
287
288         prs_debug(ps, depth, desc, "smb_io_hdrbuf");
289         depth++;
290
291         prs_align(ps);
292         
293         prs_uint32("buf_max_len", ps, depth, &(hdr->buf_max_len));
294         prs_uint32("buf_len    ", ps, depth, &(hdr->buf_len    ));
295
296         /* oops! XXXX maybe issue a warning that this is happening... */
297         if (hdr->buf_max_len > MAX_BUFFERLEN) hdr->buf_max_len = MAX_BUFFERLEN;
298         if (hdr->buf_len     > MAX_BUFFERLEN) hdr->buf_len     = MAX_BUFFERLEN;
299 }
300
301 /*******************************************************************
302 creates a UNIHDR2 structure.
303 ********************************************************************/
304 void make_uni_hdr2(UNIHDR2 *hdr, int max_len, int len, uint16 terminate)
305 {
306         make_uni_hdr(&(hdr->unihdr), max_len, len, terminate);
307         hdr->buffer = len > 0 ? 1 : 0;
308 }
309
310 /*******************************************************************
311 reads or writes a UNIHDR2 structure.
312 ********************************************************************/
313 void smb_io_unihdr2(char *desc,  UNIHDR2 *hdr2, prs_struct *ps, int depth)
314 {
315         if (hdr2 == NULL) return;
316
317         prs_debug(ps, depth, desc, "smb_io_unihdr2");
318         depth++;
319
320         prs_align(ps);
321
322         smb_io_unihdr("hdr", &(hdr2->unihdr), ps, depth);
323         prs_uint32("buffer", ps, depth, &(hdr2->buffer));
324 }
325
326 /*******************************************************************
327 creates a UNISTR structure.
328 ********************************************************************/
329 void make_unistr(UNISTR *str, char *buf)
330 {
331         /* store the string (null-terminated copy) */
332         struni2(str->buffer, buf);
333 }
334
335 /*******************************************************************
336 reads or writes a UNISTR structure.
337 XXXX NOTE: UNISTR structures NEED to be null-terminated.
338 ********************************************************************/
339 void smb_io_unistr(char *desc,  UNISTR *uni, prs_struct *ps, int depth)
340 {
341         if (uni == NULL) return;
342
343         prs_debug(ps, depth, desc, "smb_io_unistr");
344         depth++;
345
346         prs_align(ps);
347         prs_unistr("unistr", ps, depth, uni);
348 }
349
350 /*******************************************************************
351 creates a BUFFER3 structure from a uint32
352 ********************************************************************/
353 void make_buffer3_uint32(BUFFER3 *str, uint32 val)
354 {
355         ZERO_STRUCTP(str);
356
357         /* set up string lengths. */
358         str->buf_max_len = sizeof(uint32);
359         str->buf_len     = sizeof(uint32);
360
361         SIVAL(str->buffer, 0, val);
362 }
363
364 /*******************************************************************
365 creates a BUFFER3 structure.
366 ********************************************************************/
367 void make_buffer3_str(BUFFER3 *str, char *buf, int len)
368 {
369         ZERO_STRUCTP(str);
370
371         /* set up string lengths. */
372         str->buf_max_len = len * 2;
373         str->buf_len     = len * 2;
374
375         /* store the string (null-terminated 8 bit chars into 16 bit chars) */
376         struni2((uint16*)str->buffer, buf);
377 }
378
379 /*******************************************************************
380 creates a BUFFER3 structure from a hex string.
381 ********************************************************************/
382 void make_buffer3_hex(BUFFER3 *str, char *buf)
383 {
384         ZERO_STRUCTP(str);
385         str->buf_max_len = str->buf_len = strhex_to_str((char *)str->buffer, sizeof(str->buffer), buf);
386 }
387
388 /*******************************************************************
389 creates a BUFFER3 structure.
390 ********************************************************************/
391 void make_buffer3_bytes(BUFFER3 *str, uint8 *buf, int len)
392 {
393         ZERO_STRUCTP(str);
394
395         /* max buffer size (allocated size) */
396         str->buf_max_len = len;
397         if (buf != NULL)
398         {
399                 memcpy(str->buffer, buf, MIN(str->buf_len, sizeof(str->buffer)));
400         }
401         str->buf_len = buf != NULL ? len : 0;
402 }
403
404 /*******************************************************************
405 reads or writes a BUFFER3 structure.
406      the uni_max_len member tells you how large the buffer is.
407      the uni_str_len member tells you how much of the buffer is really used.
408 ********************************************************************/
409 void smb_io_buffer3(char *desc,  BUFFER3 *buf3, prs_struct *ps, int depth)
410 {
411         if (buf3 == NULL) return;
412
413         prs_debug(ps, depth, desc, "smb_io_buffer3");
414         depth++;
415
416         prs_align(ps);
417         
418         prs_uint32("uni_max_len", ps, depth, &(buf3->buf_max_len));
419         if (buf3->buf_max_len > MAX_UNISTRLEN) buf3->buf_max_len = MAX_UNISTRLEN;
420
421         prs_uint8s(True, "buffer     ", ps, depth, buf3->buffer, buf3->buf_max_len);
422
423         prs_uint32("buf_len    ", ps, depth, &(buf3->buf_len));
424         if (buf3->buf_len     > MAX_UNISTRLEN) buf3->buf_len     = MAX_UNISTRLEN;
425 }
426
427 /*******************************************************************
428 creates a BUFFER2 structure.
429 ********************************************************************/
430 void make_buffer2(BUFFER2 *str, uint8 *buf, int len)
431 {
432         ZERO_STRUCTP(str);
433
434         /* max buffer size (allocated size) */
435         str->buf_max_len = len;
436         str->undoc       = 0;
437         str->buf_len = buf != NULL ? len : 0;
438
439         if (buf != NULL)
440         {
441                 memcpy(str->buffer, buf, MIN(str->buf_len, sizeof(str->buffer)));
442         }
443 }
444
445 /*******************************************************************
446 reads or writes a BUFFER2 structure.
447      the uni_max_len member tells you how large the buffer is.
448      the uni_str_len member tells you how much of the buffer is really used.
449 ********************************************************************/
450 void smb_io_buffer2(char *desc,  BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth)
451 {
452         if (buf2 == NULL) return;
453
454         if (buffer)
455         {
456                 prs_debug(ps, depth, desc, "smb_io_buffer2");
457                 depth++;
458
459                 prs_align(ps);
460                 
461                 prs_uint32("buf_max_len", ps, depth, &(buf2->buf_max_len));
462                 prs_uint32("undoc      ", ps, depth, &(buf2->undoc      ));
463                 prs_uint32("buf_len    ", ps, depth, &(buf2->buf_len));
464
465                 /* oops! XXXX maybe issue a warning that this is happening... */
466                 if (buf2->buf_max_len > MAX_UNISTRLEN) buf2->buf_max_len = MAX_UNISTRLEN;
467                 if (buf2->buf_len     > MAX_UNISTRLEN) buf2->buf_len     = MAX_UNISTRLEN;
468
469                 /* buffer advanced by indicated length of string
470                    NOT by searching for null-termination */
471                 prs_buffer2(True, "buffer     ", ps, depth, buf2);
472         }
473         else
474         {
475                 prs_debug(ps, depth, desc, "smb_io_buffer2 - NULL");
476                 depth++;
477                 bzero(buf2, sizeof(*buf2));
478         }
479 }
480
481 /*******************************************************************
482 creates a UNISTR2 structure: sets up the buffer, too
483 ********************************************************************/
484 void make_buf_unistr2(UNISTR2 *str, uint32 *ptr, char *buf)
485 {
486         if (buf != NULL)
487         {
488                 *ptr = 1;
489                 make_unistr2(str, buf, strlen(buf)+1);
490         }
491         else
492         {
493                 *ptr = 0;
494                 make_unistr2(str, "", 0);
495         }
496 }
497
498 /*******************************************************************
499 copies a UNISTR2 structure.
500 ********************************************************************/
501 void copy_unistr2(UNISTR2 *str, UNISTR2 *from)
502 {
503         /* set up string lengths. add one if string is not null-terminated */
504         str->uni_max_len = from->uni_max_len;
505         str->undoc       = from->undoc;
506         str->uni_str_len = from->uni_str_len;
507
508         /* copy the string */
509         memcpy(str->buffer, from->buffer, sizeof(from->buffer));
510 }
511
512 /*******************************************************************
513 creates a STRING2 structure.
514 ********************************************************************/
515 void make_string2(STRING2 *str, char *buf, int len)
516 {
517   /* set up string lengths. */
518   str->str_max_len = len;
519   str->undoc       = 0;
520   str->str_str_len = len;
521
522   /* store the string */
523   if(len != 0)
524     memcpy(str->buffer, buf, len);
525 }
526
527 /*******************************************************************
528 reads or writes a STRING2 structure.
529 XXXX NOTE: STRING2 structures need NOT be null-terminated.
530      the str_str_len member tells you how long the string is;
531      the str_max_len member tells you how large the buffer is.
532 ********************************************************************/
533 void smb_io_string2(char *desc,  STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
534 {
535         if (str2 == NULL) return;
536
537         if (buffer)
538         {
539                 prs_debug(ps, depth, desc, "smb_io_string2");
540                 depth++;
541
542                 prs_align(ps);
543                 
544                 prs_uint32("str_max_len", ps, depth, &(str2->str_max_len));
545                 prs_uint32("undoc      ", ps, depth, &(str2->undoc      ));
546                 prs_uint32("str_str_len", ps, depth, &(str2->str_str_len));
547
548                 /* oops! XXXX maybe issue a warning that this is happening... */
549                 if (str2->str_max_len > MAX_STRINGLEN) str2->str_max_len = MAX_STRINGLEN;
550                 if (str2->str_str_len > MAX_STRINGLEN) str2->str_str_len = MAX_STRINGLEN;
551
552                 /* buffer advanced by indicated length of string
553                    NOT by searching for null-termination */
554                 prs_string2(True, "buffer     ", ps, depth, str2);
555         }
556         else
557         {
558                 prs_debug(ps, depth, desc, "smb_io_string2 - NULL");
559                 depth++;
560                 bzero(str2, sizeof(*str2));
561         }
562 }
563
564 /*******************************************************************
565 creates a UNISTR2 structure.
566 ********************************************************************/
567 void make_unistr2(UNISTR2 *str, char *buf, int len)
568 {
569         ZERO_STRUCTP(str);
570
571         /* set up string lengths. */
572         str->uni_max_len = len;
573         str->undoc       = 0;
574         str->uni_str_len = len;
575
576         /* store the string (null-terminated 8 bit chars into 16 bit chars) */
577         struni2(str->buffer, buf);
578 }
579
580 /*******************************************************************
581 reads or writes a UNISTR2 structure.
582 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
583      the uni_str_len member tells you how long the string is;
584      the uni_max_len member tells you how large the buffer is.
585 ********************************************************************/
586 void smb_io_unistr2(char *desc,  UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
587 {
588         if (uni2 == NULL) return;
589
590         if (buffer)
591         {
592                 prs_debug(ps, depth, desc, "smb_io_unistr2");
593                 depth++;
594
595                 prs_align(ps);
596                 
597                 prs_uint32("uni_max_len", ps, depth, &(uni2->uni_max_len));
598                 prs_uint32("undoc      ", ps, depth, &(uni2->undoc      ));
599                 prs_uint32("uni_str_len", ps, depth, &(uni2->uni_str_len));
600
601                 /* oops! XXXX maybe issue a warning that this is happening... */
602                 if (uni2->uni_max_len > MAX_UNISTRLEN) uni2->uni_max_len = MAX_UNISTRLEN;
603                 if (uni2->uni_str_len > MAX_UNISTRLEN) uni2->uni_str_len = MAX_UNISTRLEN;
604
605                 /* buffer advanced by indicated length of string
606                    NOT by searching for null-termination */
607                 prs_unistr2(True, "buffer     ", ps, depth, uni2);
608         }
609         else
610         {
611                 prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");
612                 depth++;
613                 bzero(uni2, sizeof(*uni2));
614         }
615 }
616
617 /*******************************************************************
618 creates a DOM_RID2 structure.
619 ********************************************************************/
620 void make_dom_rid2(DOM_RID2 *rid2, uint32 rid, uint8 type, uint32 idx)
621 {
622         rid2->type    = type;
623         rid2->rid     = rid;
624         rid2->rid_idx = idx;
625 }
626
627 /*******************************************************************
628 reads or writes a DOM_RID2 structure.
629 ********************************************************************/
630 void smb_io_dom_rid2(char *desc,  DOM_RID2 *rid2, prs_struct *ps, int depth)
631 {
632         if (rid2 == NULL) return;
633
634         prs_debug(ps, depth, desc, "smb_io_dom_rid2");
635         depth++;
636
637         prs_align(ps);
638         
639         prs_uint8("type   ", ps, depth, &(rid2->type));
640         prs_align(ps);
641         prs_uint32("rid    ", ps, depth, &(rid2->rid     ));
642         prs_uint32("rid_idx", ps, depth, &(rid2->rid_idx ));
643 }
644
645 /*******************************************************************
646 creates a DOM_RID3 structure.
647 ********************************************************************/
648 void make_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type)
649 {
650         rid3->rid      = rid;
651         rid3->type1    = type;
652         rid3->ptr_type = 0x1; /* non-zero, basically. */
653         rid3->type2    = 0x1;
654         rid3->unk      = type;
655 }
656
657 /*******************************************************************
658 reads or writes a DOM_RID3 structure.
659 ********************************************************************/
660 void smb_io_dom_rid3(char *desc,  DOM_RID3 *rid3, prs_struct *ps, int depth)
661 {
662         if (rid3 == NULL) return;
663
664         prs_debug(ps, depth, desc, "smb_io_dom_rid3");
665         depth++;
666
667         prs_align(ps);
668         
669         prs_uint32("rid     ", ps, depth, &(rid3->rid     ));
670         prs_uint32("type1   ", ps, depth, &(rid3->type1   ));
671         prs_uint32("ptr_type", ps, depth, &(rid3->ptr_type));
672         prs_uint32("type2   ", ps, depth, &(rid3->type2   ));
673         prs_uint32("unk     ", ps, depth, &(rid3->unk     ));
674 }
675
676 /*******************************************************************
677 creates a DOM_RID4 structure.
678 ********************************************************************/
679 void make_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
680 {
681         rid4->unknown = unknown;
682         rid4->attr    = attr;
683         rid4->rid     = rid;
684 }
685
686 /*******************************************************************
687 makes a DOM_CLNT_SRV structure.
688 ********************************************************************/
689 static void make_clnt_srv(DOM_CLNT_SRV *log, char *logon_srv, char *comp_name)
690 {
691         if (log == NULL) return;
692
693         DEBUG(5,("make_clnt_srv: %d\n", __LINE__));
694
695         if (logon_srv != NULL)
696         {
697                 log->undoc_buffer = 1;
698                 make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv)+1);
699         }
700         else
701         {
702                 log->undoc_buffer = 0;
703         }
704
705         if (comp_name != NULL)
706         {
707                 log->undoc_buffer2 = 1;
708                 make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name)+1);
709         }
710         else
711         {
712                 log->undoc_buffer2 = 0;
713         }
714 }
715
716 /*******************************************************************
717 reads or writes a DOM_CLNT_SRV structure.
718 ********************************************************************/
719 static void smb_io_clnt_srv(char *desc,  DOM_CLNT_SRV *log, prs_struct *ps, int depth)
720 {
721         if (log == NULL) return;
722
723         prs_debug(ps, depth, desc, "smb_io_clnt_srv");
724         depth++;
725
726         prs_align(ps);
727         
728         prs_uint32("undoc_buffer ", ps, depth, &(log->undoc_buffer ));
729         if (log->undoc_buffer != 0)
730         {
731                 smb_io_unistr2("unistr2", &(log->uni_logon_srv), log->undoc_buffer, ps, depth);
732         }
733
734         prs_align(ps);
735
736         prs_uint32("undoc_buffer2", ps, depth, &(log->undoc_buffer2));
737         if (log->undoc_buffer2 != 0)
738         {
739                 smb_io_unistr2("unistr2", &(log->uni_comp_name), log->undoc_buffer2, ps, depth);
740         }
741 }
742
743 /*******************************************************************
744 makes a DOM_LOG_INFO structure.
745 ********************************************************************/
746 void make_log_info(DOM_LOG_INFO *log, char *logon_srv, char *acct_name,
747                 uint16 sec_chan, char *comp_name)
748 {
749         if (log == NULL) return;
750
751         DEBUG(5,("make_log_info %d\n", __LINE__));
752
753         log->undoc_buffer = 1;
754
755         make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv)+1);
756         make_unistr2(&(log->uni_acct_name), acct_name, strlen(acct_name)+1);
757
758         log->sec_chan = sec_chan;
759
760         make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name)+1);
761 }
762
763 /*******************************************************************
764 reads or writes a DOM_LOG_INFO structure.
765 ********************************************************************/
766 void smb_io_log_info(char *desc,  DOM_LOG_INFO *log, prs_struct *ps, int depth)
767 {
768         if (log == NULL) return;
769
770         prs_debug(ps, depth, desc, "smb_io_log_info");
771         depth++;
772
773         prs_align(ps);
774         
775         prs_uint32("undoc_buffer", ps, depth, &(log->undoc_buffer));
776
777         smb_io_unistr2("unistr2", &(log->uni_logon_srv), True, ps, depth);
778         smb_io_unistr2("unistr2", &(log->uni_acct_name), True, ps, depth);
779
780         prs_uint16("sec_chan", ps, depth, &(log->sec_chan));
781
782         smb_io_unistr2("unistr2", &(log->uni_comp_name), True, ps, depth);
783 }
784
785 /*******************************************************************
786 reads or writes a DOM_CHAL structure.
787 ********************************************************************/
788 void smb_io_chal(char *desc,  DOM_CHAL *chal, prs_struct *ps, int depth)
789 {
790         if (chal == NULL) return;
791
792         prs_debug(ps, depth, desc, "smb_io_chal");
793         depth++;
794
795         prs_align(ps);
796         
797         prs_uint8s (False, "data", ps, depth, chal->data, 8);
798 }
799
800 /*******************************************************************
801 reads or writes a DOM_CRED structure.
802 ********************************************************************/
803 void smb_io_cred(char *desc,  DOM_CRED *cred, prs_struct *ps, int depth)
804 {
805         if (cred == NULL) return;
806
807         prs_debug(ps, depth, desc, "smb_io_cred");
808         depth++;
809
810         prs_align(ps);
811         
812         smb_io_chal ("", &(cred->challenge), ps, depth);
813         smb_io_utime("", &(cred->timestamp), ps, depth);
814 }
815
816 /*******************************************************************
817 makes a DOM_CLNT_INFO2 structure.
818 ********************************************************************/
819 void make_clnt_info2(DOM_CLNT_INFO2 *clnt,
820                                 char *logon_srv, char *comp_name,
821                                 DOM_CRED *clnt_cred)
822 {
823         if (clnt == NULL) return;
824
825         DEBUG(5,("make_clnt_info: %d\n", __LINE__));
826
827         make_clnt_srv(&(clnt->login), logon_srv, comp_name);
828
829         if (clnt_cred != NULL)
830         {
831                 clnt->ptr_cred = 1;
832                 memcpy(&(clnt->cred), clnt_cred, sizeof(clnt->cred));
833         }
834         else
835         {
836                 clnt->ptr_cred = 0;
837         }
838 }
839
840 /*******************************************************************
841 reads or writes a DOM_CLNT_INFO2 structure.
842 ********************************************************************/
843 void smb_io_clnt_info2(char *desc,  DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
844 {
845         if (clnt == NULL) return;
846
847         prs_debug(ps, depth, desc, "smb_io_clnt_info2");
848         depth++;
849
850         prs_align(ps);
851         
852         smb_io_clnt_srv("", &(clnt->login), ps, depth);
853
854         prs_align(ps);
855         
856         prs_uint32("ptr_cred", ps, depth, &(clnt->ptr_cred));
857         smb_io_cred    ("", &(clnt->cred ), ps, depth);
858 }
859
860 /*******************************************************************
861 makes a DOM_CLNT_INFO structure.
862 ********************************************************************/
863 void make_clnt_info(DOM_CLNT_INFO *clnt,
864                 char *logon_srv, char *acct_name,
865                 uint16 sec_chan, char *comp_name,
866                                 DOM_CRED *cred)
867 {
868         if (clnt == NULL || cred == NULL) return;
869
870         DEBUG(5,("make_clnt_info\n"));
871
872         make_log_info(&(clnt->login), logon_srv, acct_name, sec_chan, comp_name);
873         memcpy(&(clnt->cred), cred, sizeof(clnt->cred));
874 }
875
876 /*******************************************************************
877 reads or writes a DOM_CLNT_INFO structure.
878 ********************************************************************/
879 void smb_io_clnt_info(char *desc,  DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
880 {
881         if (clnt == NULL) return;
882
883         prs_debug(ps, depth, desc, "smb_io_clnt_info");
884         depth++;
885
886         prs_align(ps);
887         
888         smb_io_log_info("", &(clnt->login), ps, depth);
889         smb_io_cred    ("", &(clnt->cred ), ps, depth);
890 }
891
892 /*******************************************************************
893 makes a DOM_LOGON_ID structure.
894 ********************************************************************/
895 void make_logon_id(DOM_LOGON_ID *log, uint32 log_id_low, uint32 log_id_high)
896 {
897         if (log == NULL) return;
898
899         DEBUG(5,("make_logon_id: %d\n", __LINE__));
900
901         log->low  = log_id_low;
902         log->high = log_id_high;
903 }
904
905 /*******************************************************************
906 reads or writes a DOM_LOGON_ID structure.
907 ********************************************************************/
908 void smb_io_logon_id(char *desc,  DOM_LOGON_ID *log, prs_struct *ps, int depth)
909 {
910         if (log == NULL) return;
911
912         prs_debug(ps, depth, desc, "smb_io_logon_id");
913         depth++;
914
915         prs_align(ps);
916         
917         prs_uint32("low ", ps, depth, &(log->low ));
918         prs_uint32("high", ps, depth, &(log->high));
919 }
920
921 /*******************************************************************
922 makes an OWF_INFO structure.
923 ********************************************************************/
924 void make_owf_info(OWF_INFO *hash, uint8 data[16])
925 {
926         if (hash == NULL) return;
927
928         DEBUG(5,("make_owf_info: %d\n", __LINE__));
929         
930         if (data != NULL)
931         {
932                 memcpy(hash->data, data, sizeof(hash->data));
933         }
934         else
935         {
936                 bzero(hash->data, sizeof(hash->data));
937         }
938 }
939
940 /*******************************************************************
941 reads or writes an OWF_INFO structure.
942 ********************************************************************/
943 void smb_io_owf_info(char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
944 {
945         if (hash == NULL) return;
946
947         prs_debug(ps, depth, desc, "smb_io_owf_info");
948         depth++;
949
950         prs_align(ps);
951         
952         prs_uint8s (False, "data", ps, depth, hash->data, 16);
953 }
954
955 /*******************************************************************
956 reads or writes a DOM_GID structure.
957 ********************************************************************/
958 void smb_io_gid(char *desc,  DOM_GID *gid, prs_struct *ps, int depth)
959 {
960         if (gid == NULL) return;
961
962         prs_debug(ps, depth, desc, "smb_io_gid");
963         depth++;
964
965         prs_align(ps);
966         
967         prs_uint32("g_rid", ps, depth, &(gid->g_rid));
968         prs_uint32("attr ", ps, depth, &(gid->attr ));
969 }
970
971 /*******************************************************************
972 reads or writes an POLICY_HND structure.
973 ********************************************************************/
974 void smb_io_pol_hnd(char *desc,  POLICY_HND *pol, prs_struct *ps, int depth)
975 {
976         if (pol == NULL) return;
977
978         prs_debug(ps, depth, desc, "smb_io_pol_hnd");
979         depth++;
980
981         prs_align(ps);
982         
983         prs_uint8s (False, "data", ps, depth, pol->data, POL_HND_SIZE);
984 }
985
986 /*******************************************************************
987 reads or writes a dom query structure.
988 ********************************************************************/
989 static void smb_io_dom_query(char *desc,  DOM_QUERY *d_q, prs_struct *ps, int depth)
990 {
991         if (d_q == NULL) return;
992
993         prs_debug(ps, depth, desc, "smb_io_dom_query");
994         depth++;
995
996         prs_align(ps);
997         
998         prs_uint16("uni_dom_max_len", ps, depth, &(d_q->uni_dom_max_len)); /* domain name string length * 2 */
999         prs_uint16("uni_dom_str_len", ps, depth, &(d_q->uni_dom_str_len)); /* domain name string length * 2 */
1000
1001         prs_uint32("buffer_dom_name", ps, depth, &(d_q->buffer_dom_name)); /* undocumented domain name string buffer pointer */
1002         prs_uint32("buffer_dom_sid ", ps, depth, &(d_q->buffer_dom_sid )); /* undocumented domain SID string buffer pointer */
1003
1004         smb_io_unistr2("unistr2", &(d_q->uni_domain_name), d_q->buffer_dom_name, ps, depth); /* domain name (unicode string) */
1005
1006         if (d_q->buffer_dom_sid != 0)
1007         {
1008                 smb_io_dom_sid2("", &(d_q->dom_sid), ps, depth); /* domain SID */
1009         }
1010         else
1011         {
1012                 bzero(&(d_q->dom_sid), sizeof(d_q->dom_sid));
1013         }
1014 }
1015
1016 /*******************************************************************
1017 reads or writes a dom query structure.
1018 ********************************************************************/
1019 void smb_io_dom_query_3(char *desc,  DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
1020 {
1021         smb_io_dom_query("", d_q, ps, depth);
1022 }
1023
1024 /*******************************************************************
1025 reads or writes a dom query structure.
1026 ********************************************************************/
1027 void smb_io_dom_query_5(char *desc,  DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
1028 {
1029         smb_io_dom_query("", d_q, ps, depth);
1030 }
1031
1032
1033 /*******************************************************************
1034 reads or writes a UNISTR3 structure.
1035 ********************************************************************/
1036 void smb_io_unistr3(char *desc,  UNISTR3 *name, prs_struct *ps, int depth)
1037 {
1038         if (name == NULL) return;
1039
1040         prs_debug(ps, depth, desc, "smb_io_unistr3");
1041         depth++;
1042
1043         prs_align(ps);
1044         
1045         prs_uint32("uni_str_len", ps, depth, &(name->uni_str_len));
1046
1047         /* don't know if len is specified by uni_str_len member... */
1048         /* assume unicode string is unicode-null-terminated, instead */
1049
1050         prs_unistr3(True, "unistr", name, ps, depth);
1051 }
1052
1053