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