[GLUE] Rsync SAMBA_3_0 SVN r25598 in order to create the v3-0-test branch.
[Samba.git] / source / rpc_parse / parse_net.c
blob5837ee6fd8406fc43dbf53315fe68a1887f7cc1b
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.
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.
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.
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.
24 #include "includes.h"
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_RPC_PARSE
29 /*******************************************************************
30 Reads or writes a structure.
31 ********************************************************************/
33 static BOOL net_io_neg_flags(const char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth)
35 if (neg == NULL)
36 return False;
38 prs_debug(ps, depth, desc, "net_io_neg_flags");
39 depth++;
41 if(!prs_align(ps))
42 return False;
44 if(!prs_uint32("neg_flags", ps, depth, &neg->neg_flags))
45 return False;
47 return True;
50 /*******************************************************************
51 Inits a NETLOGON_INFO_3 structure.
52 ********************************************************************/
54 static void init_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_attempts)
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;
65 /*******************************************************************
66 Reads or writes a NETLOGON_INFO_3 structure.
67 ********************************************************************/
69 static BOOL net_io_netinfo_3(const char *desc, NETLOGON_INFO_3 *info, prs_struct *ps, int depth)
71 if (info == NULL)
72 return False;
74 prs_debug(ps, depth, desc, "net_io_netinfo_3");
75 depth++;
77 if(!prs_align(ps))
78 return False;
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;
95 return True;
99 /*******************************************************************
100 Inits a NETLOGON_INFO_1 structure.
101 ********************************************************************/
103 static void init_netinfo_1(NETLOGON_INFO_1 *info, uint32 flags, uint32 pdc_status)
105 info->flags = flags;
106 info->pdc_status = pdc_status;
109 /*******************************************************************
110 Reads or writes a NETLOGON_INFO_1 structure.
111 ********************************************************************/
113 static BOOL net_io_netinfo_1(const char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth)
115 if (info == NULL)
116 return False;
118 prs_debug(ps, depth, desc, "net_io_netinfo_1");
119 depth++;
121 if(!prs_align(ps))
122 return False;
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;
129 return True;
132 /*******************************************************************
133 Inits a NETLOGON_INFO_2 structure.
134 ********************************************************************/
136 static void init_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_status,
137 uint32 tc_status, const char *trusted_dc_name)
139 info->flags = flags;
140 info->pdc_status = pdc_status;
141 info->ptr_trusted_dc_name = 1;
142 info->tc_status = tc_status;
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);
150 /*******************************************************************
151 Reads or writes a NETLOGON_INFO_2 structure.
152 ********************************************************************/
154 static BOOL net_io_netinfo_2(const char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth)
156 if (info == NULL)
157 return False;
159 prs_debug(ps, depth, desc, "net_io_netinfo_2");
160 depth++;
162 if(!prs_align(ps))
163 return False;
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;
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;
179 if(!prs_align(ps))
180 return False;
182 return True;
185 static BOOL net_io_ctrl_data_info_5(const char *desc, CTRL_DATA_INFO_5 *info, prs_struct *ps, int depth)
187 if (info == NULL)
188 return False;
190 prs_debug(ps, depth, desc, "net_io_ctrl_data_info_5");
191 depth++;
193 if ( !prs_uint32( "function_code", ps, depth, &info->function_code ) )
194 return False;
196 if(!prs_uint32("ptr_domain", ps, depth, &info->ptr_domain))
197 return False;
199 if ( info->ptr_domain ) {
200 if(!smb_io_unistr2("domain", &info->domain, info->ptr_domain, ps, depth))
201 return False;
204 return True;
207 static BOOL net_io_ctrl_data_info_6(const char *desc, CTRL_DATA_INFO_6 *info, prs_struct *ps, int depth)
209 if (info == NULL)
210 return False;
212 prs_debug(ps, depth, desc, "net_io_ctrl_data_info_6");
213 depth++;
215 if ( !prs_uint32( "function_code", ps, depth, &info->function_code ) )
216 return False;
218 if(!prs_uint32("ptr_domain", ps, depth, &info->ptr_domain))
219 return False;
221 if ( info->ptr_domain ) {
222 if(!smb_io_unistr2("domain", &info->domain, info->ptr_domain, ps, depth))
223 return False;
226 return True;
229 /*******************************************************************
230 Reads or writes an NET_Q_LOGON_CTRL2 structure.
231 ********************************************************************/
233 BOOL net_io_q_logon_ctrl2(const char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth)
235 if (q_l == NULL)
236 return False;
238 prs_debug(ps, depth, desc, "net_io_q_logon_ctrl2");
239 depth++;
241 if(!prs_align(ps))
242 return False;
244 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
245 return False;
247 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
248 return False;
250 if(!prs_align(ps))
251 return False;
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;
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;
268 default:
269 DEBUG(0,("net_io_q_logon_ctrl2: unknown function_code [%d]\n",
270 q_l->function_code));
271 return False;
274 return True;
277 /*******************************************************************
278 Inits an NET_Q_LOGON_CTRL2 structure.
279 ********************************************************************/
281 void init_net_q_logon_ctrl2(NET_Q_LOGON_CTRL2 *q_l, const char *srv_name,
282 uint32 query_level)
284 DEBUG(5,("init_q_logon_ctrl2\n"));
286 q_l->function_code = 0x01;
287 q_l->query_level = query_level;
289 init_unistr2(&q_l->uni_server_name, srv_name, UNI_STR_TERMINATE);
292 /*******************************************************************
293 Inits an NET_R_LOGON_CTRL2 structure.
294 ********************************************************************/
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)
301 r_l->switch_value = query_level;
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 */
325 /* take a guess at an error code... */
326 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
327 break;
331 /*******************************************************************
332 Reads or writes an NET_R_LOGON_CTRL2 structure.
333 ********************************************************************/
335 BOOL net_io_r_logon_ctrl2(const char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth)
337 if (r_l == NULL)
338 return False;
340 prs_debug(ps, depth, desc, "net_io_r_logon_ctrl2");
341 depth++;
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;
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;
369 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
370 return False;
372 return True;
375 /*******************************************************************
376 Reads or writes an NET_Q_LOGON_CTRL structure.
377 ********************************************************************/
379 BOOL net_io_q_logon_ctrl(const char *desc, NET_Q_LOGON_CTRL *q_l, prs_struct *ps,
380 int depth)
382 prs_debug(ps, depth, desc, "net_io_q_logon_ctrl");
383 depth++;
385 if(!prs_align(ps))
386 return False;
388 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
389 return False;
391 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
392 return False;
394 if(!prs_align(ps))
395 return False;
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;
402 return True;
405 /*******************************************************************
406 Inits an NET_Q_LOGON_CTRL structure.
407 ********************************************************************/
409 void init_net_q_logon_ctrl(NET_Q_LOGON_CTRL *q_l, const char *srv_name,
410 uint32 query_level)
412 DEBUG(5,("init_q_logon_ctrl\n"));
414 q_l->function_code = 0x01; /* ??? */
415 q_l->query_level = query_level;
417 init_unistr2(&q_l->uni_server_name, srv_name, UNI_STR_TERMINATE);
420 /*******************************************************************
421 Inits an NET_R_LOGON_CTRL structure.
422 ********************************************************************/
424 void init_net_r_logon_ctrl(NET_R_LOGON_CTRL *r_l, uint32 query_level,
425 uint32 flags, uint32 pdc_status)
427 DEBUG(5,("init_r_logon_ctrl\n"));
429 r_l->switch_value = query_level; /* should only be 0x1 */
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 */
442 /* take a guess at an error code... */
443 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
444 break;
448 /*******************************************************************
449 Reads or writes an NET_R_LOGON_CTRL structure.
450 ********************************************************************/
452 BOOL net_io_r_logon_ctrl(const char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps,
453 int depth)
455 prs_debug(ps, depth, desc, "net_io_r_logon_ctrl");
456 depth++;
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;
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;
476 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
477 return False;
479 return True;
482 /*******************************************************************
483 Inits an NET_R_GETANYDCNAME structure.
484 ********************************************************************/
485 void init_net_q_getanydcname(NET_Q_GETANYDCNAME *r_t, const char *logon_server,
486 const char *domainname)
488 DEBUG(5,("init_q_getanydcname\n"));
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);
496 /*******************************************************************
497 Reads or writes an NET_Q_GETANYDCNAME structure.
498 ********************************************************************/
500 BOOL net_io_q_getanydcname(const char *desc, NET_Q_GETANYDCNAME *r_t, prs_struct *ps,
501 int depth)
503 if (r_t == NULL)
504 return False;
506 prs_debug(ps, depth, desc, "net_io_q_getanydcname");
507 depth++;
509 if (!prs_uint32("ptr_logon_server", ps, depth, &r_t->ptr_logon_server))
510 return False;
512 if (!smb_io_unistr2("logon_server", &r_t->uni_logon_server,
513 r_t->ptr_logon_server, ps, depth))
514 return False;
516 if (!prs_align(ps))
517 return False;
519 if (!prs_uint32("ptr_domainname", ps, depth, &r_t->ptr_domainname))
520 return False;
522 if (!smb_io_unistr2("domainname", &r_t->uni_domainname,
523 r_t->ptr_domainname, ps, depth))
524 return False;
526 return True;
530 /*******************************************************************
531 Inits an NET_R_GETANYDCNAME structure.
532 ********************************************************************/
533 void init_net_r_getanydcname(NET_R_GETANYDCNAME *r_t, const char *dcname)
535 DEBUG(5,("init_r_getanydcname\n"));
537 init_unistr2(&r_t->uni_dcname, dcname, UNI_STR_TERMINATE);
540 /*******************************************************************
541 Reads or writes an NET_R_GETANYDCNAME structure.
542 ********************************************************************/
544 BOOL net_io_r_getanydcname(const char *desc, NET_R_GETANYDCNAME *r_t, prs_struct *ps,
545 int depth)
547 if (r_t == NULL)
548 return False;
550 prs_debug(ps, depth, desc, "net_io_r_getanydcname");
551 depth++;
553 if (!prs_uint32("ptr_dcname", ps, depth, &r_t->ptr_dcname))
554 return False;
556 if (!smb_io_unistr2("dcname", &r_t->uni_dcname,
557 r_t->ptr_dcname, ps, depth))
558 return False;
560 if (!prs_align(ps))
561 return False;
563 if (!prs_werror("status", ps, depth, &r_t->status))
564 return False;
566 return True;
569 /*******************************************************************
570 Inits an NET_R_TRUST_DOM_LIST structure.
571 ********************************************************************/
573 void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
574 uint32 num_doms, const char *dom_name)
576 unsigned int i = 0;
578 DEBUG(5,("init_r_trust_dom\n"));
580 for (i = 0; i < MAX_TRUST_DOMS; i++) {
581 r_t->uni_trust_dom_name[i].uni_str_len = 0;
582 r_t->uni_trust_dom_name[i].uni_max_len = 0;
584 if (num_doms > MAX_TRUST_DOMS)
585 num_doms = MAX_TRUST_DOMS;
587 for (i = 0; i < num_doms; i++) {
588 fstring domain_name;
589 fstrcpy(domain_name, dom_name);
590 strupper_m(domain_name);
591 init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, UNI_STR_TERMINATE);
592 /* the use of UNISTR2 here is non-standard. */
593 r_t->uni_trust_dom_name[i].offset = 0x1;
596 r_t->status = NT_STATUS_OK;
599 /*******************************************************************
600 Reads or writes an NET_R_TRUST_DOM_LIST structure.
601 ********************************************************************/
603 BOOL net_io_r_trust_dom(const char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth)
605 uint32 value;
607 if (r_t == NULL)
608 return False;
610 prs_debug(ps, depth, desc, "net_io_r_trust_dom");
611 depth++;
613 /* temporary code to give a valid response */
614 value=2;
615 if(!prs_uint32("status", ps, depth, &value))
616 return False;
618 value=1;
619 if(!prs_uint32("status", ps, depth, &value))
620 return False;
621 value=2;
622 if(!prs_uint32("status", ps, depth, &value))
623 return False;
625 value=0;
626 if(!prs_uint32("status", ps, depth, &value))
627 return False;
629 value=0;
630 if(!prs_uint32("status", ps, depth, &value))
631 return False;
633 /* old non working code */
634 #if 0
635 int i;
637 for (i = 0; i < MAX_TRUST_DOMS; i++) {
638 if (r_t->uni_trust_dom_name[i].uni_str_len == 0)
639 break;
640 if(!smb_io_unistr2("", &r_t->uni_trust_dom_name[i], True, ps, depth))
641 return False;
644 if(!prs_ntstatus("status", ps, depth, &r_t->status))
645 return False;
646 #endif
647 return True;
651 /*******************************************************************
652 Reads or writes an NET_Q_TRUST_DOM_LIST structure.
653 ********************************************************************/
655 BOOL net_io_q_trust_dom(const char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth)
657 if (q_l == NULL)
658 return False;
660 prs_debug(ps, depth, desc, "net_io_q_trust_dom");
661 depth++;
663 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
664 return False;
665 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
666 return False;
668 return True;
671 /*******************************************************************
672 Inits an NET_Q_REQ_CHAL structure.
673 ********************************************************************/
675 void init_q_req_chal(NET_Q_REQ_CHAL *q_c,
676 const char *logon_srv, const char *logon_clnt,
677 const DOM_CHAL *clnt_chal)
679 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
681 q_c->undoc_buffer = 1; /* don't know what this buffer is */
683 init_unistr2(&q_c->uni_logon_srv, logon_srv , UNI_STR_TERMINATE);
684 init_unistr2(&q_c->uni_logon_clnt, logon_clnt, UNI_STR_TERMINATE);
686 memcpy(q_c->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
688 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
691 /*******************************************************************
692 Reads or writes an NET_Q_REQ_CHAL structure.
693 ********************************************************************/
695 BOOL net_io_q_req_chal(const char *desc, NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth)
697 if (q_c == NULL)
698 return False;
700 prs_debug(ps, depth, desc, "net_io_q_req_chal");
701 depth++;
703 if(!prs_align(ps))
704 return False;
706 if(!prs_uint32("undoc_buffer", ps, depth, &q_c->undoc_buffer))
707 return False;
709 if(!smb_io_unistr2("", &q_c->uni_logon_srv, True, ps, depth)) /* logon server unicode string */
710 return False;
711 if(!smb_io_unistr2("", &q_c->uni_logon_clnt, True, ps, depth)) /* logon client unicode string */
712 return False;
714 if(!smb_io_chal("", &q_c->clnt_chal, ps, depth))
715 return False;
717 return True;
720 /*******************************************************************
721 Reads or writes a structure.
722 ********************************************************************/
724 BOOL net_io_r_req_chal(const char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth)
726 if (r_c == NULL)
727 return False;
729 prs_debug(ps, depth, desc, "net_io_r_req_chal");
730 depth++;
732 if(!prs_align(ps))
733 return False;
735 if(!smb_io_chal("", &r_c->srv_chal, ps, depth)) /* server challenge */
736 return False;
738 if(!prs_ntstatus("status", ps, depth, &r_c->status))
739 return False;
741 return True;
745 /*******************************************************************
746 Reads or writes a structure.
747 ********************************************************************/
749 BOOL net_io_q_auth(const char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
751 if (q_a == NULL)
752 return False;
754 prs_debug(ps, depth, desc, "net_io_q_auth");
755 depth++;
757 if(!prs_align(ps))
758 return False;
760 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
761 return False;
762 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
763 return False;
765 return True;
768 /*******************************************************************
769 Reads or writes a structure.
770 ********************************************************************/
772 BOOL net_io_r_auth(const char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
774 if (r_a == NULL)
775 return False;
777 prs_debug(ps, depth, desc, "net_io_r_auth");
778 depth++;
780 if(!prs_align(ps))
781 return False;
783 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
784 return False;
786 if(!prs_ntstatus("status", ps, depth, &r_a->status))
787 return False;
789 return True;
792 /*******************************************************************
793 Inits a NET_Q_AUTH_2 struct.
794 ********************************************************************/
796 void init_q_auth_2(NET_Q_AUTH_2 *q_a,
797 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
798 const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
800 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
802 init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
803 memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
804 q_a->clnt_flgs.neg_flags = clnt_flgs;
806 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
809 /*******************************************************************
810 Reads or writes a structure.
811 ********************************************************************/
813 BOOL net_io_q_auth_2(const char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth)
815 if (q_a == NULL)
816 return False;
818 prs_debug(ps, depth, desc, "net_io_q_auth_2");
819 depth++;
821 if(!prs_align(ps))
822 return False;
824 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
825 return False;
826 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
827 return False;
828 if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
829 return False;
831 return True;
834 /*******************************************************************
835 Reads or writes a structure.
836 ********************************************************************/
838 BOOL net_io_r_auth_2(const char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth)
840 if (r_a == NULL)
841 return False;
843 prs_debug(ps, depth, desc, "net_io_r_auth_2");
844 depth++;
846 if(!prs_align(ps))
847 return False;
849 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
850 return False;
851 if(!net_io_neg_flags("", &r_a->srv_flgs, ps, depth))
852 return False;
854 if(!prs_ntstatus("status", ps, depth, &r_a->status))
855 return False;
857 return True;
860 /*******************************************************************
861 Inits a NET_Q_AUTH_3 struct.
862 ********************************************************************/
864 void init_q_auth_3(NET_Q_AUTH_3 *q_a,
865 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
866 const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
868 DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
870 init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
871 memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
872 q_a->clnt_flgs.neg_flags = clnt_flgs;
874 DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
877 /*******************************************************************
878 Reads or writes a structure.
879 ********************************************************************/
881 BOOL net_io_q_auth_3(const char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int depth)
883 if (q_a == NULL)
884 return False;
886 prs_debug(ps, depth, desc, "net_io_q_auth_3");
887 depth++;
889 if(!prs_align(ps))
890 return False;
892 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
893 return False;
894 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
895 return False;
896 if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
897 return False;
899 return True;
902 /*******************************************************************
903 Reads or writes a structure.
904 ********************************************************************/
906 BOOL net_io_r_auth_3(const char *desc, NET_R_AUTH_3 *r_a, prs_struct *ps, int depth)
908 if (r_a == NULL)
909 return False;
911 prs_debug(ps, depth, desc, "net_io_r_auth_3");
912 depth++;
914 if(!prs_align(ps))
915 return False;
917 if(!smb_io_chal("srv_chal", &r_a->srv_chal, ps, depth)) /* server challenge */
918 return False;
919 if(!net_io_neg_flags("srv_flgs", &r_a->srv_flgs, ps, depth))
920 return False;
921 if (!prs_uint32("unknown", ps, depth, &r_a->unknown))
922 return False;
924 if(!prs_ntstatus("status", ps, depth, &r_a->status))
925 return False;
927 return True;
931 /*******************************************************************
932 Inits a NET_Q_SRV_PWSET.
933 ********************************************************************/
935 void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s,
936 const char *logon_srv, const char *sess_key, const char *acct_name,
937 uint16 sec_chan, const char *comp_name,
938 DOM_CRED *cred, const uchar hashed_mach_pwd[16])
940 unsigned char nt_cypher[16];
942 DEBUG(5,("init_q_srv_pwset\n"));
944 /* Process the new password. */
945 cred_hash3( nt_cypher, hashed_mach_pwd, (const unsigned char *)sess_key, 1);
947 init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
949 memcpy(q_s->pwd, nt_cypher, sizeof(q_s->pwd));
952 /*******************************************************************
953 Reads or writes a structure.
954 ********************************************************************/
956 BOOL net_io_q_srv_pwset(const char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth)
958 if (q_s == NULL)
959 return False;
961 prs_debug(ps, depth, desc, "net_io_q_srv_pwset");
962 depth++;
964 if(!prs_align(ps))
965 return False;
967 if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */
968 return False;
969 if(!prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16)) /* new password - undocumented */
970 return False;
972 return True;
975 /*******************************************************************
976 Reads or writes a structure.
977 ********************************************************************/
979 BOOL net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth)
981 if (r_s == NULL)
982 return False;
984 prs_debug(ps, depth, desc, "net_io_r_srv_pwset");
985 depth++;
987 if(!prs_align(ps))
988 return False;
990 if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */
991 return False;
993 if(!prs_ntstatus("status", ps, depth, &r_s->status))
994 return False;
996 return True;
999 /*************************************************************************
1000 Init DOM_SID2 array from a string containing multiple sids
1001 *************************************************************************/
1003 static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids)
1005 const char *ptr;
1006 pstring s2;
1007 int count = 0;
1009 DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
1011 *ppsids = NULL;
1013 if(sids_str) {
1014 int number;
1015 DOM_SID2 *sids;
1017 /* Count the number of valid SIDs. */
1018 for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1019 DOM_SID tmpsid;
1020 if (string_to_sid(&tmpsid, s2))
1021 count++;
1024 /* Now allocate space for them. */
1025 if (count) {
1026 *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
1027 if (*ppsids == NULL)
1028 return 0;
1029 } else {
1030 *ppsids = NULL;
1033 sids = *ppsids;
1035 for (number = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1036 DOM_SID tmpsid;
1037 if (string_to_sid(&tmpsid, s2)) {
1038 /* count only valid sids */
1039 init_dom_sid2(&sids[number], &tmpsid);
1040 number++;
1045 return count;
1048 /*******************************************************************
1049 Inits a NET_ID_INFO_1 structure.
1050 ********************************************************************/
1052 void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
1053 uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high,
1054 const char *user_name, const char *wksta_name,
1055 const char *sess_key,
1056 unsigned char lm_cypher[16], unsigned char nt_cypher[16])
1058 unsigned char lm_owf[16];
1059 unsigned char nt_owf[16];
1061 DEBUG(5,("init_id_info1: %d\n", __LINE__));
1063 id->ptr_id_info1 = 1;
1065 id->param_ctrl = param_ctrl;
1066 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1069 if (lm_cypher && nt_cypher) {
1070 unsigned char key[16];
1071 #ifdef DEBUG_PASSWORD
1072 DEBUG(100,("lm cypher:"));
1073 dump_data(100, (char *)lm_cypher, 16);
1075 DEBUG(100,("nt cypher:"));
1076 dump_data(100, (char *)nt_cypher, 16);
1077 #endif
1079 memset(key, 0, 16);
1080 memcpy(key, sess_key, 8);
1082 memcpy(lm_owf, lm_cypher, 16);
1083 SamOEMhash(lm_owf, key, 16);
1084 memcpy(nt_owf, nt_cypher, 16);
1085 SamOEMhash(nt_owf, key, 16);
1087 #ifdef DEBUG_PASSWORD
1088 DEBUG(100,("encrypt of lm owf password:"));
1089 dump_data(100, (char *)lm_owf, 16);
1091 DEBUG(100,("encrypt of nt owf password:"));
1092 dump_data(100, (char *)nt_owf, 16);
1093 #endif
1094 /* set up pointers to cypher blocks */
1095 lm_cypher = lm_owf;
1096 nt_cypher = nt_owf;
1099 init_owf_info(&id->lm_owf, lm_cypher);
1100 init_owf_info(&id->nt_owf, nt_cypher);
1102 init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1103 init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1104 init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1105 init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1106 init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1107 init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1110 /*******************************************************************
1111 Reads or writes an NET_ID_INFO_1 structure.
1112 ********************************************************************/
1114 static BOOL net_io_id_info1(const char *desc, NET_ID_INFO_1 *id, prs_struct *ps, int depth)
1116 if (id == NULL)
1117 return False;
1119 prs_debug(ps, depth, desc, "net_io_id_info1");
1120 depth++;
1122 if(!prs_align(ps))
1123 return False;
1125 if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1))
1126 return False;
1128 if (id->ptr_id_info1 != 0) {
1129 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1130 return False;
1132 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1133 return False;
1134 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1135 return False;
1137 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1138 return False;
1139 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1140 return False;
1142 if(!smb_io_owf_info("", &id->lm_owf, ps, depth))
1143 return False;
1144 if(!smb_io_owf_info("", &id->nt_owf, ps, depth))
1145 return False;
1147 if(!smb_io_unistr2("unistr2", &id->uni_domain_name,
1148 id->hdr_domain_name.buffer, ps, depth))
1149 return False;
1150 if(!smb_io_unistr2("unistr2", &id->uni_user_name,
1151 id->hdr_user_name.buffer, ps, depth))
1152 return False;
1153 if(!smb_io_unistr2("unistr2", &id->uni_wksta_name,
1154 id->hdr_wksta_name.buffer, ps, depth))
1155 return False;
1158 return True;
1161 /*******************************************************************
1162 Inits a NET_ID_INFO_2 structure.
1164 This is a network logon packet. The log_id parameters
1165 are what an NT server would generate for LUID once the
1166 user is logged on. I don't think we care about them.
1168 Note that this has no access to the NT and LM hashed passwords,
1169 so it forwards the challenge, and the NT and LM responses (24
1170 bytes each) over the secure channel to the Domain controller
1171 for it to say yea or nay. This is the preferred method of
1172 checking for a logon as it doesn't export the password
1173 hashes to anyone who has compromised the secure channel. JRA.
1174 ********************************************************************/
1176 void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
1177 uint32 param_ctrl,
1178 uint32 log_id_low, uint32 log_id_high,
1179 const char *user_name, const char *wksta_name,
1180 const uchar lm_challenge[8],
1181 const uchar * lm_chal_resp, size_t lm_chal_resp_len,
1182 const uchar * nt_chal_resp, size_t nt_chal_resp_len)
1185 DEBUG(5,("init_id_info2: %d\n", __LINE__));
1187 id->ptr_id_info2 = 1;
1189 id->param_ctrl = param_ctrl;
1190 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1192 memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));
1193 init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);
1194 init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);
1196 init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1197 init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1198 init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1199 init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1200 init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1201 init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1203 init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);
1204 init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);
1208 /*******************************************************************
1209 Reads or writes an NET_ID_INFO_2 structure.
1210 ********************************************************************/
1212 static BOOL net_io_id_info2(const char *desc, NET_ID_INFO_2 *id, prs_struct *ps, int depth)
1214 if (id == NULL)
1215 return False;
1217 prs_debug(ps, depth, desc, "net_io_id_info2");
1218 depth++;
1220 if(!prs_align(ps))
1221 return False;
1223 if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2))
1224 return False;
1226 if (id->ptr_id_info2 != 0) {
1227 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1228 return False;
1230 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1231 return False;
1232 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1233 return False;
1235 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1236 return False;
1237 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1238 return False;
1240 if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */
1241 return False;
1243 if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth))
1244 return False;
1245 if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth))
1246 return False;
1248 if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name,
1249 id->hdr_domain_name.buffer, ps, depth))
1250 return False;
1251 if(!smb_io_unistr2("uni_user_name ", &id->uni_user_name,
1252 id->hdr_user_name.buffer, ps, depth))
1253 return False;
1254 if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name,
1255 id->hdr_wksta_name.buffer, ps, depth))
1256 return False;
1257 if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp,
1258 id->hdr_nt_chal_resp.buffer, ps, depth))
1259 return False;
1260 if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp,
1261 id->hdr_lm_chal_resp.buffer, ps, depth))
1262 return False;
1265 return True;
1269 /*******************************************************************
1270 Inits a DOM_SAM_INFO structure.
1271 ********************************************************************/
1273 void init_sam_info(DOM_SAM_INFO *sam,
1274 const char *logon_srv, const char *comp_name,
1275 DOM_CRED *clnt_cred,
1276 DOM_CRED *rtn_cred, uint16 logon_level,
1277 NET_ID_INFO_CTR *ctr)
1279 DEBUG(5,("init_sam_info: %d\n", __LINE__));
1281 init_clnt_info2(&sam->client, logon_srv, comp_name, clnt_cred);
1283 if (rtn_cred != NULL) {
1284 sam->ptr_rtn_cred = 1;
1285 memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred));
1286 } else {
1287 sam->ptr_rtn_cred = 0;
1290 sam->logon_level = logon_level;
1291 sam->ctr = ctr;
1294 /*******************************************************************
1295 Reads or writes a DOM_SAM_INFO structure.
1296 ********************************************************************/
1298 static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1300 NET_ID_INFO_CTR *ctr = *pp_ctr;
1302 prs_debug(ps, depth, desc, "smb_io_sam_info_ctr");
1303 depth++;
1305 if (UNMARSHALLING(ps)) {
1306 ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
1307 if (ctr == NULL)
1308 return False;
1311 if (ctr == NULL)
1312 return False;
1314 /* don't 4-byte align here! */
1316 if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value))
1317 return False;
1319 switch (ctr->switch_value) {
1320 case 1:
1321 if(!net_io_id_info1("", &ctr->auth.id1, ps, depth))
1322 return False;
1323 break;
1324 case 2:
1325 if(!net_io_id_info2("", &ctr->auth.id2, ps, depth))
1326 return False;
1327 break;
1328 default:
1329 /* PANIC! */
1330 DEBUG(4,("smb_io_sam_info_ctr: unknown switch_value!\n"));
1331 break;
1334 return True;
1337 /*******************************************************************
1338 Reads or writes a DOM_SAM_INFO structure.
1339 ********************************************************************/
1341 static BOOL smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
1343 if (sam == NULL)
1344 return False;
1346 prs_debug(ps, depth, desc, "smb_io_sam_info");
1347 depth++;
1349 if(!prs_align(ps))
1350 return False;
1352 if(!smb_io_clnt_info2("", &sam->client, ps, depth))
1353 return False;
1355 if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred))
1356 return False;
1357 if (sam->ptr_rtn_cred) {
1358 if(!smb_io_cred("", &sam->rtn_cred, ps, depth))
1359 return False;
1362 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1363 return False;
1365 if (sam->logon_level != 0) {
1366 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1367 return False;
1370 return True;
1373 /*******************************************************************
1374 Reads or writes a DOM_SAM_INFO_EX structure.
1375 ********************************************************************/
1377 static BOOL smb_io_sam_info_ex(const char *desc, DOM_SAM_INFO_EX *sam, prs_struct *ps, int depth)
1379 if (sam == NULL)
1380 return False;
1382 prs_debug(ps, depth, desc, "smb_io_sam_info_ex");
1383 depth++;
1385 if(!prs_align(ps))
1386 return False;
1388 if(!smb_io_clnt_srv("", &sam->client, ps, depth))
1389 return False;
1391 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1392 return False;
1394 if (sam->logon_level != 0) {
1395 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1396 return False;
1399 return True;
1402 /*************************************************************************
1403 Inits a NET_USER_INFO_3 structure.
1405 This is a network logon reply packet, and contains much information about
1406 the user. This information is passed as a (very long) paramater list
1407 to avoid having to link in the PASSDB code to every program that deals
1408 with this file.
1409 *************************************************************************/
1411 void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
1412 uint32 user_rid,
1413 uint32 group_rid,
1415 const char* user_name,
1416 const char* full_name,
1417 const char* home_dir,
1418 const char* dir_drive,
1419 const char* logon_script,
1420 const char* profile_path,
1422 time_t unix_logon_time,
1423 time_t unix_logoff_time,
1424 time_t unix_kickoff_time,
1425 time_t unix_pass_last_set_time,
1426 time_t unix_pass_can_change_time,
1427 time_t unix_pass_must_change_time,
1429 uint16 logon_count, uint16 bad_pw_count,
1430 uint32 num_groups, const DOM_GID *gids,
1431 uint32 user_flgs, uint32 acct_flags,
1432 uchar user_session_key[16],
1433 uchar lm_session_key[16],
1434 const char *logon_srv, const char *logon_dom,
1435 const DOM_SID *dom_sid)
1437 /* only cope with one "other" sid, right now. */
1438 /* need to count the number of space-delimited sids */
1439 unsigned int i;
1440 int num_other_sids = 0;
1442 NTTIME logon_time, logoff_time, kickoff_time,
1443 pass_last_set_time, pass_can_change_time,
1444 pass_must_change_time;
1446 ZERO_STRUCTP(usr);
1448 usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */
1450 /* Create NTTIME structs */
1451 unix_to_nt_time (&logon_time, unix_logon_time);
1452 unix_to_nt_time (&logoff_time, unix_logoff_time);
1453 unix_to_nt_time (&kickoff_time, unix_kickoff_time);
1454 unix_to_nt_time (&pass_last_set_time, unix_pass_last_set_time);
1455 unix_to_nt_time (&pass_can_change_time, unix_pass_can_change_time);
1456 unix_to_nt_time (&pass_must_change_time, unix_pass_must_change_time);
1458 usr->logon_time = logon_time;
1459 usr->logoff_time = logoff_time;
1460 usr->kickoff_time = kickoff_time;
1461 usr->pass_last_set_time = pass_last_set_time;
1462 usr->pass_can_change_time = pass_can_change_time;
1463 usr->pass_must_change_time = pass_must_change_time;
1465 usr->logon_count = logon_count;
1466 usr->bad_pw_count = bad_pw_count;
1468 usr->user_rid = user_rid;
1469 usr->group_rid = group_rid;
1470 usr->num_groups = num_groups;
1472 usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */
1473 usr->user_flgs = user_flgs;
1474 usr->acct_flags = acct_flags;
1476 if (user_session_key != NULL)
1477 memcpy(usr->user_sess_key, user_session_key, sizeof(usr->user_sess_key));
1478 else
1479 memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key));
1481 usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */
1483 memset((char *)usr->lm_sess_key, '\0', sizeof(usr->lm_sess_key));
1485 for (i=0; i<7; i++) {
1486 memset(&usr->unknown[i], '\0', sizeof(usr->unknown));
1489 if (lm_session_key != NULL) {
1490 memcpy(usr->lm_sess_key, lm_session_key, sizeof(usr->lm_sess_key));
1493 num_other_sids = init_dom_sid2s(ctx, NULL, &usr->other_sids);
1495 usr->num_other_sids = num_other_sids;
1496 usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0;
1498 init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
1499 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
1500 init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
1501 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
1502 init_unistr2(&usr->uni_logon_script, logon_script, UNI_FLAGS_NONE);
1503 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
1504 init_unistr2(&usr->uni_profile_path, profile_path, UNI_FLAGS_NONE);
1505 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
1506 init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
1507 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
1508 init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
1509 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
1511 usr->num_groups2 = num_groups;
1513 if (num_groups) {
1514 usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
1515 if (usr->gids == NULL)
1516 return;
1517 } else {
1518 usr->gids = NULL;
1521 for (i = 0; i < num_groups; i++)
1522 usr->gids[i] = gids[i];
1524 init_unistr2(&usr->uni_logon_srv, logon_srv, UNI_FLAGS_NONE);
1525 init_uni_hdr(&usr->hdr_logon_srv, &usr->uni_logon_srv);
1526 init_unistr2(&usr->uni_logon_dom, logon_dom, UNI_FLAGS_NONE);
1527 init_uni_hdr(&usr->hdr_logon_dom, &usr->uni_logon_dom);
1529 init_dom_sid2(&usr->dom_sid, dom_sid);
1530 /* "other" sids are set up above */
1533 static void dump_acct_flags(uint32 acct_flags) {
1535 int lvl = 10;
1536 DEBUG(lvl,("dump_acct_flags\n"));
1537 if (acct_flags & ACB_NORMAL) {
1538 DEBUGADD(lvl,("\taccount has ACB_NORMAL\n"));
1540 if (acct_flags & ACB_PWNOEXP) {
1541 DEBUGADD(lvl,("\taccount has ACB_PWNOEXP\n"));
1543 if (acct_flags & ACB_ENC_TXT_PWD_ALLOWED) {
1544 DEBUGADD(lvl,("\taccount has ACB_ENC_TXT_PWD_ALLOWED\n"));
1546 if (acct_flags & ACB_NOT_DELEGATED) {
1547 DEBUGADD(lvl,("\taccount has ACB_NOT_DELEGATED\n"));
1549 if (acct_flags & ACB_USE_DES_KEY_ONLY) {
1550 DEBUGADD(lvl,("\taccount has ACB_USE_DES_KEY_ONLY set, sig verify wont work\n"));
1552 if (acct_flags & ACB_NO_AUTH_DATA_REQD) {
1553 DEBUGADD(lvl,("\taccount has ACB_NO_AUTH_DATA_REQD set\n"));
1555 if (acct_flags & ACB_PWEXPIRED) {
1556 DEBUGADD(lvl,("\taccount has ACB_PWEXPIRED set\n"));
1560 static void dump_user_flgs(uint32 user_flags) {
1562 int lvl = 10;
1563 DEBUG(lvl,("dump_user_flgs\n"));
1564 if (user_flags & LOGON_EXTRA_SIDS) {
1565 DEBUGADD(lvl,("\taccount has LOGON_EXTRA_SIDS\n"));
1567 if (user_flags & LOGON_RESOURCE_GROUPS) {
1568 DEBUGADD(lvl,("\taccount has LOGON_RESOURCE_GROUPS\n"));
1570 if (user_flags & LOGON_NTLMV2_ENABLED) {
1571 DEBUGADD(lvl,("\taccount has LOGON_NTLMV2_ENABLED\n"));
1573 if (user_flags & LOGON_CACHED_ACCOUNT) {
1574 DEBUGADD(lvl,("\taccount has LOGON_CACHED_ACCOUNT\n"));
1576 if (user_flags & LOGON_PROFILE_PATH_RETURNED) {
1577 DEBUGADD(lvl,("\taccount has LOGON_PROFILE_PATH_RETURNED\n"));
1579 if (user_flags & LOGON_SERVER_TRUST_ACCOUNT) {
1580 DEBUGADD(lvl,("\taccount has LOGON_SERVER_TRUST_ACCOUNT\n"));
1586 /*******************************************************************
1587 This code has been modified to cope with a NET_USER_INFO_2 - which is
1588 exactly the same as a NET_USER_INFO_3, minus the other sids parameters.
1589 We use validation level to determine if we're marshalling a info 2 or
1590 INFO_3 - be we always return an INFO_3. Based on code donated by Marc
1591 Jacobsen at HP. JRA.
1592 ********************************************************************/
1594 BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
1595 int depth, uint16 validation_level, BOOL kerb_validation_level)
1597 unsigned int i;
1599 if (usr == NULL)
1600 return False;
1602 prs_debug(ps, depth, desc, "net_io_user_info3");
1603 depth++;
1605 if (UNMARSHALLING(ps))
1606 ZERO_STRUCTP(usr);
1608 if(!prs_align(ps))
1609 return False;
1611 if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info))
1612 return False;
1614 if (usr->ptr_user_info == 0)
1615 return True;
1617 if(!smb_io_time("logon time", &usr->logon_time, ps, depth)) /* logon time */
1618 return False;
1619 if(!smb_io_time("logoff time", &usr->logoff_time, ps, depth)) /* logoff time */
1620 return False;
1621 if(!smb_io_time("kickoff time", &usr->kickoff_time, ps, depth)) /* kickoff time */
1622 return False;
1623 if(!smb_io_time("last set time", &usr->pass_last_set_time, ps, depth)) /* password last set time */
1624 return False;
1625 if(!smb_io_time("can change time", &usr->pass_can_change_time , ps, depth)) /* password can change time */
1626 return False;
1627 if(!smb_io_time("must change time", &usr->pass_must_change_time, ps, depth)) /* password must change time */
1628 return False;
1630 if(!smb_io_unihdr("hdr_user_name", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
1631 return False;
1632 if(!smb_io_unihdr("hdr_full_name", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
1633 return False;
1634 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
1635 return False;
1636 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
1637 return False;
1638 if(!smb_io_unihdr("hdr_home_dir", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
1639 return False;
1640 if(!smb_io_unihdr("hdr_dir_drive", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */
1641 return False;
1643 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count)) /* logon count */
1644 return False;
1645 if(!prs_uint16("bad_pw_count ", ps, depth, &usr->bad_pw_count)) /* bad password count */
1646 return False;
1648 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User RID */
1649 return False;
1650 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group RID */
1651 return False;
1652 if(!prs_uint32("num_groups ", ps, depth, &usr->num_groups)) /* num groups */
1653 return False;
1654 if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */
1655 return False;
1656 if(!prs_uint32("user_flgs ", ps, depth, &usr->user_flgs)) /* user flags */
1657 return False;
1658 dump_user_flgs(usr->user_flgs);
1659 if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* user session key */
1660 return False;
1662 if(!smb_io_unihdr("hdr_logon_srv", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */
1663 return False;
1664 if(!smb_io_unihdr("hdr_logon_dom", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */
1665 return False;
1667 if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */
1668 return False;
1670 if(!prs_uint8s(False, "lm_sess_key", ps, depth, usr->lm_sess_key, 8)) /* lm session key */
1671 return False;
1673 if(!prs_uint32("acct_flags ", ps, depth, &usr->acct_flags)) /* Account flags */
1674 return False;
1675 dump_acct_flags(usr->acct_flags);
1676 for (i = 0; i < 7; i++)
1678 if (!prs_uint32("unkown", ps, depth, &usr->unknown[i])) /* unknown */
1679 return False;
1682 if (validation_level == 3) {
1683 if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */
1684 return False;
1685 if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */
1686 return False;
1687 } else {
1688 if (UNMARSHALLING(ps)) {
1689 usr->num_other_sids = 0;
1690 usr->buffer_other_sids = 0;
1694 /* get kerb validation info (not really part of user_info_3) - Guenther */
1696 if (kerb_validation_level) {
1698 if(!prs_uint32("ptr_res_group_dom_sid", ps, depth, &usr->ptr_res_group_dom_sid))
1699 return False;
1700 if(!prs_uint32("res_group_count", ps, depth, &usr->res_group_count))
1701 return False;
1702 if(!prs_uint32("ptr_res_groups", ps, depth, &usr->ptr_res_groups))
1703 return False;
1706 if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
1707 return False;
1708 if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
1709 return False;
1710 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
1711 return False;
1712 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
1713 return False;
1714 if(!smb_io_unistr2("uni_home_dir", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
1715 return False;
1716 if(!smb_io_unistr2("uni_dir_drive", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
1717 return False;
1719 if(!prs_align(ps))
1720 return False;
1722 if(!prs_uint32("num_groups2 ", ps, depth, &usr->num_groups2)) /* num groups2 */
1723 return False;
1725 if (usr->num_groups != usr->num_groups2) {
1726 DEBUG(3,("net_io_user_info3: num_groups mismatch! (%d != %d)\n",
1727 usr->num_groups, usr->num_groups2));
1728 return False;
1731 if (UNMARSHALLING(ps)) {
1732 if (usr->num_groups) {
1733 usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups);
1734 if (usr->gids == NULL)
1735 return False;
1736 } else {
1737 usr->gids = NULL;
1741 for (i = 0; i < usr->num_groups; i++) {
1742 if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */
1743 return False;
1746 if(!smb_io_unistr2("uni_logon_srv", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */
1747 return False;
1748 if(!smb_io_unistr2("uni_logon_dom", &usr->uni_logon_dom, usr->hdr_logon_dom.buffer, ps, depth)) /* logon domain unicode string */
1749 return False;
1751 if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth)) /* domain SID */
1752 return False;
1754 if (validation_level == 3 && usr->buffer_other_sids) {
1756 uint32 num_other_sids = usr->num_other_sids;
1758 if (!(usr->user_flgs & LOGON_EXTRA_SIDS)) {
1759 DEBUG(10,("net_io_user_info3: user_flgs attribute does not have LOGON_EXTRA_SIDS\n"));
1760 /* return False; */
1763 if (!prs_uint32("num_other_sids", ps, depth,
1764 &num_other_sids))
1765 return False;
1767 if (num_other_sids != usr->num_other_sids)
1768 return False;
1770 if (UNMARSHALLING(ps)) {
1771 if (usr->num_other_sids) {
1772 usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
1773 usr->other_sids_attrib =
1774 PRS_ALLOC_MEM(ps, uint32, usr->num_other_sids);
1775 } else {
1776 usr->other_sids = NULL;
1777 usr->other_sids_attrib = NULL;
1780 if ((num_other_sids != 0) &&
1781 ((usr->other_sids == NULL) ||
1782 (usr->other_sids_attrib == NULL)))
1783 return False;
1786 /* First the pointers to the SIDS and attributes */
1788 depth++;
1790 for (i=0; i<usr->num_other_sids; i++) {
1791 uint32 ptr = 1;
1793 if (!prs_uint32("sid_ptr", ps, depth, &ptr))
1794 return False;
1796 if (UNMARSHALLING(ps) && (ptr == 0))
1797 return False;
1799 if (!prs_uint32("attribute", ps, depth,
1800 &usr->other_sids_attrib[i]))
1801 return False;
1804 for (i = 0; i < usr->num_other_sids; i++) {
1805 if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */
1806 return False;
1809 depth--;
1812 return True;
1815 /*******************************************************************
1816 Reads or writes a structure.
1817 ********************************************************************/
1819 BOOL net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
1821 if (q_l == NULL)
1822 return False;
1824 prs_debug(ps, depth, desc, "net_io_q_sam_logon");
1825 depth++;
1827 if(!prs_align(ps))
1828 return False;
1830 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))
1831 return False;
1833 if(!prs_align_uint16(ps))
1834 return False;
1836 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1837 return False;
1839 return True;
1842 /*******************************************************************
1843 Reads or writes a structure.
1844 ********************************************************************/
1846 BOOL net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
1848 if (r_l == NULL)
1849 return False;
1851 prs_debug(ps, depth, desc, "net_io_r_sam_logon");
1852 depth++;
1854 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1855 return False;
1856 if (&r_l->buffer_creds) {
1857 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
1858 return False;
1861 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
1862 return False;
1863 if(!prs_align(ps))
1864 return False;
1866 #if 1 /* W2k always needs this - even for bad passwd. JRA */
1867 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1868 return False;
1869 #else
1870 if (r_l->switch_value != 0) {
1871 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1872 return False;
1874 #endif
1876 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
1877 return False;
1879 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1880 return False;
1882 if(!prs_align(ps))
1883 return False;
1885 return True;
1888 /*******************************************************************
1889 Reads or writes a structure.
1890 ********************************************************************/
1892 BOOL net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct *ps, int depth)
1894 if (q_l == NULL)
1895 return False;
1897 prs_debug(ps, depth, desc, "net_io_q_sam_logon_ex");
1898 depth++;
1900 if(!prs_align(ps))
1901 return False;
1903 if(!smb_io_sam_info_ex("", &q_l->sam_id, ps, depth))
1904 return False;
1906 if(!prs_align_uint16(ps))
1907 return False;
1909 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1910 return False;
1912 if(!prs_uint32("flags ", ps, depth, &q_l->flags))
1913 return False;
1915 return True;
1918 /*******************************************************************
1919 Reads or writes a structure.
1920 ********************************************************************/
1922 BOOL net_io_r_sam_logon_ex(const char *desc, NET_R_SAM_LOGON_EX *r_l, prs_struct *ps, int depth)
1924 if (r_l == NULL)
1925 return False;
1927 prs_debug(ps, depth, desc, "net_io_r_sam_logon_ex");
1928 depth++;
1930 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
1931 return False;
1932 if(!prs_align(ps))
1933 return False;
1935 #if 1 /* W2k always needs this - even for bad passwd. JRA */
1936 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1937 return False;
1938 #else
1939 if (r_l->switch_value != 0) {
1940 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1941 return False;
1943 #endif
1945 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
1946 return False;
1948 if(!prs_uint32("flags ", ps, depth, &r_l->flags))
1949 return False;
1951 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1952 return False;
1954 if(!prs_align(ps))
1955 return False;
1957 return True;
1961 /*******************************************************************
1962 Reads or writes a structure.
1963 ********************************************************************/
1965 BOOL net_io_q_sam_logoff(const char *desc, NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
1967 if (q_l == NULL)
1968 return False;
1970 prs_debug(ps, depth, desc, "net_io_q_sam_logoff");
1971 depth++;
1973 if(!prs_align(ps))
1974 return False;
1976 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth)) /* domain SID */
1977 return False;
1979 return True;
1982 /*******************************************************************
1983 Reads or writes a structure.
1984 ********************************************************************/
1986 BOOL net_io_r_sam_logoff(const char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
1988 if (r_l == NULL)
1989 return False;
1991 prs_debug(ps, depth, desc, "net_io_r_sam_logoff");
1992 depth++;
1994 if(!prs_align(ps))
1995 return False;
1997 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1998 return False;
1999 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
2000 return False;
2002 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
2003 return False;
2005 return True;
2008 /*******************************************************************
2009 makes a NET_Q_SAM_SYNC structure.
2010 ********************************************************************/
2011 BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
2012 const char *cli_name, DOM_CRED *cli_creds,
2013 DOM_CRED *ret_creds, uint32 database_id,
2014 uint32 next_rid)
2016 DEBUG(5, ("init_q_sam_sync\n"));
2018 init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
2019 init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
2021 if (cli_creds)
2022 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
2024 if (cli_creds)
2025 memcpy(&q_s->ret_creds, ret_creds, sizeof(q_s->ret_creds));
2026 else
2027 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
2029 q_s->database_id = database_id;
2030 q_s->restart_state = 0;
2031 q_s->sync_context = next_rid;
2032 q_s->max_size = 0xffff;
2034 return True;
2037 /*******************************************************************
2038 reads or writes a structure.
2039 ********************************************************************/
2040 BOOL net_io_q_sam_sync(const char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
2041 int depth)
2043 prs_debug(ps, depth, desc, "net_io_q_sam_sync");
2044 depth++;
2046 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
2047 return False;
2048 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
2049 return False;
2051 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
2052 return False;
2053 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
2054 return False;
2056 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
2057 return False;
2058 if (!prs_uint32("restart_state", ps, depth, &q_s->restart_state))
2059 return False;
2060 if (!prs_uint32("sync_context ", ps, depth, &q_s->sync_context))
2061 return False;
2063 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
2064 return False;
2066 return True;
2069 /*******************************************************************
2070 reads or writes a structure.
2071 ********************************************************************/
2072 static BOOL net_io_sam_delta_hdr(const char *desc, SAM_DELTA_HDR * delta,
2073 prs_struct *ps, int depth)
2075 prs_debug(ps, depth, desc, "net_io_sam_delta_hdr");
2076 depth++;
2078 if (!prs_uint16("type", ps, depth, &delta->type))
2079 return False;
2080 if (!prs_uint16("type2", ps, depth, &delta->type2))
2081 return False;
2082 if (!prs_uint32("target_rid", ps, depth, &delta->target_rid))
2083 return False;
2085 if (!prs_uint32("type3", ps, depth, &delta->type3))
2086 return False;
2088 /* Not sure why we need this but it seems to be necessary to get
2089 sam deltas working. */
2091 if (delta->type != 0x16) {
2092 if (!prs_uint32("ptr_delta", ps, depth, &delta->ptr_delta))
2093 return False;
2096 return True;
2099 /*******************************************************************
2100 reads or writes a structure.
2101 ********************************************************************/
2102 static BOOL net_io_sam_delta_mod_count(const char *desc, SAM_DELTA_MOD_COUNT *info,
2103 prs_struct *ps, int depth)
2105 prs_debug(ps, depth, desc, "net_io_sam_delta_stamp");
2106 depth++;
2108 if (!prs_uint32("seqnum", ps, depth, &info->seqnum))
2109 return False;
2110 if (!prs_uint32("dom_mod_count_ptr", ps, depth,
2111 &info->dom_mod_count_ptr))
2112 return False;
2114 if (info->dom_mod_count_ptr) {
2115 if (!prs_uint64("dom_mod_count", ps, depth,
2116 &info->dom_mod_count))
2117 return False;
2120 return True;
2123 /*******************************************************************
2124 reads or writes a structure.
2125 ********************************************************************/
2126 static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
2127 prs_struct *ps, int depth)
2129 prs_debug(ps, depth, desc, "net_io_sam_domain_info");
2130 depth++;
2132 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2133 return False;
2134 if (!smb_io_unihdr("hdr_oem_info", &info->hdr_oem_info, ps, depth))
2135 return False;
2137 if (!prs_uint64("force_logoff", ps, depth, &info->force_logoff))
2138 return False;
2139 if (!prs_uint16("min_pwd_len", ps, depth, &info->min_pwd_len))
2140 return False;
2141 if (!prs_uint16("pwd_history_len", ps, depth, &info->pwd_history_len))
2142 return False;
2143 if (!prs_uint64("max_pwd_age", ps, depth, &info->max_pwd_age))
2144 return False;
2145 if (!prs_uint64("min_pwd_age", ps, depth, &info->min_pwd_age))
2146 return False;
2147 if (!prs_uint64("dom_mod_count", ps, depth, &info->dom_mod_count))
2148 return False;
2149 if (!smb_io_time("creation_time", &info->creation_time, ps, depth))
2150 return False;
2151 if (!prs_uint32("security_information", ps, depth, &info->security_information))
2152 return False;
2153 if (!smb_io_bufhdr4("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2154 return False;
2155 if (!smb_io_lockout_string_hdr("hdr_account_lockout_string", &info->hdr_account_lockout, ps, depth))
2156 return False;
2157 if (!smb_io_unihdr("hdr_unknown2", &info->hdr_unknown2, ps, depth))
2158 return False;
2159 if (!smb_io_unihdr("hdr_unknown3", &info->hdr_unknown3, ps, depth))
2160 return False;
2161 if (!smb_io_unihdr("hdr_unknown4", &info->hdr_unknown4, ps, depth))
2162 return False;
2163 if (!prs_uint32("logon_chgpass", ps, depth, &info->logon_chgpass))
2164 return False;
2165 if (!prs_uint32("unknown6", ps, depth, &info->unknown6))
2166 return False;
2167 if (!prs_uint32("unknown7", ps, depth, &info->unknown7))
2168 return False;
2169 if (!prs_uint32("unknown8", ps, depth, &info->unknown8))
2170 return False;
2172 if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
2173 info->hdr_dom_name.buffer, ps, depth))
2174 return False;
2175 if (!smb_io_unistr2("buf_oem_info", &info->buf_oem_info,
2176 info->hdr_oem_info.buffer, ps, depth))
2177 return False;
2179 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2180 return False;
2182 if (!smb_io_account_lockout_str("account_lockout", &info->account_lockout,
2183 info->hdr_account_lockout.buffer, ps, depth))
2184 return False;
2186 if (!smb_io_unistr2("buf_unknown2", &info->buf_unknown2,
2187 info->hdr_unknown2.buffer, ps, depth))
2188 return False;
2189 if (!smb_io_unistr2("buf_unknown3", &info->buf_unknown3,
2190 info->hdr_unknown3.buffer, ps, depth))
2191 return False;
2192 if (!smb_io_unistr2("buf_unknown4", &info->buf_unknown4,
2193 info->hdr_unknown4.buffer, ps, depth))
2194 return False;
2196 return True;
2199 /*******************************************************************
2200 reads or writes a structure.
2201 ********************************************************************/
2202 static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
2203 prs_struct *ps, int depth)
2205 prs_debug(ps, depth, desc, "net_io_sam_group_info");
2206 depth++;
2208 if (!smb_io_unihdr("hdr_grp_name", &info->hdr_grp_name, ps, depth))
2209 return False;
2210 if (!smb_io_gid("gid", &info->gid, ps, depth))
2211 return False;
2212 if (!smb_io_unihdr("hdr_grp_desc", &info->hdr_grp_desc, ps, depth))
2213 return False;
2214 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2215 return False;
2217 if (ps->data_offset + 48 > ps->buffer_size)
2218 return False;
2219 ps->data_offset += 48;
2221 if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
2222 info->hdr_grp_name.buffer, ps, depth))
2223 return False;
2224 if (!smb_io_unistr2("uni_grp_desc", &info->uni_grp_desc,
2225 info->hdr_grp_desc.buffer, ps, depth))
2226 return False;
2227 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2228 return False;
2230 return True;
2233 /*******************************************************************
2234 reads or writes a structure.
2235 ********************************************************************/
2236 static BOOL net_io_sam_passwd_info(const char *desc, SAM_PWD * pwd,
2237 prs_struct *ps, int depth)
2239 prs_debug(ps, depth, desc, "net_io_sam_passwd_info");
2240 depth++;
2242 if (!prs_uint32("unk_0 ", ps, depth, &pwd->unk_0))
2243 return False;
2245 if (!smb_io_unihdr("hdr_lm_pwd", &pwd->hdr_lm_pwd, ps, depth))
2246 return False;
2247 if (!prs_uint8s(False, "buf_lm_pwd", ps, depth, pwd->buf_lm_pwd, 16))
2248 return False;
2250 if (!smb_io_unihdr("hdr_nt_pwd", &pwd->hdr_nt_pwd, ps, depth))
2251 return False;
2252 if (!prs_uint8s(False, "buf_nt_pwd", ps, depth, pwd->buf_nt_pwd, 16))
2253 return False;
2255 if (!smb_io_unihdr("", &pwd->hdr_empty_lm, ps, depth))
2256 return False;
2257 if (!smb_io_unihdr("", &pwd->hdr_empty_nt, ps, depth))
2258 return False;
2260 return True;
2263 /*******************************************************************
2264 reads or writes a structure.
2265 ********************************************************************/
2266 static BOOL net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
2267 prs_struct *ps, int depth)
2269 BUFHDR2 hdr_priv_data;
2270 uint32 i;
2272 prs_debug(ps, depth, desc, "net_io_sam_account_info");
2273 depth++;
2275 if (!smb_io_unihdr("hdr_acct_name", &info->hdr_acct_name, ps, depth))
2276 return False;
2277 if (!smb_io_unihdr("hdr_full_name", &info->hdr_full_name, ps, depth))
2278 return False;
2280 if (!prs_uint32("user_rid ", ps, depth, &info->user_rid))
2281 return False;
2282 if (!prs_uint32("group_rid", ps, depth, &info->group_rid))
2283 return False;
2285 if (!smb_io_unihdr("hdr_home_dir ", &info->hdr_home_dir, ps, depth))
2286 return False;
2287 if (!smb_io_unihdr("hdr_dir_drive", &info->hdr_dir_drive, ps, depth))
2288 return False;
2289 if (!smb_io_unihdr("hdr_logon_script", &info->hdr_logon_script, ps,
2290 depth))
2291 return False;
2293 if (!smb_io_unihdr("hdr_acct_desc", &info->hdr_acct_desc, ps, depth))
2294 return False;
2295 if (!smb_io_unihdr("hdr_workstations", &info->hdr_workstations, ps,
2296 depth))
2297 return False;
2299 if (!smb_io_time("logon_time", &info->logon_time, ps, depth))
2300 return False;
2301 if (!smb_io_time("logoff_time", &info->logoff_time, ps, depth))
2302 return False;
2304 if (!prs_uint32("logon_divs ", ps, depth, &info->logon_divs))
2305 return False;
2306 if (!prs_uint32("ptr_logon_hrs", ps, depth, &info->ptr_logon_hrs))
2307 return False;
2309 if (!prs_uint16("bad_pwd_count", ps, depth, &info->bad_pwd_count))
2310 return False;
2311 if (!prs_uint16("logon_count", ps, depth, &info->logon_count))
2312 return False;
2313 if (!smb_io_time("pwd_last_set_time", &info->pwd_last_set_time, ps,
2314 depth))
2315 return False;
2316 if (!smb_io_time("acct_expiry_time", &info->acct_expiry_time, ps,
2317 depth))
2318 return False;
2320 if (!prs_uint32("acb_info", ps, depth, &info->acb_info))
2321 return False;
2322 if (!prs_uint8s(False, "nt_pwd", ps, depth, info->nt_pwd, 16))
2323 return False;
2324 if (!prs_uint8s(False, "lm_pwd", ps, depth, info->lm_pwd, 16))
2325 return False;
2326 if (!prs_uint8("lm_pwd_present", ps, depth, &info->lm_pwd_present))
2327 return False;
2328 if (!prs_uint8("nt_pwd_present", ps, depth, &info->nt_pwd_present))
2329 return False;
2330 if (!prs_uint8("pwd_expired", ps, depth, &info->pwd_expired))
2331 return False;
2333 if (!smb_io_unihdr("hdr_comment", &info->hdr_comment, ps, depth))
2334 return False;
2335 if (!smb_io_unihdr("hdr_parameters", &info->hdr_parameters, ps,
2336 depth))
2337 return False;
2338 if (!prs_uint16("country", ps, depth, &info->country))
2339 return False;
2340 if (!prs_uint16("codepage", ps, depth, &info->codepage))
2341 return False;
2343 if (!smb_io_bufhdr2("hdr_priv_data", &hdr_priv_data, ps, depth))
2344 return False;
2345 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2346 return False;
2347 if (!smb_io_unihdr("hdr_profile", &info->hdr_profile, ps, depth))
2348 return False;
2350 for (i = 0; i < 3; i++)
2352 if (!smb_io_unihdr("hdr_reserved", &info->hdr_reserved[i],
2353 ps, depth))
2354 return False;
2357 for (i = 0; i < 4; i++)
2359 if (!prs_uint32("dw_reserved", ps, depth,
2360 &info->dw_reserved[i]))
2361 return False;
2364 if (!smb_io_unistr2("uni_acct_name", &info->uni_acct_name,
2365 info->hdr_acct_name.buffer, ps, depth))
2366 return False;
2367 prs_align(ps);
2368 if (!smb_io_unistr2("uni_full_name", &info->uni_full_name,
2369 info->hdr_full_name.buffer, ps, depth))
2370 return False;
2371 prs_align(ps);
2372 if (!smb_io_unistr2("uni_home_dir ", &info->uni_home_dir,
2373 info->hdr_home_dir.buffer, ps, depth))
2374 return False;
2375 prs_align(ps);
2376 if (!smb_io_unistr2("uni_dir_drive", &info->uni_dir_drive,
2377 info->hdr_dir_drive.buffer, ps, depth))
2378 return False;
2379 prs_align(ps);
2380 if (!smb_io_unistr2("uni_logon_script", &info->uni_logon_script,
2381 info->hdr_logon_script.buffer, ps, depth))
2382 return False;
2383 prs_align(ps);
2384 if (!smb_io_unistr2("uni_acct_desc", &info->uni_acct_desc,
2385 info->hdr_acct_desc.buffer, ps, depth))
2386 return False;
2387 prs_align(ps);
2388 if (!smb_io_unistr2("uni_workstations", &info->uni_workstations,
2389 info->hdr_workstations.buffer, ps, depth))
2390 return False;
2391 prs_align(ps);
2393 if (!prs_uint32("unknown1", ps, depth, &info->unknown1))
2394 return False;
2395 if (!prs_uint32("unknown2", ps, depth, &info->unknown2))
2396 return False;
2398 if (!smb_io_rpc_blob("buf_logon_hrs", &info->buf_logon_hrs, ps, depth))
2399 return False;
2400 prs_align(ps);
2401 if (!smb_io_unistr2("uni_comment", &info->uni_comment,
2402 info->hdr_comment.buffer, ps, depth))
2403 return False;
2404 prs_align(ps);
2405 if (!smb_io_unistr2("uni_parameters", &info->uni_parameters,
2406 info->hdr_parameters.buffer, ps, depth))
2407 return False;
2408 prs_align(ps);
2409 if (hdr_priv_data.buffer != 0)
2411 int old_offset = 0;
2412 uint32 len = 0x44;
2413 if (!prs_uint32("pwd_len", ps, depth, &len))
2414 return False;
2415 old_offset = ps->data_offset;
2416 if (len > 0)
2418 if (ps->io)
2420 /* reading */
2421 if (!prs_hash1(ps, ps->data_offset, len))
2422 return False;
2424 if (!net_io_sam_passwd_info("pass", &info->pass,
2425 ps, depth))
2426 return False;
2428 if (!ps->io)
2430 /* writing */
2431 if (!prs_hash1(ps, old_offset, len))
2432 return False;
2435 if (old_offset + len > ps->buffer_size)
2436 return False;
2437 ps->data_offset = old_offset + len;
2439 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2440 return False;
2441 prs_align(ps);
2442 if (!smb_io_unistr2("uni_profile", &info->uni_profile,
2443 info->hdr_profile.buffer, ps, depth))
2444 return False;
2446 prs_align(ps);
2448 return True;
2451 /*******************************************************************
2452 reads or writes a structure.
2453 ********************************************************************/
2454 static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * info,
2455 prs_struct *ps, int depth)
2457 uint32 i;
2458 fstring tmp;
2460 prs_debug(ps, depth, desc, "net_io_sam_group_mem_info");
2461 depth++;
2463 prs_align(ps);
2464 if (!prs_uint32("ptr_rids ", ps, depth, &info->ptr_rids))
2465 return False;
2466 if (!prs_uint32("ptr_attribs", ps, depth, &info->ptr_attribs))
2467 return False;
2468 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2469 return False;
2471 if (ps->data_offset + 16 > ps->buffer_size)
2472 return False;
2473 ps->data_offset += 16;
2475 if (info->ptr_rids != 0)
2477 if (!prs_uint32("num_members2", ps, depth,
2478 &info->num_members2))
2479 return False;
2481 if (info->num_members2 != info->num_members)
2483 /* RPC fault */
2484 return False;
2487 if (UNMARSHALLING(ps)) {
2488 if (info->num_members2) {
2489 info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
2491 if (info->rids == NULL) {
2492 DEBUG(0, ("out of memory allocating %d rids\n",
2493 info->num_members2));
2494 return False;
2496 } else {
2497 info->rids = NULL;
2501 for (i = 0; i < info->num_members2; i++)
2503 slprintf(tmp, sizeof(tmp) - 1, "rids[%02d]", i);
2504 if (!prs_uint32(tmp, ps, depth, &info->rids[i]))
2505 return False;
2509 if (info->ptr_attribs != 0)
2511 if (!prs_uint32("num_members3", ps, depth,
2512 &info->num_members3))
2513 return False;
2514 if (info->num_members3 != info->num_members)
2516 /* RPC fault */
2517 return False;
2520 if (UNMARSHALLING(ps)) {
2521 if (info->num_members3) {
2522 info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
2524 if (info->attribs == NULL) {
2525 DEBUG(0, ("out of memory allocating %d attribs\n",
2526 info->num_members3));
2527 return False;
2529 } else {
2530 info->attribs = NULL;
2534 for (i = 0; i < info->num_members3; i++)
2536 slprintf(tmp, sizeof(tmp) - 1, "attribs[%02d]", i);
2537 if (!prs_uint32(tmp, ps, depth, &info->attribs[i]))
2538 return False;
2542 return True;
2545 /*******************************************************************
2546 reads or writes a structure.
2547 ********************************************************************/
2548 static BOOL net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
2549 prs_struct *ps, int depth)
2551 prs_debug(ps, depth, desc, "net_io_sam_alias_info");
2552 depth++;
2554 if (!smb_io_unihdr("hdr_als_name", &info->hdr_als_name, ps, depth))
2555 return False;
2556 if (!prs_uint32("als_rid", ps, depth, &info->als_rid))
2557 return False;
2558 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2559 return False;
2560 if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
2561 return False;
2563 if (ps->data_offset + 40 > ps->buffer_size)
2564 return False;
2565 ps->data_offset += 40;
2567 if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
2568 info->hdr_als_name.buffer, ps, depth))
2569 return False;
2570 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2571 return False;
2573 if (!smb_io_unistr2("uni_als_desc", &info->uni_als_desc,
2574 info->hdr_als_desc.buffer, ps, depth))
2575 return False;
2577 return True;
2580 /*******************************************************************
2581 reads or writes a structure.
2582 ********************************************************************/
2583 static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * info,
2584 prs_struct *ps, int depth)
2586 uint32 i;
2587 fstring tmp;
2589 prs_debug(ps, depth, desc, "net_io_sam_alias_mem_info");
2590 depth++;
2592 prs_align(ps);
2593 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2594 return False;
2595 if (!prs_uint32("ptr_members", ps, depth, &info->ptr_members))
2596 return False;
2598 if (ps->data_offset + 16 > ps->buffer_size)
2599 return False;
2600 ps->data_offset += 16;
2602 if (info->ptr_members != 0)
2604 if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
2605 return False;
2606 if (info->num_sids != info->num_members)
2608 /* RPC fault */
2609 return False;
2612 if (UNMARSHALLING(ps)) {
2613 if (info->num_sids) {
2614 info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
2616 if (info->ptr_sids == NULL) {
2617 DEBUG(0, ("out of memory allocating %d ptr_sids\n",
2618 info->num_sids));
2619 return False;
2621 } else {
2622 info->ptr_sids = NULL;
2626 for (i = 0; i < info->num_sids; i++)
2628 slprintf(tmp, sizeof(tmp) - 1, "ptr_sids[%02d]", i);
2629 if (!prs_uint32(tmp, ps, depth, &info->ptr_sids[i]))
2630 return False;
2633 if (UNMARSHALLING(ps)) {
2634 if (info->num_sids) {
2635 info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
2637 if (info->sids == NULL) {
2638 DEBUG(0, ("error allocating %d sids\n",
2639 info->num_sids));
2640 return False;
2642 } else {
2643 info->sids = NULL;
2647 for (i = 0; i < info->num_sids; i++)
2649 if (info->ptr_sids[i] != 0)
2651 slprintf(tmp, sizeof(tmp) - 1, "sids[%02d]",
2653 if (!smb_io_dom_sid2(tmp, &info->sids[i],
2654 ps, depth))
2655 return False;
2660 return True;
2663 /*******************************************************************
2664 reads or writes a structure.
2665 ********************************************************************/
2666 static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
2667 prs_struct *ps, int depth)
2669 unsigned int i;
2670 prs_debug(ps, depth, desc, "net_io_sam_policy_info");
2671 depth++;
2673 if(!prs_align(ps))
2674 return False;
2676 if (!prs_uint32("max_log_size", ps, depth, &info->max_log_size))
2677 return False;
2678 if (!prs_uint64("audit_retention_period", ps, depth,
2679 &info->audit_retention_period))
2680 return False;
2681 if (!prs_uint32("auditing_mode", ps, depth, &info->auditing_mode))
2682 return False;
2683 if (!prs_uint32("num_events", ps, depth, &info->num_events))
2684 return False;
2685 if (!prs_uint32("ptr_events", ps, depth, &info->ptr_events))
2686 return False;
2688 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2689 return False;
2691 if (!prs_uint32("sid_ptr", ps, depth, &info->sid_ptr))
2692 return False;
2694 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2695 return False;
2696 if (!prs_uint32("non_paged_pool_limit", ps, depth,
2697 &info->non_paged_pool_limit))
2698 return False;
2699 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
2700 return False;
2701 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
2702 return False;
2703 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
2704 return False;
2705 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
2706 return False;
2707 if (!smb_io_time("modify_time", &info->modify_time, ps, depth))
2708 return False;
2709 if (!smb_io_time("create_time", &info->create_time, ps, depth))
2710 return False;
2711 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2712 return False;
2714 for (i=0; i<4; i++) {
2715 UNIHDR dummy;
2716 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
2717 return False;
2720 for (i=0; i<4; i++) {
2721 uint32 reserved;
2722 if (!prs_uint32("reserved", ps, depth, &reserved))
2723 return False;
2726 if (!prs_uint32("num_event_audit_options", ps, depth,
2727 &info->num_event_audit_options))
2728 return False;
2730 for (i=0; i<info->num_event_audit_options; i++)
2731 if (!prs_uint32("event_audit_option", ps, depth,
2732 &info->event_audit_option))
2733 return False;
2735 if (!smb_io_unistr2("domain_name", &info->domain_name, True, ps, depth))
2736 return False;
2738 if(!smb_io_dom_sid2("domain_sid", &info->domain_sid, ps, depth))
2739 return False;
2741 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2743 return False;
2745 return True;
2748 #if 0
2750 /* This function is pretty broken - see bug #334 */
2752 /*******************************************************************
2753 reads or writes a structure.
2754 ********************************************************************/
2755 static BOOL net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *info,
2756 prs_struct *ps, int depth)
2758 int i;
2760 prs_debug(ps, depth, desc, "net_io_sam_trustdoms_info");
2761 depth++;
2763 if(!prs_align(ps))
2764 return False;
2766 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2767 return False;
2769 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2770 return False;
2772 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2773 return False;
2775 if(!smb_io_unihdr("hdr_domain", &info->hdr_domain, ps, depth))
2776 return False;
2778 if(!prs_uint32("unknown0", ps, depth, &info->unknown0))
2779 return False;
2780 if(!prs_uint32("unknown1", ps, depth, &info->unknown1))
2781 return False;
2782 if(!prs_uint32("unknown2", ps, depth, &info->unknown2))
2783 return False;
2785 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2786 return False;
2787 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2788 return False;
2790 for (i=0; i<12; i++)
2791 if(!prs_uint32("unknown3", ps, depth, &info->unknown3))
2792 return False;
2794 if (!smb_io_unistr2("domain", &info->domain, True, ps, depth))
2795 return False;
2797 return True;
2800 #endif
2802 #if 0
2804 /* This function doesn't work - see bug #334 */
2806 /*******************************************************************
2807 reads or writes a structure.
2808 ********************************************************************/
2809 static BOOL net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
2810 prs_struct *ps, int depth)
2812 int i;
2814 prs_debug(ps, depth, desc, "net_io_sam_secret_info");
2815 depth++;
2817 if(!prs_align(ps))
2818 return False;
2820 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2821 return False;
2823 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2824 return False;
2826 if (!smb_io_unistr2("secret", &info->secret, True, ps, depth))
2827 return False;
2829 if(!prs_align(ps))
2830 return False;
2832 if(!prs_uint32("count1", ps, depth, &info->count1))
2833 return False;
2834 if(!prs_uint32("count2", ps, depth, &info->count2))
2835 return False;
2836 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2837 return False;
2840 if(!smb_io_time("time1", &info->time1, ps, depth)) /* logon time */
2841 return False;
2842 if(!prs_uint32("count3", ps, depth, &info->count3))
2843 return False;
2844 if(!prs_uint32("count4", ps, depth, &info->count4))
2845 return False;
2846 if(!prs_uint32("ptr2", ps, depth, &info->ptr2))
2847 return False;
2848 if(!smb_io_time("time2", &info->time2, ps, depth)) /* logon time */
2849 return False;
2850 if(!prs_uint32("unknow1", ps, depth, &info->unknow1))
2851 return False;
2854 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2855 return False;
2856 if(!prs_uint32("ptr3", ps, depth, &info->ptr3))
2857 return False;
2858 for(i=0; i<12; i++)
2859 if(!prs_uint32("unknow2", ps, depth, &info->unknow2))
2860 return False;
2862 if(!prs_uint32("chal_len", ps, depth, &info->chal_len))
2863 return False;
2864 if(!prs_uint32("reserved1", ps, depth, &info->reserved1))
2865 return False;
2866 if(!prs_uint32("chal_len2", ps, depth, &info->chal_len2))
2867 return False;
2869 if(!prs_uint8s (False, "chal", ps, depth, info->chal, info->chal_len2))
2870 return False;
2872 if(!prs_uint32("key_len", ps, depth, &info->key_len))
2873 return False;
2874 if(!prs_uint32("reserved2", ps, depth, &info->reserved2))
2875 return False;
2876 if(!prs_uint32("key_len2", ps, depth, &info->key_len2))
2877 return False;
2879 if(!prs_uint8s (False, "key", ps, depth, info->key, info->key_len2))
2880 return False;
2883 if(!prs_uint32("buf_size3", ps, depth, &info->buf_size3))
2884 return False;
2886 if(!sec_io_desc("sec_desc2", &info->sec_desc2, ps, depth))
2887 return False;
2890 return True;
2893 #endif
2895 /*******************************************************************
2896 reads or writes a structure.
2897 ********************************************************************/
2898 static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
2899 prs_struct *ps, int depth)
2901 unsigned int i;
2903 prs_debug(ps, depth, desc, "net_io_sam_privs_info");
2904 depth++;
2906 if(!prs_align(ps))
2907 return False;
2909 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2910 return False;
2912 if(!prs_uint32("priv_count", ps, depth, &info->priv_count))
2913 return False;
2914 if(!prs_uint32("priv_control", ps, depth, &info->priv_control))
2915 return False;
2917 if(!prs_uint32("priv_attr_ptr", ps, depth, &info->priv_attr_ptr))
2918 return False;
2919 if(!prs_uint32("priv_name_ptr", ps, depth, &info->priv_name_ptr))
2920 return False;
2922 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2923 return False;
2924 if (!prs_uint32("non_paged_pool_limit", ps, depth,
2925 &info->non_paged_pool_limit))
2926 return False;
2927 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
2928 return False;
2929 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
2930 return False;
2931 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
2932 return False;
2933 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
2934 return False;
2935 if (!prs_uint32("system_flags", ps, depth, &info->system_flags))
2936 return False;
2937 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2938 return False;
2940 for (i=0; i<4; i++) {
2941 UNIHDR dummy;
2942 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
2943 return False;
2946 for (i=0; i<4; i++) {
2947 uint32 reserved;
2948 if (!prs_uint32("reserved", ps, depth, &reserved))
2949 return False;
2952 if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
2953 return False;
2955 if (UNMARSHALLING(ps)) {
2956 if (info->attribute_count) {
2957 info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
2958 if (!info->attributes) {
2959 return False;
2961 } else {
2962 info->attributes = NULL;
2966 for (i=0; i<info->attribute_count; i++)
2967 if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
2968 return False;
2970 if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
2971 return False;
2973 if (UNMARSHALLING(ps)) {
2974 if (info->privlist_count) {
2975 info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
2976 info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
2977 if (!info->hdr_privslist) {
2978 return False;
2980 if (!info->uni_privslist) {
2981 return False;
2983 } else {
2984 info->hdr_privslist = NULL;
2985 info->uni_privslist = NULL;
2989 for (i=0; i<info->privlist_count; i++)
2990 if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
2991 return False;
2993 for (i=0; i<info->privlist_count; i++)
2994 if (!smb_io_unistr2("uni_privslist", &info->uni_privslist[i], True, ps, depth))
2995 return False;
2997 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2998 return False;
3000 return True;
3003 /*******************************************************************
3004 reads or writes a structure.
3005 ********************************************************************/
3006 static BOOL net_io_sam_delta_ctr(const char *desc,
3007 SAM_DELTA_CTR * delta, uint16 type,
3008 prs_struct *ps, int depth)
3010 prs_debug(ps, depth, desc, "net_io_sam_delta_ctr");
3011 depth++;
3013 switch (type) {
3014 /* Seen in sam deltas */
3015 case SAM_DELTA_MODIFIED_COUNT:
3016 if (!net_io_sam_delta_mod_count("", &delta->mod_count, ps, depth))
3017 return False;
3018 break;
3020 case SAM_DELTA_DOMAIN_INFO:
3021 if (!net_io_sam_domain_info("", &delta->domain_info, ps, depth))
3022 return False;
3023 break;
3025 case SAM_DELTA_GROUP_INFO:
3026 if (!net_io_sam_group_info("", &delta->group_info, ps, depth))
3027 return False;
3028 break;
3030 case SAM_DELTA_ACCOUNT_INFO:
3031 if (!net_io_sam_account_info("", &delta->account_info, ps, depth))
3032 return False;
3033 break;
3035 case SAM_DELTA_GROUP_MEM:
3036 if (!net_io_sam_group_mem_info("", &delta->grp_mem_info, ps, depth))
3037 return False;
3038 break;
3040 case SAM_DELTA_ALIAS_INFO:
3041 if (!net_io_sam_alias_info("", &delta->alias_info, ps, depth))
3042 return False;
3043 break;
3045 case SAM_DELTA_POLICY_INFO:
3046 if (!net_io_sam_policy_info("", &delta->policy_info, ps, depth))
3047 return False;
3048 break;
3050 case SAM_DELTA_ALIAS_MEM:
3051 if (!net_io_sam_alias_mem_info("", &delta->als_mem_info, ps, depth))
3052 return False;
3053 break;
3055 case SAM_DELTA_PRIVS_INFO:
3056 if (!net_io_sam_privs_info("", &delta->privs_info, ps, depth))
3057 return False;
3058 break;
3060 /* These guys are implemented but broken */
3062 case SAM_DELTA_TRUST_DOMS:
3063 case SAM_DELTA_SECRET_INFO:
3064 break;
3066 /* These guys are not implemented yet */
3068 case SAM_DELTA_RENAME_GROUP:
3069 case SAM_DELTA_RENAME_USER:
3070 case SAM_DELTA_RENAME_ALIAS:
3071 case SAM_DELTA_DELETE_GROUP:
3072 case SAM_DELTA_DELETE_USER:
3073 default:
3074 DEBUG(0, ("Replication error: Unknown delta type 0x%x\n", type));
3075 break;
3078 return True;
3081 /*******************************************************************
3082 reads or writes a structure.
3083 ********************************************************************/
3084 BOOL net_io_r_sam_sync(const char *desc,
3085 NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
3087 uint32 i;
3089 prs_debug(ps, depth, desc, "net_io_r_sam_sync");
3090 depth++;
3092 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3093 return False;
3094 if (!prs_uint32("sync_context", ps, depth, &r_s->sync_context))
3095 return False;
3097 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3098 return False;
3099 if (r_s->ptr_deltas != 0)
3101 if (!prs_uint32("num_deltas ", ps, depth, &r_s->num_deltas))
3102 return False;
3103 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->ptr_deltas2))
3104 return False;
3105 if (r_s->ptr_deltas2 != 0)
3107 if (!prs_uint32("num_deltas2", ps, depth,
3108 &r_s->num_deltas2))
3109 return False;
3111 if (r_s->num_deltas2 != r_s->num_deltas)
3113 /* RPC fault */
3114 return False;
3117 if (UNMARSHALLING(ps)) {
3118 if (r_s->num_deltas2) {
3119 r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
3120 if (r_s->hdr_deltas == NULL) {
3121 DEBUG(0, ("error tallocating memory "
3122 "for %d delta headers\n",
3123 r_s->num_deltas2));
3124 return False;
3126 } else {
3127 r_s->hdr_deltas = NULL;
3131 for (i = 0; i < r_s->num_deltas2; i++)
3133 if (!net_io_sam_delta_hdr("",
3134 &r_s->hdr_deltas[i],
3135 ps, depth))
3136 return False;
3139 if (UNMARSHALLING(ps)) {
3140 if (r_s->num_deltas2) {
3141 r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
3142 if (r_s->deltas == NULL) {
3143 DEBUG(0, ("error tallocating memory "
3144 "for %d deltas\n",
3145 r_s->num_deltas2));
3146 return False;
3148 } else {
3149 r_s->deltas = NULL;
3153 for (i = 0; i < r_s->num_deltas2; i++)
3155 if (!net_io_sam_delta_ctr(
3156 "", &r_s->deltas[i],
3157 r_s->hdr_deltas[i].type3,
3158 ps, depth)) {
3159 DEBUG(0, ("hmm, failed on i=%d\n", i));
3160 return False;
3166 prs_align(ps);
3167 if (!prs_ntstatus("status", ps, depth, &(r_s->status)))
3168 return False;
3170 return True;
3173 /*******************************************************************
3174 makes a NET_Q_SAM_DELTAS structure.
3175 ********************************************************************/
3176 BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
3177 const char *cli_name, DOM_CRED *cli_creds,
3178 uint32 database_id, uint64 dom_mod_count)
3180 DEBUG(5, ("init_net_q_sam_deltas\n"));
3182 init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
3183 init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
3185 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
3186 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
3188 q_s->database_id = database_id;
3189 q_s->dom_mod_count = dom_mod_count;
3190 q_s->max_size = 0xffff;
3192 return True;
3195 /*******************************************************************
3196 reads or writes a structure.
3197 ********************************************************************/
3198 BOOL net_io_q_sam_deltas(const char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
3199 int depth)
3201 prs_debug(ps, depth, desc, "net_io_q_sam_deltas");
3202 depth++;
3204 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
3205 return False;
3206 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
3207 return False;
3209 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
3210 return False;
3211 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
3212 return False;
3214 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
3215 return False;
3216 if (!prs_uint64("dom_mod_count", ps, depth, &q_s->dom_mod_count))
3217 return False;
3218 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
3219 return False;
3221 return True;
3224 /*******************************************************************
3225 reads or writes a structure.
3226 ********************************************************************/
3227 BOOL net_io_r_sam_deltas(const char *desc,
3228 NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
3230 unsigned int i;
3232 prs_debug(ps, depth, desc, "net_io_r_sam_deltas");
3233 depth++;
3235 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3236 return False;
3237 if (!prs_uint64("dom_mod_count", ps, depth, &r_s->dom_mod_count))
3238 return False;
3240 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3241 return False;
3242 if (!prs_uint32("num_deltas", ps, depth, &r_s->num_deltas))
3243 return False;
3244 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->num_deltas2))
3245 return False;
3247 if (r_s->num_deltas2 != 0)
3249 if (!prs_uint32("num_deltas2 ", ps, depth, &r_s->num_deltas2))
3250 return False;
3252 if (r_s->ptr_deltas != 0)
3254 if (UNMARSHALLING(ps)) {
3255 if (r_s->num_deltas) {
3256 r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
3257 if (r_s->hdr_deltas == NULL) {
3258 DEBUG(0, ("error tallocating memory "
3259 "for %d delta headers\n",
3260 r_s->num_deltas));
3261 return False;
3263 } else {
3264 r_s->hdr_deltas = NULL;
3268 for (i = 0; i < r_s->num_deltas; i++)
3270 net_io_sam_delta_hdr("", &r_s->hdr_deltas[i],
3271 ps, depth);
3274 if (UNMARSHALLING(ps)) {
3275 if (r_s->num_deltas) {
3276 r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
3277 if (r_s->deltas == NULL) {
3278 DEBUG(0, ("error tallocating memory "
3279 "for %d deltas\n",
3280 r_s->num_deltas));
3281 return False;
3283 } else {
3284 r_s->deltas = NULL;
3288 for (i = 0; i < r_s->num_deltas; i++)
3290 if (!net_io_sam_delta_ctr(
3292 &r_s->deltas[i],
3293 r_s->hdr_deltas[i].type2,
3294 ps, depth))
3296 return False;
3301 prs_align(ps);
3302 if (!prs_ntstatus("status", ps, depth, &r_s->status))
3303 return False;
3305 return True;
3308 /*******************************************************************
3309 Inits a NET_Q_DSR_GETDCNAME structure.
3310 ********************************************************************/
3312 void init_net_q_dsr_getdcname(NET_Q_DSR_GETDCNAME *r_t, const char *server_unc,
3313 const char *domain_name,
3314 struct GUID *domain_guid,
3315 struct GUID *site_guid,
3316 uint32_t flags)
3318 DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3320 r_t->ptr_server_unc = (server_unc != NULL);
3321 init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3323 r_t->ptr_domain_name = (domain_name != NULL);
3324 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3326 r_t->ptr_domain_guid = (domain_guid != NULL);
3327 r_t->domain_guid = domain_guid;
3329 r_t->ptr_site_guid = (site_guid != NULL);
3330 r_t->site_guid = site_guid;
3332 r_t->flags = flags;
3335 /*******************************************************************
3336 Inits a NET_Q_DSR_GETDCNAMEEX structure.
3337 ********************************************************************/
3339 void init_net_q_dsr_getdcnameex(NET_Q_DSR_GETDCNAMEEX *r_t, const char *server_unc,
3340 const char *domain_name,
3341 struct GUID *domain_guid,
3342 const char *site_name,
3343 uint32_t flags)
3345 DEBUG(5, ("init_net_q_dsr_getdcnameex\n"));
3347 r_t->ptr_server_unc = (server_unc != NULL);
3348 init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3350 r_t->ptr_domain_name = (domain_name != NULL);
3351 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3353 r_t->ptr_domain_guid = (domain_guid != NULL);
3354 r_t->domain_guid = domain_guid;
3356 r_t->ptr_site_name = (site_name != NULL);
3357 init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
3359 r_t->flags = flags;
3362 /*******************************************************************
3363 Inits a NET_Q_DSR_GETDCNAMEEX2 structure.
3364 ********************************************************************/
3366 void init_net_q_dsr_getdcnameex2(NET_Q_DSR_GETDCNAMEEX2 *r_t, const char *server_unc,
3367 const char *domain_name,
3368 const char *client_account,
3369 uint32 mask,
3370 struct GUID *domain_guid,
3371 const char *site_name,
3372 uint32_t flags)
3374 DEBUG(5, ("init_net_q_dsr_getdcnameex2\n"));
3376 r_t->ptr_server_unc = (server_unc != NULL);
3377 init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3379 r_t->ptr_client_account = (client_account != NULL);
3380 init_unistr2(&r_t->uni_client_account, client_account, UNI_STR_TERMINATE);
3382 r_t->mask = mask;
3384 r_t->ptr_domain_name = (domain_name != NULL);
3385 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3387 r_t->ptr_domain_guid = (domain_guid != NULL);
3388 r_t->domain_guid = domain_guid;
3390 r_t->ptr_site_name = (site_name != NULL);
3391 init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
3393 r_t->flags = flags;
3396 /*******************************************************************
3397 Reads or writes an NET_Q_DSR_GETDCNAME structure.
3398 ********************************************************************/
3400 BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
3401 prs_struct *ps, int depth)
3403 if (r_t == NULL)
3404 return False;
3406 prs_debug(ps, depth, desc, "net_io_q_dsr_getdcname");
3407 depth++;
3409 if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3410 return False;
3412 if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3413 r_t->ptr_server_unc, ps, depth))
3414 return False;
3416 if (!prs_align(ps))
3417 return False;
3419 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3420 return False;
3422 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3423 r_t->ptr_domain_name, ps, depth))
3424 return False;
3426 if (!prs_align(ps))
3427 return False;
3429 if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3430 return False;
3432 if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3433 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3434 if (r_t->domain_guid == NULL)
3435 return False;
3438 if ((r_t->ptr_domain_guid) &&
3439 (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3440 return False;
3442 if (!prs_align(ps))
3443 return False;
3445 if (!prs_uint32("ptr_site_guid", ps, depth, &r_t->ptr_site_guid))
3446 return False;
3448 if (UNMARSHALLING(ps) && (r_t->ptr_site_guid)) {
3449 r_t->site_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3450 if (r_t->site_guid == NULL)
3451 return False;
3454 if ((r_t->ptr_site_guid) &&
3455 (!smb_io_uuid("site_guid", r_t->site_guid, ps, depth)))
3456 return False;
3458 if (!prs_align(ps))
3459 return False;
3461 if (!prs_uint32("flags", ps, depth, &r_t->flags))
3462 return False;
3464 return True;
3467 /*******************************************************************
3468 Reads or writes an NET_Q_DSR_GETDCNAMEEX structure.
3469 ********************************************************************/
3471 BOOL net_io_q_dsr_getdcnameex(const char *desc, NET_Q_DSR_GETDCNAMEEX *r_t,
3472 prs_struct *ps, int depth)
3474 if (r_t == NULL)
3475 return False;
3477 prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex");
3478 depth++;
3480 if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3481 return False;
3483 if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3484 r_t->ptr_server_unc, ps, depth))
3485 return False;
3487 if (!prs_align(ps))
3488 return False;
3490 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3491 return False;
3493 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3494 r_t->ptr_domain_name, ps, depth))
3495 return False;
3497 if (!prs_align(ps))
3498 return False;
3500 if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3501 return False;
3503 if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3504 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3505 if (r_t->domain_guid == NULL)
3506 return False;
3509 if ((r_t->ptr_domain_guid) &&
3510 (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3511 return False;
3513 if (!prs_align(ps))
3514 return False;
3516 if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3517 return False;
3519 if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3520 r_t->ptr_site_name, ps, depth))
3521 return False;
3523 if (!prs_align(ps))
3524 return False;
3526 if (!prs_uint32("flags", ps, depth, &r_t->flags))
3527 return False;
3529 return True;
3532 /*******************************************************************
3533 Reads or writes an NET_Q_DSR_GETDCNAMEEX2 structure.
3534 ********************************************************************/
3536 BOOL net_io_q_dsr_getdcnameex2(const char *desc, NET_Q_DSR_GETDCNAMEEX2 *r_t,
3537 prs_struct *ps, int depth)
3539 if (r_t == NULL)
3540 return False;
3542 prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex2");
3543 depth++;
3545 if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3546 return False;
3548 if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3549 r_t->ptr_server_unc, ps, depth))
3550 return False;
3552 if (!prs_align(ps))
3553 return False;
3555 if (!prs_uint32("ptr_client_account", ps, depth, &r_t->ptr_client_account))
3556 return False;
3558 if (!smb_io_unistr2("client_account", &r_t->uni_client_account,
3559 r_t->ptr_client_account, ps, depth))
3560 return False;
3562 if (!prs_align(ps))
3563 return False;
3565 if (!prs_uint32("mask", ps, depth, &r_t->mask))
3566 return False;
3568 if (!prs_align(ps))
3569 return False;
3571 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3572 return False;
3574 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3575 r_t->ptr_domain_name, ps, depth))
3576 return False;
3578 if (!prs_align(ps))
3579 return False;
3581 if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3582 return False;
3584 if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3585 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3586 if (r_t->domain_guid == NULL)
3587 return False;
3590 if ((r_t->ptr_domain_guid) &&
3591 (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3592 return False;
3594 if (!prs_align(ps))
3595 return False;
3597 if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3598 return False;
3600 if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3601 r_t->ptr_site_name, ps, depth))
3602 return False;
3604 if (!prs_align(ps))
3605 return False;
3607 if (!prs_uint32("flags", ps, depth, &r_t->flags))
3608 return False;
3610 return True;
3615 /*******************************************************************
3616 Inits a NET_R_DSR_GETDCNAME structure.
3617 ********************************************************************/
3618 void init_net_r_dsr_getdcname(NET_R_DSR_GETDCNAME *r_t, const char *dc_unc,
3619 const char *dc_address, int32 dc_address_type,
3620 struct GUID domain_guid, const char *domain_name,
3621 const char *forest_name, uint32 dc_flags,
3622 const char *dc_site_name,
3623 const char *client_site_name)
3625 DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3627 r_t->ptr_dc_unc = (dc_unc != NULL);
3628 init_unistr2(&r_t->uni_dc_unc, dc_unc, UNI_STR_TERMINATE);
3630 r_t->ptr_dc_address = (dc_address != NULL);
3631 init_unistr2(&r_t->uni_dc_address, dc_address, UNI_STR_TERMINATE);
3633 r_t->dc_address_type = dc_address_type;
3634 r_t->domain_guid = domain_guid;
3636 r_t->ptr_domain_name = (domain_name != NULL);
3637 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3639 r_t->ptr_forest_name = (forest_name != NULL);
3640 init_unistr2(&r_t->uni_forest_name, forest_name, UNI_STR_TERMINATE);
3642 r_t->dc_flags = dc_flags;
3644 r_t->ptr_dc_site_name = (dc_site_name != NULL);
3645 init_unistr2(&r_t->uni_dc_site_name, dc_site_name, UNI_STR_TERMINATE);
3647 r_t->ptr_client_site_name = (client_site_name != NULL);
3648 init_unistr2(&r_t->uni_client_site_name, client_site_name,
3649 UNI_STR_TERMINATE);
3652 /*******************************************************************
3653 Reads or writes an NET_R_DSR_GETDCNAME structure.
3654 ********************************************************************/
3656 BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t,
3657 prs_struct *ps, int depth)
3659 uint32 info_ptr = 1;
3661 if (r_t == NULL)
3662 return False;
3664 prs_debug(ps, depth, desc, "net_io_r_dsr_getdcname");
3665 depth++;
3667 /* The reply contains *just* an info struct, this is the ptr to it */
3668 if (!prs_uint32("info_ptr", ps, depth, &info_ptr))
3669 return False;
3671 if (info_ptr == 0)
3672 return False;
3674 if (!prs_uint32("ptr_dc_unc", ps, depth, &r_t->ptr_dc_unc))
3675 return False;
3677 if (!prs_uint32("ptr_dc_address", ps, depth, &r_t->ptr_dc_address))
3678 return False;
3680 if (!prs_int32("dc_address_type", ps, depth, &r_t->dc_address_type))
3681 return False;
3683 if (!smb_io_uuid("domain_guid", &r_t->domain_guid, ps, depth))
3684 return False;
3686 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3687 return False;
3689 if (!prs_uint32("ptr_forest_name", ps, depth, &r_t->ptr_forest_name))
3690 return False;
3692 if (!prs_uint32("dc_flags", ps, depth, &r_t->dc_flags))
3693 return False;
3695 if (!prs_uint32("ptr_dc_site_name", ps, depth, &r_t->ptr_dc_site_name))
3696 return False;
3698 if (!prs_uint32("ptr_client_site_name", ps, depth,
3699 &r_t->ptr_client_site_name))
3700 return False;
3702 if (!prs_align(ps))
3703 return False;
3705 if (!smb_io_unistr2("dc_unc", &r_t->uni_dc_unc,
3706 r_t->ptr_dc_unc, ps, depth))
3707 return False;
3709 if (!prs_align(ps))
3710 return False;
3712 if (!smb_io_unistr2("dc_address", &r_t->uni_dc_address,
3713 r_t->ptr_dc_address, ps, depth))
3714 return False;
3716 if (!prs_align(ps))
3717 return False;
3719 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3720 r_t->ptr_domain_name, ps, depth))
3721 return False;
3723 if (!prs_align(ps))
3724 return False;
3726 if (!smb_io_unistr2("forest_name", &r_t->uni_forest_name,
3727 r_t->ptr_forest_name, ps, depth))
3728 return False;
3730 if (!prs_align(ps))
3731 return False;
3733 if (!smb_io_unistr2("dc_site_name", &r_t->uni_dc_site_name,
3734 r_t->ptr_dc_site_name, ps, depth))
3735 return False;
3737 if (!prs_align(ps))
3738 return False;
3740 if (!smb_io_unistr2("client_site_name", &r_t->uni_client_site_name,
3741 r_t->ptr_client_site_name, ps, depth))
3742 return False;
3744 if (!prs_align(ps))
3745 return False;
3747 if (!prs_werror("result", ps, depth, &r_t->result))
3748 return False;
3750 return True;
3753 /*******************************************************************
3754 Inits a NET_Q_DSR_GETSITENAME structure.
3755 ********************************************************************/
3757 void init_net_q_dsr_getsitename(NET_Q_DSR_GETSITENAME *r_t, const char *computer_name)
3759 DEBUG(5, ("init_net_q_dsr_getsitename\n"));
3761 r_t->ptr_computer_name = (computer_name != NULL);
3762 init_unistr2(&r_t->uni_computer_name, computer_name, UNI_STR_TERMINATE);
3765 /*******************************************************************
3766 Reads or writes an NET_Q_DSR_GETSITENAME structure.
3767 ********************************************************************/
3769 BOOL net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
3770 prs_struct *ps, int depth)
3772 if (r_t == NULL)
3773 return False;
3775 prs_debug(ps, depth, desc, "net_io_q_dsr_getsitename");
3776 depth++;
3778 if (!prs_uint32("ptr_computer_name", ps, depth, &r_t->ptr_computer_name))
3779 return False;
3781 if (!smb_io_unistr2("computer_name", &r_t->uni_computer_name,
3782 r_t->ptr_computer_name, ps, depth))
3783 return False;
3785 if (!prs_align(ps))
3786 return False;
3788 return True;
3791 /*******************************************************************
3792 Reads or writes an NET_R_DSR_GETSITENAME structure.
3793 ********************************************************************/
3795 BOOL net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t,
3796 prs_struct *ps, int depth)
3798 if (r_t == NULL)
3799 return False;
3801 prs_debug(ps, depth, desc, "net_io_r_dsr_getsitename");
3802 depth++;
3804 if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3805 return False;
3807 if (!prs_align(ps))
3808 return False;
3810 if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3811 r_t->ptr_site_name, ps, depth))
3812 return False;
3814 if (!prs_align(ps))
3815 return False;
3817 if (!prs_werror("result", ps, depth, &r_t->result))
3818 return False;
3820 return True;