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