At the prompting, start to add infrastructure to detect the presence of
[Samba/gebeck_regimport.git] / source3 / rpc_parse / parse_samr.c
blob918cdbcd1dfbf1c190bdcb8776ce6c9db6f5c655
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Paul Ashton 1997-2000,
7 * Copyright (C) Elrond 2000,
8 * Copyright (C) Jeremy Allison 2001,
9 * Copyright (C) Jean François Micouleau 1998-2001,
10 * Copyright (C) Anthony Liguori 2002,
11 * Copyright (C) Jim McDonough 2002.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "includes.h"
29 #include "rpc_parse.h"
30 #include "nterr.h"
32 #undef DBGC_CLASS
33 #define DBGC_CLASS DBGC_RPC_PARSE
35 /*******************************************************************
36 inits a SAMR_Q_CLOSE_HND structure.
37 ********************************************************************/
39 void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd)
41 DEBUG(5, ("init_samr_q_close_hnd\n"));
43 q_c->pol = *hnd;
46 /*******************************************************************
47 reads or writes a structure.
48 ********************************************************************/
50 BOOL samr_io_q_close_hnd(const char *desc, SAMR_Q_CLOSE_HND * q_u,
51 prs_struct *ps, int depth)
53 if (q_u == NULL)
54 return False;
56 prs_debug(ps, depth, desc, "samr_io_q_close_hnd");
57 depth++;
59 if(!prs_align(ps))
60 return False;
62 return smb_io_pol_hnd("pol", &q_u->pol, ps, depth);
65 /*******************************************************************
66 reads or writes a structure.
67 ********************************************************************/
69 BOOL samr_io_r_close_hnd(const char *desc, SAMR_R_CLOSE_HND * r_u,
70 prs_struct *ps, int depth)
72 if (r_u == NULL)
73 return False;
75 prs_debug(ps, depth, desc, "samr_io_r_close_hnd");
76 depth++;
78 if(!prs_align(ps))
79 return False;
81 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
82 return False;
84 if(!prs_ntstatus("status", ps, depth, &r_u->status))
85 return False;
87 return True;
90 /*******************************************************************
91 inits a SAMR_Q_LOOKUP_DOMAIN structure.
92 ********************************************************************/
94 void init_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN * q_u,
95 POLICY_HND *pol, char *dom_name)
97 int len_name = strlen(dom_name);
99 DEBUG(5, ("init_samr_q_lookup_domain\n"));
101 q_u->connect_pol = *pol;
103 init_uni_hdr(&q_u->hdr_domain, len_name);
104 init_unistr2(&q_u->uni_domain, dom_name, len_name);
107 /*******************************************************************
108 reads or writes a structure.
109 ********************************************************************/
110 BOOL samr_io_q_lookup_domain(const char *desc, SAMR_Q_LOOKUP_DOMAIN * q_u,
111 prs_struct *ps, int depth)
113 if (q_u == NULL)
114 return False;
116 prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
117 depth++;
119 if(!prs_align(ps))
120 return False;
122 if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth))
123 return False;
125 if(!smb_io_unihdr("hdr_domain", &q_u->hdr_domain, ps, depth))
126 return False;
128 if(!smb_io_unistr2("uni_domain", &q_u->uni_domain, q_u->hdr_domain.buffer, ps, depth))
129 return False;
131 return True;
134 /*******************************************************************
135 inits a SAMR_R_LOOKUP_DOMAIN structure.
136 ********************************************************************/
138 void init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
139 DOM_SID *dom_sid, NTSTATUS status)
141 DEBUG(5, ("init_samr_r_lookup_domain\n"));
143 r_u->status = status;
144 r_u->ptr_sid = 0;
145 if (NT_STATUS_IS_OK(status)) {
146 r_u->ptr_sid = 1;
147 init_dom_sid2(&r_u->dom_sid, dom_sid);
151 /*******************************************************************
152 reads or writes a structure.
153 ********************************************************************/
155 BOOL samr_io_r_lookup_domain(const char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
156 prs_struct *ps, int depth)
158 if (r_u == NULL)
159 return False;
161 prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
162 depth++;
164 if(!prs_align(ps))
165 return False;
167 if(!prs_uint32("ptr", ps, depth, &r_u->ptr_sid))
168 return False;
170 if (r_u->ptr_sid != 0) {
171 if(!smb_io_dom_sid2("sid", &r_u->dom_sid, ps, depth))
172 return False;
173 if(!prs_align(ps))
174 return False;
177 if(!prs_ntstatus("status", ps, depth, &r_u->status))
178 return False;
180 return True;
183 /*******************************************************************
184 reads or writes a structure.
185 ********************************************************************/
187 void init_samr_q_unknown_2d(SAMR_Q_UNKNOWN_2D * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
189 DEBUG(5, ("samr_init_samr_q_unknown_2d\n"));
191 q_u->dom_pol = *dom_pol;
192 init_dom_sid2(&q_u->sid, sid);
195 /*******************************************************************
196 reads or writes a structure.
197 ********************************************************************/
199 BOOL samr_io_q_unknown_2d(const char *desc, SAMR_Q_UNKNOWN_2D * q_u,
200 prs_struct *ps, int depth)
202 if (q_u == NULL)
203 return False;
205 prs_debug(ps, depth, desc, "samr_io_q_unknown_2d");
206 depth++;
208 if(!prs_align(ps))
209 return False;
211 if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
212 return False;
214 if(!smb_io_dom_sid2("sid", &q_u->sid, ps, depth))
215 return False;
217 if(!prs_align(ps))
218 return False;
220 return True;
223 /*******************************************************************
224 reads or writes a structure.
225 ********************************************************************/
227 BOOL samr_io_r_unknown_2d(const char *desc, SAMR_R_UNKNOWN_2D * r_u,
228 prs_struct *ps, int depth)
230 if (r_u == NULL)
231 return False;
233 prs_debug(ps, depth, desc, "samr_io_r_unknown_2d");
234 depth++;
236 if(!prs_align(ps))
237 return False;
239 if(!prs_ntstatus("status", ps, depth, &r_u->status))
240 return False;
242 return True;
245 /*******************************************************************
246 reads or writes a structure.
247 ********************************************************************/
249 void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u,
250 POLICY_HND *pol, uint32 flags,
251 const DOM_SID *sid)
253 DEBUG(5, ("samr_init_samr_q_open_domain\n"));
255 q_u->pol = *pol;
256 q_u->flags = flags;
257 init_dom_sid2(&q_u->dom_sid, sid);
260 /*******************************************************************
261 reads or writes a structure.
262 ********************************************************************/
264 BOOL samr_io_q_open_domain(const char *desc, SAMR_Q_OPEN_DOMAIN * q_u,
265 prs_struct *ps, int depth)
267 if (q_u == NULL)
268 return False;
270 prs_debug(ps, depth, desc, "samr_io_q_open_domain");
271 depth++;
273 if(!prs_align(ps))
274 return False;
276 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
277 return False;
279 if(!prs_uint32("flags", ps, depth, &q_u->flags))
280 return False;
282 if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth))
283 return False;
285 return True;
288 /*******************************************************************
289 reads or writes a structure.
290 ********************************************************************/
292 BOOL samr_io_r_open_domain(const char *desc, SAMR_R_OPEN_DOMAIN * r_u,
293 prs_struct *ps, int depth)
295 if (r_u == NULL)
296 return False;
298 prs_debug(ps, depth, desc, "samr_io_r_open_domain");
299 depth++;
301 if(!prs_align(ps))
302 return False;
304 if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth))
305 return False;
307 if(!prs_ntstatus("status", ps, depth, &r_u->status))
308 return False;
310 return True;
313 /*******************************************************************
314 reads or writes a structure.
315 ********************************************************************/
317 void init_samr_q_get_usrdom_pwinfo(SAMR_Q_GET_USRDOM_PWINFO * q_u,
318 POLICY_HND *user_pol)
320 DEBUG(5, ("samr_init_samr_q_get_usrdom_pwinfo\n"));
322 q_u->user_pol = *user_pol;
325 /*******************************************************************
326 reads or writes a structure.
327 ********************************************************************/
329 BOOL samr_io_q_get_usrdom_pwinfo(const char *desc, SAMR_Q_GET_USRDOM_PWINFO * q_u,
330 prs_struct *ps, int depth)
332 if (q_u == NULL)
333 return False;
335 prs_debug(ps, depth, desc, "samr_io_q_get_usrdom_pwinfo");
336 depth++;
338 if(!prs_align(ps))
339 return False;
341 return smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth);
344 /*******************************************************************
345 Init.
346 ********************************************************************/
348 void init_samr_r_get_usrdom_pwinfo(SAMR_R_GET_USRDOM_PWINFO *r_u, NTSTATUS status)
350 DEBUG(5, ("init_samr_r_get_usrdom_pwinfo\n"));
352 r_u->unknown_0 = 0x0000;
355 * used to be
356 * r_u->unknown_1 = 0x0015;
357 * but for trusts.
359 r_u->unknown_1 = 0x01D1;
360 r_u->unknown_1 = 0x0015;
362 r_u->unknown_2 = 0x00000000;
364 r_u->status = status;
367 /*******************************************************************
368 reads or writes a structure.
369 ********************************************************************/
371 BOOL samr_io_r_get_usrdom_pwinfo(const char *desc, SAMR_R_GET_USRDOM_PWINFO * r_u,
372 prs_struct *ps, int depth)
374 if (r_u == NULL)
375 return False;
377 prs_debug(ps, depth, desc, "samr_io_r_get_usrdom_pwinfo");
378 depth++;
380 if(!prs_align(ps))
381 return False;
383 if(!prs_uint16("unknown_0", ps, depth, &r_u->unknown_0))
384 return False;
385 if(!prs_uint16("unknown_1", ps, depth, &r_u->unknown_1))
386 return False;
387 if(!prs_uint32("unknown_2", ps, depth, &r_u->unknown_2))
388 return False;
389 if(!prs_ntstatus("status ", ps, depth, &r_u->status))
390 return False;
392 return True;
396 /*******************************************************************
397 reads or writes a structure.
398 ********************************************************************/
400 BOOL samr_io_q_set_sec_obj(const char *desc, SAMR_Q_SET_SEC_OBJ * q_u,
401 prs_struct *ps, int depth)
403 if (q_u == NULL)
404 return False;
406 prs_debug(ps, depth, desc, "samr_io_q_set_sec_obj");
407 depth++;
409 if(!prs_align(ps))
410 return False;
412 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
413 return False;
415 if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
416 return False;
418 if(!sec_io_desc_buf("sec_desc", &q_u->buf, ps, depth))
419 return False;
421 return True;
425 /*******************************************************************
426 reads or writes a structure.
427 ********************************************************************/
429 void init_samr_q_query_sec_obj(SAMR_Q_QUERY_SEC_OBJ * q_u,
430 POLICY_HND *user_pol, uint32 sec_info)
432 DEBUG(5, ("samr_init_samr_q_query_sec_obj\n"));
434 q_u->user_pol = *user_pol;
435 q_u->sec_info = sec_info;
439 /*******************************************************************
440 reads or writes a structure.
441 ********************************************************************/
443 BOOL samr_io_q_query_sec_obj(const char *desc, SAMR_Q_QUERY_SEC_OBJ * q_u,
444 prs_struct *ps, int depth)
446 if (q_u == NULL)
447 return False;
449 prs_debug(ps, depth, desc, "samr_io_q_query_sec_obj");
450 depth++;
452 if(!prs_align(ps))
453 return False;
455 if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
456 return False;
458 if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
459 return False;
461 return True;
464 /*******************************************************************
465 reads or writes a structure.
466 ********************************************************************/
468 void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO * q_u,
469 POLICY_HND *domain_pol, uint16 switch_value)
471 DEBUG(5, ("samr_init_samr_q_query_dom_info\n"));
473 q_u->domain_pol = *domain_pol;
474 q_u->switch_value = switch_value;
477 /*******************************************************************
478 reads or writes a structure.
479 ********************************************************************/
481 BOOL samr_io_q_query_dom_info(const char *desc, SAMR_Q_QUERY_DOMAIN_INFO * q_u,
482 prs_struct *ps, int depth)
484 if (q_u == NULL)
485 return False;
487 prs_debug(ps, depth, desc, "samr_io_q_query_dom_info");
488 depth++;
490 if(!prs_align(ps))
491 return False;
493 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
494 return False;
496 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
497 return False;
499 return True;
503 /*******************************************************************
504 inits a structure.
505 ********************************************************************/
507 void init_unk_info3(SAM_UNK_INFO_3 *u_3, NTTIME nt_logout)
509 u_3->logout.low = nt_logout.low;
510 u_3->logout.high = nt_logout.high;
513 /*******************************************************************
514 reads or writes a structure.
515 ********************************************************************/
517 static BOOL sam_io_unk_info3(const char *desc, SAM_UNK_INFO_3 * u_3,
518 prs_struct *ps, int depth)
520 if (u_3 == NULL)
521 return False;
523 prs_debug(ps, depth, desc, "sam_io_unk_info3");
524 depth++;
526 if(!smb_io_time("logout", &u_3->logout, ps, depth))
527 return False;
529 return True;
532 /*******************************************************************
533 inits a structure.
534 ********************************************************************/
536 void init_unk_info6(SAM_UNK_INFO_6 * u_6)
538 u_6->unknown_0 = 0x00000000;
539 u_6->ptr_0 = 1;
540 memset(u_6->padding, 0, sizeof(u_6->padding)); /* 12 bytes zeros */
543 /*******************************************************************
544 reads or writes a structure.
545 ********************************************************************/
547 static BOOL sam_io_unk_info6(const char *desc, SAM_UNK_INFO_6 * u_6,
548 prs_struct *ps, int depth)
550 if (u_6 == NULL)
551 return False;
553 prs_debug(ps, depth, desc, "sam_io_unk_info6");
554 depth++;
556 if(!prs_uint32("unknown_0", ps, depth, &u_6->unknown_0)) /* 0x0000 0000 */
557 return False;
558 if(!prs_uint32("ptr_0", ps, depth, &u_6->ptr_0)) /* pointer to unknown structure */
559 return False;
560 if(!prs_uint8s(False, "padding", ps, depth, u_6->padding, sizeof(u_6->padding))) /* 12 bytes zeros */
561 return False;
563 return True;
566 /*******************************************************************
567 inits a structure.
568 ********************************************************************/
570 void init_unk_info7(SAM_UNK_INFO_7 * u_7)
572 u_7->unknown_0 = 0x0003;
575 /*******************************************************************
576 reads or writes a structure.
577 ********************************************************************/
579 static BOOL sam_io_unk_info7(const char *desc, SAM_UNK_INFO_7 * u_7,
580 prs_struct *ps, int depth)
582 if (u_7 == NULL)
583 return False;
585 prs_debug(ps, depth, desc, "sam_io_unk_info7");
586 depth++;
588 if(!prs_uint16("unknown_0", ps, depth, &u_7->unknown_0)) /* 0x0003 */
589 return False;
591 return True;
594 /*******************************************************************
595 inits a structure.
596 ********************************************************************/
598 void init_unk_info12(SAM_UNK_INFO_12 * u_12, NTTIME nt_lock_duration, NTTIME nt_reset_time, uint16 lockout)
600 u_12->duration.low = nt_lock_duration.low;
601 u_12->duration.high = nt_lock_duration.high;
602 u_12->reset_count.low = nt_reset_time.low;
603 u_12->reset_count.high = nt_reset_time.high;
605 u_12->bad_attempt_lockout = lockout;
608 /*******************************************************************
609 reads or writes a structure.
610 ********************************************************************/
612 static BOOL sam_io_unk_info12(const char *desc, SAM_UNK_INFO_12 * u_12,
613 prs_struct *ps, int depth)
615 if (u_12 == NULL)
616 return False;
618 prs_debug(ps, depth, desc, "sam_io_unk_info12");
619 depth++;
621 if(!smb_io_time("duration", &u_12->duration, ps, depth))
622 return False;
623 if(!smb_io_time("reset_count", &u_12->reset_count, ps, depth))
624 return False;
625 if(!prs_uint16("bad_attempt_lockout", ps, depth, &u_12->bad_attempt_lockout))
626 return False;
628 return True;
631 /*******************************************************************
632 inits a structure.
633 ********************************************************************/
634 void init_unk_info5(SAM_UNK_INFO_5 * u_5,const char *server)
636 int len_server = strlen(server);
638 init_uni_hdr(&u_5->hdr_server, len_server);
640 init_unistr2(&u_5->uni_server, server, len_server);
643 /*******************************************************************
644 reads or writes a structure.
645 ********************************************************************/
647 static BOOL sam_io_unk_info5(const char *desc, SAM_UNK_INFO_5 * u_5,
648 prs_struct *ps, int depth)
650 if (u_5 == NULL)
651 return False;
653 prs_debug(ps, depth, desc, "sam_io_unk_info5");
654 depth++;
656 if(!smb_io_unihdr("hdr_server", &u_5->hdr_server, ps, depth))
657 return False;
659 if(!smb_io_unistr2("uni_server", &u_5->uni_server, u_5->hdr_server.buffer, ps, depth))
660 return False;
662 return True;
665 /*******************************************************************
666 inits a structure.
667 ********************************************************************/
668 void init_unk_info2(SAM_UNK_INFO_2 * u_2,
669 const char *domain, const char *server,
670 uint32 seq_num, uint32 num_users, uint32 num_groups, uint32 num_alias)
672 int len_domain = strlen(domain);
673 int len_server = strlen(server);
675 u_2->unknown_0 = 0x00000000;
676 u_2->unknown_1 = 0x80000000;
677 u_2->unknown_2 = 0x00000000;
679 u_2->ptr_0 = 1;
680 init_uni_hdr(&u_2->hdr_domain, len_domain);
681 init_uni_hdr(&u_2->hdr_server, len_server);
683 u_2->seq_num = seq_num;
684 u_2->unknown_3 = 0x00000000;
686 u_2->unknown_4 = 0x00000001;
687 u_2->unknown_5 = 0x00000003;
688 u_2->unknown_6 = 0x00000001;
689 u_2->num_domain_usrs = num_users;
690 u_2->num_domain_grps = num_groups;
691 u_2->num_local_grps = num_alias;
693 memset(u_2->padding, 0, sizeof(u_2->padding)); /* 12 bytes zeros */
695 init_unistr2(&u_2->uni_domain, domain, len_domain);
696 init_unistr2(&u_2->uni_server, server, len_server);
699 /*******************************************************************
700 reads or writes a structure.
701 ********************************************************************/
703 static BOOL sam_io_unk_info2(const char *desc, SAM_UNK_INFO_2 * u_2,
704 prs_struct *ps, int depth)
706 if (u_2 == NULL)
707 return False;
709 prs_debug(ps, depth, desc, "sam_io_unk_info2");
710 depth++;
712 if(!prs_uint32("unknown_0", ps, depth, &u_2->unknown_0)) /* 0x0000 0000 */
713 return False;
714 if(!prs_uint32("unknown_1", ps, depth, &u_2->unknown_1)) /* 0x8000 0000 */
715 return False;
716 if(!prs_uint32("unknown_2", ps, depth, &u_2->unknown_2)) /* 0x0000 0000 */
717 return False;
719 if(!prs_uint32("ptr_0", ps, depth, &u_2->ptr_0))
720 return False;
721 if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth))
722 return False;
723 if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth))
724 return False;
726 /* put all the data in here, at the moment, including what the above
727 pointer is referring to
730 if(!prs_uint32("seq_num ", ps, depth, &u_2->seq_num)) /* 0x0000 0099 or 0x1000 0000 */
731 return False;
732 if(!prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3)) /* 0x0000 0000 */
733 return False;
735 if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4)) /* 0x0000 0001 */
736 return False;
737 if(!prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5)) /* 0x0000 0003 */
738 return False;
739 if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6)) /* 0x0000 0001 */
740 return False;
741 if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs))
742 return False;
743 if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps))
744 return False;
745 if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps))
746 return False;
748 if (u_2->ptr_0) {
749 /* this was originally marked as 'padding'. It isn't
750 padding, it is some sort of optional 12 byte
751 structure. When it is present it contains zeros
752 !? */
753 if(!prs_uint8s(False, "unknown", ps, depth, u_2->padding,sizeof(u_2->padding)))
754 return False;
757 if(!smb_io_unistr2("uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth))
758 return False;
759 if(!smb_io_unistr2("uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth))
760 return False;
762 return True;
765 /*******************************************************************
766 inits a structure.
767 ********************************************************************/
769 void init_unk_info1(SAM_UNK_INFO_1 *u_1, uint16 min_pass_len, uint16 pass_hist,
770 uint32 flag, NTTIME nt_expire, NTTIME nt_min_age)
772 u_1->min_length_password = min_pass_len;
773 u_1->password_history = pass_hist;
774 u_1->flag = flag;
776 /* password never expire */
777 u_1->expire.high = nt_expire.high;
778 u_1->expire.low = nt_expire.low;
780 /* can change the password now */
781 u_1->min_passwordage.high = nt_min_age.high;
782 u_1->min_passwordage.low = nt_min_age.low;
786 /*******************************************************************
787 reads or writes a structure.
788 ********************************************************************/
790 static BOOL sam_io_unk_info1(const char *desc, SAM_UNK_INFO_1 * u_1,
791 prs_struct *ps, int depth)
793 if (u_1 == NULL)
794 return False;
796 prs_debug(ps, depth, desc, "sam_io_unk_info1");
797 depth++;
799 if(!prs_uint16("min_length_password", ps, depth, &u_1->min_length_password))
800 return False;
801 if(!prs_uint16("password_history", ps, depth, &u_1->password_history))
802 return False;
803 if(!prs_uint32("flag", ps, depth, &u_1->flag))
804 return False;
805 if(!smb_io_time("expire", &u_1->expire, ps, depth))
806 return False;
807 if(!smb_io_time("min_passwordage", &u_1->min_passwordage, ps, depth))
808 return False;
810 return True;
813 /*******************************************************************
814 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
815 ********************************************************************/
817 void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO * r_u,
818 uint16 switch_value, SAM_UNK_CTR * ctr,
819 NTSTATUS status)
821 DEBUG(5, ("init_samr_r_query_dom_info\n"));
823 r_u->ptr_0 = 0;
824 r_u->switch_value = 0;
825 r_u->status = status; /* return status */
827 if (NT_STATUS_IS_OK(status)) {
828 r_u->switch_value = switch_value;
829 r_u->ptr_0 = 1;
830 r_u->ctr = ctr;
834 /*******************************************************************
835 reads or writes a structure.
836 ********************************************************************/
838 BOOL samr_io_r_query_dom_info(const char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u,
839 prs_struct *ps, int depth)
841 if (r_u == NULL)
842 return False;
844 prs_debug(ps, depth, desc, "samr_io_r_query_dom_info");
845 depth++;
847 if(!prs_align(ps))
848 return False;
850 if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
851 return False;
853 if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
854 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
855 return False;
856 if(!prs_align(ps))
857 return False;
859 switch (r_u->switch_value) {
860 case 0x0c:
861 if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
862 return False;
863 break;
864 case 0x07:
865 if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
866 return False;
867 break;
868 case 0x06:
869 if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
870 return False;
871 break;
872 case 0x05:
873 if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
874 return False;
875 break;
876 case 0x03:
877 if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
878 return False;
879 break;
880 case 0x02:
881 if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
882 return False;
883 break;
884 case 0x01:
885 if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
886 return False;
887 break;
888 default:
889 DEBUG(0, ("samr_io_r_query_dom_info: unknown switch level 0x%x\n",
890 r_u->switch_value));
891 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
892 return False;
896 if(!prs_align(ps))
897 return False;
899 if(!prs_ntstatus("status", ps, depth, &r_u->status))
900 return False;
902 return True;
905 /*******************************************************************
906 reads or writes a SAMR_R_SET_SEC_OBJ structure.
907 ********************************************************************/
909 BOOL samr_io_r_set_sec_obj(const char *desc, SAMR_R_SET_SEC_OBJ * r_u,
910 prs_struct *ps, int depth)
912 if (r_u == NULL)
913 return False;
915 prs_debug(ps, depth, desc, "samr_io_r_set_sec_obj");
916 depth++;
918 if(!prs_align(ps))
919 return False;
921 if(!prs_ntstatus("status", ps, depth, &r_u->status))
922 return False;
924 return True;
927 /*******************************************************************
928 reads or writes a SAMR_R_QUERY_SEC_OBJ structure.
929 ********************************************************************/
931 BOOL samr_io_r_query_sec_obj(const char *desc, SAMR_R_QUERY_SEC_OBJ * r_u,
932 prs_struct *ps, int depth)
934 if (r_u == NULL)
935 return False;
937 prs_debug(ps, depth, desc, "samr_io_r_query_sec_obj");
938 depth++;
940 if(!prs_align(ps))
941 return False;
943 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
944 return False;
945 if (r_u->ptr != 0) {
946 if(!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
947 return False;
950 if(!prs_ntstatus("status", ps, depth, &r_u->status))
951 return False;
953 return True;
956 /*******************************************************************
957 reads or writes a SAM_STR1 structure.
958 ********************************************************************/
960 static BOOL sam_io_sam_str1(const char *desc, SAM_STR1 * sam, uint32 acct_buf,
961 uint32 name_buf, uint32 desc_buf,
962 prs_struct *ps, int depth)
964 if (sam == NULL)
965 return False;
967 prs_debug(ps, depth, desc, "sam_io_sam_str1");
968 depth++;
970 if(!prs_align(ps))
971 return False;
972 if (!smb_io_unistr2("name", &sam->uni_acct_name, acct_buf, ps, depth))
973 return False;
975 if (!smb_io_unistr2("desc", &sam->uni_acct_desc, desc_buf, ps, depth))
976 return False;
978 if (!smb_io_unistr2("full", &sam->uni_full_name, name_buf, ps, depth))
979 return False;
981 return True;
984 /*******************************************************************
985 inits a SAM_ENTRY1 structure.
986 ********************************************************************/
988 static void init_sam_entry1(SAM_ENTRY1 * sam, uint32 user_idx,
989 uint32 len_sam_name, uint32 len_sam_full,
990 uint32 len_sam_desc, uint32 rid_user,
991 uint16 acb_info)
993 DEBUG(5, ("init_sam_entry1\n"));
995 ZERO_STRUCTP(sam);
997 sam->user_idx = user_idx;
998 sam->rid_user = rid_user;
999 sam->acb_info = acb_info;
1001 init_uni_hdr(&sam->hdr_acct_name, len_sam_name);
1002 init_uni_hdr(&sam->hdr_user_name, len_sam_full);
1003 init_uni_hdr(&sam->hdr_user_desc, len_sam_desc);
1006 /*******************************************************************
1007 reads or writes a SAM_ENTRY1 structure.
1008 ********************************************************************/
1010 static BOOL sam_io_sam_entry1(const char *desc, SAM_ENTRY1 * sam,
1011 prs_struct *ps, int depth)
1013 if (sam == NULL)
1014 return False;
1016 prs_debug(ps, depth, desc, "sam_io_sam_entry1");
1017 depth++;
1019 if(!prs_align(ps))
1020 return False;
1022 if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1023 return False;
1025 if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1026 return False;
1027 if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info))
1028 return False;
1030 if(!prs_align(ps))
1031 return False;
1033 if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
1034 return False;
1035 if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
1036 return False;
1037 if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
1038 return False;
1040 return True;
1043 /*******************************************************************
1044 reads or writes a SAM_STR2 structure.
1045 ********************************************************************/
1047 static BOOL sam_io_sam_str2(const char *desc, SAM_STR2 * sam, uint32 acct_buf,
1048 uint32 desc_buf, prs_struct *ps, int depth)
1050 if (sam == NULL)
1051 return False;
1053 prs_debug(ps, depth, desc, "sam_io_sam_str2");
1054 depth++;
1056 if(!prs_align(ps))
1057 return False;
1059 if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
1060 return False;
1061 if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth)) /* account desc unicode string */
1062 return False;
1064 return True;
1067 /*******************************************************************
1068 inits a SAM_ENTRY2 structure.
1069 ********************************************************************/
1070 static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
1071 uint32 len_sam_name, uint32 len_sam_desc,
1072 uint32 rid_user, uint16 acb_info)
1074 DEBUG(5, ("init_sam_entry2\n"));
1076 sam->user_idx = user_idx;
1077 sam->rid_user = rid_user;
1078 sam->acb_info = acb_info;
1080 init_uni_hdr(&sam->hdr_srv_name, len_sam_name);
1081 init_uni_hdr(&sam->hdr_srv_desc, len_sam_desc);
1084 /*******************************************************************
1085 reads or writes a SAM_ENTRY2 structure.
1086 ********************************************************************/
1088 static BOOL sam_io_sam_entry2(const char *desc, SAM_ENTRY2 * sam,
1089 prs_struct *ps, int depth)
1091 if (sam == NULL)
1092 return False;
1094 prs_debug(ps, depth, desc, "sam_io_sam_entry2");
1095 depth++;
1097 if(!prs_align(ps))
1098 return False;
1100 if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1101 return False;
1103 if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1104 return False;
1105 if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info))
1106 return False;
1108 if(!prs_align(ps))
1109 return False;
1111 if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth)) /* account name unicode string header */
1112 return False;
1113 if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth)) /* account name unicode string header */
1114 return False;
1116 return True;
1119 /*******************************************************************
1120 reads or writes a SAM_STR3 structure.
1121 ********************************************************************/
1123 static BOOL sam_io_sam_str3(const char *desc, SAM_STR3 * sam, uint32 acct_buf,
1124 uint32 desc_buf, prs_struct *ps, int depth)
1126 if (sam == NULL)
1127 return False;
1129 prs_debug(ps, depth, desc, "sam_io_sam_str3");
1130 depth++;
1132 if(!prs_align(ps))
1133 return False;
1135 if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth)) /* account name unicode string */
1136 return False;
1137 if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth)) /* account desc unicode string */
1138 return False;
1140 return True;
1143 /*******************************************************************
1144 inits a SAM_ENTRY3 structure.
1145 ********************************************************************/
1147 static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
1148 uint32 len_grp_name, uint32 len_grp_desc,
1149 uint32 rid_grp)
1151 DEBUG(5, ("init_sam_entry3\n"));
1153 sam->grp_idx = grp_idx;
1154 sam->rid_grp = rid_grp;
1155 sam->attr = 0x07; /* group rid attributes - gets ignored by nt 4.0 */
1157 init_uni_hdr(&sam->hdr_grp_name, len_grp_name);
1158 init_uni_hdr(&sam->hdr_grp_desc, len_grp_desc);
1161 /*******************************************************************
1162 reads or writes a SAM_ENTRY3 structure.
1163 ********************************************************************/
1165 static BOOL sam_io_sam_entry3(const char *desc, SAM_ENTRY3 * sam,
1166 prs_struct *ps, int depth)
1168 if (sam == NULL)
1169 return False;
1171 prs_debug(ps, depth, desc, "sam_io_sam_entry3");
1172 depth++;
1174 if(!prs_align(ps))
1175 return False;
1177 if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1178 return False;
1180 if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp))
1181 return False;
1182 if(!prs_uint32("attr ", ps, depth, &sam->attr))
1183 return False;
1185 if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth)) /* account name unicode string header */
1186 return False;
1187 if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth)) /* account name unicode string header */
1188 return False;
1190 return True;
1193 /*******************************************************************
1194 inits a SAM_ENTRY4 structure.
1195 ********************************************************************/
1197 static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
1198 uint32 len_acct_name)
1200 DEBUG(5, ("init_sam_entry4\n"));
1202 sam->user_idx = user_idx;
1203 init_str_hdr(&sam->hdr_acct_name, len_acct_name+1, len_acct_name, len_acct_name != 0);
1206 /*******************************************************************
1207 reads or writes a SAM_ENTRY4 structure.
1208 ********************************************************************/
1210 static BOOL sam_io_sam_entry4(const char *desc, SAM_ENTRY4 * sam,
1211 prs_struct *ps, int depth)
1213 if (sam == NULL)
1214 return False;
1216 prs_debug(ps, depth, desc, "sam_io_sam_entry4");
1217 depth++;
1219 if(!prs_align(ps))
1220 return False;
1222 if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
1223 return False;
1224 if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
1225 return False;
1227 return True;
1230 /*******************************************************************
1231 inits a SAM_ENTRY5 structure.
1232 ********************************************************************/
1234 static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
1235 uint32 len_grp_name)
1237 DEBUG(5, ("init_sam_entry5\n"));
1239 sam->grp_idx = grp_idx;
1240 init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
1241 len_grp_name != 0);
1244 /*******************************************************************
1245 reads or writes a SAM_ENTRY5 structure.
1246 ********************************************************************/
1248 static BOOL sam_io_sam_entry5(const char *desc, SAM_ENTRY5 * sam,
1249 prs_struct *ps, int depth)
1251 if (sam == NULL)
1252 return False;
1254 prs_debug(ps, depth, desc, "sam_io_sam_entry5");
1255 depth++;
1257 if(!prs_align(ps))
1258 return False;
1260 if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1261 return False;
1262 if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
1263 return False;
1265 return True;
1268 /*******************************************************************
1269 inits a SAM_ENTRY structure.
1270 ********************************************************************/
1272 void init_sam_entry(SAM_ENTRY * sam, uint32 len_sam_name, uint32 rid)
1274 DEBUG(10, ("init_sam_entry: %d %d\n", len_sam_name, rid));
1276 sam->rid = rid;
1277 init_uni_hdr(&sam->hdr_name, len_sam_name);
1280 /*******************************************************************
1281 reads or writes a SAM_ENTRY structure.
1282 ********************************************************************/
1284 static BOOL sam_io_sam_entry(const char *desc, SAM_ENTRY * sam,
1285 prs_struct *ps, int depth)
1287 if (sam == NULL)
1288 return False;
1290 prs_debug(ps, depth, desc, "sam_io_sam_entry");
1291 depth++;
1293 if(!prs_align(ps))
1294 return False;
1295 if(!prs_uint32("rid", ps, depth, &sam->rid))
1296 return False;
1297 if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
1298 return False;
1300 return True;
1303 /*******************************************************************
1304 inits a SAMR_Q_ENUM_DOM_USERS structure.
1305 ********************************************************************/
1307 void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
1308 uint32 start_idx,
1309 uint16 acb_mask, uint16 unk_1, uint32 size)
1311 DEBUG(5, ("init_samr_q_enum_dom_users\n"));
1313 q_e->pol = *pol;
1315 q_e->start_idx = start_idx; /* zero indicates lots */
1316 q_e->acb_mask = acb_mask;
1317 q_e->unknown_1 = unk_1;
1318 q_e->max_size = size;
1321 /*******************************************************************
1322 reads or writes a structure.
1323 ********************************************************************/
1325 BOOL samr_io_q_enum_dom_users(const char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
1326 prs_struct *ps, int depth)
1328 if (q_e == NULL)
1329 return False;
1331 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
1332 depth++;
1334 if(!prs_align(ps))
1335 return False;
1337 if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
1338 return False;
1340 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1341 return False;
1342 if(!prs_uint16("acb_mask ", ps, depth, &q_e->acb_mask))
1343 return False;
1344 if(!prs_uint16("unknown_1", ps, depth, &q_e->unknown_1))
1345 return False;
1347 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1348 return False;
1350 return True;
1354 /*******************************************************************
1355 inits a SAMR_R_ENUM_DOM_USERS structure.
1356 ********************************************************************/
1358 void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
1359 uint32 next_idx, uint32 num_sam_entries)
1361 DEBUG(5, ("init_samr_r_enum_dom_users\n"));
1363 r_u->next_idx = next_idx;
1365 if (num_sam_entries != 0) {
1366 r_u->ptr_entries1 = 1;
1367 r_u->ptr_entries2 = 1;
1368 r_u->num_entries2 = num_sam_entries;
1369 r_u->num_entries3 = num_sam_entries;
1371 r_u->num_entries4 = num_sam_entries;
1372 } else {
1373 r_u->ptr_entries1 = 0;
1374 r_u->num_entries2 = num_sam_entries;
1375 r_u->ptr_entries2 = 1;
1379 /*******************************************************************
1380 reads or writes a structure.
1381 ********************************************************************/
1383 BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
1384 prs_struct *ps, int depth)
1386 uint32 i;
1388 if (r_u == NULL)
1389 return False;
1391 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
1392 depth++;
1394 if(!prs_align(ps))
1395 return False;
1397 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
1398 return False;
1399 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1400 return False;
1402 if (r_u->ptr_entries1 != 0) {
1403 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1404 return False;
1405 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1406 return False;
1407 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1408 return False;
1410 if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1411 r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
1412 r_u->uni_acct_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
1415 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
1416 DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
1417 r_u->num_entries4 = 0;
1418 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
1419 return False;
1422 for (i = 0; i < r_u->num_entries2; i++) {
1423 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
1424 return False;
1427 for (i = 0; i < r_u->num_entries2; i++) {
1428 if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
1429 return False;
1434 if(!prs_align(ps))
1435 return False;
1437 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
1438 return False;
1439 if(!prs_ntstatus("status", ps, depth, &r_u->status))
1440 return False;
1442 return True;
1445 /*******************************************************************
1446 inits a SAMR_Q_QUERY_DISPINFO structure.
1447 ********************************************************************/
1449 void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
1450 uint16 switch_level, uint32 start_idx,
1451 uint32 max_entries)
1453 DEBUG(5, ("init_samr_q_query_dispinfo\n"));
1455 q_e->domain_pol = *pol;
1457 q_e->switch_level = switch_level;
1459 q_e->start_idx = start_idx;
1460 q_e->max_entries = max_entries;
1461 q_e->max_size = 0xffff; /* Not especially useful */
1464 /*******************************************************************
1465 reads or writes a structure.
1466 ********************************************************************/
1468 BOOL samr_io_q_query_dispinfo(const char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
1469 prs_struct *ps, int depth)
1471 if (q_e == NULL)
1472 return False;
1474 prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1475 depth++;
1477 if(!prs_align(ps))
1478 return False;
1480 if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
1481 return False;
1483 if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
1484 return False;
1485 if(!prs_align(ps))
1486 return False;
1488 if(!prs_uint32("start_idx ", ps, depth, &q_e->start_idx))
1489 return False;
1490 if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
1491 return False;
1492 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1493 return False;
1495 return True;
1498 /*******************************************************************
1499 inits a SAM_DISPINFO_1 structure.
1500 ********************************************************************/
1502 NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 *sam, uint32 num_entries,
1503 uint32 start_idx, DISP_USER_INFO *disp_user_info,
1504 DOM_SID *domain_sid)
1506 uint32 len_sam_name, len_sam_full, len_sam_desc;
1507 uint32 i;
1509 SAM_ACCOUNT *pwd = NULL;
1510 ZERO_STRUCTP(sam);
1512 DEBUG(10, ("init_sam_dispinfo_1: num_entries: %d\n", num_entries));
1514 if (num_entries==0)
1515 return NT_STATUS_OK;
1517 sam->sam=(SAM_ENTRY1 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY1));
1518 if (!sam->sam)
1519 return NT_STATUS_NO_MEMORY;
1521 sam->str=(SAM_STR1 *)talloc(ctx, num_entries*sizeof(SAM_STR1));
1522 if (!sam->str)
1523 return NT_STATUS_NO_MEMORY;
1525 ZERO_STRUCTP(sam->sam);
1526 ZERO_STRUCTP(sam->str);
1528 for (i = 0; i < num_entries ; i++) {
1529 const char *username;
1530 const char *fullname;
1531 const char *acct_desc;
1532 uint32 user_rid;
1533 const DOM_SID *user_sid;
1534 fstring user_sid_string, domain_sid_string;
1536 DEBUG(11, ("init_sam_dispinfo_1: entry: %d\n",i));
1538 pwd=disp_user_info[i+start_idx].sam;
1540 username = pdb_get_username(pwd);
1541 fullname = pdb_get_fullname(pwd);
1542 acct_desc = pdb_get_acct_desc(pwd);
1544 if (!username)
1545 username = "";
1547 if (!fullname)
1548 fullname = "";
1550 if (!acct_desc)
1551 acct_desc = "";
1553 user_sid = pdb_get_user_sid(pwd);
1555 if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
1556 DEBUG(0, ("init_sam_dispinfo_1: User %s has SID %s, which conflicts with "
1557 "the domain sid %s. Failing operation.\n",
1558 username,
1559 sid_to_string(user_sid_string, user_sid),
1560 sid_to_string(domain_sid_string, domain_sid)));
1561 return NT_STATUS_UNSUCCESSFUL;
1564 len_sam_name = strlen(username);
1565 len_sam_full = strlen(fullname);
1566 len_sam_desc = strlen(acct_desc);
1568 init_sam_entry1(&sam->sam[i], start_idx + i + 1,
1569 len_sam_name, len_sam_full, len_sam_desc,
1570 user_rid, pdb_get_acct_ctrl(pwd));
1572 ZERO_STRUCTP(&sam->str[i].uni_acct_name);
1573 ZERO_STRUCTP(&sam->str[i].uni_full_name);
1574 ZERO_STRUCTP(&sam->str[i].uni_acct_desc);
1576 init_unistr2(&sam->str[i].uni_acct_name, pdb_get_username(pwd), len_sam_name);
1577 init_unistr2(&sam->str[i].uni_full_name, pdb_get_fullname(pwd), len_sam_full);
1578 init_unistr2(&sam->str[i].uni_acct_desc, pdb_get_acct_desc(pwd), len_sam_desc);
1581 return NT_STATUS_OK;
1584 /*******************************************************************
1585 reads or writes a structure.
1586 ********************************************************************/
1588 static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
1589 uint32 num_entries,
1590 prs_struct *ps, int depth)
1592 uint32 i;
1594 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
1595 depth++;
1597 if(!prs_align(ps))
1598 return False;
1600 if (UNMARSHALLING(ps) && num_entries > 0) {
1602 if ((sam->sam = (SAM_ENTRY1 *)
1603 prs_alloc_mem(ps, sizeof(SAM_ENTRY1) *
1604 num_entries)) == NULL) {
1605 DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1606 return False;
1609 if ((sam->str = (SAM_STR1 *)
1610 prs_alloc_mem(ps, sizeof(SAM_STR1) *
1611 num_entries)) == NULL) {
1612 DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1613 return False;
1617 for (i = 0; i < num_entries; i++) {
1618 if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
1619 return False;
1622 for (i = 0; i < num_entries; i++) {
1623 if(!sam_io_sam_str1("", &sam->str[i],
1624 sam->sam[i].hdr_acct_name.buffer,
1625 sam->sam[i].hdr_user_name.buffer,
1626 sam->sam[i].hdr_user_desc.buffer, ps, depth))
1627 return False;
1630 return True;
1633 /*******************************************************************
1634 inits a SAM_DISPINFO_2 structure.
1635 ********************************************************************/
1637 NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 *sam, uint32 num_entries,
1638 uint32 start_idx, DISP_USER_INFO *disp_user_info,
1639 DOM_SID *domain_sid )
1641 uint32 len_sam_name, len_sam_desc;
1642 uint32 i;
1644 SAM_ACCOUNT *pwd = NULL;
1645 ZERO_STRUCTP(sam);
1647 DEBUG(10, ("init_sam_dispinfo_2: num_entries: %d\n", num_entries));
1649 if (num_entries==0)
1650 return NT_STATUS_OK;
1652 if (!(sam->sam=(SAM_ENTRY2 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY2))))
1653 return NT_STATUS_NO_MEMORY;
1655 if (!(sam->str=(SAM_STR2 *)talloc(ctx, num_entries*sizeof(SAM_STR2))))
1656 return NT_STATUS_NO_MEMORY;
1658 ZERO_STRUCTP(sam->sam);
1659 ZERO_STRUCTP(sam->str);
1661 for (i = 0; i < num_entries; i++) {
1662 uint32 user_rid;
1663 const DOM_SID *user_sid;
1664 const char *username;
1665 const char *acct_desc;
1666 fstring user_sid_string, domain_sid_string;
1668 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1669 pwd=disp_user_info[i+start_idx].sam;
1671 username = pdb_get_username(pwd);
1672 acct_desc = pdb_get_acct_desc(pwd);
1673 user_sid = pdb_get_user_sid(pwd);
1675 if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
1676 DEBUG(0, ("init_sam_dispinfo_2: User %s has SID %s, which conflicts with "
1677 "the domain sid %s. Failing operation.\n",
1678 username,
1679 sid_to_string(user_sid_string, user_sid),
1680 sid_to_string(domain_sid_string, domain_sid)));
1681 return NT_STATUS_UNSUCCESSFUL;
1684 len_sam_name = strlen(username);
1685 len_sam_desc = strlen(acct_desc);
1687 init_sam_entry2(&sam->sam[i], start_idx + i + 1,
1688 len_sam_name, len_sam_desc,
1689 user_rid, pdb_get_acct_ctrl(pwd));
1691 ZERO_STRUCTP(&sam->str[i].uni_srv_name);
1692 ZERO_STRUCTP(&sam->str[i].uni_srv_desc);
1694 init_unistr2(&sam->str[i].uni_srv_name, username, len_sam_name);
1695 init_unistr2(&sam->str[i].uni_srv_desc, pdb_get_acct_desc(pwd), len_sam_desc);
1698 return NT_STATUS_OK;
1701 /*******************************************************************
1702 reads or writes a structure.
1703 ********************************************************************/
1705 static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
1706 uint32 num_entries,
1707 prs_struct *ps, int depth)
1709 uint32 i;
1711 if (sam == NULL)
1712 return False;
1714 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
1715 depth++;
1717 if(!prs_align(ps))
1718 return False;
1720 if (UNMARSHALLING(ps) && num_entries > 0) {
1722 if ((sam->sam = (SAM_ENTRY2 *)
1723 prs_alloc_mem(ps, sizeof(SAM_ENTRY2) *
1724 num_entries)) == NULL) {
1725 DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1726 return False;
1729 if ((sam->str = (SAM_STR2 *)
1730 prs_alloc_mem(ps, sizeof(SAM_STR2) *
1731 num_entries)) == NULL) {
1732 DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1733 return False;
1737 for (i = 0; i < num_entries; i++) {
1738 if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
1739 return False;
1742 for (i = 0; i < num_entries; i++) {
1743 if(!sam_io_sam_str2("", &sam->str[i],
1744 sam->sam[i].hdr_srv_name.buffer,
1745 sam->sam[i].hdr_srv_desc.buffer, ps, depth))
1746 return False;
1749 return True;
1752 /*******************************************************************
1753 inits a SAM_DISPINFO_3 structure.
1754 ********************************************************************/
1756 NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 *sam, uint32 num_entries,
1757 uint32 start_idx, DISP_GROUP_INFO *disp_group_info)
1759 uint32 len_sam_name, len_sam_desc;
1760 uint32 i;
1762 ZERO_STRUCTP(sam);
1764 DEBUG(5, ("init_sam_dispinfo_3: num_entries: %d\n", num_entries));
1766 if (num_entries==0)
1767 return NT_STATUS_OK;
1769 if (!(sam->sam=(SAM_ENTRY3 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY3))))
1770 return NT_STATUS_NO_MEMORY;
1772 if (!(sam->str=(SAM_STR3 *)talloc(ctx, num_entries*sizeof(SAM_STR3))))
1773 return NT_STATUS_NO_MEMORY;
1775 ZERO_STRUCTP(sam->sam);
1776 ZERO_STRUCTP(sam->str);
1778 for (i = 0; i < num_entries; i++) {
1779 DOMAIN_GRP *grp = disp_group_info[i+start_idx].grp;
1781 DEBUG(11, ("init_sam_dispinfo_3: entry: %d\n",i));
1783 len_sam_name = strlen(grp->name);
1784 len_sam_desc = strlen(grp->comment);
1786 init_sam_entry3(&sam->sam[i], start_idx + i + 1, len_sam_name, len_sam_desc, grp->rid);
1788 init_unistr2(&sam->str[i].uni_grp_name, grp->name, len_sam_name);
1789 init_unistr2(&sam->str[i].uni_grp_desc, grp->comment, len_sam_desc);
1792 return NT_STATUS_OK;
1795 /*******************************************************************
1796 reads or writes a structure.
1797 ********************************************************************/
1799 static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
1800 uint32 num_entries,
1801 prs_struct *ps, int depth)
1803 uint32 i;
1805 if (sam == NULL)
1806 return False;
1808 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
1809 depth++;
1811 if(!prs_align(ps))
1812 return False;
1814 if (UNMARSHALLING(ps) && num_entries > 0) {
1816 if ((sam->sam = (SAM_ENTRY3 *)
1817 prs_alloc_mem(ps, sizeof(SAM_ENTRY3) *
1818 num_entries)) == NULL) {
1819 DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1820 return False;
1823 if ((sam->str = (SAM_STR3 *)
1824 prs_alloc_mem(ps, sizeof(SAM_STR3) *
1825 num_entries)) == NULL) {
1826 DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1827 return False;
1831 for (i = 0; i < num_entries; i++) {
1832 if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
1833 return False;
1836 for (i = 0; i < num_entries; i++) {
1837 if(!sam_io_sam_str3("", &sam->str[i],
1838 sam->sam[i].hdr_grp_name.buffer,
1839 sam->sam[i].hdr_grp_desc.buffer, ps, depth))
1840 return False;
1843 return True;
1846 /*******************************************************************
1847 inits a SAM_DISPINFO_4 structure.
1848 ********************************************************************/
1850 NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 *sam, uint32 num_entries,
1851 uint32 start_idx, DISP_USER_INFO *disp_user_info)
1853 uint32 len_sam_name;
1854 uint32 i;
1856 SAM_ACCOUNT *pwd = NULL;
1857 ZERO_STRUCTP(sam);
1859 DEBUG(5, ("init_sam_dispinfo_4: num_entries: %d\n", num_entries));
1861 if (num_entries==0)
1862 return NT_STATUS_OK;
1864 if (!(sam->sam=(SAM_ENTRY4 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY4))))
1865 return NT_STATUS_NO_MEMORY;
1867 if (!(sam->str=(SAM_STR4 *)talloc(ctx, num_entries*sizeof(SAM_STR4))))
1868 return NT_STATUS_NO_MEMORY;
1870 ZERO_STRUCTP(sam->sam);
1871 ZERO_STRUCTP(sam->str);
1873 for (i = 0; i < num_entries; i++) {
1874 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1875 pwd=disp_user_info[i+start_idx].sam;
1877 len_sam_name = strlen(pdb_get_username(pwd));
1879 init_sam_entry4(&sam->sam[i], start_idx + i + 1, len_sam_name);
1881 init_string2(&sam->str[i].acct_name, pdb_get_username(pwd), len_sam_name+1, len_sam_name);
1884 return NT_STATUS_OK;
1887 /*******************************************************************
1888 reads or writes a structure.
1889 ********************************************************************/
1891 static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
1892 uint32 num_entries,
1893 prs_struct *ps, int depth)
1895 uint32 i;
1897 if (sam == NULL)
1898 return False;
1900 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1901 depth++;
1903 if(!prs_align(ps))
1904 return False;
1906 if (UNMARSHALLING(ps) && num_entries > 0) {
1908 if ((sam->sam = (SAM_ENTRY4 *)
1909 prs_alloc_mem(ps, sizeof(SAM_ENTRY4) *
1910 num_entries)) == NULL) {
1911 DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1912 return False;
1915 if ((sam->str = (SAM_STR4 *)
1916 prs_alloc_mem(ps, sizeof(SAM_STR4) *
1917 num_entries)) == NULL) {
1918 DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1919 return False;
1923 for (i = 0; i < num_entries; i++) {
1924 if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
1925 return False;
1928 for (i = 0; i < num_entries; i++) {
1929 if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
1930 sam->sam[i].hdr_acct_name.buffer, ps, depth))
1931 return False;
1934 return True;
1937 /*******************************************************************
1938 inits a SAM_DISPINFO_5 structure.
1939 ********************************************************************/
1941 NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 *sam, uint32 num_entries,
1942 uint32 start_idx, DISP_GROUP_INFO *disp_group_info)
1944 uint32 len_sam_name;
1945 uint32 i;
1947 ZERO_STRUCTP(sam);
1949 DEBUG(5, ("init_sam_dispinfo_5: num_entries: %d\n", num_entries));
1951 if (num_entries==0)
1952 return NT_STATUS_OK;
1954 if (!(sam->sam=(SAM_ENTRY5 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY5))))
1955 return NT_STATUS_NO_MEMORY;
1957 if (!(sam->str=(SAM_STR5 *)talloc(ctx, num_entries*sizeof(SAM_STR5))))
1958 return NT_STATUS_NO_MEMORY;
1960 ZERO_STRUCTP(sam->sam);
1961 ZERO_STRUCTP(sam->str);
1963 for (i = 0; i < num_entries; i++) {
1964 DOMAIN_GRP *grp = disp_group_info[i+start_idx].grp;
1966 DEBUG(11, ("init_sam_dispinfo_5: entry: %d\n",i));
1968 len_sam_name = strlen(grp->name);
1970 init_sam_entry5(&sam->sam[i], start_idx + i + 1, len_sam_name);
1971 init_string2(&sam->str[i].grp_name, grp->name, len_sam_name+1, len_sam_name);
1974 return NT_STATUS_OK;
1977 /*******************************************************************
1978 reads or writes a structure.
1979 ********************************************************************/
1981 static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
1982 uint32 num_entries,
1983 prs_struct *ps, int depth)
1985 uint32 i;
1987 if (sam == NULL)
1988 return False;
1990 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
1991 depth++;
1993 if(!prs_align(ps))
1994 return False;
1996 if (UNMARSHALLING(ps) && num_entries > 0) {
1998 if ((sam->sam = (SAM_ENTRY5 *)
1999 prs_alloc_mem(ps, sizeof(SAM_ENTRY5) *
2000 num_entries)) == NULL) {
2001 DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
2002 return False;
2005 if ((sam->str = (SAM_STR5 *)
2006 prs_alloc_mem(ps, sizeof(SAM_STR5) *
2007 num_entries)) == NULL) {
2008 DEBUG(0, ("out of memory allocating SAM_STR5\n"));
2009 return False;
2013 for (i = 0; i < num_entries; i++) {
2014 if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
2015 return False;
2018 for (i = 0; i < num_entries; i++) {
2019 if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
2020 sam->sam[i].hdr_grp_name.buffer, ps, depth))
2021 return False;
2024 return True;
2027 /*******************************************************************
2028 inits a SAMR_R_QUERY_DISPINFO structure.
2029 ********************************************************************/
2031 void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
2032 uint32 num_entries, uint32 total_size, uint32 data_size,
2033 uint16 switch_level, SAM_DISPINFO_CTR * ctr,
2034 NTSTATUS status)
2036 DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
2038 r_u->total_size = total_size;
2040 r_u->data_size = data_size;
2042 r_u->switch_level = switch_level;
2043 r_u->num_entries = num_entries;
2045 if (num_entries==0)
2046 r_u->ptr_entries = 0;
2047 else
2048 r_u->ptr_entries = 1;
2050 r_u->num_entries2 = num_entries;
2051 r_u->ctr = ctr;
2053 r_u->status = status;
2056 /*******************************************************************
2057 reads or writes a structure.
2058 ********************************************************************/
2060 BOOL samr_io_r_query_dispinfo(const char *desc, SAMR_R_QUERY_DISPINFO * r_u,
2061 prs_struct *ps, int depth)
2063 if (r_u == NULL)
2064 return False;
2066 prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
2067 depth++;
2069 if(!prs_align(ps))
2070 return False;
2072 if(!prs_uint32("total_size ", ps, depth, &r_u->total_size))
2073 return False;
2074 if(!prs_uint32("data_size ", ps, depth, &r_u->data_size))
2075 return False;
2076 if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
2077 return False;
2078 if(!prs_align(ps))
2079 return False;
2081 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2082 return False;
2083 if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
2084 return False;
2086 if (r_u->ptr_entries==0) {
2087 if(!prs_align(ps))
2088 return False;
2089 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2090 return False;
2092 return True;
2095 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
2096 return False;
2098 switch (r_u->switch_level) {
2099 case 0x1:
2100 if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
2101 r_u->num_entries, ps, depth))
2102 return False;
2103 break;
2104 case 0x2:
2105 if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
2106 r_u->num_entries, ps, depth))
2107 return False;
2108 break;
2109 case 0x3:
2110 if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
2111 r_u->num_entries, ps, depth))
2112 return False;
2113 break;
2114 case 0x4:
2115 if(!sam_io_sam_dispinfo_4("user list",
2116 r_u->ctr->sam.info4,
2117 r_u->num_entries, ps, depth))
2118 return False;
2119 break;
2120 case 0x5:
2121 if(!sam_io_sam_dispinfo_5("group list",
2122 r_u->ctr->sam.info5,
2123 r_u->num_entries, ps, depth))
2124 return False;
2125 break;
2126 default:
2127 DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
2128 break;
2131 if(!prs_align(ps))
2132 return False;
2133 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2134 return False;
2136 return True;
2139 /*******************************************************************
2140 inits a SAMR_Q_OPEN_GROUP structure.
2141 ********************************************************************/
2143 void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
2144 POLICY_HND *hnd,
2145 uint32 access_mask, uint32 rid)
2147 DEBUG(5, ("init_samr_q_open_group\n"));
2149 q_c->domain_pol = *hnd;
2150 q_c->access_mask = access_mask;
2151 q_c->rid_group = rid;
2154 /*******************************************************************
2155 reads or writes a structure.
2156 ********************************************************************/
2158 BOOL samr_io_q_open_group(const char *desc, SAMR_Q_OPEN_GROUP * q_u,
2159 prs_struct *ps, int depth)
2161 if (q_u == NULL)
2162 return False;
2164 prs_debug(ps, depth, desc, "samr_io_q_open_group");
2165 depth++;
2167 if(!prs_align(ps))
2168 return False;
2170 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
2171 return False;
2173 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
2174 return False;
2175 if(!prs_uint32("rid_group", ps, depth, &q_u->rid_group))
2176 return False;
2178 return True;
2181 /*******************************************************************
2182 reads or writes a structure.
2183 ********************************************************************/
2185 BOOL samr_io_r_open_group(const char *desc, SAMR_R_OPEN_GROUP * r_u,
2186 prs_struct *ps, int depth)
2188 if (r_u == NULL)
2189 return False;
2191 prs_debug(ps, depth, desc, "samr_io_r_open_group");
2192 depth++;
2194 if(!prs_align(ps))
2195 return False;
2197 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2198 return False;
2200 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2201 return False;
2203 return True;
2206 /*******************************************************************
2207 inits a GROUP_INFO1 structure.
2208 ********************************************************************/
2210 void init_samr_group_info1(GROUP_INFO1 * gr1,
2211 char *acct_name, char *acct_desc,
2212 uint32 num_members)
2214 int desc_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2215 int acct_len = acct_name != NULL ? strlen(acct_name) : 0;
2217 DEBUG(5, ("init_samr_group_info1\n"));
2219 init_uni_hdr(&gr1->hdr_acct_name, acct_len);
2221 gr1->unknown_1 = 0x3;
2222 gr1->num_members = num_members;
2224 init_uni_hdr(&gr1->hdr_acct_desc, desc_len);
2226 init_unistr2(&gr1->uni_acct_name, acct_name, acct_len);
2227 init_unistr2(&gr1->uni_acct_desc, acct_desc, desc_len);
2230 /*******************************************************************
2231 reads or writes a structure.
2232 ********************************************************************/
2234 BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
2235 prs_struct *ps, int depth)
2237 if (gr1 == NULL)
2238 return False;
2240 prs_debug(ps, depth, desc, "samr_io_group_info1");
2241 depth++;
2243 if(!prs_align(ps))
2244 return False;
2246 if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
2247 return False;
2249 if(!prs_uint32("unknown_1", ps, depth, &gr1->unknown_1))
2250 return False;
2251 if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
2252 return False;
2254 if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
2255 return False;
2257 if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
2258 gr1->hdr_acct_name.buffer, ps, depth))
2259 return False;
2261 if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
2262 gr1->hdr_acct_desc.buffer, ps, depth))
2263 return False;
2265 return True;
2268 /*******************************************************************
2269 inits a GROUP_INFO3 structure.
2270 ********************************************************************/
2272 void init_samr_group_info3(GROUP_INFO3 *gr3)
2274 DEBUG(5, ("init_samr_group_info3\n"));
2276 gr3->unknown_1 = 0x3;
2279 /*******************************************************************
2280 reads or writes a structure.
2281 ********************************************************************/
2283 BOOL samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int depth)
2285 if (gr3 == NULL)
2286 return False;
2288 prs_debug(ps, depth, desc, "samr_io_group_info3");
2289 depth++;
2291 if(!prs_align(ps))
2292 return False;
2294 if(!prs_uint32("unknown_1", ps, depth, &gr3->unknown_1))
2295 return False;
2297 return True;
2300 /*******************************************************************
2301 inits a GROUP_INFO4 structure.
2302 ********************************************************************/
2304 void init_samr_group_info4(GROUP_INFO4 * gr4, char *acct_desc)
2306 int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2308 DEBUG(5, ("init_samr_group_info4\n"));
2310 init_uni_hdr(&gr4->hdr_acct_desc, acct_len);
2311 init_unistr2(&gr4->uni_acct_desc, acct_desc, acct_len);
2314 /*******************************************************************
2315 reads or writes a structure.
2316 ********************************************************************/
2318 BOOL samr_io_group_info4(const char *desc, GROUP_INFO4 * gr4,
2319 prs_struct *ps, int depth)
2321 if (gr4 == NULL)
2322 return False;
2324 prs_debug(ps, depth, desc, "samr_io_group_info4");
2325 depth++;
2327 if(!prs_align(ps))
2328 return False;
2330 if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
2331 return False;
2332 if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
2333 gr4->hdr_acct_desc.buffer, ps, depth))
2334 return False;
2336 return True;
2339 /*******************************************************************
2340 reads or writes a structure.
2341 ********************************************************************/
2343 static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
2344 prs_struct *ps, int depth)
2346 if (UNMARSHALLING(ps))
2347 *ctr = (GROUP_INFO_CTR *)prs_alloc_mem(ps,sizeof(GROUP_INFO_CTR));
2349 if (*ctr == NULL)
2350 return False;
2352 prs_debug(ps, depth, desc, "samr_group_info_ctr");
2353 depth++;
2355 if(!prs_uint16("switch_value1", ps, depth, &(*ctr)->switch_value1))
2356 return False;
2358 switch ((*ctr)->switch_value1) {
2359 case 1:
2360 if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
2361 return False;
2362 break;
2363 case 3:
2364 if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
2365 return False;
2366 break;
2367 case 4:
2368 if(!samr_io_group_info4("group_info4", &(*ctr)->group.info4, ps, depth))
2369 return False;
2370 break;
2371 default:
2372 DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
2373 break;
2376 return True;
2379 /*******************************************************************
2380 inits a SAMR_Q_CREATE_DOM_GROUP structure.
2381 ********************************************************************/
2383 void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
2384 POLICY_HND *pol, char *acct_desc,
2385 uint32 access_mask)
2387 int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2389 DEBUG(5, ("init_samr_q_create_dom_group\n"));
2391 q_e->pol = *pol;
2393 init_uni_hdr(&q_e->hdr_acct_desc, acct_len);
2394 init_unistr2(&q_e->uni_acct_desc, acct_desc, acct_len);
2396 q_e->access_mask = access_mask;
2399 /*******************************************************************
2400 reads or writes a structure.
2401 ********************************************************************/
2403 BOOL samr_io_q_create_dom_group(const char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
2404 prs_struct *ps, int depth)
2406 if (q_e == NULL)
2407 return False;
2409 prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
2410 depth++;
2412 if(!prs_align(ps))
2413 return False;
2415 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2416 return False;
2418 if(!smb_io_unihdr("hdr_acct_desc", &q_e->hdr_acct_desc, ps, depth))
2419 return False;
2420 if(!smb_io_unistr2("uni_acct_desc", &q_e->uni_acct_desc,
2421 q_e->hdr_acct_desc.buffer, ps, depth))
2422 return False;
2424 if(!prs_align(ps))
2425 return False;
2426 if(!prs_uint32("access", ps, depth, &q_e->access_mask))
2427 return False;
2429 return True;
2432 /*******************************************************************
2433 reads or writes a structure.
2434 ********************************************************************/
2436 BOOL samr_io_r_create_dom_group(const char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
2437 prs_struct *ps, int depth)
2439 if (r_u == NULL)
2440 return False;
2442 prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
2443 depth++;
2445 if(!prs_align(ps))
2446 return False;
2448 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2449 return False;
2451 if(!prs_uint32("rid ", ps, depth, &r_u->rid))
2452 return False;
2453 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2454 return False;
2456 return True;
2459 /*******************************************************************
2460 inits a SAMR_Q_DELETE_DOM_GROUP structure.
2461 ********************************************************************/
2463 void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
2464 POLICY_HND *hnd)
2466 DEBUG(5, ("init_samr_q_delete_dom_group\n"));
2468 q_c->group_pol = *hnd;
2471 /*******************************************************************
2472 reads or writes a structure.
2473 ********************************************************************/
2475 BOOL samr_io_q_delete_dom_group(const char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
2476 prs_struct *ps, int depth)
2478 if (q_u == NULL)
2479 return False;
2481 prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
2482 depth++;
2484 if(!prs_align(ps))
2485 return False;
2487 if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2488 return False;
2490 return True;
2493 /*******************************************************************
2494 reads or writes a structure.
2495 ********************************************************************/
2497 BOOL samr_io_r_delete_dom_group(const char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
2498 prs_struct *ps, int depth)
2500 if (r_u == NULL)
2501 return False;
2503 prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
2504 depth++;
2506 if(!prs_align(ps))
2507 return False;
2509 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2510 return False;
2512 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2513 return False;
2515 return True;
2518 /*******************************************************************
2519 inits a SAMR_Q_DEL_GROUPMEM structure.
2520 ********************************************************************/
2522 void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
2523 POLICY_HND *pol, uint32 rid)
2525 DEBUG(5, ("init_samr_q_del_groupmem\n"));
2527 q_e->pol = *pol;
2528 q_e->rid = rid;
2531 /*******************************************************************
2532 reads or writes a structure.
2533 ********************************************************************/
2535 BOOL samr_io_q_del_groupmem(const char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
2536 prs_struct *ps, int depth)
2538 if (q_e == NULL)
2539 return False;
2541 prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
2542 depth++;
2544 if(!prs_align(ps))
2545 return False;
2547 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2548 return False;
2550 if(!prs_uint32("rid", ps, depth, &q_e->rid))
2551 return False;
2553 return True;
2556 /*******************************************************************
2557 inits a SAMR_R_DEL_GROUPMEM structure.
2558 ********************************************************************/
2560 void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
2561 NTSTATUS status)
2563 DEBUG(5, ("init_samr_r_del_groupmem\n"));
2565 r_u->status = status;
2568 /*******************************************************************
2569 reads or writes a structure.
2570 ********************************************************************/
2572 BOOL samr_io_r_del_groupmem(const char *desc, SAMR_R_DEL_GROUPMEM * r_u,
2573 prs_struct *ps, int depth)
2575 if (r_u == NULL)
2576 return False;
2578 prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
2579 depth++;
2581 if(!prs_align(ps))
2582 return False;
2584 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2585 return False;
2587 return True;
2590 /*******************************************************************
2591 inits a SAMR_Q_ADD_GROUPMEM structure.
2592 ********************************************************************/
2594 void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
2595 POLICY_HND *pol, uint32 rid)
2597 DEBUG(5, ("init_samr_q_add_groupmem\n"));
2599 q_e->pol = *pol;
2600 q_e->rid = rid;
2601 q_e->unknown = 0x0005;
2604 /*******************************************************************
2605 reads or writes a structure.
2606 ********************************************************************/
2608 BOOL samr_io_q_add_groupmem(const char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
2609 prs_struct *ps, int depth)
2611 if (q_e == NULL)
2612 return False;
2614 prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
2615 depth++;
2617 if(!prs_align(ps))
2618 return False;
2620 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2621 return False;
2623 if(!prs_uint32("rid ", ps, depth, &q_e->rid))
2624 return False;
2625 if(!prs_uint32("unknown", ps, depth, &q_e->unknown))
2626 return False;
2628 return True;
2631 /*******************************************************************
2632 inits a SAMR_R_ADD_GROUPMEM structure.
2633 ********************************************************************/
2635 void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
2636 NTSTATUS status)
2638 DEBUG(5, ("init_samr_r_add_groupmem\n"));
2640 r_u->status = status;
2643 /*******************************************************************
2644 reads or writes a structure.
2645 ********************************************************************/
2647 BOOL samr_io_r_add_groupmem(const char *desc, SAMR_R_ADD_GROUPMEM * r_u,
2648 prs_struct *ps, int depth)
2650 if (r_u == NULL)
2651 return False;
2653 prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
2654 depth++;
2656 if(!prs_align(ps))
2657 return False;
2659 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2660 return False;
2662 return True;
2665 /*******************************************************************
2666 inits a SAMR_Q_SET_GROUPINFO structure.
2667 ********************************************************************/
2669 void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
2670 POLICY_HND *pol, GROUP_INFO_CTR * ctr)
2672 DEBUG(5, ("init_samr_q_set_groupinfo\n"));
2674 q_e->pol = *pol;
2675 q_e->ctr = ctr;
2678 /*******************************************************************
2679 reads or writes a structure.
2680 ********************************************************************/
2682 BOOL samr_io_q_set_groupinfo(const char *desc, SAMR_Q_SET_GROUPINFO * q_e,
2683 prs_struct *ps, int depth)
2685 if (q_e == NULL)
2686 return False;
2688 prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
2689 depth++;
2691 if(!prs_align(ps))
2692 return False;
2694 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2695 return False;
2697 if(!samr_group_info_ctr("ctr", &q_e->ctr, ps, depth))
2698 return False;
2700 return True;
2703 /*******************************************************************
2704 inits a SAMR_R_SET_GROUPINFO structure.
2705 ********************************************************************/
2707 void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, NTSTATUS status)
2709 DEBUG(5, ("init_samr_r_set_groupinfo\n"));
2711 r_u->status = status;
2714 /*******************************************************************
2715 reads or writes a structure.
2716 ********************************************************************/
2718 BOOL samr_io_r_set_groupinfo(const char *desc, SAMR_R_SET_GROUPINFO * r_u,
2719 prs_struct *ps, int depth)
2721 if (r_u == NULL)
2722 return False;
2724 prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
2725 depth++;
2727 if(!prs_align(ps))
2728 return False;
2730 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2731 return False;
2733 return True;
2736 /*******************************************************************
2737 inits a SAMR_Q_QUERY_GROUPINFO structure.
2738 ********************************************************************/
2740 void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
2741 POLICY_HND *pol, uint16 switch_level)
2743 DEBUG(5, ("init_samr_q_query_groupinfo\n"));
2745 q_e->pol = *pol;
2747 q_e->switch_level = switch_level;
2750 /*******************************************************************
2751 reads or writes a structure.
2752 ********************************************************************/
2754 BOOL samr_io_q_query_groupinfo(const char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
2755 prs_struct *ps, int depth)
2757 if (q_e == NULL)
2758 return False;
2760 prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
2761 depth++;
2763 if(!prs_align(ps))
2764 return False;
2766 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2767 return False;
2769 if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
2770 return False;
2772 return True;
2775 /*******************************************************************
2776 inits a SAMR_R_QUERY_GROUPINFO structure.
2777 ********************************************************************/
2779 void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
2780 GROUP_INFO_CTR * ctr, NTSTATUS status)
2782 DEBUG(5, ("init_samr_r_query_groupinfo\n"));
2784 r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
2785 r_u->ctr = ctr;
2786 r_u->status = status;
2789 /*******************************************************************
2790 reads or writes a structure.
2791 ********************************************************************/
2793 BOOL samr_io_r_query_groupinfo(const char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
2794 prs_struct *ps, int depth)
2796 if (r_u == NULL)
2797 return False;
2799 prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
2800 depth++;
2802 if(!prs_align(ps))
2803 return False;
2805 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2806 return False;
2808 if (r_u->ptr != 0) {
2809 if(!samr_group_info_ctr("ctr", &r_u->ctr, ps, depth))
2810 return False;
2813 if(!prs_align(ps))
2814 return False;
2815 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2816 return False;
2818 return True;
2821 /*******************************************************************
2822 inits a SAMR_Q_QUERY_GROUPMEM structure.
2823 ********************************************************************/
2825 void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd)
2827 DEBUG(5, ("init_samr_q_query_groupmem\n"));
2829 q_c->group_pol = *hnd;
2832 /*******************************************************************
2833 reads or writes a structure.
2834 ********************************************************************/
2836 BOOL samr_io_q_query_groupmem(const char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
2837 prs_struct *ps, int depth)
2839 if (q_u == NULL)
2840 return False;
2842 prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
2843 depth++;
2845 if(!prs_align(ps))
2846 return False;
2848 if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2849 return False;
2851 return True;
2854 /*******************************************************************
2855 inits a SAMR_R_QUERY_GROUPMEM structure.
2856 ********************************************************************/
2858 void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
2859 uint32 num_entries, uint32 *rid,
2860 uint32 *attr, NTSTATUS status)
2862 DEBUG(5, ("init_samr_r_query_groupmem\n"));
2864 if (NT_STATUS_IS_OK(status)) {
2865 r_u->ptr = 1;
2866 r_u->num_entries = num_entries;
2868 r_u->ptr_attrs = attr != NULL ? 1 : 0;
2869 r_u->ptr_rids = rid != NULL ? 1 : 0;
2871 r_u->num_rids = num_entries;
2872 r_u->rid = rid;
2874 r_u->num_attrs = num_entries;
2875 r_u->attr = attr;
2876 } else {
2877 r_u->ptr = 0;
2878 r_u->num_entries = 0;
2881 r_u->status = status;
2884 /*******************************************************************
2885 reads or writes a structure.
2886 ********************************************************************/
2888 BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
2889 prs_struct *ps, int depth)
2891 uint32 i;
2893 if (r_u == NULL)
2894 return False;
2896 if (UNMARSHALLING(ps))
2897 ZERO_STRUCTP(r_u);
2899 prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
2900 depth++;
2902 if(!prs_align(ps))
2903 return False;
2905 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2906 return False;
2907 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2908 return False;
2910 if (r_u->ptr != 0) {
2911 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
2912 return False;
2913 if(!prs_uint32("ptr_attrs", ps, depth, &r_u->ptr_attrs))
2914 return False;
2916 if (r_u->ptr_rids != 0) {
2917 if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
2918 return False;
2919 if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
2920 r_u->rid = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->rid[0])*r_u->num_rids);
2921 if (r_u->rid == NULL)
2922 return False;
2925 for (i = 0; i < r_u->num_rids; i++) {
2926 if(!prs_uint32("", ps, depth, &r_u->rid[i]))
2927 return False;
2931 if (r_u->ptr_attrs != 0) {
2932 if(!prs_uint32("num_attrs", ps, depth, &r_u->num_attrs))
2933 return False;
2935 if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
2936 r_u->attr = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->attr[0])*r_u->num_attrs);
2937 if (r_u->attr == NULL)
2938 return False;
2941 for (i = 0; i < r_u->num_attrs; i++) {
2942 if(!prs_uint32("", ps, depth, &r_u->attr[i]))
2943 return False;
2948 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2949 return False;
2951 return True;
2954 /*******************************************************************
2955 inits a SAMR_Q_QUERY_USERGROUPS structure.
2956 ********************************************************************/
2958 void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
2959 POLICY_HND *hnd)
2961 DEBUG(5, ("init_samr_q_query_usergroups\n"));
2963 q_u->pol = *hnd;
2966 /*******************************************************************
2967 reads or writes a structure.
2968 ********************************************************************/
2970 BOOL samr_io_q_query_usergroups(const char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
2971 prs_struct *ps, int depth)
2973 if (q_u == NULL)
2974 return False;
2976 prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
2977 depth++;
2979 if(!prs_align(ps))
2980 return False;
2982 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2983 return False;
2985 return True;
2988 /*******************************************************************
2989 inits a SAMR_R_QUERY_USERGROUPS structure.
2990 ********************************************************************/
2992 void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
2993 uint32 num_gids, DOM_GID * gid,
2994 NTSTATUS status)
2996 DEBUG(5, ("init_samr_r_query_usergroups\n"));
2998 if (NT_STATUS_IS_OK(status)) {
2999 r_u->ptr_0 = 1;
3000 r_u->num_entries = num_gids;
3001 r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
3002 r_u->num_entries2 = num_gids;
3004 r_u->gid = gid;
3005 } else {
3006 r_u->ptr_0 = 0;
3007 r_u->num_entries = 0;
3008 r_u->ptr_1 = 0;
3009 r_u->gid = NULL;
3012 r_u->status = status;
3015 /*******************************************************************
3016 reads or writes a structure.
3017 ********************************************************************/
3019 BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
3020 prs_struct *ps, int depth)
3022 uint32 i;
3023 if (gid == NULL)
3024 return False;
3026 prs_debug(ps, depth, desc, "samr_io_gids");
3027 depth++;
3029 if(!prs_align(ps))
3030 return False;
3032 if(!prs_uint32("num_gids", ps, depth, num_gids))
3033 return False;
3035 if ((*num_gids) != 0) {
3036 if (UNMARSHALLING(ps)) {
3037 (*gid) = (DOM_GID *)prs_alloc_mem(ps,sizeof(DOM_GID)*(*num_gids));
3040 if ((*gid) == NULL) {
3041 return False;
3044 for (i = 0; i < (*num_gids); i++) {
3045 if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
3046 return False;
3050 return True;
3053 /*******************************************************************
3054 reads or writes a structure.
3055 ********************************************************************/
3057 BOOL samr_io_r_query_usergroups(const char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
3058 prs_struct *ps, int depth)
3060 if (r_u == NULL)
3061 return False;
3063 prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
3064 depth++;
3066 if(!prs_align(ps))
3067 return False;
3069 if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
3070 return False;
3072 if (r_u->ptr_0 != 0) {
3073 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
3074 return False;
3075 if(!prs_uint32("ptr_1 ", ps, depth, &r_u->ptr_1))
3076 return False;
3078 if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
3079 if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
3080 return False;
3084 if(!prs_align(ps))
3085 return False;
3086 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3087 return False;
3089 return True;
3092 /*******************************************************************
3093 inits a SAMR_Q_ENUM_DOMAINS structure.
3094 ********************************************************************/
3096 void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
3097 POLICY_HND *pol,
3098 uint32 start_idx, uint32 size)
3100 DEBUG(5, ("init_samr_q_enum_domains\n"));
3102 q_e->pol = *pol;
3104 q_e->start_idx = start_idx;
3105 q_e->max_size = size;
3108 /*******************************************************************
3109 reads or writes a structure.
3110 ********************************************************************/
3112 BOOL samr_io_q_enum_domains(const char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
3113 prs_struct *ps, int depth)
3115 if (q_e == NULL)
3116 return False;
3118 prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
3119 depth++;
3121 if(!prs_align(ps))
3122 return False;
3124 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3125 return False;
3127 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3128 return False;
3129 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3130 return False;
3132 return True;
3135 /*******************************************************************
3136 inits a SAMR_R_ENUM_DOMAINS structure.
3137 ********************************************************************/
3139 void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
3140 uint32 next_idx, uint32 num_sam_entries)
3142 DEBUG(5, ("init_samr_r_enum_domains\n"));
3144 r_u->next_idx = next_idx;
3146 if (num_sam_entries != 0) {
3147 r_u->ptr_entries1 = 1;
3148 r_u->ptr_entries2 = 1;
3149 r_u->num_entries2 = num_sam_entries;
3150 r_u->num_entries3 = num_sam_entries;
3152 r_u->num_entries4 = num_sam_entries;
3153 } else {
3154 r_u->ptr_entries1 = 0;
3155 r_u->num_entries2 = num_sam_entries;
3156 r_u->ptr_entries2 = 1;
3160 /*******************************************************************
3161 reads or writes a structure.
3162 ********************************************************************/
3164 BOOL samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
3165 prs_struct *ps, int depth)
3167 uint32 i;
3169 if (r_u == NULL)
3170 return False;
3172 prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
3173 depth++;
3175 if(!prs_align(ps))
3176 return False;
3178 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
3179 return False;
3180 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3181 return False;
3183 if (r_u->ptr_entries1 != 0) {
3184 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3185 return False;
3186 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3187 return False;
3188 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3189 return False;
3191 if (UNMARSHALLING(ps)) {
3192 r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3193 r_u->uni_dom_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3196 if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
3197 DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
3198 r_u->num_entries4 = 0;
3199 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3200 return False;
3203 for (i = 0; i < r_u->num_entries2; i++) {
3204 fstring tmp;
3205 slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3206 if(!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
3207 return False;
3210 for (i = 0; i < r_u->num_entries2; i++) {
3211 fstring tmp;
3212 slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3213 if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i],
3214 r_u->sam[i].hdr_name.buffer, ps,
3215 depth))
3216 return False;
3221 if(!prs_align(ps))
3222 return False;
3223 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3224 return False;
3225 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3226 return False;
3228 return True;
3231 /*******************************************************************
3232 inits a SAMR_Q_ENUM_DOM_GROUPS structure.
3233 ********************************************************************/
3235 void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
3236 POLICY_HND *pol,
3237 uint32 start_idx, uint32 size)
3239 DEBUG(5, ("init_samr_q_enum_dom_groups\n"));
3241 q_e->pol = *pol;
3243 q_e->start_idx = start_idx;
3244 q_e->max_size = size;
3247 /*******************************************************************
3248 reads or writes a structure.
3249 ********************************************************************/
3251 BOOL samr_io_q_enum_dom_groups(const char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
3252 prs_struct *ps, int depth)
3254 if (q_e == NULL)
3255 return False;
3257 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
3258 depth++;
3260 if(!prs_align(ps))
3261 return False;
3263 if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
3264 return False;
3266 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3267 return False;
3268 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3269 return False;
3271 return True;
3274 /*******************************************************************
3275 inits a SAMR_R_ENUM_DOM_GROUPS structure.
3276 ********************************************************************/
3278 void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
3279 uint32 next_idx, uint32 num_sam_entries)
3281 DEBUG(5, ("init_samr_r_enum_dom_groups\n"));
3283 r_u->next_idx = next_idx;
3285 if (num_sam_entries != 0) {
3286 r_u->ptr_entries1 = 1;
3287 r_u->ptr_entries2 = 1;
3288 r_u->num_entries2 = num_sam_entries;
3289 r_u->num_entries3 = num_sam_entries;
3291 r_u->num_entries4 = num_sam_entries;
3292 } else {
3293 r_u->ptr_entries1 = 0;
3294 r_u->num_entries2 = num_sam_entries;
3295 r_u->ptr_entries2 = 1;
3299 /*******************************************************************
3300 reads or writes a structure.
3301 ********************************************************************/
3303 BOOL samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
3304 prs_struct *ps, int depth)
3306 uint32 i;
3308 if (r_u == NULL)
3309 return False;
3311 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
3312 depth++;
3314 if(!prs_align(ps))
3315 return False;
3317 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
3318 return False;
3319 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3320 return False;
3322 if (r_u->ptr_entries1 != 0) {
3323 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3324 return False;
3325 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3326 return False;
3327 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3328 return False;
3330 if (UNMARSHALLING(ps)) {
3331 r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3332 r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3335 if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
3336 DEBUG(0,
3337 ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n"));
3338 r_u->num_entries4 = 0;
3339 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3340 return False;
3343 for (i = 0; i < r_u->num_entries2; i++) {
3344 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3345 return False;
3348 for (i = 0; i < r_u->num_entries2; i++) {
3349 if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3350 r_u->sam[i].hdr_name.buffer, ps, depth))
3351 return False;
3355 if(!prs_align(ps))
3356 return False;
3357 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3358 return False;
3359 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3360 return False;
3362 return True;
3365 /*******************************************************************
3366 inits a SAMR_Q_ENUM_DOM_ALIASES structure.
3367 ********************************************************************/
3369 void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
3370 POLICY_HND *pol, uint32 start_idx,
3371 uint32 size)
3373 DEBUG(5, ("init_samr_q_enum_dom_aliases\n"));
3375 q_e->pol = *pol;
3377 q_e->start_idx = start_idx;
3378 q_e->max_size = size;
3382 /*******************************************************************
3383 reads or writes a structure.
3384 ********************************************************************/
3386 BOOL samr_io_q_enum_dom_aliases(const char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
3387 prs_struct *ps, int depth)
3389 if (q_e == NULL)
3390 return False;
3392 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
3393 depth++;
3395 if(!prs_align(ps))
3396 return False;
3398 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3399 return False;
3401 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3402 return False;
3403 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3404 return False;
3406 return True;
3409 /*******************************************************************
3410 inits a SAMR_R_ENUM_DOM_ALIASES structure.
3411 ********************************************************************/
3413 void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries)
3415 DEBUG(5, ("init_samr_r_enum_dom_aliases\n"));
3417 r_u->next_idx = next_idx;
3419 if (num_sam_entries != 0) {
3420 r_u->ptr_entries1 = 1;
3421 r_u->ptr_entries2 = 1;
3422 r_u->num_entries2 = num_sam_entries;
3423 r_u->num_entries3 = num_sam_entries;
3425 r_u->num_entries4 = num_sam_entries;
3426 } else {
3427 r_u->ptr_entries1 = 0;
3428 r_u->num_entries2 = num_sam_entries;
3429 r_u->ptr_entries2 = 1;
3433 /*******************************************************************
3434 reads or writes a structure.
3435 ********************************************************************/
3437 BOOL samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
3438 prs_struct *ps, int depth)
3440 uint32 i;
3442 if (r_u == NULL)
3443 return False;
3445 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
3446 depth++;
3448 if(!prs_align(ps))
3449 return False;
3451 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
3452 return False;
3453 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3454 return False;
3456 if (r_u->ptr_entries1 != 0) {
3457 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3458 return False;
3459 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3460 return False;
3461 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3462 return False;
3464 if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
3465 r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3466 r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3469 if (r_u->num_entries2 != 0 &&
3470 (r_u->sam == NULL || r_u->uni_grp_name == NULL)) {
3471 DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n"));
3472 r_u->num_entries4 = 0;
3473 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3474 return False;
3477 for (i = 0; i < r_u->num_entries2; i++) {
3478 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3479 return False;
3482 for (i = 0; i < r_u->num_entries2; i++) {
3483 if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3484 r_u->sam[i].hdr_name.buffer, ps,
3485 depth))
3486 return False;
3490 if(!prs_align(ps))
3491 return False;
3492 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3493 return False;
3494 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3495 return False;
3497 return True;
3500 /*******************************************************************
3501 inits a ALIAS_INFO1 structure.
3502 ********************************************************************/
3504 void init_samr_alias_info1(ALIAS_INFO1 * al1, char *acct_name, uint32 num_member, char *acct_desc)
3506 int acct_len_name = acct_name != NULL ? strlen(acct_name) : 0;
3507 int acct_len_desc = acct_desc != NULL ? strlen(acct_desc) : 0;
3509 DEBUG(5, ("init_samr_alias_info1\n"));
3511 init_uni_hdr(&al1->hdr_acct_name, acct_len_name);
3512 init_unistr2(&al1->uni_acct_name, acct_name, acct_len_name);
3514 al1->num_member=num_member;
3516 init_uni_hdr(&al1->hdr_acct_desc, acct_len_desc);
3517 init_unistr2(&al1->uni_acct_desc, acct_desc, acct_len_desc);
3520 /*******************************************************************
3521 reads or writes a structure.
3522 ********************************************************************/
3524 BOOL samr_io_alias_info1(const char *desc, ALIAS_INFO1 * al1,
3525 prs_struct *ps, int depth)
3527 if (al1 == NULL)
3528 return False;
3530 prs_debug(ps, depth, desc, "samr_io_alias_info1");
3531 depth++;
3533 if(!prs_align(ps))
3534 return False;
3536 if(!smb_io_unihdr("hdr_acct_name", &al1->hdr_acct_name, ps, depth))
3537 return False;
3538 if(!prs_uint32("num_member", ps, depth, &al1->num_member))
3539 return False;
3540 if(!smb_io_unihdr("hdr_acct_desc", &al1->hdr_acct_desc, ps, depth))
3541 return False;
3543 if(!smb_io_unistr2("uni_acct_name", &al1->uni_acct_name,
3544 al1->hdr_acct_name.buffer, ps, depth))
3545 return False;
3547 if(!prs_align(ps))
3548 return False;
3550 if(!smb_io_unistr2("uni_acct_desc", &al1->uni_acct_desc,
3551 al1->hdr_acct_desc.buffer, ps, depth))
3552 return False;
3554 return True;
3557 /*******************************************************************
3558 inits a ALIAS_INFO3 structure.
3559 ********************************************************************/
3561 void init_samr_alias_info3(ALIAS_INFO3 * al3, char *acct_desc)
3563 int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
3565 DEBUG(5, ("init_samr_alias_info3\n"));
3567 init_uni_hdr(&al3->hdr_acct_desc, acct_len);
3568 init_unistr2(&al3->uni_acct_desc, acct_desc, acct_len);
3571 /*******************************************************************
3572 reads or writes a structure.
3573 ********************************************************************/
3575 BOOL samr_io_alias_info3(const char *desc, ALIAS_INFO3 * al3,
3576 prs_struct *ps, int depth)
3578 if (al3 == NULL)
3579 return False;
3581 prs_debug(ps, depth, desc, "samr_io_alias_info3");
3582 depth++;
3584 if(!prs_align(ps))
3585 return False;
3587 if(!smb_io_unihdr("hdr_acct_desc", &al3->hdr_acct_desc, ps, depth))
3588 return False;
3589 if(!smb_io_unistr2("uni_acct_desc", &al3->uni_acct_desc,
3590 al3->hdr_acct_desc.buffer, ps, depth))
3591 return False;
3593 return True;
3596 /*******************************************************************
3597 reads or writes a structure.
3598 ********************************************************************/
3600 BOOL samr_alias_info_ctr(const char *desc, ALIAS_INFO_CTR * ctr,
3601 prs_struct *ps, int depth)
3603 if (ctr == NULL)
3604 return False;
3606 prs_debug(ps, depth, desc, "samr_alias_info_ctr");
3607 depth++;
3609 if(!prs_uint16("switch_value1", ps, depth, &ctr->switch_value1))
3610 return False;
3611 if(!prs_uint16("switch_value2", ps, depth, &ctr->switch_value2))
3612 return False;
3614 switch (ctr->switch_value1) {
3615 case 1:
3616 if(!samr_io_alias_info1("alias_info1", &ctr->alias.info1, ps, depth))
3617 return False;
3618 break;
3619 case 3:
3620 if(!samr_io_alias_info3("alias_info3", &ctr->alias.info3, ps, depth))
3621 return False;
3622 break;
3623 default:
3624 DEBUG(0,("samr_alias_info_ctr: unsupported switch level\n"));
3625 break;
3628 return True;
3631 /*******************************************************************
3632 inits a SAMR_Q_QUERY_ALIASINFO structure.
3633 ********************************************************************/
3635 void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO * q_e,
3636 POLICY_HND *pol, uint16 switch_level)
3638 DEBUG(5, ("init_samr_q_query_aliasinfo\n"));
3640 q_e->pol = *pol;
3641 q_e->switch_level = switch_level;
3644 /*******************************************************************
3645 reads or writes a structure.
3646 ********************************************************************/
3648 BOOL samr_io_q_query_aliasinfo(const char *desc, SAMR_Q_QUERY_ALIASINFO * q_e,
3649 prs_struct *ps, int depth)
3651 if (q_e == NULL)
3652 return False;
3654 prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
3655 depth++;
3657 if(!prs_align(ps))
3658 return False;
3660 if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
3661 return False;
3663 if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
3664 return False;
3666 return True;
3669 /*******************************************************************
3670 inits a SAMR_R_QUERY_ALIASINFO structure.
3671 ********************************************************************/
3673 void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO * r_u,
3674 ALIAS_INFO_CTR * ctr, NTSTATUS status)
3676 DEBUG(5, ("init_samr_r_query_aliasinfo\n"));
3678 r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
3679 r_u->ctr = *ctr;
3680 r_u->status = status;
3683 /*******************************************************************
3684 reads or writes a structure.
3685 ********************************************************************/
3687 BOOL samr_io_r_query_aliasinfo(const char *desc, SAMR_R_QUERY_ALIASINFO * r_u,
3688 prs_struct *ps, int depth)
3690 if (r_u == NULL)
3691 return False;
3693 prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
3694 depth++;
3696 if(!prs_align(ps))
3697 return False;
3699 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
3700 return False;
3702 if (r_u->ptr != 0) {
3703 if(!samr_alias_info_ctr("ctr", &r_u->ctr, ps, depth))
3704 return False;
3707 if(!prs_align(ps))
3708 return False;
3709 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3710 return False;
3712 return True;
3715 /*******************************************************************
3716 inits a SAMR_Q_SET_ALIASINFO structure.
3717 ********************************************************************/
3719 void init_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO * q_u,
3720 POLICY_HND *hnd, ALIAS_INFO_CTR * ctr)
3722 DEBUG(5, ("init_samr_q_set_aliasinfo\n"));
3724 q_u->alias_pol = *hnd;
3725 q_u->ctr = *ctr;
3728 /*******************************************************************
3729 reads or writes a structure.
3730 ********************************************************************/
3732 BOOL samr_io_q_set_aliasinfo(const char *desc, SAMR_Q_SET_ALIASINFO * q_u,
3733 prs_struct *ps, int depth)
3735 if (q_u == NULL)
3736 return False;
3738 prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
3739 depth++;
3741 if(!prs_align(ps))
3742 return False;
3744 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
3745 return False;
3746 if(!samr_alias_info_ctr("ctr", &q_u->ctr, ps, depth))
3747 return False;
3749 return True;
3752 /*******************************************************************
3753 reads or writes a structure.
3754 ********************************************************************/
3756 BOOL samr_io_r_set_aliasinfo(const char *desc, SAMR_R_SET_ALIASINFO * r_u,
3757 prs_struct *ps, int depth)
3759 if (r_u == NULL)
3760 return False;
3762 prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
3763 depth++;
3765 if(!prs_align(ps))
3766 return False;
3767 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3768 return False;
3770 return True;
3773 /*******************************************************************
3774 inits a SAMR_Q_QUERY_USERALIASES structure.
3775 ********************************************************************/
3777 void init_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES * q_u,
3778 POLICY_HND *hnd,
3779 uint32 num_sids,
3780 uint32 *ptr_sid, DOM_SID2 * sid)
3782 DEBUG(5, ("init_samr_q_query_useraliases\n"));
3784 q_u->pol = *hnd;
3786 q_u->num_sids1 = num_sids;
3787 q_u->ptr = 1;
3788 q_u->num_sids2 = num_sids;
3790 q_u->ptr_sid = ptr_sid;
3791 q_u->sid = sid;
3794 /*******************************************************************
3795 reads or writes a SAMR_Q_QUERY_USERALIASES structure.
3796 ********************************************************************/
3798 BOOL samr_io_q_query_useraliases(const char *desc, SAMR_Q_QUERY_USERALIASES * q_u,
3799 prs_struct *ps, int depth)
3801 fstring tmp;
3802 uint32 i;
3804 if (q_u == NULL)
3805 return False;
3807 prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
3808 depth++;
3810 if(!prs_align(ps))
3811 return False;
3813 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
3814 return False;
3816 if(!prs_uint32("num_sids1", ps, depth, &q_u->num_sids1))
3817 return False;
3818 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
3819 return False;
3821 if (q_u->ptr==0)
3822 return True;
3824 if(!prs_uint32("num_sids2", ps, depth, &q_u->num_sids2))
3825 return False;
3827 if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
3828 q_u->ptr_sid = (uint32 *)prs_alloc_mem(ps,sizeof(q_u->ptr_sid[0])*q_u->num_sids2);
3829 if (q_u->ptr_sid == NULL)
3830 return False;
3832 q_u->sid = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(q_u->sid[0]) * q_u->num_sids2);
3833 if (q_u->sid == NULL)
3834 return False;
3837 for (i = 0; i < q_u->num_sids2; i++) {
3838 slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
3839 if(!prs_uint32(tmp, ps, depth, &q_u->ptr_sid[i]))
3840 return False;
3843 for (i = 0; i < q_u->num_sids2; i++) {
3844 if (q_u->ptr_sid[i] != 0) {
3845 slprintf(tmp, sizeof(tmp) - 1, "sid[%02d]", i);
3846 if(!smb_io_dom_sid2(tmp, &q_u->sid[i], ps, depth))
3847 return False;
3851 return True;
3854 /*******************************************************************
3855 inits a SAMR_R_QUERY_USERALIASES structure.
3856 ********************************************************************/
3858 void init_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES * r_u,
3859 uint32 num_rids, uint32 *rid,
3860 NTSTATUS status)
3862 DEBUG(5, ("init_samr_r_query_useraliases\n"));
3864 if (NT_STATUS_IS_OK(status)) {
3865 r_u->num_entries = num_rids;
3866 r_u->ptr = 1;
3867 r_u->num_entries2 = num_rids;
3869 r_u->rid = rid;
3870 } else {
3871 r_u->num_entries = 0;
3872 r_u->ptr = 0;
3873 r_u->num_entries2 = 0;
3876 r_u->status = status;
3879 /*******************************************************************
3880 reads or writes a structure.
3881 ********************************************************************/
3883 BOOL samr_io_rids(const char *desc, uint32 *num_rids, uint32 **rid,
3884 prs_struct *ps, int depth)
3886 fstring tmp;
3887 uint32 i;
3888 if (rid == NULL)
3889 return False;
3891 prs_debug(ps, depth, desc, "samr_io_rids");
3892 depth++;
3894 if(!prs_align(ps))
3895 return False;
3897 if(!prs_uint32("num_rids", ps, depth, num_rids))
3898 return False;
3900 if ((*num_rids) != 0) {
3901 if (UNMARSHALLING(ps)) {
3902 /* reading */
3903 (*rid) = (uint32 *)prs_alloc_mem(ps,sizeof(uint32)*(*num_rids));
3905 if ((*rid) == NULL)
3906 return False;
3908 for (i = 0; i < (*num_rids); i++) {
3909 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]", i);
3910 if(!prs_uint32(tmp, ps, depth, &((*rid)[i])))
3911 return False;
3915 return True;
3918 /*******************************************************************
3919 reads or writes a structure.
3920 ********************************************************************/
3922 BOOL samr_io_r_query_useraliases(const char *desc, SAMR_R_QUERY_USERALIASES * r_u,
3923 prs_struct *ps, int depth)
3925 if (r_u == NULL)
3926 return False;
3928 prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
3929 depth++;
3931 if(!prs_align(ps))
3932 return False;
3934 if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries))
3935 return False;
3936 if(!prs_uint32("ptr ", ps, depth, &r_u->ptr))
3937 return False;
3939 if (r_u->ptr != 0) {
3940 if(!samr_io_rids("rids", &r_u->num_entries2, &r_u->rid, ps, depth))
3941 return False;
3944 if(!prs_align(ps))
3945 return False;
3946 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3947 return False;
3949 return True;
3952 /*******************************************************************
3953 inits a SAMR_Q_OPEN_ALIAS structure.
3954 ********************************************************************/
3956 void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS * q_u, POLICY_HND *pol,
3957 uint32 access_mask, uint32 rid)
3959 DEBUG(5, ("init_samr_q_open_alias\n"));
3961 q_u->dom_pol = *pol;
3962 q_u->access_mask = access_mask;
3963 q_u->rid_alias = rid;
3966 /*******************************************************************
3967 reads or writes a structure.
3968 ********************************************************************/
3970 BOOL samr_io_q_open_alias(const char *desc, SAMR_Q_OPEN_ALIAS * q_u,
3971 prs_struct *ps, int depth)
3973 if (q_u == NULL)
3974 return False;
3976 prs_debug(ps, depth, desc, "samr_io_q_open_alias");
3977 depth++;
3979 if(!prs_align(ps))
3980 return False;
3982 if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
3983 return False;
3985 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
3986 return False;
3987 if(!prs_uint32("rid_alias", ps, depth, &q_u->rid_alias))
3988 return False;
3990 return True;
3993 /*******************************************************************
3994 reads or writes a structure.
3995 ********************************************************************/
3997 BOOL samr_io_r_open_alias(const char *desc, SAMR_R_OPEN_ALIAS * r_u,
3998 prs_struct *ps, int depth)
4000 if (r_u == NULL)
4001 return False;
4003 prs_debug(ps, depth, desc, "samr_io_r_open_alias");
4004 depth++;
4006 if(!prs_align(ps))
4007 return False;
4009 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4010 return False;
4012 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4013 return False;
4015 return True;
4018 /*******************************************************************
4019 inits a SAMR_Q_LOOKUP_RIDS structure.
4020 ********************************************************************/
4022 void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
4023 POLICY_HND *pol, uint32 flags,
4024 uint32 num_rids, uint32 *rid)
4026 DEBUG(5, ("init_samr_q_lookup_rids\n"));
4028 q_u->pol = *pol;
4030 q_u->num_rids1 = num_rids;
4031 q_u->flags = flags;
4032 q_u->ptr = 0;
4033 q_u->num_rids2 = num_rids;
4034 q_u->rid = (uint32 *)talloc_zero(ctx, num_rids * sizeof(q_u->rid[0]));
4035 if (q_u->rid == NULL) {
4036 q_u->num_rids1 = 0;
4037 q_u->num_rids2 = 0;
4038 } else {
4039 memcpy(q_u->rid, rid, num_rids * sizeof(q_u->rid[0]));
4043 /*******************************************************************
4044 reads or writes a structure.
4045 ********************************************************************/
4047 BOOL samr_io_q_lookup_rids(const char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
4048 prs_struct *ps, int depth)
4050 uint32 i;
4051 fstring tmp;
4053 if (q_u == NULL)
4054 return False;
4056 prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
4057 depth++;
4059 if (UNMARSHALLING(ps))
4060 ZERO_STRUCTP(q_u);
4062 if(!prs_align(ps))
4063 return False;
4065 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4066 return False;
4068 if(!prs_uint32("num_rids1", ps, depth, &q_u->num_rids1))
4069 return False;
4070 if(!prs_uint32("flags ", ps, depth, &q_u->flags))
4071 return False;
4072 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
4073 return False;
4074 if(!prs_uint32("num_rids2", ps, depth, &q_u->num_rids2))
4075 return False;
4077 if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
4078 q_u->rid = (uint32 *)prs_alloc_mem(ps, sizeof(q_u->rid[0])*q_u->num_rids2);
4079 if (q_u->rid == NULL)
4080 return False;
4083 for (i = 0; i < q_u->num_rids2; i++) {
4084 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i);
4085 if(!prs_uint32(tmp, ps, depth, &q_u->rid[i]))
4086 return False;
4089 return True;
4092 /*******************************************************************
4093 inits a SAMR_R_LOOKUP_RIDS structure.
4094 ********************************************************************/
4096 void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS * r_u,
4097 uint32 num_names, UNIHDR * hdr_name,
4098 UNISTR2 *uni_name, uint32 *type)
4100 DEBUG(5, ("init_samr_r_lookup_rids\n"));
4102 r_u->hdr_name = NULL;
4103 r_u->uni_name = NULL;
4104 r_u->type = NULL;
4106 if (num_names != 0) {
4107 r_u->num_names1 = num_names;
4108 r_u->ptr_names = 1;
4109 r_u->num_names2 = num_names;
4111 r_u->num_types1 = num_names;
4112 r_u->ptr_types = 1;
4113 r_u->num_types2 = num_names;
4115 r_u->hdr_name = hdr_name;
4116 r_u->uni_name = uni_name;
4117 r_u->type = type;
4118 } else {
4119 r_u->num_names1 = num_names;
4120 r_u->ptr_names = 0;
4121 r_u->num_names2 = num_names;
4123 r_u->num_types1 = num_names;
4124 r_u->ptr_types = 0;
4125 r_u->num_types2 = num_names;
4129 /*******************************************************************
4130 reads or writes a structure.
4131 ********************************************************************/
4133 BOOL samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
4134 prs_struct *ps, int depth)
4136 uint32 i;
4137 fstring tmp;
4138 if (r_u == NULL)
4139 return False;
4141 prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
4142 depth++;
4144 if(!prs_align(ps))
4145 return False;
4147 if(!prs_uint32("num_names1", ps, depth, &r_u->num_names1))
4148 return False;
4149 if(!prs_uint32("ptr_names ", ps, depth, &r_u->ptr_names))
4150 return False;
4152 if (r_u->ptr_names != 0) {
4154 if(!prs_uint32("num_names2", ps, depth, &r_u->num_names2))
4155 return False;
4158 if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
4159 r_u->hdr_name = (UNIHDR *) prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->hdr_name[0]));
4160 if (r_u->hdr_name == NULL)
4161 return False;
4163 r_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->uni_name[0]));
4164 if (r_u->uni_name == NULL)
4165 return False;
4168 for (i = 0; i < r_u->num_names2; i++) {
4169 slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d] ", i);
4170 if(!smb_io_unihdr("", &r_u->hdr_name[i], ps, depth))
4171 return False;
4173 for (i = 0; i < r_u->num_names2; i++) {
4174 slprintf(tmp, sizeof(tmp) - 1, "str[%02d] ", i);
4175 if(!smb_io_unistr2("", &r_u->uni_name[i], r_u->hdr_name[i].buffer, ps, depth))
4176 return False;
4181 if(!prs_align(ps))
4182 return False;
4183 if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
4184 return False;
4185 if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
4186 return False;
4188 if (r_u->ptr_types != 0) {
4190 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
4191 return False;
4193 if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
4194 r_u->type = (uint32 *)prs_alloc_mem(ps, r_u->num_types2 * sizeof(r_u->type[0]));
4195 if (r_u->type == NULL)
4196 return False;
4199 for (i = 0; i < r_u->num_types2; i++) {
4200 slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i);
4201 if(!prs_uint32(tmp, ps, depth, &r_u->type[i]))
4202 return False;
4206 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4207 return False;
4209 return True;
4212 /*******************************************************************
4213 inits a SAMR_Q_OPEN_ALIAS structure.
4214 ********************************************************************/
4216 void init_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS * q_u, POLICY_HND *hnd)
4218 DEBUG(5, ("init_samr_q_delete_alias\n"));
4220 q_u->alias_pol = *hnd;
4223 /*******************************************************************
4224 reads or writes a structure.
4225 ********************************************************************/
4227 BOOL samr_io_q_delete_alias(const char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
4228 prs_struct *ps, int depth)
4230 if (q_u == NULL)
4231 return False;
4233 prs_debug(ps, depth, desc, "samr_io_q_delete_alias");
4234 depth++;
4236 if(!prs_align(ps))
4237 return False;
4239 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4240 return False;
4242 return True;
4245 /*******************************************************************
4246 reads or writes a structure.
4247 ********************************************************************/
4249 BOOL samr_io_r_delete_alias(const char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
4250 prs_struct *ps, int depth)
4252 if (r_u == NULL)
4253 return False;
4255 prs_debug(ps, depth, desc, "samr_io_r_delete_alias");
4256 depth++;
4258 if(!prs_align(ps))
4259 return False;
4261 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4262 return False;
4263 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4264 return False;
4266 return True;
4269 /*******************************************************************
4270 inits a SAMR_Q_CREATE_DOM_ALIAS structure.
4271 ********************************************************************/
4273 void init_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS * q_u,
4274 POLICY_HND *hnd, char *acct_desc)
4276 int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
4278 DEBUG(5, ("init_samr_q_create_dom_alias\n"));
4280 q_u->dom_pol = *hnd;
4282 init_uni_hdr(&q_u->hdr_acct_desc, acct_len);
4283 init_unistr2(&q_u->uni_acct_desc, acct_desc, acct_len);
4285 q_u->access_mask = 0x001f000f;
4288 /*******************************************************************
4289 reads or writes a structure.
4290 ********************************************************************/
4292 BOOL samr_io_q_create_dom_alias(const char *desc, SAMR_Q_CREATE_DOM_ALIAS * q_u,
4293 prs_struct *ps, int depth)
4295 if (q_u == NULL)
4296 return False;
4298 prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias");
4299 depth++;
4301 if(!prs_align(ps))
4302 return False;
4304 if(!smb_io_pol_hnd("dom_pol", &q_u->dom_pol, ps, depth))
4305 return False;
4307 if(!smb_io_unihdr("hdr_acct_desc", &q_u->hdr_acct_desc, ps, depth))
4308 return False;
4309 if(!smb_io_unistr2("uni_acct_desc", &q_u->uni_acct_desc,
4310 q_u->hdr_acct_desc.buffer, ps, depth))
4311 return False;
4313 if(!prs_align(ps))
4314 return False;
4315 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
4316 return False;
4318 return True;
4321 /*******************************************************************
4322 reads or writes a structure.
4323 ********************************************************************/
4325 BOOL samr_io_r_create_dom_alias(const char *desc, SAMR_R_CREATE_DOM_ALIAS * r_u,
4326 prs_struct *ps, int depth)
4328 if (r_u == NULL)
4329 return False;
4331 prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias");
4332 depth++;
4334 if(!prs_align(ps))
4335 return False;
4337 if(!smb_io_pol_hnd("alias_pol", &r_u->alias_pol, ps, depth))
4338 return False;
4340 if(!prs_uint32("rid", ps, depth, &r_u->rid))
4341 return False;
4343 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4344 return False;
4346 return True;
4349 /*******************************************************************
4350 inits a SAMR_Q_ADD_ALIASMEM structure.
4351 ********************************************************************/
4353 void init_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM * q_u, POLICY_HND *hnd,
4354 DOM_SID *sid)
4356 DEBUG(5, ("init_samr_q_add_aliasmem\n"));
4358 q_u->alias_pol = *hnd;
4359 init_dom_sid2(&q_u->sid, sid);
4362 /*******************************************************************
4363 reads or writes a structure.
4364 ********************************************************************/
4366 BOOL samr_io_q_add_aliasmem(const char *desc, SAMR_Q_ADD_ALIASMEM * q_u,
4367 prs_struct *ps, int depth)
4369 if (q_u == NULL)
4370 return False;
4372 prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem");
4373 depth++;
4375 if(!prs_align(ps))
4376 return False;
4378 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4379 return False;
4380 if(!smb_io_dom_sid2("sid ", &q_u->sid, ps, depth))
4381 return False;
4383 return True;
4386 /*******************************************************************
4387 reads or writes a structure.
4388 ********************************************************************/
4390 BOOL samr_io_r_add_aliasmem(const char *desc, SAMR_R_ADD_ALIASMEM * r_u,
4391 prs_struct *ps, int depth)
4393 if (r_u == NULL)
4394 return False;
4396 prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem");
4397 depth++;
4399 if(!prs_align(ps))
4400 return False;
4402 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4403 return False;
4405 return True;
4408 /*******************************************************************
4409 inits a SAMR_Q_DEL_ALIASMEM structure.
4410 ********************************************************************/
4412 void init_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM * q_u, POLICY_HND *hnd,
4413 DOM_SID *sid)
4415 DEBUG(5, ("init_samr_q_del_aliasmem\n"));
4417 q_u->alias_pol = *hnd;
4418 init_dom_sid2(&q_u->sid, sid);
4421 /*******************************************************************
4422 reads or writes a structure.
4423 ********************************************************************/
4425 BOOL samr_io_q_del_aliasmem(const char *desc, SAMR_Q_DEL_ALIASMEM * q_u,
4426 prs_struct *ps, int depth)
4428 if (q_u == NULL)
4429 return False;
4431 prs_debug(ps, depth, desc, "samr_io_q_del_aliasmem");
4432 depth++;
4434 if(!prs_align(ps))
4435 return False;
4437 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4438 return False;
4439 if(!smb_io_dom_sid2("sid ", &q_u->sid, ps, depth))
4440 return False;
4442 return True;
4445 /*******************************************************************
4446 reads or writes a structure.
4447 ********************************************************************/
4449 BOOL samr_io_r_del_aliasmem(const char *desc, SAMR_R_DEL_ALIASMEM * r_u,
4450 prs_struct *ps, int depth)
4452 if (r_u == NULL)
4453 return False;
4455 prs_debug(ps, depth, desc, "samr_io_r_del_aliasmem");
4456 depth++;
4458 if(!prs_align(ps))
4459 return False;
4461 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4462 return False;
4464 return True;
4467 /*******************************************************************
4468 inits a SAMR_Q_DELETE_DOM_ALIAS structure.
4469 ********************************************************************/
4471 void init_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS * q_c,
4472 POLICY_HND *hnd)
4474 DEBUG(5, ("init_samr_q_delete_dom_alias\n"));
4476 q_c->alias_pol = *hnd;
4479 /*******************************************************************
4480 reads or writes a structure.
4481 ********************************************************************/
4483 BOOL samr_io_q_delete_dom_alias(const char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
4484 prs_struct *ps, int depth)
4486 if (q_u == NULL)
4487 return False;
4489 prs_debug(ps, depth, desc, "samr_io_q_delete_dom_alias");
4490 depth++;
4492 if(!prs_align(ps))
4493 return False;
4495 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4496 return False;
4498 return True;
4501 /*******************************************************************
4502 inits a SAMR_R_DELETE_DOM_ALIAS structure.
4503 ********************************************************************/
4505 void init_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS * r_u,
4506 NTSTATUS status)
4508 DEBUG(5, ("init_samr_r_delete_dom_alias\n"));
4510 r_u->status = status;
4513 /*******************************************************************
4514 reads or writes a structure.
4515 ********************************************************************/
4517 BOOL samr_io_r_delete_dom_alias(const char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
4518 prs_struct *ps, int depth)
4520 if (r_u == NULL)
4521 return False;
4523 prs_debug(ps, depth, desc, "samr_io_r_delete_dom_alias");
4524 depth++;
4526 if(!prs_align(ps))
4527 return False;
4529 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4530 return False;
4532 return True;
4535 /*******************************************************************
4536 inits a SAMR_Q_QUERY_ALIASMEM structure.
4537 ********************************************************************/
4539 void init_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM * q_c,
4540 POLICY_HND *hnd)
4542 DEBUG(5, ("init_samr_q_query_aliasmem\n"));
4544 q_c->alias_pol = *hnd;
4547 /*******************************************************************
4548 reads or writes a structure.
4549 ********************************************************************/
4551 BOOL samr_io_q_query_aliasmem(const char *desc, SAMR_Q_QUERY_ALIASMEM * q_u,
4552 prs_struct *ps, int depth)
4554 if (q_u == NULL)
4555 return False;
4557 prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem");
4558 depth++;
4560 if(!prs_align(ps))
4561 return False;
4563 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4564 return False;
4566 return True;
4569 /*******************************************************************
4570 inits a SAMR_R_QUERY_ALIASMEM structure.
4571 ********************************************************************/
4573 void init_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM * r_u,
4574 uint32 num_sids, DOM_SID2 * sid,
4575 NTSTATUS status)
4577 DEBUG(5, ("init_samr_r_query_aliasmem\n"));
4579 if (NT_STATUS_IS_OK(status)) {
4580 r_u->num_sids = num_sids;
4581 r_u->ptr = (num_sids != 0) ? 1 : 0;
4582 r_u->num_sids1 = num_sids;
4584 r_u->sid = sid;
4585 } else {
4586 r_u->ptr = 0;
4587 r_u->num_sids = 0;
4590 r_u->status = status;
4593 /*******************************************************************
4594 reads or writes a structure.
4595 ********************************************************************/
4597 BOOL samr_io_r_query_aliasmem(const char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
4598 prs_struct *ps, int depth)
4600 uint32 i;
4601 uint32 ptr_sid[MAX_LOOKUP_SIDS];
4603 if (r_u == NULL)
4604 return False;
4606 prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
4607 depth++;
4609 if(!prs_align(ps))
4610 return False;
4612 if(!prs_uint32("num_sids ", ps, depth, &r_u->num_sids))
4613 return False;
4614 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
4615 return False;
4617 if (r_u->ptr != 0) {
4618 SMB_ASSERT_ARRAY(ptr_sid, r_u->num_sids);
4620 if (r_u->num_sids != 0) {
4621 if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
4622 return False;
4624 for (i = 0; i < r_u->num_sids1; i++) {
4625 ptr_sid[i] = 1;
4626 if(!prs_uint32("", ps, depth, &ptr_sid[i]))
4627 return False;
4630 for (i = 0; i < r_u->num_sids1; i++) {
4631 if (ptr_sid[i] != 0) {
4632 if(!smb_io_dom_sid2("", &r_u->sid[i], ps, depth))
4633 return False;
4639 if(!prs_align(ps))
4640 return False;
4641 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4642 return False;
4644 return True;
4647 /*******************************************************************
4648 inits a SAMR_Q_LOOKUP_NAMES structure.
4649 ********************************************************************/
4651 NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
4652 POLICY_HND *pol, uint32 flags,
4653 uint32 num_names, const char **name)
4655 uint32 i;
4657 DEBUG(5, ("init_samr_q_lookup_names\n"));
4659 q_u->pol = *pol;
4661 q_u->num_names1 = num_names;
4662 q_u->flags = flags;
4663 q_u->ptr = 0;
4664 q_u->num_names2 = num_names;
4666 if (!(q_u->hdr_name = (UNIHDR *)talloc_zero(ctx, num_names * sizeof(UNIHDR))))
4667 return NT_STATUS_NO_MEMORY;
4669 if (!(q_u->uni_name = (UNISTR2 *)talloc_zero(ctx, num_names * sizeof(UNISTR2))))
4670 return NT_STATUS_NO_MEMORY;
4672 for (i = 0; i < num_names; i++) {
4673 int len_name = name[i] != NULL ? strlen(name[i]) : 0;
4674 init_uni_hdr(&q_u->hdr_name[i], len_name); /* unicode header for user_name */
4675 init_unistr2(&q_u->uni_name[i], name[i], len_name); /* unicode string for machine account */
4678 return NT_STATUS_OK;
4681 /*******************************************************************
4682 reads or writes a structure.
4683 ********************************************************************/
4685 BOOL samr_io_q_lookup_names(const char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
4686 prs_struct *ps, int depth)
4688 uint32 i;
4690 if (q_u == NULL)
4691 return False;
4693 prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
4694 depth++;
4696 if (UNMARSHALLING(ps))
4697 ZERO_STRUCTP(q_u);
4699 if(!prs_align(ps))
4700 return False;
4702 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4703 return False;
4705 if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1))
4706 return False;
4707 if(!prs_uint32("flags ", ps, depth, &q_u->flags))
4708 return False;
4709 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
4710 return False;
4711 if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2))
4712 return False;
4714 if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
4715 q_u->hdr_name = (UNIHDR *)prs_alloc_mem(ps, sizeof(UNIHDR) *
4716 q_u->num_names2);
4717 q_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, sizeof(UNISTR2) *
4718 q_u->num_names2);
4719 if (!q_u->hdr_name || !q_u->uni_name)
4720 return False;
4723 for (i = 0; i < q_u->num_names2; i++) {
4724 if(!smb_io_unihdr("", &q_u->hdr_name[i], ps, depth))
4725 return False;
4728 for (i = 0; i < q_u->num_names2; i++) {
4729 if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth))
4730 return False;
4733 return True;
4736 /*******************************************************************
4737 inits a SAMR_R_LOOKUP_NAMES structure.
4738 ********************************************************************/
4740 NTSTATUS init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
4741 uint32 num_rids,
4742 uint32 *rid, uint32 *type,
4743 NTSTATUS status)
4745 DEBUG(5, ("init_samr_r_lookup_names\n"));
4747 if (NT_STATUS_IS_OK(status) && (num_rids != 0)) {
4748 uint32 i;
4750 r_u->num_types1 = num_rids;
4751 r_u->ptr_types = 1;
4752 r_u->num_types2 = num_rids;
4754 r_u->num_rids1 = num_rids;
4755 r_u->ptr_rids = 1;
4756 r_u->num_rids2 = num_rids;
4758 if (!(r_u->rids = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4759 return NT_STATUS_NO_MEMORY;
4760 if (!(r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4761 return NT_STATUS_NO_MEMORY;
4763 if (!r_u->rids || !r_u->types)
4764 goto empty;
4766 for (i = 0; i < num_rids; i++) {
4767 r_u->rids[i] = rid[i];
4768 r_u->types[i] = type[i];
4770 } else {
4772 empty:
4773 r_u->num_types1 = 0;
4774 r_u->ptr_types = 0;
4775 r_u->num_types2 = 0;
4777 r_u->num_rids1 = 0;
4778 r_u->ptr_rids = 0;
4779 r_u->num_rids2 = 0;
4781 r_u->rids = NULL;
4782 r_u->types = NULL;
4785 r_u->status = status;
4787 return NT_STATUS_OK;
4790 /*******************************************************************
4791 reads or writes a structure.
4792 ********************************************************************/
4794 BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
4795 prs_struct *ps, int depth)
4797 uint32 i;
4798 fstring tmp;
4800 if (r_u == NULL)
4801 return False;
4803 prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
4804 depth++;
4806 if (UNMARSHALLING(ps))
4807 ZERO_STRUCTP(r_u);
4809 if(!prs_align(ps))
4810 return False;
4812 if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1))
4813 return False;
4814 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
4815 return False;
4817 if (r_u->ptr_rids != 0) {
4818 if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2))
4819 return False;
4821 if (r_u->num_rids2 != r_u->num_rids1) {
4822 /* RPC fault */
4823 return False;
4826 if (UNMARSHALLING(ps))
4827 r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
4829 if (!r_u->rids) {
4830 DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
4831 return False;
4834 for (i = 0; i < r_u->num_rids2; i++) {
4835 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i);
4836 if(!prs_uint32(tmp, ps, depth, &r_u->rids[i]))
4837 return False;
4841 if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
4842 return False;
4843 if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
4844 return False;
4846 if (r_u->ptr_types != 0) {
4847 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
4848 return False;
4850 if (r_u->num_types2 != r_u->num_types1) {
4851 /* RPC fault */
4852 return False;
4855 if (UNMARSHALLING(ps))
4856 r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
4858 if (!r_u->types) {
4859 DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
4860 return False;
4863 for (i = 0; i < r_u->num_types2; i++) {
4864 slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i);
4865 if(!prs_uint32(tmp, ps, depth, &r_u->types[i]))
4866 return False;
4870 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4871 return False;
4873 return True;
4876 /*******************************************************************
4877 inits a SAMR_Q_DELETE_DOM_USER structure.
4878 ********************************************************************/
4880 void init_samr_q_delete_dom_user(SAMR_Q_DELETE_DOM_USER * q_c,
4881 POLICY_HND *hnd)
4883 DEBUG(5, ("init_samr_q_delete_dom_user\n"));
4885 q_c->user_pol = *hnd;
4888 /*******************************************************************
4889 reads or writes a structure.
4890 ********************************************************************/
4892 BOOL samr_io_q_delete_dom_user(const char *desc, SAMR_Q_DELETE_DOM_USER * q_u,
4893 prs_struct *ps, int depth)
4895 if (q_u == NULL)
4896 return False;
4898 prs_debug(ps, depth, desc, "samr_io_q_delete_dom_user");
4899 depth++;
4901 if(!prs_align(ps))
4902 return False;
4904 if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
4905 return False;
4907 return True;
4910 /*******************************************************************
4911 reads or writes a structure.
4912 ********************************************************************/
4914 BOOL samr_io_r_delete_dom_user(const char *desc, SAMR_R_DELETE_DOM_USER * r_u,
4915 prs_struct *ps, int depth)
4917 if (r_u == NULL)
4918 return False;
4920 prs_debug(ps, depth, desc, "samr_io_r_delete_dom_user");
4921 depth++;
4923 if(!prs_align(ps))
4924 return False;
4926 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4927 return False;
4928 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4929 return False;
4931 return True;
4934 /*******************************************************************
4935 reads or writes a structure.
4936 ********************************************************************/
4938 void init_samr_q_open_user(SAMR_Q_OPEN_USER * q_u,
4939 POLICY_HND *pol,
4940 uint32 access_mask, uint32 rid)
4942 DEBUG(5, ("samr_init_samr_q_open_user\n"));
4944 q_u->domain_pol = *pol;
4945 q_u->access_mask = access_mask;
4946 q_u->user_rid = rid;
4949 /*******************************************************************
4950 reads or writes a structure.
4951 ********************************************************************/
4953 BOOL samr_io_q_open_user(const char *desc, SAMR_Q_OPEN_USER * q_u,
4954 prs_struct *ps, int depth)
4956 if (q_u == NULL)
4957 return False;
4959 prs_debug(ps, depth, desc, "samr_io_q_open_user");
4960 depth++;
4962 if(!prs_align(ps))
4963 return False;
4965 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
4966 return False;
4968 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
4969 return False;
4970 if(!prs_uint32("user_rid ", ps, depth, &q_u->user_rid))
4971 return False;
4973 return True;
4976 /*******************************************************************
4977 reads or writes a structure.
4978 ********************************************************************/
4980 BOOL samr_io_r_open_user(const char *desc, SAMR_R_OPEN_USER * r_u,
4981 prs_struct *ps, int depth)
4983 if (r_u == NULL)
4984 return False;
4986 prs_debug(ps, depth, desc, "samr_io_r_open_user");
4987 depth++;
4989 if(!prs_align(ps))
4990 return False;
4992 if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
4993 return False;
4995 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4996 return False;
4998 return True;
5002 /*******************************************************************
5003 reads or writes a structure.
5004 ********************************************************************/
5006 void init_samr_q_create_user(SAMR_Q_CREATE_USER * q_u,
5007 POLICY_HND *pol,
5008 const char *name,
5009 uint32 acb_info, uint32 access_mask)
5011 int len_name;
5012 len_name = strlen(name);
5014 DEBUG(5, ("samr_init_samr_q_create_user\n"));
5016 q_u->domain_pol = *pol;
5018 init_uni_hdr(&q_u->hdr_name, len_name);
5019 init_unistr2(&q_u->uni_name, name, len_name);
5021 q_u->acb_info = acb_info;
5022 q_u->access_mask = access_mask;
5025 /*******************************************************************
5026 reads or writes a structure.
5027 ********************************************************************/
5029 BOOL samr_io_q_create_user(const char *desc, SAMR_Q_CREATE_USER * q_u,
5030 prs_struct *ps, int depth)
5032 if (q_u == NULL)
5033 return False;
5035 prs_debug(ps, depth, desc, "samr_io_q_create_user");
5036 depth++;
5038 if(!prs_align(ps))
5039 return False;
5041 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
5042 return False;
5044 if(!smb_io_unihdr("hdr_name", &q_u->hdr_name, ps, depth))
5045 return False;
5046 if(!smb_io_unistr2("uni_name", &q_u->uni_name, q_u->hdr_name.buffer, ps, depth))
5047 return False;
5049 if(!prs_align(ps))
5050 return False;
5051 if(!prs_uint32("acb_info ", ps, depth, &q_u->acb_info))
5052 return False;
5053 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
5054 return False;
5056 return True;
5059 /*******************************************************************
5060 reads or writes a structure.
5061 ********************************************************************/
5063 BOOL samr_io_r_create_user(const char *desc, SAMR_R_CREATE_USER * r_u,
5064 prs_struct *ps, int depth)
5066 if (r_u == NULL)
5067 return False;
5069 prs_debug(ps, depth, desc, "samr_io_r_create_user");
5070 depth++;
5072 if(!prs_align(ps))
5073 return False;
5075 if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
5076 return False;
5078 if(!prs_uint32("access_granted", ps, depth, &r_u->access_granted))
5079 return False;
5080 if(!prs_uint32("user_rid ", ps, depth, &r_u->user_rid))
5081 return False;
5082 if(!prs_ntstatus("status", ps, depth, &r_u->status))
5083 return False;
5085 return True;
5088 /*******************************************************************
5089 inits a SAMR_Q_QUERY_USERINFO structure.
5090 ********************************************************************/
5092 void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
5093 POLICY_HND *hnd, uint16 switch_value)
5095 DEBUG(5, ("init_samr_q_query_userinfo\n"));
5097 q_u->pol = *hnd;
5098 q_u->switch_value = switch_value;
5101 /*******************************************************************
5102 reads or writes a structure.
5103 ********************************************************************/
5105 BOOL samr_io_q_query_userinfo(const char *desc, SAMR_Q_QUERY_USERINFO * q_u,
5106 prs_struct *ps, int depth)
5108 if (q_u == NULL)
5109 return False;
5111 prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
5112 depth++;
5114 if(!prs_align(ps))
5115 return False;
5117 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
5118 return False;
5120 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */
5121 return False;
5123 return True;
5126 /*******************************************************************
5127 reads or writes a LOGON_HRS structure.
5128 ********************************************************************/
5130 static BOOL sam_io_logon_hrs(const char *desc, LOGON_HRS * hrs,
5131 prs_struct *ps, int depth)
5133 if (hrs == NULL)
5134 return False;
5136 prs_debug(ps, depth, desc, "sam_io_logon_hrs");
5137 depth++;
5139 if(!prs_align(ps))
5140 return False;
5142 if(!prs_uint32("len ", ps, depth, &hrs->len))
5143 return False;
5145 if (hrs->len > sizeof(hrs->hours)) {
5146 DEBUG(3, ("sam_io_logon_hrs: truncating length from %d\n", hrs->len));
5147 hrs->len = sizeof(hrs->hours);
5150 if(!prs_uint8s(False, "hours", ps, depth, hrs->hours, hrs->len))
5151 return False;
5153 return True;
5156 /*******************************************************************
5157 inits a SAM_USER_INFO_12 structure.
5158 ********************************************************************/
5160 void init_sam_user_info12(SAM_USER_INFO_12 * usr,
5161 const uint8 lm_pwd[16], const uint8 nt_pwd[16])
5163 DEBUG(5, ("init_sam_user_info12\n"));
5165 usr->lm_pwd_active =
5166 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd)) ? 1 : 0;
5167 usr->nt_pwd_active =
5168 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd)) ? 1 : 0;
5171 /*******************************************************************
5172 reads or writes a structure.
5173 ********************************************************************/
5175 static BOOL sam_io_user_info12(const char *desc, SAM_USER_INFO_12 * u,
5176 prs_struct *ps, int depth)
5178 if (u == NULL)
5179 return False;
5181 prs_debug(ps, depth, desc, "samr_io_r_user_info12");
5182 depth++;
5184 if(!prs_align(ps))
5185 return False;
5187 if(!prs_uint8s(False, "lm_pwd", ps, depth, u->lm_pwd, sizeof(u->lm_pwd)))
5188 return False;
5189 if(!prs_uint8s(False, "nt_pwd", ps, depth, u->nt_pwd, sizeof(u->nt_pwd)))
5190 return False;
5192 if(!prs_uint8("lm_pwd_active", ps, depth, &u->lm_pwd_active))
5193 return False;
5194 if(!prs_uint8("nt_pwd_active", ps, depth, &u->nt_pwd_active))
5195 return False;
5197 return True;
5200 /*******************************************************************
5201 inits a SAM_USER_INFO_10 structure.
5202 ********************************************************************/
5204 void init_sam_user_info10(SAM_USER_INFO_10 * usr, uint32 acb_info)
5206 DEBUG(5, ("init_sam_user_info10\n"));
5208 usr->acb_info = acb_info;
5211 /*******************************************************************
5212 reads or writes a structure.
5213 ********************************************************************/
5215 static BOOL sam_io_user_info10(const char *desc, SAM_USER_INFO_10 * usr,
5216 prs_struct *ps, int depth)
5218 if (usr == NULL)
5219 return False;
5221 prs_debug(ps, depth, desc, "samr_io_r_user_info10");
5222 depth++;
5224 if(!prs_align(ps))
5225 return False;
5227 if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
5228 return False;
5230 return True;
5233 /*******************************************************************
5234 inits a SAM_USER_INFO_11 structure.
5235 ********************************************************************/
5237 void init_sam_user_info11(SAM_USER_INFO_11 * usr,
5238 NTTIME * expiry,
5239 char *mach_acct,
5240 uint32 rid_user, uint32 rid_group, uint16 acct_ctrl)
5242 int len_mach_acct;
5244 DEBUG(5, ("init_sam_user_info11\n"));
5246 len_mach_acct = strlen(mach_acct);
5248 memcpy(&(usr->expiry), expiry, sizeof(usr->expiry)); /* expiry time or something? */
5249 ZERO_STRUCT(usr->padding_1); /* 0 - padding 24 bytes */
5251 init_uni_hdr(&usr->hdr_mach_acct, len_mach_acct); /* unicode header for machine account */
5252 usr->padding_2 = 0; /* 0 - padding 4 bytes */
5254 usr->ptr_1 = 1; /* pointer */
5255 ZERO_STRUCT(usr->padding_3); /* 0 - padding 32 bytes */
5256 usr->padding_4 = 0; /* 0 - padding 4 bytes */
5258 usr->ptr_2 = 1; /* pointer */
5259 usr->padding_5 = 0; /* 0 - padding 4 bytes */
5261 usr->ptr_3 = 1; /* pointer */
5262 ZERO_STRUCT(usr->padding_6); /* 0 - padding 32 bytes */
5264 usr->rid_user = rid_user;
5265 usr->rid_group = rid_group;
5267 usr->acct_ctrl = acct_ctrl;
5268 usr->unknown_3 = 0x0000;
5270 usr->unknown_4 = 0x003f; /* 0x003f - 16 bit unknown */
5271 usr->unknown_5 = 0x003c; /* 0x003c - 16 bit unknown */
5273 ZERO_STRUCT(usr->padding_7); /* 0 - padding 16 bytes */
5274 usr->padding_8 = 0; /* 0 - padding 4 bytes */
5276 init_unistr2(&usr->uni_mach_acct, mach_acct, len_mach_acct); /* unicode string for machine account */
5279 /*******************************************************************
5280 reads or writes a structure.
5281 ********************************************************************/
5283 static BOOL sam_io_user_info11(const char *desc, SAM_USER_INFO_11 * usr,
5284 prs_struct *ps, int depth)
5286 if (usr == NULL)
5287 return False;
5289 prs_debug(ps, depth, desc, "samr_io_r_unknown_11");
5290 depth++;
5292 if(!prs_align(ps))
5293 return False;
5295 if(!prs_uint8s(False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)))
5296 return False;
5298 if(!smb_io_time("time", &usr->expiry, ps, depth))
5299 return False;
5301 if(!prs_uint8s(False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)))
5302 return False;
5304 if(!smb_io_unihdr("unihdr", &usr->hdr_mach_acct, ps, depth))
5305 return False;
5307 if(!prs_uint32("padding_2", ps, depth, &usr->padding_2))
5308 return False;
5310 if(!prs_uint32("ptr_1 ", ps, depth, &usr->ptr_1))
5311 return False;
5312 if(!prs_uint8s(False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)))
5313 return False;
5315 if(!prs_uint32("padding_4", ps, depth, &usr->padding_4))
5316 return False;
5318 if(!prs_uint32("ptr_2 ", ps, depth, &usr->ptr_2))
5319 return False;
5320 if(!prs_uint32("padding_5", ps, depth, &usr->padding_5))
5321 return False;
5323 if(!prs_uint32("ptr_3 ", ps, depth, &usr->ptr_3))
5324 return False;
5325 if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6,sizeof(usr->padding_6)))
5326 return False;
5328 if(!prs_uint32("rid_user ", ps, depth, &usr->rid_user))
5329 return False;
5330 if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
5331 return False;
5332 if(!prs_uint16("acct_ctrl", ps, depth, &usr->acct_ctrl))
5333 return False;
5334 if(!prs_uint16("unknown_3", ps, depth, &usr->unknown_3))
5335 return False;
5336 if(!prs_uint16("unknown_4", ps, depth, &usr->unknown_4))
5337 return False;
5338 if(!prs_uint16("unknown_5", ps, depth, &usr->unknown_5))
5339 return False;
5341 if(!prs_uint8s(False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)))
5342 return False;
5344 if(!prs_uint32("padding_8", ps, depth, &(usr->padding_8)))
5345 return False;
5347 if(!smb_io_unistr2("unistr2", &usr->uni_mach_acct, True, ps, depth))
5348 return False;
5350 if(!prs_align(ps))
5351 return False;
5353 if(!prs_uint8s(False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9)))
5354 return False;
5356 return True;
5359 /*************************************************************************
5360 init_sam_user_infoa
5362 unknown_3 = 0x09f8 27fa
5363 unknown_5 = 0x0001 0000
5364 unknown_6 = 0x0000 04ec
5366 *************************************************************************/
5368 void init_sam_user_info24(SAM_USER_INFO_24 * usr, char newpass[516], uint16 pw_len)
5370 DEBUG(10, ("init_sam_user_info24:\n"));
5371 memcpy(usr->pass, newpass, sizeof(usr->pass));
5372 usr->pw_len = pw_len;
5375 /*******************************************************************
5376 reads or writes a structure.
5377 ********************************************************************/
5379 static BOOL sam_io_user_info24(const char *desc, SAM_USER_INFO_24 * usr,
5380 prs_struct *ps, int depth)
5382 if (usr == NULL)
5383 return False;
5385 prs_debug(ps, depth, desc, "sam_io_user_info24");
5386 depth++;
5388 if(!prs_align(ps))
5389 return False;
5391 if(!prs_uint8s(False, "password", ps, depth, usr->pass,
5392 sizeof(usr->pass)))
5393 return False;
5395 if (MARSHALLING(ps) && (usr->pw_len != 0)) {
5396 if (!prs_uint16("pw_len", ps, depth, &usr->pw_len))
5397 return False;
5399 if(!prs_align(ps))
5400 return False;
5402 return True;
5405 /*************************************************************************
5406 init_sam_user_info23
5408 unknown_3 = 0x09f8 27fa
5409 unknown_5 = 0x0001 0000
5410 unknown_6 = 0x0000 04ec
5412 *************************************************************************/
5414 void init_sam_user_info23W(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5415 NTTIME * logoff_time, /* all zeros */
5416 NTTIME * kickoff_time, /* all zeros */
5417 NTTIME * pass_last_set_time, /* all zeros */
5418 NTTIME * pass_can_change_time, /* all zeros */
5419 NTTIME * pass_must_change_time, /* all zeros */
5420 UNISTR2 *user_name,
5421 UNISTR2 *full_name,
5422 UNISTR2 *home_dir,
5423 UNISTR2 *dir_drive,
5424 UNISTR2 *log_scr,
5425 UNISTR2 *prof_path,
5426 UNISTR2 *desc,
5427 UNISTR2 *wkstas,
5428 UNISTR2 *unk_str,
5429 UNISTR2 *mung_dial,
5430 uint32 user_rid, /* 0x0000 0000 */
5431 uint32 group_rid,
5432 uint32 acb_info,
5433 uint32 unknown_3,
5434 uint16 logon_divs,
5435 LOGON_HRS * hrs,
5436 uint32 unknown_5,
5437 char newpass[516], uint32 unknown_6)
5439 int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
5440 int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
5441 int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
5442 int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
5443 int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
5444 int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
5445 int len_description = desc != NULL ? desc->uni_str_len : 0;
5446 int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
5447 int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
5448 int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
5450 usr->logon_time = *logon_time; /* all zeros */
5451 usr->logoff_time = *logoff_time; /* all zeros */
5452 usr->kickoff_time = *kickoff_time; /* all zeros */
5453 usr->pass_last_set_time = *pass_last_set_time; /* all zeros */
5454 usr->pass_can_change_time = *pass_can_change_time; /* all zeros */
5455 usr->pass_must_change_time = *pass_must_change_time; /* all zeros */
5457 init_uni_hdr(&usr->hdr_user_name, len_user_name); /* NULL */
5458 init_uni_hdr(&usr->hdr_full_name, len_full_name);
5459 init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5460 init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5461 init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5462 init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5463 init_uni_hdr(&usr->hdr_acct_desc, len_description);
5464 init_uni_hdr(&usr->hdr_workstations, len_workstations);
5465 init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5466 init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5468 ZERO_STRUCT(usr->nt_pwd);
5469 ZERO_STRUCT(usr->lm_pwd);
5471 usr->user_rid = user_rid; /* 0x0000 0000 */
5472 usr->group_rid = group_rid;
5473 usr->acb_info = acb_info;
5474 usr->unknown_3 = unknown_3; /* 09f8 27fa */
5476 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
5477 usr->ptr_logon_hrs = hrs ? 1 : 0;
5479 if (nt_time_is_zero(pass_must_change_time)) {
5480 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5481 } else {
5482 usr->passmustchange=0;
5486 ZERO_STRUCT(usr->padding1);
5487 ZERO_STRUCT(usr->padding2);
5489 usr->unknown_5 = unknown_5; /* 0x0001 0000 */
5491 memcpy(usr->pass, newpass, sizeof(usr->pass));
5493 copy_unistr2(&usr->uni_user_name, user_name);
5494 copy_unistr2(&usr->uni_full_name, full_name);
5495 copy_unistr2(&usr->uni_home_dir, home_dir);
5496 copy_unistr2(&usr->uni_dir_drive, dir_drive);
5497 copy_unistr2(&usr->uni_logon_script, log_scr);
5498 copy_unistr2(&usr->uni_profile_path, prof_path);
5499 copy_unistr2(&usr->uni_acct_desc, desc);
5500 copy_unistr2(&usr->uni_workstations, wkstas);
5501 copy_unistr2(&usr->uni_unknown_str, unk_str);
5502 copy_unistr2(&usr->uni_munged_dial, mung_dial);
5504 usr->unknown_6 = unknown_6; /* 0x0000 04ec */
5505 usr->padding4 = 0;
5507 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5510 /*************************************************************************
5511 init_sam_user_info23
5513 unknown_3 = 0x09f8 27fa
5514 unknown_5 = 0x0001 0000
5515 unknown_6 = 0x0000 04ec
5517 *************************************************************************/
5519 void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5520 NTTIME * logoff_time, /* all zeros */
5521 NTTIME * kickoff_time, /* all zeros */
5522 NTTIME * pass_last_set_time, /* all zeros */
5523 NTTIME * pass_can_change_time, /* all zeros */
5524 NTTIME * pass_must_change_time, /* all zeros */
5525 char *user_name, /* NULL */
5526 char *full_name,
5527 char *home_dir, char *dir_drive, char *log_scr,
5528 char *prof_path, const char *desc, char *wkstas,
5529 char *unk_str, char *mung_dial, uint32 user_rid, /* 0x0000 0000 */
5530 uint32 group_rid, uint32 acb_info,
5531 uint32 unknown_3, uint16 logon_divs,
5532 LOGON_HRS * hrs, uint32 unknown_5,
5533 char newpass[516], uint32 unknown_6)
5535 int len_user_name = user_name != NULL ? strlen(user_name) : 0;
5536 int len_full_name = full_name != NULL ? strlen(full_name) : 0;
5537 int len_home_dir = home_dir != NULL ? strlen(home_dir) : 0;
5538 int len_dir_drive = dir_drive != NULL ? strlen(dir_drive) : 0;
5539 int len_logon_script = log_scr != NULL ? strlen(log_scr) : 0;
5540 int len_profile_path = prof_path != NULL ? strlen(prof_path) : 0;
5541 int len_description = desc != NULL ? strlen(desc) : 0;
5542 int len_workstations = wkstas != NULL ? strlen(wkstas) : 0;
5543 int len_unknown_str = unk_str != NULL ? strlen(unk_str) : 0;
5544 int len_munged_dial = mung_dial != NULL ? strlen(mung_dial) : 0;
5546 usr->logon_time = *logon_time; /* all zeros */
5547 usr->logoff_time = *logoff_time; /* all zeros */
5548 usr->kickoff_time = *kickoff_time; /* all zeros */
5549 usr->pass_last_set_time = *pass_last_set_time; /* all zeros */
5550 usr->pass_can_change_time = *pass_can_change_time; /* all zeros */
5551 usr->pass_must_change_time = *pass_must_change_time; /* all zeros */
5553 init_uni_hdr(&usr->hdr_user_name, len_user_name); /* NULL */
5554 init_uni_hdr(&usr->hdr_full_name, len_full_name);
5555 init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5556 init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5557 init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5558 init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5559 init_uni_hdr(&usr->hdr_acct_desc, len_description);
5560 init_uni_hdr(&usr->hdr_workstations, len_workstations);
5561 init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5562 init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5564 ZERO_STRUCT(usr->nt_pwd);
5565 ZERO_STRUCT(usr->lm_pwd);
5567 usr->user_rid = user_rid; /* 0x0000 0000 */
5568 usr->group_rid = group_rid;
5569 usr->acb_info = acb_info;
5570 usr->unknown_3 = unknown_3; /* 09f8 27fa */
5572 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
5573 usr->ptr_logon_hrs = hrs ? 1 : 0;
5575 if (nt_time_is_zero(pass_must_change_time)) {
5576 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5577 } else {
5578 usr->passmustchange=0;
5581 ZERO_STRUCT(usr->padding1);
5582 ZERO_STRUCT(usr->padding2);
5584 usr->unknown_5 = unknown_5; /* 0x0001 0000 */
5586 memcpy(usr->pass, newpass, sizeof(usr->pass));
5588 init_unistr2(&usr->uni_user_name, user_name, len_user_name); /* NULL */
5589 init_unistr2(&usr->uni_full_name, full_name, len_full_name);
5590 init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
5591 init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
5592 init_unistr2(&usr->uni_logon_script, log_scr, len_logon_script);
5593 init_unistr2(&usr->uni_profile_path, prof_path, len_profile_path);
5594 init_unistr2(&usr->uni_acct_desc, desc, len_description);
5595 init_unistr2(&usr->uni_workstations, wkstas, len_workstations);
5596 init_unistr2(&usr->uni_unknown_str, unk_str, len_unknown_str);
5597 init_unistr2(&usr->uni_munged_dial, mung_dial, len_munged_dial);
5599 usr->unknown_6 = unknown_6; /* 0x0000 04ec */
5600 usr->padding4 = 0;
5602 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5605 /*******************************************************************
5606 reads or writes a structure.
5607 ********************************************************************/
5609 static BOOL sam_io_user_info23(const char *desc, SAM_USER_INFO_23 * usr,
5610 prs_struct *ps, int depth)
5612 if (usr == NULL)
5613 return False;
5615 prs_debug(ps, depth, desc, "sam_io_user_info23");
5616 depth++;
5618 if(!prs_align(ps))
5619 return False;
5621 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
5622 return False;
5623 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
5624 return False;
5625 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
5626 return False;
5627 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps, depth))
5628 return False;
5629 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5630 return False;
5631 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5632 return False;
5634 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
5635 return False;
5636 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
5637 return False;
5638 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
5639 return False;
5640 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
5641 return False;
5642 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
5643 return False;
5644 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
5645 return False;
5646 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
5647 return False;
5648 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
5649 return False;
5650 if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
5651 return False;
5652 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
5653 return False;
5655 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5656 return False;
5657 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5658 return False;
5660 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
5661 return False;
5662 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
5663 return False;
5664 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
5665 return False;
5667 if(!prs_uint32("unknown_3 ", ps, depth, &usr->unknown_3))
5668 return False;
5669 if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */
5670 return False;
5671 if(!prs_align(ps))
5672 return False;
5673 if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
5674 return False;
5676 if(!prs_uint32("unknown_5 ", ps, depth, &usr->unknown_5))
5677 return False;
5679 if(!prs_uint8s(False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)))
5680 return False;
5681 if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
5682 return False;
5683 if(!prs_uint8("padding2 ", ps, depth, &usr->padding2))
5684 return False;
5687 if(!prs_uint8s(False, "password ", ps, depth, usr->pass, sizeof(usr->pass)))
5688 return False;
5690 /* here begins pointed-to data */
5692 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
5693 return False;
5695 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
5696 return False;
5698 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
5699 return False;
5701 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
5702 return False;
5704 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
5705 return False;
5707 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
5708 return False;
5710 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
5711 return False;
5713 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
5714 return False;
5716 if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth)) /* unknown string */
5717 return False;
5719 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5720 return False;
5722 /* ok, this is only guess-work (as usual) */
5723 if (usr->ptr_logon_hrs) {
5724 if(!prs_uint32("unknown_6 ", ps, depth, &usr->unknown_6))
5725 return False;
5726 if(!prs_uint32("padding4 ", ps, depth, &usr->padding4))
5727 return False;
5728 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5729 return False;
5730 } else if (UNMARSHALLING(ps)) {
5731 usr->unknown_6 = 0;
5732 usr->padding4 = 0;
5735 return True;
5738 /*******************************************************************
5739 reads or writes a structure.
5740 NB. This structure is *definately* incorrect. It's my best guess
5741 currently for W2K SP2. The password field is encrypted in a different
5742 way than normal... And there are definately other problems. JRA.
5743 ********************************************************************/
5745 static BOOL sam_io_user_info25(const char *desc, SAM_USER_INFO_25 * usr, prs_struct *ps, int depth)
5747 if (usr == NULL)
5748 return False;
5750 prs_debug(ps, depth, desc, "sam_io_user_info25");
5751 depth++;
5753 if(!prs_align(ps))
5754 return False;
5756 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
5757 return False;
5758 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
5759 return False;
5760 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
5761 return False;
5762 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps, depth))
5763 return False;
5764 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5765 return False;
5766 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5767 return False;
5769 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
5770 return False;
5771 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
5772 return False;
5773 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
5774 return False;
5775 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
5776 return False;
5777 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
5778 return False;
5779 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
5780 return False;
5781 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
5782 return False;
5783 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
5784 return False;
5785 if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
5786 return False;
5787 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
5788 return False;
5790 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5791 return False;
5792 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5793 return False;
5795 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
5796 return False;
5797 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
5798 return False;
5799 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
5800 return False;
5802 if(!prs_uint32s(False, "unknown_6 ", ps, depth, usr->unknown_6, 6))
5803 return False;
5805 if(!prs_uint8s(False, "password ", ps, depth, usr->pass, sizeof(usr->pass)))
5806 return False;
5808 /* here begins pointed-to data */
5810 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
5811 return False;
5813 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
5814 return False;
5816 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
5817 return False;
5819 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
5820 return False;
5822 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
5823 return False;
5825 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
5826 return False;
5828 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
5829 return False;
5831 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
5832 return False;
5834 if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth)) /* unknown string */
5835 return False;
5837 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5838 return False;
5840 #if 0 /* JRA - unknown... */
5841 /* ok, this is only guess-work (as usual) */
5842 if (usr->ptr_logon_hrs) {
5843 if(!prs_uint32("unknown_6 ", ps, depth, &usr->unknown_6))
5844 return False;
5845 if(!prs_uint32("padding4 ", ps, depth, &usr->padding4))
5846 return False;
5847 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5848 return False;
5849 } else if (UNMARSHALLING(ps)) {
5850 usr->unknown_6 = 0;
5851 usr->padding4 = 0;
5853 #endif
5855 return True;
5859 /*************************************************************************
5860 init_sam_user_info21W
5862 unknown_3 = 0x00ff ffff
5863 unknown_5 = 0x0002 0000
5864 unknown_6 = 0x0000 04ec
5866 *************************************************************************/
5868 void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
5869 NTTIME * logon_time,
5870 NTTIME * logoff_time,
5871 NTTIME * kickoff_time,
5872 NTTIME * pass_last_set_time,
5873 NTTIME * pass_can_change_time,
5874 NTTIME * pass_must_change_time,
5875 UNISTR2 *user_name,
5876 UNISTR2 *full_name,
5877 UNISTR2 *home_dir,
5878 UNISTR2 *dir_drive,
5879 UNISTR2 *log_scr,
5880 UNISTR2 *prof_path,
5881 UNISTR2 *desc,
5882 UNISTR2 *wkstas,
5883 UNISTR2 *unk_str,
5884 UNISTR2 *mung_dial,
5885 uchar lm_pwd[16],
5886 uchar nt_pwd[16],
5887 uint32 user_rid,
5888 uint32 group_rid,
5889 uint32 acb_info,
5890 uint32 unknown_3,
5891 uint16 logon_divs,
5892 LOGON_HRS * hrs,
5893 uint32 unknown_5, uint32 unknown_6)
5895 int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
5896 int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
5897 int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
5898 int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
5899 int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
5900 int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
5901 int len_description = desc != NULL ? desc->uni_str_len : 0;
5902 int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
5903 int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
5904 int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
5906 usr->logon_time = *logon_time;
5907 usr->logoff_time = *logoff_time;
5908 usr->kickoff_time = *kickoff_time;
5909 usr->pass_last_set_time = *pass_last_set_time;
5910 usr->pass_can_change_time = *pass_can_change_time;
5911 usr->pass_must_change_time = *pass_must_change_time;
5913 init_uni_hdr(&usr->hdr_user_name, len_user_name);
5914 init_uni_hdr(&usr->hdr_full_name, len_full_name);
5915 init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5916 init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5917 init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5918 init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5919 init_uni_hdr(&usr->hdr_acct_desc, len_description);
5920 init_uni_hdr(&usr->hdr_workstations, len_workstations);
5921 init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5922 init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5924 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd));
5925 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd));
5927 usr->user_rid = user_rid;
5928 usr->group_rid = group_rid;
5929 usr->acb_info = acb_info;
5930 usr->unknown_3 = unknown_3; /* 0x00ff ffff */
5932 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
5933 usr->ptr_logon_hrs = hrs ? 1 : 0;
5934 usr->unknown_5 = unknown_5; /* 0x0002 0000 */
5936 if (nt_time_is_zero(pass_must_change_time)) {
5937 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5938 } else {
5939 usr->passmustchange=0;
5943 ZERO_STRUCT(usr->padding1);
5944 ZERO_STRUCT(usr->padding2);
5946 copy_unistr2(&usr->uni_user_name, user_name);
5947 copy_unistr2(&usr->uni_full_name, full_name);
5948 copy_unistr2(&usr->uni_home_dir, home_dir);
5949 copy_unistr2(&usr->uni_dir_drive, dir_drive);
5950 copy_unistr2(&usr->uni_logon_script, log_scr);
5951 copy_unistr2(&usr->uni_profile_path, prof_path);
5952 copy_unistr2(&usr->uni_acct_desc, desc);
5953 copy_unistr2(&usr->uni_workstations, wkstas);
5954 copy_unistr2(&usr->uni_unknown_str, unk_str);
5955 copy_unistr2(&usr->uni_munged_dial, mung_dial);
5957 usr->unknown_6 = unknown_6; /* 0x0000 04ec */
5958 usr->padding4 = 0;
5960 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5963 /*************************************************************************
5964 init_sam_user_info21
5966 unknown_3 = 0x00ff ffff
5967 unknown_5 = 0x0002 0000
5968 unknown_6 = 0x0000 04ec
5970 *************************************************************************/
5972 NTSTATUS init_sam_user_info21A(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw, DOM_SID *domain_sid)
5974 NTTIME logon_time, logoff_time, kickoff_time,
5975 pass_last_set_time, pass_can_change_time,
5976 pass_must_change_time;
5978 int len_user_name, len_full_name, len_home_dir,
5979 len_dir_drive, len_logon_script, len_profile_path,
5980 len_description, len_workstations, len_unknown_str,
5981 len_munged_dial;
5983 const char* user_name = pdb_get_username(pw);
5984 const char* full_name = pdb_get_fullname(pw);
5985 const char* home_dir = pdb_get_homedir(pw);
5986 const char* dir_drive = pdb_get_dir_drive(pw);
5987 const char* logon_script = pdb_get_logon_script(pw);
5988 const char* profile_path = pdb_get_profile_path(pw);
5989 const char* description = pdb_get_acct_desc(pw);
5990 const char* workstations = pdb_get_workstations(pw);
5991 const char* munged_dial = pdb_get_munged_dial(pw);
5993 uint32 user_rid;
5994 const DOM_SID *user_sid;
5996 uint32 group_rid;
5997 const DOM_SID *group_sid;
5999 len_user_name = user_name != NULL ? strlen(user_name )+1 : 0;
6000 len_full_name = full_name != NULL ? strlen(full_name )+1 : 0;
6001 len_home_dir = home_dir != NULL ? strlen(home_dir )+1 : 0;
6002 len_dir_drive = dir_drive != NULL ? strlen(dir_drive )+1 : 0;
6003 len_logon_script = logon_script != NULL ? strlen(logon_script)+1 : 0;
6004 len_profile_path = profile_path != NULL ? strlen(profile_path)+1 : 0;
6005 len_description = description != NULL ? strlen(description )+1 : 0;
6006 len_workstations = workstations != NULL ? strlen(workstations)+1 : 0;
6007 len_unknown_str = 0;
6008 len_munged_dial = munged_dial != NULL ? strlen(munged_dial )+1 : 0;
6011 /* Create NTTIME structs */
6012 unix_to_nt_time (&logon_time, pdb_get_logon_time(pw));
6013 unix_to_nt_time (&logoff_time, pdb_get_logoff_time(pw));
6014 unix_to_nt_time (&kickoff_time, pdb_get_kickoff_time(pw));
6015 unix_to_nt_time (&pass_last_set_time, pdb_get_pass_last_set_time(pw));
6016 unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(pw));
6017 unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(pw));
6019 /* structure assignment */
6020 usr->logon_time = logon_time;
6021 usr->logoff_time = logoff_time;
6022 usr->kickoff_time = kickoff_time;
6023 usr->pass_last_set_time = pass_last_set_time;
6024 usr->pass_can_change_time = pass_can_change_time;
6025 usr->pass_must_change_time = pass_must_change_time;
6027 init_uni_hdr(&usr->hdr_user_name, len_user_name);
6028 init_uni_hdr(&usr->hdr_full_name, len_full_name);
6029 init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
6030 init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
6031 init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
6032 init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
6033 init_uni_hdr(&usr->hdr_acct_desc, len_description);
6034 init_uni_hdr(&usr->hdr_workstations, len_workstations);
6035 init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
6036 init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
6038 ZERO_STRUCT(usr->nt_pwd);
6039 ZERO_STRUCT(usr->lm_pwd);
6041 user_sid = pdb_get_user_sid(pw);
6043 if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
6044 fstring user_sid_string;
6045 fstring domain_sid_string;
6046 DEBUG(0, ("init_sam_user_info_21A: User %s has SID %s, \nwhich conflicts with "
6047 "the domain sid %s. Failing operation.\n",
6048 user_name,
6049 sid_to_string(user_sid_string, user_sid),
6050 sid_to_string(domain_sid_string, domain_sid)));
6051 return NT_STATUS_UNSUCCESSFUL;
6054 group_sid = pdb_get_group_sid(pw);
6056 if (!sid_peek_check_rid(domain_sid, group_sid, &group_rid)) {
6057 fstring group_sid_string;
6058 fstring domain_sid_string;
6059 DEBUG(0, ("init_sam_user_info_21A: User %s has Primary Group SID %s, \n"
6060 "which conflicts with the domain sid %s. Failing operation.\n",
6061 user_name,
6062 sid_to_string(group_sid_string, group_sid),
6063 sid_to_string(domain_sid_string, domain_sid)));
6064 return NT_STATUS_UNSUCCESSFUL;
6067 usr->user_rid = user_rid;
6068 usr->group_rid = group_rid;
6069 usr->acb_info = pdb_get_acct_ctrl(pw);
6072 Look at a user on a real NT4 PDC with usrmgr, press
6073 'ok'. Then you will see that unknown_3 is set to
6074 0x08f827fa. Look at the user immediately after that again,
6075 and you will see that 0x00fffff is returned. This solves
6076 the problem that you get access denied after having looked
6077 at the user.
6078 -- Volker
6080 usr->unknown_3 = 0x00ffffff;
6082 usr->logon_divs = pdb_get_logon_divs(pw);
6083 usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
6084 usr->unknown_5 = pdb_get_unknown_5(pw); /* 0x0002 0000 */
6086 if (pdb_get_pass_must_change_time(pw) == 0) {
6087 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
6088 } else {
6089 usr->passmustchange=0;
6093 ZERO_STRUCT(usr->padding1);
6094 ZERO_STRUCT(usr->padding2);
6096 init_unistr2(&usr->uni_user_name, user_name, len_user_name);
6097 init_unistr2(&usr->uni_full_name, full_name, len_full_name);
6098 init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
6099 init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
6100 init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
6101 init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
6102 init_unistr2(&usr->uni_acct_desc, description, len_description);
6103 init_unistr2(&usr->uni_workstations, workstations, len_workstations);
6104 init_unistr2(&usr->uni_unknown_str, NULL, len_unknown_str);
6105 init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
6107 usr->unknown_6 = pdb_get_unknown_6(pw);
6108 usr->padding4 = 0;
6110 if (pdb_get_hours(pw)) {
6111 usr->logon_hrs.len = pdb_get_hours_len(pw);
6112 memcpy(&usr->logon_hrs.hours, pdb_get_hours(pw), MAX_HOURS_LEN);
6113 } else
6114 memset(&usr->logon_hrs, 0xff, sizeof(usr->logon_hrs));
6116 return NT_STATUS_OK;
6119 /*******************************************************************
6120 reads or writes a structure.
6121 ********************************************************************/
6123 static BOOL sam_io_user_info21(const char *desc, SAM_USER_INFO_21 * usr,
6124 prs_struct *ps, int depth)
6126 if (usr == NULL)
6127 return False;
6129 prs_debug(ps, depth, desc, "sam_io_user_info21");
6130 depth++;
6132 if(!prs_align(ps))
6133 return False;
6135 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
6136 return False;
6137 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
6138 return False;
6139 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps,depth))
6140 return False;
6141 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
6142 return False;
6143 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps,depth))
6144 return False;
6145 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
6146 return False;
6148 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
6149 return False;
6150 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
6151 return False;
6152 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
6153 return False;
6154 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
6155 return False;
6156 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
6157 return False;
6158 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
6159 return False;
6160 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
6161 return False;
6162 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
6163 return False;
6164 if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
6165 return False;
6166 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
6167 return False;
6169 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
6170 return False;
6171 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
6172 return False;
6174 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
6175 return False;
6176 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
6177 return False;
6178 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
6179 return False;
6181 if(!prs_uint32("unknown_3 ", ps, depth, &usr->unknown_3))
6182 return False;
6183 if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */
6184 return False;
6185 if(!prs_align(ps))
6186 return False;
6187 if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
6188 return False;
6190 if(!prs_uint32("unknown_5 ", ps, depth, &usr->unknown_5))
6191 return False;
6193 if(!prs_uint8s(False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)))
6194 return False;
6195 if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
6196 return False;
6197 if(!prs_uint8("padding2 ", ps, depth, &usr->padding2))
6198 return False;
6200 /* here begins pointed-to data */
6202 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name,usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
6203 return False;
6204 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
6205 return False;
6206 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
6207 return False;
6208 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
6209 return False;
6210 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
6211 return False;
6212 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
6213 return False;
6214 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
6215 return False;
6216 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
6217 return False;
6218 if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth)) /* unknown string */
6219 return False;
6220 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth)) /* worksations user can log on from */
6221 return False;
6223 /* ok, this is only guess-work (as usual) */
6224 if (usr->ptr_logon_hrs) {
6225 if(!prs_align(ps))
6226 return False;
6227 if(!prs_uint32("unknown_6 ", ps, depth, &usr->unknown_6))
6228 return False;
6229 if(!prs_uint32("padding4 ", ps, depth, &usr->padding4))
6230 return False;
6231 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
6232 return False;
6233 } else if (UNMARSHALLING(ps)) {
6234 usr->unknown_6 = 0;
6235 usr->padding4 = 0;
6238 return True;
6241 void init_sam_user_info20A(SAM_USER_INFO_20 *usr, SAM_ACCOUNT *pw)
6243 int len_munged_dial;
6244 const char* munged_dial = pdb_get_munged_dial(pw);
6246 len_munged_dial = munged_dial != NULL ? strlen(munged_dial )+1 : 0;
6247 init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
6248 init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
6252 /*******************************************************************
6253 reads or writes a structure.
6254 ********************************************************************/
6256 static BOOL sam_io_user_info20(const char *desc, SAM_USER_INFO_20 *usr,
6257 prs_struct *ps, int depth)
6259 if (usr == NULL)
6260 return False;
6262 prs_debug(ps, depth, desc, "sam_io_user_info20");
6263 depth++;
6265 if(!prs_align(ps))
6266 return False;
6268 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
6269 return False;
6271 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth)) /* worksations user can log on from */
6272 return False;
6274 return True;
6277 /*******************************************************************
6278 inits a SAM_USERINFO_CTR structure.
6279 ********************************************************************/
6281 NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
6282 uint16 switch_value,
6283 SAM_USER_INFO_21 * usr)
6285 DEBUG(5, ("init_samr_userinfo_ctr\n"));
6287 ctr->switch_value = switch_value;
6288 ctr->info.id = NULL;
6290 switch (switch_value) {
6291 case 0x10:
6292 ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
6293 if (ctr->info.id10 == NULL)
6294 return NT_STATUS_NO_MEMORY;
6296 init_sam_user_info10(ctr->info.id10, usr->acb_info);
6297 break;
6298 #if 0
6299 /* whoops - got this wrong. i think. or don't understand what's happening. */
6300 case 0x11:
6302 NTTIME expire;
6303 info = (void *)&id11;
6305 expire.low = 0xffffffff;
6306 expire.high = 0x7fffffff;
6308 ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
6309 init_sam_user_info11(ctr->info.id11, &expire,
6310 "BROOKFIELDS$", /* name */
6311 0x03ef, /* user rid */
6312 0x201, /* group rid */
6313 0x0080); /* acb info */
6315 break;
6317 #endif
6318 case 0x12:
6319 ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
6320 if (ctr->info.id12 == NULL)
6321 return NT_STATUS_NO_MEMORY;
6323 init_sam_user_info12(ctr->info.id12, usr->lm_pwd, usr->nt_pwd);
6324 break;
6325 case 21:
6327 SAM_USER_INFO_21 *cusr;
6328 cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
6329 ctr->info.id21 = cusr;
6330 if (ctr->info.id21 == NULL)
6331 return NT_STATUS_NO_MEMORY;
6332 memcpy(cusr, usr, sizeof(*usr));
6333 memset(cusr->lm_pwd, 0, sizeof(cusr->lm_pwd));
6334 memset(cusr->nt_pwd, 0, sizeof(cusr->nt_pwd));
6335 break;
6337 default:
6338 DEBUG(4,("make_samr_userinfo_ctr: unsupported info\n"));
6339 return NT_STATUS_INVALID_INFO_CLASS;
6342 return NT_STATUS_OK;
6345 /*******************************************************************
6346 inits a SAM_USERINFO_CTR structure.
6347 ********************************************************************/
6349 void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, uchar * sess_key,
6350 uint16 switch_value, void *info)
6352 DEBUG(5, ("init_samr_userinfo_ctr\n"));
6354 ctr->switch_value = switch_value;
6355 ctr->info.id = info;
6357 switch (switch_value) {
6358 case 0x18:
6359 SamOEMhash(ctr->info.id24->pass, sess_key, 516);
6360 dump_data(100, (char *)sess_key, 16);
6361 dump_data(100, (char *)ctr->info.id24->pass, 516);
6362 break;
6363 case 0x17:
6364 SamOEMhash(ctr->info.id23->pass, sess_key, 516);
6365 dump_data(100, (char *)sess_key, 16);
6366 dump_data(100, (char *)ctr->info.id23->pass, 516);
6367 break;
6368 default:
6369 DEBUG(4,("init_samr_userinfo_ctr: unsupported switch level\n"));
6373 /*******************************************************************
6374 reads or writes a structure.
6375 ********************************************************************/
6377 static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
6378 prs_struct *ps, int depth)
6380 BOOL ret;
6381 SAM_USERINFO_CTR *ctr;
6383 prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
6384 depth++;
6386 if (UNMARSHALLING(ps)) {
6387 ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
6388 if (ctr == NULL)
6389 return False;
6390 *ppctr = ctr;
6391 } else {
6392 ctr = *ppctr;
6395 /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
6397 if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
6398 return False;
6399 if(!prs_align(ps))
6400 return False;
6402 ret = False;
6404 switch (ctr->switch_value) {
6405 case 0x10:
6406 if (UNMARSHALLING(ps))
6407 ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
6408 if (ctr->info.id10 == NULL) {
6409 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6410 return False;
6412 ret = sam_io_user_info10("", ctr->info.id10, ps, depth);
6413 break;
6414 case 0x11:
6415 if (UNMARSHALLING(ps))
6416 ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
6418 if (ctr->info.id11 == NULL) {
6419 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6420 return False;
6422 ret = sam_io_user_info11("", ctr->info.id11, ps, depth);
6423 break;
6424 case 0x12:
6425 if (UNMARSHALLING(ps))
6426 ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
6428 if (ctr->info.id12 == NULL) {
6429 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6430 return False;
6432 ret = sam_io_user_info12("", ctr->info.id12, ps, depth);
6433 break;
6434 case 20:
6435 if (UNMARSHALLING(ps))
6436 ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
6438 if (ctr->info.id20 == NULL) {
6439 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6440 return False;
6442 ret = sam_io_user_info20("", ctr->info.id20, ps, depth);
6443 break;
6444 case 21:
6445 if (UNMARSHALLING(ps))
6446 ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
6448 if (ctr->info.id21 == NULL) {
6449 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6450 return False;
6452 ret = sam_io_user_info21("", ctr->info.id21, ps, depth);
6453 break;
6454 case 23:
6455 if (UNMARSHALLING(ps))
6456 ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
6458 if (ctr->info.id23 == NULL) {
6459 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6460 return False;
6462 ret = sam_io_user_info23("", ctr->info.id23, ps, depth);
6463 break;
6464 case 24:
6465 if (UNMARSHALLING(ps))
6466 ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
6468 if (ctr->info.id24 == NULL) {
6469 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6470 return False;
6472 ret = sam_io_user_info24("", ctr->info.id24, ps, depth);
6473 break;
6474 case 25:
6475 if (UNMARSHALLING(ps))
6476 ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
6478 if (ctr->info.id25 == NULL) {
6479 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6480 return False;
6482 ret = sam_io_user_info25("", ctr->info.id25, ps, depth);
6483 break;
6484 default:
6485 DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
6486 ret = False;
6487 break;
6490 return ret;
6493 /*******************************************************************
6494 inits a SAMR_R_QUERY_USERINFO structure.
6495 ********************************************************************/
6497 void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
6498 SAM_USERINFO_CTR * ctr, NTSTATUS status)
6500 DEBUG(5, ("init_samr_r_query_userinfo\n"));
6502 r_u->ptr = 0;
6503 r_u->ctr = NULL;
6505 if (NT_STATUS_IS_OK(status)) {
6506 r_u->ptr = 1;
6507 r_u->ctr = ctr;
6510 r_u->status = status; /* return status */
6513 /*******************************************************************
6514 reads or writes a structure.
6515 ********************************************************************/
6517 BOOL samr_io_r_query_userinfo(const char *desc, SAMR_R_QUERY_USERINFO * r_u,
6518 prs_struct *ps, int depth)
6520 if (r_u == NULL)
6521 return False;
6523 prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
6524 depth++;
6526 if(!prs_align(ps))
6527 return False;
6529 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
6530 return False;
6532 if (r_u->ptr != 0) {
6533 if(!samr_io_userinfo_ctr("ctr", &r_u->ctr, ps, depth))
6534 return False;
6537 if(!prs_align(ps))
6538 return False;
6539 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6540 return False;
6542 return True;
6545 /*******************************************************************
6546 inits a SAMR_Q_SET_USERINFO structure.
6547 ********************************************************************/
6549 void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
6550 POLICY_HND *hnd, unsigned char sess_key[16],
6551 uint16 switch_value, void *info)
6553 DEBUG(5, ("init_samr_q_set_userinfo\n"));
6555 q_u->pol = *hnd;
6556 q_u->switch_value = switch_value;
6557 init_samr_userinfo_ctr(q_u->ctr, sess_key, switch_value, info);
6560 /*******************************************************************
6561 reads or writes a structure.
6562 ********************************************************************/
6564 BOOL samr_io_q_set_userinfo(const char *desc, SAMR_Q_SET_USERINFO * q_u,
6565 prs_struct *ps, int depth)
6567 if (q_u == NULL)
6568 return False;
6570 prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
6571 depth++;
6573 if(!prs_align(ps))
6574 return False;
6576 smb_io_pol_hnd("pol", &(q_u->pol), ps, depth);
6578 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6579 return False;
6580 if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6581 return False;
6583 return True;
6586 /*******************************************************************
6587 inits a SAMR_R_SET_USERINFO structure.
6588 ********************************************************************/
6590 void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, NTSTATUS status)
6592 DEBUG(5, ("init_samr_r_set_userinfo\n"));
6594 r_u->status = status; /* return status */
6597 /*******************************************************************
6598 reads or writes a structure.
6599 ********************************************************************/
6601 BOOL samr_io_r_set_userinfo(const char *desc, SAMR_R_SET_USERINFO * r_u,
6602 prs_struct *ps, int depth)
6604 if (r_u == NULL)
6605 return False;
6607 prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
6608 depth++;
6610 if(!prs_align(ps))
6611 return False;
6613 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6614 return False;
6616 return True;
6619 /*******************************************************************
6620 inits a SAMR_Q_SET_USERINFO2 structure.
6621 ********************************************************************/
6623 void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
6624 POLICY_HND *hnd, unsigned char sess_key[16],
6625 uint16 switch_value, SAM_USERINFO_CTR * ctr)
6627 DEBUG(5, ("init_samr_q_set_userinfo2\n"));
6629 q_u->pol = *hnd;
6630 q_u->switch_value = switch_value;
6631 q_u->ctr = ctr;
6633 if (q_u->ctr != NULL)
6634 q_u->ctr->switch_value = switch_value;
6636 switch (switch_value) {
6637 case 0x12:
6638 SamOEMhash(ctr->info.id12->lm_pwd, sess_key, 16);
6639 SamOEMhash(ctr->info.id12->nt_pwd, sess_key, 16);
6640 dump_data(100, (char *)sess_key, 16);
6641 dump_data(100, (char *)ctr->info.id12->lm_pwd, 16);
6642 dump_data(100, (char *)ctr->info.id12->nt_pwd, 16);
6643 break;
6647 /*******************************************************************
6648 reads or writes a structure.
6649 ********************************************************************/
6651 BOOL samr_io_q_set_userinfo2(const char *desc, SAMR_Q_SET_USERINFO2 * q_u,
6652 prs_struct *ps, int depth)
6654 if (q_u == NULL)
6655 return False;
6657 prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
6658 depth++;
6660 if(!prs_align(ps))
6661 return False;
6663 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
6664 return False;
6666 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6667 return False;
6668 if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6669 return False;
6671 return True;
6674 /*******************************************************************
6675 inits a SAMR_R_SET_USERINFO2 structure.
6676 ********************************************************************/
6678 void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, NTSTATUS status)
6680 DEBUG(5, ("init_samr_r_set_userinfo2\n"));
6682 r_u->status = status; /* return status */
6685 /*******************************************************************
6686 reads or writes a structure.
6687 ********************************************************************/
6689 BOOL samr_io_r_set_userinfo2(const char *desc, SAMR_R_SET_USERINFO2 * r_u,
6690 prs_struct *ps, int depth)
6692 if (r_u == NULL)
6693 return False;
6695 prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
6696 depth++;
6698 if(!prs_align(ps))
6699 return False;
6701 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6702 return False;
6704 return True;
6707 /*******************************************************************
6708 inits a SAMR_Q_CONNECT structure.
6709 ********************************************************************/
6711 void init_samr_q_connect(SAMR_Q_CONNECT * q_u,
6712 char *srv_name, uint32 access_mask)
6714 int len_srv_name = strlen(srv_name);
6716 DEBUG(5, ("init_samr_q_connect\n"));
6718 /* make PDC server name \\server */
6719 q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0;
6720 init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);
6722 /* example values: 0x0000 0002 */
6723 q_u->access_mask = access_mask;
6726 /*******************************************************************
6727 reads or writes a structure.
6728 ********************************************************************/
6730 BOOL samr_io_q_connect(const char *desc, SAMR_Q_CONNECT * q_u,
6731 prs_struct *ps, int depth)
6733 if (q_u == NULL)
6734 return False;
6736 prs_debug(ps, depth, desc, "samr_io_q_connect");
6737 depth++;
6739 if(!prs_align(ps))
6740 return False;
6742 if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6743 return False;
6744 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6745 return False;
6747 if(!prs_align(ps))
6748 return False;
6749 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6750 return False;
6752 return True;
6755 /*******************************************************************
6756 reads or writes a structure.
6757 ********************************************************************/
6759 BOOL samr_io_r_connect(const char *desc, SAMR_R_CONNECT * r_u,
6760 prs_struct *ps, int depth)
6762 if (r_u == NULL)
6763 return False;
6765 prs_debug(ps, depth, desc, "samr_io_r_connect");
6766 depth++;
6768 if(!prs_align(ps))
6769 return False;
6771 if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6772 return False;
6774 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6775 return False;
6777 return True;
6780 /*******************************************************************
6781 inits a SAMR_Q_CONNECT4 structure.
6782 ********************************************************************/
6784 void init_samr_q_connect4(SAMR_Q_CONNECT4 * q_u,
6785 char *srv_name, uint32 access_mask)
6787 int len_srv_name = strlen(srv_name);
6789 DEBUG(5, ("init_samr_q_connect\n"));
6791 /* make PDC server name \\server */
6792 q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0;
6793 init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);
6795 /* Only value we've seen, possibly an address type ? */
6796 q_u->unk_0 = 2;
6798 /* example values: 0x0000 0002 */
6799 q_u->access_mask = access_mask;
6802 /*******************************************************************
6803 reads or writes a structure.
6804 ********************************************************************/
6806 BOOL samr_io_q_connect4(const char *desc, SAMR_Q_CONNECT4 * q_u,
6807 prs_struct *ps, int depth)
6809 if (q_u == NULL)
6810 return False;
6812 prs_debug(ps, depth, desc, "samr_io_q_connect4");
6813 depth++;
6815 if(!prs_align(ps))
6816 return False;
6818 if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6819 return False;
6820 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6821 return False;
6823 if(!prs_align(ps))
6824 return False;
6825 if(!prs_uint32("unk_0", ps, depth, &q_u->unk_0))
6826 return False;
6827 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6828 return False;
6830 return True;
6833 /*******************************************************************
6834 reads or writes a structure.
6835 ********************************************************************/
6837 BOOL samr_io_r_connect4(const char *desc, SAMR_R_CONNECT4 * r_u,
6838 prs_struct *ps, int depth)
6840 if (r_u == NULL)
6841 return False;
6843 prs_debug(ps, depth, desc, "samr_io_r_connect4");
6844 depth++;
6846 if(!prs_align(ps))
6847 return False;
6849 if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6850 return False;
6852 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6853 return False;
6855 return True;
6858 /*******************************************************************
6859 inits a SAMR_Q_CONNECT_ANON structure.
6860 ********************************************************************/
6862 void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON * q_u)
6864 DEBUG(5, ("init_samr_q_connect_anon\n"));
6866 q_u->ptr = 1;
6867 q_u->unknown_0 = 0x5c; /* server name (?!!) */
6868 q_u->unknown_1 = 0x01;
6869 q_u->access_mask = 0x20;
6872 /*******************************************************************
6873 reads or writes a structure.
6874 ********************************************************************/
6876 BOOL samr_io_q_connect_anon(const char *desc, SAMR_Q_CONNECT_ANON * q_u,
6877 prs_struct *ps, int depth)
6879 if (q_u == NULL)
6880 return False;
6882 prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
6883 depth++;
6885 if(!prs_align(ps))
6886 return False;
6888 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
6889 return False;
6890 if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0))
6891 return False;
6892 if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
6893 return False;
6894 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6895 return False;
6897 return True;
6900 /*******************************************************************
6901 reads or writes a structure.
6902 ********************************************************************/
6904 BOOL samr_io_r_connect_anon(const char *desc, SAMR_R_CONNECT_ANON * r_u,
6905 prs_struct *ps, int depth)
6907 if (r_u == NULL)
6908 return False;
6910 prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
6911 depth++;
6913 if(!prs_align(ps))
6914 return False;
6916 if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6917 return False;
6919 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6920 return False;
6922 return True;
6925 /*******************************************************************
6926 inits a SAMR_Q_GET_DOM_PWINFO structure.
6927 ********************************************************************/
6929 void init_samr_q_get_dom_pwinfo(SAMR_Q_GET_DOM_PWINFO * q_u,
6930 char *srv_name)
6932 int len_srv_name = strlen(srv_name);
6934 DEBUG(5, ("init_samr_q_get_dom_pwinfo\n"));
6936 q_u->ptr = 1;
6937 init_uni_hdr(&q_u->hdr_srv_name, len_srv_name);
6938 init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name);
6941 /*******************************************************************
6942 reads or writes a structure.
6943 ********************************************************************/
6945 BOOL samr_io_q_get_dom_pwinfo(const char *desc, SAMR_Q_GET_DOM_PWINFO * q_u,
6946 prs_struct *ps, int depth)
6948 if (q_u == NULL)
6949 return False;
6951 prs_debug(ps, depth, desc, "samr_io_q_get_dom_pwinfo");
6952 depth++;
6954 if(!prs_align(ps))
6955 return False;
6957 if(!prs_uint32("ptr", ps, depth, &q_u->ptr))
6958 return False;
6959 if (q_u->ptr != 0) {
6960 if(!smb_io_unihdr("", &q_u->hdr_srv_name, ps, depth))
6961 return False;
6962 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth))
6963 return False;
6966 return True;
6969 /*******************************************************************
6970 reads or writes a structure.
6971 ********************************************************************/
6973 BOOL samr_io_r_get_dom_pwinfo(const char *desc, SAMR_R_GET_DOM_PWINFO * r_u,
6974 prs_struct *ps, int depth)
6976 if (r_u == NULL)
6977 return False;
6979 prs_debug(ps, depth, desc, "samr_io_r_get_dom_pwinfo");
6980 depth++;
6982 if(!prs_align(ps))
6983 return False;
6986 * We need 16 bytes here according to tests. Don't know
6987 * what they are, but the length is important for the singing
6990 if(!prs_uint32("unk_0", ps, depth, &r_u->unk_0))
6991 return False;
6992 if(!prs_uint32("unk_1", ps, depth, &r_u->unk_1))
6993 return False;
6994 if(!prs_uint32("unk_2", ps, depth, &r_u->unk_2))
6995 return False;
6997 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6998 return False;
7000 return True;
7003 /*******************************************************************
7004 make a SAMR_ENC_PASSWD structure.
7005 ********************************************************************/
7007 void init_enc_passwd(SAMR_ENC_PASSWD * pwd, char pass[512])
7009 ZERO_STRUCTP(pwd);
7011 if (pass == NULL) {
7012 pwd->ptr = 0;
7013 } else {
7014 pwd->ptr = 1;
7015 memcpy(pwd->pass, pass, sizeof(pwd->pass));
7019 /*******************************************************************
7020 reads or writes a SAMR_ENC_PASSWD structure.
7021 ********************************************************************/
7023 BOOL samr_io_enc_passwd(const char *desc, SAMR_ENC_PASSWD * pwd,
7024 prs_struct *ps, int depth)
7026 if (pwd == NULL)
7027 return False;
7029 prs_debug(ps, depth, desc, "samr_io_enc_passwd");
7030 depth++;
7032 if(!prs_align(ps))
7033 return False;
7035 if(!prs_uint32("ptr", ps, depth, &pwd->ptr))
7036 return False;
7038 if (pwd->ptr != 0) {
7039 if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)))
7040 return False;
7043 return True;
7046 /*******************************************************************
7047 inits a SAMR_ENC_HASH structure.
7048 ********************************************************************/
7050 void init_enc_hash(SAMR_ENC_HASH * hsh, uchar hash[16])
7052 ZERO_STRUCTP(hsh);
7054 if (hash == NULL) {
7055 hsh->ptr = 0;
7056 } else {
7057 hsh->ptr = 1;
7058 memcpy(hsh->hash, hash, sizeof(hsh->hash));
7062 /*******************************************************************
7063 reads or writes a SAMR_ENC_HASH structure.
7064 ********************************************************************/
7066 BOOL samr_io_enc_hash(const char *desc, SAMR_ENC_HASH * hsh,
7067 prs_struct *ps, int depth)
7069 if (hsh == NULL)
7070 return False;
7072 prs_debug(ps, depth, desc, "samr_io_enc_hash");
7073 depth++;
7075 if(!prs_align(ps))
7076 return False;
7078 if(!prs_uint32("ptr ", ps, depth, &hsh->ptr))
7079 return False;
7080 if (hsh->ptr != 0) {
7081 if(!prs_uint8s(False, "hash", ps, depth, hsh->hash,sizeof(hsh->hash)))
7082 return False;
7085 return True;
7088 /*******************************************************************
7089 inits a SAMR_R_GET_DOM_PWINFO structure.
7090 ********************************************************************/
7092 void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u,
7093 char *dest_host, char *user_name,
7094 char nt_newpass[516],
7095 uchar nt_oldhash[16],
7096 char lm_newpass[516],
7097 uchar lm_oldhash[16])
7099 int len_dest_host = strlen(dest_host);
7100 int len_user_name = strlen(user_name);
7102 DEBUG(5, ("init_samr_q_chgpasswd_user\n"));
7104 q_u->ptr_0 = 1;
7105 init_uni_hdr(&q_u->hdr_dest_host, len_dest_host);
7106 init_unistr2(&q_u->uni_dest_host, dest_host, len_dest_host);
7107 init_uni_hdr(&q_u->hdr_user_name, len_user_name);
7108 init_unistr2(&q_u->uni_user_name, user_name, len_user_name);
7110 init_enc_passwd(&q_u->nt_newpass, nt_newpass);
7111 init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
7113 q_u->unknown = 0x01;
7115 init_enc_passwd(&q_u->lm_newpass, lm_newpass);
7116 init_enc_hash(&q_u->lm_oldhash, lm_oldhash);
7119 /*******************************************************************
7120 reads or writes a structure.
7121 ********************************************************************/
7123 BOOL samr_io_q_chgpasswd_user(const char *desc, SAMR_Q_CHGPASSWD_USER * q_u,
7124 prs_struct *ps, int depth)
7126 if (q_u == NULL)
7127 return False;
7129 prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user");
7130 depth++;
7132 if(!prs_align(ps))
7133 return False;
7135 if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
7136 return False;
7138 if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth))
7139 return False;
7140 if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
7141 return False;
7143 if(!prs_align(ps))
7144 return False;
7145 if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth))
7146 return False;
7147 if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth))
7148 return False;
7150 if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
7151 return False;
7152 if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth))
7153 return False;
7155 if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
7156 return False;
7158 if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
7159 return False;
7160 if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
7161 return False;
7163 return True;
7166 /*******************************************************************
7167 inits a SAMR_R_CHGPASSWD_USER structure.
7168 ********************************************************************/
7170 void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER * r_u, NTSTATUS status)
7172 DEBUG(5, ("init_r_chgpasswd_user\n"));
7174 r_u->status = status;
7177 /*******************************************************************
7178 reads or writes a structure.
7179 ********************************************************************/
7181 BOOL samr_io_r_chgpasswd_user(const char *desc, SAMR_R_CHGPASSWD_USER * r_u,
7182 prs_struct *ps, int depth)
7184 if (r_u == NULL)
7185 return False;
7187 prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user");
7188 depth++;
7190 if(!prs_align(ps))
7191 return False;
7193 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7194 return False;
7196 return True;
7199 /*******************************************************************
7200 reads or writes a structure.
7201 ********************************************************************/
7203 void init_samr_q_unknown_2e(SAMR_Q_UNKNOWN_2E *q_u,
7204 POLICY_HND *domain_pol, uint16 switch_value)
7206 DEBUG(5, ("init_samr_q_unknown_2e\n"));
7208 q_u->domain_pol = *domain_pol;
7209 q_u->switch_value = switch_value;
7212 /*******************************************************************
7213 reads or writes a structure.
7214 ********************************************************************/
7216 BOOL samr_io_q_unknown_2e(const char *desc, SAMR_Q_UNKNOWN_2E *q_u,
7217 prs_struct *ps, int depth)
7219 if (q_u == NULL)
7220 return False;
7222 prs_debug(ps, depth, desc, "samr_io_q_unknown_2e");
7223 depth++;
7225 if(!prs_align(ps))
7226 return False;
7228 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7229 return False;
7231 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7232 return False;
7234 return True;
7237 /*******************************************************************
7238 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7239 ********************************************************************/
7241 void init_samr_r_samr_unknown_2e(SAMR_R_UNKNOWN_2E * r_u,
7242 uint16 switch_value, SAM_UNK_CTR * ctr,
7243 NTSTATUS status)
7245 DEBUG(5, ("init_samr_r_samr_unknown_2e\n"));
7247 r_u->ptr_0 = 0;
7248 r_u->switch_value = 0;
7249 r_u->status = status; /* return status */
7251 if (NT_STATUS_IS_OK(status)) {
7252 r_u->switch_value = switch_value;
7253 r_u->ptr_0 = 1;
7254 r_u->ctr = ctr;
7258 /*******************************************************************
7259 reads or writes a structure.
7260 ********************************************************************/
7262 BOOL samr_io_r_samr_unknown_2e(const char *desc, SAMR_R_UNKNOWN_2E * r_u,
7263 prs_struct *ps, int depth)
7265 if (r_u == NULL)
7266 return False;
7268 prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7269 depth++;
7271 if(!prs_align(ps))
7272 return False;
7274 if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
7275 return False;
7277 if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
7278 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
7279 return False;
7280 if(!prs_align(ps))
7281 return False;
7283 switch (r_u->switch_value) {
7284 case 0x0c:
7285 if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
7286 return False;
7287 break;
7288 case 0x07:
7289 if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
7290 return False;
7291 break;
7292 case 0x06:
7293 if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
7294 return False;
7295 break;
7296 case 0x05:
7297 if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
7298 return False;
7299 break;
7300 case 0x03:
7301 if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
7302 return False;
7303 break;
7304 case 0x02:
7305 if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
7306 return False;
7307 break;
7308 case 0x01:
7309 if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
7310 return False;
7311 break;
7312 default:
7313 DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7314 r_u->switch_value));
7315 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
7316 return False;
7320 if(!prs_align(ps))
7321 return False;
7323 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7324 return False;
7326 return True;
7330 /*******************************************************************
7331 reads or writes a structure.
7332 ********************************************************************/
7334 void init_samr_q_set_domain_info(SAMR_Q_SET_DOMAIN_INFO *q_u,
7335 POLICY_HND *domain_pol, uint16 switch_value, SAM_UNK_CTR *ctr)
7337 DEBUG(5, ("init_samr_q_set_domain_info\n"));
7339 q_u->domain_pol = *domain_pol;
7340 q_u->switch_value0 = switch_value;
7342 q_u->switch_value = switch_value;
7343 q_u->ctr = ctr;
7347 /*******************************************************************
7348 reads or writes a structure.
7349 ********************************************************************/
7351 BOOL samr_io_q_set_domain_info(const char *desc, SAMR_Q_SET_DOMAIN_INFO *q_u,
7352 prs_struct *ps, int depth)
7354 if (q_u == NULL)
7355 return False;
7357 prs_debug(ps, depth, desc, "samr_io_q_set_domain_info");
7358 depth++;
7360 if(!prs_align(ps))
7361 return False;
7363 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7364 return False;
7366 if(!prs_uint16("switch_value0", ps, depth, &q_u->switch_value0))
7367 return False;
7369 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7370 return False;
7372 if(!prs_align(ps))
7373 return False;
7375 if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
7376 return False;
7378 switch (q_u->switch_value) {
7380 case 0x0c:
7381 if(!sam_io_unk_info12("unk_inf12", &q_u->ctr->info.inf12, ps, depth))
7382 return False;
7383 break;
7384 case 0x07:
7385 if(!sam_io_unk_info7("unk_inf7",&q_u->ctr->info.inf7, ps,depth))
7386 return False;
7387 break;
7388 case 0x06:
7389 if(!sam_io_unk_info6("unk_inf6",&q_u->ctr->info.inf6, ps,depth))
7390 return False;
7391 break;
7392 case 0x05:
7393 if(!sam_io_unk_info5("unk_inf5",&q_u->ctr->info.inf5, ps,depth))
7394 return False;
7395 break;
7396 case 0x03:
7397 if(!sam_io_unk_info3("unk_inf3",&q_u->ctr->info.inf3, ps,depth))
7398 return False;
7399 break;
7400 case 0x02:
7401 if(!sam_io_unk_info2("unk_inf2",&q_u->ctr->info.inf2, ps,depth))
7402 return False;
7403 break;
7404 case 0x01:
7405 if(!sam_io_unk_info1("unk_inf1",&q_u->ctr->info.inf1, ps,depth))
7406 return False;
7407 break;
7408 default:
7409 DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7410 q_u->switch_value));
7411 return False;
7414 return True;
7417 /*******************************************************************
7418 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7419 ********************************************************************/
7421 void init_samr_r_set_domain_info(SAMR_R_SET_DOMAIN_INFO * r_u, NTSTATUS status)
7423 DEBUG(5, ("init_samr_r_set_domain_info\n"));
7425 r_u->status = status; /* return status */
7428 /*******************************************************************
7429 reads or writes a structure.
7430 ********************************************************************/
7432 BOOL samr_io_r_set_domain_info(const char *desc, SAMR_R_SET_DOMAIN_INFO * r_u,
7433 prs_struct *ps, int depth)
7435 if (r_u == NULL)
7436 return False;
7438 prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7439 depth++;
7441 if(!prs_align(ps))
7442 return False;
7444 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7445 return False;
7447 return True;