RIP BOOL. Convert BOOL -> bool. I found a few interesting
[tprouty/samba.git] / source3 / rpc_parse / parse_net.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997.
7  *  Copyright (C) Jean Francois Micouleau           2002.
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 3 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "includes.h"
24
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_PARSE
27
28 /*******************************************************************
29  Reads or writes a structure.
30 ********************************************************************/
31
32 static bool net_io_neg_flags(const char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth)
33 {
34         if (neg == NULL)
35                 return False;
36
37         prs_debug(ps, depth, desc, "net_io_neg_flags");
38         depth++;
39
40         if(!prs_align(ps))
41                 return False;
42         
43         if(!prs_uint32("neg_flags", ps, depth, &neg->neg_flags))
44                 return False;
45
46         return True;
47 }
48
49 /*******************************************************************
50  Inits a NETLOGON_INFO_3 structure.
51 ********************************************************************/
52
53 static void init_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_attempts)
54 {
55         info->flags          = flags;
56         info->logon_attempts = logon_attempts;
57         info->reserved_1     = 0x0;
58         info->reserved_2     = 0x0;
59         info->reserved_3     = 0x0;
60         info->reserved_4     = 0x0;
61         info->reserved_5     = 0x0;
62 }
63
64 /*******************************************************************
65  Reads or writes a NETLOGON_INFO_3 structure.
66 ********************************************************************/
67
68 static bool net_io_netinfo_3(const char *desc,  NETLOGON_INFO_3 *info, prs_struct *ps, int depth)
69 {
70         if (info == NULL)
71                 return False;
72
73         prs_debug(ps, depth, desc, "net_io_netinfo_3");
74         depth++;
75
76         if(!prs_align(ps))
77                 return False;
78
79         if(!prs_uint32("flags         ", ps, depth, &info->flags))
80                 return False;
81         if(!prs_uint32("logon_attempts", ps, depth, &info->logon_attempts))
82                 return False;
83         if(!prs_uint32("reserved_1    ", ps, depth, &info->reserved_1))
84                 return False;
85         if(!prs_uint32("reserved_2    ", ps, depth, &info->reserved_2))
86                 return False;
87         if(!prs_uint32("reserved_3    ", ps, depth, &info->reserved_3))
88                 return False;
89         if(!prs_uint32("reserved_4    ", ps, depth, &info->reserved_4))
90                 return False;
91         if(!prs_uint32("reserved_5    ", ps, depth, &info->reserved_5))
92                 return False;
93
94         return True;
95 }
96
97
98 /*******************************************************************
99  Inits a NETLOGON_INFO_1 structure.
100 ********************************************************************/
101
102 static void init_netinfo_1(NETLOGON_INFO_1 *info, uint32 flags, uint32 pdc_status)
103 {
104         info->flags      = flags;
105         info->pdc_status = pdc_status;
106 }
107
108 /*******************************************************************
109  Reads or writes a NETLOGON_INFO_1 structure.
110 ********************************************************************/
111
112 static bool net_io_netinfo_1(const char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth)
113 {
114         if (info == NULL)
115                 return False;
116
117         prs_debug(ps, depth, desc, "net_io_netinfo_1");
118         depth++;
119
120         if(!prs_align(ps))
121                 return False;
122         
123         if(!prs_uint32("flags     ", ps, depth, &info->flags))
124                 return False;
125         if(!prs_uint32("pdc_status", ps, depth, &info->pdc_status))
126                 return False;
127
128         return True;
129 }
130
131 /*******************************************************************
132  Inits a NETLOGON_INFO_2 structure.
133 ********************************************************************/
134
135 static void init_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_status,
136                                 uint32 tc_status, const char *trusted_dc_name)
137 {
138         info->flags      = flags;
139         info->pdc_status = pdc_status;
140         info->ptr_trusted_dc_name = 1;
141         info->tc_status  = tc_status;
142
143         if (trusted_dc_name != NULL)
144                 init_unistr2(&info->uni_trusted_dc_name, trusted_dc_name, UNI_STR_TERMINATE);
145         else
146                 init_unistr2(&info->uni_trusted_dc_name, "", UNI_STR_TERMINATE);
147 }
148
149 /*******************************************************************
150  Reads or writes a NETLOGON_INFO_2 structure.
151 ********************************************************************/
152
153 static bool net_io_netinfo_2(const char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth)
154 {
155         if (info == NULL)
156                 return False;
157
158         prs_debug(ps, depth, desc, "net_io_netinfo_2");
159         depth++;
160
161         if(!prs_align(ps))
162                 return False;
163         
164         if(!prs_uint32("flags              ", ps, depth, &info->flags))
165                 return False;
166         if(!prs_uint32("pdc_status         ", ps, depth, &info->pdc_status))
167                 return False;
168         if(!prs_uint32("ptr_trusted_dc_name", ps, depth, &info->ptr_trusted_dc_name))
169                 return False;
170         if(!prs_uint32("tc_status          ", ps, depth, &info->tc_status))
171                 return False;
172
173         if (info->ptr_trusted_dc_name != 0) {
174                 if(!smb_io_unistr2("unistr2", &info->uni_trusted_dc_name, info->ptr_trusted_dc_name, ps, depth))
175                         return False;
176         }
177
178         if(!prs_align(ps))
179                 return False;
180
181         return True;
182 }
183
184 static bool net_io_ctrl_data_info_5(const char *desc, CTRL_DATA_INFO_5 *info, prs_struct *ps, int depth)
185 {
186         if (info == NULL)
187                 return False;
188                 
189         prs_debug(ps, depth, desc, "net_io_ctrl_data_info_5");
190         depth++;
191         
192         if ( !prs_uint32( "function_code", ps, depth, &info->function_code ) )
193                 return False;
194         
195         if(!prs_uint32("ptr_domain", ps, depth, &info->ptr_domain))
196                 return False;
197                 
198         if ( info->ptr_domain ) {
199                 if(!smb_io_unistr2("domain", &info->domain, info->ptr_domain, ps, depth))
200                         return False;
201         }
202                 
203         return True;
204 }
205
206 static bool net_io_ctrl_data_info_6(const char *desc, CTRL_DATA_INFO_6 *info, prs_struct *ps, int depth)
207 {
208         if (info == NULL)
209                 return False;
210                 
211         prs_debug(ps, depth, desc, "net_io_ctrl_data_info_6");
212         depth++;
213         
214         if ( !prs_uint32( "function_code", ps, depth, &info->function_code ) )
215                 return False;
216         
217         if(!prs_uint32("ptr_domain", ps, depth, &info->ptr_domain))
218                 return False;
219                 
220         if ( info->ptr_domain ) {
221                 if(!smb_io_unistr2("domain", &info->domain, info->ptr_domain, ps, depth))
222                         return False;
223         }
224                 
225         return True;
226 }
227
228 /*******************************************************************
229  Reads or writes an NET_Q_LOGON_CTRL2 structure.
230 ********************************************************************/
231
232 bool net_io_q_logon_ctrl2(const char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth)
233 {
234         if (q_l == NULL)
235                 return False;
236
237         prs_debug(ps, depth, desc, "net_io_q_logon_ctrl2");
238         depth++;
239
240         if(!prs_align(ps))
241                 return False;
242
243         if(!prs_uint32("ptr          ", ps, depth, &q_l->ptr))
244                 return False;
245
246         if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
247                 return False;
248
249         if(!prs_align(ps))
250                 return False;
251
252         if(!prs_uint32("function_code", ps, depth, &q_l->function_code))
253                 return False;
254         if(!prs_uint32("query_level  ", ps, depth, &q_l->query_level))
255                 return False;
256         switch ( q_l->function_code ) {
257                 case NETLOGON_CONTROL_REDISCOVER:
258                         if ( !net_io_ctrl_data_info_5( "ctrl_data_info5", &q_l->info.info5, ps, depth) ) 
259                                 return False;
260                         break;
261                         
262                 case NETLOGON_CONTROL_TC_QUERY:
263                         if ( !net_io_ctrl_data_info_6( "ctrl_data_info6", &q_l->info.info6, ps, depth) ) 
264                                 return False;
265                         break;
266
267                 default:
268                         DEBUG(0,("net_io_q_logon_ctrl2: unknown function_code [%d]\n",
269                                 q_l->function_code));
270                         return False;
271         }
272         
273         return True;
274 }
275
276 /*******************************************************************
277  Inits an NET_Q_LOGON_CTRL2 structure.
278 ********************************************************************/
279
280 void init_net_q_logon_ctrl2(NET_Q_LOGON_CTRL2 *q_l, const char *srv_name,
281                             uint32 query_level)
282 {
283         DEBUG(5,("init_q_logon_ctrl2\n"));
284
285         q_l->function_code = 0x01;
286         q_l->query_level = query_level;
287
288         init_unistr2(&q_l->uni_server_name, srv_name, UNI_STR_TERMINATE);
289 }
290
291 /*******************************************************************
292  Inits an NET_R_LOGON_CTRL2 structure.
293 ********************************************************************/
294
295 void init_net_r_logon_ctrl2(NET_R_LOGON_CTRL2 *r_l, uint32 query_level,
296                             uint32 flags, uint32 pdc_status, 
297                             uint32 logon_attempts, uint32 tc_status, 
298                             const char *trusted_domain_name)
299 {
300         r_l->switch_value  = query_level; 
301
302         switch (query_level) {
303         case 1:
304                 r_l->ptr = 1; /* undocumented pointer */
305                 init_netinfo_1(&r_l->logon.info1, flags, pdc_status);   
306                 r_l->status = NT_STATUS_OK;
307                 break;
308         case 2:
309                 r_l->ptr = 1; /* undocumented pointer */
310                 init_netinfo_2(&r_l->logon.info2, flags, pdc_status,
311                                tc_status, trusted_domain_name); 
312                 r_l->status = NT_STATUS_OK;
313                 break;
314         case 3:
315                 r_l->ptr = 1; /* undocumented pointer */
316                 init_netinfo_3(&r_l->logon.info3, flags, logon_attempts);       
317                 r_l->status = NT_STATUS_OK;
318                 break;
319         default:
320                 DEBUG(2,("init_r_logon_ctrl2: unsupported switch value %d\n",
321                         r_l->switch_value));
322                 r_l->ptr = 0; /* undocumented pointer */
323
324                 /* take a guess at an error code... */
325                 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
326                 break;
327         }
328 }
329
330 /*******************************************************************
331  Reads or writes an NET_R_LOGON_CTRL2 structure.
332 ********************************************************************/
333
334 bool net_io_r_logon_ctrl2(const char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth)
335 {
336         if (r_l == NULL)
337                 return False;
338
339         prs_debug(ps, depth, desc, "net_io_r_logon_ctrl2");
340         depth++;
341
342         if(!prs_uint32("switch_value ", ps, depth, &r_l->switch_value))
343                 return False;
344         if(!prs_uint32("ptr          ", ps, depth, &r_l->ptr))
345                 return False;
346
347         if (r_l->ptr != 0) {
348                 switch (r_l->switch_value) {
349                 case 1:
350                         if(!net_io_netinfo_1("", &r_l->logon.info1, ps, depth))
351                                 return False;
352                         break;
353                 case 2:
354                         if(!net_io_netinfo_2("", &r_l->logon.info2, ps, depth))
355                                 return False;
356                         break;
357                 case 3:
358                         if(!net_io_netinfo_3("", &r_l->logon.info3, ps, depth))
359                                 return False;
360                         break;
361                 default:
362                         DEBUG(2,("net_io_r_logon_ctrl2: unsupported switch value %d\n",
363                                 r_l->switch_value));
364                         break;
365                 }
366         }
367
368         if(!prs_ntstatus("status       ", ps, depth, &r_l->status))
369                 return False;
370
371         return True;
372 }
373
374 /*******************************************************************
375  Reads or writes an NET_Q_LOGON_CTRL structure.
376 ********************************************************************/
377
378 bool net_io_q_logon_ctrl(const char *desc, NET_Q_LOGON_CTRL *q_l, prs_struct *ps, 
379                          int depth)
380 {
381         prs_debug(ps, depth, desc, "net_io_q_logon_ctrl");
382         depth++;
383
384         if(!prs_align(ps))
385                 return False;
386
387         if(!prs_uint32("ptr          ", ps, depth, &q_l->ptr))
388                 return False;
389
390         if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
391                 return False;
392
393         if(!prs_align(ps))
394                 return False;
395
396         if(!prs_uint32("function_code", ps, depth, &q_l->function_code))
397                 return False;
398         if(!prs_uint32("query_level  ", ps, depth, &q_l->query_level))
399                 return False;
400
401         return True;
402 }
403
404 /*******************************************************************
405  Inits an NET_Q_LOGON_CTRL structure.
406 ********************************************************************/
407
408 void init_net_q_logon_ctrl(NET_Q_LOGON_CTRL *q_l, const char *srv_name,
409                            uint32 query_level)
410 {
411         DEBUG(5,("init_q_logon_ctrl\n"));
412
413         q_l->function_code = 0x01; /* ??? */
414         q_l->query_level = query_level;
415
416         init_unistr2(&q_l->uni_server_name, srv_name, UNI_STR_TERMINATE);
417 }
418
419 /*******************************************************************
420  Inits an NET_R_LOGON_CTRL structure.
421 ********************************************************************/
422
423 void init_net_r_logon_ctrl(NET_R_LOGON_CTRL *r_l, uint32 query_level,
424                            uint32 flags, uint32 pdc_status)
425 {
426         DEBUG(5,("init_r_logon_ctrl\n"));
427
428         r_l->switch_value  = query_level; /* should only be 0x1 */
429
430         switch (query_level) {
431         case 1:
432                 r_l->ptr = 1; /* undocumented pointer */
433                 init_netinfo_1(&r_l->logon.info1, flags, pdc_status);   
434                 r_l->status = NT_STATUS_OK;
435                 break;
436         default:
437                 DEBUG(2,("init_r_logon_ctrl: unsupported switch value %d\n",
438                         r_l->switch_value));
439                 r_l->ptr = 0; /* undocumented pointer */
440
441                 /* take a guess at an error code... */
442                 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
443                 break;
444         }
445 }
446
447 /*******************************************************************
448  Reads or writes an NET_R_LOGON_CTRL structure.
449 ********************************************************************/
450
451 bool net_io_r_logon_ctrl(const char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps, 
452                          int depth)
453 {
454         prs_debug(ps, depth, desc, "net_io_r_logon_ctrl");
455         depth++;
456
457         if(!prs_uint32("switch_value ", ps, depth, &r_l->switch_value))
458                 return False;
459         if(!prs_uint32("ptr          ", ps, depth, &r_l->ptr))
460                 return False;
461
462         if (r_l->ptr != 0) {
463                 switch (r_l->switch_value) {
464                 case 1:
465                         if(!net_io_netinfo_1("", &r_l->logon.info1, ps, depth))
466                                 return False;
467                         break;
468                 default:
469                         DEBUG(2,("net_io_r_logon_ctrl: unsupported switch value %d\n",
470                                 r_l->switch_value));
471                         break;
472                 }
473         }
474
475         if(!prs_ntstatus("status       ", ps, depth, &r_l->status))
476                 return False;
477
478         return True;
479 }
480
481 /*******************************************************************
482  Inits an NET_R_GETANYDCNAME structure.
483 ********************************************************************/
484 void init_net_q_getanydcname(NET_Q_GETANYDCNAME *r_t, const char *logon_server,
485                              const char *domainname)
486 {
487         DEBUG(5,("init_q_getanydcname\n"));
488
489         r_t->ptr_logon_server = (logon_server != NULL);
490         init_unistr2(&r_t->uni_logon_server, logon_server, UNI_STR_TERMINATE);
491         r_t->ptr_domainname = (domainname != NULL);
492         init_unistr2(&r_t->uni_domainname, domainname, UNI_STR_TERMINATE);
493 }
494
495 /*******************************************************************
496  Reads or writes an NET_Q_GETANYDCNAME structure.
497 ********************************************************************/
498
499 bool net_io_q_getanydcname(const char *desc, NET_Q_GETANYDCNAME *r_t, prs_struct *ps,
500                            int depth)
501 {
502         if (r_t == NULL)
503                 return False;
504
505         prs_debug(ps, depth, desc, "net_io_q_getanydcname");
506         depth++;
507
508         if (!prs_uint32("ptr_logon_server", ps, depth, &r_t->ptr_logon_server))
509                 return False;
510
511         if (!smb_io_unistr2("logon_server", &r_t->uni_logon_server,
512                             r_t->ptr_logon_server, ps, depth))
513                 return False;
514
515         if (!prs_align(ps))
516                 return False;
517
518         if (!prs_uint32("ptr_domainname", ps, depth, &r_t->ptr_domainname))
519                 return False;
520
521         if (!smb_io_unistr2("domainname", &r_t->uni_domainname,
522                             r_t->ptr_domainname, ps, depth))
523                 return False;
524
525         return True;
526 }
527
528
529 /*******************************************************************
530  Inits an NET_R_GETANYDCNAME structure.
531 ********************************************************************/
532 void init_net_r_getanydcname(NET_R_GETANYDCNAME *r_t, const char *dcname)
533 {
534         DEBUG(5,("init_r_getanydcname\n"));
535
536         init_unistr2(&r_t->uni_dcname, dcname, UNI_STR_TERMINATE);
537 }
538
539 /*******************************************************************
540  Reads or writes an NET_R_GETANYDCNAME structure.
541 ********************************************************************/
542
543 bool net_io_r_getanydcname(const char *desc, NET_R_GETANYDCNAME *r_t, prs_struct *ps,
544                            int depth)
545 {
546         if (r_t == NULL)
547                 return False;
548
549         prs_debug(ps, depth, desc, "net_io_r_getanydcname");
550         depth++;
551
552         if (!prs_uint32("ptr_dcname", ps, depth, &r_t->ptr_dcname))
553                 return False;
554
555         if (!smb_io_unistr2("dcname", &r_t->uni_dcname,
556                             r_t->ptr_dcname, ps, depth))
557                 return False;
558
559         if (!prs_align(ps))
560                 return False;
561
562         if (!prs_werror("status", ps, depth, &r_t->status))
563                 return False;
564
565         return True;
566 }
567
568
569 /*******************************************************************
570  Inits an NET_R_GETDCNAME structure.
571 ********************************************************************/
572 void init_net_q_getdcname(NET_Q_GETDCNAME *r_t, const char *logon_server,
573                           const char *domainname)
574 {
575         DEBUG(5,("init_q_getdcname\n"));
576
577         init_unistr2(&r_t->uni_logon_server, logon_server, UNI_STR_TERMINATE);
578         r_t->ptr_domainname = (domainname != NULL);
579         init_unistr2(&r_t->uni_domainname, domainname, UNI_STR_TERMINATE);
580 }
581
582 /*******************************************************************
583  Reads or writes an NET_Q_GETDCNAME structure.
584 ********************************************************************/
585
586 bool net_io_q_getdcname(const char *desc, NET_Q_GETDCNAME *r_t, prs_struct *ps,
587                         int depth)
588 {
589         if (r_t == NULL)
590                 return False;
591
592         prs_debug(ps, depth, desc, "net_io_q_getdcname");
593         depth++;
594
595         if (!smb_io_unistr2("logon_server", &r_t->uni_logon_server,
596                             1, ps, depth))
597                 return False;
598
599         if (!prs_align(ps))
600                 return False;
601
602         if (!prs_uint32("ptr_domainname", ps, depth, &r_t->ptr_domainname))
603                 return False;
604
605         if (!smb_io_unistr2("domainname", &r_t->uni_domainname,
606                             r_t->ptr_domainname, ps, depth))
607                 return False;
608
609         return True;
610 }
611
612
613 /*******************************************************************
614  Inits an NET_R_GETDCNAME structure.
615 ********************************************************************/
616 void init_net_r_getdcname(NET_R_GETDCNAME *r_t, const char *dcname)
617 {
618         DEBUG(5,("init_r_getdcname\n"));
619
620         init_unistr2(&r_t->uni_dcname, dcname, UNI_STR_TERMINATE);
621 }
622
623 /*******************************************************************
624  Reads or writes an NET_R_GETDCNAME structure.
625 ********************************************************************/
626
627 bool net_io_r_getdcname(const char *desc, NET_R_GETDCNAME *r_t, prs_struct *ps,
628                         int depth)
629 {
630         if (r_t == NULL)
631                 return False;
632
633         prs_debug(ps, depth, desc, "net_io_r_getdcname");
634         depth++;
635
636         if (!prs_uint32("ptr_dcname", ps, depth, &r_t->ptr_dcname))
637                 return False;
638
639         if (!smb_io_unistr2("dcname", &r_t->uni_dcname,
640                             r_t->ptr_dcname, ps, depth))
641                 return False;
642
643         if (!prs_align(ps))
644                 return False;
645
646         if (!prs_werror("status", ps, depth, &r_t->status))
647                 return False;
648
649         return True;
650 }
651
652 /*******************************************************************
653  Inits an NET_R_TRUST_DOM_LIST structure.
654 ********************************************************************/
655
656 void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
657                         uint32 num_doms, const char *dom_name)
658 {
659         unsigned int i = 0;
660
661         DEBUG(5,("init_r_trust_dom\n"));
662
663         for (i = 0; i < MAX_TRUST_DOMS; i++) {
664                 r_t->uni_trust_dom_name[i].uni_str_len = 0;
665                 r_t->uni_trust_dom_name[i].uni_max_len = 0;
666         }
667         if (num_doms > MAX_TRUST_DOMS)
668                 num_doms = MAX_TRUST_DOMS;
669
670         for (i = 0; i < num_doms; i++) {
671                 fstring domain_name;
672                 fstrcpy(domain_name, dom_name);
673                 strupper_m(domain_name);
674                 init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, UNI_STR_TERMINATE);
675                 /* the use of UNISTR2 here is non-standard. */
676                 r_t->uni_trust_dom_name[i].offset = 0x1;
677         }
678         
679         r_t->status = NT_STATUS_OK;
680 }
681
682 /*******************************************************************
683  Reads or writes an NET_R_TRUST_DOM_LIST structure.
684 ********************************************************************/
685
686 bool net_io_r_trust_dom(const char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth)
687 {
688         uint32 value;
689
690         if (r_t == NULL)
691                  return False;
692
693         prs_debug(ps, depth, desc, "net_io_r_trust_dom");
694         depth++;
695
696         /* temporary code to give a valid response */
697         value=2;
698         if(!prs_uint32("status", ps, depth, &value))
699                  return False;
700
701         value=1;
702         if(!prs_uint32("status", ps, depth, &value))
703                  return False;
704         value=2;
705         if(!prs_uint32("status", ps, depth, &value))
706                  return False;
707
708         value=0;
709         if(!prs_uint32("status", ps, depth, &value))
710                  return False;
711
712         value=0;
713         if(!prs_uint32("status", ps, depth, &value))
714                  return False;
715
716 /* old non working code */
717 #if 0
718         int i;
719
720         for (i = 0; i < MAX_TRUST_DOMS; i++) {
721                 if (r_t->uni_trust_dom_name[i].uni_str_len == 0)
722                         break;
723                 if(!smb_io_unistr2("", &r_t->uni_trust_dom_name[i], True, ps, depth))
724                          return False;
725         }
726
727         if(!prs_ntstatus("status", ps, depth, &r_t->status))
728                  return False;
729 #endif
730         return True;
731 }
732
733
734 /*******************************************************************
735  Reads or writes an NET_Q_TRUST_DOM_LIST structure.
736 ********************************************************************/
737
738 bool net_io_q_trust_dom(const char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth)
739 {
740         if (q_l == NULL)
741                  return False;
742
743         prs_debug(ps, depth, desc, "net_io_q_trust_dom");
744         depth++;
745
746         if(!prs_uint32("ptr          ", ps, depth, &q_l->ptr))
747                  return False;
748         if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
749                  return False;
750
751         return True;
752 }
753
754 /*******************************************************************
755  Inits an NET_Q_REQ_CHAL structure.
756 ********************************************************************/
757
758 void init_q_req_chal(NET_Q_REQ_CHAL *q_c,
759                      const char *logon_srv, const char *logon_clnt,
760                      const DOM_CHAL *clnt_chal)
761 {
762         DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
763
764         q_c->undoc_buffer = 1; /* don't know what this buffer is */
765
766         init_unistr2(&q_c->uni_logon_srv, logon_srv , UNI_STR_TERMINATE);
767         init_unistr2(&q_c->uni_logon_clnt, logon_clnt, UNI_STR_TERMINATE);
768
769         memcpy(q_c->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
770
771         DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
772 }
773
774 /*******************************************************************
775  Reads or writes an NET_Q_REQ_CHAL structure.
776 ********************************************************************/
777
778 bool net_io_q_req_chal(const char *desc,  NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth)
779 {
780         if (q_c == NULL)
781                 return False;
782
783         prs_debug(ps, depth, desc, "net_io_q_req_chal");
784         depth++;
785
786         if(!prs_align(ps))
787                 return False;
788     
789         if(!prs_uint32("undoc_buffer", ps, depth, &q_c->undoc_buffer))
790                 return False;
791
792         if(!smb_io_unistr2("", &q_c->uni_logon_srv, True, ps, depth)) /* logon server unicode string */
793                 return False;
794         if(!smb_io_unistr2("", &q_c->uni_logon_clnt, True, ps, depth)) /* logon client unicode string */
795                 return False;
796
797         if(!smb_io_chal("", &q_c->clnt_chal, ps, depth))
798                 return False;
799
800         return True;
801 }
802
803 /*******************************************************************
804  Reads or writes a structure.
805 ********************************************************************/
806
807 bool net_io_r_req_chal(const char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth)
808 {
809         if (r_c == NULL)
810                 return False;
811
812         prs_debug(ps, depth, desc, "net_io_r_req_chal");
813         depth++;
814
815         if(!prs_align(ps))
816                 return False;
817     
818         if(!smb_io_chal("", &r_c->srv_chal, ps, depth)) /* server challenge */
819                 return False;
820
821         if(!prs_ntstatus("status", ps, depth, &r_c->status))
822                 return False;
823
824         return True;
825 }
826
827
828 /*******************************************************************
829  Reads or writes a structure.
830 ********************************************************************/
831
832 bool net_io_q_auth(const char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
833 {
834         if (q_a == NULL)
835                 return False;
836
837         prs_debug(ps, depth, desc, "net_io_q_auth");
838         depth++;
839
840         if(!prs_align(ps))
841                 return False;
842     
843         if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
844                 return False;
845         if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
846                 return False;
847
848         return True;
849 }
850
851 /*******************************************************************
852  Reads or writes a structure.
853 ********************************************************************/
854
855 bool net_io_r_auth(const char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
856 {
857         if (r_a == NULL)
858                 return False;
859
860         prs_debug(ps, depth, desc, "net_io_r_auth");
861         depth++;
862
863         if(!prs_align(ps))
864                 return False;
865     
866         if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
867                 return False;
868
869         if(!prs_ntstatus("status", ps, depth, &r_a->status))
870                 return False;
871
872         return True;
873 }
874
875 /*******************************************************************
876  Inits a NET_Q_AUTH_2 struct.
877 ********************************************************************/
878
879 void init_q_auth_2(NET_Q_AUTH_2 *q_a,
880                 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
881                 const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
882 {
883         DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
884
885         init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
886         memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
887         q_a->clnt_flgs.neg_flags = clnt_flgs;
888
889         DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
890 }
891
892 /*******************************************************************
893  Reads or writes a structure.
894 ********************************************************************/
895
896 bool net_io_q_auth_2(const char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth)
897 {
898         if (q_a == NULL)
899                 return False;
900
901         prs_debug(ps, depth, desc, "net_io_q_auth_2");
902         depth++;
903
904         if(!prs_align(ps))
905                 return False;
906     
907         if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
908                 return False;
909         if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
910                 return False;
911         if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
912                 return False;
913
914         return True;
915 }
916
917 /*******************************************************************
918  Reads or writes a structure.
919 ********************************************************************/
920
921 bool net_io_r_auth_2(const char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth)
922 {
923         if (r_a == NULL)
924                 return False;
925
926         prs_debug(ps, depth, desc, "net_io_r_auth_2");
927         depth++;
928
929         if(!prs_align(ps))
930                 return False;
931     
932         if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
933                 return False;
934         if(!net_io_neg_flags("", &r_a->srv_flgs, ps, depth))
935                 return False;
936
937         if(!prs_ntstatus("status", ps, depth, &r_a->status))
938                 return False;
939
940         return True;
941 }
942
943 /*******************************************************************
944  Inits a NET_Q_AUTH_3 struct.
945 ********************************************************************/
946
947 void init_q_auth_3(NET_Q_AUTH_3 *q_a,
948                 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
949                 const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
950 {
951         DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
952
953         init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
954         memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
955         q_a->clnt_flgs.neg_flags = clnt_flgs;
956
957         DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
958 }
959
960 /*******************************************************************
961  Reads or writes a structure.
962 ********************************************************************/
963
964 bool net_io_q_auth_3(const char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int depth)
965 {
966         if (q_a == NULL)
967                 return False;
968
969         prs_debug(ps, depth, desc, "net_io_q_auth_3");
970         depth++;
971
972         if(!prs_align(ps))
973                 return False;
974     
975         if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
976                 return False;
977         if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
978                 return False;
979         if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
980                 return False;
981
982         return True;
983 }
984
985 /*******************************************************************
986  Reads or writes a structure.
987 ********************************************************************/
988
989 bool net_io_r_auth_3(const char *desc, NET_R_AUTH_3 *r_a, prs_struct *ps, int depth)
990 {
991         if (r_a == NULL)
992                 return False;
993
994         prs_debug(ps, depth, desc, "net_io_r_auth_3");
995         depth++;
996
997         if(!prs_align(ps))
998                 return False;
999     
1000         if(!smb_io_chal("srv_chal", &r_a->srv_chal, ps, depth)) /* server challenge */
1001                 return False;
1002         if(!net_io_neg_flags("srv_flgs", &r_a->srv_flgs, ps, depth))
1003                 return False;
1004         if (!prs_uint32("unknown", ps, depth, &r_a->unknown))
1005                 return False;
1006
1007         if(!prs_ntstatus("status", ps, depth, &r_a->status))
1008                 return False;
1009
1010         return True;
1011 }
1012
1013
1014 /*******************************************************************
1015  Inits a NET_Q_SRV_PWSET.
1016 ********************************************************************/
1017
1018 void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s,
1019                 const char *logon_srv, const char *sess_key, const char *acct_name, 
1020                 uint16 sec_chan, const char *comp_name,
1021                 DOM_CRED *cred, const uchar hashed_mach_pwd[16])
1022 {
1023         unsigned char nt_cypher[16];
1024         
1025         DEBUG(5,("init_q_srv_pwset\n"));
1026         
1027         /* Process the new password. */
1028         cred_hash3( nt_cypher, hashed_mach_pwd, (const unsigned char *)sess_key, 1);
1029
1030         init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
1031
1032         memcpy(q_s->pwd, nt_cypher, sizeof(q_s->pwd)); 
1033 }
1034
1035 /*******************************************************************
1036  Reads or writes a structure.
1037 ********************************************************************/
1038
1039 bool net_io_q_srv_pwset(const char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth)
1040 {
1041         if (q_s == NULL)
1042                 return False;
1043
1044         prs_debug(ps, depth, desc, "net_io_q_srv_pwset");
1045         depth++;
1046
1047         if(!prs_align(ps))
1048                 return False;
1049     
1050         if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */
1051                 return False;
1052         if(!prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16)) /* new password - undocumented */
1053                 return False;
1054
1055         return True;
1056 }
1057
1058 /*******************************************************************
1059  Reads or writes a structure.
1060 ********************************************************************/
1061
1062 bool net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth)
1063 {
1064         if (r_s == NULL)
1065                 return False;
1066
1067         prs_debug(ps, depth, desc, "net_io_r_srv_pwset");
1068         depth++;
1069
1070         if(!prs_align(ps))
1071                 return False;
1072     
1073         if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */
1074                 return False;
1075
1076         if(!prs_ntstatus("status", ps, depth, &r_s->status))
1077                 return False;
1078
1079         return True;
1080 }
1081
1082 /*************************************************************************
1083  Init DOM_SID2 array from a string containing multiple sids
1084  *************************************************************************/
1085
1086 static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids)
1087 {
1088         const char *ptr;
1089         pstring s2;
1090         int count = 0;
1091
1092         DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
1093
1094         *ppsids = NULL;
1095
1096         if(sids_str) {
1097                 int number;
1098                 DOM_SID2 *sids;
1099
1100                 /* Count the number of valid SIDs. */
1101                 for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1102                         DOM_SID tmpsid;
1103                         if (string_to_sid(&tmpsid, s2))
1104                                 count++;
1105                 }
1106
1107                 /* Now allocate space for them. */
1108                 if (count) {
1109                         *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
1110                         if (*ppsids == NULL)
1111                                 return 0;
1112                 } else {
1113                         *ppsids = NULL;
1114                 }
1115
1116                 sids = *ppsids;
1117
1118                 for (number = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1119                         DOM_SID tmpsid;
1120                         if (string_to_sid(&tmpsid, s2)) {
1121                                 /* count only valid sids */
1122                                 init_dom_sid2(&sids[number], &tmpsid);
1123                                 number++;
1124                         }
1125                 }
1126         }
1127
1128         return count;
1129 }
1130
1131 /*******************************************************************
1132  Inits a NET_ID_INFO_1 structure.
1133 ********************************************************************/
1134
1135 void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
1136                                 uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high,
1137                                 const char *user_name, const char *wksta_name,
1138                                 const char *sess_key,
1139                                 unsigned char lm_cypher[16], unsigned char nt_cypher[16])
1140 {
1141         unsigned char lm_owf[16];
1142         unsigned char nt_owf[16];
1143
1144         DEBUG(5,("init_id_info1: %d\n", __LINE__));
1145
1146         id->ptr_id_info1 = 1;
1147
1148         id->param_ctrl = param_ctrl;
1149         init_logon_id(&id->logon_id, log_id_low, log_id_high);
1150
1151
1152         if (lm_cypher && nt_cypher) {
1153                 unsigned char key[16];
1154 #ifdef DEBUG_PASSWORD
1155                 DEBUG(100,("lm cypher:"));
1156                 dump_data(100, lm_cypher, 16);
1157
1158                 DEBUG(100,("nt cypher:"));
1159                 dump_data(100, nt_cypher, 16);
1160 #endif
1161
1162                 memset(key, 0, 16);
1163                 memcpy(key, sess_key, 8);
1164
1165                 memcpy(lm_owf, lm_cypher, 16);
1166                 SamOEMhash(lm_owf, key, 16);
1167                 memcpy(nt_owf, nt_cypher, 16);
1168                 SamOEMhash(nt_owf, key, 16);
1169
1170 #ifdef DEBUG_PASSWORD
1171                 DEBUG(100,("encrypt of lm owf password:"));
1172                 dump_data(100, lm_owf, 16);
1173
1174                 DEBUG(100,("encrypt of nt owf password:"));
1175                 dump_data(100, nt_owf, 16);
1176 #endif
1177                 /* set up pointers to cypher blocks */
1178                 lm_cypher = lm_owf;
1179                 nt_cypher = nt_owf;
1180         }
1181
1182         init_owf_info(&id->lm_owf, lm_cypher);
1183         init_owf_info(&id->nt_owf, nt_cypher);
1184
1185         init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1186         init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1187         init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1188         init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1189         init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1190         init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1191 }
1192
1193 /*******************************************************************
1194  Reads or writes an NET_ID_INFO_1 structure.
1195 ********************************************************************/
1196
1197 static bool net_io_id_info1(const char *desc,  NET_ID_INFO_1 *id, prs_struct *ps, int depth)
1198 {
1199         if (id == NULL)
1200                 return False;
1201
1202         prs_debug(ps, depth, desc, "net_io_id_info1");
1203         depth++;
1204
1205         if(!prs_align(ps))
1206                 return False;
1207         
1208         if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1))
1209                 return False;
1210
1211         if (id->ptr_id_info1 != 0) {
1212                 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1213                         return False;
1214
1215                 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1216                         return False;
1217                 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1218                         return False;
1219
1220                 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1221                         return False;
1222                 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1223                         return False;
1224
1225                 if(!smb_io_owf_info("", &id->lm_owf, ps, depth))
1226                         return False;
1227                 if(!smb_io_owf_info("", &id->nt_owf, ps, depth))
1228                         return False;
1229
1230                 if(!smb_io_unistr2("unistr2", &id->uni_domain_name,
1231                                 id->hdr_domain_name.buffer, ps, depth))
1232                         return False;
1233                 if(!smb_io_unistr2("unistr2", &id->uni_user_name,
1234                                 id->hdr_user_name.buffer, ps, depth))
1235                         return False;
1236                 if(!smb_io_unistr2("unistr2", &id->uni_wksta_name,
1237                                 id->hdr_wksta_name.buffer, ps, depth))
1238                         return False;
1239         }
1240
1241         return True;
1242 }
1243
1244 /*******************************************************************
1245 Inits a NET_ID_INFO_2 structure.
1246
1247 This is a network logon packet. The log_id parameters
1248 are what an NT server would generate for LUID once the
1249 user is logged on. I don't think we care about them.
1250
1251 Note that this has no access to the NT and LM hashed passwords,
1252 so it forwards the challenge, and the NT and LM responses (24
1253 bytes each) over the secure channel to the Domain controller
1254 for it to say yea or nay. This is the preferred method of 
1255 checking for a logon as it doesn't export the password
1256 hashes to anyone who has compromised the secure channel. JRA.
1257 ********************************************************************/
1258
1259 void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
1260                    uint32 param_ctrl,
1261                    uint32 log_id_low, uint32 log_id_high,
1262                    const char *user_name, const char *wksta_name,
1263                    const uchar lm_challenge[8],
1264                    const uchar * lm_chal_resp, size_t lm_chal_resp_len,
1265                    const uchar * nt_chal_resp, size_t nt_chal_resp_len)
1266 {
1267
1268         DEBUG(5,("init_id_info2: %d\n", __LINE__));
1269
1270         id->ptr_id_info2 = 1;
1271
1272         id->param_ctrl = param_ctrl;
1273         init_logon_id(&id->logon_id, log_id_low, log_id_high);
1274
1275         memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));
1276         init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);
1277         init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);
1278
1279         init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1280         init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1281         init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1282         init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1283         init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1284         init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1285
1286         init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);
1287         init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);
1288
1289 }
1290
1291 /*******************************************************************
1292  Reads or writes an NET_ID_INFO_2 structure.
1293 ********************************************************************/
1294
1295 static bool net_io_id_info2(const char *desc,  NET_ID_INFO_2 *id, prs_struct *ps, int depth)
1296 {
1297         if (id == NULL)
1298                 return False;
1299
1300         prs_debug(ps, depth, desc, "net_io_id_info2");
1301         depth++;
1302
1303         if(!prs_align(ps))
1304                 return False;
1305         
1306         if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2))
1307                 return False;
1308
1309         if (id->ptr_id_info2 != 0) {
1310                 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1311                         return False;
1312
1313                 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1314                         return False;
1315                 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1316                         return False;
1317
1318                 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1319                         return False;
1320                 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1321                         return False;
1322
1323                 if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */
1324                         return False;
1325
1326                 if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth))
1327                         return False;
1328                 if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth))
1329                         return False;
1330
1331                 if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name,
1332                                 id->hdr_domain_name.buffer, ps, depth))
1333                         return False;
1334                 if(!smb_io_unistr2("uni_user_name  ", &id->uni_user_name,
1335                                 id->hdr_user_name.buffer, ps, depth))
1336                         return False;
1337                 if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name,
1338                                 id->hdr_wksta_name.buffer, ps, depth))
1339                         return False;
1340                 if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp,
1341                                 id->hdr_nt_chal_resp.buffer, ps, depth))
1342                         return False;
1343                 if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp,
1344                                 id->hdr_lm_chal_resp.buffer, ps, depth))
1345                         return False;
1346         }
1347
1348         return True;
1349 }
1350
1351
1352 /*******************************************************************
1353  Inits a DOM_SAM_INFO structure.
1354 ********************************************************************/
1355
1356 void init_sam_info(DOM_SAM_INFO *sam,
1357                                 const char *logon_srv, const char *comp_name,
1358                                 DOM_CRED *clnt_cred,
1359                                 DOM_CRED *rtn_cred, uint16 logon_level,
1360                                 NET_ID_INFO_CTR *ctr)
1361 {
1362         DEBUG(5,("init_sam_info: %d\n", __LINE__));
1363
1364         init_clnt_info2(&sam->client, logon_srv, comp_name, clnt_cred);
1365
1366         if (rtn_cred != NULL) {
1367                 sam->ptr_rtn_cred = 1;
1368                 memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred));
1369         } else {
1370                 sam->ptr_rtn_cred = 0;
1371         }
1372
1373         sam->logon_level  = logon_level;
1374         sam->ctr          = ctr;
1375 }
1376
1377 /*******************************************************************
1378  Inits a DOM_SAM_INFO structure.
1379 ********************************************************************/
1380
1381 void init_sam_info_ex(DOM_SAM_INFO_EX *sam,
1382                       const char *logon_srv, const char *comp_name,
1383                       uint16 logon_level, NET_ID_INFO_CTR *ctr)
1384 {
1385         DEBUG(5,("init_sam_info_ex: %d\n", __LINE__));
1386
1387         init_clnt_srv(&sam->client, logon_srv, comp_name);
1388         sam->logon_level  = logon_level;
1389         sam->ctr          = ctr;
1390 }
1391
1392 /*******************************************************************
1393  Reads or writes a DOM_SAM_INFO structure.
1394 ********************************************************************/
1395
1396 static bool net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1397 {
1398         NET_ID_INFO_CTR *ctr = *pp_ctr;
1399
1400         prs_debug(ps, depth, desc, "smb_io_sam_info_ctr");
1401         depth++;
1402
1403         if (UNMARSHALLING(ps)) {
1404                 ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
1405                 if (ctr == NULL)
1406                         return False;
1407         }
1408         
1409         if (ctr == NULL)
1410                 return False;
1411
1412         /* don't 4-byte align here! */
1413
1414         if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value))
1415                 return False;
1416
1417         switch (ctr->switch_value) {
1418         case 1:
1419                 if(!net_io_id_info1("", &ctr->auth.id1, ps, depth))
1420                         return False;
1421                 break;
1422         case 2:
1423                 if(!net_io_id_info2("", &ctr->auth.id2, ps, depth))
1424                         return False;
1425                 break;
1426         default:
1427                 /* PANIC! */
1428                 DEBUG(4,("smb_io_sam_info_ctr: unknown switch_value!\n"));
1429                 break;
1430         }
1431
1432         return True;
1433 }
1434
1435 /*******************************************************************
1436  Reads or writes a DOM_SAM_INFO structure.
1437  ********************************************************************/
1438
1439 static bool smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
1440 {
1441         if (sam == NULL)
1442                 return False;
1443
1444         prs_debug(ps, depth, desc, "smb_io_sam_info");
1445         depth++;
1446
1447         if(!prs_align(ps))
1448                 return False;
1449         
1450         if(!smb_io_clnt_info2("", &sam->client, ps, depth))
1451                 return False;
1452
1453         if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred))
1454                 return False;
1455         if (sam->ptr_rtn_cred) {
1456                 if(!smb_io_cred("", &sam->rtn_cred, ps, depth))
1457                         return False;
1458         }
1459
1460         if(!prs_uint16("logon_level  ", ps, depth, &sam->logon_level))
1461                 return False;
1462
1463         if (sam->logon_level != 0) {
1464                 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1465                         return False;
1466         }
1467
1468         return True;
1469 }
1470
1471 /*******************************************************************
1472  Reads or writes a DOM_SAM_INFO_EX structure.
1473  ********************************************************************/
1474
1475 static bool smb_io_sam_info_ex(const char *desc, DOM_SAM_INFO_EX *sam, prs_struct *ps, int depth)
1476 {
1477         if (sam == NULL)
1478                 return False;
1479
1480         prs_debug(ps, depth, desc, "smb_io_sam_info_ex");
1481         depth++;
1482
1483         if(!prs_align(ps))
1484                 return False;
1485         
1486         if(!smb_io_clnt_srv("", &sam->client, ps, depth))
1487                 return False;
1488
1489         if(!prs_uint16("logon_level  ", ps, depth, &sam->logon_level))
1490                 return False;
1491
1492         if (sam->logon_level != 0) {
1493                 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1494                         return False;
1495         }
1496
1497         return True;
1498 }
1499
1500 /*************************************************************************
1501  Inits a NET_USER_INFO_3 structure.
1502
1503  This is a network logon reply packet, and contains much information about
1504  the user.  This information is passed as a (very long) paramater list
1505  to avoid having to link in the PASSDB code to every program that deals 
1506  with this file.
1507  *************************************************************************/
1508
1509 void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr, 
1510                          uint32                user_rid,
1511                          uint32                group_rid,
1512
1513                          const char*            user_name,
1514                          const char*            full_name,
1515                          const char*            home_dir,
1516                          const char*            dir_drive,
1517                          const char*            logon_script,
1518                          const char*            profile_path,
1519
1520                          time_t unix_logon_time,
1521                          time_t unix_logoff_time,
1522                          time_t unix_kickoff_time,
1523                          time_t unix_pass_last_set_time,
1524                          time_t unix_pass_can_change_time,
1525                          time_t unix_pass_must_change_time,
1526                          
1527                          uint16 logon_count, uint16 bad_pw_count,
1528                          uint32 num_groups, const DOM_GID *gids,
1529                          uint32 user_flgs, uint32 acct_flags,
1530                          uchar user_session_key[16],
1531                          uchar lm_session_key[16],
1532                          const char *logon_srv, const char *logon_dom,
1533                          const DOM_SID *dom_sid)
1534 {
1535         /* only cope with one "other" sid, right now. */
1536         /* need to count the number of space-delimited sids */
1537         unsigned int i;
1538         int num_other_sids = 0;
1539         
1540         NTTIME          logon_time, logoff_time, kickoff_time,
1541                         pass_last_set_time, pass_can_change_time,
1542                         pass_must_change_time;
1543
1544         ZERO_STRUCTP(usr);
1545
1546         usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */
1547
1548         /* Create NTTIME structs */
1549         unix_to_nt_time (&logon_time,            unix_logon_time);
1550         unix_to_nt_time (&logoff_time,           unix_logoff_time);
1551         unix_to_nt_time (&kickoff_time,          unix_kickoff_time);
1552         unix_to_nt_time (&pass_last_set_time,    unix_pass_last_set_time);
1553         unix_to_nt_time (&pass_can_change_time,  unix_pass_can_change_time);
1554         unix_to_nt_time (&pass_must_change_time, unix_pass_must_change_time);
1555
1556         usr->logon_time            = logon_time;
1557         usr->logoff_time           = logoff_time;
1558         usr->kickoff_time          = kickoff_time;
1559         usr->pass_last_set_time    = pass_last_set_time;
1560         usr->pass_can_change_time  = pass_can_change_time;
1561         usr->pass_must_change_time = pass_must_change_time;
1562
1563         usr->logon_count = logon_count;
1564         usr->bad_pw_count = bad_pw_count;
1565
1566         usr->user_rid = user_rid;
1567         usr->group_rid = group_rid;
1568         usr->num_groups = num_groups;
1569
1570         usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */
1571         usr->user_flgs = user_flgs;
1572         usr->acct_flags = acct_flags;
1573
1574         if (user_session_key != NULL)
1575                 memcpy(usr->user_sess_key, user_session_key, sizeof(usr->user_sess_key));
1576         else
1577                 memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key));
1578
1579         usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */
1580
1581         memset((char *)usr->lm_sess_key, '\0', sizeof(usr->lm_sess_key));
1582
1583         for (i=0; i<7; i++) {
1584                 memset(&usr->unknown[i], '\0', sizeof(usr->unknown));
1585         }
1586
1587         if (lm_session_key != NULL) {
1588                 memcpy(usr->lm_sess_key, lm_session_key, sizeof(usr->lm_sess_key));
1589         }
1590
1591         num_other_sids = init_dom_sid2s(ctx, NULL, &usr->other_sids);
1592
1593         usr->num_other_sids = num_other_sids;
1594         usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0; 
1595         
1596         init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
1597         init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
1598         init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
1599         init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
1600         init_unistr2(&usr->uni_logon_script, logon_script, UNI_FLAGS_NONE);
1601         init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
1602         init_unistr2(&usr->uni_profile_path, profile_path, UNI_FLAGS_NONE);
1603         init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
1604         init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
1605         init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
1606         init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
1607         init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
1608
1609         usr->num_groups2 = num_groups;
1610
1611         if (num_groups) {
1612                 usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
1613                 if (usr->gids == NULL)
1614                         return;
1615         } else {
1616                 usr->gids = NULL;
1617         }
1618
1619         for (i = 0; i < num_groups; i++) 
1620                 usr->gids[i] = gids[i]; 
1621                 
1622         init_unistr2(&usr->uni_logon_srv, logon_srv, UNI_FLAGS_NONE);
1623         init_uni_hdr(&usr->hdr_logon_srv, &usr->uni_logon_srv);
1624         init_unistr2(&usr->uni_logon_dom, logon_dom, UNI_FLAGS_NONE);
1625         init_uni_hdr(&usr->hdr_logon_dom, &usr->uni_logon_dom);
1626
1627         init_dom_sid2(&usr->dom_sid, dom_sid);
1628         /* "other" sids are set up above */
1629 }
1630
1631 static void dump_acct_flags(uint32 acct_flags) {
1632
1633         int lvl = 10;
1634         DEBUG(lvl,("dump_acct_flags\n"));
1635         if (acct_flags & ACB_NORMAL) {
1636                 DEBUGADD(lvl,("\taccount has ACB_NORMAL\n"));
1637         }
1638         if (acct_flags & ACB_PWNOEXP) {
1639                 DEBUGADD(lvl,("\taccount has ACB_PWNOEXP\n"));
1640         }
1641         if (acct_flags & ACB_ENC_TXT_PWD_ALLOWED) {
1642                 DEBUGADD(lvl,("\taccount has ACB_ENC_TXT_PWD_ALLOWED\n"));
1643         }
1644         if (acct_flags & ACB_NOT_DELEGATED) {
1645                 DEBUGADD(lvl,("\taccount has ACB_NOT_DELEGATED\n"));
1646         }
1647         if (acct_flags & ACB_USE_DES_KEY_ONLY) {
1648                 DEBUGADD(lvl,("\taccount has ACB_USE_DES_KEY_ONLY set, sig verify wont work\n"));
1649         }
1650         if (acct_flags & ACB_NO_AUTH_DATA_REQD) {
1651                 DEBUGADD(lvl,("\taccount has ACB_NO_AUTH_DATA_REQD set\n"));
1652         }
1653         if (acct_flags & ACB_PWEXPIRED) {
1654                 DEBUGADD(lvl,("\taccount has ACB_PWEXPIRED set\n"));
1655         }
1656 }
1657
1658 static void dump_user_flgs(uint32 user_flags) {
1659
1660         int lvl = 10;
1661         DEBUG(lvl,("dump_user_flgs\n"));
1662         if (user_flags & LOGON_EXTRA_SIDS) {
1663                 DEBUGADD(lvl,("\taccount has LOGON_EXTRA_SIDS\n"));
1664         }
1665         if (user_flags & LOGON_RESOURCE_GROUPS) {
1666                 DEBUGADD(lvl,("\taccount has LOGON_RESOURCE_GROUPS\n"));
1667         }
1668         if (user_flags & LOGON_NTLMV2_ENABLED) {
1669                 DEBUGADD(lvl,("\taccount has LOGON_NTLMV2_ENABLED\n"));
1670         }
1671         if (user_flags & LOGON_CACHED_ACCOUNT) {
1672                 DEBUGADD(lvl,("\taccount has LOGON_CACHED_ACCOUNT\n"));
1673         }
1674         if (user_flags & LOGON_PROFILE_PATH_RETURNED) {
1675                 DEBUGADD(lvl,("\taccount has LOGON_PROFILE_PATH_RETURNED\n"));
1676         }
1677         if (user_flags & LOGON_SERVER_TRUST_ACCOUNT) {
1678                 DEBUGADD(lvl,("\taccount has LOGON_SERVER_TRUST_ACCOUNT\n"));
1679         }
1680
1681
1682 }
1683
1684 /*******************************************************************
1685  This code has been modified to cope with a NET_USER_INFO_2 - which is
1686  exactly the same as a NET_USER_INFO_3, minus the other sids parameters.
1687  We use validation level to determine if we're marshalling a info 2 or
1688  INFO_3 - be we always return an INFO_3. Based on code donated by Marc
1689  Jacobsen at HP. JRA.
1690 ********************************************************************/
1691
1692 bool net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, 
1693                        int depth, uint16 validation_level, bool kerb_validation_level)
1694 {
1695         unsigned int i;
1696
1697         if (usr == NULL)
1698                 return False;
1699
1700         prs_debug(ps, depth, desc, "net_io_user_info3");
1701         depth++;
1702
1703         if (UNMARSHALLING(ps))
1704                 ZERO_STRUCTP(usr);
1705
1706         if(!prs_align(ps))
1707                 return False;
1708         
1709         if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info))
1710                 return False;
1711
1712         if (usr->ptr_user_info == 0)
1713                 return True;
1714
1715         if(!smb_io_time("logon time", &usr->logon_time, ps, depth)) /* logon time */
1716                 return False;
1717         if(!smb_io_time("logoff time", &usr->logoff_time, ps, depth)) /* logoff time */
1718                 return False;
1719         if(!smb_io_time("kickoff time", &usr->kickoff_time, ps, depth)) /* kickoff time */
1720                 return False;
1721         if(!smb_io_time("last set time", &usr->pass_last_set_time, ps, depth)) /* password last set time */
1722                 return False;
1723         if(!smb_io_time("can change time", &usr->pass_can_change_time , ps, depth)) /* password can change time */
1724                 return False;
1725         if(!smb_io_time("must change time", &usr->pass_must_change_time, ps, depth)) /* password must change time */
1726                 return False;
1727
1728         if(!smb_io_unihdr("hdr_user_name", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
1729                 return False;
1730         if(!smb_io_unihdr("hdr_full_name", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
1731                 return False;
1732         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
1733                 return False;
1734         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
1735                 return False;
1736         if(!smb_io_unihdr("hdr_home_dir", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
1737                 return False;
1738         if(!smb_io_unihdr("hdr_dir_drive", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */
1739                 return False;
1740
1741         if(!prs_uint16("logon_count   ", ps, depth, &usr->logon_count))  /* logon count */
1742                 return False;
1743         if(!prs_uint16("bad_pw_count  ", ps, depth, &usr->bad_pw_count)) /* bad password count */
1744                 return False;
1745
1746         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))       /* User RID */
1747                 return False;
1748         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))      /* Group RID */
1749                 return False;
1750         if(!prs_uint32("num_groups    ", ps, depth, &usr->num_groups))    /* num groups */
1751                 return False;
1752         if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */
1753                 return False;
1754         if(!prs_uint32("user_flgs     ", ps, depth, &usr->user_flgs))     /* user flags */
1755                 return False;
1756         dump_user_flgs(usr->user_flgs);
1757         if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* user session key */
1758                 return False;
1759
1760         if(!smb_io_unihdr("hdr_logon_srv", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */
1761                 return False;
1762         if(!smb_io_unihdr("hdr_logon_dom", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */
1763                 return False;
1764
1765         if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */
1766                 return False;
1767
1768         if(!prs_uint8s(False, "lm_sess_key", ps, depth, usr->lm_sess_key, 8)) /* lm session key */
1769                 return False;
1770
1771         if(!prs_uint32("acct_flags ", ps, depth, &usr->acct_flags)) /* Account flags  */
1772                 return False;
1773         dump_acct_flags(usr->acct_flags);
1774         for (i = 0; i < 7; i++)
1775         {
1776                 if (!prs_uint32("unkown", ps, depth, &usr->unknown[i])) /* unknown */
1777                         return False;
1778         }
1779
1780         if (validation_level == 3) {
1781                 if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */
1782                         return False;
1783                 if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */
1784                         return False;
1785         } else {
1786                 if (UNMARSHALLING(ps)) {
1787                         usr->num_other_sids = 0;
1788                         usr->buffer_other_sids = 0;
1789                 }
1790         }
1791                 
1792         /* get kerb validation info (not really part of user_info_3) - Guenther */
1793
1794         if (kerb_validation_level) {
1795
1796                 if(!prs_uint32("ptr_res_group_dom_sid", ps, depth, &usr->ptr_res_group_dom_sid))
1797                         return False;
1798                 if(!prs_uint32("res_group_count", ps, depth, &usr->res_group_count))
1799                         return False;
1800                 if(!prs_uint32("ptr_res_groups", ps, depth, &usr->ptr_res_groups))
1801                         return False;
1802         }
1803
1804         if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
1805                 return False;
1806         if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
1807                 return False;
1808         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
1809                 return False;
1810         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
1811                 return False;
1812         if(!smb_io_unistr2("uni_home_dir", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
1813                 return False;
1814         if(!smb_io_unistr2("uni_dir_drive", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
1815                 return False;
1816
1817         if(!prs_align(ps))
1818                 return False;
1819
1820         if(!prs_uint32("num_groups2   ", ps, depth, &usr->num_groups2))        /* num groups2 */
1821                 return False;
1822
1823         if (usr->num_groups != usr->num_groups2) {
1824                 DEBUG(3,("net_io_user_info3: num_groups mismatch! (%d != %d)\n", 
1825                          usr->num_groups, usr->num_groups2));
1826                 return False;
1827         }
1828
1829         if (UNMARSHALLING(ps)) {
1830                 if (usr->num_groups) {
1831                         usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups);
1832                         if (usr->gids == NULL)
1833                                 return False;
1834                 } else {
1835                         usr->gids = NULL;
1836                 }
1837         }
1838
1839         for (i = 0; i < usr->num_groups; i++) {
1840                 if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */
1841                         return False;
1842         }
1843
1844         if(!smb_io_unistr2("uni_logon_srv", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */
1845                 return False;
1846         if(!smb_io_unistr2("uni_logon_dom", &usr->uni_logon_dom, usr->hdr_logon_dom.buffer, ps, depth)) /* logon domain unicode string */
1847                 return False;
1848
1849         if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth))           /* domain SID */
1850                 return False;
1851
1852         if (validation_level == 3 && usr->buffer_other_sids) {
1853
1854                 uint32 num_other_sids = usr->num_other_sids;
1855
1856                 if (!(usr->user_flgs & LOGON_EXTRA_SIDS)) {
1857                         DEBUG(10,("net_io_user_info3: user_flgs attribute does not have LOGON_EXTRA_SIDS\n"));
1858                         /* return False; */
1859                 }
1860
1861                 if (!prs_uint32("num_other_sids", ps, depth,
1862                                 &num_other_sids))
1863                         return False;
1864
1865                 if (num_other_sids != usr->num_other_sids)
1866                         return False;
1867
1868                 if (UNMARSHALLING(ps)) {
1869                         if (usr->num_other_sids) {
1870                                 usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
1871                                 usr->other_sids_attrib =
1872                                         PRS_ALLOC_MEM(ps, uint32, usr->num_other_sids);
1873                         } else {
1874                                 usr->other_sids = NULL;
1875                                 usr->other_sids_attrib = NULL;
1876                         }
1877
1878                         if ((num_other_sids != 0) &&
1879                             ((usr->other_sids == NULL) ||
1880                              (usr->other_sids_attrib == NULL)))
1881                                 return False;
1882                 }
1883
1884                 /* First the pointers to the SIDS and attributes */
1885
1886                 depth++;
1887
1888                 for (i=0; i<usr->num_other_sids; i++) {
1889                         uint32 ptr = 1;
1890
1891                         if (!prs_uint32("sid_ptr", ps, depth, &ptr))
1892                                 return False;
1893
1894                         if (UNMARSHALLING(ps) && (ptr == 0))
1895                                 return False;
1896
1897                         if (!prs_uint32("attribute", ps, depth,
1898                                         &usr->other_sids_attrib[i]))
1899                                 return False;
1900                 }
1901         
1902                 for (i = 0; i < usr->num_other_sids; i++) {
1903                         if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */
1904                                 return False;
1905                 }
1906
1907                 depth--;
1908         }
1909
1910         return True;
1911 }
1912
1913 /*******************************************************************
1914  Reads or writes a structure.
1915 ********************************************************************/
1916
1917 bool net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
1918 {
1919         if (q_l == NULL)
1920                 return False;
1921
1922         prs_debug(ps, depth, desc, "net_io_q_sam_logon");
1923         depth++;
1924
1925         if(!prs_align(ps))
1926                 return False;
1927         
1928         if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))
1929                 return False;
1930
1931         if(!prs_align_uint16(ps))
1932                 return False;
1933
1934         if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1935                 return False;
1936
1937         return True;
1938 }
1939
1940 /*******************************************************************
1941  Reads or writes a structure.
1942 ********************************************************************/
1943
1944 bool net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
1945 {
1946         if (r_l == NULL)
1947                 return False;
1948
1949         prs_debug(ps, depth, desc, "net_io_r_sam_logon");
1950         depth++;
1951
1952         if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1953                 return False;
1954         if (&r_l->buffer_creds) {
1955                 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials.  server time stamp appears to be ignored. */
1956                         return False;
1957         }
1958
1959         if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
1960                 return False;
1961         if(!prs_align(ps))
1962                 return False;
1963
1964 #if 1 /* W2k always needs this - even for bad passwd. JRA */
1965         if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1966                 return False;
1967 #else
1968         if (r_l->switch_value != 0) {
1969                 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1970                         return False;
1971         }
1972 #endif
1973
1974         if(!prs_uint32("auth_resp   ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
1975                 return False;
1976
1977         if(!prs_ntstatus("status      ", ps, depth, &r_l->status))
1978                 return False;
1979
1980         if(!prs_align(ps))
1981                 return False;
1982
1983         return True;
1984 }
1985
1986 /*******************************************************************
1987  Reads or writes a structure.
1988 ********************************************************************/
1989
1990 bool net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct *ps, int depth)
1991 {
1992         if (q_l == NULL)
1993                 return False;
1994
1995         prs_debug(ps, depth, desc, "net_io_q_sam_logon_ex");
1996         depth++;
1997
1998         if(!prs_align(ps))
1999                 return False;
2000         
2001         if(!smb_io_sam_info_ex("", &q_l->sam_id, ps, depth))
2002                 return False;
2003
2004         if(!prs_align_uint16(ps))
2005                 return False;
2006
2007         if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
2008                 return False;
2009
2010         if (!prs_align(ps))
2011                 return False;
2012
2013         if(!prs_uint32("flags  ", ps, depth, &q_l->flags))
2014                 return False;
2015
2016         return True;
2017 }
2018
2019 /*******************************************************************
2020  Reads or writes a structure.
2021 ********************************************************************/
2022
2023 bool net_io_r_sam_logon_ex(const char *desc, NET_R_SAM_LOGON_EX *r_l, prs_struct *ps, int depth)
2024 {
2025         if (r_l == NULL)
2026                 return False;
2027
2028         prs_debug(ps, depth, desc, "net_io_r_sam_logon_ex");
2029         depth++;
2030
2031         if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
2032                 return False;
2033         if(!prs_align(ps))
2034                 return False;
2035
2036 #if 1 /* W2k always needs this - even for bad passwd. JRA */
2037         if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
2038                 return False;
2039 #else
2040         if (r_l->switch_value != 0) {
2041                 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
2042                         return False;
2043         }
2044 #endif
2045
2046         if(!prs_uint32("auth_resp   ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
2047                 return False;
2048
2049         if(!prs_uint32("flags   ", ps, depth, &r_l->flags))
2050                 return False;
2051
2052         if(!prs_ntstatus("status      ", ps, depth, &r_l->status))
2053                 return False;
2054
2055         if(!prs_align(ps))
2056                 return False;
2057
2058         return True;
2059 }
2060
2061
2062 /*******************************************************************
2063  Reads or writes a structure.
2064 ********************************************************************/
2065
2066 bool net_io_q_sam_logoff(const char *desc,  NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
2067 {
2068         if (q_l == NULL)
2069                 return False;
2070
2071         prs_debug(ps, depth, desc, "net_io_q_sam_logoff");
2072         depth++;
2073
2074         if(!prs_align(ps))
2075                 return False;
2076         
2077         if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))           /* domain SID */
2078                 return False;
2079
2080         return True;
2081 }
2082
2083 /*******************************************************************
2084  Reads or writes a structure.
2085 ********************************************************************/
2086
2087 bool net_io_r_sam_logoff(const char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
2088 {
2089         if (r_l == NULL)
2090                 return False;
2091
2092         prs_debug(ps, depth, desc, "net_io_r_sam_logoff");
2093         depth++;
2094
2095         if(!prs_align(ps))
2096                 return False;
2097         
2098         if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
2099                 return False;
2100         if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials.  server time stamp appears to be ignored. */
2101                 return False;
2102
2103         if(!prs_ntstatus("status      ", ps, depth, &r_l->status))
2104                 return False;
2105
2106         return True;
2107 }
2108
2109 /*******************************************************************
2110 makes a NET_Q_SAM_SYNC structure.
2111 ********************************************************************/
2112 bool init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
2113                          const char *cli_name, DOM_CRED *cli_creds, 
2114                          DOM_CRED *ret_creds, uint32 database_id, 
2115                          uint32 next_rid)
2116 {
2117         DEBUG(5, ("init_q_sam_sync\n"));
2118
2119         init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
2120         init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
2121
2122         if (cli_creds)
2123                 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
2124
2125         if (cli_creds)
2126                 memcpy(&q_s->ret_creds, ret_creds, sizeof(q_s->ret_creds));
2127         else
2128                 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
2129
2130         q_s->database_id = database_id;
2131         q_s->restart_state = 0;
2132         q_s->sync_context = next_rid;
2133         q_s->max_size = 0xffff;
2134
2135         return True;
2136 }
2137
2138 /*******************************************************************
2139 reads or writes a structure.
2140 ********************************************************************/
2141 bool net_io_q_sam_sync(const char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
2142                        int depth)
2143 {
2144         prs_debug(ps, depth, desc, "net_io_q_sam_sync");
2145         depth++;
2146
2147         if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
2148                 return False;
2149         if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
2150                 return False;
2151
2152         if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
2153                 return False;
2154         if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
2155                 return False;
2156
2157         if (!prs_uint32("database_id  ", ps, depth, &q_s->database_id))
2158                 return False;
2159         if (!prs_uint32("restart_state", ps, depth, &q_s->restart_state))
2160                 return False;
2161         if (!prs_uint32("sync_context ", ps, depth, &q_s->sync_context))
2162                 return False;
2163
2164         if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
2165                 return False;
2166
2167         return True;
2168 }
2169
2170 /*******************************************************************
2171 reads or writes a structure.
2172 ********************************************************************/
2173 static bool net_io_sam_delta_hdr(const char *desc, SAM_DELTA_HDR * delta,
2174                                  prs_struct *ps, int depth)
2175 {
2176         prs_debug(ps, depth, desc, "net_io_sam_delta_hdr");
2177         depth++;
2178
2179         if (!prs_uint16("type", ps, depth, &delta->type))
2180                 return False;
2181         if (!prs_uint16("type2", ps, depth, &delta->type2))
2182                 return False;
2183         if (!prs_uint32("target_rid", ps, depth, &delta->target_rid))
2184                 return False;
2185
2186         if (!prs_uint32("type3", ps, depth, &delta->type3))
2187                 return False;
2188
2189         /* Not sure why we need this but it seems to be necessary to get
2190            sam deltas working. */
2191
2192         if (delta->type != 0x16) {
2193                 if (!prs_uint32("ptr_delta", ps, depth, &delta->ptr_delta))
2194                         return False;
2195         }
2196
2197         return True;
2198 }
2199
2200 /*******************************************************************
2201 reads or writes a structure.
2202 ********************************************************************/
2203 static bool net_io_sam_delta_mod_count(const char *desc, SAM_DELTA_MOD_COUNT *info,
2204                                    prs_struct *ps, int depth)
2205 {
2206         prs_debug(ps, depth, desc, "net_io_sam_delta_stamp");
2207         depth++;
2208
2209         if (!prs_uint32("seqnum", ps, depth, &info->seqnum))
2210                 return False;
2211         if (!prs_uint32("dom_mod_count_ptr", ps, depth, 
2212                         &info->dom_mod_count_ptr))
2213                 return False;
2214
2215         if (info->dom_mod_count_ptr) {
2216                 if (!prs_uint64("dom_mod_count", ps, depth,
2217                                 &info->dom_mod_count))
2218                         return False;
2219         }
2220
2221         return True;
2222 }
2223
2224 /*******************************************************************
2225 reads or writes a structure.
2226 ********************************************************************/
2227 static bool net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
2228                                    prs_struct *ps, int depth)
2229 {
2230         prs_debug(ps, depth, desc, "net_io_sam_domain_info");
2231         depth++;
2232
2233         if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2234                 return False;
2235         if (!smb_io_unihdr("hdr_oem_info", &info->hdr_oem_info, ps, depth))
2236                 return False;
2237
2238         if (!prs_uint64("force_logoff", ps, depth, &info->force_logoff))
2239                 return False;
2240         if (!prs_uint16("min_pwd_len", ps, depth, &info->min_pwd_len))
2241                 return False;
2242         if (!prs_uint16("pwd_history_len", ps, depth, &info->pwd_history_len))
2243                 return False;
2244         if (!prs_uint64("max_pwd_age", ps, depth, &info->max_pwd_age))
2245                 return False;
2246         if (!prs_uint64("min_pwd_age", ps, depth, &info->min_pwd_age))
2247                 return False;
2248         if (!prs_uint64("dom_mod_count", ps, depth, &info->dom_mod_count))
2249                 return False;
2250         if (!smb_io_time("creation_time", &info->creation_time, ps, depth))
2251                 return False;
2252         if (!prs_uint32("security_information", ps, depth, &info->security_information))
2253                 return False;
2254         if (!smb_io_bufhdr4("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2255                 return False;
2256         if (!smb_io_lockout_string_hdr("hdr_account_lockout_string", &info->hdr_account_lockout, ps, depth))
2257                 return False;
2258         if (!smb_io_unihdr("hdr_unknown2", &info->hdr_unknown2, ps, depth))
2259                 return False;
2260         if (!smb_io_unihdr("hdr_unknown3", &info->hdr_unknown3, ps, depth))
2261                 return False;
2262         if (!smb_io_unihdr("hdr_unknown4", &info->hdr_unknown4, ps, depth))
2263                 return False;
2264         if (!prs_uint32("logon_chgpass", ps, depth, &info->logon_chgpass))
2265                 return False;
2266         if (!prs_uint32("unknown6", ps, depth, &info->unknown6))
2267                 return False;
2268         if (!prs_uint32("unknown7", ps, depth, &info->unknown7))
2269                 return False;
2270         if (!prs_uint32("unknown8", ps, depth, &info->unknown8))
2271                 return False;
2272
2273         if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
2274                             info->hdr_dom_name.buffer, ps, depth))
2275                 return False;
2276         if (!smb_io_unistr2("buf_oem_info", &info->buf_oem_info,
2277                             info->hdr_oem_info.buffer, ps, depth))
2278                 return False;
2279
2280         if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2281                 return False;
2282
2283         if (!smb_io_account_lockout_str("account_lockout", &info->account_lockout, 
2284                                         info->hdr_account_lockout.buffer, ps, depth))
2285                 return False;
2286
2287         if (!smb_io_unistr2("buf_unknown2", &info->buf_unknown2, 
2288                             info->hdr_unknown2.buffer, ps, depth))
2289                 return False;
2290         if (!smb_io_unistr2("buf_unknown3", &info->buf_unknown3, 
2291                             info->hdr_unknown3.buffer, ps, depth))
2292                 return False;
2293         if (!smb_io_unistr2("buf_unknown4", &info->buf_unknown4, 
2294                             info->hdr_unknown4.buffer, ps, depth))
2295                 return False;
2296
2297         return True;
2298 }
2299
2300 /*******************************************************************
2301 reads or writes a structure.
2302 ********************************************************************/
2303 static bool net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
2304                                   prs_struct *ps, int depth)
2305 {
2306         prs_debug(ps, depth, desc, "net_io_sam_group_info");
2307         depth++;
2308
2309         if (!smb_io_unihdr("hdr_grp_name", &info->hdr_grp_name, ps, depth))
2310                 return False;
2311         if (!smb_io_gid("gid", &info->gid, ps, depth))
2312                 return False;
2313         if (!smb_io_unihdr("hdr_grp_desc", &info->hdr_grp_desc, ps, depth))
2314                 return False;
2315         if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2316                 return False;
2317
2318         if (ps->data_offset + 48 > ps->buffer_size)
2319                 return False;
2320         ps->data_offset += 48;
2321
2322         if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
2323                             info->hdr_grp_name.buffer, ps, depth))
2324                 return False;
2325         if (!smb_io_unistr2("uni_grp_desc", &info->uni_grp_desc,
2326                             info->hdr_grp_desc.buffer, ps, depth))
2327                 return False;
2328         if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2329                 return False;
2330
2331         return True;
2332 }
2333
2334 /*******************************************************************
2335 reads or writes a structure.
2336 ********************************************************************/
2337 static bool net_io_sam_passwd_info(const char *desc, SAM_PWD * pwd,
2338                                    prs_struct *ps, int depth)
2339 {
2340         prs_debug(ps, depth, desc, "net_io_sam_passwd_info");
2341         depth++;
2342
2343         if (!prs_uint32("unk_0 ", ps, depth, &pwd->unk_0))
2344                 return False;
2345
2346         if (!smb_io_unihdr("hdr_lm_pwd", &pwd->hdr_lm_pwd, ps, depth))
2347                 return False;
2348         if (!prs_uint8s(False, "buf_lm_pwd", ps, depth, pwd->buf_lm_pwd, 16))
2349                 return False;
2350
2351         if (!smb_io_unihdr("hdr_nt_pwd", &pwd->hdr_nt_pwd, ps, depth))
2352                 return False;
2353         if (!prs_uint8s(False, "buf_nt_pwd", ps, depth, pwd->buf_nt_pwd, 16))
2354                 return False;
2355
2356         if (!smb_io_unihdr("", &pwd->hdr_empty_lm, ps, depth))
2357                 return False;
2358         if (!smb_io_unihdr("", &pwd->hdr_empty_nt, ps, depth))
2359                 return False;
2360
2361         return True;
2362 }
2363
2364 /*******************************************************************
2365 reads or writes a structure.
2366 ********************************************************************/
2367 static bool net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
2368                                 prs_struct *ps, int depth)
2369 {
2370         BUFHDR2 hdr_priv_data;
2371         uint32 i;
2372
2373         prs_debug(ps, depth, desc, "net_io_sam_account_info");
2374         depth++;
2375
2376         if (!smb_io_unihdr("hdr_acct_name", &info->hdr_acct_name, ps, depth))
2377                 return False;
2378         if (!smb_io_unihdr("hdr_full_name", &info->hdr_full_name, ps, depth))
2379                 return False;
2380
2381         if (!prs_uint32("user_rid ", ps, depth, &info->user_rid))
2382                 return False;
2383         if (!prs_uint32("group_rid", ps, depth, &info->group_rid))
2384                 return False;
2385
2386         if (!smb_io_unihdr("hdr_home_dir ", &info->hdr_home_dir, ps, depth))
2387                 return False;
2388         if (!smb_io_unihdr("hdr_dir_drive", &info->hdr_dir_drive, ps, depth))
2389                 return False;
2390         if (!smb_io_unihdr("hdr_logon_script", &info->hdr_logon_script, ps,
2391                            depth))
2392                 return False;
2393
2394         if (!smb_io_unihdr("hdr_acct_desc", &info->hdr_acct_desc, ps, depth))
2395                 return False;
2396         if (!smb_io_unihdr("hdr_workstations", &info->hdr_workstations, ps,
2397                            depth))
2398                 return False;
2399
2400         if (!smb_io_time("logon_time", &info->logon_time, ps, depth))
2401                 return False;
2402         if (!smb_io_time("logoff_time", &info->logoff_time, ps, depth))
2403                 return False;
2404
2405         if (!prs_uint32("logon_divs   ", ps, depth, &info->logon_divs))
2406                 return False;
2407         if (!prs_uint32("ptr_logon_hrs", ps, depth, &info->ptr_logon_hrs))
2408                 return False;
2409
2410         if (!prs_uint16("bad_pwd_count", ps, depth, &info->bad_pwd_count))
2411                 return False;
2412         if (!prs_uint16("logon_count", ps, depth, &info->logon_count))
2413                 return False;
2414         if (!smb_io_time("pwd_last_set_time", &info->pwd_last_set_time, ps,
2415                          depth))
2416                 return False;
2417         if (!smb_io_time("acct_expiry_time", &info->acct_expiry_time, ps, 
2418                          depth))
2419                 return False;
2420
2421         if (!prs_uint32("acb_info", ps, depth, &info->acb_info))
2422                 return False;
2423         if (!prs_uint8s(False, "nt_pwd", ps, depth, info->nt_pwd, 16))
2424                 return False;
2425         if (!prs_uint8s(False, "lm_pwd", ps, depth, info->lm_pwd, 16))
2426                 return False;
2427         if (!prs_uint8("lm_pwd_present", ps, depth, &info->lm_pwd_present))
2428                 return False;
2429         if (!prs_uint8("nt_pwd_present", ps, depth, &info->nt_pwd_present))
2430                 return False;
2431         if (!prs_uint8("pwd_expired", ps, depth, &info->pwd_expired))
2432                 return False;
2433
2434         if (!smb_io_unihdr("hdr_comment", &info->hdr_comment, ps, depth))
2435                 return False;
2436         if (!smb_io_unihdr("hdr_parameters", &info->hdr_parameters, ps, 
2437                            depth))
2438                 return False;
2439         if (!prs_uint16("country", ps, depth, &info->country))
2440                 return False;
2441         if (!prs_uint16("codepage", ps, depth, &info->codepage))
2442                 return False;
2443
2444         if (!smb_io_bufhdr2("hdr_priv_data", &hdr_priv_data, ps, depth))
2445                 return False;
2446         if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2447                 return False;
2448         if (!smb_io_unihdr("hdr_profile", &info->hdr_profile, ps, depth))
2449                 return False;
2450
2451         for (i = 0; i < 3; i++)
2452         {
2453                 if (!smb_io_unihdr("hdr_reserved", &info->hdr_reserved[i], 
2454                                    ps, depth))
2455                         return False;                                          
2456         }
2457
2458         for (i = 0; i < 4; i++)
2459         {
2460                 if (!prs_uint32("dw_reserved", ps, depth, 
2461                                 &info->dw_reserved[i]))
2462                         return False;
2463         }
2464
2465         if (!smb_io_unistr2("uni_acct_name", &info->uni_acct_name,
2466                             info->hdr_acct_name.buffer, ps, depth))
2467                 return False;
2468         prs_align(ps);
2469         if (!smb_io_unistr2("uni_full_name", &info->uni_full_name,
2470                             info->hdr_full_name.buffer, ps, depth))
2471                 return False;
2472         prs_align(ps);
2473         if (!smb_io_unistr2("uni_home_dir ", &info->uni_home_dir,
2474                             info->hdr_home_dir.buffer, ps, depth))
2475                 return False;
2476         prs_align(ps);
2477         if (!smb_io_unistr2("uni_dir_drive", &info->uni_dir_drive,
2478                             info->hdr_dir_drive.buffer, ps, depth))
2479                 return False;
2480         prs_align(ps);
2481         if (!smb_io_unistr2("uni_logon_script", &info->uni_logon_script,
2482                             info->hdr_logon_script.buffer, ps, depth))
2483                 return False;
2484         prs_align(ps);
2485         if (!smb_io_unistr2("uni_acct_desc", &info->uni_acct_desc,
2486                             info->hdr_acct_desc.buffer, ps, depth))
2487                 return False;
2488         prs_align(ps);
2489         if (!smb_io_unistr2("uni_workstations", &info->uni_workstations,
2490                             info->hdr_workstations.buffer, ps, depth))
2491                 return False;
2492         prs_align(ps);
2493
2494         if (!prs_uint32("unknown1", ps, depth, &info->unknown1))
2495                 return False;
2496         if (!prs_uint32("unknown2", ps, depth, &info->unknown2))
2497                 return False;
2498
2499         if (!smb_io_rpc_blob("buf_logon_hrs", &info->buf_logon_hrs, ps, depth))
2500                 return False;
2501         prs_align(ps);
2502         if (!smb_io_unistr2("uni_comment", &info->uni_comment,
2503                             info->hdr_comment.buffer, ps, depth))
2504                 return False;
2505         prs_align(ps);
2506         if (!smb_io_unistr2("uni_parameters", &info->uni_parameters,
2507                             info->hdr_parameters.buffer, ps, depth))
2508                 return False;
2509         prs_align(ps);
2510         if (hdr_priv_data.buffer != 0)
2511         {
2512                 int old_offset = 0;
2513                 uint32 len = 0x44;
2514                 if (!prs_uint32("pwd_len", ps, depth, &len))
2515                         return False;
2516                 old_offset = ps->data_offset;
2517                 if (len > 0)
2518                 {
2519                         if (ps->io)
2520                         {
2521                                 /* reading */
2522                                 if (!prs_hash1(ps, ps->data_offset, len))
2523                                         return False;
2524                         }
2525                         if (!net_io_sam_passwd_info("pass", &info->pass, 
2526                                                     ps, depth))
2527                                 return False;
2528
2529                         if (!ps->io)
2530                         {
2531                                 /* writing */
2532                                 if (!prs_hash1(ps, old_offset, len))
2533                                         return False;
2534                         }
2535                 }
2536                 if (old_offset + len > ps->buffer_size)
2537                         return False;
2538                 ps->data_offset = old_offset + len;
2539         }
2540         if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2541                 return False;
2542         prs_align(ps);
2543         if (!smb_io_unistr2("uni_profile", &info->uni_profile,
2544                             info->hdr_profile.buffer, ps, depth))
2545                 return False;
2546
2547         prs_align(ps);
2548
2549         return True;
2550 }
2551
2552 /*******************************************************************
2553 reads or writes a structure.
2554 ********************************************************************/
2555 static bool net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * info,
2556                                       prs_struct *ps, int depth)
2557 {
2558         uint32 i;
2559         fstring tmp;
2560
2561         prs_debug(ps, depth, desc, "net_io_sam_group_mem_info");
2562         depth++;
2563
2564         prs_align(ps);
2565         if (!prs_uint32("ptr_rids   ", ps, depth, &info->ptr_rids))
2566                 return False;
2567         if (!prs_uint32("ptr_attribs", ps, depth, &info->ptr_attribs))
2568                 return False;
2569         if (!prs_uint32("num_members", ps, depth, &info->num_members))
2570                 return False;
2571
2572         if (ps->data_offset + 16 > ps->buffer_size)
2573                 return False;
2574         ps->data_offset += 16;
2575
2576         if (info->ptr_rids != 0)
2577         {
2578                 if (!prs_uint32("num_members2", ps, depth, 
2579                                 &info->num_members2))
2580                         return False;
2581
2582                 if (info->num_members2 != info->num_members)
2583                 {
2584                         /* RPC fault */
2585                         return False;
2586                 }
2587
2588                 if (UNMARSHALLING(ps)) {
2589                         if (info->num_members2) {
2590                                 info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
2591
2592                                 if (info->rids == NULL) {
2593                                         DEBUG(0, ("out of memory allocating %d rids\n",
2594                                                 info->num_members2));
2595                                         return False;
2596                                 }
2597                         } else {
2598                                 info->rids = NULL;
2599                         }
2600                 }
2601
2602                 for (i = 0; i < info->num_members2; i++)
2603                 {
2604                         slprintf(tmp, sizeof(tmp) - 1, "rids[%02d]", i);
2605                         if (!prs_uint32(tmp, ps, depth, &info->rids[i]))
2606                                 return False;
2607                 }
2608         }
2609
2610         if (info->ptr_attribs != 0)
2611         {
2612                 if (!prs_uint32("num_members3", ps, depth, 
2613                                 &info->num_members3))
2614                         return False;
2615                 if (info->num_members3 != info->num_members)
2616                 {
2617                         /* RPC fault */
2618                         return False;
2619                 }
2620
2621                 if (UNMARSHALLING(ps)) {
2622                         if (info->num_members3) {
2623                                 info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
2624
2625                                 if (info->attribs == NULL) {
2626                                         DEBUG(0, ("out of memory allocating %d attribs\n",
2627                                                 info->num_members3));
2628                                         return False;
2629                                 }
2630                         } else {
2631                                 info->attribs = NULL;
2632                         }
2633                 }       
2634
2635                 for (i = 0; i < info->num_members3; i++)
2636                 {
2637                         slprintf(tmp, sizeof(tmp) - 1, "attribs[%02d]", i);
2638                         if (!prs_uint32(tmp, ps, depth, &info->attribs[i]))
2639                                 return False;
2640                 }
2641         }
2642
2643         return True;
2644 }
2645
2646 /*******************************************************************
2647 reads or writes a structure.
2648 ********************************************************************/
2649 static bool net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
2650                                   prs_struct *ps, int depth)
2651 {
2652         prs_debug(ps, depth, desc, "net_io_sam_alias_info");
2653         depth++;
2654
2655         if (!smb_io_unihdr("hdr_als_name", &info->hdr_als_name, ps, depth))
2656                 return False;
2657         if (!prs_uint32("als_rid", ps, depth, &info->als_rid))
2658                 return False;
2659         if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2660                 return False;
2661         if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
2662                 return False;
2663
2664         if (ps->data_offset + 40 > ps->buffer_size)
2665                 return False;
2666         ps->data_offset += 40;
2667
2668         if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
2669                             info->hdr_als_name.buffer, ps, depth))
2670                 return False;
2671         if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2672                 return False;
2673
2674         if (!smb_io_unistr2("uni_als_desc", &info->uni_als_desc,
2675                             info->hdr_als_desc.buffer, ps, depth))
2676                 return False;
2677
2678         return True;
2679 }
2680
2681 /*******************************************************************
2682 reads or writes a structure.
2683 ********************************************************************/
2684 static bool net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * info,
2685                                       prs_struct *ps, int depth)
2686 {
2687         uint32 i;
2688         fstring tmp;
2689
2690         prs_debug(ps, depth, desc, "net_io_sam_alias_mem_info");
2691         depth++;
2692
2693         prs_align(ps);
2694         if (!prs_uint32("num_members", ps, depth, &info->num_members))
2695                 return False;
2696         if (!prs_uint32("ptr_members", ps, depth, &info->ptr_members))
2697                 return False;
2698
2699         if (ps->data_offset + 16 > ps->buffer_size)
2700                 return False;
2701         ps->data_offset += 16;
2702
2703         if (info->ptr_members != 0)
2704         {
2705                 if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
2706                         return False;
2707                 if (info->num_sids != info->num_members)
2708                 {
2709                         /* RPC fault */
2710                         return False;
2711                 }
2712
2713                 if (UNMARSHALLING(ps)) {
2714                         if (info->num_sids) {
2715                                 info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
2716                 
2717                                 if (info->ptr_sids == NULL) {
2718                                         DEBUG(0, ("out of memory allocating %d ptr_sids\n",
2719                                                 info->num_sids));
2720                                         return False;
2721                                 }
2722                         } else {
2723                                 info->ptr_sids = NULL;
2724                         }
2725                 }
2726
2727                 for (i = 0; i < info->num_sids; i++)
2728                 {
2729                         slprintf(tmp, sizeof(tmp) - 1, "ptr_sids[%02d]", i);
2730                         if (!prs_uint32(tmp, ps, depth, &info->ptr_sids[i]))
2731                                 return False;
2732                 }
2733
2734                 if (UNMARSHALLING(ps)) {
2735                         if (info->num_sids) {
2736                                 info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
2737
2738                                 if (info->sids == NULL) {
2739                                         DEBUG(0, ("error allocating %d sids\n",
2740                                                 info->num_sids));
2741                                         return False;
2742                                 }
2743                         } else {
2744                                 info->sids = NULL;
2745                         }
2746                 }
2747
2748                 for (i = 0; i < info->num_sids; i++)
2749                 {
2750                         if (info->ptr_sids[i] != 0)
2751                         {
2752                                 slprintf(tmp, sizeof(tmp) - 1, "sids[%02d]",
2753                                          i);
2754                                 if (!smb_io_dom_sid2(tmp, &info->sids[i], 
2755                                                      ps, depth))
2756                                         return False;
2757                         }
2758                 }
2759         }
2760
2761         return True;
2762 }
2763
2764 /*******************************************************************
2765 reads or writes a structure.
2766 ********************************************************************/
2767 static bool net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
2768                                       prs_struct *ps, int depth)
2769 {
2770         unsigned int i;
2771         prs_debug(ps, depth, desc, "net_io_sam_policy_info");
2772         depth++;
2773
2774         if(!prs_align(ps))
2775                 return False;
2776
2777         if (!prs_uint32("max_log_size", ps, depth, &info->max_log_size))
2778                 return False;
2779         if (!prs_uint64("audit_retention_period", ps, depth,
2780                         &info->audit_retention_period))
2781                 return False;
2782         if (!prs_uint32("auditing_mode", ps, depth, &info->auditing_mode))
2783                 return False;
2784         if (!prs_uint32("num_events", ps, depth, &info->num_events))
2785                 return False;
2786         if (!prs_uint32("ptr_events", ps, depth, &info->ptr_events))
2787                 return False;
2788
2789         if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2790                 return False;
2791
2792         if (!prs_uint32("sid_ptr", ps, depth, &info->sid_ptr))
2793                 return False;
2794
2795         if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2796                 return False;
2797         if (!prs_uint32("non_paged_pool_limit", ps, depth,
2798                         &info->non_paged_pool_limit))
2799                 return False;
2800         if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
2801                 return False;
2802         if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
2803                 return False;
2804         if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
2805                 return False;
2806         if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
2807                 return False;
2808         if (!smb_io_time("modify_time", &info->modify_time, ps, depth))
2809                 return False;
2810         if (!smb_io_time("create_time", &info->create_time, ps, depth))
2811                 return False;
2812         if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2813                 return False;
2814
2815         for (i=0; i<4; i++) {
2816                 UNIHDR dummy;
2817                 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
2818                         return False;
2819         }
2820
2821         for (i=0; i<4; i++) {
2822                 uint32 reserved;
2823                 if (!prs_uint32("reserved", ps, depth, &reserved))
2824                         return False;
2825         }
2826
2827         if (!prs_uint32("num_event_audit_options", ps, depth,
2828                         &info->num_event_audit_options))
2829                 return False;
2830
2831         for (i=0; i<info->num_event_audit_options; i++)
2832                 if (!prs_uint32("event_audit_option", ps, depth,
2833                                 &info->event_audit_option))
2834                         return False;
2835
2836         if (!smb_io_unistr2("domain_name", &info->domain_name, True, ps, depth))
2837                 return False;
2838
2839         if(!smb_io_dom_sid2("domain_sid", &info->domain_sid, ps, depth))
2840                 return False;
2841
2842         if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2843
2844                 return False;
2845
2846         return True;
2847 }
2848
2849 #if 0
2850
2851 /* This function is pretty broken - see bug #334 */
2852
2853 /*******************************************************************
2854 reads or writes a structure.
2855 ********************************************************************/
2856 static bool net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *info,
2857                                       prs_struct *ps, int depth)
2858 {
2859         int i;
2860
2861         prs_debug(ps, depth, desc, "net_io_sam_trustdoms_info");
2862         depth++;
2863
2864         if(!prs_align(ps))
2865                 return False;
2866
2867         if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2868                 return False;
2869
2870         if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2871                 return False;
2872
2873         if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2874                 return False;
2875
2876         if(!smb_io_unihdr("hdr_domain", &info->hdr_domain, ps, depth))
2877                 return False;
2878
2879         if(!prs_uint32("unknown0", ps, depth, &info->unknown0))
2880                 return False;
2881         if(!prs_uint32("unknown1", ps, depth, &info->unknown1))
2882                 return False;
2883         if(!prs_uint32("unknown2", ps, depth, &info->unknown2))
2884                 return False;
2885
2886         if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2887                 return False;
2888         if(!prs_uint32("ptr", ps, depth, &info->ptr))
2889                 return False;
2890
2891         for (i=0; i<12; i++)
2892                 if(!prs_uint32("unknown3", ps, depth, &info->unknown3))
2893                         return False;
2894
2895         if (!smb_io_unistr2("domain", &info->domain, True, ps, depth))
2896                 return False;
2897
2898         return True;
2899 }
2900
2901 #endif
2902
2903 #if 0
2904
2905 /* This function doesn't work - see bug #334 */
2906
2907 /*******************************************************************
2908 reads or writes a structure.
2909 ********************************************************************/
2910 static bool net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
2911                                    prs_struct *ps, int depth)
2912 {
2913         int i;
2914
2915         prs_debug(ps, depth, desc, "net_io_sam_secret_info");
2916         depth++;
2917
2918         if(!prs_align(ps))
2919                 return False;
2920
2921         if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2922                 return False;
2923
2924         if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2925                 return False;
2926
2927         if (!smb_io_unistr2("secret", &info->secret, True, ps, depth))
2928                 return False;
2929
2930         if(!prs_align(ps))
2931                 return False;
2932
2933         if(!prs_uint32("count1", ps, depth, &info->count1))
2934                 return False;
2935         if(!prs_uint32("count2", ps, depth, &info->count2))
2936                 return False;
2937         if(!prs_uint32("ptr", ps, depth, &info->ptr))
2938                 return False;
2939
2940
2941         if(!smb_io_time("time1", &info->time1, ps, depth)) /* logon time */
2942                 return False;
2943         if(!prs_uint32("count3", ps, depth, &info->count3))
2944                 return False;
2945         if(!prs_uint32("count4", ps, depth, &info->count4))
2946                 return False;
2947         if(!prs_uint32("ptr2", ps, depth, &info->ptr2))
2948                 return False;
2949         if(!smb_io_time("time2", &info->time2, ps, depth)) /* logon time */
2950                 return False;
2951         if(!prs_uint32("unknow1", ps, depth, &info->unknow1))
2952                 return False;
2953
2954
2955         if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2956                 return False;
2957         if(!prs_uint32("ptr3", ps, depth, &info->ptr3))
2958                 return False;
2959         for(i=0; i<12; i++)
2960                 if(!prs_uint32("unknow2", ps, depth, &info->unknow2))
2961                         return False;
2962
2963         if(!prs_uint32("chal_len", ps, depth, &info->chal_len))
2964                 return False;
2965         if(!prs_uint32("reserved1", ps, depth, &info->reserved1))
2966                 return False;
2967         if(!prs_uint32("chal_len2", ps, depth, &info->chal_len2))
2968                 return False;
2969
2970         if(!prs_uint8s (False, "chal", ps, depth, info->chal, info->chal_len2))
2971                 return False;
2972
2973         if(!prs_uint32("key_len", ps, depth, &info->key_len))
2974                 return False;
2975         if(!prs_uint32("reserved2", ps, depth, &info->reserved2))
2976                 return False;
2977         if(!prs_uint32("key_len2", ps, depth, &info->key_len2))
2978                 return False;
2979
2980         if(!prs_uint8s (False, "key", ps, depth, info->key, info->key_len2))
2981                 return False;
2982
2983
2984         if(!prs_uint32("buf_size3", ps, depth, &info->buf_size3))
2985                 return False;
2986
2987         if(!sec_io_desc("sec_desc2", &info->sec_desc2, ps, depth))
2988                 return False;
2989
2990
2991         return True;
2992 }
2993
2994 #endif
2995
2996 /*******************************************************************
2997 reads or writes a structure.
2998 ********************************************************************/
2999 static bool net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
3000                                       prs_struct *ps, int depth)
3001 {
3002         unsigned int i;
3003
3004         prs_debug(ps, depth, desc, "net_io_sam_privs_info");
3005         depth++;
3006
3007         if(!prs_align(ps))
3008                 return False;
3009
3010         if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
3011                 return False;
3012
3013         if(!prs_uint32("priv_count", ps, depth, &info->priv_count))
3014                 return False;
3015         if(!prs_uint32("priv_control", ps, depth, &info->priv_control))
3016                 return False;
3017
3018         if(!prs_uint32("priv_attr_ptr", ps, depth, &info->priv_attr_ptr))
3019                 return False;
3020         if(!prs_uint32("priv_name_ptr", ps, depth, &info->priv_name_ptr))
3021                 return False;
3022
3023         if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
3024                 return False;
3025         if (!prs_uint32("non_paged_pool_limit", ps, depth,
3026                         &info->non_paged_pool_limit))
3027                 return False;
3028         if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
3029                 return False;
3030         if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
3031                 return False;
3032         if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
3033                 return False;
3034         if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
3035                 return False;
3036         if (!prs_uint32("system_flags", ps, depth, &info->system_flags))
3037                 return False;
3038         if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
3039                 return False;
3040
3041         for (i=0; i<4; i++) {
3042                 UNIHDR dummy;
3043                 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
3044                         return False;
3045         }
3046
3047         for (i=0; i<4; i++) {
3048                 uint32 reserved;
3049                 if (!prs_uint32("reserved", ps, depth, &reserved))
3050                         return False;
3051         }
3052
3053         if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
3054                 return False;
3055
3056         if (UNMARSHALLING(ps)) {
3057                 if (info->attribute_count) {
3058                         info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
3059                         if (!info->attributes) {
3060                                 return False;
3061                         }
3062                 } else {
3063                         info->attributes = NULL;
3064                 }
3065         }
3066
3067         for (i=0; i<info->attribute_count; i++)
3068                 if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
3069                         return False;
3070
3071         if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
3072                 return False;
3073
3074         if (UNMARSHALLING(ps)) {
3075                 if (info->privlist_count) {
3076                         info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
3077                         info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
3078                         if (!info->hdr_privslist) {
3079                                 return False;
3080                         }
3081                         if (!info->uni_privslist) {
3082                                 return False;
3083                         }
3084                 } else {
3085                         info->hdr_privslist = NULL;
3086                         info->uni_privslist = NULL;
3087                 }
3088         }
3089
3090         for (i=0; i<info->privlist_count; i++)
3091                 if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
3092                         return False;
3093
3094         for (i=0; i<info->privlist_count; i++)
3095                 if (!smb_io_unistr2("uni_privslist", &info->uni_privslist[i], True, ps, depth))
3096                         return False;
3097
3098         if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
3099                 return False;
3100
3101         return True;
3102 }
3103
3104 /*******************************************************************
3105 reads or writes a structure.
3106 ********************************************************************/
3107 static bool net_io_sam_delta_ctr(const char *desc,
3108                                  SAM_DELTA_CTR * delta, uint16 type,
3109                                  prs_struct *ps, int depth)
3110 {
3111         prs_debug(ps, depth, desc, "net_io_sam_delta_ctr");
3112         depth++;
3113
3114         switch (type) {
3115                 /* Seen in sam deltas */
3116                 case SAM_DELTA_MODIFIED_COUNT:
3117                         if (!net_io_sam_delta_mod_count("", &delta->mod_count, ps, depth))
3118                                 return False;
3119                         break;
3120
3121                 case SAM_DELTA_DOMAIN_INFO:
3122                         if (!net_io_sam_domain_info("", &delta->domain_info, ps, depth))
3123                                 return False;
3124                         break;
3125
3126                 case SAM_DELTA_GROUP_INFO:
3127                         if (!net_io_sam_group_info("", &delta->group_info, ps, depth))
3128                                 return False;
3129                         break;
3130
3131                 case SAM_DELTA_ACCOUNT_INFO:
3132                         if (!net_io_sam_account_info("", &delta->account_info, ps, depth))
3133                                 return False;
3134                         break;
3135
3136                 case SAM_DELTA_GROUP_MEM:
3137                         if (!net_io_sam_group_mem_info("", &delta->grp_mem_info, ps, depth))
3138                                 return False;
3139                         break;
3140
3141                 case SAM_DELTA_ALIAS_INFO:
3142                         if (!net_io_sam_alias_info("", &delta->alias_info, ps, depth))
3143                                 return False;
3144                         break;
3145
3146                 case SAM_DELTA_POLICY_INFO:
3147                         if (!net_io_sam_policy_info("", &delta->policy_info, ps, depth))
3148                                 return False;
3149                         break;
3150
3151                 case SAM_DELTA_ALIAS_MEM:
3152                         if (!net_io_sam_alias_mem_info("", &delta->als_mem_info, ps, depth))
3153                                 return False;
3154                         break;
3155
3156                 case SAM_DELTA_PRIVS_INFO:
3157                         if (!net_io_sam_privs_info("", &delta->privs_info, ps, depth))
3158                                 return False;
3159                         break;
3160
3161                         /* These guys are implemented but broken */
3162
3163                 case SAM_DELTA_TRUST_DOMS:
3164                 case SAM_DELTA_SECRET_INFO:
3165                         break;
3166
3167                         /* These guys are not implemented yet */
3168
3169                 case SAM_DELTA_RENAME_GROUP:
3170                 case SAM_DELTA_RENAME_USER:
3171                 case SAM_DELTA_RENAME_ALIAS:
3172                 case SAM_DELTA_DELETE_GROUP:
3173                 case SAM_DELTA_DELETE_USER:
3174                 default:
3175                         DEBUG(0, ("Replication error: Unknown delta type 0x%x\n", type));
3176                         break;
3177         }
3178
3179         return True;
3180 }
3181
3182 /*******************************************************************
3183 reads or writes a structure.
3184 ********************************************************************/
3185 bool net_io_r_sam_sync(const char *desc,
3186                        NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
3187 {
3188         uint32 i;
3189
3190         prs_debug(ps, depth, desc, "net_io_r_sam_sync");
3191         depth++;
3192
3193         if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3194                 return False;
3195         if (!prs_uint32("sync_context", ps, depth, &r_s->sync_context))
3196                 return False;
3197
3198         if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3199                 return False;
3200         if (r_s->ptr_deltas != 0)
3201         {
3202                 if (!prs_uint32("num_deltas ", ps, depth, &r_s->num_deltas))
3203                         return False;
3204                 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->ptr_deltas2))
3205                         return False;
3206                 if (r_s->ptr_deltas2 != 0)
3207                 {
3208                         if (!prs_uint32("num_deltas2", ps, depth,
3209                                         &r_s->num_deltas2))
3210                                 return False;
3211
3212                         if (r_s->num_deltas2 != r_s->num_deltas)
3213                         {
3214                                 /* RPC fault */
3215                                 return False;
3216                         }
3217
3218                         if (UNMARSHALLING(ps)) {
3219                                 if (r_s->num_deltas2) {
3220                                         r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
3221                                         if (r_s->hdr_deltas == NULL) {
3222                                                 DEBUG(0, ("error tallocating memory "
3223                                                         "for %d delta headers\n", 
3224                                                         r_s->num_deltas2));
3225                                                 return False;
3226                                         }
3227                                 } else {
3228                                         r_s->hdr_deltas = NULL;
3229                                 }
3230                         }
3231
3232                         for (i = 0; i < r_s->num_deltas2; i++)
3233                         {
3234                                 if (!net_io_sam_delta_hdr("", 
3235                                                           &r_s->hdr_deltas[i],
3236                                                           ps, depth))
3237                                         return False;
3238                         }
3239
3240                         if (UNMARSHALLING(ps)) {
3241                                 if (r_s->num_deltas2) {
3242                                         r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
3243                                         if (r_s->deltas == NULL) {
3244                                                 DEBUG(0, ("error tallocating memory "
3245                                                         "for %d deltas\n", 
3246                                                         r_s->num_deltas2));
3247                                                 return False;
3248                                         }
3249                                 } else {
3250                                         r_s->deltas = NULL;
3251                                 }
3252                         }
3253
3254                         for (i = 0; i < r_s->num_deltas2; i++)
3255                         {
3256                                 if (!net_io_sam_delta_ctr(
3257                                         "", &r_s->deltas[i],
3258                                         r_s->hdr_deltas[i].type3,
3259                                         ps, depth)) {
3260                                         DEBUG(0, ("hmm, failed on i=%d\n", i));
3261                                         return False;
3262                                 }
3263                         }
3264                 }
3265         }
3266
3267         prs_align(ps);
3268         if (!prs_ntstatus("status", ps, depth, &(r_s->status)))
3269                 return False;
3270
3271         return True;
3272 }
3273
3274 /*******************************************************************
3275 makes a NET_Q_SAM_DELTAS structure.
3276 ********************************************************************/
3277 bool init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name, 
3278                            const char *cli_name, DOM_CRED *cli_creds, 
3279                            uint32 database_id, uint64 dom_mod_count)
3280 {
3281         DEBUG(5, ("init_net_q_sam_deltas\n"));
3282
3283         init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
3284         init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
3285
3286         memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
3287         memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
3288
3289         q_s->database_id = database_id;
3290     q_s->dom_mod_count = dom_mod_count;
3291         q_s->max_size = 0xffff;
3292
3293         return True;
3294 }
3295
3296 /*******************************************************************
3297 reads or writes a structure.
3298 ********************************************************************/
3299 bool net_io_q_sam_deltas(const char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
3300                          int depth)
3301 {
3302         prs_debug(ps, depth, desc, "net_io_q_sam_deltas");
3303         depth++;
3304
3305         if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
3306                 return False;
3307         if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
3308                 return False;
3309
3310         if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
3311                 return False;
3312         if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
3313                 return False;
3314
3315         if (!prs_uint32("database_id  ", ps, depth, &q_s->database_id))
3316                 return False;
3317         if (!prs_uint64("dom_mod_count", ps, depth, &q_s->dom_mod_count))
3318                 return False;
3319         if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
3320                 return False;
3321
3322         return True;
3323 }
3324
3325 /*******************************************************************
3326 reads or writes a structure.
3327 ********************************************************************/
3328 bool net_io_r_sam_deltas(const char *desc,
3329                          NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
3330 {
3331         unsigned int i;
3332
3333         prs_debug(ps, depth, desc, "net_io_r_sam_deltas");
3334         depth++;
3335
3336         if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3337                 return False;
3338         if (!prs_uint64("dom_mod_count", ps, depth, &r_s->dom_mod_count))
3339                 return False;
3340
3341         if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3342                 return False;
3343         if (!prs_uint32("num_deltas", ps, depth, &r_s->num_deltas))
3344                 return False;
3345         if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->num_deltas2))
3346                 return False;
3347
3348         if (r_s->num_deltas2 != 0)
3349         {
3350                 if (!prs_uint32("num_deltas2 ", ps, depth, &r_s->num_deltas2))
3351                         return False;
3352
3353                 if (r_s->ptr_deltas != 0)
3354                 {
3355                         if (UNMARSHALLING(ps)) {
3356                                 if (r_s->num_deltas) {
3357                                         r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
3358                                         if (r_s->hdr_deltas == NULL) {
3359                                                 DEBUG(0, ("error tallocating memory "
3360                                                         "for %d delta headers\n", 
3361                                                         r_s->num_deltas));
3362                                                 return False;
3363                                         }
3364                                 } else {
3365                                         r_s->hdr_deltas = NULL;
3366                                 }
3367                         }
3368
3369                         for (i = 0; i < r_s->num_deltas; i++)
3370                         {
3371                                 net_io_sam_delta_hdr("", &r_s->hdr_deltas[i],
3372                                                       ps, depth);
3373                         }
3374                         
3375                         if (UNMARSHALLING(ps)) {
3376                                 if (r_s->num_deltas) {
3377                                         r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
3378                                         if (r_s->deltas == NULL) {
3379                                                 DEBUG(0, ("error tallocating memory "
3380                                                         "for %d deltas\n", 
3381                                                         r_s->num_deltas));
3382                                                 return False;
3383                                         }
3384                                 } else {
3385                                         r_s->deltas = NULL;
3386                                 }
3387                         }
3388
3389                         for (i = 0; i < r_s->num_deltas; i++)
3390                         {
3391                                 if (!net_io_sam_delta_ctr(
3392                                         "",
3393                                         &r_s->deltas[i],
3394                                         r_s->hdr_deltas[i].type2,
3395                                         ps, depth))
3396                                         
3397                                         return False;
3398                         }
3399                 }
3400         }
3401
3402         prs_align(ps);
3403         if (!prs_ntstatus("status", ps, depth, &r_s->status))
3404                 return False;
3405
3406         return True;
3407 }
3408
3409 /*******************************************************************
3410  Inits a NET_Q_DSR_GETDCNAME structure.
3411 ********************************************************************/
3412
3413 void init_net_q_dsr_getdcname(NET_Q_DSR_GETDCNAME *r_t, const char *server_unc,
3414                               const char *domain_name,
3415                               struct GUID *domain_guid,
3416                               struct GUID *site_guid,
3417                               uint32_t flags)
3418 {
3419         DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3420
3421         r_t->ptr_server_unc = (server_unc != NULL);
3422         init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3423
3424         r_t->ptr_domain_name = (domain_name != NULL);
3425         init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3426
3427         r_t->ptr_domain_guid = (domain_guid != NULL);
3428         r_t->domain_guid = domain_guid;
3429
3430         r_t->ptr_site_guid = (site_guid != NULL);
3431         r_t->site_guid = site_guid;
3432
3433         r_t->flags = flags;
3434 }
3435
3436 /*******************************************************************
3437  Inits a NET_Q_DSR_GETDCNAMEEX structure.
3438 ********************************************************************/
3439
3440 void init_net_q_dsr_getdcnameex(NET_Q_DSR_GETDCNAMEEX *r_t, const char *server_unc,
3441                                 const char *domain_name,
3442                                 struct GUID *domain_guid,
3443                                 const char *site_name,
3444                                 uint32_t flags)
3445 {
3446         DEBUG(5, ("init_net_q_dsr_getdcnameex\n"));
3447
3448         r_t->ptr_server_unc = (server_unc != NULL);
3449         init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3450
3451         r_t->ptr_domain_name = (domain_name != NULL);
3452         init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3453
3454         r_t->ptr_domain_guid = (domain_guid != NULL);
3455         r_t->domain_guid = domain_guid;
3456
3457         r_t->ptr_site_name = (site_name != NULL);
3458         init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
3459
3460         r_t->flags = flags;
3461 }
3462
3463 /*******************************************************************
3464  Inits a NET_Q_DSR_GETDCNAMEEX2 structure.
3465 ********************************************************************/
3466
3467 void init_net_q_dsr_getdcnameex2(NET_Q_DSR_GETDCNAMEEX2 *r_t, const char *server_unc,
3468                                  const char *domain_name,
3469                                  const char *client_account,
3470                                  uint32 mask,
3471                                  struct GUID *domain_guid,
3472                                  const char *site_name,
3473                                  uint32_t flags)
3474 {
3475         DEBUG(5, ("init_net_q_dsr_getdcnameex2\n"));
3476
3477         r_t->ptr_server_unc = (server_unc != NULL);
3478         init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3479
3480         r_t->ptr_client_account = (client_account != NULL);
3481         init_unistr2(&r_t->uni_client_account, client_account, UNI_STR_TERMINATE);
3482
3483         r_t->mask = mask;
3484
3485         r_t->ptr_domain_name = (domain_name != NULL);
3486         init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3487
3488         r_t->ptr_domain_guid = (domain_guid != NULL);
3489         r_t->domain_guid = domain_guid;
3490
3491         r_t->ptr_site_name = (site_name != NULL);
3492         init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
3493
3494         r_t->flags = flags;
3495 }
3496
3497 /*******************************************************************
3498  Reads or writes an NET_Q_DSR_GETDCNAME structure.
3499 ********************************************************************/
3500
3501 bool net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
3502                             prs_struct *ps, int depth)
3503 {
3504         if (r_t == NULL)
3505                 return False;
3506
3507         prs_debug(ps, depth, desc, "net_io_q_dsr_getdcname");
3508         depth++;
3509
3510         if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3511                 return False;
3512
3513         if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3514                             r_t->ptr_server_unc, ps, depth))
3515                 return False;
3516
3517         if (!prs_align(ps))
3518                 return False;
3519
3520         if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3521                 return False;
3522
3523         if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3524                             r_t->ptr_domain_name, ps, depth))
3525                 return False;
3526
3527         if (!prs_align(ps))
3528                 return False;
3529
3530         if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3531                 return False;
3532
3533         if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3534                 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3535                 if (r_t->domain_guid == NULL)
3536                         return False;
3537         }
3538
3539         if ((r_t->ptr_domain_guid) &&
3540             (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3541                 return False;
3542
3543         if (!prs_align(ps))
3544                 return False;
3545
3546         if (!prs_uint32("ptr_site_guid", ps, depth, &r_t->ptr_site_guid))
3547                 return False;
3548
3549         if (UNMARSHALLING(ps) && (r_t->ptr_site_guid)) {
3550                 r_t->site_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3551                 if (r_t->site_guid == NULL)
3552                         return False;
3553         }
3554
3555         if ((r_t->ptr_site_guid) &&
3556             (!smb_io_uuid("site_guid", r_t->site_guid, ps, depth)))
3557                 return False;
3558
3559         if (!prs_align(ps))
3560                 return False;
3561
3562         if (!prs_uint32("flags", ps, depth, &r_t->flags))
3563                 return False;
3564
3565         return True;
3566 }
3567
3568 /*******************************************************************
3569  Reads or writes an NET_Q_DSR_GETDCNAMEEX structure.
3570 ********************************************************************/
3571
3572 bool net_io_q_dsr_getdcnameex(const char *desc, NET_Q_DSR_GETDCNAMEEX *r_t,
3573                               prs_struct *ps, int depth)
3574 {
3575         if (r_t == NULL)
3576                 return False;
3577
3578         prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex");
3579         depth++;
3580
3581         if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3582                 return False;
3583
3584         if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3585                             r_t->ptr_server_unc, ps, depth))
3586                 return False;
3587
3588         if (!prs_align(ps))
3589                 return False;
3590
3591         if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3592                 return False;
3593
3594         if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3595                             r_t->ptr_domain_name, ps, depth))
3596                 return False;
3597
3598         if (!prs_align(ps))
3599                 return False;
3600
3601         if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3602                 return False;
3603
3604         if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3605                 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3606                 if (r_t->domain_guid == NULL)
3607                         return False;
3608         }
3609
3610         if ((r_t->ptr_domain_guid) &&
3611             (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3612                 return False;
3613
3614         if (!prs_align(ps))
3615                 return False;
3616
3617         if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3618                 return False;
3619
3620         if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3621                             r_t->ptr_site_name, ps, depth))
3622                 return False;
3623
3624         if (!prs_align(ps))
3625                 return False;
3626
3627         if (!prs_uint32("flags", ps, depth, &r_t->flags))
3628                 return False;
3629
3630         return True;
3631 }
3632
3633 /*******************************************************************
3634  Reads or writes an NET_Q_DSR_GETDCNAMEEX2 structure.
3635 ********************************************************************/
3636
3637 bool net_io_q_dsr_getdcnameex2(const char *desc, NET_Q_DSR_GETDCNAMEEX2 *r_t,
3638                                prs_struct *ps, int depth)
3639 {
3640         if (r_t == NULL)
3641                 return False;
3642
3643         prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex2");
3644         depth++;
3645
3646         if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3647                 return False;
3648
3649         if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3650                             r_t->ptr_server_unc, ps, depth))
3651                 return False;
3652
3653         if (!prs_align(ps))
3654                 return False;
3655
3656         if (!prs_uint32("ptr_client_account", ps, depth, &r_t->ptr_client_account))
3657                 return False;
3658
3659         if (!smb_io_unistr2("client_account", &r_t->uni_client_account,
3660                             r_t->ptr_client_account, ps, depth))
3661                 return False;
3662
3663         if (!prs_align(ps))
3664                 return False;
3665
3666         if (!prs_uint32("mask", ps, depth, &r_t->mask))
3667                 return False;
3668
3669         if (!prs_align(ps))
3670                 return False;
3671
3672         if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3673                 return False;
3674
3675         if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3676                             r_t->ptr_domain_name, ps, depth))
3677                 return False;
3678
3679         if (!prs_align(ps))
3680                 return False;
3681
3682         if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3683                 return False;
3684
3685         if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3686                 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3687                 if (r_t->domain_guid == NULL)
3688                         return False;
3689         }
3690
3691         if ((r_t->ptr_domain_guid) &&
3692             (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3693                 return False;
3694
3695         if (!prs_align(ps))
3696                 return False;
3697
3698         if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3699                 return False;
3700
3701         if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3702                             r_t->ptr_site_name, ps, depth))
3703                 return False;
3704
3705         if (!prs_align(ps))
3706                 return False;
3707
3708         if (!prs_uint32("flags", ps, depth, &r_t->flags))
3709                 return False;
3710
3711         return True;
3712 }
3713
3714
3715
3716 /*******************************************************************
3717  Inits a NET_R_DSR_GETDCNAME structure.
3718 ********************************************************************/
3719 void init_net_r_dsr_getdcname(NET_R_DSR_GETDCNAME *r_t, const char *dc_unc,
3720                               const char *dc_address, int32 dc_address_type,
3721                               struct GUID domain_guid, const char *domain_name,
3722                               const char *forest_name, uint32 dc_flags,
3723                               const char *dc_site_name,
3724                               const char *client_site_name)
3725 {
3726         DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3727
3728         r_t->ptr_dc_unc = (dc_unc != NULL);
3729         init_unistr2(&r_t->uni_dc_unc, dc_unc, UNI_STR_TERMINATE);
3730
3731         r_t->ptr_dc_address = (dc_address != NULL);
3732         init_unistr2(&r_t->uni_dc_address, dc_address, UNI_STR_TERMINATE);
3733
3734         r_t->dc_address_type = dc_address_type;
3735         r_t->domain_guid = domain_guid;
3736
3737         r_t->ptr_domain_name = (domain_name != NULL);
3738         init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3739
3740         r_t->ptr_forest_name = (forest_name != NULL);
3741         init_unistr2(&r_t->uni_forest_name, forest_name, UNI_STR_TERMINATE);
3742
3743         r_t->dc_flags = dc_flags;
3744
3745         r_t->ptr_dc_site_name = (dc_site_name != NULL);
3746         init_unistr2(&r_t->uni_dc_site_name, dc_site_name, UNI_STR_TERMINATE);
3747
3748         r_t->ptr_client_site_name = (client_site_name != NULL);
3749         init_unistr2(&r_t->uni_client_site_name, client_site_name,
3750                      UNI_STR_TERMINATE);
3751 }
3752
3753 /*******************************************************************
3754  Reads or writes an NET_R_DSR_GETDCNAME structure.
3755 ********************************************************************/
3756
3757 bool net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t,
3758                             prs_struct *ps, int depth)
3759 {
3760         uint32 info_ptr = 1;
3761
3762         if (r_t == NULL)
3763                 return False;
3764
3765         prs_debug(ps, depth, desc, "net_io_r_dsr_getdcname");
3766         depth++;
3767
3768         /* The reply contains *just* an info struct, this is the ptr to it */
3769         if (!prs_uint32("info_ptr", ps, depth, &info_ptr))
3770                 return False;
3771
3772         if (info_ptr == 0)
3773                 return False;
3774
3775         if (!prs_uint32("ptr_dc_unc", ps, depth, &r_t->ptr_dc_unc))
3776                 return False;
3777
3778         if (!prs_uint32("ptr_dc_address", ps, depth, &r_t->ptr_dc_address))
3779                 return False;
3780
3781         if (!prs_int32("dc_address_type", ps, depth, &r_t->dc_address_type))
3782                 return False;
3783
3784         if (!smb_io_uuid("domain_guid", &r_t->domain_guid, ps, depth))
3785                 return False;
3786
3787         if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3788                 return False;
3789
3790         if (!prs_uint32("ptr_forest_name", ps, depth, &r_t->ptr_forest_name))
3791                 return False;
3792
3793         if (!prs_uint32("dc_flags", ps, depth, &r_t->dc_flags))
3794                 return False;
3795
3796         if (!prs_uint32("ptr_dc_site_name", ps, depth, &r_t->ptr_dc_site_name))
3797                 return False;
3798
3799         if (!prs_uint32("ptr_client_site_name", ps, depth,
3800                         &r_t->ptr_client_site_name))
3801                 return False;
3802
3803         if (!prs_align(ps))
3804                 return False;
3805
3806         if (!smb_io_unistr2("dc_unc", &r_t->uni_dc_unc,
3807                             r_t->ptr_dc_unc, ps, depth))
3808                 return False;
3809
3810         if (!prs_align(ps))
3811                 return False;
3812
3813         if (!smb_io_unistr2("dc_address", &r_t->uni_dc_address,
3814                             r_t->ptr_dc_address, ps, depth))
3815                 return False;
3816
3817         if (!prs_align(ps))
3818                 return False;
3819
3820         if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3821                             r_t->ptr_domain_name, ps, depth))
3822                 return False;
3823
3824         if (!prs_align(ps))
3825                 return False;
3826
3827         if (!smb_io_unistr2("forest_name", &r_t->uni_forest_name,
3828                             r_t->ptr_forest_name, ps, depth))
3829                 return False;
3830
3831         if (!prs_align(ps))
3832                 return False;
3833
3834         if (!smb_io_unistr2("dc_site_name", &r_t->uni_dc_site_name,
3835                             r_t->ptr_dc_site_name, ps, depth))
3836                 return False;
3837
3838         if (!prs_align(ps))
3839                 return False;
3840
3841         if (!smb_io_unistr2("client_site_name", &r_t->uni_client_site_name,
3842                             r_t->ptr_client_site_name, ps, depth))
3843                 return False;
3844
3845         if (!prs_align(ps))
3846                 return False;
3847
3848         if (!prs_werror("result", ps, depth, &r_t->result))
3849                 return False;
3850
3851         return True;
3852 }
3853
3854 /*******************************************************************
3855  Inits a NET_Q_DSR_GETSITENAME structure.
3856 ********************************************************************/
3857
3858 void init_net_q_dsr_getsitename(NET_Q_DSR_GETSITENAME *r_t, const char *computer_name)
3859 {
3860         DEBUG(5, ("init_net_q_dsr_getsitename\n"));
3861
3862         r_t->ptr_computer_name = (computer_name != NULL);
3863         init_unistr2(&r_t->uni_computer_name, computer_name, UNI_STR_TERMINATE);
3864 }
3865
3866 /*******************************************************************
3867  Reads or writes an NET_Q_DSR_GETSITENAME structure.
3868 ********************************************************************/
3869
3870 bool net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
3871                               prs_struct *ps, int depth)
3872 {
3873         if (r_t == NULL)
3874                 return False;
3875
3876         prs_debug(ps, depth, desc, "net_io_q_dsr_getsitename");
3877         depth++;
3878
3879         if (!prs_uint32("ptr_computer_name", ps, depth, &r_t->ptr_computer_name))
3880                 return False;
3881
3882         if (!smb_io_unistr2("computer_name", &r_t->uni_computer_name,
3883                             r_t->ptr_computer_name, ps, depth))
3884                 return False;
3885
3886         if (!prs_align(ps))
3887                 return False;
3888
3889         return True;
3890 }
3891
3892 /*******************************************************************
3893  Reads or writes an NET_R_DSR_GETSITENAME structure.
3894 ********************************************************************/
3895
3896 bool net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t,
3897                               prs_struct *ps, int depth)
3898 {
3899         if (r_t == NULL)
3900                 return False;
3901
3902         prs_debug(ps, depth, desc, "net_io_r_dsr_getsitename");
3903         depth++;
3904
3905         if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3906                 return False;
3907
3908         if (!prs_align(ps))
3909                 return False;
3910
3911         if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3912                             r_t->ptr_site_name, ps, depth))
3913                 return False;
3914
3915         if (!prs_align(ps))
3916                 return False;
3917
3918         if (!prs_werror("result", ps, depth, &r_t->result))
3919                 return False;
3920
3921         return True;
3922 }
3923
3924