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