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