Added clear-out-structure fix for make_unistr2.
[bbaumbach/samba-autobuild/.git] / source / rpc_parse / parse_misc.c
1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
5  *  RPC Pipe client / server routines
6  *  Copyright (C) Andrew Tridgell              1992-1997,
7  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8  *  Copyright (C) Paul Ashton                       1997.
9  *  
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25
26 #include "includes.h"
27
28 extern int DEBUGLEVEL;
29
30
31
32 /*******************************************************************
33 reads or writes a UTIME type.
34 ********************************************************************/
35 static void smb_io_utime(char *desc,  UTIME *t, prs_struct *ps, int depth)
36 {
37         if (t == NULL) return;
38
39         prs_debug(ps, depth, desc, "smb_io_utime");
40         depth++;
41
42         prs_align(ps);
43         
44         prs_uint32 ("time", ps, depth, &(t->time));
45 }
46
47 /*******************************************************************
48 reads or writes an NTTIME structure.
49 ********************************************************************/
50 void smb_io_time(char *desc,  NTTIME *nttime, prs_struct *ps, int depth)
51 {
52         if (nttime == NULL) return;
53
54         prs_debug(ps, depth, desc, "smb_io_time");
55         depth++;
56
57         prs_align(ps);
58         
59         prs_uint32("low ", ps, depth, &(nttime->low )); /* low part */
60         prs_uint32("high", ps, depth, &(nttime->high)); /* high part */
61 }
62
63 /*******************************************************************
64 reads or writes a LOOKUP_LEVEL structure.
65 ********************************************************************/
66 void smb_io_lookup_level(char *desc, LOOKUP_LEVEL *level, prs_struct *ps, int depth)
67 {
68         if (level == NULL) return;
69
70         prs_debug(ps, depth, desc, "smb_io_lookup_level");
71         depth++;
72
73         prs_align(ps);
74         prs_uint16("value", ps, depth, &(level->value));
75         prs_align(ps);
76 }
77
78 /*******************************************************************
79 gets an enumeration handle from an ENUM_HND structure.
80 ********************************************************************/
81 uint32 get_enum_hnd(ENUM_HND *enh)
82 {
83         return (enh && enh->ptr_hnd != 0) ? enh->handle : 0;
84 }
85
86 /*******************************************************************
87 makes an ENUM_HND structure.
88 ********************************************************************/
89 void make_enum_hnd(ENUM_HND *enh, uint32 hnd)
90 {
91         if (enh == NULL) return;
92
93         DEBUG(5,("smb_io_enum_hnd\n"));
94
95         enh->ptr_hnd = (hnd != 0) ? 1 : 0;
96         enh->handle = hnd;
97 }
98
99 /*******************************************************************
100 reads or writes an ENUM_HND structure.
101 ********************************************************************/
102 void smb_io_enum_hnd(char *desc,  ENUM_HND *hnd, prs_struct *ps, int depth)
103 {
104         if (hnd == NULL) return;
105
106         prs_debug(ps, depth, desc, "smb_io_enum_hnd");
107         depth++;
108
109         prs_align(ps);
110         
111         prs_uint32("ptr_hnd", ps, depth, &(hnd->ptr_hnd)); /* pointer */
112         if (hnd->ptr_hnd != 0)
113         {
114                 prs_uint32("handle ", ps, depth, &(hnd->handle )); /* enum handle */
115         }
116 }
117
118 /*******************************************************************
119 reads or writes a DOM_SID structure.
120 ********************************************************************/
121 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         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_max_len = 2 * max_len;
265         hdr->uni_str_len = 2 * 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 UNIHDR2 structure.
292 ********************************************************************/
293 void make_uni_hdr2(UNIHDR2 *hdr, int max_len, int len, uint16 terminate)
294 {
295         make_uni_hdr(&(hdr->unihdr), max_len, len, terminate);
296         hdr->buffer = len > 0 ? 1 : 0;
297 }
298
299 /*******************************************************************
300 reads or writes a UNIHDR2 structure.
301 ********************************************************************/
302 void smb_io_unihdr2(char *desc,  UNIHDR2 *hdr2, prs_struct *ps, int depth)
303 {
304         if (hdr2 == NULL) return;
305
306         prs_debug(ps, depth, desc, "smb_io_unihdr2");
307         depth++;
308
309         prs_align(ps);
310
311         smb_io_unihdr("hdr", &(hdr2->unihdr), ps, depth);
312         prs_uint32("buffer", ps, depth, &(hdr2->buffer));
313 }
314
315 /*******************************************************************
316 creates a UNISTR structure.
317 ********************************************************************/
318 void make_unistr(UNISTR *str, char *buf)
319 {
320         /* store the string (null-terminated copy) */
321         struni2(str->buffer, buf);
322 }
323
324 /*******************************************************************
325 reads or writes a UNISTR structure.
326 XXXX NOTE: UNISTR structures NEED to be null-terminated.
327 ********************************************************************/
328 void smb_io_unistr(char *desc,  UNISTR *uni, prs_struct *ps, int depth)
329 {
330         if (uni == NULL) return;
331
332         prs_debug(ps, depth, desc, "smb_io_unistr");
333         depth++;
334
335         prs_align(ps);
336         prs_unistr("unistr", ps, depth, uni);
337 }
338
339 /*******************************************************************
340 creates a UNINOTSTR2 structure.
341 ********************************************************************/
342 void make_uninotstr2(UNINOTSTR2 *str, char *buf, int len)
343 {
344         /* set up string lengths. add one if string is not null-terminated */
345         str->uni_max_len = (len+1)*2;
346         str->undoc       = 0;
347         str->uni_buf_len = (len+1)*2;
348
349         /* store the string (null-terminated copy) */
350         struni2(str->buffer, buf);
351 }
352
353 /*******************************************************************
354 reads or writes a UNINOTSTR2 structure.
355 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
356      the uni_str_len member tells you how long the string is;
357      the uni_max_len member tells you how large the buffer is.
358 ********************************************************************/
359 void smb_io_uninotstr2(char *desc,  UNINOTSTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
360 {
361         if (uni2 == NULL) return;
362
363         if (buffer)
364         {
365                 prs_debug(ps, depth, desc, "smb_io_uninotstr2");
366                 depth++;
367
368                 prs_align(ps);
369                 
370                 prs_uint32("uni_max_len", ps, depth, &(uni2->uni_max_len));
371                 prs_uint32("undoc      ", ps, depth, &(uni2->undoc      ));
372                 prs_uint32("uni_buf_len", ps, depth, &(uni2->uni_buf_len));
373
374                 /* oops! XXXX maybe issue a warning that this is happening... */
375                 if (uni2->uni_max_len > MAX_UNISTRLEN) uni2->uni_max_len = MAX_UNISTRLEN;
376                 if (uni2->uni_buf_len > MAX_UNISTRLEN) uni2->uni_buf_len = MAX_UNISTRLEN;
377
378                 /* buffer advanced by indicated length of string
379                    NOT by searching for null-termination */
380                 prs_uninotstr2(True, "buffer     ", ps, depth, uni2);
381         }
382         else
383         {
384                 prs_debug(ps, depth, desc, "smb_io_uninotstr2 - NULL");
385                 depth++;
386                 bzero(uni2, sizeof(*uni2));
387         }
388 }
389
390 /*******************************************************************
391 creates a UNISTR2 structure: sets up the buffer, too
392 ********************************************************************/
393 void make_buf_unistr2(UNISTR2 *str, uint32 *ptr, char *buf)
394 {
395         if (buf != NULL)
396         {
397                 *ptr = 1;
398                 make_unistr2(str, buf, strlen(buf)+1);
399         }
400         else
401         {
402                 *ptr = 0;
403                 make_unistr2(str, "", 0);
404         }
405 }
406
407 /*******************************************************************
408 copies a UNISTR2 structure.
409 ********************************************************************/
410 void copy_unistr2(UNISTR2 *str, UNISTR2 *from)
411 {
412         /* set up string lengths. add one if string is not null-terminated */
413         str->uni_max_len = from->uni_max_len;
414         str->undoc       = from->undoc;
415         str->uni_str_len = from->uni_str_len;
416
417         /* copy the string */
418         memcpy(str->buffer, from->buffer, sizeof(from->buffer));
419 }
420
421 /*******************************************************************
422 creates a STRING2 structure.
423 ********************************************************************/
424 void make_string2(STRING2 *str, char *buf, int len)
425 {
426   /* set up string lengths. */
427   str->str_max_len = len;
428   str->undoc       = 0;
429   str->str_str_len = len;
430
431   /* store the string */
432   if(len != 0)
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     ZERO_STRUCTP(str);
479
480         /* set up string lengths. */
481         str->uni_max_len = len;
482         str->undoc       = 0;
483         str->uni_str_len = len;
484
485         /* store the string (null-terminated 8 bit chars into 16 bit chars) */
486         struni2(str->buffer, buf);
487 }
488
489 /*******************************************************************
490 reads or writes a UNISTR2 structure.
491 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
492      the uni_str_len member tells you how long the string is;
493      the uni_max_len member tells you how large the buffer is.
494 ********************************************************************/
495 void smb_io_unistr2(char *desc,  UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
496 {
497         if (uni2 == NULL) return;
498
499         if (buffer)
500         {
501                 prs_debug(ps, depth, desc, "smb_io_unistr2");
502                 depth++;
503
504                 prs_align(ps);
505                 
506                 prs_uint32("uni_max_len", ps, depth, &(uni2->uni_max_len));
507                 prs_uint32("undoc      ", ps, depth, &(uni2->undoc      ));
508                 prs_uint32("uni_str_len", ps, depth, &(uni2->uni_str_len));
509
510                 /* oops! XXXX maybe issue a warning that this is happening... */
511                 if (uni2->uni_max_len > MAX_UNISTRLEN) uni2->uni_max_len = MAX_UNISTRLEN;
512                 if (uni2->uni_str_len > MAX_UNISTRLEN) uni2->uni_str_len = MAX_UNISTRLEN;
513
514                 /* buffer advanced by indicated length of string
515                    NOT by searching for null-termination */
516                 prs_unistr2(True, "buffer     ", ps, depth, uni2);
517         }
518         else
519         {
520                 prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");
521                 depth++;
522                 bzero(uni2, sizeof(*uni2));
523         }
524 }
525
526 /*******************************************************************
527 creates a DOM_RID2 structure.
528 ********************************************************************/
529 void make_dom_rid2(DOM_RID2 *rid2, uint32 rid)
530 {
531         rid2->type    = 0x5;
532         rid2->undoc   = 0x5;
533         rid2->rid     = rid;
534         rid2->rid_idx = 0;
535 }
536
537 /*******************************************************************
538 reads or writes a DOM_RID2 structure.
539 ********************************************************************/
540 void smb_io_dom_rid2(char *desc,  DOM_RID2 *rid2, prs_struct *ps, int depth)
541 {
542         if (rid2 == NULL) return;
543
544         prs_debug(ps, depth, desc, "smb_io_dom_rid2");
545         depth++;
546
547         prs_align(ps);
548         
549         /* should be value 5, so enforce it */
550         rid2->type = 5;
551
552         /* should be value 5, so enforce it */
553         rid2->undoc = 5;
554
555         prs_uint32("type   ", ps, depth, &(rid2->type));
556         prs_uint32("undoc  ", ps, depth, &(rid2->undoc   ));
557         prs_uint32("rid    ", ps, depth, &(rid2->rid     ));
558         prs_uint32("rid_idx", ps, depth, &(rid2->rid_idx ));
559 }
560
561 /*******************************************************************
562 creates a DOM_RID3 structure.
563 ********************************************************************/
564 void make_dom_rid3(DOM_RID3 *rid3, uint32 rid)
565 {
566         rid3->rid      = rid;
567         rid3->type1    = 0x1;
568         rid3->ptr_type = 0x1; /* non-zero, basically. */
569         rid3->type2    = 0x1;
570 }
571
572 /*******************************************************************
573 reads or writes a DOM_RID3 structure.
574 ********************************************************************/
575 void smb_io_dom_rid3(char *desc,  DOM_RID3 *rid3, prs_struct *ps, int depth)
576 {
577         if (rid3 == NULL) return;
578
579         prs_debug(ps, depth, desc, "smb_io_dom_rid3");
580         depth++;
581
582         prs_align(ps);
583         
584         prs_uint32("rid     ", ps, depth, &(rid3->rid     ));
585         prs_uint32("type1   ", ps, depth, &(rid3->type1   ));
586         prs_uint32("ptr_type", ps, depth, &(rid3->ptr_type));
587         prs_uint32("type2   ", ps, depth, &(rid3->type2   ));
588 }
589
590 /*******************************************************************
591 creates a DOM_RID4 structure.
592 ********************************************************************/
593 void make_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
594 {
595         rid4->unknown = unknown;
596         rid4->attr    = attr;
597         rid4->rid     = rid;
598 }
599
600
601 /*******************************************************************
602 makes a DOM_CLNT_SRV structure.
603 ********************************************************************/
604 static void make_clnt_srv(DOM_CLNT_SRV *log, char *logon_srv, char *comp_name)
605 {
606         if (log == NULL) return;
607
608         DEBUG(5,("make_clnt_srv: %d\n", __LINE__));
609
610         if (logon_srv != NULL)
611         {
612                 log->undoc_buffer = 1;
613                 make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv)+1);
614         }
615         else
616         {
617                 log->undoc_buffer = 0;
618         }
619
620         if (comp_name != NULL)
621         {
622                 log->undoc_buffer2 = 1;
623                 make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name)+1);
624         }
625         else
626         {
627                 log->undoc_buffer2 = 0;
628         }
629 }
630
631 /*******************************************************************
632 reads or writes a DOM_CLNT_SRV structure.
633 ********************************************************************/
634 static void smb_io_clnt_srv(char *desc,  DOM_CLNT_SRV *log, prs_struct *ps, int depth)
635 {
636         if (log == NULL) return;
637
638         prs_debug(ps, depth, desc, "smb_io_clnt_srv");
639         depth++;
640
641         prs_align(ps);
642         
643         prs_uint32("undoc_buffer ", ps, depth, &(log->undoc_buffer ));
644         if (log->undoc_buffer != 0)
645         {
646                 smb_io_unistr2("unistr2", &(log->uni_logon_srv), log->undoc_buffer, ps, depth);
647         }
648
649         prs_align(ps);
650
651         prs_uint32("undoc_buffer2", ps, depth, &(log->undoc_buffer2));
652         if (log->undoc_buffer2 != 0)
653         {
654                 smb_io_unistr2("unistr2", &(log->uni_comp_name), log->undoc_buffer2, ps, depth);
655         }
656 }
657
658 /*******************************************************************
659 makes a DOM_LOG_INFO structure.
660 ********************************************************************/
661 void make_log_info(DOM_LOG_INFO *log, char *logon_srv, char *acct_name,
662                 uint16 sec_chan, char *comp_name)
663 {
664         if (log == NULL) return;
665
666         DEBUG(5,("make_log_info %d\n", __LINE__));
667
668         log->undoc_buffer = 1;
669
670         make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv)+1);
671         make_unistr2(&(log->uni_acct_name), acct_name, strlen(acct_name)+1);
672
673         log->sec_chan = sec_chan;
674
675         make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name)+1);
676 }
677
678 /*******************************************************************
679 reads or writes a DOM_LOG_INFO structure.
680 ********************************************************************/
681 void smb_io_log_info(char *desc,  DOM_LOG_INFO *log, prs_struct *ps, int depth)
682 {
683         if (log == NULL) return;
684
685         prs_debug(ps, depth, desc, "smb_io_log_info");
686         depth++;
687
688         prs_align(ps);
689         
690         prs_uint32("undoc_buffer", ps, depth, &(log->undoc_buffer));
691
692         smb_io_unistr2("unistr2", &(log->uni_logon_srv), True, ps, depth);
693         smb_io_unistr2("unistr2", &(log->uni_acct_name), True, ps, depth);
694
695         prs_uint16("sec_chan", ps, depth, &(log->sec_chan));
696
697         smb_io_unistr2("unistr2", &(log->uni_comp_name), True, ps, depth);
698 }
699
700 /*******************************************************************
701 reads or writes a DOM_CHAL structure.
702 ********************************************************************/
703 void smb_io_chal(char *desc,  DOM_CHAL *chal, prs_struct *ps, int depth)
704 {
705         if (chal == NULL) return;
706
707         prs_debug(ps, depth, desc, "smb_io_chal");
708         depth++;
709
710         prs_align(ps);
711         
712         prs_uint8s (False, "data", ps, depth, chal->data, 8);
713 }
714
715 /*******************************************************************
716 reads or writes a DOM_CRED structure.
717 ********************************************************************/
718 void smb_io_cred(char *desc,  DOM_CRED *cred, prs_struct *ps, int depth)
719 {
720         if (cred == NULL) return;
721
722         prs_debug(ps, depth, desc, "smb_io_cred");
723         depth++;
724
725         prs_align(ps);
726         
727         smb_io_chal ("", &(cred->challenge), ps, depth);
728         smb_io_utime("", &(cred->timestamp), ps, depth);
729 }
730
731 /*******************************************************************
732 makes a DOM_CLNT_INFO2 structure.
733 ********************************************************************/
734 void make_clnt_info2(DOM_CLNT_INFO2 *clnt,
735                                 char *logon_srv, char *comp_name,
736                                 DOM_CRED *clnt_cred)
737 {
738         if (clnt == NULL) return;
739
740         DEBUG(5,("make_clnt_info: %d\n", __LINE__));
741
742         make_clnt_srv(&(clnt->login), logon_srv, comp_name);
743
744         if (clnt_cred != NULL)
745         {
746                 clnt->ptr_cred = 1;
747                 memcpy(&(clnt->cred), clnt_cred, sizeof(clnt->cred));
748         }
749         else
750         {
751                 clnt->ptr_cred = 0;
752         }
753 }
754
755 /*******************************************************************
756 reads or writes a DOM_CLNT_INFO2 structure.
757 ********************************************************************/
758 void smb_io_clnt_info2(char *desc,  DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
759 {
760         if (clnt == NULL) return;
761
762         prs_debug(ps, depth, desc, "smb_io_clnt_info2");
763         depth++;
764
765         prs_align(ps);
766         
767         smb_io_clnt_srv("", &(clnt->login), ps, depth);
768
769         prs_align(ps);
770         
771         prs_uint32("ptr_cred", ps, depth, &(clnt->ptr_cred));
772         smb_io_cred    ("", &(clnt->cred ), ps, depth);
773 }
774
775 /*******************************************************************
776 makes a DOM_CLNT_INFO structure.
777 ********************************************************************/
778 void make_clnt_info(DOM_CLNT_INFO *clnt,
779                 char *logon_srv, char *acct_name,
780                 uint16 sec_chan, char *comp_name,
781                                 DOM_CRED *cred)
782 {
783         if (clnt == NULL || cred == NULL) return;
784
785         DEBUG(5,("make_clnt_info\n"));
786
787         make_log_info(&(clnt->login), logon_srv, acct_name, sec_chan, comp_name);
788         memcpy(&(clnt->cred), cred, sizeof(clnt->cred));
789 }
790
791 /*******************************************************************
792 reads or writes a DOM_CLNT_INFO structure.
793 ********************************************************************/
794 void smb_io_clnt_info(char *desc,  DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
795 {
796         if (clnt == NULL) return;
797
798         prs_debug(ps, depth, desc, "smb_io_clnt_info");
799         depth++;
800
801         prs_align(ps);
802         
803         smb_io_log_info("", &(clnt->login), ps, depth);
804         smb_io_cred    ("", &(clnt->cred ), ps, depth);
805 }
806
807 /*******************************************************************
808 makes a DOM_LOGON_ID structure.
809 ********************************************************************/
810 void make_logon_id(DOM_LOGON_ID *log, uint32 log_id_low, uint32 log_id_high)
811 {
812         if (log == NULL) return;
813
814         DEBUG(5,("make_logon_id: %d\n", __LINE__));
815
816         log->low  = log_id_low;
817         log->high = log_id_high;
818 }
819
820 /*******************************************************************
821 reads or writes a DOM_LOGON_ID structure.
822 ********************************************************************/
823 void smb_io_logon_id(char *desc,  DOM_LOGON_ID *log, prs_struct *ps, int depth)
824 {
825         if (log == NULL) return;
826
827         prs_debug(ps, depth, desc, "smb_io_logon_id");
828         depth++;
829
830         prs_align(ps);
831         
832         prs_uint32("low ", ps, depth, &(log->low ));
833         prs_uint32("high", ps, depth, &(log->high));
834 }
835
836 /*******************************************************************
837 makes an OWF_INFO structure.
838 ********************************************************************/
839 void make_owf_info(OWF_INFO *hash, uint8 data[16])
840 {
841         if (hash == NULL) return;
842
843         DEBUG(5,("make_owf_info: %d\n", __LINE__));
844         
845         if (data != NULL)
846         {
847                 memcpy(hash->data, data, sizeof(hash->data));
848         }
849         else
850         {
851                 bzero(hash->data, sizeof(hash->data));
852         }
853 }
854
855 /*******************************************************************
856 reads or writes an OWF_INFO structure.
857 ********************************************************************/
858 void smb_io_owf_info(char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
859 {
860         if (hash == NULL) return;
861
862         prs_debug(ps, depth, desc, "smb_io_owf_info");
863         depth++;
864
865         prs_align(ps);
866         
867         prs_uint8s (False, "data", ps, depth, hash->data, 16);
868 }
869
870 /*******************************************************************
871 reads or writes a DOM_GID structure.
872 ********************************************************************/
873 void smb_io_gid(char *desc,  DOM_GID *gid, prs_struct *ps, int depth)
874 {
875         if (gid == NULL) return;
876
877         prs_debug(ps, depth, desc, "smb_io_gid");
878         depth++;
879
880         prs_align(ps);
881         
882         prs_uint32("g_rid", ps, depth, &(gid->g_rid));
883         prs_uint32("attr ", ps, depth, &(gid->attr ));
884 }
885
886 /*******************************************************************
887 reads or writes an POLICY_HND structure.
888 ********************************************************************/
889 void smb_io_pol_hnd(char *desc,  POLICY_HND *pol, prs_struct *ps, int depth)
890 {
891         if (pol == NULL) return;
892
893         prs_debug(ps, depth, desc, "smb_io_pol_hnd");
894         depth++;
895
896         prs_align(ps);
897         
898         prs_uint8s (False, "data", ps, depth, pol->data, POL_HND_SIZE);
899 }
900
901 /*******************************************************************
902 reads or writes a dom query structure.
903 ********************************************************************/
904 static void smb_io_dom_query(char *desc,  DOM_QUERY *d_q, prs_struct *ps, int depth)
905 {
906         if (d_q == NULL) return;
907
908         prs_debug(ps, depth, desc, "smb_io_dom_query");
909         depth++;
910
911         prs_align(ps);
912         
913         prs_uint16("uni_dom_max_len", ps, depth, &(d_q->uni_dom_max_len)); /* domain name string length * 2 */
914         prs_uint16("uni_dom_str_len", ps, depth, &(d_q->uni_dom_str_len)); /* domain name string length * 2 */
915
916         prs_uint32("buffer_dom_name", ps, depth, &(d_q->buffer_dom_name)); /* undocumented domain name string buffer pointer */
917         prs_uint32("buffer_dom_sid ", ps, depth, &(d_q->buffer_dom_sid )); /* undocumented domain SID string buffer pointer */
918
919         smb_io_unistr2("unistr2", &(d_q->uni_domain_name), d_q->buffer_dom_name, ps, depth); /* domain name (unicode string) */
920
921         if (d_q->buffer_dom_sid != 0)
922         {
923                 smb_io_dom_sid2("", &(d_q->dom_sid), ps, depth); /* domain SID */
924         }
925         else
926         {
927                 bzero(&(d_q->dom_sid), sizeof(d_q->dom_sid));
928         }
929 }
930
931 /*******************************************************************
932 reads or writes a dom query structure.
933 ********************************************************************/
934 void smb_io_dom_query_3(char *desc,  DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
935 {
936         smb_io_dom_query("", d_q, ps, depth);
937 }
938
939 /*******************************************************************
940 reads or writes a dom query structure.
941 ********************************************************************/
942 void smb_io_dom_query_5(char *desc,  DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
943 {
944         smb_io_dom_query("", d_q, ps, depth);
945 }
946
947
948 /*******************************************************************
949 reads or writes a DOM_NAME structure.
950 ********************************************************************/
951 void smb_io_dom_name(char *desc,  DOM_NAME *name, prs_struct *ps, int depth)
952 {
953         if (name == NULL) return;
954
955         prs_debug(ps, depth, desc, "smb_io_dom_name");
956         depth++;
957
958         prs_align(ps);
959         
960         prs_uint32("uni_str_len", ps, depth, &(name->uni_str_len));
961
962         /* don't know if len is specified by uni_str_len member... */
963         /* assume unicode string is unicode-null-terminated, instead */
964
965         smb_io_unistr("", &(name->str), ps, depth);
966 }
967
968