fix net_io_q_srv_pwset2.
[Samba.git] / source / rpc_parse / parse_net.c
blob8d99e808e6c6071885d7c97c6717621a5f0411c5
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 Inits a NET_Q_SRV_PWSET2.
1001 ********************************************************************/
1003 void init_q_srv_pwset2(NET_Q_SRV_PWSET2 *q_s,
1004 const char *logon_srv,
1005 const char *sess_key,
1006 const char *acct_name,
1007 uint16 sec_chan,
1008 const char *comp_name,
1009 DOM_CRED *cred,
1010 const char *clear_text_mach_pwd)
1012 uint8_t password_buf[516];
1013 NET_CRYPT_PWD new_password;
1015 DEBUG(5,("init_q_srv_pwset2\n"));
1017 /* Process the new password. */
1019 encode_pw_buffer(password_buf, clear_text_mach_pwd, STR_UNICODE);
1021 SamOEMhash(password_buf, (const unsigned char *)sess_key, 516);
1022 memcpy(new_password.data, password_buf, 512);
1023 new_password.length = IVAL(password_buf, 512);
1025 init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
1027 memcpy(&q_s->pwd, &new_password, sizeof(q_s->pwd));
1030 /*******************************************************************
1031 Reads or writes a structure.
1032 ********************************************************************/
1034 BOOL net_io_q_srv_pwset2(const char *desc, NET_Q_SRV_PWSET2 *q_s, prs_struct *ps, int depth)
1036 if (q_s == NULL)
1037 return False;
1039 prs_debug(ps, depth, desc, "net_io_q_srv_pwset2");
1040 depth++;
1042 if(!prs_align(ps))
1043 return False;
1045 if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */
1046 return False;
1047 if(!prs_uint8s(False, "pwd.data", ps, depth, q_s->pwd.data, 512)) /* new password - undocumented */
1048 return False;
1049 if(!prs_uint32("pwd.length", ps, depth, &q_s->pwd.length)) /* new password - undocumented */
1050 return False;
1052 return True;
1055 /*******************************************************************
1056 Reads or writes a structure.
1057 ********************************************************************/
1059 BOOL net_io_r_srv_pwset2(const char *desc, NET_R_SRV_PWSET2 *r_s, prs_struct *ps, int depth)
1061 if (r_s == NULL)
1062 return False;
1064 prs_debug(ps, depth, desc, "net_io_r_srv_pwset2");
1065 depth++;
1067 if(!prs_align(ps))
1068 return False;
1070 if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */
1071 return False;
1073 if(!prs_ntstatus("status", ps, depth, &r_s->status))
1074 return False;
1076 return True;
1079 /*************************************************************************
1080 Init DOM_SID2 array from a string containing multiple sids
1081 *************************************************************************/
1083 static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids)
1085 const char *ptr;
1086 pstring s2;
1087 int count = 0;
1089 DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
1091 *ppsids = NULL;
1093 if(sids_str) {
1094 int number;
1095 DOM_SID2 *sids;
1097 /* Count the number of valid SIDs. */
1098 for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1099 DOM_SID tmpsid;
1100 if (string_to_sid(&tmpsid, s2))
1101 count++;
1104 /* Now allocate space for them. */
1105 if (count) {
1106 *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
1107 if (*ppsids == NULL)
1108 return 0;
1109 } else {
1110 *ppsids = NULL;
1113 sids = *ppsids;
1115 for (number = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1116 DOM_SID tmpsid;
1117 if (string_to_sid(&tmpsid, s2)) {
1118 /* count only valid sids */
1119 init_dom_sid2(&sids[number], &tmpsid);
1120 number++;
1125 return count;
1128 /*******************************************************************
1129 Inits a NET_ID_INFO_1 structure.
1130 ********************************************************************/
1132 void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
1133 uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high,
1134 const char *user_name, const char *wksta_name,
1135 const char *sess_key,
1136 unsigned char lm_cypher[16], unsigned char nt_cypher[16])
1138 unsigned char lm_owf[16];
1139 unsigned char nt_owf[16];
1141 DEBUG(5,("init_id_info1: %d\n", __LINE__));
1143 id->ptr_id_info1 = 1;
1145 id->param_ctrl = param_ctrl;
1146 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1149 if (lm_cypher && nt_cypher) {
1150 unsigned char key[16];
1151 #ifdef DEBUG_PASSWORD
1152 DEBUG(100,("lm cypher:"));
1153 dump_data(100, (char *)lm_cypher, 16);
1155 DEBUG(100,("nt cypher:"));
1156 dump_data(100, (char *)nt_cypher, 16);
1157 #endif
1159 memset(key, 0, 16);
1160 memcpy(key, sess_key, 8);
1162 memcpy(lm_owf, lm_cypher, 16);
1163 SamOEMhash(lm_owf, key, 16);
1164 memcpy(nt_owf, nt_cypher, 16);
1165 SamOEMhash(nt_owf, key, 16);
1167 #ifdef DEBUG_PASSWORD
1168 DEBUG(100,("encrypt of lm owf password:"));
1169 dump_data(100, (char *)lm_owf, 16);
1171 DEBUG(100,("encrypt of nt owf password:"));
1172 dump_data(100, (char *)nt_owf, 16);
1173 #endif
1174 /* set up pointers to cypher blocks */
1175 lm_cypher = lm_owf;
1176 nt_cypher = nt_owf;
1179 init_owf_info(&id->lm_owf, lm_cypher);
1180 init_owf_info(&id->nt_owf, nt_cypher);
1182 init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1183 init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1184 init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1185 init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1186 init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1187 init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1190 /*******************************************************************
1191 Reads or writes an NET_ID_INFO_1 structure.
1192 ********************************************************************/
1194 static BOOL net_io_id_info1(const char *desc, NET_ID_INFO_1 *id, prs_struct *ps, int depth)
1196 if (id == NULL)
1197 return False;
1199 prs_debug(ps, depth, desc, "net_io_id_info1");
1200 depth++;
1202 if(!prs_align(ps))
1203 return False;
1205 if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1))
1206 return False;
1208 if (id->ptr_id_info1 != 0) {
1209 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1210 return False;
1212 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1213 return False;
1214 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1215 return False;
1217 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1218 return False;
1219 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1220 return False;
1222 if(!smb_io_owf_info("", &id->lm_owf, ps, depth))
1223 return False;
1224 if(!smb_io_owf_info("", &id->nt_owf, ps, depth))
1225 return False;
1227 if(!smb_io_unistr2("unistr2", &id->uni_domain_name,
1228 id->hdr_domain_name.buffer, ps, depth))
1229 return False;
1230 if(!smb_io_unistr2("unistr2", &id->uni_user_name,
1231 id->hdr_user_name.buffer, ps, depth))
1232 return False;
1233 if(!smb_io_unistr2("unistr2", &id->uni_wksta_name,
1234 id->hdr_wksta_name.buffer, ps, depth))
1235 return False;
1238 return True;
1241 /*******************************************************************
1242 Inits a NET_ID_INFO_2 structure.
1244 This is a network logon packet. The log_id parameters
1245 are what an NT server would generate for LUID once the
1246 user is logged on. I don't think we care about them.
1248 Note that this has no access to the NT and LM hashed passwords,
1249 so it forwards the challenge, and the NT and LM responses (24
1250 bytes each) over the secure channel to the Domain controller
1251 for it to say yea or nay. This is the preferred method of
1252 checking for a logon as it doesn't export the password
1253 hashes to anyone who has compromised the secure channel. JRA.
1254 ********************************************************************/
1256 void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
1257 uint32 param_ctrl,
1258 uint32 log_id_low, uint32 log_id_high,
1259 const char *user_name, const char *wksta_name,
1260 const uchar lm_challenge[8],
1261 const uchar * lm_chal_resp, size_t lm_chal_resp_len,
1262 const uchar * nt_chal_resp, size_t nt_chal_resp_len)
1265 DEBUG(5,("init_id_info2: %d\n", __LINE__));
1267 id->ptr_id_info2 = 1;
1269 id->param_ctrl = param_ctrl;
1270 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1272 memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));
1273 init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);
1274 init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);
1276 init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1277 init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1278 init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1279 init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1280 init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1281 init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1283 init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);
1284 init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);
1288 /*******************************************************************
1289 Reads or writes an NET_ID_INFO_2 structure.
1290 ********************************************************************/
1292 static BOOL net_io_id_info2(const char *desc, NET_ID_INFO_2 *id, prs_struct *ps, int depth)
1294 if (id == NULL)
1295 return False;
1297 prs_debug(ps, depth, desc, "net_io_id_info2");
1298 depth++;
1300 if(!prs_align(ps))
1301 return False;
1303 if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2))
1304 return False;
1306 if (id->ptr_id_info2 != 0) {
1307 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1308 return False;
1310 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1311 return False;
1312 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1313 return False;
1315 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1316 return False;
1317 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1318 return False;
1320 if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */
1321 return False;
1323 if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth))
1324 return False;
1325 if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth))
1326 return False;
1328 if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name,
1329 id->hdr_domain_name.buffer, ps, depth))
1330 return False;
1331 if(!smb_io_unistr2("uni_user_name ", &id->uni_user_name,
1332 id->hdr_user_name.buffer, ps, depth))
1333 return False;
1334 if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name,
1335 id->hdr_wksta_name.buffer, ps, depth))
1336 return False;
1337 if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp,
1338 id->hdr_nt_chal_resp.buffer, ps, depth))
1339 return False;
1340 if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp,
1341 id->hdr_lm_chal_resp.buffer, ps, depth))
1342 return False;
1345 return True;
1349 /*******************************************************************
1350 Inits a DOM_SAM_INFO structure.
1351 ********************************************************************/
1353 void init_sam_info(DOM_SAM_INFO *sam,
1354 const char *logon_srv, const char *comp_name,
1355 DOM_CRED *clnt_cred,
1356 DOM_CRED *rtn_cred, uint16 logon_level,
1357 NET_ID_INFO_CTR *ctr)
1359 DEBUG(5,("init_sam_info: %d\n", __LINE__));
1361 init_clnt_info2(&sam->client, logon_srv, comp_name, clnt_cred);
1363 if (rtn_cred != NULL) {
1364 sam->ptr_rtn_cred = 1;
1365 memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred));
1366 } else {
1367 sam->ptr_rtn_cred = 0;
1370 sam->logon_level = logon_level;
1371 sam->ctr = ctr;
1374 /*******************************************************************
1375 Reads or writes a DOM_SAM_INFO structure.
1376 ********************************************************************/
1378 static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1380 NET_ID_INFO_CTR *ctr = *pp_ctr;
1382 prs_debug(ps, depth, desc, "smb_io_sam_info_ctr");
1383 depth++;
1385 if (UNMARSHALLING(ps)) {
1386 ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
1387 if (ctr == NULL)
1388 return False;
1391 if (ctr == NULL)
1392 return False;
1394 /* don't 4-byte align here! */
1396 if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value))
1397 return False;
1399 switch (ctr->switch_value) {
1400 case 1:
1401 if(!net_io_id_info1("", &ctr->auth.id1, ps, depth))
1402 return False;
1403 break;
1404 case 2:
1405 if(!net_io_id_info2("", &ctr->auth.id2, ps, depth))
1406 return False;
1407 break;
1408 default:
1409 /* PANIC! */
1410 DEBUG(4,("smb_io_sam_info_ctr: unknown switch_value!\n"));
1411 break;
1414 return True;
1417 /*******************************************************************
1418 Reads or writes a DOM_SAM_INFO structure.
1419 ********************************************************************/
1421 static BOOL smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
1423 if (sam == NULL)
1424 return False;
1426 prs_debug(ps, depth, desc, "smb_io_sam_info");
1427 depth++;
1429 if(!prs_align(ps))
1430 return False;
1432 if(!smb_io_clnt_info2("", &sam->client, ps, depth))
1433 return False;
1435 if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred))
1436 return False;
1437 if (sam->ptr_rtn_cred) {
1438 if(!smb_io_cred("", &sam->rtn_cred, ps, depth))
1439 return False;
1442 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1443 return False;
1445 if (sam->logon_level != 0) {
1446 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1447 return False;
1450 return True;
1453 /*******************************************************************
1454 Reads or writes a DOM_SAM_INFO_EX structure.
1455 ********************************************************************/
1457 static BOOL smb_io_sam_info_ex(const char *desc, DOM_SAM_INFO_EX *sam, prs_struct *ps, int depth)
1459 if (sam == NULL)
1460 return False;
1462 prs_debug(ps, depth, desc, "smb_io_sam_info_ex");
1463 depth++;
1465 if(!prs_align(ps))
1466 return False;
1468 if(!smb_io_clnt_srv("", &sam->client, ps, depth))
1469 return False;
1471 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1472 return False;
1474 if (sam->logon_level != 0) {
1475 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1476 return False;
1479 return True;
1482 /*************************************************************************
1483 Inits a NET_USER_INFO_3 structure.
1485 This is a network logon reply packet, and contains much information about
1486 the user. This information is passed as a (very long) paramater list
1487 to avoid having to link in the PASSDB code to every program that deals
1488 with this file.
1489 *************************************************************************/
1491 void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
1492 uint32 user_rid,
1493 uint32 group_rid,
1495 const char* user_name,
1496 const char* full_name,
1497 const char* home_dir,
1498 const char* dir_drive,
1499 const char* logon_script,
1500 const char* profile_path,
1502 time_t unix_logon_time,
1503 time_t unix_logoff_time,
1504 time_t unix_kickoff_time,
1505 time_t unix_pass_last_set_time,
1506 time_t unix_pass_can_change_time,
1507 time_t unix_pass_must_change_time,
1509 uint16 logon_count, uint16 bad_pw_count,
1510 uint32 num_groups, const DOM_GID *gids,
1511 uint32 user_flgs, uint32 acct_flags,
1512 uchar user_session_key[16],
1513 uchar lm_session_key[8],
1514 const char *logon_srv, const char *logon_dom,
1515 const DOM_SID *dom_sid)
1517 /* only cope with one "other" sid, right now. */
1518 /* need to count the number of space-delimited sids */
1519 unsigned int i;
1520 int num_other_sids = 0;
1522 NTTIME logon_time, logoff_time, kickoff_time,
1523 pass_last_set_time, pass_can_change_time,
1524 pass_must_change_time;
1526 ZERO_STRUCTP(usr);
1528 usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */
1530 /* Create NTTIME structs */
1531 unix_to_nt_time (&logon_time, unix_logon_time);
1532 unix_to_nt_time (&logoff_time, unix_logoff_time);
1533 unix_to_nt_time (&kickoff_time, unix_kickoff_time);
1534 unix_to_nt_time (&pass_last_set_time, unix_pass_last_set_time);
1535 unix_to_nt_time (&pass_can_change_time, unix_pass_can_change_time);
1536 unix_to_nt_time (&pass_must_change_time, unix_pass_must_change_time);
1538 usr->logon_time = logon_time;
1539 usr->logoff_time = logoff_time;
1540 usr->kickoff_time = kickoff_time;
1541 usr->pass_last_set_time = pass_last_set_time;
1542 usr->pass_can_change_time = pass_can_change_time;
1543 usr->pass_must_change_time = pass_must_change_time;
1545 usr->logon_count = logon_count;
1546 usr->bad_pw_count = bad_pw_count;
1548 usr->user_rid = user_rid;
1549 usr->group_rid = group_rid;
1550 usr->num_groups = num_groups;
1552 usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */
1553 usr->user_flgs = user_flgs;
1554 usr->acct_flags = acct_flags;
1556 if (user_session_key != NULL)
1557 memcpy(usr->user_sess_key, user_session_key, sizeof(usr->user_sess_key));
1558 else
1559 memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key));
1561 usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */
1563 memset((char *)usr->lm_sess_key, '\0', sizeof(usr->lm_sess_key));
1565 for (i=0; i<7; i++) {
1566 memset(&usr->unknown[i], '\0', sizeof(usr->unknown));
1569 if (lm_session_key != NULL) {
1570 memcpy(usr->lm_sess_key, lm_session_key, sizeof(usr->lm_sess_key));
1573 num_other_sids = init_dom_sid2s(ctx, NULL, &usr->other_sids);
1575 usr->num_other_sids = num_other_sids;
1576 usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0;
1578 init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
1579 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
1580 init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
1581 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
1582 init_unistr2(&usr->uni_logon_script, logon_script, UNI_FLAGS_NONE);
1583 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
1584 init_unistr2(&usr->uni_profile_path, profile_path, UNI_FLAGS_NONE);
1585 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
1586 init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
1587 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
1588 init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
1589 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
1591 usr->num_groups2 = num_groups;
1593 if (num_groups) {
1594 usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
1595 if (usr->gids == NULL)
1596 return;
1597 } else {
1598 usr->gids = NULL;
1601 for (i = 0; i < num_groups; i++)
1602 usr->gids[i] = gids[i];
1604 init_unistr2(&usr->uni_logon_srv, logon_srv, UNI_FLAGS_NONE);
1605 init_uni_hdr(&usr->hdr_logon_srv, &usr->uni_logon_srv);
1606 init_unistr2(&usr->uni_logon_dom, logon_dom, UNI_FLAGS_NONE);
1607 init_uni_hdr(&usr->hdr_logon_dom, &usr->uni_logon_dom);
1609 init_dom_sid2(&usr->dom_sid, dom_sid);
1610 /* "other" sids are set up above */
1613 static void dump_acct_flags(uint32 acct_flags) {
1615 int lvl = 10;
1616 DEBUG(lvl,("dump_acct_flags\n"));
1617 if (acct_flags & ACB_NORMAL) {
1618 DEBUGADD(lvl,("\taccount has ACB_NORMAL\n"));
1620 if (acct_flags & ACB_PWNOEXP) {
1621 DEBUGADD(lvl,("\taccount has ACB_PWNOEXP\n"));
1623 if (acct_flags & ACB_ENC_TXT_PWD_ALLOWED) {
1624 DEBUGADD(lvl,("\taccount has ACB_ENC_TXT_PWD_ALLOWED\n"));
1626 if (acct_flags & ACB_NOT_DELEGATED) {
1627 DEBUGADD(lvl,("\taccount has ACB_NOT_DELEGATED\n"));
1629 if (acct_flags & ACB_USE_DES_KEY_ONLY) {
1630 DEBUGADD(lvl,("\taccount has ACB_USE_DES_KEY_ONLY set, sig verify wont work\n"));
1632 if (acct_flags & ACB_NO_AUTH_DATA_REQD) {
1633 DEBUGADD(lvl,("\taccount has ACB_NO_AUTH_DATA_REQD set\n"));
1635 if (acct_flags & ACB_PWEXPIRED) {
1636 DEBUGADD(lvl,("\taccount has ACB_PWEXPIRED set\n"));
1640 static void dump_user_flgs(uint32 user_flags) {
1642 int lvl = 10;
1643 DEBUG(lvl,("dump_user_flgs\n"));
1644 if (user_flags & LOGON_EXTRA_SIDS) {
1645 DEBUGADD(lvl,("\taccount has LOGON_EXTRA_SIDS\n"));
1647 if (user_flags & LOGON_RESOURCE_GROUPS) {
1648 DEBUGADD(lvl,("\taccount has LOGON_RESOURCE_GROUPS\n"));
1650 if (user_flags & LOGON_NTLMV2_ENABLED) {
1651 DEBUGADD(lvl,("\taccount has LOGON_NTLMV2_ENABLED\n"));
1653 if (user_flags & LOGON_CACHED_ACCOUNT) {
1654 DEBUGADD(lvl,("\taccount has LOGON_CACHED_ACCOUNT\n"));
1656 if (user_flags & LOGON_PROFILE_PATH_RETURNED) {
1657 DEBUGADD(lvl,("\taccount has LOGON_PROFILE_PATH_RETURNED\n"));
1659 if (user_flags & LOGON_SERVER_TRUST_ACCOUNT) {
1660 DEBUGADD(lvl,("\taccount has LOGON_SERVER_TRUST_ACCOUNT\n"));
1666 /*******************************************************************
1667 This code has been modified to cope with a NET_USER_INFO_2 - which is
1668 exactly the same as a NET_USER_INFO_3, minus the other sids parameters.
1669 We use validation level to determine if we're marshalling a info 2 or
1670 INFO_3 - be we always return an INFO_3. Based on code donated by Marc
1671 Jacobsen at HP. JRA.
1672 ********************************************************************/
1674 BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
1675 int depth, uint16 validation_level, BOOL kerb_validation_level)
1677 unsigned int i;
1679 if (usr == NULL)
1680 return False;
1682 prs_debug(ps, depth, desc, "net_io_user_info3");
1683 depth++;
1685 if (UNMARSHALLING(ps))
1686 ZERO_STRUCTP(usr);
1688 if(!prs_align(ps))
1689 return False;
1691 if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info))
1692 return False;
1694 if (usr->ptr_user_info == 0)
1695 return True;
1697 if(!smb_io_time("logon time", &usr->logon_time, ps, depth)) /* logon time */
1698 return False;
1699 if(!smb_io_time("logoff time", &usr->logoff_time, ps, depth)) /* logoff time */
1700 return False;
1701 if(!smb_io_time("kickoff time", &usr->kickoff_time, ps, depth)) /* kickoff time */
1702 return False;
1703 if(!smb_io_time("last set time", &usr->pass_last_set_time, ps, depth)) /* password last set time */
1704 return False;
1705 if(!smb_io_time("can change time", &usr->pass_can_change_time , ps, depth)) /* password can change time */
1706 return False;
1707 if(!smb_io_time("must change time", &usr->pass_must_change_time, ps, depth)) /* password must change time */
1708 return False;
1710 if(!smb_io_unihdr("hdr_user_name", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
1711 return False;
1712 if(!smb_io_unihdr("hdr_full_name", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
1713 return False;
1714 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
1715 return False;
1716 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
1717 return False;
1718 if(!smb_io_unihdr("hdr_home_dir", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
1719 return False;
1720 if(!smb_io_unihdr("hdr_dir_drive", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */
1721 return False;
1723 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count)) /* logon count */
1724 return False;
1725 if(!prs_uint16("bad_pw_count ", ps, depth, &usr->bad_pw_count)) /* bad password count */
1726 return False;
1728 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User RID */
1729 return False;
1730 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group RID */
1731 return False;
1732 if(!prs_uint32("num_groups ", ps, depth, &usr->num_groups)) /* num groups */
1733 return False;
1734 if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */
1735 return False;
1736 if(!prs_uint32("user_flgs ", ps, depth, &usr->user_flgs)) /* user flags */
1737 return False;
1738 dump_user_flgs(usr->user_flgs);
1739 if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* user session key */
1740 return False;
1742 if(!smb_io_unihdr("hdr_logon_srv", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */
1743 return False;
1744 if(!smb_io_unihdr("hdr_logon_dom", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */
1745 return False;
1747 if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */
1748 return False;
1750 if(!prs_uint8s(False, "lm_sess_key", ps, depth, usr->lm_sess_key, 8)) /* lm session key */
1751 return False;
1753 if(!prs_uint32("acct_flags ", ps, depth, &usr->acct_flags)) /* Account flags */
1754 return False;
1755 dump_acct_flags(usr->acct_flags);
1756 for (i = 0; i < 7; i++)
1758 if (!prs_uint32("unkown", ps, depth, &usr->unknown[i])) /* unknown */
1759 return False;
1762 if (validation_level == 3) {
1763 if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */
1764 return False;
1765 if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */
1766 return False;
1767 } else {
1768 if (UNMARSHALLING(ps)) {
1769 usr->num_other_sids = 0;
1770 usr->buffer_other_sids = 0;
1774 /* get kerb validation info (not really part of user_info_3) - Guenther */
1776 if (kerb_validation_level) {
1778 if(!prs_uint32("ptr_res_group_dom_sid", ps, depth, &usr->ptr_res_group_dom_sid))
1779 return False;
1780 if(!prs_uint32("res_group_count", ps, depth, &usr->res_group_count))
1781 return False;
1782 if(!prs_uint32("ptr_res_groups", ps, depth, &usr->ptr_res_groups))
1783 return False;
1786 if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
1787 return False;
1788 if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
1789 return False;
1790 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
1791 return False;
1792 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
1793 return False;
1794 if(!smb_io_unistr2("uni_home_dir", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
1795 return False;
1796 if(!smb_io_unistr2("uni_dir_drive", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
1797 return False;
1799 if(!prs_align(ps))
1800 return False;
1802 if(!prs_uint32("num_groups2 ", ps, depth, &usr->num_groups2)) /* num groups2 */
1803 return False;
1805 if (usr->num_groups != usr->num_groups2) {
1806 DEBUG(3,("net_io_user_info3: num_groups mismatch! (%d != %d)\n",
1807 usr->num_groups, usr->num_groups2));
1808 return False;
1811 if (UNMARSHALLING(ps)) {
1812 if (usr->num_groups) {
1813 usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups);
1814 if (usr->gids == NULL)
1815 return False;
1816 } else {
1817 usr->gids = NULL;
1821 for (i = 0; i < usr->num_groups; i++) {
1822 if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */
1823 return False;
1826 if(!smb_io_unistr2("uni_logon_srv", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */
1827 return False;
1828 if(!smb_io_unistr2("uni_logon_dom", &usr->uni_logon_dom, usr->hdr_logon_dom.buffer, ps, depth)) /* logon domain unicode string */
1829 return False;
1831 if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth)) /* domain SID */
1832 return False;
1834 if (validation_level == 3 && usr->buffer_other_sids) {
1836 uint32 num_other_sids = usr->num_other_sids;
1838 if (!(usr->user_flgs & LOGON_EXTRA_SIDS)) {
1839 DEBUG(10,("net_io_user_info3: user_flgs attribute does not have LOGON_EXTRA_SIDS\n"));
1840 /* return False; */
1843 if (!prs_uint32("num_other_sids", ps, depth,
1844 &num_other_sids))
1845 return False;
1847 if (num_other_sids != usr->num_other_sids)
1848 return False;
1850 if (UNMARSHALLING(ps)) {
1851 if (usr->num_other_sids) {
1852 usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
1853 usr->other_sids_attrib =
1854 PRS_ALLOC_MEM(ps, uint32, usr->num_other_sids);
1855 } else {
1856 usr->other_sids = NULL;
1857 usr->other_sids_attrib = NULL;
1860 if ((num_other_sids != 0) &&
1861 ((usr->other_sids == NULL) ||
1862 (usr->other_sids_attrib == NULL)))
1863 return False;
1866 /* First the pointers to the SIDS and attributes */
1868 depth++;
1870 for (i=0; i<usr->num_other_sids; i++) {
1871 uint32 ptr = 1;
1873 if (!prs_uint32("sid_ptr", ps, depth, &ptr))
1874 return False;
1876 if (UNMARSHALLING(ps) && (ptr == 0))
1877 return False;
1879 if (!prs_uint32("attribute", ps, depth,
1880 &usr->other_sids_attrib[i]))
1881 return False;
1884 for (i = 0; i < usr->num_other_sids; i++) {
1885 if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */
1886 return False;
1889 depth--;
1892 return True;
1895 /*******************************************************************
1896 Reads or writes a structure.
1897 ********************************************************************/
1899 BOOL net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
1901 if (q_l == NULL)
1902 return False;
1904 prs_debug(ps, depth, desc, "net_io_q_sam_logon");
1905 depth++;
1907 if(!prs_align(ps))
1908 return False;
1910 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))
1911 return False;
1913 if(!prs_align_uint16(ps))
1914 return False;
1916 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1917 return False;
1919 return True;
1922 /*******************************************************************
1923 Reads or writes a structure.
1924 ********************************************************************/
1926 BOOL net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
1928 if (r_l == NULL)
1929 return False;
1931 prs_debug(ps, depth, desc, "net_io_r_sam_logon");
1932 depth++;
1934 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1935 return False;
1936 if (&r_l->buffer_creds) {
1937 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
1938 return False;
1941 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
1942 return False;
1943 if(!prs_align(ps))
1944 return False;
1946 #if 1 /* W2k always needs this - even for bad passwd. JRA */
1947 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1948 return False;
1949 #else
1950 if (r_l->switch_value != 0) {
1951 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1952 return False;
1954 #endif
1956 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
1957 return False;
1959 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1960 return False;
1962 if(!prs_align(ps))
1963 return False;
1965 return True;
1968 /*******************************************************************
1969 Reads or writes a structure.
1970 ********************************************************************/
1972 BOOL net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct *ps, int depth)
1974 if (q_l == NULL)
1975 return False;
1977 prs_debug(ps, depth, desc, "net_io_q_sam_logon_ex");
1978 depth++;
1980 if(!prs_align(ps))
1981 return False;
1983 if(!smb_io_sam_info_ex("", &q_l->sam_id, ps, depth))
1984 return False;
1986 if(!prs_align_uint16(ps))
1987 return False;
1989 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1990 return False;
1992 if(!prs_uint32("flags ", ps, depth, &q_l->flags))
1993 return False;
1995 return True;
1998 /*******************************************************************
1999 Reads or writes a structure.
2000 ********************************************************************/
2002 BOOL net_io_r_sam_logon_ex(const char *desc, NET_R_SAM_LOGON_EX *r_l, prs_struct *ps, int depth)
2004 if (r_l == NULL)
2005 return False;
2007 prs_debug(ps, depth, desc, "net_io_r_sam_logon_ex");
2008 depth++;
2010 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
2011 return False;
2012 if(!prs_align(ps))
2013 return False;
2015 #if 1 /* W2k always needs this - even for bad passwd. JRA */
2016 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
2017 return False;
2018 #else
2019 if (r_l->switch_value != 0) {
2020 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
2021 return False;
2023 #endif
2025 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
2026 return False;
2028 if(!prs_uint32("flags ", ps, depth, &r_l->flags))
2029 return False;
2031 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
2032 return False;
2034 if(!prs_align(ps))
2035 return False;
2037 return True;
2041 /*******************************************************************
2042 Reads or writes a structure.
2043 ********************************************************************/
2045 BOOL net_io_q_sam_logoff(const char *desc, NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
2047 if (q_l == NULL)
2048 return False;
2050 prs_debug(ps, depth, desc, "net_io_q_sam_logoff");
2051 depth++;
2053 if(!prs_align(ps))
2054 return False;
2056 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth)) /* domain SID */
2057 return False;
2059 return True;
2062 /*******************************************************************
2063 Reads or writes a structure.
2064 ********************************************************************/
2066 BOOL net_io_r_sam_logoff(const char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
2068 if (r_l == NULL)
2069 return False;
2071 prs_debug(ps, depth, desc, "net_io_r_sam_logoff");
2072 depth++;
2074 if(!prs_align(ps))
2075 return False;
2077 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
2078 return False;
2079 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
2080 return False;
2082 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
2083 return False;
2085 return True;
2088 /*******************************************************************
2089 makes a NET_Q_SAM_SYNC structure.
2090 ********************************************************************/
2091 BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
2092 const char *cli_name, DOM_CRED *cli_creds,
2093 DOM_CRED *ret_creds, uint32 database_id,
2094 uint32 next_rid)
2096 DEBUG(5, ("init_q_sam_sync\n"));
2098 init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
2099 init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
2101 if (cli_creds)
2102 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
2104 if (cli_creds)
2105 memcpy(&q_s->ret_creds, ret_creds, sizeof(q_s->ret_creds));
2106 else
2107 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
2109 q_s->database_id = database_id;
2110 q_s->restart_state = 0;
2111 q_s->sync_context = next_rid;
2112 q_s->max_size = 0xffff;
2114 return True;
2117 /*******************************************************************
2118 reads or writes a structure.
2119 ********************************************************************/
2120 BOOL net_io_q_sam_sync(const char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
2121 int depth)
2123 prs_debug(ps, depth, desc, "net_io_q_sam_sync");
2124 depth++;
2126 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
2127 return False;
2128 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
2129 return False;
2131 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
2132 return False;
2133 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
2134 return False;
2136 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
2137 return False;
2138 if (!prs_uint32("restart_state", ps, depth, &q_s->restart_state))
2139 return False;
2140 if (!prs_uint32("sync_context ", ps, depth, &q_s->sync_context))
2141 return False;
2143 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
2144 return False;
2146 return True;
2149 /*******************************************************************
2150 reads or writes a structure.
2151 ********************************************************************/
2152 static BOOL net_io_sam_delta_hdr(const char *desc, SAM_DELTA_HDR * delta,
2153 prs_struct *ps, int depth)
2155 prs_debug(ps, depth, desc, "net_io_sam_delta_hdr");
2156 depth++;
2158 if (!prs_uint16("type", ps, depth, &delta->type))
2159 return False;
2160 if (!prs_uint16("type2", ps, depth, &delta->type2))
2161 return False;
2162 if (!prs_uint32("target_rid", ps, depth, &delta->target_rid))
2163 return False;
2165 if (!prs_uint32("type3", ps, depth, &delta->type3))
2166 return False;
2168 /* Not sure why we need this but it seems to be necessary to get
2169 sam deltas working. */
2171 if (delta->type != 0x16) {
2172 if (!prs_uint32("ptr_delta", ps, depth, &delta->ptr_delta))
2173 return False;
2176 return True;
2179 /*******************************************************************
2180 reads or writes a structure.
2181 ********************************************************************/
2182 static BOOL net_io_sam_delta_mod_count(const char *desc, SAM_DELTA_MOD_COUNT *info,
2183 prs_struct *ps, int depth)
2185 prs_debug(ps, depth, desc, "net_io_sam_delta_stamp");
2186 depth++;
2188 if (!prs_uint32("seqnum", ps, depth, &info->seqnum))
2189 return False;
2190 if (!prs_uint32("dom_mod_count_ptr", ps, depth,
2191 &info->dom_mod_count_ptr))
2192 return False;
2194 if (info->dom_mod_count_ptr) {
2195 if (!prs_uint64("dom_mod_count", ps, depth,
2196 &info->dom_mod_count))
2197 return False;
2200 return True;
2203 /*******************************************************************
2204 reads or writes a structure.
2205 ********************************************************************/
2206 static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
2207 prs_struct *ps, int depth)
2209 prs_debug(ps, depth, desc, "net_io_sam_domain_info");
2210 depth++;
2212 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2213 return False;
2214 if (!smb_io_unihdr("hdr_oem_info", &info->hdr_oem_info, ps, depth))
2215 return False;
2217 if (!prs_uint64("force_logoff", ps, depth, &info->force_logoff))
2218 return False;
2219 if (!prs_uint16("min_pwd_len", ps, depth, &info->min_pwd_len))
2220 return False;
2221 if (!prs_uint16("pwd_history_len", ps, depth, &info->pwd_history_len))
2222 return False;
2223 if (!prs_uint64("max_pwd_age", ps, depth, &info->max_pwd_age))
2224 return False;
2225 if (!prs_uint64("min_pwd_age", ps, depth, &info->min_pwd_age))
2226 return False;
2227 if (!prs_uint64("dom_mod_count", ps, depth, &info->dom_mod_count))
2228 return False;
2229 if (!smb_io_time("creation_time", &info->creation_time, ps, depth))
2230 return False;
2231 if (!prs_uint32("security_information", ps, depth, &info->security_information))
2232 return False;
2233 if (!smb_io_bufhdr4("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2234 return False;
2235 if (!smb_io_lockout_string_hdr("hdr_account_lockout_string", &info->hdr_account_lockout, ps, depth))
2236 return False;
2237 if (!smb_io_unihdr("hdr_unknown2", &info->hdr_unknown2, ps, depth))
2238 return False;
2239 if (!smb_io_unihdr("hdr_unknown3", &info->hdr_unknown3, ps, depth))
2240 return False;
2241 if (!smb_io_unihdr("hdr_unknown4", &info->hdr_unknown4, ps, depth))
2242 return False;
2243 if (!prs_uint32("logon_chgpass", ps, depth, &info->logon_chgpass))
2244 return False;
2245 if (!prs_uint32("unknown6", ps, depth, &info->unknown6))
2246 return False;
2247 if (!prs_uint32("unknown7", ps, depth, &info->unknown7))
2248 return False;
2249 if (!prs_uint32("unknown8", ps, depth, &info->unknown8))
2250 return False;
2252 if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
2253 info->hdr_dom_name.buffer, ps, depth))
2254 return False;
2255 if (!smb_io_unistr2("buf_oem_info", &info->buf_oem_info,
2256 info->hdr_oem_info.buffer, ps, depth))
2257 return False;
2259 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2260 return False;
2262 if (!smb_io_account_lockout_str("account_lockout", &info->account_lockout,
2263 info->hdr_account_lockout.buffer, ps, depth))
2264 return False;
2266 if (!smb_io_unistr2("buf_unknown2", &info->buf_unknown2,
2267 info->hdr_unknown2.buffer, ps, depth))
2268 return False;
2269 if (!smb_io_unistr2("buf_unknown3", &info->buf_unknown3,
2270 info->hdr_unknown3.buffer, ps, depth))
2271 return False;
2272 if (!smb_io_unistr2("buf_unknown4", &info->buf_unknown4,
2273 info->hdr_unknown4.buffer, ps, depth))
2274 return False;
2276 return True;
2279 /*******************************************************************
2280 reads or writes a structure.
2281 ********************************************************************/
2282 static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
2283 prs_struct *ps, int depth)
2285 prs_debug(ps, depth, desc, "net_io_sam_group_info");
2286 depth++;
2288 if (!smb_io_unihdr("hdr_grp_name", &info->hdr_grp_name, ps, depth))
2289 return False;
2290 if (!smb_io_gid("gid", &info->gid, ps, depth))
2291 return False;
2292 if (!smb_io_unihdr("hdr_grp_desc", &info->hdr_grp_desc, ps, depth))
2293 return False;
2294 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2295 return False;
2297 if (ps->data_offset + 48 > ps->buffer_size)
2298 return False;
2299 ps->data_offset += 48;
2301 if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
2302 info->hdr_grp_name.buffer, ps, depth))
2303 return False;
2304 if (!smb_io_unistr2("uni_grp_desc", &info->uni_grp_desc,
2305 info->hdr_grp_desc.buffer, ps, depth))
2306 return False;
2307 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2308 return False;
2310 return True;
2313 /*******************************************************************
2314 reads or writes a structure.
2315 ********************************************************************/
2316 static BOOL net_io_sam_passwd_info(const char *desc, SAM_PWD * pwd,
2317 prs_struct *ps, int depth)
2319 prs_debug(ps, depth, desc, "net_io_sam_passwd_info");
2320 depth++;
2322 if (!prs_uint32("unk_0 ", ps, depth, &pwd->unk_0))
2323 return False;
2325 if (!smb_io_unihdr("hdr_lm_pwd", &pwd->hdr_lm_pwd, ps, depth))
2326 return False;
2327 if (!prs_uint8s(False, "buf_lm_pwd", ps, depth, pwd->buf_lm_pwd, 16))
2328 return False;
2330 if (!smb_io_unihdr("hdr_nt_pwd", &pwd->hdr_nt_pwd, ps, depth))
2331 return False;
2332 if (!prs_uint8s(False, "buf_nt_pwd", ps, depth, pwd->buf_nt_pwd, 16))
2333 return False;
2335 if (!smb_io_unihdr("", &pwd->hdr_empty_lm, ps, depth))
2336 return False;
2337 if (!smb_io_unihdr("", &pwd->hdr_empty_nt, ps, depth))
2338 return False;
2340 return True;
2343 /*******************************************************************
2344 reads or writes a structure.
2345 ********************************************************************/
2346 static BOOL net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
2347 prs_struct *ps, int depth)
2349 BUFHDR2 hdr_priv_data;
2350 uint32 i;
2352 prs_debug(ps, depth, desc, "net_io_sam_account_info");
2353 depth++;
2355 if (!smb_io_unihdr("hdr_acct_name", &info->hdr_acct_name, ps, depth))
2356 return False;
2357 if (!smb_io_unihdr("hdr_full_name", &info->hdr_full_name, ps, depth))
2358 return False;
2360 if (!prs_uint32("user_rid ", ps, depth, &info->user_rid))
2361 return False;
2362 if (!prs_uint32("group_rid", ps, depth, &info->group_rid))
2363 return False;
2365 if (!smb_io_unihdr("hdr_home_dir ", &info->hdr_home_dir, ps, depth))
2366 return False;
2367 if (!smb_io_unihdr("hdr_dir_drive", &info->hdr_dir_drive, ps, depth))
2368 return False;
2369 if (!smb_io_unihdr("hdr_logon_script", &info->hdr_logon_script, ps,
2370 depth))
2371 return False;
2373 if (!smb_io_unihdr("hdr_acct_desc", &info->hdr_acct_desc, ps, depth))
2374 return False;
2375 if (!smb_io_unihdr("hdr_workstations", &info->hdr_workstations, ps,
2376 depth))
2377 return False;
2379 if (!smb_io_time("logon_time", &info->logon_time, ps, depth))
2380 return False;
2381 if (!smb_io_time("logoff_time", &info->logoff_time, ps, depth))
2382 return False;
2384 if (!prs_uint32("logon_divs ", ps, depth, &info->logon_divs))
2385 return False;
2386 if (!prs_uint32("ptr_logon_hrs", ps, depth, &info->ptr_logon_hrs))
2387 return False;
2389 if (!prs_uint16("bad_pwd_count", ps, depth, &info->bad_pwd_count))
2390 return False;
2391 if (!prs_uint16("logon_count", ps, depth, &info->logon_count))
2392 return False;
2393 if (!smb_io_time("pwd_last_set_time", &info->pwd_last_set_time, ps,
2394 depth))
2395 return False;
2396 if (!smb_io_time("acct_expiry_time", &info->acct_expiry_time, ps,
2397 depth))
2398 return False;
2400 if (!prs_uint32("acb_info", ps, depth, &info->acb_info))
2401 return False;
2402 if (!prs_uint8s(False, "nt_pwd", ps, depth, info->nt_pwd, 16))
2403 return False;
2404 if (!prs_uint8s(False, "lm_pwd", ps, depth, info->lm_pwd, 16))
2405 return False;
2406 if (!prs_uint8("lm_pwd_present", ps, depth, &info->lm_pwd_present))
2407 return False;
2408 if (!prs_uint8("nt_pwd_present", ps, depth, &info->nt_pwd_present))
2409 return False;
2410 if (!prs_uint8("pwd_expired", ps, depth, &info->pwd_expired))
2411 return False;
2413 if (!smb_io_unihdr("hdr_comment", &info->hdr_comment, ps, depth))
2414 return False;
2415 if (!smb_io_unihdr("hdr_parameters", &info->hdr_parameters, ps,
2416 depth))
2417 return False;
2418 if (!prs_uint16("country", ps, depth, &info->country))
2419 return False;
2420 if (!prs_uint16("codepage", ps, depth, &info->codepage))
2421 return False;
2423 if (!smb_io_bufhdr2("hdr_priv_data", &hdr_priv_data, ps, depth))
2424 return False;
2425 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2426 return False;
2427 if (!smb_io_unihdr("hdr_profile", &info->hdr_profile, ps, depth))
2428 return False;
2430 for (i = 0; i < 3; i++)
2432 if (!smb_io_unihdr("hdr_reserved", &info->hdr_reserved[i],
2433 ps, depth))
2434 return False;
2437 for (i = 0; i < 4; i++)
2439 if (!prs_uint32("dw_reserved", ps, depth,
2440 &info->dw_reserved[i]))
2441 return False;
2444 if (!smb_io_unistr2("uni_acct_name", &info->uni_acct_name,
2445 info->hdr_acct_name.buffer, ps, depth))
2446 return False;
2447 prs_align(ps);
2448 if (!smb_io_unistr2("uni_full_name", &info->uni_full_name,
2449 info->hdr_full_name.buffer, ps, depth))
2450 return False;
2451 prs_align(ps);
2452 if (!smb_io_unistr2("uni_home_dir ", &info->uni_home_dir,
2453 info->hdr_home_dir.buffer, ps, depth))
2454 return False;
2455 prs_align(ps);
2456 if (!smb_io_unistr2("uni_dir_drive", &info->uni_dir_drive,
2457 info->hdr_dir_drive.buffer, ps, depth))
2458 return False;
2459 prs_align(ps);
2460 if (!smb_io_unistr2("uni_logon_script", &info->uni_logon_script,
2461 info->hdr_logon_script.buffer, ps, depth))
2462 return False;
2463 prs_align(ps);
2464 if (!smb_io_unistr2("uni_acct_desc", &info->uni_acct_desc,
2465 info->hdr_acct_desc.buffer, ps, depth))
2466 return False;
2467 prs_align(ps);
2468 if (!smb_io_unistr2("uni_workstations", &info->uni_workstations,
2469 info->hdr_workstations.buffer, ps, depth))
2470 return False;
2471 prs_align(ps);
2473 if (!prs_uint32("unknown1", ps, depth, &info->unknown1))
2474 return False;
2475 if (!prs_uint32("unknown2", ps, depth, &info->unknown2))
2476 return False;
2478 if (!smb_io_rpc_blob("buf_logon_hrs", &info->buf_logon_hrs, ps, depth))
2479 return False;
2480 prs_align(ps);
2481 if (!smb_io_unistr2("uni_comment", &info->uni_comment,
2482 info->hdr_comment.buffer, ps, depth))
2483 return False;
2484 prs_align(ps);
2485 if (!smb_io_unistr2("uni_parameters", &info->uni_parameters,
2486 info->hdr_parameters.buffer, ps, depth))
2487 return False;
2488 prs_align(ps);
2489 if (hdr_priv_data.buffer != 0)
2491 int old_offset = 0;
2492 uint32 len = 0x44;
2493 if (!prs_uint32("pwd_len", ps, depth, &len))
2494 return False;
2495 old_offset = ps->data_offset;
2496 if (len > 0)
2498 if (ps->io)
2500 /* reading */
2501 if (!prs_hash1(ps, ps->data_offset, len))
2502 return False;
2504 if (!net_io_sam_passwd_info("pass", &info->pass,
2505 ps, depth))
2506 return False;
2508 if (!ps->io)
2510 /* writing */
2511 if (!prs_hash1(ps, old_offset, len))
2512 return False;
2515 if (old_offset + len > ps->buffer_size)
2516 return False;
2517 ps->data_offset = old_offset + len;
2519 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2520 return False;
2521 prs_align(ps);
2522 if (!smb_io_unistr2("uni_profile", &info->uni_profile,
2523 info->hdr_profile.buffer, ps, depth))
2524 return False;
2526 prs_align(ps);
2528 return True;
2531 /*******************************************************************
2532 reads or writes a structure.
2533 ********************************************************************/
2534 static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * info,
2535 prs_struct *ps, int depth)
2537 uint32 i;
2538 fstring tmp;
2540 prs_debug(ps, depth, desc, "net_io_sam_group_mem_info");
2541 depth++;
2543 prs_align(ps);
2544 if (!prs_uint32("ptr_rids ", ps, depth, &info->ptr_rids))
2545 return False;
2546 if (!prs_uint32("ptr_attribs", ps, depth, &info->ptr_attribs))
2547 return False;
2548 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2549 return False;
2551 if (ps->data_offset + 16 > ps->buffer_size)
2552 return False;
2553 ps->data_offset += 16;
2555 if (info->ptr_rids != 0)
2557 if (!prs_uint32("num_members2", ps, depth,
2558 &info->num_members2))
2559 return False;
2561 if (info->num_members2 != info->num_members)
2563 /* RPC fault */
2564 return False;
2567 if (UNMARSHALLING(ps)) {
2568 if (info->num_members2) {
2569 info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
2571 if (info->rids == NULL) {
2572 DEBUG(0, ("out of memory allocating %d rids\n",
2573 info->num_members2));
2574 return False;
2576 } else {
2577 info->rids = NULL;
2581 for (i = 0; i < info->num_members2; i++)
2583 slprintf(tmp, sizeof(tmp) - 1, "rids[%02d]", i);
2584 if (!prs_uint32(tmp, ps, depth, &info->rids[i]))
2585 return False;
2589 if (info->ptr_attribs != 0)
2591 if (!prs_uint32("num_members3", ps, depth,
2592 &info->num_members3))
2593 return False;
2594 if (info->num_members3 != info->num_members)
2596 /* RPC fault */
2597 return False;
2600 if (UNMARSHALLING(ps)) {
2601 if (info->num_members3) {
2602 info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
2604 if (info->attribs == NULL) {
2605 DEBUG(0, ("out of memory allocating %d attribs\n",
2606 info->num_members3));
2607 return False;
2609 } else {
2610 info->attribs = NULL;
2614 for (i = 0; i < info->num_members3; i++)
2616 slprintf(tmp, sizeof(tmp) - 1, "attribs[%02d]", i);
2617 if (!prs_uint32(tmp, ps, depth, &info->attribs[i]))
2618 return False;
2622 return True;
2625 /*******************************************************************
2626 reads or writes a structure.
2627 ********************************************************************/
2628 static BOOL net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
2629 prs_struct *ps, int depth)
2631 prs_debug(ps, depth, desc, "net_io_sam_alias_info");
2632 depth++;
2634 if (!smb_io_unihdr("hdr_als_name", &info->hdr_als_name, ps, depth))
2635 return False;
2636 if (!prs_uint32("als_rid", ps, depth, &info->als_rid))
2637 return False;
2638 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2639 return False;
2640 if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
2641 return False;
2643 if (ps->data_offset + 40 > ps->buffer_size)
2644 return False;
2645 ps->data_offset += 40;
2647 if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
2648 info->hdr_als_name.buffer, ps, depth))
2649 return False;
2650 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2651 return False;
2653 if (!smb_io_unistr2("uni_als_desc", &info->uni_als_desc,
2654 info->hdr_als_desc.buffer, ps, depth))
2655 return False;
2657 return True;
2660 /*******************************************************************
2661 reads or writes a structure.
2662 ********************************************************************/
2663 static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * info,
2664 prs_struct *ps, int depth)
2666 uint32 i;
2667 fstring tmp;
2669 prs_debug(ps, depth, desc, "net_io_sam_alias_mem_info");
2670 depth++;
2672 prs_align(ps);
2673 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2674 return False;
2675 if (!prs_uint32("ptr_members", ps, depth, &info->ptr_members))
2676 return False;
2678 if (ps->data_offset + 16 > ps->buffer_size)
2679 return False;
2680 ps->data_offset += 16;
2682 if (info->ptr_members != 0)
2684 if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
2685 return False;
2686 if (info->num_sids != info->num_members)
2688 /* RPC fault */
2689 return False;
2692 if (UNMARSHALLING(ps)) {
2693 if (info->num_sids) {
2694 info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
2696 if (info->ptr_sids == NULL) {
2697 DEBUG(0, ("out of memory allocating %d ptr_sids\n",
2698 info->num_sids));
2699 return False;
2701 } else {
2702 info->ptr_sids = NULL;
2706 for (i = 0; i < info->num_sids; i++)
2708 slprintf(tmp, sizeof(tmp) - 1, "ptr_sids[%02d]", i);
2709 if (!prs_uint32(tmp, ps, depth, &info->ptr_sids[i]))
2710 return False;
2713 if (UNMARSHALLING(ps)) {
2714 if (info->num_sids) {
2715 info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
2717 if (info->sids == NULL) {
2718 DEBUG(0, ("error allocating %d sids\n",
2719 info->num_sids));
2720 return False;
2722 } else {
2723 info->sids = NULL;
2727 for (i = 0; i < info->num_sids; i++)
2729 if (info->ptr_sids[i] != 0)
2731 slprintf(tmp, sizeof(tmp) - 1, "sids[%02d]",
2733 if (!smb_io_dom_sid2(tmp, &info->sids[i],
2734 ps, depth))
2735 return False;
2740 return True;
2743 /*******************************************************************
2744 reads or writes a structure.
2745 ********************************************************************/
2746 static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
2747 prs_struct *ps, int depth)
2749 unsigned int i;
2750 prs_debug(ps, depth, desc, "net_io_sam_policy_info");
2751 depth++;
2753 if(!prs_align(ps))
2754 return False;
2756 if (!prs_uint32("max_log_size", ps, depth, &info->max_log_size))
2757 return False;
2758 if (!prs_uint64("audit_retention_period", ps, depth,
2759 &info->audit_retention_period))
2760 return False;
2761 if (!prs_uint32("auditing_mode", ps, depth, &info->auditing_mode))
2762 return False;
2763 if (!prs_uint32("num_events", ps, depth, &info->num_events))
2764 return False;
2765 if (!prs_uint32("ptr_events", ps, depth, &info->ptr_events))
2766 return False;
2768 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2769 return False;
2771 if (!prs_uint32("sid_ptr", ps, depth, &info->sid_ptr))
2772 return False;
2774 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2775 return False;
2776 if (!prs_uint32("non_paged_pool_limit", ps, depth,
2777 &info->non_paged_pool_limit))
2778 return False;
2779 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
2780 return False;
2781 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
2782 return False;
2783 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
2784 return False;
2785 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
2786 return False;
2787 if (!smb_io_time("modify_time", &info->modify_time, ps, depth))
2788 return False;
2789 if (!smb_io_time("create_time", &info->create_time, ps, depth))
2790 return False;
2791 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2792 return False;
2794 for (i=0; i<4; i++) {
2795 UNIHDR dummy;
2796 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
2797 return False;
2800 for (i=0; i<4; i++) {
2801 uint32 reserved;
2802 if (!prs_uint32("reserved", ps, depth, &reserved))
2803 return False;
2806 if (!prs_uint32("num_event_audit_options", ps, depth,
2807 &info->num_event_audit_options))
2808 return False;
2810 for (i=0; i<info->num_event_audit_options; i++)
2811 if (!prs_uint32("event_audit_option", ps, depth,
2812 &info->event_audit_option))
2813 return False;
2815 if (!smb_io_unistr2("domain_name", &info->domain_name, True, ps, depth))
2816 return False;
2818 if(!smb_io_dom_sid2("domain_sid", &info->domain_sid, ps, depth))
2819 return False;
2821 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2823 return False;
2825 return True;
2828 #if 0
2830 /* This function is pretty broken - see bug #334 */
2832 /*******************************************************************
2833 reads or writes a structure.
2834 ********************************************************************/
2835 static BOOL net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *info,
2836 prs_struct *ps, int depth)
2838 int i;
2840 prs_debug(ps, depth, desc, "net_io_sam_trustdoms_info");
2841 depth++;
2843 if(!prs_align(ps))
2844 return False;
2846 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2847 return False;
2849 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2850 return False;
2852 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2853 return False;
2855 if(!smb_io_unihdr("hdr_domain", &info->hdr_domain, ps, depth))
2856 return False;
2858 if(!prs_uint32("unknown0", ps, depth, &info->unknown0))
2859 return False;
2860 if(!prs_uint32("unknown1", ps, depth, &info->unknown1))
2861 return False;
2862 if(!prs_uint32("unknown2", ps, depth, &info->unknown2))
2863 return False;
2865 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2866 return False;
2867 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2868 return False;
2870 for (i=0; i<12; i++)
2871 if(!prs_uint32("unknown3", ps, depth, &info->unknown3))
2872 return False;
2874 if (!smb_io_unistr2("domain", &info->domain, True, ps, depth))
2875 return False;
2877 return True;
2880 #endif
2882 #if 0
2884 /* This function doesn't work - see bug #334 */
2886 /*******************************************************************
2887 reads or writes a structure.
2888 ********************************************************************/
2889 static BOOL net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
2890 prs_struct *ps, int depth)
2892 int i;
2894 prs_debug(ps, depth, desc, "net_io_sam_secret_info");
2895 depth++;
2897 if(!prs_align(ps))
2898 return False;
2900 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2901 return False;
2903 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2904 return False;
2906 if (!smb_io_unistr2("secret", &info->secret, True, ps, depth))
2907 return False;
2909 if(!prs_align(ps))
2910 return False;
2912 if(!prs_uint32("count1", ps, depth, &info->count1))
2913 return False;
2914 if(!prs_uint32("count2", ps, depth, &info->count2))
2915 return False;
2916 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2917 return False;
2920 if(!smb_io_time("time1", &info->time1, ps, depth)) /* logon time */
2921 return False;
2922 if(!prs_uint32("count3", ps, depth, &info->count3))
2923 return False;
2924 if(!prs_uint32("count4", ps, depth, &info->count4))
2925 return False;
2926 if(!prs_uint32("ptr2", ps, depth, &info->ptr2))
2927 return False;
2928 if(!smb_io_time("time2", &info->time2, ps, depth)) /* logon time */
2929 return False;
2930 if(!prs_uint32("unknow1", ps, depth, &info->unknow1))
2931 return False;
2934 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2935 return False;
2936 if(!prs_uint32("ptr3", ps, depth, &info->ptr3))
2937 return False;
2938 for(i=0; i<12; i++)
2939 if(!prs_uint32("unknow2", ps, depth, &info->unknow2))
2940 return False;
2942 if(!prs_uint32("chal_len", ps, depth, &info->chal_len))
2943 return False;
2944 if(!prs_uint32("reserved1", ps, depth, &info->reserved1))
2945 return False;
2946 if(!prs_uint32("chal_len2", ps, depth, &info->chal_len2))
2947 return False;
2949 if(!prs_uint8s (False, "chal", ps, depth, info->chal, info->chal_len2))
2950 return False;
2952 if(!prs_uint32("key_len", ps, depth, &info->key_len))
2953 return False;
2954 if(!prs_uint32("reserved2", ps, depth, &info->reserved2))
2955 return False;
2956 if(!prs_uint32("key_len2", ps, depth, &info->key_len2))
2957 return False;
2959 if(!prs_uint8s (False, "key", ps, depth, info->key, info->key_len2))
2960 return False;
2963 if(!prs_uint32("buf_size3", ps, depth, &info->buf_size3))
2964 return False;
2966 if(!sec_io_desc("sec_desc2", &info->sec_desc2, ps, depth))
2967 return False;
2970 return True;
2973 #endif
2975 /*******************************************************************
2976 reads or writes a structure.
2977 ********************************************************************/
2978 static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
2979 prs_struct *ps, int depth)
2981 unsigned int i;
2983 prs_debug(ps, depth, desc, "net_io_sam_privs_info");
2984 depth++;
2986 if(!prs_align(ps))
2987 return False;
2989 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2990 return False;
2992 if(!prs_uint32("priv_count", ps, depth, &info->priv_count))
2993 return False;
2994 if(!prs_uint32("priv_control", ps, depth, &info->priv_control))
2995 return False;
2997 if(!prs_uint32("priv_attr_ptr", ps, depth, &info->priv_attr_ptr))
2998 return False;
2999 if(!prs_uint32("priv_name_ptr", ps, depth, &info->priv_name_ptr))
3000 return False;
3002 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
3003 return False;
3004 if (!prs_uint32("non_paged_pool_limit", ps, depth,
3005 &info->non_paged_pool_limit))
3006 return False;
3007 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
3008 return False;
3009 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
3010 return False;
3011 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
3012 return False;
3013 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
3014 return False;
3015 if (!prs_uint32("system_flags", ps, depth, &info->system_flags))
3016 return False;
3017 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
3018 return False;
3020 for (i=0; i<4; i++) {
3021 UNIHDR dummy;
3022 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
3023 return False;
3026 for (i=0; i<4; i++) {
3027 uint32 reserved;
3028 if (!prs_uint32("reserved", ps, depth, &reserved))
3029 return False;
3032 if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
3033 return False;
3035 if (UNMARSHALLING(ps)) {
3036 if (info->attribute_count) {
3037 info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
3038 if (!info->attributes) {
3039 return False;
3041 } else {
3042 info->attributes = NULL;
3046 for (i=0; i<info->attribute_count; i++)
3047 if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
3048 return False;
3050 if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
3051 return False;
3053 if (UNMARSHALLING(ps)) {
3054 if (info->privlist_count) {
3055 info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
3056 info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
3057 if (!info->hdr_privslist) {
3058 return False;
3060 if (!info->uni_privslist) {
3061 return False;
3063 } else {
3064 info->hdr_privslist = NULL;
3065 info->uni_privslist = NULL;
3069 for (i=0; i<info->privlist_count; i++)
3070 if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
3071 return False;
3073 for (i=0; i<info->privlist_count; i++)
3074 if (!smb_io_unistr2("uni_privslist", &info->uni_privslist[i], True, ps, depth))
3075 return False;
3077 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
3078 return False;
3080 return True;
3083 /*******************************************************************
3084 reads or writes a structure.
3085 ********************************************************************/
3086 static BOOL net_io_sam_delta_ctr(const char *desc,
3087 SAM_DELTA_CTR * delta, uint16 type,
3088 prs_struct *ps, int depth)
3090 prs_debug(ps, depth, desc, "net_io_sam_delta_ctr");
3091 depth++;
3093 switch (type) {
3094 /* Seen in sam deltas */
3095 case SAM_DELTA_MODIFIED_COUNT:
3096 if (!net_io_sam_delta_mod_count("", &delta->mod_count, ps, depth))
3097 return False;
3098 break;
3100 case SAM_DELTA_DOMAIN_INFO:
3101 if (!net_io_sam_domain_info("", &delta->domain_info, ps, depth))
3102 return False;
3103 break;
3105 case SAM_DELTA_GROUP_INFO:
3106 if (!net_io_sam_group_info("", &delta->group_info, ps, depth))
3107 return False;
3108 break;
3110 case SAM_DELTA_ACCOUNT_INFO:
3111 if (!net_io_sam_account_info("", &delta->account_info, ps, depth))
3112 return False;
3113 break;
3115 case SAM_DELTA_GROUP_MEM:
3116 if (!net_io_sam_group_mem_info("", &delta->grp_mem_info, ps, depth))
3117 return False;
3118 break;
3120 case SAM_DELTA_ALIAS_INFO:
3121 if (!net_io_sam_alias_info("", &delta->alias_info, ps, depth))
3122 return False;
3123 break;
3125 case SAM_DELTA_POLICY_INFO:
3126 if (!net_io_sam_policy_info("", &delta->policy_info, ps, depth))
3127 return False;
3128 break;
3130 case SAM_DELTA_ALIAS_MEM:
3131 if (!net_io_sam_alias_mem_info("", &delta->als_mem_info, ps, depth))
3132 return False;
3133 break;
3135 case SAM_DELTA_PRIVS_INFO:
3136 if (!net_io_sam_privs_info("", &delta->privs_info, ps, depth))
3137 return False;
3138 break;
3140 /* These guys are implemented but broken */
3142 case SAM_DELTA_TRUST_DOMS:
3143 case SAM_DELTA_SECRET_INFO:
3144 break;
3146 /* These guys are not implemented yet */
3148 case SAM_DELTA_RENAME_GROUP:
3149 case SAM_DELTA_RENAME_USER:
3150 case SAM_DELTA_RENAME_ALIAS:
3151 case SAM_DELTA_DELETE_GROUP:
3152 case SAM_DELTA_DELETE_USER:
3153 default:
3154 DEBUG(0, ("Replication error: Unknown delta type 0x%x\n", type));
3155 break;
3158 return True;
3161 /*******************************************************************
3162 reads or writes a structure.
3163 ********************************************************************/
3164 BOOL net_io_r_sam_sync(const char *desc,
3165 NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
3167 uint32 i;
3169 prs_debug(ps, depth, desc, "net_io_r_sam_sync");
3170 depth++;
3172 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3173 return False;
3174 if (!prs_uint32("sync_context", ps, depth, &r_s->sync_context))
3175 return False;
3177 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3178 return False;
3179 if (r_s->ptr_deltas != 0)
3181 if (!prs_uint32("num_deltas ", ps, depth, &r_s->num_deltas))
3182 return False;
3183 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->ptr_deltas2))
3184 return False;
3185 if (r_s->ptr_deltas2 != 0)
3187 if (!prs_uint32("num_deltas2", ps, depth,
3188 &r_s->num_deltas2))
3189 return False;
3191 if (r_s->num_deltas2 != r_s->num_deltas)
3193 /* RPC fault */
3194 return False;
3197 if (UNMARSHALLING(ps)) {
3198 if (r_s->num_deltas2) {
3199 r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
3200 if (r_s->hdr_deltas == NULL) {
3201 DEBUG(0, ("error tallocating memory "
3202 "for %d delta headers\n",
3203 r_s->num_deltas2));
3204 return False;
3206 } else {
3207 r_s->hdr_deltas = NULL;
3211 for (i = 0; i < r_s->num_deltas2; i++)
3213 if (!net_io_sam_delta_hdr("",
3214 &r_s->hdr_deltas[i],
3215 ps, depth))
3216 return False;
3219 if (UNMARSHALLING(ps)) {
3220 if (r_s->num_deltas2) {
3221 r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
3222 if (r_s->deltas == NULL) {
3223 DEBUG(0, ("error tallocating memory "
3224 "for %d deltas\n",
3225 r_s->num_deltas2));
3226 return False;
3228 } else {
3229 r_s->deltas = NULL;
3233 for (i = 0; i < r_s->num_deltas2; i++)
3235 if (!net_io_sam_delta_ctr(
3236 "", &r_s->deltas[i],
3237 r_s->hdr_deltas[i].type3,
3238 ps, depth)) {
3239 DEBUG(0, ("hmm, failed on i=%d\n", i));
3240 return False;
3246 prs_align(ps);
3247 if (!prs_ntstatus("status", ps, depth, &(r_s->status)))
3248 return False;
3250 return True;
3253 /*******************************************************************
3254 makes a NET_Q_SAM_DELTAS structure.
3255 ********************************************************************/
3256 BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
3257 const char *cli_name, DOM_CRED *cli_creds,
3258 uint32 database_id, uint64 dom_mod_count)
3260 DEBUG(5, ("init_net_q_sam_deltas\n"));
3262 init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
3263 init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
3265 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
3266 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
3268 q_s->database_id = database_id;
3269 q_s->dom_mod_count = dom_mod_count;
3270 q_s->max_size = 0xffff;
3272 return True;
3275 /*******************************************************************
3276 reads or writes a structure.
3277 ********************************************************************/
3278 BOOL net_io_q_sam_deltas(const char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
3279 int depth)
3281 prs_debug(ps, depth, desc, "net_io_q_sam_deltas");
3282 depth++;
3284 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
3285 return False;
3286 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
3287 return False;
3289 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
3290 return False;
3291 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
3292 return False;
3294 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
3295 return False;
3296 if (!prs_uint64("dom_mod_count", ps, depth, &q_s->dom_mod_count))
3297 return False;
3298 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
3299 return False;
3301 return True;
3304 /*******************************************************************
3305 reads or writes a structure.
3306 ********************************************************************/
3307 BOOL net_io_r_sam_deltas(const char *desc,
3308 NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
3310 unsigned int i;
3312 prs_debug(ps, depth, desc, "net_io_r_sam_deltas");
3313 depth++;
3315 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3316 return False;
3317 if (!prs_uint64("dom_mod_count", ps, depth, &r_s->dom_mod_count))
3318 return False;
3320 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3321 return False;
3322 if (!prs_uint32("num_deltas", ps, depth, &r_s->num_deltas))
3323 return False;
3324 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->num_deltas2))
3325 return False;
3327 if (r_s->num_deltas2 != 0)
3329 if (!prs_uint32("num_deltas2 ", ps, depth, &r_s->num_deltas2))
3330 return False;
3332 if (r_s->ptr_deltas != 0)
3334 if (UNMARSHALLING(ps)) {
3335 if (r_s->num_deltas) {
3336 r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
3337 if (r_s->hdr_deltas == NULL) {
3338 DEBUG(0, ("error tallocating memory "
3339 "for %d delta headers\n",
3340 r_s->num_deltas));
3341 return False;
3343 } else {
3344 r_s->hdr_deltas = NULL;
3348 for (i = 0; i < r_s->num_deltas; i++)
3350 net_io_sam_delta_hdr("", &r_s->hdr_deltas[i],
3351 ps, depth);
3354 if (UNMARSHALLING(ps)) {
3355 if (r_s->num_deltas) {
3356 r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
3357 if (r_s->deltas == NULL) {
3358 DEBUG(0, ("error tallocating memory "
3359 "for %d deltas\n",
3360 r_s->num_deltas));
3361 return False;
3363 } else {
3364 r_s->deltas = NULL;
3368 for (i = 0; i < r_s->num_deltas; i++)
3370 if (!net_io_sam_delta_ctr(
3372 &r_s->deltas[i],
3373 r_s->hdr_deltas[i].type2,
3374 ps, depth))
3376 return False;
3381 prs_align(ps);
3382 if (!prs_ntstatus("status", ps, depth, &r_s->status))
3383 return False;
3385 return True;
3388 /*******************************************************************
3389 Inits a NET_Q_DSR_GETDCNAME structure.
3390 ********************************************************************/
3392 void init_net_q_dsr_getdcname(NET_Q_DSR_GETDCNAME *r_t, const char *server_unc,
3393 const char *domain_name,
3394 struct GUID *domain_guid,
3395 struct GUID *site_guid,
3396 uint32_t flags)
3398 DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3400 r_t->ptr_server_unc = (server_unc != NULL);
3401 init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3403 r_t->ptr_domain_name = (domain_name != NULL);
3404 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3406 r_t->ptr_domain_guid = (domain_guid != NULL);
3407 r_t->domain_guid = domain_guid;
3409 r_t->ptr_site_guid = (site_guid != NULL);
3410 r_t->site_guid = site_guid;
3412 r_t->flags = flags;
3415 /*******************************************************************
3416 Inits a NET_Q_DSR_GETDCNAMEEX structure.
3417 ********************************************************************/
3419 void init_net_q_dsr_getdcnameex(NET_Q_DSR_GETDCNAMEEX *r_t, const char *server_unc,
3420 const char *domain_name,
3421 struct GUID *domain_guid,
3422 const char *site_name,
3423 uint32_t flags)
3425 DEBUG(5, ("init_net_q_dsr_getdcnameex\n"));
3427 r_t->ptr_server_unc = (server_unc != NULL);
3428 init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3430 r_t->ptr_domain_name = (domain_name != NULL);
3431 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3433 r_t->ptr_domain_guid = (domain_guid != NULL);
3434 r_t->domain_guid = domain_guid;
3436 r_t->ptr_site_name = (site_name != NULL);
3437 init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
3439 r_t->flags = flags;
3442 /*******************************************************************
3443 Inits a NET_Q_DSR_GETDCNAMEEX2 structure.
3444 ********************************************************************/
3446 void init_net_q_dsr_getdcnameex2(NET_Q_DSR_GETDCNAMEEX2 *r_t, const char *server_unc,
3447 const char *domain_name,
3448 const char *client_account,
3449 uint32 mask,
3450 struct GUID *domain_guid,
3451 const char *site_name,
3452 uint32_t flags)
3454 DEBUG(5, ("init_net_q_dsr_getdcnameex2\n"));
3456 r_t->ptr_server_unc = (server_unc != NULL);
3457 init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3459 r_t->ptr_client_account = (client_account != NULL);
3460 init_unistr2(&r_t->uni_client_account, client_account, UNI_STR_TERMINATE);
3462 r_t->mask = mask;
3464 r_t->ptr_domain_name = (domain_name != NULL);
3465 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3467 r_t->ptr_domain_guid = (domain_guid != NULL);
3468 r_t->domain_guid = domain_guid;
3470 r_t->ptr_site_name = (site_name != NULL);
3471 init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
3473 r_t->flags = flags;
3476 /*******************************************************************
3477 Reads or writes an NET_Q_DSR_GETDCNAME structure.
3478 ********************************************************************/
3480 BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
3481 prs_struct *ps, int depth)
3483 if (r_t == NULL)
3484 return False;
3486 prs_debug(ps, depth, desc, "net_io_q_dsr_getdcname");
3487 depth++;
3489 if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3490 return False;
3492 if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3493 r_t->ptr_server_unc, ps, depth))
3494 return False;
3496 if (!prs_align(ps))
3497 return False;
3499 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3500 return False;
3502 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3503 r_t->ptr_domain_name, ps, depth))
3504 return False;
3506 if (!prs_align(ps))
3507 return False;
3509 if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3510 return False;
3512 if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3513 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3514 if (r_t->domain_guid == NULL)
3515 return False;
3518 if ((r_t->ptr_domain_guid) &&
3519 (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3520 return False;
3522 if (!prs_align(ps))
3523 return False;
3525 if (!prs_uint32("ptr_site_guid", ps, depth, &r_t->ptr_site_guid))
3526 return False;
3528 if (UNMARSHALLING(ps) && (r_t->ptr_site_guid)) {
3529 r_t->site_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3530 if (r_t->site_guid == NULL)
3531 return False;
3534 if ((r_t->ptr_site_guid) &&
3535 (!smb_io_uuid("site_guid", r_t->site_guid, ps, depth)))
3536 return False;
3538 if (!prs_align(ps))
3539 return False;
3541 if (!prs_uint32("flags", ps, depth, &r_t->flags))
3542 return False;
3544 return True;
3547 /*******************************************************************
3548 Reads or writes an NET_Q_DSR_GETDCNAMEEX structure.
3549 ********************************************************************/
3551 BOOL net_io_q_dsr_getdcnameex(const char *desc, NET_Q_DSR_GETDCNAMEEX *r_t,
3552 prs_struct *ps, int depth)
3554 if (r_t == NULL)
3555 return False;
3557 prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex");
3558 depth++;
3560 if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3561 return False;
3563 if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3564 r_t->ptr_server_unc, ps, depth))
3565 return False;
3567 if (!prs_align(ps))
3568 return False;
3570 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3571 return False;
3573 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3574 r_t->ptr_domain_name, ps, depth))
3575 return False;
3577 if (!prs_align(ps))
3578 return False;
3580 if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3581 return False;
3583 if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3584 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3585 if (r_t->domain_guid == NULL)
3586 return False;
3589 if ((r_t->ptr_domain_guid) &&
3590 (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3591 return False;
3593 if (!prs_align(ps))
3594 return False;
3596 if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3597 return False;
3599 if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3600 r_t->ptr_site_name, ps, depth))
3601 return False;
3603 if (!prs_align(ps))
3604 return False;
3606 if (!prs_uint32("flags", ps, depth, &r_t->flags))
3607 return False;
3609 return True;
3612 /*******************************************************************
3613 Reads or writes an NET_Q_DSR_GETDCNAMEEX2 structure.
3614 ********************************************************************/
3616 BOOL net_io_q_dsr_getdcnameex2(const char *desc, NET_Q_DSR_GETDCNAMEEX2 *r_t,
3617 prs_struct *ps, int depth)
3619 if (r_t == NULL)
3620 return False;
3622 prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex2");
3623 depth++;
3625 if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3626 return False;
3628 if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3629 r_t->ptr_server_unc, ps, depth))
3630 return False;
3632 if (!prs_align(ps))
3633 return False;
3635 if (!prs_uint32("ptr_client_account", ps, depth, &r_t->ptr_client_account))
3636 return False;
3638 if (!smb_io_unistr2("client_account", &r_t->uni_client_account,
3639 r_t->ptr_client_account, ps, depth))
3640 return False;
3642 if (!prs_align(ps))
3643 return False;
3645 if (!prs_uint32("mask", ps, depth, &r_t->mask))
3646 return False;
3648 if (!prs_align(ps))
3649 return False;
3651 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3652 return False;
3654 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3655 r_t->ptr_domain_name, ps, depth))
3656 return False;
3658 if (!prs_align(ps))
3659 return False;
3661 if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3662 return False;
3664 if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3665 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3666 if (r_t->domain_guid == NULL)
3667 return False;
3670 if ((r_t->ptr_domain_guid) &&
3671 (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3672 return False;
3674 if (!prs_align(ps))
3675 return False;
3677 if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3678 return False;
3680 if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3681 r_t->ptr_site_name, ps, depth))
3682 return False;
3684 if (!prs_align(ps))
3685 return False;
3687 if (!prs_uint32("flags", ps, depth, &r_t->flags))
3688 return False;
3690 return True;
3695 /*******************************************************************
3696 Inits a NET_R_DSR_GETDCNAME structure.
3697 ********************************************************************/
3698 void init_net_r_dsr_getdcname(NET_R_DSR_GETDCNAME *r_t, const char *dc_unc,
3699 const char *dc_address, int32 dc_address_type,
3700 struct GUID domain_guid, const char *domain_name,
3701 const char *forest_name, uint32 dc_flags,
3702 const char *dc_site_name,
3703 const char *client_site_name)
3705 DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3707 r_t->ptr_dc_unc = (dc_unc != NULL);
3708 init_unistr2(&r_t->uni_dc_unc, dc_unc, UNI_STR_TERMINATE);
3710 r_t->ptr_dc_address = (dc_address != NULL);
3711 init_unistr2(&r_t->uni_dc_address, dc_address, UNI_STR_TERMINATE);
3713 r_t->dc_address_type = dc_address_type;
3714 r_t->domain_guid = domain_guid;
3716 r_t->ptr_domain_name = (domain_name != NULL);
3717 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3719 r_t->ptr_forest_name = (forest_name != NULL);
3720 init_unistr2(&r_t->uni_forest_name, forest_name, UNI_STR_TERMINATE);
3722 r_t->dc_flags = dc_flags;
3724 r_t->ptr_dc_site_name = (dc_site_name != NULL);
3725 init_unistr2(&r_t->uni_dc_site_name, dc_site_name, UNI_STR_TERMINATE);
3727 r_t->ptr_client_site_name = (client_site_name != NULL);
3728 init_unistr2(&r_t->uni_client_site_name, client_site_name,
3729 UNI_STR_TERMINATE);
3732 /*******************************************************************
3733 Reads or writes an NET_R_DSR_GETDCNAME structure.
3734 ********************************************************************/
3736 BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t,
3737 prs_struct *ps, int depth)
3739 uint32 info_ptr = 1;
3741 if (r_t == NULL)
3742 return False;
3744 prs_debug(ps, depth, desc, "net_io_r_dsr_getdcname");
3745 depth++;
3747 /* The reply contains *just* an info struct, this is the ptr to it */
3748 if (!prs_uint32("info_ptr", ps, depth, &info_ptr))
3749 return False;
3751 if (info_ptr == 0)
3752 return False;
3754 if (!prs_uint32("ptr_dc_unc", ps, depth, &r_t->ptr_dc_unc))
3755 return False;
3757 if (!prs_uint32("ptr_dc_address", ps, depth, &r_t->ptr_dc_address))
3758 return False;
3760 if (!prs_int32("dc_address_type", ps, depth, &r_t->dc_address_type))
3761 return False;
3763 if (!smb_io_uuid("domain_guid", &r_t->domain_guid, ps, depth))
3764 return False;
3766 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3767 return False;
3769 if (!prs_uint32("ptr_forest_name", ps, depth, &r_t->ptr_forest_name))
3770 return False;
3772 if (!prs_uint32("dc_flags", ps, depth, &r_t->dc_flags))
3773 return False;
3775 if (!prs_uint32("ptr_dc_site_name", ps, depth, &r_t->ptr_dc_site_name))
3776 return False;
3778 if (!prs_uint32("ptr_client_site_name", ps, depth,
3779 &r_t->ptr_client_site_name))
3780 return False;
3782 if (!prs_align(ps))
3783 return False;
3785 if (!smb_io_unistr2("dc_unc", &r_t->uni_dc_unc,
3786 r_t->ptr_dc_unc, ps, depth))
3787 return False;
3789 if (!prs_align(ps))
3790 return False;
3792 if (!smb_io_unistr2("dc_address", &r_t->uni_dc_address,
3793 r_t->ptr_dc_address, ps, depth))
3794 return False;
3796 if (!prs_align(ps))
3797 return False;
3799 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3800 r_t->ptr_domain_name, ps, depth))
3801 return False;
3803 if (!prs_align(ps))
3804 return False;
3806 if (!smb_io_unistr2("forest_name", &r_t->uni_forest_name,
3807 r_t->ptr_forest_name, ps, depth))
3808 return False;
3810 if (!prs_align(ps))
3811 return False;
3813 if (!smb_io_unistr2("dc_site_name", &r_t->uni_dc_site_name,
3814 r_t->ptr_dc_site_name, ps, depth))
3815 return False;
3817 if (!prs_align(ps))
3818 return False;
3820 if (!smb_io_unistr2("client_site_name", &r_t->uni_client_site_name,
3821 r_t->ptr_client_site_name, ps, depth))
3822 return False;
3824 if (!prs_align(ps))
3825 return False;
3827 if (!prs_werror("result", ps, depth, &r_t->result))
3828 return False;
3830 return True;
3833 /*******************************************************************
3834 Inits a NET_Q_DSR_GETSITENAME structure.
3835 ********************************************************************/
3837 void init_net_q_dsr_getsitename(NET_Q_DSR_GETSITENAME *r_t, const char *computer_name)
3839 DEBUG(5, ("init_net_q_dsr_getsitename\n"));
3841 r_t->ptr_computer_name = (computer_name != NULL);
3842 init_unistr2(&r_t->uni_computer_name, computer_name, UNI_STR_TERMINATE);
3845 /*******************************************************************
3846 Reads or writes an NET_Q_DSR_GETSITENAME structure.
3847 ********************************************************************/
3849 BOOL net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
3850 prs_struct *ps, int depth)
3852 if (r_t == NULL)
3853 return False;
3855 prs_debug(ps, depth, desc, "net_io_q_dsr_getsitename");
3856 depth++;
3858 if (!prs_uint32("ptr_computer_name", ps, depth, &r_t->ptr_computer_name))
3859 return False;
3861 if (!smb_io_unistr2("computer_name", &r_t->uni_computer_name,
3862 r_t->ptr_computer_name, ps, depth))
3863 return False;
3865 if (!prs_align(ps))
3866 return False;
3868 return True;
3871 /*******************************************************************
3872 Reads or writes an NET_R_DSR_GETSITENAME structure.
3873 ********************************************************************/
3875 BOOL net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t,
3876 prs_struct *ps, int depth)
3878 if (r_t == NULL)
3879 return False;
3881 prs_debug(ps, depth, desc, "net_io_r_dsr_getsitename");
3882 depth++;
3884 if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3885 return False;
3887 if (!prs_align(ps))
3888 return False;
3890 if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3891 r_t->ptr_site_name, ps, depth))
3892 return False;
3894 if (!prs_align(ps))
3895 return False;
3897 if (!prs_werror("result", ps, depth, &r_t->result))
3898 return False;
3900 return True;