r23041: Remainder of fix for 4630: fix special case of unix_to_nt_time() for
[Samba/nascimento.git] / source3 / rpc_parse / parse_net.c
blob4c2f67683149ffe81a83ae76c851ac1be6c0ec0d
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_GETDCNAME structure.
484 ********************************************************************/
485 void init_net_q_getdcname(NET_Q_GETDCNAME *r_t, const char *logon_server,
486 const char *domainname)
488 DEBUG(5,("init_q_getdcname\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_GETDCNAME structure.
498 ********************************************************************/
500 BOOL net_io_q_getdcname(const char *desc, NET_Q_GETDCNAME *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_getdcname");
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_GETDCNAME structure.
532 ********************************************************************/
533 void init_net_r_getdcname(NET_R_GETDCNAME *r_t, const char *dcname)
535 DEBUG(5,("init_r_getdcname\n"));
537 init_unistr2(&r_t->uni_dcname, dcname, UNI_STR_TERMINATE);
540 /*******************************************************************
541 Reads or writes an NET_R_GETDCNAME structure.
542 ********************************************************************/
544 BOOL net_io_r_getdcname(const char *desc, NET_R_GETDCNAME *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_getdcname");
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;
570 /*******************************************************************
571 Inits an NET_R_GETANYDCNAME structure.
572 ********************************************************************/
573 void init_net_q_getanydcname(NET_Q_GETANYDCNAME *r_t, const char *logon_server,
574 const char *domainname)
576 DEBUG(5,("init_q_getanydcname\n"));
578 init_unistr2(&r_t->uni_logon_server, logon_server, UNI_STR_TERMINATE);
579 r_t->ptr_domainname = (domainname != NULL);
580 init_unistr2(&r_t->uni_domainname, domainname, UNI_STR_TERMINATE);
583 /*******************************************************************
584 Reads or writes an NET_Q_GETANYDCNAME structure.
585 ********************************************************************/
587 BOOL net_io_q_getanydcname(const char *desc, NET_Q_GETANYDCNAME *r_t, prs_struct *ps,
588 int depth)
590 if (r_t == NULL)
591 return False;
593 prs_debug(ps, depth, desc, "net_io_q_getanydcname");
594 depth++;
596 if (!smb_io_unistr2("logon_server", &r_t->uni_logon_server,
597 1, ps, depth))
598 return False;
600 if (!prs_align(ps))
601 return False;
603 if (!prs_uint32("ptr_domainname", ps, depth, &r_t->ptr_domainname))
604 return False;
606 if (!smb_io_unistr2("domainname", &r_t->uni_domainname,
607 r_t->ptr_domainname, ps, depth))
608 return False;
610 return True;
614 /*******************************************************************
615 Inits an NET_R_GETANYDCNAME structure.
616 ********************************************************************/
617 void init_net_r_getanydcname(NET_R_GETANYDCNAME *r_t, const char *dcname)
619 DEBUG(5,("init_r_getanydcname\n"));
621 init_unistr2(&r_t->uni_dcname, dcname, UNI_STR_TERMINATE);
624 /*******************************************************************
625 Reads or writes an NET_R_GETANYDCNAME structure.
626 ********************************************************************/
628 BOOL net_io_r_getanydcname(const char *desc, NET_R_GETANYDCNAME *r_t, prs_struct *ps,
629 int depth)
631 if (r_t == NULL)
632 return False;
634 prs_debug(ps, depth, desc, "net_io_r_getanydcname");
635 depth++;
637 if (!prs_uint32("ptr_dcname", ps, depth, &r_t->ptr_dcname))
638 return False;
640 if (!smb_io_unistr2("dcname", &r_t->uni_dcname,
641 r_t->ptr_dcname, ps, depth))
642 return False;
644 if (!prs_align(ps))
645 return False;
647 if (!prs_werror("status", ps, depth, &r_t->status))
648 return False;
650 return True;
653 /*******************************************************************
654 Inits an NET_R_TRUST_DOM_LIST structure.
655 ********************************************************************/
657 void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
658 uint32 num_doms, const char *dom_name)
660 unsigned int i = 0;
662 DEBUG(5,("init_r_trust_dom\n"));
664 for (i = 0; i < MAX_TRUST_DOMS; i++) {
665 r_t->uni_trust_dom_name[i].uni_str_len = 0;
666 r_t->uni_trust_dom_name[i].uni_max_len = 0;
668 if (num_doms > MAX_TRUST_DOMS)
669 num_doms = MAX_TRUST_DOMS;
671 for (i = 0; i < num_doms; i++) {
672 fstring domain_name;
673 fstrcpy(domain_name, dom_name);
674 strupper_m(domain_name);
675 init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, UNI_STR_TERMINATE);
676 /* the use of UNISTR2 here is non-standard. */
677 r_t->uni_trust_dom_name[i].offset = 0x1;
680 r_t->status = NT_STATUS_OK;
683 /*******************************************************************
684 Reads or writes an NET_R_TRUST_DOM_LIST structure.
685 ********************************************************************/
687 BOOL net_io_r_trust_dom(const char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth)
689 uint32 value;
691 if (r_t == NULL)
692 return False;
694 prs_debug(ps, depth, desc, "net_io_r_trust_dom");
695 depth++;
697 /* temporary code to give a valid response */
698 value=2;
699 if(!prs_uint32("status", ps, depth, &value))
700 return False;
702 value=1;
703 if(!prs_uint32("status", ps, depth, &value))
704 return False;
705 value=2;
706 if(!prs_uint32("status", ps, depth, &value))
707 return False;
709 value=0;
710 if(!prs_uint32("status", ps, depth, &value))
711 return False;
713 value=0;
714 if(!prs_uint32("status", ps, depth, &value))
715 return False;
717 /* old non working code */
718 #if 0
719 int i;
721 for (i = 0; i < MAX_TRUST_DOMS; i++) {
722 if (r_t->uni_trust_dom_name[i].uni_str_len == 0)
723 break;
724 if(!smb_io_unistr2("", &r_t->uni_trust_dom_name[i], True, ps, depth))
725 return False;
728 if(!prs_ntstatus("status", ps, depth, &r_t->status))
729 return False;
730 #endif
731 return True;
735 /*******************************************************************
736 Reads or writes an NET_Q_TRUST_DOM_LIST structure.
737 ********************************************************************/
739 BOOL net_io_q_trust_dom(const char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth)
741 if (q_l == NULL)
742 return False;
744 prs_debug(ps, depth, desc, "net_io_q_trust_dom");
745 depth++;
747 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
748 return False;
749 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
750 return False;
752 return True;
755 /*******************************************************************
756 Inits an NET_Q_REQ_CHAL structure.
757 ********************************************************************/
759 void init_q_req_chal(NET_Q_REQ_CHAL *q_c,
760 const char *logon_srv, const char *logon_clnt,
761 const DOM_CHAL *clnt_chal)
763 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
765 q_c->undoc_buffer = 1; /* don't know what this buffer is */
767 init_unistr2(&q_c->uni_logon_srv, logon_srv , UNI_STR_TERMINATE);
768 init_unistr2(&q_c->uni_logon_clnt, logon_clnt, UNI_STR_TERMINATE);
770 memcpy(q_c->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
772 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
775 /*******************************************************************
776 Reads or writes an NET_Q_REQ_CHAL structure.
777 ********************************************************************/
779 BOOL net_io_q_req_chal(const char *desc, NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth)
781 if (q_c == NULL)
782 return False;
784 prs_debug(ps, depth, desc, "net_io_q_req_chal");
785 depth++;
787 if(!prs_align(ps))
788 return False;
790 if(!prs_uint32("undoc_buffer", ps, depth, &q_c->undoc_buffer))
791 return False;
793 if(!smb_io_unistr2("", &q_c->uni_logon_srv, True, ps, depth)) /* logon server unicode string */
794 return False;
795 if(!smb_io_unistr2("", &q_c->uni_logon_clnt, True, ps, depth)) /* logon client unicode string */
796 return False;
798 if(!smb_io_chal("", &q_c->clnt_chal, ps, depth))
799 return False;
801 return True;
804 /*******************************************************************
805 Reads or writes a structure.
806 ********************************************************************/
808 BOOL net_io_r_req_chal(const char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth)
810 if (r_c == NULL)
811 return False;
813 prs_debug(ps, depth, desc, "net_io_r_req_chal");
814 depth++;
816 if(!prs_align(ps))
817 return False;
819 if(!smb_io_chal("", &r_c->srv_chal, ps, depth)) /* server challenge */
820 return False;
822 if(!prs_ntstatus("status", ps, depth, &r_c->status))
823 return False;
825 return True;
829 /*******************************************************************
830 Reads or writes a structure.
831 ********************************************************************/
833 BOOL net_io_q_auth(const char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
835 if (q_a == NULL)
836 return False;
838 prs_debug(ps, depth, desc, "net_io_q_auth");
839 depth++;
841 if(!prs_align(ps))
842 return False;
844 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
845 return False;
846 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
847 return False;
849 return True;
852 /*******************************************************************
853 Reads or writes a structure.
854 ********************************************************************/
856 BOOL net_io_r_auth(const char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
858 if (r_a == NULL)
859 return False;
861 prs_debug(ps, depth, desc, "net_io_r_auth");
862 depth++;
864 if(!prs_align(ps))
865 return False;
867 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
868 return False;
870 if(!prs_ntstatus("status", ps, depth, &r_a->status))
871 return False;
873 return True;
876 /*******************************************************************
877 Inits a NET_Q_AUTH_2 struct.
878 ********************************************************************/
880 void init_q_auth_2(NET_Q_AUTH_2 *q_a,
881 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
882 const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
884 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
886 init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
887 memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
888 q_a->clnt_flgs.neg_flags = clnt_flgs;
890 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
893 /*******************************************************************
894 Reads or writes a structure.
895 ********************************************************************/
897 BOOL net_io_q_auth_2(const char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth)
899 if (q_a == NULL)
900 return False;
902 prs_debug(ps, depth, desc, "net_io_q_auth_2");
903 depth++;
905 if(!prs_align(ps))
906 return False;
908 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
909 return False;
910 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
911 return False;
912 if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
913 return False;
915 return True;
918 /*******************************************************************
919 Reads or writes a structure.
920 ********************************************************************/
922 BOOL net_io_r_auth_2(const char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth)
924 if (r_a == NULL)
925 return False;
927 prs_debug(ps, depth, desc, "net_io_r_auth_2");
928 depth++;
930 if(!prs_align(ps))
931 return False;
933 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
934 return False;
935 if(!net_io_neg_flags("", &r_a->srv_flgs, ps, depth))
936 return False;
938 if(!prs_ntstatus("status", ps, depth, &r_a->status))
939 return False;
941 return True;
944 /*******************************************************************
945 Inits a NET_Q_AUTH_3 struct.
946 ********************************************************************/
948 void init_q_auth_3(NET_Q_AUTH_3 *q_a,
949 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
950 const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
952 DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
954 init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
955 memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
956 q_a->clnt_flgs.neg_flags = clnt_flgs;
958 DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
961 /*******************************************************************
962 Reads or writes a structure.
963 ********************************************************************/
965 BOOL net_io_q_auth_3(const char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int depth)
967 if (q_a == NULL)
968 return False;
970 prs_debug(ps, depth, desc, "net_io_q_auth_3");
971 depth++;
973 if(!prs_align(ps))
974 return False;
976 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
977 return False;
978 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
979 return False;
980 if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
981 return False;
983 return True;
986 /*******************************************************************
987 Reads or writes a structure.
988 ********************************************************************/
990 BOOL net_io_r_auth_3(const char *desc, NET_R_AUTH_3 *r_a, prs_struct *ps, int depth)
992 if (r_a == NULL)
993 return False;
995 prs_debug(ps, depth, desc, "net_io_r_auth_3");
996 depth++;
998 if(!prs_align(ps))
999 return False;
1001 if(!smb_io_chal("srv_chal", &r_a->srv_chal, ps, depth)) /* server challenge */
1002 return False;
1003 if(!net_io_neg_flags("srv_flgs", &r_a->srv_flgs, ps, depth))
1004 return False;
1005 if (!prs_uint32("unknown", ps, depth, &r_a->unknown))
1006 return False;
1008 if(!prs_ntstatus("status", ps, depth, &r_a->status))
1009 return False;
1011 return True;
1015 /*******************************************************************
1016 Inits a NET_Q_SRV_PWSET.
1017 ********************************************************************/
1019 void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s,
1020 const char *logon_srv, const char *sess_key, const char *acct_name,
1021 uint16 sec_chan, const char *comp_name,
1022 DOM_CRED *cred, const uchar hashed_mach_pwd[16])
1024 unsigned char nt_cypher[16];
1026 DEBUG(5,("init_q_srv_pwset\n"));
1028 /* Process the new password. */
1029 cred_hash3( nt_cypher, hashed_mach_pwd, (const unsigned char *)sess_key, 1);
1031 init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
1033 memcpy(q_s->pwd, nt_cypher, sizeof(q_s->pwd));
1036 /*******************************************************************
1037 Reads or writes a structure.
1038 ********************************************************************/
1040 BOOL net_io_q_srv_pwset(const char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth)
1042 if (q_s == NULL)
1043 return False;
1045 prs_debug(ps, depth, desc, "net_io_q_srv_pwset");
1046 depth++;
1048 if(!prs_align(ps))
1049 return False;
1051 if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */
1052 return False;
1053 if(!prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16)) /* new password - undocumented */
1054 return False;
1056 return True;
1059 /*******************************************************************
1060 Reads or writes a structure.
1061 ********************************************************************/
1063 BOOL net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth)
1065 if (r_s == NULL)
1066 return False;
1068 prs_debug(ps, depth, desc, "net_io_r_srv_pwset");
1069 depth++;
1071 if(!prs_align(ps))
1072 return False;
1074 if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */
1075 return False;
1077 if(!prs_ntstatus("status", ps, depth, &r_s->status))
1078 return False;
1080 return True;
1083 /*************************************************************************
1084 Init DOM_SID2 array from a string containing multiple sids
1085 *************************************************************************/
1087 static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids)
1089 const char *ptr;
1090 pstring s2;
1091 int count = 0;
1093 DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
1095 *ppsids = NULL;
1097 if(sids_str) {
1098 int number;
1099 DOM_SID2 *sids;
1101 /* Count the number of valid SIDs. */
1102 for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1103 DOM_SID tmpsid;
1104 if (string_to_sid(&tmpsid, s2))
1105 count++;
1108 /* Now allocate space for them. */
1109 if (count) {
1110 *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
1111 if (*ppsids == NULL)
1112 return 0;
1113 } else {
1114 *ppsids = NULL;
1117 sids = *ppsids;
1119 for (number = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
1120 DOM_SID tmpsid;
1121 if (string_to_sid(&tmpsid, s2)) {
1122 /* count only valid sids */
1123 init_dom_sid2(&sids[number], &tmpsid);
1124 number++;
1129 return count;
1132 /*******************************************************************
1133 Inits a NET_ID_INFO_1 structure.
1134 ********************************************************************/
1136 void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
1137 uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high,
1138 const char *user_name, const char *wksta_name,
1139 const char *sess_key,
1140 unsigned char lm_cypher[16], unsigned char nt_cypher[16])
1142 unsigned char lm_owf[16];
1143 unsigned char nt_owf[16];
1145 DEBUG(5,("init_id_info1: %d\n", __LINE__));
1147 id->ptr_id_info1 = 1;
1149 id->param_ctrl = param_ctrl;
1150 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1153 if (lm_cypher && nt_cypher) {
1154 unsigned char key[16];
1155 #ifdef DEBUG_PASSWORD
1156 DEBUG(100,("lm cypher:"));
1157 dump_data(100, lm_cypher, 16);
1159 DEBUG(100,("nt cypher:"));
1160 dump_data(100, nt_cypher, 16);
1161 #endif
1163 memset(key, 0, 16);
1164 memcpy(key, sess_key, 8);
1166 memcpy(lm_owf, lm_cypher, 16);
1167 SamOEMhash(lm_owf, key, 16);
1168 memcpy(nt_owf, nt_cypher, 16);
1169 SamOEMhash(nt_owf, key, 16);
1171 #ifdef DEBUG_PASSWORD
1172 DEBUG(100,("encrypt of lm owf password:"));
1173 dump_data(100, lm_owf, 16);
1175 DEBUG(100,("encrypt of nt owf password:"));
1176 dump_data(100, nt_owf, 16);
1177 #endif
1178 /* set up pointers to cypher blocks */
1179 lm_cypher = lm_owf;
1180 nt_cypher = nt_owf;
1183 init_owf_info(&id->lm_owf, lm_cypher);
1184 init_owf_info(&id->nt_owf, nt_cypher);
1186 init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1187 init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1188 init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1189 init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1190 init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1191 init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1194 /*******************************************************************
1195 Reads or writes an NET_ID_INFO_1 structure.
1196 ********************************************************************/
1198 static BOOL net_io_id_info1(const char *desc, NET_ID_INFO_1 *id, prs_struct *ps, int depth)
1200 if (id == NULL)
1201 return False;
1203 prs_debug(ps, depth, desc, "net_io_id_info1");
1204 depth++;
1206 if(!prs_align(ps))
1207 return False;
1209 if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1))
1210 return False;
1212 if (id->ptr_id_info1 != 0) {
1213 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1214 return False;
1216 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1217 return False;
1218 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1219 return False;
1221 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1222 return False;
1223 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1224 return False;
1226 if(!smb_io_owf_info("", &id->lm_owf, ps, depth))
1227 return False;
1228 if(!smb_io_owf_info("", &id->nt_owf, ps, depth))
1229 return False;
1231 if(!smb_io_unistr2("unistr2", &id->uni_domain_name,
1232 id->hdr_domain_name.buffer, ps, depth))
1233 return False;
1234 if(!smb_io_unistr2("unistr2", &id->uni_user_name,
1235 id->hdr_user_name.buffer, ps, depth))
1236 return False;
1237 if(!smb_io_unistr2("unistr2", &id->uni_wksta_name,
1238 id->hdr_wksta_name.buffer, ps, depth))
1239 return False;
1242 return True;
1245 /*******************************************************************
1246 Inits a NET_ID_INFO_2 structure.
1248 This is a network logon packet. The log_id parameters
1249 are what an NT server would generate for LUID once the
1250 user is logged on. I don't think we care about them.
1252 Note that this has no access to the NT and LM hashed passwords,
1253 so it forwards the challenge, and the NT and LM responses (24
1254 bytes each) over the secure channel to the Domain controller
1255 for it to say yea or nay. This is the preferred method of
1256 checking for a logon as it doesn't export the password
1257 hashes to anyone who has compromised the secure channel. JRA.
1258 ********************************************************************/
1260 void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
1261 uint32 param_ctrl,
1262 uint32 log_id_low, uint32 log_id_high,
1263 const char *user_name, const char *wksta_name,
1264 const uchar lm_challenge[8],
1265 const uchar * lm_chal_resp, size_t lm_chal_resp_len,
1266 const uchar * nt_chal_resp, size_t nt_chal_resp_len)
1269 DEBUG(5,("init_id_info2: %d\n", __LINE__));
1271 id->ptr_id_info2 = 1;
1273 id->param_ctrl = param_ctrl;
1274 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1276 memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));
1277 init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);
1278 init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);
1280 init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
1281 init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
1282 init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
1283 init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
1284 init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
1285 init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
1287 init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);
1288 init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);
1292 /*******************************************************************
1293 Reads or writes an NET_ID_INFO_2 structure.
1294 ********************************************************************/
1296 static BOOL net_io_id_info2(const char *desc, NET_ID_INFO_2 *id, prs_struct *ps, int depth)
1298 if (id == NULL)
1299 return False;
1301 prs_debug(ps, depth, desc, "net_io_id_info2");
1302 depth++;
1304 if(!prs_align(ps))
1305 return False;
1307 if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2))
1308 return False;
1310 if (id->ptr_id_info2 != 0) {
1311 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1312 return False;
1314 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1315 return False;
1316 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1317 return False;
1319 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1320 return False;
1321 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1322 return False;
1324 if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */
1325 return False;
1327 if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth))
1328 return False;
1329 if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth))
1330 return False;
1332 if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name,
1333 id->hdr_domain_name.buffer, ps, depth))
1334 return False;
1335 if(!smb_io_unistr2("uni_user_name ", &id->uni_user_name,
1336 id->hdr_user_name.buffer, ps, depth))
1337 return False;
1338 if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name,
1339 id->hdr_wksta_name.buffer, ps, depth))
1340 return False;
1341 if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp,
1342 id->hdr_nt_chal_resp.buffer, ps, depth))
1343 return False;
1344 if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp,
1345 id->hdr_lm_chal_resp.buffer, ps, depth))
1346 return False;
1349 return True;
1353 /*******************************************************************
1354 Inits a DOM_SAM_INFO structure.
1355 ********************************************************************/
1357 void init_sam_info(DOM_SAM_INFO *sam,
1358 const char *logon_srv, const char *comp_name,
1359 DOM_CRED *clnt_cred,
1360 DOM_CRED *rtn_cred, uint16 logon_level,
1361 NET_ID_INFO_CTR *ctr)
1363 DEBUG(5,("init_sam_info: %d\n", __LINE__));
1365 init_clnt_info2(&sam->client, logon_srv, comp_name, clnt_cred);
1367 if (rtn_cred != NULL) {
1368 sam->ptr_rtn_cred = 1;
1369 memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred));
1370 } else {
1371 sam->ptr_rtn_cred = 0;
1374 sam->logon_level = logon_level;
1375 sam->ctr = ctr;
1378 /*******************************************************************
1379 Reads or writes a DOM_SAM_INFO structure.
1380 ********************************************************************/
1382 static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1384 NET_ID_INFO_CTR *ctr = *pp_ctr;
1386 prs_debug(ps, depth, desc, "smb_io_sam_info_ctr");
1387 depth++;
1389 if (UNMARSHALLING(ps)) {
1390 ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
1391 if (ctr == NULL)
1392 return False;
1395 if (ctr == NULL)
1396 return False;
1398 /* don't 4-byte align here! */
1400 if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value))
1401 return False;
1403 switch (ctr->switch_value) {
1404 case 1:
1405 if(!net_io_id_info1("", &ctr->auth.id1, ps, depth))
1406 return False;
1407 break;
1408 case 2:
1409 if(!net_io_id_info2("", &ctr->auth.id2, ps, depth))
1410 return False;
1411 break;
1412 default:
1413 /* PANIC! */
1414 DEBUG(4,("smb_io_sam_info_ctr: unknown switch_value!\n"));
1415 break;
1418 return True;
1421 /*******************************************************************
1422 Reads or writes a DOM_SAM_INFO structure.
1423 ********************************************************************/
1425 static BOOL smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
1427 if (sam == NULL)
1428 return False;
1430 prs_debug(ps, depth, desc, "smb_io_sam_info");
1431 depth++;
1433 if(!prs_align(ps))
1434 return False;
1436 if(!smb_io_clnt_info2("", &sam->client, ps, depth))
1437 return False;
1439 if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred))
1440 return False;
1441 if (sam->ptr_rtn_cred) {
1442 if(!smb_io_cred("", &sam->rtn_cred, ps, depth))
1443 return False;
1446 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1447 return False;
1449 if (sam->logon_level != 0) {
1450 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1451 return False;
1454 return True;
1457 /*******************************************************************
1458 Reads or writes a DOM_SAM_INFO_EX structure.
1459 ********************************************************************/
1461 static BOOL smb_io_sam_info_ex(const char *desc, DOM_SAM_INFO_EX *sam, prs_struct *ps, int depth)
1463 if (sam == NULL)
1464 return False;
1466 prs_debug(ps, depth, desc, "smb_io_sam_info_ex");
1467 depth++;
1469 if(!prs_align(ps))
1470 return False;
1472 if(!smb_io_clnt_srv("", &sam->client, ps, depth))
1473 return False;
1475 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1476 return False;
1478 if (sam->logon_level != 0) {
1479 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1480 return False;
1483 return True;
1486 /*************************************************************************
1487 Inits a NET_USER_INFO_3 structure.
1489 This is a network logon reply packet, and contains much information about
1490 the user. This information is passed as a (very long) paramater list
1491 to avoid having to link in the PASSDB code to every program that deals
1492 with this file.
1493 *************************************************************************/
1495 void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
1496 uint32 user_rid,
1497 uint32 group_rid,
1499 const char* user_name,
1500 const char* full_name,
1501 const char* home_dir,
1502 const char* dir_drive,
1503 const char* logon_script,
1504 const char* profile_path,
1506 time_t unix_logon_time,
1507 time_t unix_logoff_time,
1508 time_t unix_kickoff_time,
1509 time_t unix_pass_last_set_time,
1510 time_t unix_pass_can_change_time,
1511 time_t unix_pass_must_change_time,
1513 uint16 logon_count, uint16 bad_pw_count,
1514 uint32 num_groups, const DOM_GID *gids,
1515 uint32 user_flgs, uint32 acct_flags,
1516 uchar user_session_key[16],
1517 uchar lm_session_key[16],
1518 const char *logon_srv, const char *logon_dom,
1519 const DOM_SID *dom_sid)
1521 /* only cope with one "other" sid, right now. */
1522 /* need to count the number of space-delimited sids */
1523 unsigned int i;
1524 int num_other_sids = 0;
1526 NTTIME logon_time, logoff_time, kickoff_time,
1527 pass_last_set_time, pass_can_change_time,
1528 pass_must_change_time;
1530 ZERO_STRUCTP(usr);
1532 usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */
1534 /* Create NTTIME structs */
1535 unix_to_nt_time (&logon_time, unix_logon_time);
1536 unix_to_nt_time (&logoff_time, unix_logoff_time);
1537 unix_to_nt_time (&kickoff_time, unix_kickoff_time);
1538 unix_to_nt_time (&pass_last_set_time, unix_pass_last_set_time);
1539 unix_to_nt_time (&pass_can_change_time, unix_pass_can_change_time);
1540 unix_to_nt_time (&pass_must_change_time, unix_pass_must_change_time);
1542 usr->logon_time = logon_time;
1543 usr->logoff_time = logoff_time;
1544 usr->kickoff_time = kickoff_time;
1545 usr->pass_last_set_time = pass_last_set_time;
1546 usr->pass_can_change_time = pass_can_change_time;
1547 usr->pass_must_change_time = pass_must_change_time;
1549 usr->logon_count = logon_count;
1550 usr->bad_pw_count = bad_pw_count;
1552 usr->user_rid = user_rid;
1553 usr->group_rid = group_rid;
1554 usr->num_groups = num_groups;
1556 usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */
1557 usr->user_flgs = user_flgs;
1558 usr->acct_flags = acct_flags;
1560 if (user_session_key != NULL)
1561 memcpy(usr->user_sess_key, user_session_key, sizeof(usr->user_sess_key));
1562 else
1563 memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key));
1565 usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */
1567 memset((char *)usr->lm_sess_key, '\0', sizeof(usr->lm_sess_key));
1569 for (i=0; i<7; i++) {
1570 memset(&usr->unknown[i], '\0', sizeof(usr->unknown));
1573 if (lm_session_key != NULL) {
1574 memcpy(usr->lm_sess_key, lm_session_key, sizeof(usr->lm_sess_key));
1577 num_other_sids = init_dom_sid2s(ctx, NULL, &usr->other_sids);
1579 usr->num_other_sids = num_other_sids;
1580 usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0;
1582 init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
1583 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
1584 init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
1585 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
1586 init_unistr2(&usr->uni_logon_script, logon_script, UNI_FLAGS_NONE);
1587 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
1588 init_unistr2(&usr->uni_profile_path, profile_path, UNI_FLAGS_NONE);
1589 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
1590 init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
1591 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
1592 init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
1593 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
1595 usr->num_groups2 = num_groups;
1597 if (num_groups) {
1598 usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
1599 if (usr->gids == NULL)
1600 return;
1601 } else {
1602 usr->gids = NULL;
1605 for (i = 0; i < num_groups; i++)
1606 usr->gids[i] = gids[i];
1608 init_unistr2(&usr->uni_logon_srv, logon_srv, UNI_FLAGS_NONE);
1609 init_uni_hdr(&usr->hdr_logon_srv, &usr->uni_logon_srv);
1610 init_unistr2(&usr->uni_logon_dom, logon_dom, UNI_FLAGS_NONE);
1611 init_uni_hdr(&usr->hdr_logon_dom, &usr->uni_logon_dom);
1613 init_dom_sid2(&usr->dom_sid, dom_sid);
1614 /* "other" sids are set up above */
1617 static void dump_acct_flags(uint32 acct_flags) {
1619 int lvl = 10;
1620 DEBUG(lvl,("dump_acct_flags\n"));
1621 if (acct_flags & ACB_NORMAL) {
1622 DEBUGADD(lvl,("\taccount has ACB_NORMAL\n"));
1624 if (acct_flags & ACB_PWNOEXP) {
1625 DEBUGADD(lvl,("\taccount has ACB_PWNOEXP\n"));
1627 if (acct_flags & ACB_ENC_TXT_PWD_ALLOWED) {
1628 DEBUGADD(lvl,("\taccount has ACB_ENC_TXT_PWD_ALLOWED\n"));
1630 if (acct_flags & ACB_NOT_DELEGATED) {
1631 DEBUGADD(lvl,("\taccount has ACB_NOT_DELEGATED\n"));
1633 if (acct_flags & ACB_USE_DES_KEY_ONLY) {
1634 DEBUGADD(lvl,("\taccount has ACB_USE_DES_KEY_ONLY set, sig verify wont work\n"));
1636 if (acct_flags & ACB_NO_AUTH_DATA_REQD) {
1637 DEBUGADD(lvl,("\taccount has ACB_NO_AUTH_DATA_REQD set\n"));
1639 if (acct_flags & ACB_PWEXPIRED) {
1640 DEBUGADD(lvl,("\taccount has ACB_PWEXPIRED set\n"));
1644 static void dump_user_flgs(uint32 user_flags) {
1646 int lvl = 10;
1647 DEBUG(lvl,("dump_user_flgs\n"));
1648 if (user_flags & LOGON_EXTRA_SIDS) {
1649 DEBUGADD(lvl,("\taccount has LOGON_EXTRA_SIDS\n"));
1651 if (user_flags & LOGON_RESOURCE_GROUPS) {
1652 DEBUGADD(lvl,("\taccount has LOGON_RESOURCE_GROUPS\n"));
1654 if (user_flags & LOGON_NTLMV2_ENABLED) {
1655 DEBUGADD(lvl,("\taccount has LOGON_NTLMV2_ENABLED\n"));
1657 if (user_flags & LOGON_CACHED_ACCOUNT) {
1658 DEBUGADD(lvl,("\taccount has LOGON_CACHED_ACCOUNT\n"));
1660 if (user_flags & LOGON_PROFILE_PATH_RETURNED) {
1661 DEBUGADD(lvl,("\taccount has LOGON_PROFILE_PATH_RETURNED\n"));
1663 if (user_flags & LOGON_SERVER_TRUST_ACCOUNT) {
1664 DEBUGADD(lvl,("\taccount has LOGON_SERVER_TRUST_ACCOUNT\n"));
1670 /*******************************************************************
1671 This code has been modified to cope with a NET_USER_INFO_2 - which is
1672 exactly the same as a NET_USER_INFO_3, minus the other sids parameters.
1673 We use validation level to determine if we're marshalling a info 2 or
1674 INFO_3 - be we always return an INFO_3. Based on code donated by Marc
1675 Jacobsen at HP. JRA.
1676 ********************************************************************/
1678 BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
1679 int depth, uint16 validation_level, BOOL kerb_validation_level)
1681 unsigned int i;
1683 if (usr == NULL)
1684 return False;
1686 prs_debug(ps, depth, desc, "net_io_user_info3");
1687 depth++;
1689 if (UNMARSHALLING(ps))
1690 ZERO_STRUCTP(usr);
1692 if(!prs_align(ps))
1693 return False;
1695 if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info))
1696 return False;
1698 if (usr->ptr_user_info == 0)
1699 return True;
1701 if(!smb_io_time("logon time", &usr->logon_time, ps, depth)) /* logon time */
1702 return False;
1703 if(!smb_io_time("logoff time", &usr->logoff_time, ps, depth)) /* logoff time */
1704 return False;
1705 if(!smb_io_time("kickoff time", &usr->kickoff_time, ps, depth)) /* kickoff time */
1706 return False;
1707 if(!smb_io_time("last set time", &usr->pass_last_set_time, ps, depth)) /* password last set time */
1708 return False;
1709 if(!smb_io_time("can change time", &usr->pass_can_change_time , ps, depth)) /* password can change time */
1710 return False;
1711 if(!smb_io_time("must change time", &usr->pass_must_change_time, ps, depth)) /* password must change time */
1712 return False;
1714 if(!smb_io_unihdr("hdr_user_name", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
1715 return False;
1716 if(!smb_io_unihdr("hdr_full_name", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
1717 return False;
1718 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
1719 return False;
1720 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
1721 return False;
1722 if(!smb_io_unihdr("hdr_home_dir", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
1723 return False;
1724 if(!smb_io_unihdr("hdr_dir_drive", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */
1725 return False;
1727 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count)) /* logon count */
1728 return False;
1729 if(!prs_uint16("bad_pw_count ", ps, depth, &usr->bad_pw_count)) /* bad password count */
1730 return False;
1732 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User RID */
1733 return False;
1734 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group RID */
1735 return False;
1736 if(!prs_uint32("num_groups ", ps, depth, &usr->num_groups)) /* num groups */
1737 return False;
1738 if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */
1739 return False;
1740 if(!prs_uint32("user_flgs ", ps, depth, &usr->user_flgs)) /* user flags */
1741 return False;
1742 dump_user_flgs(usr->user_flgs);
1743 if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* user session key */
1744 return False;
1746 if(!smb_io_unihdr("hdr_logon_srv", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */
1747 return False;
1748 if(!smb_io_unihdr("hdr_logon_dom", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */
1749 return False;
1751 if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */
1752 return False;
1754 if(!prs_uint8s(False, "lm_sess_key", ps, depth, usr->lm_sess_key, 8)) /* lm session key */
1755 return False;
1757 if(!prs_uint32("acct_flags ", ps, depth, &usr->acct_flags)) /* Account flags */
1758 return False;
1759 dump_acct_flags(usr->acct_flags);
1760 for (i = 0; i < 7; i++)
1762 if (!prs_uint32("unkown", ps, depth, &usr->unknown[i])) /* unknown */
1763 return False;
1766 if (validation_level == 3) {
1767 if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */
1768 return False;
1769 if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */
1770 return False;
1771 } else {
1772 if (UNMARSHALLING(ps)) {
1773 usr->num_other_sids = 0;
1774 usr->buffer_other_sids = 0;
1778 /* get kerb validation info (not really part of user_info_3) - Guenther */
1780 if (kerb_validation_level) {
1782 if(!prs_uint32("ptr_res_group_dom_sid", ps, depth, &usr->ptr_res_group_dom_sid))
1783 return False;
1784 if(!prs_uint32("res_group_count", ps, depth, &usr->res_group_count))
1785 return False;
1786 if(!prs_uint32("ptr_res_groups", ps, depth, &usr->ptr_res_groups))
1787 return False;
1790 if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
1791 return False;
1792 if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
1793 return False;
1794 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
1795 return False;
1796 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
1797 return False;
1798 if(!smb_io_unistr2("uni_home_dir", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
1799 return False;
1800 if(!smb_io_unistr2("uni_dir_drive", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
1801 return False;
1803 if(!prs_align(ps))
1804 return False;
1806 if(!prs_uint32("num_groups2 ", ps, depth, &usr->num_groups2)) /* num groups2 */
1807 return False;
1809 if (usr->num_groups != usr->num_groups2) {
1810 DEBUG(3,("net_io_user_info3: num_groups mismatch! (%d != %d)\n",
1811 usr->num_groups, usr->num_groups2));
1812 return False;
1815 if (UNMARSHALLING(ps)) {
1816 usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups);
1817 if (usr->gids == NULL)
1818 return False;
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 usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
1852 usr->other_sids_attrib =
1853 PRS_ALLOC_MEM(ps, uint32, usr->num_other_sids);
1855 if ((num_other_sids != 0) &&
1856 ((usr->other_sids == NULL) ||
1857 (usr->other_sids_attrib == NULL)))
1858 return False;
1861 /* First the pointers to the SIDS and attributes */
1863 depth++;
1865 for (i=0; i<usr->num_other_sids; i++) {
1866 uint32 ptr = 1;
1868 if (!prs_uint32("sid_ptr", ps, depth, &ptr))
1869 return False;
1871 if (UNMARSHALLING(ps) && (ptr == 0))
1872 return False;
1874 if (!prs_uint32("attribute", ps, depth,
1875 &usr->other_sids_attrib[i]))
1876 return False;
1879 for (i = 0; i < usr->num_other_sids; i++) {
1880 if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */
1881 return False;
1884 depth--;
1887 return True;
1890 /*******************************************************************
1891 Reads or writes a structure.
1892 ********************************************************************/
1894 BOOL net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
1896 if (q_l == NULL)
1897 return False;
1899 prs_debug(ps, depth, desc, "net_io_q_sam_logon");
1900 depth++;
1902 if(!prs_align(ps))
1903 return False;
1905 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))
1906 return False;
1908 if(!prs_align_uint16(ps))
1909 return False;
1911 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1912 return False;
1914 return True;
1917 /*******************************************************************
1918 Reads or writes a structure.
1919 ********************************************************************/
1921 BOOL net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
1923 if (r_l == NULL)
1924 return False;
1926 prs_debug(ps, depth, desc, "net_io_r_sam_logon");
1927 depth++;
1929 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1930 return False;
1931 if (&r_l->buffer_creds) {
1932 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
1933 return False;
1936 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
1937 return False;
1938 if(!prs_align(ps))
1939 return False;
1941 #if 1 /* W2k always needs this - even for bad passwd. JRA */
1942 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1943 return False;
1944 #else
1945 if (r_l->switch_value != 0) {
1946 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
1947 return False;
1949 #endif
1951 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
1952 return False;
1954 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1955 return False;
1957 if(!prs_align(ps))
1958 return False;
1960 return True;
1963 /*******************************************************************
1964 Reads or writes a structure.
1965 ********************************************************************/
1967 BOOL net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct *ps, int depth)
1969 if (q_l == NULL)
1970 return False;
1972 prs_debug(ps, depth, desc, "net_io_q_sam_logon_ex");
1973 depth++;
1975 if(!prs_align(ps))
1976 return False;
1978 if(!smb_io_sam_info_ex("", &q_l->sam_id, ps, depth))
1979 return False;
1981 if(!prs_align_uint16(ps))
1982 return False;
1984 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1985 return False;
1987 if(!prs_uint32("flags ", ps, depth, &q_l->flags))
1988 return False;
1990 return True;
1993 /*******************************************************************
1994 Reads or writes a structure.
1995 ********************************************************************/
1997 BOOL net_io_r_sam_logon_ex(const char *desc, NET_R_SAM_LOGON_EX *r_l, prs_struct *ps, int depth)
1999 if (r_l == NULL)
2000 return False;
2002 prs_debug(ps, depth, desc, "net_io_r_sam_logon_ex");
2003 depth++;
2005 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
2006 return False;
2007 if(!prs_align(ps))
2008 return False;
2010 #if 1 /* W2k always needs this - even for bad passwd. JRA */
2011 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
2012 return False;
2013 #else
2014 if (r_l->switch_value != 0) {
2015 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
2016 return False;
2018 #endif
2020 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
2021 return False;
2023 if(!prs_uint32("flags ", ps, depth, &r_l->flags))
2024 return False;
2026 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
2027 return False;
2029 if(!prs_align(ps))
2030 return False;
2032 return True;
2036 /*******************************************************************
2037 Reads or writes a structure.
2038 ********************************************************************/
2040 BOOL net_io_q_sam_logoff(const char *desc, NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
2042 if (q_l == NULL)
2043 return False;
2045 prs_debug(ps, depth, desc, "net_io_q_sam_logoff");
2046 depth++;
2048 if(!prs_align(ps))
2049 return False;
2051 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth)) /* domain SID */
2052 return False;
2054 return True;
2057 /*******************************************************************
2058 Reads or writes a structure.
2059 ********************************************************************/
2061 BOOL net_io_r_sam_logoff(const char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
2063 if (r_l == NULL)
2064 return False;
2066 prs_debug(ps, depth, desc, "net_io_r_sam_logoff");
2067 depth++;
2069 if(!prs_align(ps))
2070 return False;
2072 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
2073 return False;
2074 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
2075 return False;
2077 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
2078 return False;
2080 return True;
2083 /*******************************************************************
2084 makes a NET_Q_SAM_SYNC structure.
2085 ********************************************************************/
2086 BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
2087 const char *cli_name, DOM_CRED *cli_creds,
2088 DOM_CRED *ret_creds, uint32 database_id,
2089 uint32 next_rid)
2091 DEBUG(5, ("init_q_sam_sync\n"));
2093 init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
2094 init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
2096 if (cli_creds)
2097 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
2099 if (cli_creds)
2100 memcpy(&q_s->ret_creds, ret_creds, sizeof(q_s->ret_creds));
2101 else
2102 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
2104 q_s->database_id = database_id;
2105 q_s->restart_state = 0;
2106 q_s->sync_context = next_rid;
2107 q_s->max_size = 0xffff;
2109 return True;
2112 /*******************************************************************
2113 reads or writes a structure.
2114 ********************************************************************/
2115 BOOL net_io_q_sam_sync(const char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
2116 int depth)
2118 prs_debug(ps, depth, desc, "net_io_q_sam_sync");
2119 depth++;
2121 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
2122 return False;
2123 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
2124 return False;
2126 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
2127 return False;
2128 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
2129 return False;
2131 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
2132 return False;
2133 if (!prs_uint32("restart_state", ps, depth, &q_s->restart_state))
2134 return False;
2135 if (!prs_uint32("sync_context ", ps, depth, &q_s->sync_context))
2136 return False;
2138 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
2139 return False;
2141 return True;
2144 /*******************************************************************
2145 reads or writes a structure.
2146 ********************************************************************/
2147 static BOOL net_io_sam_delta_hdr(const char *desc, SAM_DELTA_HDR * delta,
2148 prs_struct *ps, int depth)
2150 prs_debug(ps, depth, desc, "net_io_sam_delta_hdr");
2151 depth++;
2153 if (!prs_uint16("type", ps, depth, &delta->type))
2154 return False;
2155 if (!prs_uint16("type2", ps, depth, &delta->type2))
2156 return False;
2157 if (!prs_uint32("target_rid", ps, depth, &delta->target_rid))
2158 return False;
2160 if (!prs_uint32("type3", ps, depth, &delta->type3))
2161 return False;
2163 /* Not sure why we need this but it seems to be necessary to get
2164 sam deltas working. */
2166 if (delta->type != 0x16) {
2167 if (!prs_uint32("ptr_delta", ps, depth, &delta->ptr_delta))
2168 return False;
2171 return True;
2174 /*******************************************************************
2175 reads or writes a structure.
2176 ********************************************************************/
2177 static BOOL net_io_sam_delta_mod_count(const char *desc, SAM_DELTA_MOD_COUNT *info,
2178 prs_struct *ps, int depth)
2180 prs_debug(ps, depth, desc, "net_io_sam_delta_stamp");
2181 depth++;
2183 if (!prs_uint32("seqnum", ps, depth, &info->seqnum))
2184 return False;
2185 if (!prs_uint32("dom_mod_count_ptr", ps, depth,
2186 &info->dom_mod_count_ptr))
2187 return False;
2189 if (info->dom_mod_count_ptr) {
2190 if (!prs_uint64("dom_mod_count", ps, depth,
2191 &info->dom_mod_count))
2192 return False;
2195 return True;
2198 /*******************************************************************
2199 reads or writes a structure.
2200 ********************************************************************/
2201 static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
2202 prs_struct *ps, int depth)
2204 prs_debug(ps, depth, desc, "net_io_sam_domain_info");
2205 depth++;
2207 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2208 return False;
2209 if (!smb_io_unihdr("hdr_oem_info", &info->hdr_oem_info, ps, depth))
2210 return False;
2212 if (!prs_uint64("force_logoff", ps, depth, &info->force_logoff))
2213 return False;
2214 if (!prs_uint16("min_pwd_len", ps, depth, &info->min_pwd_len))
2215 return False;
2216 if (!prs_uint16("pwd_history_len", ps, depth, &info->pwd_history_len))
2217 return False;
2218 if (!prs_uint64("max_pwd_age", ps, depth, &info->max_pwd_age))
2219 return False;
2220 if (!prs_uint64("min_pwd_age", ps, depth, &info->min_pwd_age))
2221 return False;
2222 if (!prs_uint64("dom_mod_count", ps, depth, &info->dom_mod_count))
2223 return False;
2224 if (!smb_io_time("creation_time", &info->creation_time, ps, depth))
2225 return False;
2226 if (!prs_uint32("security_information", ps, depth, &info->security_information))
2227 return False;
2228 if (!smb_io_bufhdr4("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2229 return False;
2230 if (!smb_io_lockout_string_hdr("hdr_account_lockout_string", &info->hdr_account_lockout, ps, depth))
2231 return False;
2232 if (!smb_io_unihdr("hdr_unknown2", &info->hdr_unknown2, ps, depth))
2233 return False;
2234 if (!smb_io_unihdr("hdr_unknown3", &info->hdr_unknown3, ps, depth))
2235 return False;
2236 if (!smb_io_unihdr("hdr_unknown4", &info->hdr_unknown4, ps, depth))
2237 return False;
2238 if (!prs_uint32("logon_chgpass", ps, depth, &info->logon_chgpass))
2239 return False;
2240 if (!prs_uint32("unknown6", ps, depth, &info->unknown6))
2241 return False;
2242 if (!prs_uint32("unknown7", ps, depth, &info->unknown7))
2243 return False;
2244 if (!prs_uint32("unknown8", ps, depth, &info->unknown8))
2245 return False;
2247 if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
2248 info->hdr_dom_name.buffer, ps, depth))
2249 return False;
2250 if (!smb_io_unistr2("buf_oem_info", &info->buf_oem_info,
2251 info->hdr_oem_info.buffer, ps, depth))
2252 return False;
2254 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2255 return False;
2257 if (!smb_io_account_lockout_str("account_lockout", &info->account_lockout,
2258 info->hdr_account_lockout.buffer, ps, depth))
2259 return False;
2261 if (!smb_io_unistr2("buf_unknown2", &info->buf_unknown2,
2262 info->hdr_unknown2.buffer, ps, depth))
2263 return False;
2264 if (!smb_io_unistr2("buf_unknown3", &info->buf_unknown3,
2265 info->hdr_unknown3.buffer, ps, depth))
2266 return False;
2267 if (!smb_io_unistr2("buf_unknown4", &info->buf_unknown4,
2268 info->hdr_unknown4.buffer, ps, depth))
2269 return False;
2271 return True;
2274 /*******************************************************************
2275 reads or writes a structure.
2276 ********************************************************************/
2277 static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
2278 prs_struct *ps, int depth)
2280 prs_debug(ps, depth, desc, "net_io_sam_group_info");
2281 depth++;
2283 if (!smb_io_unihdr("hdr_grp_name", &info->hdr_grp_name, ps, depth))
2284 return False;
2285 if (!smb_io_gid("gid", &info->gid, ps, depth))
2286 return False;
2287 if (!smb_io_unihdr("hdr_grp_desc", &info->hdr_grp_desc, ps, depth))
2288 return False;
2289 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2290 return False;
2292 if (ps->data_offset + 48 > ps->buffer_size)
2293 return False;
2294 ps->data_offset += 48;
2296 if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
2297 info->hdr_grp_name.buffer, ps, depth))
2298 return False;
2299 if (!smb_io_unistr2("uni_grp_desc", &info->uni_grp_desc,
2300 info->hdr_grp_desc.buffer, ps, depth))
2301 return False;
2302 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2303 return False;
2305 return True;
2308 /*******************************************************************
2309 reads or writes a structure.
2310 ********************************************************************/
2311 static BOOL net_io_sam_passwd_info(const char *desc, SAM_PWD * pwd,
2312 prs_struct *ps, int depth)
2314 prs_debug(ps, depth, desc, "net_io_sam_passwd_info");
2315 depth++;
2317 if (!prs_uint32("unk_0 ", ps, depth, &pwd->unk_0))
2318 return False;
2320 if (!smb_io_unihdr("hdr_lm_pwd", &pwd->hdr_lm_pwd, ps, depth))
2321 return False;
2322 if (!prs_uint8s(False, "buf_lm_pwd", ps, depth, pwd->buf_lm_pwd, 16))
2323 return False;
2325 if (!smb_io_unihdr("hdr_nt_pwd", &pwd->hdr_nt_pwd, ps, depth))
2326 return False;
2327 if (!prs_uint8s(False, "buf_nt_pwd", ps, depth, pwd->buf_nt_pwd, 16))
2328 return False;
2330 if (!smb_io_unihdr("", &pwd->hdr_empty_lm, ps, depth))
2331 return False;
2332 if (!smb_io_unihdr("", &pwd->hdr_empty_nt, ps, depth))
2333 return False;
2335 return True;
2338 /*******************************************************************
2339 reads or writes a structure.
2340 ********************************************************************/
2341 static BOOL net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
2342 prs_struct *ps, int depth)
2344 BUFHDR2 hdr_priv_data;
2345 uint32 i;
2347 prs_debug(ps, depth, desc, "net_io_sam_account_info");
2348 depth++;
2350 if (!smb_io_unihdr("hdr_acct_name", &info->hdr_acct_name, ps, depth))
2351 return False;
2352 if (!smb_io_unihdr("hdr_full_name", &info->hdr_full_name, ps, depth))
2353 return False;
2355 if (!prs_uint32("user_rid ", ps, depth, &info->user_rid))
2356 return False;
2357 if (!prs_uint32("group_rid", ps, depth, &info->group_rid))
2358 return False;
2360 if (!smb_io_unihdr("hdr_home_dir ", &info->hdr_home_dir, ps, depth))
2361 return False;
2362 if (!smb_io_unihdr("hdr_dir_drive", &info->hdr_dir_drive, ps, depth))
2363 return False;
2364 if (!smb_io_unihdr("hdr_logon_script", &info->hdr_logon_script, ps,
2365 depth))
2366 return False;
2368 if (!smb_io_unihdr("hdr_acct_desc", &info->hdr_acct_desc, ps, depth))
2369 return False;
2370 if (!smb_io_unihdr("hdr_workstations", &info->hdr_workstations, ps,
2371 depth))
2372 return False;
2374 if (!smb_io_time("logon_time", &info->logon_time, ps, depth))
2375 return False;
2376 if (!smb_io_time("logoff_time", &info->logoff_time, ps, depth))
2377 return False;
2379 if (!prs_uint32("logon_divs ", ps, depth, &info->logon_divs))
2380 return False;
2381 if (!prs_uint32("ptr_logon_hrs", ps, depth, &info->ptr_logon_hrs))
2382 return False;
2384 if (!prs_uint16("bad_pwd_count", ps, depth, &info->bad_pwd_count))
2385 return False;
2386 if (!prs_uint16("logon_count", ps, depth, &info->logon_count))
2387 return False;
2388 if (!smb_io_time("pwd_last_set_time", &info->pwd_last_set_time, ps,
2389 depth))
2390 return False;
2391 if (!smb_io_time("acct_expiry_time", &info->acct_expiry_time, ps,
2392 depth))
2393 return False;
2395 if (!prs_uint32("acb_info", ps, depth, &info->acb_info))
2396 return False;
2397 if (!prs_uint8s(False, "nt_pwd", ps, depth, info->nt_pwd, 16))
2398 return False;
2399 if (!prs_uint8s(False, "lm_pwd", ps, depth, info->lm_pwd, 16))
2400 return False;
2401 if (!prs_uint8("lm_pwd_present", ps, depth, &info->lm_pwd_present))
2402 return False;
2403 if (!prs_uint8("nt_pwd_present", ps, depth, &info->nt_pwd_present))
2404 return False;
2405 if (!prs_uint8("pwd_expired", ps, depth, &info->pwd_expired))
2406 return False;
2408 if (!smb_io_unihdr("hdr_comment", &info->hdr_comment, ps, depth))
2409 return False;
2410 if (!smb_io_unihdr("hdr_parameters", &info->hdr_parameters, ps,
2411 depth))
2412 return False;
2413 if (!prs_uint16("country", ps, depth, &info->country))
2414 return False;
2415 if (!prs_uint16("codepage", ps, depth, &info->codepage))
2416 return False;
2418 if (!smb_io_bufhdr2("hdr_priv_data", &hdr_priv_data, ps, depth))
2419 return False;
2420 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2421 return False;
2422 if (!smb_io_unihdr("hdr_profile", &info->hdr_profile, ps, depth))
2423 return False;
2425 for (i = 0; i < 3; i++)
2427 if (!smb_io_unihdr("hdr_reserved", &info->hdr_reserved[i],
2428 ps, depth))
2429 return False;
2432 for (i = 0; i < 4; i++)
2434 if (!prs_uint32("dw_reserved", ps, depth,
2435 &info->dw_reserved[i]))
2436 return False;
2439 if (!smb_io_unistr2("uni_acct_name", &info->uni_acct_name,
2440 info->hdr_acct_name.buffer, ps, depth))
2441 return False;
2442 prs_align(ps);
2443 if (!smb_io_unistr2("uni_full_name", &info->uni_full_name,
2444 info->hdr_full_name.buffer, ps, depth))
2445 return False;
2446 prs_align(ps);
2447 if (!smb_io_unistr2("uni_home_dir ", &info->uni_home_dir,
2448 info->hdr_home_dir.buffer, ps, depth))
2449 return False;
2450 prs_align(ps);
2451 if (!smb_io_unistr2("uni_dir_drive", &info->uni_dir_drive,
2452 info->hdr_dir_drive.buffer, ps, depth))
2453 return False;
2454 prs_align(ps);
2455 if (!smb_io_unistr2("uni_logon_script", &info->uni_logon_script,
2456 info->hdr_logon_script.buffer, ps, depth))
2457 return False;
2458 prs_align(ps);
2459 if (!smb_io_unistr2("uni_acct_desc", &info->uni_acct_desc,
2460 info->hdr_acct_desc.buffer, ps, depth))
2461 return False;
2462 prs_align(ps);
2463 if (!smb_io_unistr2("uni_workstations", &info->uni_workstations,
2464 info->hdr_workstations.buffer, ps, depth))
2465 return False;
2466 prs_align(ps);
2468 if (!prs_uint32("unknown1", ps, depth, &info->unknown1))
2469 return False;
2470 if (!prs_uint32("unknown2", ps, depth, &info->unknown2))
2471 return False;
2473 if (!smb_io_rpc_blob("buf_logon_hrs", &info->buf_logon_hrs, ps, depth))
2474 return False;
2475 prs_align(ps);
2476 if (!smb_io_unistr2("uni_comment", &info->uni_comment,
2477 info->hdr_comment.buffer, ps, depth))
2478 return False;
2479 prs_align(ps);
2480 if (!smb_io_unistr2("uni_parameters", &info->uni_parameters,
2481 info->hdr_parameters.buffer, ps, depth))
2482 return False;
2483 prs_align(ps);
2484 if (hdr_priv_data.buffer != 0)
2486 int old_offset = 0;
2487 uint32 len = 0x44;
2488 if (!prs_uint32("pwd_len", ps, depth, &len))
2489 return False;
2490 old_offset = ps->data_offset;
2491 if (len > 0)
2493 if (ps->io)
2495 /* reading */
2496 if (!prs_hash1(ps, ps->data_offset, len))
2497 return False;
2499 if (!net_io_sam_passwd_info("pass", &info->pass,
2500 ps, depth))
2501 return False;
2503 if (!ps->io)
2505 /* writing */
2506 if (!prs_hash1(ps, old_offset, len))
2507 return False;
2510 if (old_offset + len > ps->buffer_size)
2511 return False;
2512 ps->data_offset = old_offset + len;
2514 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2515 return False;
2516 prs_align(ps);
2517 if (!smb_io_unistr2("uni_profile", &info->uni_profile,
2518 info->hdr_profile.buffer, ps, depth))
2519 return False;
2521 prs_align(ps);
2523 return True;
2526 /*******************************************************************
2527 reads or writes a structure.
2528 ********************************************************************/
2529 static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * info,
2530 prs_struct *ps, int depth)
2532 uint32 i;
2533 fstring tmp;
2535 prs_debug(ps, depth, desc, "net_io_sam_group_mem_info");
2536 depth++;
2538 prs_align(ps);
2539 if (!prs_uint32("ptr_rids ", ps, depth, &info->ptr_rids))
2540 return False;
2541 if (!prs_uint32("ptr_attribs", ps, depth, &info->ptr_attribs))
2542 return False;
2543 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2544 return False;
2546 if (ps->data_offset + 16 > ps->buffer_size)
2547 return False;
2548 ps->data_offset += 16;
2550 if (info->ptr_rids != 0)
2552 if (!prs_uint32("num_members2", ps, depth,
2553 &info->num_members2))
2554 return False;
2556 if (info->num_members2 != info->num_members)
2558 /* RPC fault */
2559 return False;
2562 if (UNMARSHALLING(ps)) {
2563 if (info->num_members2) {
2564 info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
2566 if (info->rids == NULL) {
2567 DEBUG(0, ("out of memory allocating %d rids\n",
2568 info->num_members2));
2569 return False;
2571 } else {
2572 info->rids = NULL;
2576 for (i = 0; i < info->num_members2; i++)
2578 slprintf(tmp, sizeof(tmp) - 1, "rids[%02d]", i);
2579 if (!prs_uint32(tmp, ps, depth, &info->rids[i]))
2580 return False;
2584 if (info->ptr_attribs != 0)
2586 if (!prs_uint32("num_members3", ps, depth,
2587 &info->num_members3))
2588 return False;
2589 if (info->num_members3 != info->num_members)
2591 /* RPC fault */
2592 return False;
2595 if (UNMARSHALLING(ps)) {
2596 if (info->num_members3) {
2597 info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
2599 if (info->attribs == NULL) {
2600 DEBUG(0, ("out of memory allocating %d attribs\n",
2601 info->num_members3));
2602 return False;
2604 } else {
2605 info->attribs = NULL;
2609 for (i = 0; i < info->num_members3; i++)
2611 slprintf(tmp, sizeof(tmp) - 1, "attribs[%02d]", i);
2612 if (!prs_uint32(tmp, ps, depth, &info->attribs[i]))
2613 return False;
2617 return True;
2620 /*******************************************************************
2621 reads or writes a structure.
2622 ********************************************************************/
2623 static BOOL net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
2624 prs_struct *ps, int depth)
2626 prs_debug(ps, depth, desc, "net_io_sam_alias_info");
2627 depth++;
2629 if (!smb_io_unihdr("hdr_als_name", &info->hdr_als_name, ps, depth))
2630 return False;
2631 if (!prs_uint32("als_rid", ps, depth, &info->als_rid))
2632 return False;
2633 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2634 return False;
2635 if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
2636 return False;
2638 if (ps->data_offset + 40 > ps->buffer_size)
2639 return False;
2640 ps->data_offset += 40;
2642 if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
2643 info->hdr_als_name.buffer, ps, depth))
2644 return False;
2645 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2646 return False;
2648 if (!smb_io_unistr2("uni_als_desc", &info->uni_als_desc,
2649 info->hdr_als_desc.buffer, ps, depth))
2650 return False;
2652 return True;
2655 /*******************************************************************
2656 reads or writes a structure.
2657 ********************************************************************/
2658 static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * info,
2659 prs_struct *ps, int depth)
2661 uint32 i;
2662 fstring tmp;
2664 prs_debug(ps, depth, desc, "net_io_sam_alias_mem_info");
2665 depth++;
2667 prs_align(ps);
2668 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2669 return False;
2670 if (!prs_uint32("ptr_members", ps, depth, &info->ptr_members))
2671 return False;
2673 if (ps->data_offset + 16 > ps->buffer_size)
2674 return False;
2675 ps->data_offset += 16;
2677 if (info->ptr_members != 0)
2679 if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
2680 return False;
2681 if (info->num_sids != info->num_members)
2683 /* RPC fault */
2684 return False;
2687 if (UNMARSHALLING(ps)) {
2688 if (info->num_sids) {
2689 info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
2691 if (info->ptr_sids == NULL) {
2692 DEBUG(0, ("out of memory allocating %d ptr_sids\n",
2693 info->num_sids));
2694 return False;
2696 } else {
2697 info->ptr_sids = NULL;
2701 for (i = 0; i < info->num_sids; i++)
2703 slprintf(tmp, sizeof(tmp) - 1, "ptr_sids[%02d]", i);
2704 if (!prs_uint32(tmp, ps, depth, &info->ptr_sids[i]))
2705 return False;
2708 if (UNMARSHALLING(ps)) {
2709 if (info->num_sids) {
2710 info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
2712 if (info->sids == NULL) {
2713 DEBUG(0, ("error allocating %d sids\n",
2714 info->num_sids));
2715 return False;
2717 } else {
2718 info->sids = NULL;
2722 for (i = 0; i < info->num_sids; i++)
2724 if (info->ptr_sids[i] != 0)
2726 slprintf(tmp, sizeof(tmp) - 1, "sids[%02d]",
2728 if (!smb_io_dom_sid2(tmp, &info->sids[i],
2729 ps, depth))
2730 return False;
2735 return True;
2738 /*******************************************************************
2739 reads or writes a structure.
2740 ********************************************************************/
2741 static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
2742 prs_struct *ps, int depth)
2744 unsigned int i;
2745 prs_debug(ps, depth, desc, "net_io_sam_policy_info");
2746 depth++;
2748 if(!prs_align(ps))
2749 return False;
2751 if (!prs_uint32("max_log_size", ps, depth, &info->max_log_size))
2752 return False;
2753 if (!prs_uint64("audit_retention_period", ps, depth,
2754 &info->audit_retention_period))
2755 return False;
2756 if (!prs_uint32("auditing_mode", ps, depth, &info->auditing_mode))
2757 return False;
2758 if (!prs_uint32("num_events", ps, depth, &info->num_events))
2759 return False;
2760 if (!prs_uint32("ptr_events", ps, depth, &info->ptr_events))
2761 return False;
2763 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2764 return False;
2766 if (!prs_uint32("sid_ptr", ps, depth, &info->sid_ptr))
2767 return False;
2769 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2770 return False;
2771 if (!prs_uint32("non_paged_pool_limit", ps, depth,
2772 &info->non_paged_pool_limit))
2773 return False;
2774 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
2775 return False;
2776 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
2777 return False;
2778 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
2779 return False;
2780 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
2781 return False;
2782 if (!smb_io_time("modify_time", &info->modify_time, ps, depth))
2783 return False;
2784 if (!smb_io_time("create_time", &info->create_time, ps, depth))
2785 return False;
2786 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2787 return False;
2789 for (i=0; i<4; i++) {
2790 UNIHDR dummy;
2791 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
2792 return False;
2795 for (i=0; i<4; i++) {
2796 uint32 reserved;
2797 if (!prs_uint32("reserved", ps, depth, &reserved))
2798 return False;
2801 if (!prs_uint32("num_event_audit_options", ps, depth,
2802 &info->num_event_audit_options))
2803 return False;
2805 for (i=0; i<info->num_event_audit_options; i++)
2806 if (!prs_uint32("event_audit_option", ps, depth,
2807 &info->event_audit_option))
2808 return False;
2810 if (!smb_io_unistr2("domain_name", &info->domain_name, True, ps, depth))
2811 return False;
2813 if(!smb_io_dom_sid2("domain_sid", &info->domain_sid, ps, depth))
2814 return False;
2816 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
2818 return False;
2820 return True;
2823 #if 0
2825 /* This function is pretty broken - see bug #334 */
2827 /*******************************************************************
2828 reads or writes a structure.
2829 ********************************************************************/
2830 static BOOL net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *info,
2831 prs_struct *ps, int depth)
2833 int i;
2835 prs_debug(ps, depth, desc, "net_io_sam_trustdoms_info");
2836 depth++;
2838 if(!prs_align(ps))
2839 return False;
2841 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2842 return False;
2844 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2845 return False;
2847 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2848 return False;
2850 if(!smb_io_unihdr("hdr_domain", &info->hdr_domain, ps, depth))
2851 return False;
2853 if(!prs_uint32("unknown0", ps, depth, &info->unknown0))
2854 return False;
2855 if(!prs_uint32("unknown1", ps, depth, &info->unknown1))
2856 return False;
2857 if(!prs_uint32("unknown2", ps, depth, &info->unknown2))
2858 return False;
2860 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2861 return False;
2862 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2863 return False;
2865 for (i=0; i<12; i++)
2866 if(!prs_uint32("unknown3", ps, depth, &info->unknown3))
2867 return False;
2869 if (!smb_io_unistr2("domain", &info->domain, True, ps, depth))
2870 return False;
2872 return True;
2875 #endif
2877 #if 0
2879 /* This function doesn't work - see bug #334 */
2881 /*******************************************************************
2882 reads or writes a structure.
2883 ********************************************************************/
2884 static BOOL net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
2885 prs_struct *ps, int depth)
2887 int i;
2889 prs_debug(ps, depth, desc, "net_io_sam_secret_info");
2890 depth++;
2892 if(!prs_align(ps))
2893 return False;
2895 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2896 return False;
2898 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2899 return False;
2901 if (!smb_io_unistr2("secret", &info->secret, True, ps, depth))
2902 return False;
2904 if(!prs_align(ps))
2905 return False;
2907 if(!prs_uint32("count1", ps, depth, &info->count1))
2908 return False;
2909 if(!prs_uint32("count2", ps, depth, &info->count2))
2910 return False;
2911 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2912 return False;
2915 if(!smb_io_time("time1", &info->time1, ps, depth)) /* logon time */
2916 return False;
2917 if(!prs_uint32("count3", ps, depth, &info->count3))
2918 return False;
2919 if(!prs_uint32("count4", ps, depth, &info->count4))
2920 return False;
2921 if(!prs_uint32("ptr2", ps, depth, &info->ptr2))
2922 return False;
2923 if(!smb_io_time("time2", &info->time2, ps, depth)) /* logon time */
2924 return False;
2925 if(!prs_uint32("unknow1", ps, depth, &info->unknow1))
2926 return False;
2929 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2930 return False;
2931 if(!prs_uint32("ptr3", ps, depth, &info->ptr3))
2932 return False;
2933 for(i=0; i<12; i++)
2934 if(!prs_uint32("unknow2", ps, depth, &info->unknow2))
2935 return False;
2937 if(!prs_uint32("chal_len", ps, depth, &info->chal_len))
2938 return False;
2939 if(!prs_uint32("reserved1", ps, depth, &info->reserved1))
2940 return False;
2941 if(!prs_uint32("chal_len2", ps, depth, &info->chal_len2))
2942 return False;
2944 if(!prs_uint8s (False, "chal", ps, depth, info->chal, info->chal_len2))
2945 return False;
2947 if(!prs_uint32("key_len", ps, depth, &info->key_len))
2948 return False;
2949 if(!prs_uint32("reserved2", ps, depth, &info->reserved2))
2950 return False;
2951 if(!prs_uint32("key_len2", ps, depth, &info->key_len2))
2952 return False;
2954 if(!prs_uint8s (False, "key", ps, depth, info->key, info->key_len2))
2955 return False;
2958 if(!prs_uint32("buf_size3", ps, depth, &info->buf_size3))
2959 return False;
2961 if(!sec_io_desc("sec_desc2", &info->sec_desc2, ps, depth))
2962 return False;
2965 return True;
2968 #endif
2970 /*******************************************************************
2971 reads or writes a structure.
2972 ********************************************************************/
2973 static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
2974 prs_struct *ps, int depth)
2976 unsigned int i;
2978 prs_debug(ps, depth, desc, "net_io_sam_privs_info");
2979 depth++;
2981 if(!prs_align(ps))
2982 return False;
2984 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2985 return False;
2987 if(!prs_uint32("priv_count", ps, depth, &info->priv_count))
2988 return False;
2989 if(!prs_uint32("priv_control", ps, depth, &info->priv_control))
2990 return False;
2992 if(!prs_uint32("priv_attr_ptr", ps, depth, &info->priv_attr_ptr))
2993 return False;
2994 if(!prs_uint32("priv_name_ptr", ps, depth, &info->priv_name_ptr))
2995 return False;
2997 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2998 return False;
2999 if (!prs_uint32("non_paged_pool_limit", ps, depth,
3000 &info->non_paged_pool_limit))
3001 return False;
3002 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
3003 return False;
3004 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
3005 return False;
3006 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
3007 return False;
3008 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
3009 return False;
3010 if (!prs_uint32("system_flags", ps, depth, &info->system_flags))
3011 return False;
3012 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
3013 return False;
3015 for (i=0; i<4; i++) {
3016 UNIHDR dummy;
3017 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
3018 return False;
3021 for (i=0; i<4; i++) {
3022 uint32 reserved;
3023 if (!prs_uint32("reserved", ps, depth, &reserved))
3024 return False;
3027 if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
3028 return False;
3030 if (UNMARSHALLING(ps)) {
3031 if (info->attribute_count) {
3032 info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
3033 if (!info->attributes) {
3034 return False;
3036 } else {
3037 info->attributes = NULL;
3041 for (i=0; i<info->attribute_count; i++)
3042 if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
3043 return False;
3045 if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
3046 return False;
3048 if (UNMARSHALLING(ps)) {
3049 if (info->privlist_count) {
3050 info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
3051 info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
3052 if (!info->hdr_privslist) {
3053 return False;
3055 if (!info->uni_privslist) {
3056 return False;
3058 } else {
3059 info->hdr_privslist = NULL;
3060 info->uni_privslist = NULL;
3064 for (i=0; i<info->privlist_count; i++)
3065 if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
3066 return False;
3068 for (i=0; i<info->privlist_count; i++)
3069 if (!smb_io_unistr2("uni_privslist", &info->uni_privslist[i], True, ps, depth))
3070 return False;
3072 if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
3073 return False;
3075 return True;
3078 /*******************************************************************
3079 reads or writes a structure.
3080 ********************************************************************/
3081 static BOOL net_io_sam_delta_ctr(const char *desc,
3082 SAM_DELTA_CTR * delta, uint16 type,
3083 prs_struct *ps, int depth)
3085 prs_debug(ps, depth, desc, "net_io_sam_delta_ctr");
3086 depth++;
3088 switch (type) {
3089 /* Seen in sam deltas */
3090 case SAM_DELTA_MODIFIED_COUNT:
3091 if (!net_io_sam_delta_mod_count("", &delta->mod_count, ps, depth))
3092 return False;
3093 break;
3095 case SAM_DELTA_DOMAIN_INFO:
3096 if (!net_io_sam_domain_info("", &delta->domain_info, ps, depth))
3097 return False;
3098 break;
3100 case SAM_DELTA_GROUP_INFO:
3101 if (!net_io_sam_group_info("", &delta->group_info, ps, depth))
3102 return False;
3103 break;
3105 case SAM_DELTA_ACCOUNT_INFO:
3106 if (!net_io_sam_account_info("", &delta->account_info, ps, depth))
3107 return False;
3108 break;
3110 case SAM_DELTA_GROUP_MEM:
3111 if (!net_io_sam_group_mem_info("", &delta->grp_mem_info, ps, depth))
3112 return False;
3113 break;
3115 case SAM_DELTA_ALIAS_INFO:
3116 if (!net_io_sam_alias_info("", &delta->alias_info, ps, depth))
3117 return False;
3118 break;
3120 case SAM_DELTA_POLICY_INFO:
3121 if (!net_io_sam_policy_info("", &delta->policy_info, ps, depth))
3122 return False;
3123 break;
3125 case SAM_DELTA_ALIAS_MEM:
3126 if (!net_io_sam_alias_mem_info("", &delta->als_mem_info, ps, depth))
3127 return False;
3128 break;
3130 case SAM_DELTA_PRIVS_INFO:
3131 if (!net_io_sam_privs_info("", &delta->privs_info, ps, depth))
3132 return False;
3133 break;
3135 /* These guys are implemented but broken */
3137 case SAM_DELTA_TRUST_DOMS:
3138 case SAM_DELTA_SECRET_INFO:
3139 break;
3141 /* These guys are not implemented yet */
3143 case SAM_DELTA_RENAME_GROUP:
3144 case SAM_DELTA_RENAME_USER:
3145 case SAM_DELTA_RENAME_ALIAS:
3146 case SAM_DELTA_DELETE_GROUP:
3147 case SAM_DELTA_DELETE_USER:
3148 default:
3149 DEBUG(0, ("Replication error: Unknown delta type 0x%x\n", type));
3150 break;
3153 return True;
3156 /*******************************************************************
3157 reads or writes a structure.
3158 ********************************************************************/
3159 BOOL net_io_r_sam_sync(const char *desc,
3160 NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
3162 uint32 i;
3164 prs_debug(ps, depth, desc, "net_io_r_sam_sync");
3165 depth++;
3167 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3168 return False;
3169 if (!prs_uint32("sync_context", ps, depth, &r_s->sync_context))
3170 return False;
3172 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3173 return False;
3174 if (r_s->ptr_deltas != 0)
3176 if (!prs_uint32("num_deltas ", ps, depth, &r_s->num_deltas))
3177 return False;
3178 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->ptr_deltas2))
3179 return False;
3180 if (r_s->ptr_deltas2 != 0)
3182 if (!prs_uint32("num_deltas2", ps, depth,
3183 &r_s->num_deltas2))
3184 return False;
3186 if (r_s->num_deltas2 != r_s->num_deltas)
3188 /* RPC fault */
3189 return False;
3192 if (UNMARSHALLING(ps)) {
3193 if (r_s->num_deltas2) {
3194 r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
3195 if (r_s->hdr_deltas == NULL) {
3196 DEBUG(0, ("error tallocating memory "
3197 "for %d delta headers\n",
3198 r_s->num_deltas2));
3199 return False;
3201 } else {
3202 r_s->hdr_deltas = NULL;
3206 for (i = 0; i < r_s->num_deltas2; i++)
3208 if (!net_io_sam_delta_hdr("",
3209 &r_s->hdr_deltas[i],
3210 ps, depth))
3211 return False;
3214 if (UNMARSHALLING(ps)) {
3215 if (r_s->num_deltas2) {
3216 r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
3217 if (r_s->deltas == NULL) {
3218 DEBUG(0, ("error tallocating memory "
3219 "for %d deltas\n",
3220 r_s->num_deltas2));
3221 return False;
3223 } else {
3224 r_s->deltas = NULL;
3228 for (i = 0; i < r_s->num_deltas2; i++)
3230 if (!net_io_sam_delta_ctr(
3231 "", &r_s->deltas[i],
3232 r_s->hdr_deltas[i].type3,
3233 ps, depth)) {
3234 DEBUG(0, ("hmm, failed on i=%d\n", i));
3235 return False;
3241 prs_align(ps);
3242 if (!prs_ntstatus("status", ps, depth, &(r_s->status)))
3243 return False;
3245 return True;
3248 /*******************************************************************
3249 makes a NET_Q_SAM_DELTAS structure.
3250 ********************************************************************/
3251 BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
3252 const char *cli_name, DOM_CRED *cli_creds,
3253 uint32 database_id, uint64 dom_mod_count)
3255 DEBUG(5, ("init_net_q_sam_deltas\n"));
3257 init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
3258 init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
3260 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
3261 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
3263 q_s->database_id = database_id;
3264 q_s->dom_mod_count = dom_mod_count;
3265 q_s->max_size = 0xffff;
3267 return True;
3270 /*******************************************************************
3271 reads or writes a structure.
3272 ********************************************************************/
3273 BOOL net_io_q_sam_deltas(const char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
3274 int depth)
3276 prs_debug(ps, depth, desc, "net_io_q_sam_deltas");
3277 depth++;
3279 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
3280 return False;
3281 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
3282 return False;
3284 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
3285 return False;
3286 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
3287 return False;
3289 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
3290 return False;
3291 if (!prs_uint64("dom_mod_count", ps, depth, &q_s->dom_mod_count))
3292 return False;
3293 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
3294 return False;
3296 return True;
3299 /*******************************************************************
3300 reads or writes a structure.
3301 ********************************************************************/
3302 BOOL net_io_r_sam_deltas(const char *desc,
3303 NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
3305 unsigned int i;
3307 prs_debug(ps, depth, desc, "net_io_r_sam_deltas");
3308 depth++;
3310 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
3311 return False;
3312 if (!prs_uint64("dom_mod_count", ps, depth, &r_s->dom_mod_count))
3313 return False;
3315 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
3316 return False;
3317 if (!prs_uint32("num_deltas", ps, depth, &r_s->num_deltas))
3318 return False;
3319 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->num_deltas2))
3320 return False;
3322 if (r_s->num_deltas2 != 0)
3324 if (!prs_uint32("num_deltas2 ", ps, depth, &r_s->num_deltas2))
3325 return False;
3327 if (r_s->ptr_deltas != 0)
3329 if (UNMARSHALLING(ps)) {
3330 if (r_s->num_deltas) {
3331 r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
3332 if (r_s->hdr_deltas == NULL) {
3333 DEBUG(0, ("error tallocating memory "
3334 "for %d delta headers\n",
3335 r_s->num_deltas));
3336 return False;
3338 } else {
3339 r_s->hdr_deltas = NULL;
3343 for (i = 0; i < r_s->num_deltas; i++)
3345 net_io_sam_delta_hdr("", &r_s->hdr_deltas[i],
3346 ps, depth);
3349 if (UNMARSHALLING(ps)) {
3350 if (r_s->num_deltas) {
3351 r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
3352 if (r_s->deltas == NULL) {
3353 DEBUG(0, ("error tallocating memory "
3354 "for %d deltas\n",
3355 r_s->num_deltas));
3356 return False;
3358 } else {
3359 r_s->deltas = NULL;
3363 for (i = 0; i < r_s->num_deltas; i++)
3365 if (!net_io_sam_delta_ctr(
3367 &r_s->deltas[i],
3368 r_s->hdr_deltas[i].type2,
3369 ps, depth))
3371 return False;
3376 prs_align(ps);
3377 if (!prs_ntstatus("status", ps, depth, &r_s->status))
3378 return False;
3380 return True;
3383 /*******************************************************************
3384 Inits a NET_Q_DSR_GETDCNAME structure.
3385 ********************************************************************/
3387 void init_net_q_dsr_getdcname(NET_Q_DSR_GETDCNAME *r_t, const char *server_unc,
3388 const char *domain_name,
3389 struct GUID *domain_guid,
3390 struct GUID *site_guid,
3391 uint32_t flags)
3393 DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3395 r_t->ptr_server_unc = (server_unc != NULL);
3396 init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
3398 r_t->ptr_domain_name = (domain_name != NULL);
3399 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3401 r_t->ptr_domain_guid = (domain_guid != NULL);
3402 r_t->domain_guid = domain_guid;
3404 r_t->ptr_site_guid = (site_guid != NULL);
3405 r_t->site_guid = site_guid;
3407 r_t->flags = flags;
3410 /*******************************************************************
3411 Reads or writes an NET_Q_DSR_GETDCNAME structure.
3412 ********************************************************************/
3414 BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
3415 prs_struct *ps, int depth)
3417 if (r_t == NULL)
3418 return False;
3420 prs_debug(ps, depth, desc, "net_io_q_dsr_getdcname");
3421 depth++;
3423 if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
3424 return False;
3426 if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
3427 r_t->ptr_server_unc, ps, depth))
3428 return False;
3430 if (!prs_align(ps))
3431 return False;
3433 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3434 return False;
3436 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3437 r_t->ptr_domain_name, ps, depth))
3438 return False;
3440 if (!prs_align(ps))
3441 return False;
3443 if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
3444 return False;
3446 if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
3447 r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3448 if (r_t->domain_guid == NULL)
3449 return False;
3452 if ((r_t->ptr_domain_guid) &&
3453 (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
3454 return False;
3456 if (!prs_align(ps))
3457 return False;
3459 if (!prs_uint32("ptr_site_guid", ps, depth, &r_t->ptr_site_guid))
3460 return False;
3462 if (UNMARSHALLING(ps) && (r_t->ptr_site_guid)) {
3463 r_t->site_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
3464 if (r_t->site_guid == NULL)
3465 return False;
3468 if ((r_t->ptr_site_guid) &&
3469 (!smb_io_uuid("site_guid", r_t->site_guid, ps, depth)))
3470 return False;
3472 if (!prs_align(ps))
3473 return False;
3475 if (!prs_uint32("flags", ps, depth, &r_t->flags))
3476 return False;
3478 return True;
3481 /*******************************************************************
3482 Inits a NET_R_DSR_GETDCNAME structure.
3483 ********************************************************************/
3484 void init_net_r_dsr_getdcname(NET_R_DSR_GETDCNAME *r_t, const char *dc_unc,
3485 const char *dc_address, int32 dc_address_type,
3486 struct GUID domain_guid, const char *domain_name,
3487 const char *forest_name, uint32 dc_flags,
3488 const char *dc_site_name,
3489 const char *client_site_name)
3491 DEBUG(5, ("init_net_q_dsr_getdcname\n"));
3493 r_t->ptr_dc_unc = (dc_unc != NULL);
3494 init_unistr2(&r_t->uni_dc_unc, dc_unc, UNI_STR_TERMINATE);
3496 r_t->ptr_dc_address = (dc_address != NULL);
3497 init_unistr2(&r_t->uni_dc_address, dc_address, UNI_STR_TERMINATE);
3499 r_t->dc_address_type = dc_address_type;
3500 r_t->domain_guid = domain_guid;
3502 r_t->ptr_domain_name = (domain_name != NULL);
3503 init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
3505 r_t->ptr_forest_name = (forest_name != NULL);
3506 init_unistr2(&r_t->uni_forest_name, forest_name, UNI_STR_TERMINATE);
3508 r_t->dc_flags = dc_flags;
3510 r_t->ptr_dc_site_name = (dc_site_name != NULL);
3511 init_unistr2(&r_t->uni_dc_site_name, dc_site_name, UNI_STR_TERMINATE);
3513 r_t->ptr_client_site_name = (client_site_name != NULL);
3514 init_unistr2(&r_t->uni_client_site_name, client_site_name,
3515 UNI_STR_TERMINATE);
3518 /*******************************************************************
3519 Reads or writes an NET_R_DSR_GETDCNAME structure.
3520 ********************************************************************/
3522 BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t,
3523 prs_struct *ps, int depth)
3525 uint32 info_ptr = 1;
3527 if (r_t == NULL)
3528 return False;
3530 prs_debug(ps, depth, desc, "net_io_r_dsr_getdcname");
3531 depth++;
3533 /* The reply contains *just* an info struct, this is the ptr to it */
3534 if (!prs_uint32("info_ptr", ps, depth, &info_ptr))
3535 return False;
3537 if (info_ptr == 0)
3538 return False;
3540 if (!prs_uint32("ptr_dc_unc", ps, depth, &r_t->ptr_dc_unc))
3541 return False;
3543 if (!prs_uint32("ptr_dc_address", ps, depth, &r_t->ptr_dc_address))
3544 return False;
3546 if (!prs_int32("dc_address_type", ps, depth, &r_t->dc_address_type))
3547 return False;
3549 if (!smb_io_uuid("domain_guid", &r_t->domain_guid, ps, depth))
3550 return False;
3552 if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
3553 return False;
3555 if (!prs_uint32("ptr_forest_name", ps, depth, &r_t->ptr_forest_name))
3556 return False;
3558 if (!prs_uint32("dc_flags", ps, depth, &r_t->dc_flags))
3559 return False;
3561 if (!prs_uint32("ptr_dc_site_name", ps, depth, &r_t->ptr_dc_site_name))
3562 return False;
3564 if (!prs_uint32("ptr_client_site_name", ps, depth,
3565 &r_t->ptr_client_site_name))
3566 return False;
3568 if (!prs_align(ps))
3569 return False;
3571 if (!smb_io_unistr2("dc_unc", &r_t->uni_dc_unc,
3572 r_t->ptr_dc_unc, ps, depth))
3573 return False;
3575 if (!prs_align(ps))
3576 return False;
3578 if (!smb_io_unistr2("dc_address", &r_t->uni_dc_address,
3579 r_t->ptr_dc_address, ps, depth))
3580 return False;
3582 if (!prs_align(ps))
3583 return False;
3585 if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
3586 r_t->ptr_domain_name, ps, depth))
3587 return False;
3589 if (!prs_align(ps))
3590 return False;
3592 if (!smb_io_unistr2("forest_name", &r_t->uni_forest_name,
3593 r_t->ptr_forest_name, ps, depth))
3594 return False;
3596 if (!prs_align(ps))
3597 return False;
3599 if (!smb_io_unistr2("dc_site_name", &r_t->uni_dc_site_name,
3600 r_t->ptr_dc_site_name, ps, depth))
3601 return False;
3603 if (!prs_align(ps))
3604 return False;
3606 if (!smb_io_unistr2("client_site_name", &r_t->uni_client_site_name,
3607 r_t->ptr_client_site_name, ps, depth))
3608 return False;
3610 if (!prs_align(ps))
3611 return False;
3613 if (!prs_werror("result", ps, depth, &r_t->result))
3614 return False;
3616 return True;
3619 /*******************************************************************
3620 Inits a NET_Q_DSR_GETSITENAME structure.
3621 ********************************************************************/
3623 void init_net_q_dsr_getsitename(NET_Q_DSR_GETSITENAME *r_t, const char *computer_name)
3625 DEBUG(5, ("init_net_q_dsr_getsitename\n"));
3627 r_t->ptr_computer_name = (computer_name != NULL);
3628 init_unistr2(&r_t->uni_computer_name, computer_name, UNI_STR_TERMINATE);
3631 /*******************************************************************
3632 Reads or writes an NET_Q_DSR_GETSITENAME structure.
3633 ********************************************************************/
3635 BOOL net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
3636 prs_struct *ps, int depth)
3638 if (r_t == NULL)
3639 return False;
3641 prs_debug(ps, depth, desc, "net_io_q_dsr_getsitename");
3642 depth++;
3644 if (!prs_uint32("ptr_computer_name", ps, depth, &r_t->ptr_computer_name))
3645 return False;
3647 if (!smb_io_unistr2("computer_name", &r_t->uni_computer_name,
3648 r_t->ptr_computer_name, ps, depth))
3649 return False;
3651 if (!prs_align(ps))
3652 return False;
3654 return True;
3657 /*******************************************************************
3658 Reads or writes an NET_R_DSR_GETSITENAME structure.
3659 ********************************************************************/
3661 BOOL net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t,
3662 prs_struct *ps, int depth)
3664 if (r_t == NULL)
3665 return False;
3667 prs_debug(ps, depth, desc, "net_io_r_dsr_getsitename");
3668 depth++;
3670 if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
3671 return False;
3673 if (!prs_align(ps))
3674 return False;
3676 if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
3677 r_t->ptr_site_name, ps, depth))
3678 return False;
3680 if (!prs_align(ps))
3681 return False;
3683 if (!prs_werror("result", ps, depth, &r_t->result))
3684 return False;
3686 return True;