chgpasswd.c: Added comments to #ifdefs
[samba.git] / source / rpc_parse / parse_misc.c
1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
5  *  RPC Pipe client / server routines
6  *  Copyright (C) Andrew Tridgell              1992-1997,
7  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8  *  Copyright (C) Paul Ashton                       1997.
9  *  
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25
26 #include "includes.h"
27
28 extern int DEBUGLEVEL;
29
30
31
32 /*******************************************************************
33 reads or writes a UTIME type.
34 ********************************************************************/
35 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         memcpy(str->buffer, buf, len);
379 }
380
381 /*******************************************************************
382 reads or writes a STRING2 structure.
383 XXXX NOTE: STRING2 structures need NOT be null-terminated.
384      the str_str_len member tells you how long the string is;
385      the str_max_len member tells you how large the buffer is.
386 ********************************************************************/
387 void smb_io_string2(char *desc,  STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
388 {
389         if (str2 == NULL) return;
390
391         if (buffer)
392         {
393                 prs_debug(ps, depth, desc, "smb_io_string2");
394                 depth++;
395
396                 prs_align(ps);
397                 
398                 prs_uint32("str_max_len", ps, depth, &(str2->str_max_len));
399                 prs_uint32("undoc      ", ps, depth, &(str2->undoc      ));
400                 prs_uint32("str_str_len", ps, depth, &(str2->str_str_len));
401
402                 /* oops! XXXX maybe issue a warning that this is happening... */
403                 if (str2->str_max_len > MAX_STRINGLEN) str2->str_max_len = MAX_STRINGLEN;
404                 if (str2->str_str_len > MAX_STRINGLEN) str2->str_str_len = MAX_STRINGLEN;
405
406                 /* buffer advanced by indicated length of string
407                    NOT by searching for null-termination */
408                 prs_string2(True, "buffer     ", ps, depth, str2);
409         }
410         else
411         {
412                 prs_debug(ps, depth, desc, "smb_io_string2 - NULL");
413                 depth++;
414                 bzero(str2, sizeof(*str2));
415         }
416 }
417
418 /*******************************************************************
419 creates a UNISTR2 structure.
420 ********************************************************************/
421 void make_unistr2(UNISTR2 *str, char *buf, int len)
422 {
423         /* set up string lengths. add one if string is not null-terminated */
424         str->uni_max_len = len+1;
425         str->undoc       = 0;
426         str->uni_str_len = len+1;
427
428         /* store the string (null-terminated 8 bit chars into 16 bit chars) */
429         struni2(str->buffer, buf);
430 }
431
432 /*******************************************************************
433 reads or writes a UNISTR2 structure.
434 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
435      the uni_str_len member tells you how long the string is;
436      the uni_max_len member tells you how large the buffer is.
437 ********************************************************************/
438 void smb_io_unistr2(char *desc,  UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
439 {
440         if (uni2 == NULL) return;
441
442         if (buffer)
443         {
444                 prs_debug(ps, depth, desc, "smb_io_unistr2");
445                 depth++;
446
447                 prs_align(ps);
448                 
449                 prs_uint32("uni_max_len", ps, depth, &(uni2->uni_max_len));
450                 prs_uint32("undoc      ", ps, depth, &(uni2->undoc      ));
451                 prs_uint32("uni_str_len", ps, depth, &(uni2->uni_str_len));
452
453                 /* oops! XXXX maybe issue a warning that this is happening... */
454                 if (uni2->uni_max_len > MAX_UNISTRLEN) uni2->uni_max_len = MAX_UNISTRLEN;
455                 if (uni2->uni_str_len > MAX_UNISTRLEN) uni2->uni_str_len = MAX_UNISTRLEN;
456
457                 /* buffer advanced by indicated length of string
458                    NOT by searching for null-termination */
459                 prs_unistr2(True, "buffer     ", ps, depth, uni2);
460         }
461         else
462         {
463                 prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");
464                 depth++;
465                 bzero(uni2, sizeof(*uni2));
466         }
467 }
468
469 /*******************************************************************
470 creates a DOM_RID2 structure.
471 ********************************************************************/
472 void make_dom_rid2(DOM_RID2 *rid2, uint32 rid)
473 {
474         rid2->type    = 0x5;
475         rid2->undoc   = 0x5;
476         rid2->rid     = rid;
477         rid2->rid_idx = 0;
478 }
479
480 /*******************************************************************
481 reads or writes a DOM_RID2 structure.
482 ********************************************************************/
483 void smb_io_dom_rid2(char *desc,  DOM_RID2 *rid2, prs_struct *ps, int depth)
484 {
485         if (rid2 == NULL) return;
486
487         prs_debug(ps, depth, desc, "smb_io_dom_rid2");
488         depth++;
489
490         prs_align(ps);
491         
492         /* should be value 5, so enforce it */
493         rid2->type = 5;
494
495         /* should be value 5, so enforce it */
496         rid2->undoc = 5;
497
498         prs_uint32("type   ", ps, depth, &(rid2->type));
499         prs_uint32("undoc  ", ps, depth, &(rid2->undoc   ));
500         prs_uint32("rid    ", ps, depth, &(rid2->rid     ));
501         prs_uint32("rid_idx", ps, depth, &(rid2->rid_idx ));
502 }
503
504 /*******************************************************************
505 creates a DOM_RID3 structure.
506 ********************************************************************/
507 void make_dom_rid3(DOM_RID3 *rid3, uint32 rid)
508 {
509         rid3->rid      = rid;
510         rid3->type1    = 0x1;
511         rid3->ptr_type = 0x1; /* non-zero, basically. */
512         rid3->type2    = 0x1;
513 }
514
515 /*******************************************************************
516 reads or writes a DOM_RID3 structure.
517 ********************************************************************/
518 void smb_io_dom_rid3(char *desc,  DOM_RID3 *rid3, prs_struct *ps, int depth)
519 {
520         if (rid3 == NULL) return;
521
522         prs_debug(ps, depth, desc, "smb_io_dom_rid3");
523         depth++;
524
525         prs_align(ps);
526         
527         prs_uint32("rid     ", ps, depth, &(rid3->rid     ));
528         prs_uint32("type1   ", ps, depth, &(rid3->type1   ));
529         prs_uint32("ptr_type", ps, depth, &(rid3->ptr_type));
530         prs_uint32("type2   ", ps, depth, &(rid3->type2   ));
531 }
532
533 /*******************************************************************
534 creates a DOM_RID4 structure.
535 ********************************************************************/
536 void make_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
537 {
538         rid4->unknown = unknown;
539         rid4->attr    = attr;
540         rid4->rid     = rid;
541 }
542
543 /*******************************************************************
544 reads or writes a DOM_RID4 structure.
545 ********************************************************************/
546 void smb_io_dom_rid4(char *desc,  DOM_RID4 *rid4, prs_struct *ps, int depth)
547 {
548         if (rid4 == NULL) return;
549
550         prs_debug(ps, depth, desc, "smb_io_dom_rid4. XXXX !check size of unknown! XXXX");
551         depth++;
552
553         prs_align(ps);
554         
555         prs_uint32("unknown", ps, depth, &(rid4->unknown));
556         prs_uint16("attr   ", ps, depth, &(rid4->attr   ));
557         prs_uint32("rid    ", ps, depth, &(rid4->rid    ));
558 }
559
560 /*******************************************************************
561 makes a DOM_CLNT_SRV structure.
562 ********************************************************************/
563 void make_clnt_srv(DOM_CLNT_SRV *log, char *logon_srv, char *comp_name)
564 {
565         if (log == NULL) return;
566
567         DEBUG(5,("make_clnt_srv: %d\n", __LINE__));
568
569         if (logon_srv != NULL)
570         {
571                 log->undoc_buffer = 1;
572                 make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv));
573         }
574         else
575         {
576                 log->undoc_buffer = 0;
577         }
578
579         if (comp_name != NULL)
580         {
581                 log->undoc_buffer2 = 1;
582                 make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name));
583         }
584         else
585         {
586                 log->undoc_buffer2 = 0;
587         }
588 }
589
590 /*******************************************************************
591 reads or writes a DOM_CLNT_SRV structure.
592 ********************************************************************/
593 void smb_io_clnt_srv(char *desc,  DOM_CLNT_SRV *log, prs_struct *ps, int depth)
594 {
595         if (log == NULL) return;
596
597         prs_debug(ps, depth, desc, "smb_io_clnt_srv");
598         depth++;
599
600         prs_align(ps);
601         
602         prs_uint32("undoc_buffer ", ps, depth, &(log->undoc_buffer ));
603         if (log->undoc_buffer != 0)
604         {
605                 smb_io_unistr2("unistr2", &(log->uni_logon_srv), log->undoc_buffer, ps, depth);
606         }
607
608         prs_align(ps);
609
610         prs_uint32("undoc_buffer2", ps, depth, &(log->undoc_buffer2));
611         if (log->undoc_buffer2 != 0)
612         {
613                 smb_io_unistr2("unistr2", &(log->uni_comp_name), log->undoc_buffer2, ps, depth);
614         }
615 }
616
617 /*******************************************************************
618 makes a DOM_LOG_INFO structure.
619 ********************************************************************/
620 void make_log_info(DOM_LOG_INFO *log, char *logon_srv, char *acct_name,
621                 uint16 sec_chan, char *comp_name)
622 {
623         if (log == NULL) return;
624
625         DEBUG(5,("make_log_info %d\n", __LINE__));
626
627         log->undoc_buffer = 1;
628
629         make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv));
630         make_unistr2(&(log->uni_acct_name), acct_name, strlen(acct_name));
631
632         log->sec_chan = sec_chan;
633
634         make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name));
635 }
636
637 /*******************************************************************
638 reads or writes a DOM_LOG_INFO structure.
639 ********************************************************************/
640 void smb_io_log_info(char *desc,  DOM_LOG_INFO *log, prs_struct *ps, int depth)
641 {
642         if (log == NULL) return;
643
644         prs_debug(ps, depth, desc, "smb_io_log_info");
645         depth++;
646
647         prs_align(ps);
648         
649         prs_uint32("undoc_buffer", ps, depth, &(log->undoc_buffer));
650
651         smb_io_unistr2("unistr2", &(log->uni_logon_srv), True, ps, depth);
652         smb_io_unistr2("unistr2", &(log->uni_acct_name), True, ps, depth);
653
654         prs_uint16("sec_chan", ps, depth, &(log->sec_chan));
655
656         smb_io_unistr2("unistr2", &(log->uni_comp_name), True, ps, depth);
657 }
658
659 /*******************************************************************
660 reads or writes a DOM_CHAL structure.
661 ********************************************************************/
662 void smb_io_chal(char *desc,  DOM_CHAL *chal, prs_struct *ps, int depth)
663 {
664         if (chal == NULL) return;
665
666         prs_debug(ps, depth, desc, "smb_io_chal");
667         depth++;
668
669         prs_align(ps);
670         
671         prs_uint8s (False, "data", ps, depth, chal->data, 8);
672 }
673
674 /*******************************************************************
675 reads or writes a DOM_CRED structure.
676 ********************************************************************/
677 void smb_io_cred(char *desc,  DOM_CRED *cred, prs_struct *ps, int depth)
678 {
679         if (cred == NULL) return;
680
681         prs_debug(ps, depth, desc, "smb_io_cred");
682         depth++;
683
684         prs_align(ps);
685         
686         smb_io_chal ("", &(cred->challenge), ps, depth);
687         smb_io_utime("", &(cred->timestamp), ps, depth);
688 }
689
690 /*******************************************************************
691 makes a DOM_CLNT_INFO2 structure.
692 ********************************************************************/
693 void make_clnt_info2(DOM_CLNT_INFO2 *clnt,
694                                 char *logon_srv, char *comp_name,
695                                 DOM_CRED *clnt_cred)
696 {
697         if (clnt == NULL) return;
698
699         DEBUG(5,("make_clnt_info: %d\n", __LINE__));
700
701         make_clnt_srv(&(clnt->login), logon_srv, comp_name);
702
703         if (clnt_cred != NULL)
704         {
705                 clnt->ptr_cred = 1;
706                 memcpy(&(clnt->cred), clnt_cred, sizeof(clnt->cred));
707         }
708         else
709         {
710                 clnt->ptr_cred = 0;
711         }
712 }
713
714 /*******************************************************************
715 reads or writes a DOM_CLNT_INFO2 structure.
716 ********************************************************************/
717 void smb_io_clnt_info2(char *desc,  DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
718 {
719         if (clnt == NULL) return;
720
721         prs_debug(ps, depth, desc, "smb_io_clnt_info2");
722         depth++;
723
724         prs_align(ps);
725         
726         smb_io_clnt_srv("", &(clnt->login), ps, depth);
727
728         prs_align(ps);
729         
730         prs_uint32("ptr_cred", ps, depth, &(clnt->ptr_cred));
731         smb_io_cred    ("", &(clnt->cred ), ps, depth);
732 }
733
734 /*******************************************************************
735 makes a DOM_CLNT_INFO structure.
736 ********************************************************************/
737 void make_clnt_info(DOM_CLNT_INFO *clnt,
738                 char *logon_srv, char *acct_name,
739                 uint16 sec_chan, char *comp_name,
740                                 DOM_CRED *cred)
741 {
742         if (clnt == NULL || cred == NULL) return;
743
744         DEBUG(5,("make_clnt_info\n"));
745
746         make_log_info(&(clnt->login), logon_srv, acct_name, sec_chan, comp_name);
747         memcpy(&(clnt->cred), cred, sizeof(clnt->cred));
748 }
749
750 /*******************************************************************
751 reads or writes a DOM_CLNT_INFO structure.
752 ********************************************************************/
753 void smb_io_clnt_info(char *desc,  DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
754 {
755         if (clnt == NULL) return;
756
757         prs_debug(ps, depth, desc, "smb_io_clnt_info");
758         depth++;
759
760         prs_align(ps);
761         
762         smb_io_log_info("", &(clnt->login), ps, depth);
763         smb_io_cred    ("", &(clnt->cred ), ps, depth);
764 }
765
766 /*******************************************************************
767 makes a DOM_LOGON_ID structure.
768 ********************************************************************/
769 void make_logon_id(DOM_LOGON_ID *log, uint32 log_id_low, uint32 log_id_high)
770 {
771         if (log == NULL) return;
772
773         DEBUG(5,("make_logon_id: %d\n", __LINE__));
774
775         log->low  = log_id_low;
776         log->high = log_id_high;
777 }
778
779 /*******************************************************************
780 reads or writes a DOM_LOGON_ID structure.
781 ********************************************************************/
782 void smb_io_logon_id(char *desc,  DOM_LOGON_ID *log, prs_struct *ps, int depth)
783 {
784         if (log == NULL) return;
785
786         prs_debug(ps, depth, desc, "smb_io_logon_id");
787         depth++;
788
789         prs_align(ps);
790         
791         prs_uint32("low ", ps, depth, &(log->low ));
792         prs_uint32("high", ps, depth, &(log->high));
793 }
794
795 /*******************************************************************
796 makes an OWF_INFO structure.
797 ********************************************************************/
798 void make_owf_info(OWF_INFO *hash, uint8 data[16])
799 {
800         if (hash == NULL) return;
801
802         DEBUG(5,("make_owf_info: %d\n", __LINE__));
803         
804         if (data != NULL)
805         {
806                 memcpy(hash->data, data, sizeof(hash->data));
807         }
808         else
809         {
810                 bzero(hash->data, sizeof(hash->data));
811         }
812 }
813
814 /*******************************************************************
815 reads or writes an OWF_INFO structure.
816 ********************************************************************/
817 void smb_io_owf_info(char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
818 {
819         if (hash == NULL) return;
820
821         prs_debug(ps, depth, desc, "smb_io_owf_info");
822         depth++;
823
824         prs_align(ps);
825         
826         prs_uint8s (False, "data", ps, depth, hash->data, 16);
827 }
828
829 /*******************************************************************
830 reads or writes a DOM_GID structure.
831 ********************************************************************/
832 void smb_io_gid(char *desc,  DOM_GID *gid, prs_struct *ps, int depth)
833 {
834         if (gid == NULL) return;
835
836         prs_debug(ps, depth, desc, "smb_io_gid");
837         depth++;
838
839         prs_align(ps);
840         
841         prs_uint32("g_rid", ps, depth, &(gid->g_rid));
842         prs_uint32("attr ", ps, depth, &(gid->attr ));
843 }
844
845 /*******************************************************************
846 reads or writes an POLICY_HND structure.
847 ********************************************************************/
848 void smb_io_pol_hnd(char *desc,  POLICY_HND *pol, prs_struct *ps, int depth)
849 {
850         if (pol == NULL) return;
851
852         prs_debug(ps, depth, desc, "smb_io_pol_hnd");
853         depth++;
854
855         prs_align(ps);
856         
857         prs_uint8s (False, "data", ps, depth, pol->data, POL_HND_SIZE);
858 }
859
860 /*******************************************************************
861 reads or writes a dom query structure.
862 ********************************************************************/
863 void smb_io_dom_query_3(char *desc,  DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
864 {
865         smb_io_dom_query("", d_q, ps, depth);
866 }
867
868 /*******************************************************************
869 reads or writes a dom query structure.
870 ********************************************************************/
871 void smb_io_dom_query_5(char *desc,  DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
872 {
873         smb_io_dom_query("", d_q, ps, depth);
874 }
875
876 /*******************************************************************
877 reads or writes a dom query structure.
878 ********************************************************************/
879 void smb_io_dom_query(char *desc,  DOM_QUERY *d_q, prs_struct *ps, int depth)
880 {
881         if (d_q == NULL) return;
882
883         prs_debug(ps, depth, desc, "smb_io_dom_query");
884         depth++;
885
886         prs_align(ps);
887         
888         prs_uint16("uni_dom_max_len", ps, depth, &(d_q->uni_dom_max_len)); /* domain name string length * 2 */
889         prs_uint16("uni_dom_str_len", ps, depth, &(d_q->uni_dom_str_len)); /* domain name string length * 2 */
890
891         prs_uint32("buffer_dom_name", ps, depth, &(d_q->buffer_dom_name)); /* undocumented domain name string buffer pointer */
892         prs_uint32("buffer_dom_sid ", ps, depth, &(d_q->buffer_dom_sid )); /* undocumented domain SID string buffer pointer */
893
894         smb_io_unistr2("unistr2", &(d_q->uni_domain_name), d_q->buffer_dom_name, ps, depth); /* domain name (unicode string) */
895
896         if (d_q->buffer_dom_sid != 0)
897         {
898                 smb_io_dom_sid2("", &(d_q->dom_sid), ps, depth); /* domain SID */
899         }
900         else
901         {
902                 bzero(&(d_q->dom_sid), sizeof(d_q->dom_sid));
903         }
904 }
905
906 /*******************************************************************
907 reads or writes a DOM_NAME structure.
908 ********************************************************************/
909 void smb_io_dom_name(char *desc,  DOM_NAME *name, prs_struct *ps, int depth)
910 {
911         if (name == NULL) return;
912
913         prs_debug(ps, depth, desc, "smb_io_dom_name");
914         depth++;
915
916         prs_align(ps);
917         
918         prs_uint32("uni_str_len", ps, depth, &(name->uni_str_len));
919
920         /* don't know if len is specified by uni_str_len member... */
921         /* assume unicode string is unicode-null-terminated, instead */
922
923         smb_io_unistr("", &(name->str), ps, depth);
924 }
925
926