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