r14092: Fix coverity bug #22. Ensure no possible null
[Samba/nascimento.git] / source3 / rpc_parse / parse_samr.c
blob043bafe28530f2f8cd37228f5977bd716386d3dd
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) Jim McDonough <jmcd@us.ibm.com> 2002.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "includes.h"
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_RPC_PARSE
32 /*******************************************************************
33 inits a SAMR_Q_CLOSE_HND structure.
34 ********************************************************************/
36 void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd)
38 DEBUG(5, ("init_samr_q_close_hnd\n"));
40 q_c->pol = *hnd;
43 /*******************************************************************
44 reads or writes a structure.
45 ********************************************************************/
47 BOOL samr_io_q_close_hnd(const char *desc, SAMR_Q_CLOSE_HND * q_u,
48 prs_struct *ps, int depth)
50 if (q_u == NULL)
51 return False;
53 prs_debug(ps, depth, desc, "samr_io_q_close_hnd");
54 depth++;
56 if(!prs_align(ps))
57 return False;
59 return smb_io_pol_hnd("pol", &q_u->pol, ps, depth);
62 /*******************************************************************
63 reads or writes a structure.
64 ********************************************************************/
66 BOOL samr_io_r_close_hnd(const char *desc, SAMR_R_CLOSE_HND * r_u,
67 prs_struct *ps, int depth)
69 if (r_u == NULL)
70 return False;
72 prs_debug(ps, depth, desc, "samr_io_r_close_hnd");
73 depth++;
75 if(!prs_align(ps))
76 return False;
78 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
79 return False;
81 if(!prs_ntstatus("status", ps, depth, &r_u->status))
82 return False;
84 return True;
87 /*******************************************************************
88 inits a SAMR_Q_LOOKUP_DOMAIN structure.
89 ********************************************************************/
91 void init_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN * q_u,
92 POLICY_HND *pol, char *dom_name)
94 DEBUG(5, ("init_samr_q_lookup_domain\n"));
96 q_u->connect_pol = *pol;
98 init_unistr2(&q_u->uni_domain, dom_name, UNI_FLAGS_NONE);
99 init_uni_hdr(&q_u->hdr_domain, &q_u->uni_domain);
102 /*******************************************************************
103 reads or writes a structure.
104 ********************************************************************/
105 BOOL samr_io_q_lookup_domain(const char *desc, SAMR_Q_LOOKUP_DOMAIN * q_u,
106 prs_struct *ps, int depth)
108 if (q_u == NULL)
109 return False;
111 prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
112 depth++;
114 if(!prs_align(ps))
115 return False;
117 if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth))
118 return False;
120 if(!smb_io_unihdr("hdr_domain", &q_u->hdr_domain, ps, depth))
121 return False;
123 if(!smb_io_unistr2("uni_domain", &q_u->uni_domain, q_u->hdr_domain.buffer, ps, depth))
124 return False;
126 return True;
129 /*******************************************************************
130 inits a SAMR_R_LOOKUP_DOMAIN structure.
131 ********************************************************************/
133 void init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
134 DOM_SID *dom_sid, NTSTATUS status)
136 DEBUG(5, ("init_samr_r_lookup_domain\n"));
138 r_u->status = status;
139 r_u->ptr_sid = 0;
140 if (NT_STATUS_IS_OK(status)) {
141 r_u->ptr_sid = 1;
142 init_dom_sid2(&r_u->dom_sid, dom_sid);
146 /*******************************************************************
147 reads or writes a structure.
148 ********************************************************************/
150 BOOL samr_io_r_lookup_domain(const char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
151 prs_struct *ps, int depth)
153 if (r_u == NULL)
154 return False;
156 prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
157 depth++;
159 if(!prs_align(ps))
160 return False;
162 if(!prs_uint32("ptr", ps, depth, &r_u->ptr_sid))
163 return False;
165 if (r_u->ptr_sid != 0) {
166 if(!smb_io_dom_sid2("sid", &r_u->dom_sid, ps, depth))
167 return False;
168 if(!prs_align(ps))
169 return False;
172 if(!prs_ntstatus("status", ps, depth, &r_u->status))
173 return False;
175 return True;
178 /*******************************************************************
179 reads or writes a structure.
180 ********************************************************************/
182 void init_samr_q_remove_sid_foreign_domain(SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
184 DEBUG(5, ("samr_init_samr_q_remove_sid_foreign_domain\n"));
186 q_u->dom_pol = *dom_pol;
187 init_dom_sid2(&q_u->sid, sid);
190 /*******************************************************************
191 reads or writes a structure.
192 ********************************************************************/
194 BOOL samr_io_q_remove_sid_foreign_domain(const char *desc, SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u,
195 prs_struct *ps, int depth)
197 if (q_u == NULL)
198 return False;
200 prs_debug(ps, depth, desc, "samr_io_q_remove_sid_foreign_domain");
201 depth++;
203 if(!prs_align(ps))
204 return False;
206 if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
207 return False;
209 if(!smb_io_dom_sid2("sid", &q_u->sid, ps, depth))
210 return False;
212 if(!prs_align(ps))
213 return False;
215 return True;
218 /*******************************************************************
219 reads or writes a structure.
220 ********************************************************************/
222 BOOL samr_io_r_remove_sid_foreign_domain(const char *desc, SAMR_R_REMOVE_SID_FOREIGN_DOMAIN * r_u,
223 prs_struct *ps, int depth)
225 if (r_u == NULL)
226 return False;
228 prs_debug(ps, depth, desc, "samr_io_r_remove_sid_foreign_domain");
229 depth++;
231 if(!prs_align(ps))
232 return False;
234 if(!prs_ntstatus("status", ps, depth, &r_u->status))
235 return False;
237 return True;
240 /*******************************************************************
241 reads or writes a structure.
242 ********************************************************************/
244 void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u,
245 POLICY_HND *pol, uint32 flags,
246 const DOM_SID *sid)
248 DEBUG(5, ("samr_init_samr_q_open_domain\n"));
250 q_u->pol = *pol;
251 q_u->flags = flags;
252 init_dom_sid2(&q_u->dom_sid, sid);
255 /*******************************************************************
256 reads or writes a structure.
257 ********************************************************************/
259 BOOL samr_io_q_open_domain(const char *desc, SAMR_Q_OPEN_DOMAIN * q_u,
260 prs_struct *ps, int depth)
262 if (q_u == NULL)
263 return False;
265 prs_debug(ps, depth, desc, "samr_io_q_open_domain");
266 depth++;
268 if(!prs_align(ps))
269 return False;
271 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
272 return False;
274 if(!prs_uint32("flags", ps, depth, &q_u->flags))
275 return False;
277 if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth))
278 return False;
280 return True;
283 /*******************************************************************
284 reads or writes a structure.
285 ********************************************************************/
287 BOOL samr_io_r_open_domain(const char *desc, SAMR_R_OPEN_DOMAIN * r_u,
288 prs_struct *ps, int depth)
290 if (r_u == NULL)
291 return False;
293 prs_debug(ps, depth, desc, "samr_io_r_open_domain");
294 depth++;
296 if(!prs_align(ps))
297 return False;
299 if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth))
300 return False;
302 if(!prs_ntstatus("status", ps, depth, &r_u->status))
303 return False;
305 return True;
308 /*******************************************************************
309 reads or writes a structure.
310 ********************************************************************/
312 void init_samr_q_get_usrdom_pwinfo(SAMR_Q_GET_USRDOM_PWINFO * q_u,
313 POLICY_HND *user_pol)
315 DEBUG(5, ("samr_init_samr_q_get_usrdom_pwinfo\n"));
317 q_u->user_pol = *user_pol;
320 /*******************************************************************
321 reads or writes a structure.
322 ********************************************************************/
324 BOOL samr_io_q_get_usrdom_pwinfo(const char *desc, SAMR_Q_GET_USRDOM_PWINFO * q_u,
325 prs_struct *ps, int depth)
327 if (q_u == NULL)
328 return False;
330 prs_debug(ps, depth, desc, "samr_io_q_get_usrdom_pwinfo");
331 depth++;
333 if(!prs_align(ps))
334 return False;
336 return smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth);
339 /*******************************************************************
340 Init.
341 ********************************************************************/
343 void init_samr_r_get_usrdom_pwinfo(SAMR_R_GET_USRDOM_PWINFO *r_u, NTSTATUS status)
345 DEBUG(5, ("init_samr_r_get_usrdom_pwinfo\n"));
347 r_u->min_pwd_length = 0x0000;
350 * used to be
351 * r_u->unknown_1 = 0x0015;
352 * but for trusts.
354 r_u->unknown_1 = 0x01D1;
355 r_u->unknown_1 = 0x0015;
357 r_u->password_properties = 0x00000000;
359 r_u->status = status;
362 /*******************************************************************
363 reads or writes a structure.
364 ********************************************************************/
366 BOOL samr_io_r_get_usrdom_pwinfo(const char *desc, SAMR_R_GET_USRDOM_PWINFO * r_u,
367 prs_struct *ps, int depth)
369 if (r_u == NULL)
370 return False;
372 prs_debug(ps, depth, desc, "samr_io_r_get_usrdom_pwinfo");
373 depth++;
375 if(!prs_align(ps))
376 return False;
378 if(!prs_uint16("min_pwd_length", ps, depth, &r_u->min_pwd_length))
379 return False;
380 if(!prs_uint16("unknown_1", ps, depth, &r_u->unknown_1))
381 return False;
382 if(!prs_uint32("password_properties", ps, depth, &r_u->password_properties))
383 return False;
385 if(!prs_ntstatus("status ", ps, depth, &r_u->status))
386 return False;
388 return True;
392 /*******************************************************************
393 reads or writes a structure.
394 ********************************************************************/
396 BOOL samr_io_q_set_sec_obj(const char *desc, SAMR_Q_SET_SEC_OBJ * q_u,
397 prs_struct *ps, int depth)
399 if (q_u == NULL)
400 return False;
402 prs_debug(ps, depth, desc, "samr_io_q_set_sec_obj");
403 depth++;
405 if(!prs_align(ps))
406 return False;
408 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
409 return False;
411 if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
412 return False;
414 if(!sec_io_desc_buf("sec_desc", &q_u->buf, ps, depth))
415 return False;
417 return True;
421 /*******************************************************************
422 reads or writes a structure.
423 ********************************************************************/
425 void init_samr_q_query_sec_obj(SAMR_Q_QUERY_SEC_OBJ * q_u,
426 POLICY_HND *user_pol, uint32 sec_info)
428 DEBUG(5, ("samr_init_samr_q_query_sec_obj\n"));
430 q_u->user_pol = *user_pol;
431 q_u->sec_info = sec_info;
435 /*******************************************************************
436 reads or writes a structure.
437 ********************************************************************/
439 BOOL samr_io_q_query_sec_obj(const char *desc, SAMR_Q_QUERY_SEC_OBJ * q_u,
440 prs_struct *ps, int depth)
442 if (q_u == NULL)
443 return False;
445 prs_debug(ps, depth, desc, "samr_io_q_query_sec_obj");
446 depth++;
448 if(!prs_align(ps))
449 return False;
451 if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
452 return False;
454 if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
455 return False;
457 return True;
460 /*******************************************************************
461 reads or writes a structure.
462 ********************************************************************/
464 void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO * q_u,
465 POLICY_HND *domain_pol, uint16 switch_value)
467 DEBUG(5, ("samr_init_samr_q_query_dom_info\n"));
469 q_u->domain_pol = *domain_pol;
470 q_u->switch_value = switch_value;
473 /*******************************************************************
474 reads or writes a structure.
475 ********************************************************************/
477 BOOL samr_io_q_query_dom_info(const char *desc, SAMR_Q_QUERY_DOMAIN_INFO * q_u,
478 prs_struct *ps, int depth)
480 if (q_u == NULL)
481 return False;
483 prs_debug(ps, depth, desc, "samr_io_q_query_dom_info");
484 depth++;
486 if(!prs_align(ps))
487 return False;
489 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
490 return False;
492 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
493 return False;
495 return True;
499 /*******************************************************************
500 inits a structure.
501 ********************************************************************/
503 void init_unk_info3(SAM_UNK_INFO_3 *u_3, NTTIME nt_logout)
505 u_3->logout.low = nt_logout.low;
506 u_3->logout.high = nt_logout.high;
509 /*******************************************************************
510 reads or writes a structure.
511 ********************************************************************/
513 static BOOL sam_io_unk_info3(const char *desc, SAM_UNK_INFO_3 * u_3,
514 prs_struct *ps, int depth)
516 if (u_3 == NULL)
517 return False;
519 prs_debug(ps, depth, desc, "sam_io_unk_info3");
520 depth++;
522 if(!smb_io_time("logout", &u_3->logout, ps, depth))
523 return False;
525 return True;
528 /*******************************************************************
529 inits a structure.
530 ********************************************************************/
532 void init_unk_info6(SAM_UNK_INFO_6 * u_6)
534 u_6->unknown_0 = 0x00000000;
535 u_6->ptr_0 = 1;
536 memset(u_6->padding, 0, sizeof(u_6->padding)); /* 12 bytes zeros */
539 /*******************************************************************
540 reads or writes a structure.
541 ********************************************************************/
543 static BOOL sam_io_unk_info6(const char *desc, SAM_UNK_INFO_6 * u_6,
544 prs_struct *ps, int depth)
546 if (u_6 == NULL)
547 return False;
549 prs_debug(ps, depth, desc, "sam_io_unk_info6");
550 depth++;
552 if(!prs_uint32("unknown_0", ps, depth, &u_6->unknown_0)) /* 0x0000 0000 */
553 return False;
554 if(!prs_uint32("ptr_0", ps, depth, &u_6->ptr_0)) /* pointer to unknown structure */
555 return False;
556 if(!prs_uint8s(False, "padding", ps, depth, u_6->padding, sizeof(u_6->padding))) /* 12 bytes zeros */
557 return False;
559 return True;
562 /*******************************************************************
563 inits a structure.
564 ********************************************************************/
566 void init_unk_info7(SAM_UNK_INFO_7 * u_7, uint32 server_role)
568 u_7->server_role = server_role;
571 /*******************************************************************
572 reads or writes a structure.
573 ********************************************************************/
575 static BOOL sam_io_unk_info7(const char *desc, SAM_UNK_INFO_7 * u_7,
576 prs_struct *ps, int depth)
578 if (u_7 == NULL)
579 return False;
581 prs_debug(ps, depth, desc, "sam_io_unk_info7");
582 depth++;
584 if(!prs_uint16("server_role", ps, depth, &u_7->server_role))
585 return False;
587 return True;
590 /*******************************************************************
591 inits a structure.
592 ********************************************************************/
594 void init_unk_info8(SAM_UNK_INFO_8 * u_8, uint32 seq_num)
596 unix_to_nt_time(&u_8->domain_create_time, 0);
597 u_8->seq_num.low = seq_num;
598 u_8->seq_num.high = 0x0000;
601 /*******************************************************************
602 reads or writes a structure.
603 ********************************************************************/
605 static BOOL sam_io_unk_info8(const char *desc, SAM_UNK_INFO_8 * u_8,
606 prs_struct *ps, int depth)
608 if (u_8 == NULL)
609 return False;
611 prs_debug(ps, depth, desc, "sam_io_unk_info8");
612 depth++;
614 if (!prs_uint64("seq_num", ps, depth, &u_8->seq_num))
615 return False;
617 if(!smb_io_time("domain_create_time", &u_8->domain_create_time, ps, depth))
618 return False;
620 return True;
624 /*******************************************************************
625 inits a structure.
626 ********************************************************************/
628 void init_unk_info12(SAM_UNK_INFO_12 * u_12, NTTIME nt_lock_duration, NTTIME nt_reset_time, uint16 lockout)
630 u_12->duration.low = nt_lock_duration.low;
631 u_12->duration.high = nt_lock_duration.high;
632 u_12->reset_count.low = nt_reset_time.low;
633 u_12->reset_count.high = nt_reset_time.high;
635 u_12->bad_attempt_lockout = lockout;
638 /*******************************************************************
639 reads or writes a structure.
640 ********************************************************************/
642 static BOOL sam_io_unk_info12(const char *desc, SAM_UNK_INFO_12 * u_12,
643 prs_struct *ps, int depth)
645 if (u_12 == NULL)
646 return False;
648 prs_debug(ps, depth, desc, "sam_io_unk_info12");
649 depth++;
651 if(!smb_io_time("duration", &u_12->duration, ps, depth))
652 return False;
653 if(!smb_io_time("reset_count", &u_12->reset_count, ps, depth))
654 return False;
655 if(!prs_uint16("bad_attempt_lockout", ps, depth, &u_12->bad_attempt_lockout))
656 return False;
658 return True;
661 /*******************************************************************
662 inits a structure.
663 ********************************************************************/
665 void init_unk_info5(SAM_UNK_INFO_5 * u_5,const char *server)
667 init_unistr2(&u_5->uni_server, server, UNI_FLAGS_NONE);
668 init_uni_hdr(&u_5->hdr_server, &u_5->uni_server);
671 /*******************************************************************
672 reads or writes a structure.
673 ********************************************************************/
675 static BOOL sam_io_unk_info5(const char *desc, SAM_UNK_INFO_5 * u_5,
676 prs_struct *ps, int depth)
678 if (u_5 == NULL)
679 return False;
681 prs_debug(ps, depth, desc, "sam_io_unk_info5");
682 depth++;
684 if(!smb_io_unihdr("hdr_server", &u_5->hdr_server, ps, depth))
685 return False;
687 if(!smb_io_unistr2("uni_server", &u_5->uni_server, u_5->hdr_server.buffer, ps, depth))
688 return False;
690 return True;
693 /*******************************************************************
694 inits a structure.
695 ********************************************************************/
697 void init_unk_info2(SAM_UNK_INFO_2 * u_2,
698 const char *comment, const char *domain, const char *server,
699 uint32 seq_num, uint32 num_users, uint32 num_groups, uint32 num_alias, NTTIME nt_logout, uint32 server_role)
701 u_2->logout.low = nt_logout.low;
702 u_2->logout.high = nt_logout.high;
704 u_2->seq_num.low = seq_num;
705 u_2->seq_num.high = 0x00000000;
708 u_2->unknown_4 = 0x00000001;
709 u_2->server_role = server_role;
710 u_2->unknown_6 = 0x00000001;
711 u_2->num_domain_usrs = num_users;
712 u_2->num_domain_grps = num_groups;
713 u_2->num_local_grps = num_alias;
715 memset(u_2->padding, 0, sizeof(u_2->padding)); /* 12 bytes zeros */
717 init_unistr2(&u_2->uni_comment, comment, UNI_FLAGS_NONE);
718 init_uni_hdr(&u_2->hdr_comment, &u_2->uni_comment);
719 init_unistr2(&u_2->uni_domain, domain, UNI_FLAGS_NONE);
720 init_uni_hdr(&u_2->hdr_domain, &u_2->uni_domain);
721 init_unistr2(&u_2->uni_server, server, UNI_FLAGS_NONE);
722 init_uni_hdr(&u_2->hdr_server, &u_2->uni_server);
725 /*******************************************************************
726 reads or writes a structure.
727 ********************************************************************/
729 static BOOL sam_io_unk_info2(const char *desc, SAM_UNK_INFO_2 * u_2,
730 prs_struct *ps, int depth)
732 if (u_2 == NULL)
733 return False;
735 prs_debug(ps, depth, desc, "sam_io_unk_info2");
736 depth++;
738 if(!smb_io_time("logout", &u_2->logout, ps, depth))
739 return False;
740 if(!smb_io_unihdr("hdr_comment", &u_2->hdr_comment, ps, depth))
741 return False;
742 if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth))
743 return False;
744 if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth))
745 return False;
747 /* put all the data in here, at the moment, including what the above
748 pointer is referring to
751 if(!prs_uint64("seq_num ", ps, depth, &u_2->seq_num))
752 return False;
754 if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4)) /* 0x0000 0001 */
755 return False;
756 if(!prs_uint32("server_role ", ps, depth, &u_2->server_role))
757 return False;
758 if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6)) /* 0x0000 0001 */
759 return False;
760 if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs))
761 return False;
762 if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps))
763 return False;
764 if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps))
765 return False;
767 if(!smb_io_unistr2("uni_comment", &u_2->uni_comment, u_2->hdr_comment.buffer, ps, depth))
768 return False;
769 if(!smb_io_unistr2("uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth))
770 return False;
771 if(!smb_io_unistr2("uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth))
772 return False;
774 return True;
777 /*******************************************************************
778 inits a structure.
779 ********************************************************************/
781 void init_unk_info1(SAM_UNK_INFO_1 *u_1, uint16 min_pass_len, uint16 pass_hist,
782 uint32 password_properties, NTTIME nt_expire, NTTIME nt_min_age)
784 u_1->min_length_password = min_pass_len;
785 u_1->password_history = pass_hist;
786 u_1->password_properties = password_properties;
788 /* password never expire */
789 u_1->expire.high = nt_expire.high;
790 u_1->expire.low = nt_expire.low;
792 /* can change the password now */
793 u_1->min_passwordage.high = nt_min_age.high;
794 u_1->min_passwordage.low = nt_min_age.low;
798 /*******************************************************************
799 reads or writes a structure.
800 ********************************************************************/
802 static BOOL sam_io_unk_info1(const char *desc, SAM_UNK_INFO_1 * u_1,
803 prs_struct *ps, int depth)
805 if (u_1 == NULL)
806 return False;
808 prs_debug(ps, depth, desc, "sam_io_unk_info1");
809 depth++;
811 if(!prs_uint16("min_length_password", ps, depth, &u_1->min_length_password))
812 return False;
813 if(!prs_uint16("password_history", ps, depth, &u_1->password_history))
814 return False;
815 if(!prs_uint32("password_properties", ps, depth, &u_1->password_properties))
816 return False;
817 if(!smb_io_time("expire", &u_1->expire, ps, depth))
818 return False;
819 if(!smb_io_time("min_passwordage", &u_1->min_passwordage, ps, depth))
820 return False;
822 return True;
825 /*******************************************************************
826 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
827 ********************************************************************/
829 void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO * r_u,
830 uint16 switch_value, SAM_UNK_CTR * ctr,
831 NTSTATUS status)
833 DEBUG(5, ("init_samr_r_query_dom_info\n"));
835 r_u->ptr_0 = 0;
836 r_u->switch_value = 0;
837 r_u->status = status; /* return status */
839 if (NT_STATUS_IS_OK(status)) {
840 r_u->switch_value = switch_value;
841 r_u->ptr_0 = 1;
842 r_u->ctr = ctr;
846 /*******************************************************************
847 reads or writes a structure.
848 ********************************************************************/
850 BOOL samr_io_r_query_dom_info(const char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u,
851 prs_struct *ps, int depth)
853 if (r_u == NULL)
854 return False;
856 prs_debug(ps, depth, desc, "samr_io_r_query_dom_info");
857 depth++;
859 if(!prs_align(ps))
860 return False;
862 if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
863 return False;
865 if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
866 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
867 return False;
868 if(!prs_align(ps))
869 return False;
871 switch (r_u->switch_value) {
872 case 0x0c:
873 if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
874 return False;
875 break;
876 case 0x08:
877 if(!sam_io_unk_info8("unk_inf8",&r_u->ctr->info.inf8, ps,depth))
878 return False;
879 break;
880 case 0x07:
881 if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
882 return False;
883 break;
884 case 0x06:
885 if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
886 return False;
887 break;
888 case 0x05:
889 if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
890 return False;
891 break;
892 case 0x03:
893 if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
894 return False;
895 break;
896 case 0x02:
897 if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
898 return False;
899 break;
900 case 0x01:
901 if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
902 return False;
903 break;
904 default:
905 DEBUG(0, ("samr_io_r_query_dom_info: unknown switch level 0x%x\n",
906 r_u->switch_value));
907 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
908 return False;
912 if(!prs_align(ps))
913 return False;
915 if(!prs_ntstatus("status", ps, depth, &r_u->status))
916 return False;
918 return True;
921 /*******************************************************************
922 reads or writes a structure.
923 ********************************************************************/
925 void init_samr_q_set_sec_obj(SAMR_Q_SET_SEC_OBJ * q_u,
926 POLICY_HND *pol, uint32 sec_info, SEC_DESC_BUF *buf)
928 DEBUG(5, ("samr_init_samr_q_set_sec_obj\n"));
930 q_u->pol = *pol;
931 q_u->sec_info = sec_info;
932 q_u->buf = buf;
936 /*******************************************************************
937 reads or writes a SAMR_R_SET_SEC_OBJ structure.
938 ********************************************************************/
940 BOOL samr_io_r_set_sec_obj(const char *desc, SAMR_R_SET_SEC_OBJ * r_u,
941 prs_struct *ps, int depth)
943 if (r_u == NULL)
944 return False;
946 prs_debug(ps, depth, desc, "samr_io_r_set_sec_obj");
947 depth++;
949 if(!prs_align(ps))
950 return False;
952 if(!prs_ntstatus("status", ps, depth, &r_u->status))
953 return False;
955 return True;
958 /*******************************************************************
959 reads or writes a SAMR_R_QUERY_SEC_OBJ structure.
960 ********************************************************************/
962 BOOL samr_io_r_query_sec_obj(const char *desc, SAMR_R_QUERY_SEC_OBJ * r_u,
963 prs_struct *ps, int depth)
965 if (r_u == NULL)
966 return False;
968 prs_debug(ps, depth, desc, "samr_io_r_query_sec_obj");
969 depth++;
971 if(!prs_align(ps))
972 return False;
974 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
975 return False;
976 if (r_u->ptr != 0) {
977 if(!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
978 return False;
981 if(!prs_ntstatus("status", ps, depth, &r_u->status))
982 return False;
984 return True;
987 /*******************************************************************
988 reads or writes a SAM_STR1 structure.
989 ********************************************************************/
991 static BOOL sam_io_sam_str1(const char *desc, SAM_STR1 * sam, uint32 acct_buf,
992 uint32 name_buf, uint32 desc_buf,
993 prs_struct *ps, int depth)
995 if (sam == NULL)
996 return False;
998 prs_debug(ps, depth, desc, "sam_io_sam_str1");
999 depth++;
1001 if(!prs_align(ps))
1002 return False;
1003 if (!smb_io_unistr2("name", &sam->uni_acct_name, acct_buf, ps, depth))
1004 return False;
1006 if (!smb_io_unistr2("desc", &sam->uni_acct_desc, desc_buf, ps, depth))
1007 return False;
1009 if (!smb_io_unistr2("full", &sam->uni_full_name, name_buf, ps, depth))
1010 return False;
1012 return True;
1015 /*******************************************************************
1016 inits a SAM_ENTRY1 structure.
1017 ********************************************************************/
1019 static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx,
1020 UNISTR2 *sam_name, UNISTR2 *sam_full,
1021 UNISTR2 *sam_desc, uint32 rid_user,
1022 uint32 acb_info)
1024 DEBUG(5, ("init_sam_entry1\n"));
1026 ZERO_STRUCTP(sam);
1028 sam->user_idx = user_idx;
1029 sam->rid_user = rid_user;
1030 sam->acb_info = acb_info;
1032 init_uni_hdr(&sam->hdr_acct_name, sam_name);
1033 init_uni_hdr(&sam->hdr_user_name, sam_full);
1034 init_uni_hdr(&sam->hdr_user_desc, sam_desc);
1037 /*******************************************************************
1038 reads or writes a SAM_ENTRY1 structure.
1039 ********************************************************************/
1041 static BOOL sam_io_sam_entry1(const char *desc, SAM_ENTRY1 * sam,
1042 prs_struct *ps, int depth)
1044 if (sam == NULL)
1045 return False;
1047 prs_debug(ps, depth, desc, "sam_io_sam_entry1");
1048 depth++;
1050 if(!prs_align(ps))
1051 return False;
1053 if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1054 return False;
1056 if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1057 return False;
1058 if(!prs_uint32("acb_info ", ps, depth, &sam->acb_info))
1059 return False;
1061 if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
1062 return False;
1063 if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
1064 return False;
1065 if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
1066 return False;
1068 return True;
1071 /*******************************************************************
1072 reads or writes a SAM_STR2 structure.
1073 ********************************************************************/
1075 static BOOL sam_io_sam_str2(const char *desc, SAM_STR2 * sam, uint32 acct_buf,
1076 uint32 desc_buf, prs_struct *ps, int depth)
1078 if (sam == NULL)
1079 return False;
1081 prs_debug(ps, depth, desc, "sam_io_sam_str2");
1082 depth++;
1084 if(!prs_align(ps))
1085 return False;
1087 if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
1088 return False;
1089 if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth)) /* account desc unicode string */
1090 return False;
1092 return True;
1095 /*******************************************************************
1096 inits a SAM_ENTRY2 structure.
1097 ********************************************************************/
1098 static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
1099 UNISTR2 *sam_name, UNISTR2 *sam_desc,
1100 uint32 rid_user, uint32 acb_info)
1102 DEBUG(5, ("init_sam_entry2\n"));
1104 sam->user_idx = user_idx;
1105 sam->rid_user = rid_user;
1106 sam->acb_info = acb_info;
1108 init_uni_hdr(&sam->hdr_srv_name, sam_name);
1109 init_uni_hdr(&sam->hdr_srv_desc, sam_desc);
1112 /*******************************************************************
1113 reads or writes a SAM_ENTRY2 structure.
1114 ********************************************************************/
1116 static BOOL sam_io_sam_entry2(const char *desc, SAM_ENTRY2 * sam,
1117 prs_struct *ps, int depth)
1119 if (sam == NULL)
1120 return False;
1122 prs_debug(ps, depth, desc, "sam_io_sam_entry2");
1123 depth++;
1125 if(!prs_align(ps))
1126 return False;
1128 if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1129 return False;
1131 if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1132 return False;
1133 if(!prs_uint32("acb_info ", ps, depth, &sam->acb_info))
1134 return False;
1136 if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth)) /* account name unicode string header */
1137 return False;
1138 if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth)) /* account name unicode string header */
1139 return False;
1141 return True;
1144 /*******************************************************************
1145 reads or writes a SAM_STR3 structure.
1146 ********************************************************************/
1148 static BOOL sam_io_sam_str3(const char *desc, SAM_STR3 * sam, uint32 acct_buf,
1149 uint32 desc_buf, prs_struct *ps, int depth)
1151 if (sam == NULL)
1152 return False;
1154 prs_debug(ps, depth, desc, "sam_io_sam_str3");
1155 depth++;
1157 if(!prs_align(ps))
1158 return False;
1160 if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth)) /* account name unicode string */
1161 return False;
1162 if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth)) /* account desc unicode string */
1163 return False;
1165 return True;
1168 /*******************************************************************
1169 inits a SAM_ENTRY3 structure.
1170 ********************************************************************/
1172 static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
1173 UNISTR2 *grp_name, UNISTR2 *grp_desc,
1174 uint32 rid_grp)
1176 DEBUG(5, ("init_sam_entry3\n"));
1178 sam->grp_idx = grp_idx;
1179 sam->rid_grp = rid_grp;
1180 sam->attr = 0x07; /* group rid attributes - gets ignored by nt 4.0 */
1182 init_uni_hdr(&sam->hdr_grp_name, grp_name);
1183 init_uni_hdr(&sam->hdr_grp_desc, grp_desc);
1186 /*******************************************************************
1187 reads or writes a SAM_ENTRY3 structure.
1188 ********************************************************************/
1190 static BOOL sam_io_sam_entry3(const char *desc, SAM_ENTRY3 * sam,
1191 prs_struct *ps, int depth)
1193 if (sam == NULL)
1194 return False;
1196 prs_debug(ps, depth, desc, "sam_io_sam_entry3");
1197 depth++;
1199 if(!prs_align(ps))
1200 return False;
1202 if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1203 return False;
1205 if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp))
1206 return False;
1207 if(!prs_uint32("attr ", ps, depth, &sam->attr))
1208 return False;
1210 if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth)) /* account name unicode string header */
1211 return False;
1212 if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth)) /* account name unicode string header */
1213 return False;
1215 return True;
1218 /*******************************************************************
1219 inits a SAM_ENTRY4 structure.
1220 ********************************************************************/
1222 static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
1223 uint32 len_acct_name)
1225 DEBUG(5, ("init_sam_entry4\n"));
1227 sam->user_idx = user_idx;
1228 init_str_hdr(&sam->hdr_acct_name, len_acct_name+1, len_acct_name, len_acct_name != 0);
1231 /*******************************************************************
1232 reads or writes a SAM_ENTRY4 structure.
1233 ********************************************************************/
1235 static BOOL sam_io_sam_entry4(const char *desc, SAM_ENTRY4 * sam,
1236 prs_struct *ps, int depth)
1238 if (sam == NULL)
1239 return False;
1241 prs_debug(ps, depth, desc, "sam_io_sam_entry4");
1242 depth++;
1244 if(!prs_align(ps))
1245 return False;
1247 if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
1248 return False;
1249 if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
1250 return False;
1252 return True;
1255 /*******************************************************************
1256 inits a SAM_ENTRY5 structure.
1257 ********************************************************************/
1259 static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
1260 uint32 len_grp_name)
1262 DEBUG(5, ("init_sam_entry5\n"));
1264 sam->grp_idx = grp_idx;
1265 init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
1266 len_grp_name != 0);
1269 /*******************************************************************
1270 reads or writes a SAM_ENTRY5 structure.
1271 ********************************************************************/
1273 static BOOL sam_io_sam_entry5(const char *desc, SAM_ENTRY5 * sam,
1274 prs_struct *ps, int depth)
1276 if (sam == NULL)
1277 return False;
1279 prs_debug(ps, depth, desc, "sam_io_sam_entry5");
1280 depth++;
1282 if(!prs_align(ps))
1283 return False;
1285 if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1286 return False;
1287 if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
1288 return False;
1290 return True;
1293 /*******************************************************************
1294 inits a SAM_ENTRY structure.
1295 ********************************************************************/
1297 void init_sam_entry(SAM_ENTRY *sam, UNISTR2 *uni2, uint32 rid)
1299 DEBUG(10, ("init_sam_entry: %d\n", rid));
1301 sam->rid = rid;
1302 init_uni_hdr(&sam->hdr_name, uni2);
1305 /*******************************************************************
1306 reads or writes a SAM_ENTRY structure.
1307 ********************************************************************/
1309 static BOOL sam_io_sam_entry(const char *desc, SAM_ENTRY * sam,
1310 prs_struct *ps, int depth)
1312 if (sam == NULL)
1313 return False;
1315 prs_debug(ps, depth, desc, "sam_io_sam_entry");
1316 depth++;
1318 if(!prs_align(ps))
1319 return False;
1320 if(!prs_uint32("rid", ps, depth, &sam->rid))
1321 return False;
1322 if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
1323 return False;
1325 return True;
1328 /*******************************************************************
1329 inits a SAMR_Q_ENUM_DOM_USERS structure.
1330 ********************************************************************/
1332 void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
1333 uint32 start_idx,
1334 uint32 acb_mask, uint32 size)
1336 DEBUG(5, ("init_samr_q_enum_dom_users\n"));
1338 q_e->pol = *pol;
1340 q_e->start_idx = start_idx; /* zero indicates lots */
1341 q_e->acb_mask = acb_mask;
1342 q_e->max_size = size;
1345 /*******************************************************************
1346 reads or writes a structure.
1347 ********************************************************************/
1349 BOOL samr_io_q_enum_dom_users(const char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
1350 prs_struct *ps, int depth)
1352 if (q_e == NULL)
1353 return False;
1355 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
1356 depth++;
1358 if(!prs_align(ps))
1359 return False;
1361 if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
1362 return False;
1364 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1365 return False;
1366 if(!prs_uint32("acb_mask ", ps, depth, &q_e->acb_mask))
1367 return False;
1369 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1370 return False;
1372 return True;
1376 /*******************************************************************
1377 inits a SAMR_R_ENUM_DOM_USERS structure.
1378 ********************************************************************/
1380 void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
1381 uint32 next_idx, uint32 num_sam_entries)
1383 DEBUG(5, ("init_samr_r_enum_dom_users\n"));
1385 r_u->next_idx = next_idx;
1387 if (num_sam_entries != 0) {
1388 r_u->ptr_entries1 = 1;
1389 r_u->ptr_entries2 = 1;
1390 r_u->num_entries2 = num_sam_entries;
1391 r_u->num_entries3 = num_sam_entries;
1393 r_u->num_entries4 = num_sam_entries;
1394 } else {
1395 r_u->ptr_entries1 = 0;
1396 r_u->num_entries2 = num_sam_entries;
1397 r_u->ptr_entries2 = 1;
1401 /*******************************************************************
1402 reads or writes a structure.
1403 ********************************************************************/
1405 BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
1406 prs_struct *ps, int depth)
1408 uint32 i;
1410 if (r_u == NULL)
1411 return False;
1413 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
1414 depth++;
1416 if(!prs_align(ps))
1417 return False;
1419 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
1420 return False;
1421 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1422 return False;
1424 if (r_u->ptr_entries1 != 0) {
1425 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1426 return False;
1427 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1428 return False;
1429 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1430 return False;
1432 if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1433 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
1434 r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
1437 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
1438 DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
1439 r_u->num_entries4 = 0;
1440 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
1441 return False;
1444 for (i = 0; i < r_u->num_entries2; i++) {
1445 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
1446 return False;
1449 for (i = 0; i < r_u->num_entries2; i++) {
1450 if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
1451 return False;
1456 if(!prs_align(ps))
1457 return False;
1459 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
1460 return False;
1461 if(!prs_ntstatus("status", ps, depth, &r_u->status))
1462 return False;
1464 return True;
1467 /*******************************************************************
1468 inits a SAMR_Q_QUERY_DISPINFO structure.
1469 ********************************************************************/
1471 void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
1472 uint16 switch_level, uint32 start_idx,
1473 uint32 max_entries, uint32 max_size)
1475 DEBUG(5, ("init_samr_q_query_dispinfo\n"));
1477 q_e->domain_pol = *pol;
1479 q_e->switch_level = switch_level;
1481 q_e->start_idx = start_idx;
1482 q_e->max_entries = max_entries;
1483 q_e->max_size = max_size;
1486 /*******************************************************************
1487 reads or writes a structure.
1488 ********************************************************************/
1490 BOOL samr_io_q_query_dispinfo(const char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
1491 prs_struct *ps, int depth)
1493 if (q_e == NULL)
1494 return False;
1496 prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1497 depth++;
1499 if(!prs_align(ps))
1500 return False;
1502 if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
1503 return False;
1505 if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
1506 return False;
1507 if(!prs_align(ps))
1508 return False;
1510 if(!prs_uint32("start_idx ", ps, depth, &q_e->start_idx))
1511 return False;
1512 if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
1513 return False;
1514 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1515 return False;
1517 return True;
1520 /*******************************************************************
1521 inits a SAM_DISPINFO_1 structure.
1522 ********************************************************************/
1524 NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 **sam,
1525 uint32 num_entries, uint32 start_idx,
1526 struct samr_displayentry *entries)
1528 uint32 i;
1530 DEBUG(10, ("init_sam_dispinfo_1: num_entries: %d\n", num_entries));
1532 if (num_entries==0)
1533 return NT_STATUS_OK;
1535 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_1, num_entries);
1536 if (*sam == NULL)
1537 return NT_STATUS_NO_MEMORY;
1539 (*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
1540 if ((*sam)->sam == NULL)
1541 return NT_STATUS_NO_MEMORY;
1543 (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
1544 if ((*sam)->str == NULL)
1545 return NT_STATUS_NO_MEMORY;
1547 for (i = 0; i < num_entries ; i++) {
1548 init_unistr2(&(*sam)->str[i].uni_acct_name,
1549 entries[i].account_name, UNI_FLAGS_NONE);
1550 init_unistr2(&(*sam)->str[i].uni_full_name,
1551 entries[i].fullname, UNI_FLAGS_NONE);
1552 init_unistr2(&(*sam)->str[i].uni_acct_desc,
1553 entries[i].description, UNI_FLAGS_NONE);
1555 init_sam_entry1(&(*sam)->sam[i], start_idx+i+1,
1556 &(*sam)->str[i].uni_acct_name,
1557 &(*sam)->str[i].uni_full_name,
1558 &(*sam)->str[i].uni_acct_desc,
1559 entries[i].rid, entries[i].acct_flags);
1562 return NT_STATUS_OK;
1565 /*******************************************************************
1566 reads or writes a structure.
1567 ********************************************************************/
1569 static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
1570 uint32 num_entries,
1571 prs_struct *ps, int depth)
1573 uint32 i;
1575 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
1576 depth++;
1578 if(!prs_align(ps))
1579 return False;
1581 if (UNMARSHALLING(ps) && num_entries > 0) {
1583 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
1584 DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1585 return False;
1588 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
1589 DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1590 return False;
1594 for (i = 0; i < num_entries; i++) {
1595 if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
1596 return False;
1599 for (i = 0; i < num_entries; i++) {
1600 if(!sam_io_sam_str1("", &sam->str[i],
1601 sam->sam[i].hdr_acct_name.buffer,
1602 sam->sam[i].hdr_user_name.buffer,
1603 sam->sam[i].hdr_user_desc.buffer, ps, depth))
1604 return False;
1607 return True;
1610 /*******************************************************************
1611 inits a SAM_DISPINFO_2 structure.
1612 ********************************************************************/
1614 NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 **sam,
1615 uint32 num_entries, uint32 start_idx,
1616 struct samr_displayentry *entries)
1618 uint32 i;
1620 DEBUG(10, ("init_sam_dispinfo_2: num_entries: %d\n", num_entries));
1622 if (num_entries==0)
1623 return NT_STATUS_OK;
1625 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_2, num_entries);
1626 if (*sam == NULL)
1627 return NT_STATUS_NO_MEMORY;
1629 (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries);
1630 if ((*sam)->sam == NULL)
1631 return NT_STATUS_NO_MEMORY;
1633 (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries);
1634 if ((*sam)->str == NULL)
1635 return NT_STATUS_NO_MEMORY;
1637 for (i = 0; i < num_entries; i++) {
1638 init_unistr2(&(*sam)->str[i].uni_srv_name,
1639 entries[i].account_name, UNI_FLAGS_NONE);
1640 init_unistr2(&(*sam)->str[i].uni_srv_desc,
1641 entries[i].description, UNI_FLAGS_NONE);
1643 init_sam_entry2(&(*sam)->sam[i], start_idx + i + 1,
1644 &(*sam)->str[i].uni_srv_name,
1645 &(*sam)->str[i].uni_srv_desc,
1646 entries[i].rid, entries[i].acct_flags);
1649 return NT_STATUS_OK;
1652 /*******************************************************************
1653 reads or writes a structure.
1654 ********************************************************************/
1656 static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
1657 uint32 num_entries,
1658 prs_struct *ps, int depth)
1660 uint32 i;
1662 if (sam == NULL)
1663 return False;
1665 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
1666 depth++;
1668 if(!prs_align(ps))
1669 return False;
1671 if (UNMARSHALLING(ps) && num_entries > 0) {
1673 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
1674 DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1675 return False;
1678 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
1679 DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1680 return False;
1684 for (i = 0; i < num_entries; i++) {
1685 if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
1686 return False;
1689 for (i = 0; i < num_entries; i++) {
1690 if(!sam_io_sam_str2("", &sam->str[i],
1691 sam->sam[i].hdr_srv_name.buffer,
1692 sam->sam[i].hdr_srv_desc.buffer, ps, depth))
1693 return False;
1696 return True;
1699 /*******************************************************************
1700 inits a SAM_DISPINFO_3 structure.
1701 ********************************************************************/
1703 NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 **sam,
1704 uint32 num_entries, uint32 start_idx,
1705 struct samr_displayentry *entries)
1707 uint32 i;
1709 DEBUG(5, ("init_sam_dispinfo_3: num_entries: %d\n", num_entries));
1711 if (num_entries==0)
1712 return NT_STATUS_OK;
1714 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_3, num_entries);
1715 if (*sam == NULL)
1716 return NT_STATUS_NO_MEMORY;
1718 if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
1719 return NT_STATUS_NO_MEMORY;
1721 if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
1722 return NT_STATUS_NO_MEMORY;
1724 for (i = 0; i < num_entries; i++) {
1725 DEBUG(11, ("init_sam_dispinfo_3: entry: %d\n",i));
1727 init_unistr2(&(*sam)->str[i].uni_grp_name,
1728 entries[i].account_name, UNI_FLAGS_NONE);
1729 init_unistr2(&(*sam)->str[i].uni_grp_desc,
1730 entries[i].description, UNI_FLAGS_NONE);
1732 init_sam_entry3(&(*sam)->sam[i], start_idx+i+1,
1733 &(*sam)->str[i].uni_grp_name,
1734 &(*sam)->str[i].uni_grp_desc,
1735 entries[i].rid);
1738 return NT_STATUS_OK;
1741 /*******************************************************************
1742 reads or writes a structure.
1743 ********************************************************************/
1745 static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
1746 uint32 num_entries,
1747 prs_struct *ps, int depth)
1749 uint32 i;
1751 if (sam == NULL)
1752 return False;
1754 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
1755 depth++;
1757 if(!prs_align(ps))
1758 return False;
1760 if (UNMARSHALLING(ps) && num_entries > 0) {
1762 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
1763 DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1764 return False;
1767 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
1768 DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1769 return False;
1773 for (i = 0; i < num_entries; i++) {
1774 if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
1775 return False;
1778 for (i = 0; i < num_entries; i++) {
1779 if(!sam_io_sam_str3("", &sam->str[i],
1780 sam->sam[i].hdr_grp_name.buffer,
1781 sam->sam[i].hdr_grp_desc.buffer, ps, depth))
1782 return False;
1785 return True;
1788 /*******************************************************************
1789 inits a SAM_DISPINFO_4 structure.
1790 ********************************************************************/
1792 NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 **sam,
1793 uint32 num_entries, uint32 start_idx,
1794 struct samr_displayentry *entries)
1796 uint32 i;
1798 DEBUG(5, ("init_sam_dispinfo_4: num_entries: %d\n", num_entries));
1800 if (num_entries==0)
1801 return NT_STATUS_OK;
1803 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_4, num_entries);
1804 if (*sam == NULL)
1805 return NT_STATUS_NO_MEMORY;
1807 (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries);
1808 if ((*sam)->sam == NULL)
1809 return NT_STATUS_NO_MEMORY;
1811 (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries);
1812 if ((*sam)->str == NULL)
1813 return NT_STATUS_NO_MEMORY;
1815 for (i = 0; i < num_entries; i++) {
1816 size_t len_sam_name = strlen(entries[i].account_name);
1818 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1820 init_sam_entry4(&(*sam)->sam[i], start_idx + i + 1,
1821 len_sam_name);
1823 init_string2(&(*sam)->str[i].acct_name,
1824 entries[i].account_name, len_sam_name+1,
1825 len_sam_name);
1828 return NT_STATUS_OK;
1831 /*******************************************************************
1832 reads or writes a structure.
1833 ********************************************************************/
1835 static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
1836 uint32 num_entries,
1837 prs_struct *ps, int depth)
1839 uint32 i;
1841 if (sam == NULL)
1842 return False;
1844 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1845 depth++;
1847 if(!prs_align(ps))
1848 return False;
1850 if (UNMARSHALLING(ps) && num_entries > 0) {
1852 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
1853 DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1854 return False;
1857 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
1858 DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1859 return False;
1863 for (i = 0; i < num_entries; i++) {
1864 if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
1865 return False;
1868 for (i = 0; i < num_entries; i++) {
1869 if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
1870 sam->sam[i].hdr_acct_name.buffer, ps, depth))
1871 return False;
1874 return True;
1877 /*******************************************************************
1878 inits a SAM_DISPINFO_5 structure.
1879 ********************************************************************/
1881 NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 **sam,
1882 uint32 num_entries, uint32 start_idx,
1883 struct samr_displayentry *entries)
1885 uint32 len_sam_name;
1886 uint32 i;
1888 DEBUG(5, ("init_sam_dispinfo_5: num_entries: %d\n", num_entries));
1890 if (num_entries==0)
1891 return NT_STATUS_OK;
1893 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_5, num_entries);
1894 if (*sam == NULL)
1895 return NT_STATUS_NO_MEMORY;
1897 if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
1898 return NT_STATUS_NO_MEMORY;
1900 if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
1901 return NT_STATUS_NO_MEMORY;
1903 for (i = 0; i < num_entries; i++) {
1904 DEBUG(11, ("init_sam_dispinfo_5: entry: %d\n",i));
1906 len_sam_name = strlen(entries[i].account_name);
1908 init_sam_entry5(&(*sam)->sam[i], start_idx+i+1, len_sam_name);
1909 init_string2(&(*sam)->str[i].grp_name, entries[i].account_name,
1910 len_sam_name+1, len_sam_name);
1913 return NT_STATUS_OK;
1916 /*******************************************************************
1917 reads or writes a structure.
1918 ********************************************************************/
1920 static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
1921 uint32 num_entries,
1922 prs_struct *ps, int depth)
1924 uint32 i;
1926 if (sam == NULL)
1927 return False;
1929 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
1930 depth++;
1932 if(!prs_align(ps))
1933 return False;
1935 if (UNMARSHALLING(ps) && num_entries > 0) {
1937 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
1938 DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
1939 return False;
1942 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
1943 DEBUG(0, ("out of memory allocating SAM_STR5\n"));
1944 return False;
1948 for (i = 0; i < num_entries; i++) {
1949 if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
1950 return False;
1953 for (i = 0; i < num_entries; i++) {
1954 if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
1955 sam->sam[i].hdr_grp_name.buffer, ps, depth))
1956 return False;
1959 return True;
1962 /*******************************************************************
1963 inits a SAMR_R_QUERY_DISPINFO structure.
1964 ********************************************************************/
1966 void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
1967 uint32 num_entries, uint32 total_size, uint32 data_size,
1968 uint16 switch_level, SAM_DISPINFO_CTR * ctr,
1969 NTSTATUS status)
1971 DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
1973 r_u->total_size = total_size;
1975 r_u->data_size = data_size;
1977 r_u->switch_level = switch_level;
1978 r_u->num_entries = num_entries;
1980 if (num_entries==0)
1981 r_u->ptr_entries = 0;
1982 else
1983 r_u->ptr_entries = 1;
1985 r_u->num_entries2 = num_entries;
1986 r_u->ctr = ctr;
1988 r_u->status = status;
1991 /*******************************************************************
1992 reads or writes a structure.
1993 ********************************************************************/
1995 BOOL samr_io_r_query_dispinfo(const char *desc, SAMR_R_QUERY_DISPINFO * r_u,
1996 prs_struct *ps, int depth)
1998 if (r_u == NULL)
1999 return False;
2001 prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
2002 depth++;
2004 if(!prs_align(ps))
2005 return False;
2007 if(!prs_uint32("total_size ", ps, depth, &r_u->total_size))
2008 return False;
2009 if(!prs_uint32("data_size ", ps, depth, &r_u->data_size))
2010 return False;
2011 if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
2012 return False;
2013 if(!prs_align(ps))
2014 return False;
2016 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2017 return False;
2018 if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
2019 return False;
2021 if (r_u->ptr_entries==0) {
2022 if(!prs_align(ps))
2023 return False;
2024 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2025 return False;
2027 return True;
2030 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
2031 return False;
2033 switch (r_u->switch_level) {
2034 case 0x1:
2035 if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
2036 r_u->num_entries, ps, depth))
2037 return False;
2038 break;
2039 case 0x2:
2040 if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
2041 r_u->num_entries, ps, depth))
2042 return False;
2043 break;
2044 case 0x3:
2045 if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
2046 r_u->num_entries, ps, depth))
2047 return False;
2048 break;
2049 case 0x4:
2050 if(!sam_io_sam_dispinfo_4("user list",
2051 r_u->ctr->sam.info4,
2052 r_u->num_entries, ps, depth))
2053 return False;
2054 break;
2055 case 0x5:
2056 if(!sam_io_sam_dispinfo_5("group list",
2057 r_u->ctr->sam.info5,
2058 r_u->num_entries, ps, depth))
2059 return False;
2060 break;
2061 default:
2062 DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
2063 break;
2066 if(!prs_align(ps))
2067 return False;
2068 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2069 return False;
2071 return True;
2074 /*******************************************************************
2075 inits a SAMR_Q_OPEN_GROUP structure.
2076 ********************************************************************/
2078 void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
2079 POLICY_HND *hnd,
2080 uint32 access_mask, uint32 rid)
2082 DEBUG(5, ("init_samr_q_open_group\n"));
2084 q_c->domain_pol = *hnd;
2085 q_c->access_mask = access_mask;
2086 q_c->rid_group = rid;
2089 /*******************************************************************
2090 reads or writes a structure.
2091 ********************************************************************/
2093 BOOL samr_io_q_open_group(const char *desc, SAMR_Q_OPEN_GROUP * q_u,
2094 prs_struct *ps, int depth)
2096 if (q_u == NULL)
2097 return False;
2099 prs_debug(ps, depth, desc, "samr_io_q_open_group");
2100 depth++;
2102 if(!prs_align(ps))
2103 return False;
2105 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
2106 return False;
2108 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
2109 return False;
2110 if(!prs_uint32("rid_group", ps, depth, &q_u->rid_group))
2111 return False;
2113 return True;
2116 /*******************************************************************
2117 reads or writes a structure.
2118 ********************************************************************/
2120 BOOL samr_io_r_open_group(const char *desc, SAMR_R_OPEN_GROUP * r_u,
2121 prs_struct *ps, int depth)
2123 if (r_u == NULL)
2124 return False;
2126 prs_debug(ps, depth, desc, "samr_io_r_open_group");
2127 depth++;
2129 if(!prs_align(ps))
2130 return False;
2132 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2133 return False;
2135 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2136 return False;
2138 return True;
2141 /*******************************************************************
2142 inits a GROUP_INFO1 structure.
2143 ********************************************************************/
2145 void init_samr_group_info1(GROUP_INFO1 * gr1,
2146 char *acct_name, char *acct_desc,
2147 uint32 num_members)
2149 DEBUG(5, ("init_samr_group_info1\n"));
2151 gr1->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2152 gr1->num_members = num_members;
2154 init_unistr2(&gr1->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2155 init_uni_hdr(&gr1->hdr_acct_name, &gr1->uni_acct_name);
2156 init_unistr2(&gr1->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2157 init_uni_hdr(&gr1->hdr_acct_desc, &gr1->uni_acct_desc);
2160 /*******************************************************************
2161 reads or writes a structure.
2162 ********************************************************************/
2164 BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
2165 prs_struct *ps, int depth)
2167 uint16 dummy = 1;
2169 if (gr1 == NULL)
2170 return False;
2172 prs_debug(ps, depth, desc, "samr_io_group_info1");
2173 depth++;
2175 if(!prs_uint16("level", ps, depth, &dummy))
2176 return False;
2178 if(!prs_align(ps))
2179 return False;
2181 if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
2182 return False;
2184 if(!prs_uint32("group_attr", ps, depth, &gr1->group_attr))
2185 return False;
2186 if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
2187 return False;
2189 if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
2190 return False;
2192 if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
2193 gr1->hdr_acct_name.buffer, ps, depth))
2194 return False;
2196 if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
2197 gr1->hdr_acct_desc.buffer, ps, depth))
2198 return False;
2200 return True;
2203 /*******************************************************************
2204 inits a GROUP_INFO2 structure.
2205 ********************************************************************/
2207 void init_samr_group_info2(GROUP_INFO2 * gr2, const char *acct_name)
2209 DEBUG(5, ("init_samr_group_info2\n"));
2211 gr2->level = 2;
2212 init_unistr2(&gr2->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2213 init_uni_hdr(&gr2->hdr_acct_name, &gr2->uni_acct_name);
2216 /*******************************************************************
2217 reads or writes a structure.
2218 ********************************************************************/
2220 BOOL samr_io_group_info2(const char *desc, GROUP_INFO2 *gr2, prs_struct *ps, int depth)
2222 if (gr2 == NULL)
2223 return False;
2225 prs_debug(ps, depth, desc, "samr_io_group_info2");
2226 depth++;
2228 if(!prs_uint16("hdr_level", ps, depth, &gr2->level))
2229 return False;
2231 if(!smb_io_unihdr("hdr_acct_name", &gr2->hdr_acct_name, ps, depth))
2232 return False;
2233 if(!smb_io_unistr2("uni_acct_name", &gr2->uni_acct_name,
2234 gr2->hdr_acct_name.buffer, ps, depth))
2235 return False;
2237 return True;
2240 /*******************************************************************
2241 inits a GROUP_INFO3 structure.
2242 ********************************************************************/
2244 void init_samr_group_info3(GROUP_INFO3 *gr3)
2246 DEBUG(5, ("init_samr_group_info3\n"));
2248 gr3->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2251 /*******************************************************************
2252 reads or writes a structure.
2253 ********************************************************************/
2255 BOOL samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int depth)
2257 if (gr3 == NULL)
2258 return False;
2260 prs_debug(ps, depth, desc, "samr_io_group_info3");
2261 depth++;
2263 if(!prs_align(ps))
2264 return False;
2266 if(!prs_uint32("group_attr", ps, depth, &gr3->group_attr))
2267 return False;
2269 return True;
2272 /*******************************************************************
2273 inits a GROUP_INFO4 structure.
2274 ********************************************************************/
2276 void init_samr_group_info4(GROUP_INFO4 * gr4, const char *acct_desc)
2278 DEBUG(5, ("init_samr_group_info4\n"));
2280 gr4->level = 4;
2281 init_unistr2(&gr4->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2282 init_uni_hdr(&gr4->hdr_acct_desc, &gr4->uni_acct_desc);
2285 /*******************************************************************
2286 reads or writes a structure.
2287 ********************************************************************/
2289 BOOL samr_io_group_info4(const char *desc, GROUP_INFO4 * gr4,
2290 prs_struct *ps, int depth)
2292 if (gr4 == NULL)
2293 return False;
2295 prs_debug(ps, depth, desc, "samr_io_group_info4");
2296 depth++;
2298 if(!prs_uint16("hdr_level", ps, depth, &gr4->level))
2299 return False;
2300 if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
2301 return False;
2302 if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
2303 gr4->hdr_acct_desc.buffer, ps, depth))
2304 return False;
2306 return True;
2309 /*******************************************************************
2310 reads or writes a structure.
2311 ********************************************************************/
2313 static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
2314 prs_struct *ps, int depth)
2316 if (UNMARSHALLING(ps))
2317 *ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
2319 if (*ctr == NULL)
2320 return False;
2322 prs_debug(ps, depth, desc, "samr_group_info_ctr");
2323 depth++;
2325 if(!prs_uint16("switch_value1", ps, depth, &(*ctr)->switch_value1))
2326 return False;
2328 switch ((*ctr)->switch_value1) {
2329 case 1:
2330 if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
2331 return False;
2332 break;
2333 case 2:
2334 if(!samr_io_group_info2("group_info2", &(*ctr)->group.info2, ps, depth))
2335 return False;
2336 break;
2337 case 3:
2338 if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
2339 return False;
2340 break;
2341 case 4:
2342 if(!samr_io_group_info4("group_info4", &(*ctr)->group.info4, ps, depth))
2343 return False;
2344 break;
2345 default:
2346 DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
2347 break;
2350 return True;
2353 /*******************************************************************
2354 inits a SAMR_Q_CREATE_DOM_GROUP structure.
2355 ********************************************************************/
2357 void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
2358 POLICY_HND *pol, const char *acct_desc,
2359 uint32 access_mask)
2361 DEBUG(5, ("init_samr_q_create_dom_group\n"));
2363 q_e->pol = *pol;
2365 init_unistr2(&q_e->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2366 init_uni_hdr(&q_e->hdr_acct_desc, &q_e->uni_acct_desc);
2368 q_e->access_mask = access_mask;
2371 /*******************************************************************
2372 reads or writes a structure.
2373 ********************************************************************/
2375 BOOL samr_io_q_create_dom_group(const char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
2376 prs_struct *ps, int depth)
2378 if (q_e == NULL)
2379 return False;
2381 prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
2382 depth++;
2384 if(!prs_align(ps))
2385 return False;
2387 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2388 return False;
2390 if(!smb_io_unihdr("hdr_acct_desc", &q_e->hdr_acct_desc, ps, depth))
2391 return False;
2392 if(!smb_io_unistr2("uni_acct_desc", &q_e->uni_acct_desc,
2393 q_e->hdr_acct_desc.buffer, ps, depth))
2394 return False;
2396 if(!prs_align(ps))
2397 return False;
2398 if(!prs_uint32("access", ps, depth, &q_e->access_mask))
2399 return False;
2401 return True;
2404 /*******************************************************************
2405 reads or writes a structure.
2406 ********************************************************************/
2408 BOOL samr_io_r_create_dom_group(const char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
2409 prs_struct *ps, int depth)
2411 if (r_u == NULL)
2412 return False;
2414 prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
2415 depth++;
2417 if(!prs_align(ps))
2418 return False;
2420 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2421 return False;
2423 if(!prs_uint32("rid ", ps, depth, &r_u->rid))
2424 return False;
2425 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2426 return False;
2428 return True;
2431 /*******************************************************************
2432 inits a SAMR_Q_DELETE_DOM_GROUP structure.
2433 ********************************************************************/
2435 void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
2436 POLICY_HND *hnd)
2438 DEBUG(5, ("init_samr_q_delete_dom_group\n"));
2440 q_c->group_pol = *hnd;
2443 /*******************************************************************
2444 reads or writes a structure.
2445 ********************************************************************/
2447 BOOL samr_io_q_delete_dom_group(const char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
2448 prs_struct *ps, int depth)
2450 if (q_u == NULL)
2451 return False;
2453 prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
2454 depth++;
2456 if(!prs_align(ps))
2457 return False;
2459 if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2460 return False;
2462 return True;
2465 /*******************************************************************
2466 reads or writes a structure.
2467 ********************************************************************/
2469 BOOL samr_io_r_delete_dom_group(const char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
2470 prs_struct *ps, int depth)
2472 if (r_u == NULL)
2473 return False;
2475 prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
2476 depth++;
2478 if(!prs_align(ps))
2479 return False;
2481 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2482 return False;
2484 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2485 return False;
2487 return True;
2490 /*******************************************************************
2491 inits a SAMR_Q_DEL_GROUPMEM structure.
2492 ********************************************************************/
2494 void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
2495 POLICY_HND *pol, uint32 rid)
2497 DEBUG(5, ("init_samr_q_del_groupmem\n"));
2499 q_e->pol = *pol;
2500 q_e->rid = rid;
2503 /*******************************************************************
2504 reads or writes a structure.
2505 ********************************************************************/
2507 BOOL samr_io_q_del_groupmem(const char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
2508 prs_struct *ps, int depth)
2510 if (q_e == NULL)
2511 return False;
2513 prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
2514 depth++;
2516 if(!prs_align(ps))
2517 return False;
2519 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2520 return False;
2522 if(!prs_uint32("rid", ps, depth, &q_e->rid))
2523 return False;
2525 return True;
2528 /*******************************************************************
2529 inits a SAMR_R_DEL_GROUPMEM structure.
2530 ********************************************************************/
2532 void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
2533 NTSTATUS status)
2535 DEBUG(5, ("init_samr_r_del_groupmem\n"));
2537 r_u->status = status;
2540 /*******************************************************************
2541 reads or writes a structure.
2542 ********************************************************************/
2544 BOOL samr_io_r_del_groupmem(const char *desc, SAMR_R_DEL_GROUPMEM * r_u,
2545 prs_struct *ps, int depth)
2547 if (r_u == NULL)
2548 return False;
2550 prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
2551 depth++;
2553 if(!prs_align(ps))
2554 return False;
2556 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2557 return False;
2559 return True;
2562 /*******************************************************************
2563 inits a SAMR_Q_ADD_GROUPMEM structure.
2564 ********************************************************************/
2566 void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
2567 POLICY_HND *pol, uint32 rid)
2569 DEBUG(5, ("init_samr_q_add_groupmem\n"));
2571 q_e->pol = *pol;
2572 q_e->rid = rid;
2573 q_e->unknown = 0x0005;
2576 /*******************************************************************
2577 reads or writes a structure.
2578 ********************************************************************/
2580 BOOL samr_io_q_add_groupmem(const char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
2581 prs_struct *ps, int depth)
2583 if (q_e == NULL)
2584 return False;
2586 prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
2587 depth++;
2589 if(!prs_align(ps))
2590 return False;
2592 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2593 return False;
2595 if(!prs_uint32("rid ", ps, depth, &q_e->rid))
2596 return False;
2597 if(!prs_uint32("unknown", ps, depth, &q_e->unknown))
2598 return False;
2600 return True;
2603 /*******************************************************************
2604 inits a SAMR_R_ADD_GROUPMEM structure.
2605 ********************************************************************/
2607 void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
2608 NTSTATUS status)
2610 DEBUG(5, ("init_samr_r_add_groupmem\n"));
2612 r_u->status = status;
2615 /*******************************************************************
2616 reads or writes a structure.
2617 ********************************************************************/
2619 BOOL samr_io_r_add_groupmem(const char *desc, SAMR_R_ADD_GROUPMEM * r_u,
2620 prs_struct *ps, int depth)
2622 if (r_u == NULL)
2623 return False;
2625 prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
2626 depth++;
2628 if(!prs_align(ps))
2629 return False;
2631 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2632 return False;
2634 return True;
2637 /*******************************************************************
2638 inits a SAMR_Q_SET_GROUPINFO structure.
2639 ********************************************************************/
2641 void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
2642 POLICY_HND *pol, GROUP_INFO_CTR * ctr)
2644 DEBUG(5, ("init_samr_q_set_groupinfo\n"));
2646 q_e->pol = *pol;
2647 q_e->ctr = ctr;
2650 /*******************************************************************
2651 reads or writes a structure.
2652 ********************************************************************/
2654 BOOL samr_io_q_set_groupinfo(const char *desc, SAMR_Q_SET_GROUPINFO * q_e,
2655 prs_struct *ps, int depth)
2657 if (q_e == NULL)
2658 return False;
2660 prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
2661 depth++;
2663 if(!prs_align(ps))
2664 return False;
2666 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2667 return False;
2669 if(!samr_group_info_ctr("ctr", &q_e->ctr, ps, depth))
2670 return False;
2672 return True;
2675 /*******************************************************************
2676 inits a SAMR_R_SET_GROUPINFO structure.
2677 ********************************************************************/
2679 void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, NTSTATUS status)
2681 DEBUG(5, ("init_samr_r_set_groupinfo\n"));
2683 r_u->status = status;
2686 /*******************************************************************
2687 reads or writes a structure.
2688 ********************************************************************/
2690 BOOL samr_io_r_set_groupinfo(const char *desc, SAMR_R_SET_GROUPINFO * r_u,
2691 prs_struct *ps, int depth)
2693 if (r_u == NULL)
2694 return False;
2696 prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
2697 depth++;
2699 if(!prs_align(ps))
2700 return False;
2702 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2703 return False;
2705 return True;
2708 /*******************************************************************
2709 inits a SAMR_Q_QUERY_GROUPINFO structure.
2710 ********************************************************************/
2712 void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
2713 POLICY_HND *pol, uint16 switch_level)
2715 DEBUG(5, ("init_samr_q_query_groupinfo\n"));
2717 q_e->pol = *pol;
2719 q_e->switch_level = switch_level;
2722 /*******************************************************************
2723 reads or writes a structure.
2724 ********************************************************************/
2726 BOOL samr_io_q_query_groupinfo(const char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
2727 prs_struct *ps, int depth)
2729 if (q_e == NULL)
2730 return False;
2732 prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
2733 depth++;
2735 if(!prs_align(ps))
2736 return False;
2738 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2739 return False;
2741 if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
2742 return False;
2744 return True;
2747 /*******************************************************************
2748 inits a SAMR_R_QUERY_GROUPINFO structure.
2749 ********************************************************************/
2751 void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
2752 GROUP_INFO_CTR * ctr, NTSTATUS status)
2754 DEBUG(5, ("init_samr_r_query_groupinfo\n"));
2756 r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
2757 r_u->ctr = ctr;
2758 r_u->status = status;
2761 /*******************************************************************
2762 reads or writes a structure.
2763 ********************************************************************/
2765 BOOL samr_io_r_query_groupinfo(const char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
2766 prs_struct *ps, int depth)
2768 if (r_u == NULL)
2769 return False;
2771 prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
2772 depth++;
2774 if(!prs_align(ps))
2775 return False;
2777 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2778 return False;
2780 if (r_u->ptr != 0) {
2781 if(!samr_group_info_ctr("ctr", &r_u->ctr, ps, depth))
2782 return False;
2785 if(!prs_align(ps))
2786 return False;
2787 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2788 return False;
2790 return True;
2793 /*******************************************************************
2794 inits a SAMR_Q_QUERY_GROUPMEM structure.
2795 ********************************************************************/
2797 void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd)
2799 DEBUG(5, ("init_samr_q_query_groupmem\n"));
2801 q_c->group_pol = *hnd;
2804 /*******************************************************************
2805 reads or writes a structure.
2806 ********************************************************************/
2808 BOOL samr_io_q_query_groupmem(const char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
2809 prs_struct *ps, int depth)
2811 if (q_u == NULL)
2812 return False;
2814 prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
2815 depth++;
2817 if(!prs_align(ps))
2818 return False;
2820 if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2821 return False;
2823 return True;
2826 /*******************************************************************
2827 inits a SAMR_R_QUERY_GROUPMEM structure.
2828 ********************************************************************/
2830 void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
2831 uint32 num_entries, uint32 *rid,
2832 uint32 *attr, NTSTATUS status)
2834 DEBUG(5, ("init_samr_r_query_groupmem\n"));
2836 if (NT_STATUS_IS_OK(status)) {
2837 r_u->ptr = 1;
2838 r_u->num_entries = num_entries;
2840 r_u->ptr_attrs = attr != NULL ? 1 : 0;
2841 r_u->ptr_rids = rid != NULL ? 1 : 0;
2843 r_u->num_rids = num_entries;
2844 r_u->rid = rid;
2846 r_u->num_attrs = num_entries;
2847 r_u->attr = attr;
2848 } else {
2849 r_u->ptr = 0;
2850 r_u->num_entries = 0;
2853 r_u->status = status;
2856 /*******************************************************************
2857 reads or writes a structure.
2858 ********************************************************************/
2860 BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
2861 prs_struct *ps, int depth)
2863 uint32 i;
2865 if (r_u == NULL)
2866 return False;
2868 if (UNMARSHALLING(ps))
2869 ZERO_STRUCTP(r_u);
2871 prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
2872 depth++;
2874 if(!prs_align(ps))
2875 return False;
2877 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2878 return False;
2879 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2880 return False;
2882 if (r_u->ptr != 0) {
2883 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
2884 return False;
2885 if(!prs_uint32("ptr_attrs", ps, depth, &r_u->ptr_attrs))
2886 return False;
2888 if (r_u->ptr_rids != 0) {
2889 if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
2890 return False;
2891 if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
2892 r_u->rid = PRS_ALLOC_MEM(ps,uint32,r_u->num_rids);
2893 if (r_u->rid == NULL)
2894 return False;
2897 for (i = 0; i < r_u->num_rids; i++) {
2898 if(!prs_uint32("", ps, depth, &r_u->rid[i]))
2899 return False;
2903 if (r_u->ptr_attrs != 0) {
2904 if(!prs_uint32("num_attrs", ps, depth, &r_u->num_attrs))
2905 return False;
2907 if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
2908 r_u->attr = PRS_ALLOC_MEM(ps,uint32,r_u->num_attrs);
2909 if (r_u->attr == NULL)
2910 return False;
2913 for (i = 0; i < r_u->num_attrs; i++) {
2914 if(!prs_uint32("", ps, depth, &r_u->attr[i]))
2915 return False;
2920 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2921 return False;
2923 return True;
2926 /*******************************************************************
2927 inits a SAMR_Q_QUERY_USERGROUPS structure.
2928 ********************************************************************/
2930 void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
2931 POLICY_HND *hnd)
2933 DEBUG(5, ("init_samr_q_query_usergroups\n"));
2935 q_u->pol = *hnd;
2938 /*******************************************************************
2939 reads or writes a structure.
2940 ********************************************************************/
2942 BOOL samr_io_q_query_usergroups(const char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
2943 prs_struct *ps, int depth)
2945 if (q_u == NULL)
2946 return False;
2948 prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
2949 depth++;
2951 if(!prs_align(ps))
2952 return False;
2954 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2955 return False;
2957 return True;
2960 /*******************************************************************
2961 inits a SAMR_R_QUERY_USERGROUPS structure.
2962 ********************************************************************/
2964 void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
2965 uint32 num_gids, DOM_GID * gid,
2966 NTSTATUS status)
2968 DEBUG(5, ("init_samr_r_query_usergroups\n"));
2970 if (NT_STATUS_IS_OK(status)) {
2971 r_u->ptr_0 = 1;
2972 r_u->num_entries = num_gids;
2973 r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
2974 r_u->num_entries2 = num_gids;
2976 r_u->gid = gid;
2977 } else {
2978 r_u->ptr_0 = 0;
2979 r_u->num_entries = 0;
2980 r_u->ptr_1 = 0;
2981 r_u->gid = NULL;
2984 r_u->status = status;
2987 /*******************************************************************
2988 reads or writes a structure.
2989 ********************************************************************/
2991 BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
2992 prs_struct *ps, int depth)
2994 uint32 i;
2995 if (gid == NULL)
2996 return False;
2998 prs_debug(ps, depth, desc, "samr_io_gids");
2999 depth++;
3001 if(!prs_align(ps))
3002 return False;
3004 if(!prs_uint32("num_gids", ps, depth, num_gids))
3005 return False;
3007 if ((*num_gids) != 0) {
3008 if (UNMARSHALLING(ps)) {
3009 (*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
3012 if ((*gid) == NULL) {
3013 return False;
3016 for (i = 0; i < (*num_gids); i++) {
3017 if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
3018 return False;
3022 return True;
3025 /*******************************************************************
3026 reads or writes a structure.
3027 ********************************************************************/
3029 BOOL samr_io_r_query_usergroups(const char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
3030 prs_struct *ps, int depth)
3032 if (r_u == NULL)
3033 return False;
3035 prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
3036 depth++;
3038 if(!prs_align(ps))
3039 return False;
3041 if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
3042 return False;
3044 if (r_u->ptr_0 != 0) {
3045 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
3046 return False;
3047 if(!prs_uint32("ptr_1 ", ps, depth, &r_u->ptr_1))
3048 return False;
3050 if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
3051 if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
3052 return False;
3056 if(!prs_align(ps))
3057 return False;
3058 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3059 return False;
3061 return True;
3064 /*******************************************************************
3065 inits a SAMR_Q_ENUM_DOMAINS structure.
3066 ********************************************************************/
3068 void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
3069 POLICY_HND *pol,
3070 uint32 start_idx, uint32 size)
3072 DEBUG(5, ("init_samr_q_enum_domains\n"));
3074 q_e->pol = *pol;
3076 q_e->start_idx = start_idx;
3077 q_e->max_size = size;
3080 /*******************************************************************
3081 reads or writes a structure.
3082 ********************************************************************/
3084 BOOL samr_io_q_enum_domains(const char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
3085 prs_struct *ps, int depth)
3087 if (q_e == NULL)
3088 return False;
3090 prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
3091 depth++;
3093 if(!prs_align(ps))
3094 return False;
3096 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3097 return False;
3099 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3100 return False;
3101 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3102 return False;
3104 return True;
3107 /*******************************************************************
3108 inits a SAMR_R_ENUM_DOMAINS structure.
3109 ********************************************************************/
3111 void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
3112 uint32 next_idx, uint32 num_sam_entries)
3114 DEBUG(5, ("init_samr_r_enum_domains\n"));
3116 r_u->next_idx = next_idx;
3118 if (num_sam_entries != 0) {
3119 r_u->ptr_entries1 = 1;
3120 r_u->ptr_entries2 = 1;
3121 r_u->num_entries2 = num_sam_entries;
3122 r_u->num_entries3 = num_sam_entries;
3124 r_u->num_entries4 = num_sam_entries;
3125 } else {
3126 r_u->ptr_entries1 = 0;
3127 r_u->num_entries2 = num_sam_entries;
3128 r_u->ptr_entries2 = 1;
3132 /*******************************************************************
3133 reads or writes a structure.
3134 ********************************************************************/
3136 BOOL samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
3137 prs_struct *ps, int depth)
3139 uint32 i;
3141 if (r_u == NULL)
3142 return False;
3144 prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
3145 depth++;
3147 if(!prs_align(ps))
3148 return False;
3150 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
3151 return False;
3152 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3153 return False;
3155 if (r_u->ptr_entries1 != 0) {
3156 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3157 return False;
3158 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3159 return False;
3160 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3161 return False;
3163 if (UNMARSHALLING(ps)) {
3164 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3165 r_u->uni_dom_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3168 if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
3169 DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
3170 r_u->num_entries4 = 0;
3171 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3172 return False;
3175 for (i = 0; i < r_u->num_entries2; i++) {
3176 fstring tmp;
3177 slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3178 if(!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
3179 return False;
3182 for (i = 0; i < r_u->num_entries2; i++) {
3183 fstring tmp;
3184 slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3185 if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i],
3186 r_u->sam[i].hdr_name.buffer, ps,
3187 depth))
3188 return False;
3193 if(!prs_align(ps))
3194 return False;
3195 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3196 return False;
3197 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3198 return False;
3200 return True;
3203 /*******************************************************************
3204 inits a SAMR_Q_ENUM_DOM_GROUPS structure.
3205 ********************************************************************/
3207 void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
3208 POLICY_HND *pol,
3209 uint32 start_idx, uint32 size)
3211 DEBUG(5, ("init_samr_q_enum_dom_groups\n"));
3213 q_e->pol = *pol;
3215 q_e->start_idx = start_idx;
3216 q_e->max_size = size;
3219 /*******************************************************************
3220 reads or writes a structure.
3221 ********************************************************************/
3223 BOOL samr_io_q_enum_dom_groups(const char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
3224 prs_struct *ps, int depth)
3226 if (q_e == NULL)
3227 return False;
3229 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
3230 depth++;
3232 if(!prs_align(ps))
3233 return False;
3235 if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
3236 return False;
3238 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3239 return False;
3240 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3241 return False;
3243 return True;
3246 /*******************************************************************
3247 inits a SAMR_R_ENUM_DOM_GROUPS structure.
3248 ********************************************************************/
3250 void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
3251 uint32 next_idx, uint32 num_sam_entries)
3253 DEBUG(5, ("init_samr_r_enum_dom_groups\n"));
3255 r_u->next_idx = next_idx;
3257 if (num_sam_entries != 0) {
3258 r_u->ptr_entries1 = 1;
3259 r_u->ptr_entries2 = 1;
3260 r_u->num_entries2 = num_sam_entries;
3261 r_u->num_entries3 = num_sam_entries;
3263 r_u->num_entries4 = num_sam_entries;
3264 } else {
3265 r_u->ptr_entries1 = 0;
3266 r_u->num_entries2 = num_sam_entries;
3267 r_u->ptr_entries2 = 1;
3271 /*******************************************************************
3272 reads or writes a structure.
3273 ********************************************************************/
3275 BOOL samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
3276 prs_struct *ps, int depth)
3278 uint32 i;
3280 if (r_u == NULL)
3281 return False;
3283 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
3284 depth++;
3286 if(!prs_align(ps))
3287 return False;
3289 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
3290 return False;
3291 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3292 return False;
3294 if (r_u->ptr_entries1 != 0) {
3295 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3296 return False;
3297 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3298 return False;
3299 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3300 return False;
3302 if (UNMARSHALLING(ps)) {
3303 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3304 r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3307 if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
3308 DEBUG(0,
3309 ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n"));
3310 r_u->num_entries4 = 0;
3311 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3312 return False;
3315 for (i = 0; i < r_u->num_entries2; i++) {
3316 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3317 return False;
3320 for (i = 0; i < r_u->num_entries2; i++) {
3321 if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3322 r_u->sam[i].hdr_name.buffer, ps, depth))
3323 return False;
3327 if(!prs_align(ps))
3328 return False;
3329 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3330 return False;
3331 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3332 return False;
3334 return True;
3337 /*******************************************************************
3338 inits a SAMR_Q_ENUM_DOM_ALIASES structure.
3339 ********************************************************************/
3341 void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
3342 POLICY_HND *pol, uint32 start_idx,
3343 uint32 size)
3345 DEBUG(5, ("init_samr_q_enum_dom_aliases\n"));
3347 q_e->pol = *pol;
3349 q_e->start_idx = start_idx;
3350 q_e->max_size = size;
3354 /*******************************************************************
3355 reads or writes a structure.
3356 ********************************************************************/
3358 BOOL samr_io_q_enum_dom_aliases(const char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
3359 prs_struct *ps, int depth)
3361 if (q_e == NULL)
3362 return False;
3364 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
3365 depth++;
3367 if(!prs_align(ps))
3368 return False;
3370 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3371 return False;
3373 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3374 return False;
3375 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3376 return False;
3378 return True;
3381 /*******************************************************************
3382 inits a SAMR_R_ENUM_DOM_ALIASES structure.
3383 ********************************************************************/
3385 void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries)
3387 DEBUG(5, ("init_samr_r_enum_dom_aliases\n"));
3389 r_u->next_idx = next_idx;
3391 if (num_sam_entries != 0) {
3392 r_u->ptr_entries1 = 1;
3393 r_u->ptr_entries2 = 1;
3394 r_u->num_entries2 = num_sam_entries;
3395 r_u->num_entries3 = num_sam_entries;
3397 r_u->num_entries4 = num_sam_entries;
3398 } else {
3399 r_u->ptr_entries1 = 0;
3400 r_u->num_entries2 = num_sam_entries;
3401 r_u->ptr_entries2 = 1;
3405 /*******************************************************************
3406 reads or writes a structure.
3407 ********************************************************************/
3409 BOOL samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
3410 prs_struct *ps, int depth)
3412 uint32 i;
3414 if (r_u == NULL)
3415 return False;
3417 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
3418 depth++;
3420 if(!prs_align(ps))
3421 return False;
3423 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
3424 return False;
3425 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3426 return False;
3428 if (r_u->ptr_entries1 != 0) {
3429 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3430 return False;
3431 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3432 return False;
3433 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3434 return False;
3436 if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
3437 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3438 r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3441 if (r_u->num_entries2 != 0 &&
3442 (r_u->sam == NULL || r_u->uni_grp_name == NULL)) {
3443 DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n"));
3444 r_u->num_entries4 = 0;
3445 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3446 return False;
3449 for (i = 0; i < r_u->num_entries2; i++) {
3450 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3451 return False;
3454 for (i = 0; i < r_u->num_entries2; i++) {
3455 if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3456 r_u->sam[i].hdr_name.buffer, ps,
3457 depth))
3458 return False;
3462 if(!prs_align(ps))
3463 return False;
3464 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3465 return False;
3466 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3467 return False;
3469 return True;
3472 /*******************************************************************
3473 inits a ALIAS_INFO1 structure.
3474 ********************************************************************/
3476 void init_samr_alias_info1(ALIAS_INFO1 * al1, char *acct_name, uint32 num_member, char *acct_desc)
3478 DEBUG(5, ("init_samr_alias_info1\n"));
3480 init_unistr4(&al1->name, acct_name, UNI_FLAGS_NONE);
3481 al1->num_member = num_member;
3482 init_unistr4(&al1->description, acct_desc, UNI_FLAGS_NONE);
3485 /*******************************************************************
3486 reads or writes a structure.
3487 ********************************************************************/
3489 BOOL samr_io_alias_info1(const char *desc, ALIAS_INFO1 * al1,
3490 prs_struct *ps, int depth)
3492 if (al1 == NULL)
3493 return False;
3495 prs_debug(ps, depth, desc, "samr_io_alias_info1");
3496 depth++;
3498 if(!prs_align(ps))
3499 return False;
3501 if ( !prs_unistr4_hdr("name", ps, depth, &al1->name) )
3502 return False;
3503 if ( !prs_uint32("num_member", ps, depth, &al1->num_member) )
3504 return False;
3505 if ( !prs_unistr4_hdr("description", ps, depth, &al1->description) )
3506 return False;
3508 if ( !prs_unistr4_str("name", ps, depth, &al1->name) )
3509 return False;
3510 if ( !prs_align(ps) )
3511 return False;
3512 if ( !prs_unistr4_str("description", ps, depth, &al1->description) )
3513 return False;
3514 if ( !prs_align(ps) )
3515 return False;
3517 return True;
3520 /*******************************************************************
3521 inits a ALIAS_INFO3 structure.
3522 ********************************************************************/
3524 void init_samr_alias_info3(ALIAS_INFO3 * al3, const char *acct_desc)
3526 DEBUG(5, ("init_samr_alias_info3\n"));
3528 init_unistr4(&al3->description, acct_desc, UNI_FLAGS_NONE);
3531 /*******************************************************************
3532 reads or writes a structure.
3533 ********************************************************************/
3535 BOOL samr_io_alias_info3(const char *desc, ALIAS_INFO3 *al3,
3536 prs_struct *ps, int depth)
3538 if (al3 == NULL)
3539 return False;
3541 prs_debug(ps, depth, desc, "samr_io_alias_info3");
3542 depth++;
3544 if(!prs_align(ps))
3545 return False;
3547 if (!prs_unistr4("description", ps, depth, &al3->description))
3548 return False;
3550 return True;
3553 /*******************************************************************
3554 reads or writes a structure.
3555 ********************************************************************/
3557 BOOL samr_alias_info_ctr(const char *desc, prs_struct *ps, int depth, ALIAS_INFO_CTR * ctr)
3559 if ( !ctr )
3560 return False;
3562 prs_debug(ps, depth, desc, "samr_alias_info_ctr");
3563 depth++;
3565 if ( !prs_uint16("level", ps, depth, &ctr->level) )
3566 return False;
3568 if(!prs_align(ps))
3569 return False;
3570 switch (ctr->level) {
3571 case 1:
3572 if(!samr_io_alias_info1("alias_info1", &ctr->alias.info1, ps, depth))
3573 return False;
3574 break;
3575 case 3:
3576 if(!samr_io_alias_info3("alias_info3", &ctr->alias.info3, ps, depth))
3577 return False;
3578 break;
3579 default:
3580 DEBUG(0,("samr_alias_info_ctr: unsupported switch level\n"));
3581 break;
3584 return True;
3587 /*******************************************************************
3588 inits a SAMR_Q_QUERY_ALIASINFO structure.
3589 ********************************************************************/
3591 void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO * q_e,
3592 POLICY_HND *pol, uint32 switch_level)
3594 DEBUG(5, ("init_samr_q_query_aliasinfo\n"));
3596 q_e->pol = *pol;
3597 q_e->level = switch_level;
3600 /*******************************************************************
3601 reads or writes a structure.
3602 ********************************************************************/
3604 BOOL samr_io_q_query_aliasinfo(const char *desc, SAMR_Q_QUERY_ALIASINFO *in,
3605 prs_struct *ps, int depth)
3607 if ( !in )
3608 return False;
3610 prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
3611 depth++;
3613 if(!prs_align(ps))
3614 return False;
3616 if ( !smb_io_pol_hnd("pol", &(in->pol), ps, depth) )
3617 return False;
3619 if ( !prs_uint16("level", ps, depth, &in->level) )
3620 return False;
3622 return True;
3625 /*******************************************************************
3626 inits a SAMR_R_QUERY_ALIASINFO structure.
3627 ********************************************************************/
3629 void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *out,
3630 ALIAS_INFO_CTR * ctr, NTSTATUS status)
3632 DEBUG(5, ("init_samr_r_query_aliasinfo\n"));
3634 out->ctr = ctr;
3635 out->status = status;
3638 /*******************************************************************
3639 reads or writes a structure.
3640 ********************************************************************/
3642 BOOL samr_io_r_query_aliasinfo(const char *desc, SAMR_R_QUERY_ALIASINFO *out,
3643 prs_struct *ps, int depth)
3645 if ( !out )
3646 return False;
3648 prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
3649 depth++;
3651 if(!prs_align(ps))
3652 return False;
3654 if ( !prs_pointer("alias", ps, depth, (void**)&out->ctr, sizeof(ALIAS_INFO_CTR), (PRS_POINTER_CAST)samr_alias_info_ctr))
3655 return False;
3656 if(!prs_align(ps))
3657 return False;
3659 if(!prs_ntstatus("status", ps, depth, &out->status))
3660 return False;
3662 return True;
3665 /*******************************************************************
3666 inits a SAMR_Q_SET_ALIASINFO structure.
3667 ********************************************************************/
3669 void init_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO * q_u,
3670 POLICY_HND *hnd, ALIAS_INFO_CTR * ctr)
3672 DEBUG(5, ("init_samr_q_set_aliasinfo\n"));
3674 q_u->alias_pol = *hnd;
3675 q_u->ctr = *ctr;
3678 /*******************************************************************
3679 reads or writes a structure.
3680 ********************************************************************/
3682 BOOL samr_io_q_set_aliasinfo(const char *desc, SAMR_Q_SET_ALIASINFO * q_u,
3683 prs_struct *ps, int depth)
3685 if (q_u == NULL)
3686 return False;
3688 prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
3689 depth++;
3691 if(!prs_align(ps))
3692 return False;
3694 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
3695 return False;
3696 if(!samr_alias_info_ctr("ctr", ps, depth, &q_u->ctr))
3697 return False;
3699 return True;
3702 /*******************************************************************
3703 reads or writes a structure.
3704 ********************************************************************/
3706 BOOL samr_io_r_set_aliasinfo(const char *desc, SAMR_R_SET_ALIASINFO * r_u,
3707 prs_struct *ps, int depth)
3709 if (r_u == NULL)
3710 return False;
3712 prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
3713 depth++;
3715 if(!prs_align(ps))
3716 return False;
3717 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3718 return False;
3720 return True;
3723 /*******************************************************************
3724 inits a SAMR_Q_QUERY_USERALIASES structure.
3725 ********************************************************************/
3727 void init_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES * q_u,
3728 POLICY_HND *hnd,
3729 uint32 num_sids,
3730 uint32 *ptr_sid, DOM_SID2 * sid)
3732 DEBUG(5, ("init_samr_q_query_useraliases\n"));
3734 q_u->pol = *hnd;
3736 q_u->num_sids1 = num_sids;
3737 q_u->ptr = 1;
3738 q_u->num_sids2 = num_sids;
3740 q_u->ptr_sid = ptr_sid;
3741 q_u->sid = sid;
3744 /*******************************************************************
3745 reads or writes a SAMR_Q_QUERY_USERALIASES structure.
3746 ********************************************************************/
3748 BOOL samr_io_q_query_useraliases(const char *desc, SAMR_Q_QUERY_USERALIASES * q_u,
3749 prs_struct *ps, int depth)
3751 fstring tmp;
3752 uint32 i;
3754 if (q_u == NULL)
3755 return False;
3757 prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
3758 depth++;
3760 if(!prs_align(ps))
3761 return False;
3763 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
3764 return False;
3766 if(!prs_uint32("num_sids1", ps, depth, &q_u->num_sids1))
3767 return False;
3768 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
3769 return False;
3771 if (q_u->ptr==0)
3772 return True;
3774 if(!prs_uint32("num_sids2", ps, depth, &q_u->num_sids2))
3775 return False;
3777 if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
3778 q_u->ptr_sid = PRS_ALLOC_MEM(ps,uint32,q_u->num_sids2);
3779 if (q_u->ptr_sid == NULL)
3780 return False;
3782 q_u->sid = PRS_ALLOC_MEM(ps, DOM_SID2, q_u->num_sids2);
3783 if (q_u->sid == NULL)
3784 return False;
3787 for (i = 0; i < q_u->num_sids2; i++) {
3788 slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
3789 if(!prs_uint32(tmp, ps, depth, &q_u->ptr_sid[i]))
3790 return False;
3793 for (i = 0; i < q_u->num_sids2; i++) {
3794 if (q_u->ptr_sid[i] != 0) {
3795 slprintf(tmp, sizeof(tmp) - 1, "sid[%02d]", i);
3796 if(!smb_io_dom_sid2(tmp, &q_u->sid[i], ps, depth))
3797 return False;
3801 return True;
3804 /*******************************************************************
3805 inits a SAMR_R_QUERY_USERALIASES structure.
3806 ********************************************************************/
3808 void init_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES * r_u,
3809 uint32 num_rids, uint32 *rid,
3810 NTSTATUS status)
3812 DEBUG(5, ("init_samr_r_query_useraliases\n"));
3814 if (NT_STATUS_IS_OK(status)) {
3815 r_u->num_entries = num_rids;
3816 r_u->ptr = 1;
3817 r_u->num_entries2 = num_rids;
3819 r_u->rid = rid;
3820 } else {
3821 r_u->num_entries = 0;
3822 r_u->ptr = 0;
3823 r_u->num_entries2 = 0;
3826 r_u->status = status;
3829 /*******************************************************************
3830 reads or writes a structure.
3831 ********************************************************************/
3833 BOOL samr_io_rids(const char *desc, uint32 *num_rids, uint32 **rid,
3834 prs_struct *ps, int depth)
3836 fstring tmp;
3837 uint32 i;
3838 if (rid == NULL)
3839 return False;
3841 prs_debug(ps, depth, desc, "samr_io_rids");
3842 depth++;
3844 if(!prs_align(ps))
3845 return False;
3847 if(!prs_uint32("num_rids", ps, depth, num_rids))
3848 return False;
3850 if ((*num_rids) != 0) {
3851 if (UNMARSHALLING(ps)) {
3852 /* reading */
3853 (*rid) = PRS_ALLOC_MEM(ps,uint32, *num_rids);
3855 if ((*rid) == NULL)
3856 return False;
3858 for (i = 0; i < (*num_rids); i++) {
3859 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]", i);
3860 if(!prs_uint32(tmp, ps, depth, &((*rid)[i])))
3861 return False;
3865 return True;
3868 /*******************************************************************
3869 reads or writes a structure.
3870 ********************************************************************/
3872 BOOL samr_io_r_query_useraliases(const char *desc, SAMR_R_QUERY_USERALIASES * r_u,
3873 prs_struct *ps, int depth)
3875 if (r_u == NULL)
3876 return False;
3878 prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
3879 depth++;
3881 if(!prs_align(ps))
3882 return False;
3884 if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries))
3885 return False;
3886 if(!prs_uint32("ptr ", ps, depth, &r_u->ptr))
3887 return False;
3889 if (r_u->ptr != 0) {
3890 if(!samr_io_rids("rids", &r_u->num_entries2, &r_u->rid, ps, depth))
3891 return False;
3894 if(!prs_align(ps))
3895 return False;
3896 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3897 return False;
3899 return True;
3902 /*******************************************************************
3903 inits a SAMR_Q_OPEN_ALIAS structure.
3904 ********************************************************************/
3906 void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS * q_u, POLICY_HND *pol,
3907 uint32 access_mask, uint32 rid)
3909 DEBUG(5, ("init_samr_q_open_alias\n"));
3911 q_u->dom_pol = *pol;
3912 q_u->access_mask = access_mask;
3913 q_u->rid_alias = rid;
3916 /*******************************************************************
3917 reads or writes a structure.
3918 ********************************************************************/
3920 BOOL samr_io_q_open_alias(const char *desc, SAMR_Q_OPEN_ALIAS * q_u,
3921 prs_struct *ps, int depth)
3923 if (q_u == NULL)
3924 return False;
3926 prs_debug(ps, depth, desc, "samr_io_q_open_alias");
3927 depth++;
3929 if(!prs_align(ps))
3930 return False;
3932 if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
3933 return False;
3935 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
3936 return False;
3937 if(!prs_uint32("rid_alias", ps, depth, &q_u->rid_alias))
3938 return False;
3940 return True;
3943 /*******************************************************************
3944 reads or writes a structure.
3945 ********************************************************************/
3947 BOOL samr_io_r_open_alias(const char *desc, SAMR_R_OPEN_ALIAS * r_u,
3948 prs_struct *ps, int depth)
3950 if (r_u == NULL)
3951 return False;
3953 prs_debug(ps, depth, desc, "samr_io_r_open_alias");
3954 depth++;
3956 if(!prs_align(ps))
3957 return False;
3959 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
3960 return False;
3962 if(!prs_ntstatus("status", ps, depth, &r_u->status))
3963 return False;
3965 return True;
3968 /*******************************************************************
3969 inits a SAMR_Q_LOOKUP_RIDS structure.
3970 ********************************************************************/
3972 void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
3973 POLICY_HND *pol, uint32 flags,
3974 uint32 num_rids, uint32 *rid)
3976 DEBUG(5, ("init_samr_q_lookup_rids\n"));
3978 q_u->pol = *pol;
3980 q_u->num_rids1 = num_rids;
3981 q_u->flags = flags;
3982 q_u->ptr = 0;
3983 q_u->num_rids2 = num_rids;
3984 q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
3985 if (q_u->rid == NULL) {
3986 q_u->num_rids1 = 0;
3987 q_u->num_rids2 = 0;
3988 } else {
3989 memcpy(q_u->rid, rid, num_rids * sizeof(q_u->rid[0]));
3993 /*******************************************************************
3994 reads or writes a structure.
3995 ********************************************************************/
3997 BOOL samr_io_q_lookup_rids(const char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
3998 prs_struct *ps, int depth)
4000 uint32 i;
4001 fstring tmp;
4003 if (q_u == NULL)
4004 return False;
4006 prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
4007 depth++;
4009 if (UNMARSHALLING(ps))
4010 ZERO_STRUCTP(q_u);
4012 if(!prs_align(ps))
4013 return False;
4015 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4016 return False;
4018 if(!prs_uint32("num_rids1", ps, depth, &q_u->num_rids1))
4019 return False;
4020 if(!prs_uint32("flags ", ps, depth, &q_u->flags))
4021 return False;
4022 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
4023 return False;
4024 if(!prs_uint32("num_rids2", ps, depth, &q_u->num_rids2))
4025 return False;
4027 if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
4028 q_u->rid = PRS_ALLOC_MEM(ps, uint32, q_u->num_rids2);
4029 if (q_u->rid == NULL)
4030 return False;
4033 for (i = 0; i < q_u->num_rids2; i++) {
4034 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i);
4035 if(!prs_uint32(tmp, ps, depth, &q_u->rid[i]))
4036 return False;
4039 return True;
4042 /*******************************************************************
4043 inits a SAMR_R_LOOKUP_RIDS structure.
4044 ********************************************************************/
4046 void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS * r_u,
4047 uint32 num_names, UNIHDR * hdr_name,
4048 UNISTR2 *uni_name, uint32 *type)
4050 DEBUG(5, ("init_samr_r_lookup_rids\n"));
4052 r_u->hdr_name = NULL;
4053 r_u->uni_name = NULL;
4054 r_u->type = NULL;
4056 if (num_names != 0) {
4057 r_u->num_names1 = num_names;
4058 r_u->ptr_names = 1;
4059 r_u->num_names2 = num_names;
4061 r_u->num_types1 = num_names;
4062 r_u->ptr_types = 1;
4063 r_u->num_types2 = num_names;
4065 r_u->hdr_name = hdr_name;
4066 r_u->uni_name = uni_name;
4067 r_u->type = type;
4068 } else {
4069 r_u->num_names1 = num_names;
4070 r_u->ptr_names = 0;
4071 r_u->num_names2 = num_names;
4073 r_u->num_types1 = num_names;
4074 r_u->ptr_types = 0;
4075 r_u->num_types2 = num_names;
4079 /*******************************************************************
4080 reads or writes a structure.
4081 ********************************************************************/
4083 BOOL samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
4084 prs_struct *ps, int depth)
4086 uint32 i;
4087 fstring tmp;
4088 if (r_u == NULL)
4089 return False;
4091 prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
4092 depth++;
4094 if(!prs_align(ps))
4095 return False;
4097 if(!prs_uint32("num_names1", ps, depth, &r_u->num_names1))
4098 return False;
4099 if(!prs_uint32("ptr_names ", ps, depth, &r_u->ptr_names))
4100 return False;
4102 if (r_u->ptr_names != 0) {
4104 if(!prs_uint32("num_names2", ps, depth, &r_u->num_names2))
4105 return False;
4108 if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
4109 r_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, r_u->num_names2);
4110 if (r_u->hdr_name == NULL)
4111 return False;
4113 r_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, r_u->num_names2);
4114 if (r_u->uni_name == NULL)
4115 return False;
4118 for (i = 0; i < r_u->num_names2; i++) {
4119 slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d] ", i);
4120 if(!smb_io_unihdr("", &r_u->hdr_name[i], ps, depth))
4121 return False;
4123 for (i = 0; i < r_u->num_names2; i++) {
4124 slprintf(tmp, sizeof(tmp) - 1, "str[%02d] ", i);
4125 if(!smb_io_unistr2("", &r_u->uni_name[i], r_u->hdr_name[i].buffer, ps, depth))
4126 return False;
4131 if(!prs_align(ps))
4132 return False;
4133 if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
4134 return False;
4135 if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
4136 return False;
4138 if (r_u->ptr_types != 0) {
4140 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
4141 return False;
4143 if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
4144 r_u->type = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
4145 if (r_u->type == NULL)
4146 return False;
4149 for (i = 0; i < r_u->num_types2; i++) {
4150 slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i);
4151 if(!prs_uint32(tmp, ps, depth, &r_u->type[i]))
4152 return False;
4156 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4157 return False;
4159 return True;
4162 /*******************************************************************
4163 inits a SAMR_Q_OPEN_ALIAS structure.
4164 ********************************************************************/
4166 void init_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS * q_u, POLICY_HND *hnd)
4168 DEBUG(5, ("init_samr_q_delete_alias\n"));
4170 q_u->alias_pol = *hnd;
4173 /*******************************************************************
4174 reads or writes a structure.
4175 ********************************************************************/
4177 BOOL samr_io_q_delete_alias(const char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
4178 prs_struct *ps, int depth)
4180 if (q_u == NULL)
4181 return False;
4183 prs_debug(ps, depth, desc, "samr_io_q_delete_alias");
4184 depth++;
4186 if(!prs_align(ps))
4187 return False;
4189 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4190 return False;
4192 return True;
4195 /*******************************************************************
4196 reads or writes a structure.
4197 ********************************************************************/
4199 BOOL samr_io_r_delete_alias(const char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
4200 prs_struct *ps, int depth)
4202 if (r_u == NULL)
4203 return False;
4205 prs_debug(ps, depth, desc, "samr_io_r_delete_alias");
4206 depth++;
4208 if(!prs_align(ps))
4209 return False;
4211 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4212 return False;
4213 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4214 return False;
4216 return True;
4219 /*******************************************************************
4220 inits a SAMR_Q_CREATE_DOM_ALIAS structure.
4221 ********************************************************************/
4223 void init_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS * q_u,
4224 POLICY_HND *hnd, const char *acct_desc)
4226 DEBUG(5, ("init_samr_q_create_dom_alias\n"));
4228 q_u->dom_pol = *hnd;
4230 init_unistr2(&q_u->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
4231 init_uni_hdr(&q_u->hdr_acct_desc, &q_u->uni_acct_desc);
4233 q_u->access_mask = MAXIMUM_ALLOWED_ACCESS;
4236 /*******************************************************************
4237 reads or writes a structure.
4238 ********************************************************************/
4240 BOOL samr_io_q_create_dom_alias(const char *desc, SAMR_Q_CREATE_DOM_ALIAS * q_u,
4241 prs_struct *ps, int depth)
4243 if (q_u == NULL)
4244 return False;
4246 prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias");
4247 depth++;
4249 if(!prs_align(ps))
4250 return False;
4252 if(!smb_io_pol_hnd("dom_pol", &q_u->dom_pol, ps, depth))
4253 return False;
4255 if(!smb_io_unihdr("hdr_acct_desc", &q_u->hdr_acct_desc, ps, depth))
4256 return False;
4257 if(!smb_io_unistr2("uni_acct_desc", &q_u->uni_acct_desc,
4258 q_u->hdr_acct_desc.buffer, ps, depth))
4259 return False;
4261 if(!prs_align(ps))
4262 return False;
4263 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
4264 return False;
4266 return True;
4269 /*******************************************************************
4270 reads or writes a structure.
4271 ********************************************************************/
4273 BOOL samr_io_r_create_dom_alias(const char *desc, SAMR_R_CREATE_DOM_ALIAS * r_u,
4274 prs_struct *ps, int depth)
4276 if (r_u == NULL)
4277 return False;
4279 prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias");
4280 depth++;
4282 if(!prs_align(ps))
4283 return False;
4285 if(!smb_io_pol_hnd("alias_pol", &r_u->alias_pol, ps, depth))
4286 return False;
4288 if(!prs_uint32("rid", ps, depth, &r_u->rid))
4289 return False;
4291 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4292 return False;
4294 return True;
4297 /*******************************************************************
4298 inits a SAMR_Q_ADD_ALIASMEM structure.
4299 ********************************************************************/
4301 void init_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM * q_u, POLICY_HND *hnd,
4302 DOM_SID *sid)
4304 DEBUG(5, ("init_samr_q_add_aliasmem\n"));
4306 q_u->alias_pol = *hnd;
4307 init_dom_sid2(&q_u->sid, sid);
4310 /*******************************************************************
4311 reads or writes a structure.
4312 ********************************************************************/
4314 BOOL samr_io_q_add_aliasmem(const char *desc, SAMR_Q_ADD_ALIASMEM * q_u,
4315 prs_struct *ps, int depth)
4317 if (q_u == NULL)
4318 return False;
4320 prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem");
4321 depth++;
4323 if(!prs_align(ps))
4324 return False;
4326 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4327 return False;
4328 if(!smb_io_dom_sid2("sid ", &q_u->sid, ps, depth))
4329 return False;
4331 return True;
4334 /*******************************************************************
4335 reads or writes a structure.
4336 ********************************************************************/
4338 BOOL samr_io_r_add_aliasmem(const char *desc, SAMR_R_ADD_ALIASMEM * r_u,
4339 prs_struct *ps, int depth)
4341 if (r_u == NULL)
4342 return False;
4344 prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem");
4345 depth++;
4347 if(!prs_align(ps))
4348 return False;
4350 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4351 return False;
4353 return True;
4356 /*******************************************************************
4357 inits a SAMR_Q_DEL_ALIASMEM structure.
4358 ********************************************************************/
4360 void init_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM * q_u, POLICY_HND *hnd,
4361 DOM_SID *sid)
4363 DEBUG(5, ("init_samr_q_del_aliasmem\n"));
4365 q_u->alias_pol = *hnd;
4366 init_dom_sid2(&q_u->sid, sid);
4369 /*******************************************************************
4370 reads or writes a structure.
4371 ********************************************************************/
4373 BOOL samr_io_q_del_aliasmem(const char *desc, SAMR_Q_DEL_ALIASMEM * q_u,
4374 prs_struct *ps, int depth)
4376 if (q_u == NULL)
4377 return False;
4379 prs_debug(ps, depth, desc, "samr_io_q_del_aliasmem");
4380 depth++;
4382 if(!prs_align(ps))
4383 return False;
4385 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4386 return False;
4387 if(!smb_io_dom_sid2("sid ", &q_u->sid, ps, depth))
4388 return False;
4390 return True;
4393 /*******************************************************************
4394 reads or writes a structure.
4395 ********************************************************************/
4397 BOOL samr_io_r_del_aliasmem(const char *desc, SAMR_R_DEL_ALIASMEM * r_u,
4398 prs_struct *ps, int depth)
4400 if (r_u == NULL)
4401 return False;
4403 prs_debug(ps, depth, desc, "samr_io_r_del_aliasmem");
4404 depth++;
4406 if(!prs_align(ps))
4407 return False;
4409 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4410 return False;
4412 return True;
4415 /*******************************************************************
4416 inits a SAMR_Q_DELETE_DOM_ALIAS structure.
4417 ********************************************************************/
4419 void init_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS * q_c,
4420 POLICY_HND *hnd)
4422 DEBUG(5, ("init_samr_q_delete_dom_alias\n"));
4424 q_c->alias_pol = *hnd;
4427 /*******************************************************************
4428 reads or writes a structure.
4429 ********************************************************************/
4431 BOOL samr_io_q_delete_dom_alias(const char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
4432 prs_struct *ps, int depth)
4434 if (q_u == NULL)
4435 return False;
4437 prs_debug(ps, depth, desc, "samr_io_q_delete_dom_alias");
4438 depth++;
4440 if(!prs_align(ps))
4441 return False;
4443 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4444 return False;
4446 return True;
4449 /*******************************************************************
4450 inits a SAMR_R_DELETE_DOM_ALIAS structure.
4451 ********************************************************************/
4453 void init_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS * r_u,
4454 NTSTATUS status)
4456 DEBUG(5, ("init_samr_r_delete_dom_alias\n"));
4458 r_u->status = status;
4461 /*******************************************************************
4462 reads or writes a structure.
4463 ********************************************************************/
4465 BOOL samr_io_r_delete_dom_alias(const char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
4466 prs_struct *ps, int depth)
4468 if (r_u == NULL)
4469 return False;
4471 prs_debug(ps, depth, desc, "samr_io_r_delete_dom_alias");
4472 depth++;
4474 if(!prs_align(ps))
4475 return False;
4477 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4478 return False;
4480 return True;
4483 /*******************************************************************
4484 inits a SAMR_Q_QUERY_ALIASMEM structure.
4485 ********************************************************************/
4487 void init_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM * q_c,
4488 POLICY_HND *hnd)
4490 DEBUG(5, ("init_samr_q_query_aliasmem\n"));
4492 q_c->alias_pol = *hnd;
4495 /*******************************************************************
4496 reads or writes a structure.
4497 ********************************************************************/
4499 BOOL samr_io_q_query_aliasmem(const char *desc, SAMR_Q_QUERY_ALIASMEM * q_u,
4500 prs_struct *ps, int depth)
4502 if (q_u == NULL)
4503 return False;
4505 prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem");
4506 depth++;
4508 if(!prs_align(ps))
4509 return False;
4511 if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4512 return False;
4514 return True;
4517 /*******************************************************************
4518 inits a SAMR_R_QUERY_ALIASMEM structure.
4519 ********************************************************************/
4521 void init_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM * r_u,
4522 uint32 num_sids, DOM_SID2 * sid,
4523 NTSTATUS status)
4525 DEBUG(5, ("init_samr_r_query_aliasmem\n"));
4527 if (NT_STATUS_IS_OK(status)) {
4528 r_u->num_sids = num_sids;
4529 r_u->ptr = (num_sids != 0) ? 1 : 0;
4530 r_u->num_sids1 = num_sids;
4532 r_u->sid = sid;
4533 } else {
4534 r_u->ptr = 0;
4535 r_u->num_sids = 0;
4538 r_u->status = status;
4541 /*******************************************************************
4542 reads or writes a structure.
4543 ********************************************************************/
4545 BOOL samr_io_r_query_aliasmem(const char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
4546 prs_struct *ps, int depth)
4548 uint32 i;
4550 if (r_u == NULL)
4551 return False;
4553 prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
4554 depth++;
4556 if(!prs_align(ps))
4557 return False;
4559 if(!prs_uint32("num_sids ", ps, depth, &r_u->num_sids))
4560 return False;
4561 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
4562 return False;
4564 if (r_u->ptr != 0 && r_u->num_sids != 0) {
4565 uint32 *ptr_sid = NULL;
4567 if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
4568 return False;
4570 ptr_sid = TALLOC_ARRAY(ps->mem_ctx, uint32, r_u->num_sids1);
4571 if (!ptr_sid) {
4572 return False;
4575 for (i = 0; i < r_u->num_sids1; i++) {
4576 ptr_sid[i] = 1;
4577 if(!prs_uint32("ptr_sid", ps, depth, &ptr_sid[i]))
4578 return False;
4581 if (UNMARSHALLING(ps)) {
4582 r_u->sid = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, r_u->num_sids1);
4585 for (i = 0; i < r_u->num_sids1; i++) {
4586 if (ptr_sid[i] != 0) {
4587 if(!smb_io_dom_sid2("sid", &r_u->sid[i], ps, depth))
4588 return False;
4593 if(!prs_align(ps))
4594 return False;
4595 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4596 return False;
4598 return True;
4601 /*******************************************************************
4602 inits a SAMR_Q_LOOKUP_NAMES structure.
4603 ********************************************************************/
4605 NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
4606 POLICY_HND *pol, uint32 flags,
4607 uint32 num_names, const char **name)
4609 uint32 i;
4611 DEBUG(5, ("init_samr_q_lookup_names\n"));
4613 q_u->pol = *pol;
4615 q_u->num_names1 = num_names;
4616 q_u->flags = flags;
4617 q_u->ptr = 0;
4618 q_u->num_names2 = num_names;
4620 if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
4621 return NT_STATUS_NO_MEMORY;
4623 if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
4624 return NT_STATUS_NO_MEMORY;
4626 for (i = 0; i < num_names; i++) {
4627 init_unistr2(&q_u->uni_name[i], name[i], UNI_FLAGS_NONE); /* unicode string for machine account */
4628 init_uni_hdr(&q_u->hdr_name[i], &q_u->uni_name[i]); /* unicode header for user_name */
4631 return NT_STATUS_OK;
4634 /*******************************************************************
4635 reads or writes a structure.
4636 ********************************************************************/
4638 BOOL samr_io_q_lookup_names(const char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
4639 prs_struct *ps, int depth)
4641 uint32 i;
4643 if (q_u == NULL)
4644 return False;
4646 prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
4647 depth++;
4649 if (UNMARSHALLING(ps))
4650 ZERO_STRUCTP(q_u);
4652 if(!prs_align(ps))
4653 return False;
4655 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4656 return False;
4658 if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1))
4659 return False;
4660 if(!prs_uint32("flags ", ps, depth, &q_u->flags))
4661 return False;
4662 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
4663 return False;
4664 if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2))
4665 return False;
4667 if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
4668 q_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_u->num_names2);
4669 q_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_u->num_names2);
4670 if (!q_u->hdr_name || !q_u->uni_name)
4671 return False;
4674 for (i = 0; i < q_u->num_names2; i++) {
4675 if(!smb_io_unihdr("", &q_u->hdr_name[i], ps, depth))
4676 return False;
4679 for (i = 0; i < q_u->num_names2; i++) {
4680 if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth))
4681 return False;
4684 return True;
4687 /*******************************************************************
4688 inits a SAMR_R_LOOKUP_NAMES structure.
4689 ********************************************************************/
4691 NTSTATUS init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
4692 uint32 num_rids,
4693 uint32 *rid, uint32 *type,
4694 NTSTATUS status)
4696 DEBUG(5, ("init_samr_r_lookup_names\n"));
4698 if (NT_STATUS_IS_OK(status) && (num_rids != 0)) {
4699 uint32 i;
4701 r_u->num_types1 = num_rids;
4702 r_u->ptr_types = 1;
4703 r_u->num_types2 = num_rids;
4705 r_u->num_rids1 = num_rids;
4706 r_u->ptr_rids = 1;
4707 r_u->num_rids2 = num_rids;
4709 if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
4710 return NT_STATUS_NO_MEMORY;
4711 if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
4712 return NT_STATUS_NO_MEMORY;
4714 if (!r_u->rids || !r_u->types)
4715 goto empty;
4717 for (i = 0; i < num_rids; i++) {
4718 r_u->rids[i] = rid[i];
4719 r_u->types[i] = type[i];
4721 } else {
4723 empty:
4724 r_u->num_types1 = 0;
4725 r_u->ptr_types = 0;
4726 r_u->num_types2 = 0;
4728 r_u->num_rids1 = 0;
4729 r_u->ptr_rids = 0;
4730 r_u->num_rids2 = 0;
4732 r_u->rids = NULL;
4733 r_u->types = NULL;
4736 r_u->status = status;
4738 return NT_STATUS_OK;
4741 /*******************************************************************
4742 reads or writes a structure.
4743 ********************************************************************/
4745 BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
4746 prs_struct *ps, int depth)
4748 uint32 i;
4749 fstring tmp;
4751 if (r_u == NULL)
4752 return False;
4754 prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
4755 depth++;
4757 if (UNMARSHALLING(ps))
4758 ZERO_STRUCTP(r_u);
4760 if(!prs_align(ps))
4761 return False;
4763 if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1))
4764 return False;
4765 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
4766 return False;
4768 if (r_u->ptr_rids != 0) {
4769 if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2))
4770 return False;
4772 if (r_u->num_rids2 != r_u->num_rids1) {
4773 /* RPC fault */
4774 return False;
4777 if (UNMARSHALLING(ps))
4778 r_u->rids = PRS_ALLOC_MEM(ps, uint32, r_u->num_rids2);
4780 if (!r_u->rids) {
4781 DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
4782 return False;
4785 for (i = 0; i < r_u->num_rids2; i++) {
4786 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i);
4787 if(!prs_uint32(tmp, ps, depth, &r_u->rids[i]))
4788 return False;
4792 if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
4793 return False;
4794 if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
4795 return False;
4797 if (r_u->ptr_types != 0) {
4798 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
4799 return False;
4801 if (r_u->num_types2 != r_u->num_types1) {
4802 /* RPC fault */
4803 return False;
4806 if (UNMARSHALLING(ps))
4807 r_u->types = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
4809 if (!r_u->types) {
4810 DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
4811 return False;
4814 for (i = 0; i < r_u->num_types2; i++) {
4815 slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i);
4816 if(!prs_uint32(tmp, ps, depth, &r_u->types[i]))
4817 return False;
4821 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4822 return False;
4824 return True;
4827 /*******************************************************************
4828 inits a SAMR_Q_DELETE_DOM_USER structure.
4829 ********************************************************************/
4831 void init_samr_q_delete_dom_user(SAMR_Q_DELETE_DOM_USER * q_c,
4832 POLICY_HND *hnd)
4834 DEBUG(5, ("init_samr_q_delete_dom_user\n"));
4836 q_c->user_pol = *hnd;
4839 /*******************************************************************
4840 reads or writes a structure.
4841 ********************************************************************/
4843 BOOL samr_io_q_delete_dom_user(const char *desc, SAMR_Q_DELETE_DOM_USER * q_u,
4844 prs_struct *ps, int depth)
4846 if (q_u == NULL)
4847 return False;
4849 prs_debug(ps, depth, desc, "samr_io_q_delete_dom_user");
4850 depth++;
4852 if(!prs_align(ps))
4853 return False;
4855 if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
4856 return False;
4858 return True;
4861 /*******************************************************************
4862 reads or writes a structure.
4863 ********************************************************************/
4865 BOOL samr_io_r_delete_dom_user(const char *desc, SAMR_R_DELETE_DOM_USER * r_u,
4866 prs_struct *ps, int depth)
4868 if (r_u == NULL)
4869 return False;
4871 prs_debug(ps, depth, desc, "samr_io_r_delete_dom_user");
4872 depth++;
4874 if(!prs_align(ps))
4875 return False;
4877 if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4878 return False;
4879 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4880 return False;
4882 return True;
4885 /*******************************************************************
4886 reads or writes a structure.
4887 ********************************************************************/
4889 void init_samr_q_open_user(SAMR_Q_OPEN_USER * q_u,
4890 POLICY_HND *pol,
4891 uint32 access_mask, uint32 rid)
4893 DEBUG(5, ("samr_init_samr_q_open_user\n"));
4895 q_u->domain_pol = *pol;
4896 q_u->access_mask = access_mask;
4897 q_u->user_rid = rid;
4900 /*******************************************************************
4901 reads or writes a structure.
4902 ********************************************************************/
4904 BOOL samr_io_q_open_user(const char *desc, SAMR_Q_OPEN_USER * q_u,
4905 prs_struct *ps, int depth)
4907 if (q_u == NULL)
4908 return False;
4910 prs_debug(ps, depth, desc, "samr_io_q_open_user");
4911 depth++;
4913 if(!prs_align(ps))
4914 return False;
4916 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
4917 return False;
4919 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
4920 return False;
4921 if(!prs_uint32("user_rid ", ps, depth, &q_u->user_rid))
4922 return False;
4924 return True;
4927 /*******************************************************************
4928 reads or writes a structure.
4929 ********************************************************************/
4931 BOOL samr_io_r_open_user(const char *desc, SAMR_R_OPEN_USER * r_u,
4932 prs_struct *ps, int depth)
4934 if (r_u == NULL)
4935 return False;
4937 prs_debug(ps, depth, desc, "samr_io_r_open_user");
4938 depth++;
4940 if(!prs_align(ps))
4941 return False;
4943 if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
4944 return False;
4946 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4947 return False;
4949 return True;
4953 /*******************************************************************
4954 reads or writes a structure.
4955 ********************************************************************/
4957 void init_samr_q_create_user(SAMR_Q_CREATE_USER * q_u,
4958 POLICY_HND *pol,
4959 const char *name,
4960 uint32 acb_info, uint32 access_mask)
4962 DEBUG(5, ("samr_init_samr_q_create_user\n"));
4964 q_u->domain_pol = *pol;
4966 init_unistr2(&q_u->uni_name, name, UNI_FLAGS_NONE);
4967 init_uni_hdr(&q_u->hdr_name, &q_u->uni_name);
4969 q_u->acb_info = acb_info;
4970 q_u->access_mask = access_mask;
4973 /*******************************************************************
4974 reads or writes a structure.
4975 ********************************************************************/
4977 BOOL samr_io_q_create_user(const char *desc, SAMR_Q_CREATE_USER * q_u,
4978 prs_struct *ps, int depth)
4980 if (q_u == NULL)
4981 return False;
4983 prs_debug(ps, depth, desc, "samr_io_q_create_user");
4984 depth++;
4986 if(!prs_align(ps))
4987 return False;
4989 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
4990 return False;
4992 if(!smb_io_unihdr("hdr_name", &q_u->hdr_name, ps, depth))
4993 return False;
4994 if(!smb_io_unistr2("uni_name", &q_u->uni_name, q_u->hdr_name.buffer, ps, depth))
4995 return False;
4997 if(!prs_align(ps))
4998 return False;
4999 if(!prs_uint32("acb_info ", ps, depth, &q_u->acb_info))
5000 return False;
5001 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
5002 return False;
5004 return True;
5007 /*******************************************************************
5008 reads or writes a structure.
5009 ********************************************************************/
5011 BOOL samr_io_r_create_user(const char *desc, SAMR_R_CREATE_USER * r_u,
5012 prs_struct *ps, int depth)
5014 if (r_u == NULL)
5015 return False;
5017 prs_debug(ps, depth, desc, "samr_io_r_create_user");
5018 depth++;
5020 if(!prs_align(ps))
5021 return False;
5023 if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
5024 return False;
5026 if(!prs_uint32("access_granted", ps, depth, &r_u->access_granted))
5027 return False;
5028 if(!prs_uint32("user_rid ", ps, depth, &r_u->user_rid))
5029 return False;
5030 if(!prs_ntstatus("status", ps, depth, &r_u->status))
5031 return False;
5033 return True;
5036 /*******************************************************************
5037 inits a SAMR_Q_QUERY_USERINFO structure.
5038 ********************************************************************/
5040 void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
5041 const POLICY_HND *hnd, uint16 switch_value)
5043 DEBUG(5, ("init_samr_q_query_userinfo\n"));
5045 q_u->pol = *hnd;
5046 q_u->switch_value = switch_value;
5049 /*******************************************************************
5050 reads or writes a structure.
5051 ********************************************************************/
5053 BOOL samr_io_q_query_userinfo(const char *desc, SAMR_Q_QUERY_USERINFO * q_u,
5054 prs_struct *ps, int depth)
5056 if (q_u == NULL)
5057 return False;
5059 prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
5060 depth++;
5062 if(!prs_align(ps))
5063 return False;
5065 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
5066 return False;
5068 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */
5069 return False;
5071 return True;
5074 /*******************************************************************
5075 reads or writes a LOGON_HRS structure.
5076 ********************************************************************/
5078 static BOOL sam_io_logon_hrs(const char *desc, LOGON_HRS * hrs,
5079 prs_struct *ps, int depth)
5081 if (hrs == NULL)
5082 return False;
5084 prs_debug(ps, depth, desc, "sam_io_logon_hrs");
5085 depth++;
5087 if(!prs_align(ps))
5088 return False;
5090 if(!prs_uint32("maxlen", ps, depth, &hrs->max_len))
5091 return False;
5093 if(!prs_uint32("offset", ps, depth, &hrs->offset))
5094 return False;
5096 if(!prs_uint32("len ", ps, depth, &hrs->len))
5097 return False;
5099 if (hrs->len > sizeof(hrs->hours)) {
5100 DEBUG(3, ("sam_io_logon_hrs: truncating length from %d\n", hrs->len));
5101 hrs->len = sizeof(hrs->hours);
5104 if(!prs_uint8s(False, "hours", ps, depth, hrs->hours, hrs->len))
5105 return False;
5107 return True;
5110 /*******************************************************************
5111 inits a SAM_USER_INFO_18 structure.
5112 ********************************************************************/
5114 void init_sam_user_info18(SAM_USER_INFO_18 * usr,
5115 const uint8 lm_pwd[16], const uint8 nt_pwd[16])
5117 DEBUG(5, ("init_sam_user_info18\n"));
5119 usr->lm_pwd_active =
5120 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd)) ? 1 : 0;
5121 usr->nt_pwd_active =
5122 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd)) ? 1 : 0;
5125 /*******************************************************************
5126 reads or writes a structure.
5127 ********************************************************************/
5129 static BOOL sam_io_user_info18(const char *desc, SAM_USER_INFO_18 * u,
5130 prs_struct *ps, int depth)
5132 if (u == NULL)
5133 return False;
5135 prs_debug(ps, depth, desc, "samr_io_r_user_info18");
5136 depth++;
5138 if(!prs_align(ps))
5139 return False;
5141 if(!prs_uint8s(False, "lm_pwd", ps, depth, u->lm_pwd, sizeof(u->lm_pwd)))
5142 return False;
5143 if(!prs_uint8s(False, "nt_pwd", ps, depth, u->nt_pwd, sizeof(u->nt_pwd)))
5144 return False;
5146 if(!prs_uint8("lm_pwd_active", ps, depth, &u->lm_pwd_active))
5147 return False;
5148 if(!prs_uint8("nt_pwd_active", ps, depth, &u->nt_pwd_active))
5149 return False;
5151 return True;
5154 /*******************************************************************
5155 inits a SAM_USER_INFO_7 structure.
5156 ********************************************************************/
5158 void init_sam_user_info7(SAM_USER_INFO_7 * usr, const char *name)
5160 DEBUG(5, ("init_sam_user_info7\n"));
5162 init_unistr2(&usr->uni_name, name, UNI_FLAGS_NONE); /* unicode string for name */
5163 init_uni_hdr(&usr->hdr_name, &usr->uni_name); /* unicode header for name */
5167 /*******************************************************************
5168 reads or writes a structure.
5169 ********************************************************************/
5171 static BOOL sam_io_user_info7(const char *desc, SAM_USER_INFO_7 * usr,
5172 prs_struct *ps, int depth)
5174 if (usr == NULL)
5175 return False;
5177 prs_debug(ps, depth, desc, "samr_io_r_user_info7");
5178 depth++;
5180 if(!prs_align(ps))
5181 return False;
5183 if(!smb_io_unihdr("unihdr", &usr->hdr_name, ps, depth))
5184 return False;
5186 if(!smb_io_unistr2("unistr2", &usr->uni_name, True, ps, depth))
5187 return False;
5189 return True;
5192 /*******************************************************************
5193 inits a SAM_USER_INFO_9 structure.
5194 ********************************************************************/
5196 void init_sam_user_info9(SAM_USER_INFO_9 * usr, uint32 rid_group)
5198 DEBUG(5, ("init_sam_user_info9\n"));
5200 usr->rid_group = rid_group;
5203 /*******************************************************************
5204 reads or writes a structure.
5205 ********************************************************************/
5207 static BOOL sam_io_user_info9(const char *desc, SAM_USER_INFO_9 * usr,
5208 prs_struct *ps, int depth)
5210 if (usr == NULL)
5211 return False;
5213 prs_debug(ps, depth, desc, "samr_io_r_user_info9");
5214 depth++;
5216 if(!prs_align(ps))
5217 return False;
5219 if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
5220 return False;
5222 return True;
5225 /*******************************************************************
5226 inits a SAM_USER_INFO_16 structure.
5227 ********************************************************************/
5229 void init_sam_user_info16(SAM_USER_INFO_16 * usr, uint32 acb_info)
5231 DEBUG(5, ("init_sam_user_info16\n"));
5233 usr->acb_info = acb_info;
5236 /*******************************************************************
5237 reads or writes a structure.
5238 ********************************************************************/
5240 static BOOL sam_io_user_info16(const char *desc, SAM_USER_INFO_16 * usr,
5241 prs_struct *ps, int depth)
5243 if (usr == NULL)
5244 return False;
5246 prs_debug(ps, depth, desc, "samr_io_r_user_info16");
5247 depth++;
5249 if(!prs_align(ps))
5250 return False;
5252 if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
5253 return False;
5255 return True;
5258 /*******************************************************************
5259 inits a SAM_USER_INFO_17 structure.
5260 ********************************************************************/
5262 void init_sam_user_info17(SAM_USER_INFO_17 * usr,
5263 NTTIME * expiry,
5264 char *mach_acct,
5265 uint32 rid_user, uint32 rid_group, uint16 acct_ctrl)
5267 DEBUG(5, ("init_sam_user_info17\n"));
5269 memcpy(&usr->expiry, expiry, sizeof(usr->expiry)); /* expiry time or something? */
5270 ZERO_STRUCT(usr->padding_1); /* 0 - padding 24 bytes */
5272 usr->padding_2 = 0; /* 0 - padding 4 bytes */
5274 usr->ptr_1 = 1; /* pointer */
5275 ZERO_STRUCT(usr->padding_3); /* 0 - padding 32 bytes */
5276 usr->padding_4 = 0; /* 0 - padding 4 bytes */
5278 usr->ptr_2 = 1; /* pointer */
5279 usr->padding_5 = 0; /* 0 - padding 4 bytes */
5281 usr->ptr_3 = 1; /* pointer */
5282 ZERO_STRUCT(usr->padding_6); /* 0 - padding 32 bytes */
5284 usr->rid_user = rid_user;
5285 usr->rid_group = rid_group;
5287 usr->acct_ctrl = acct_ctrl;
5288 usr->unknown_3 = 0x0000;
5290 usr->unknown_4 = 0x003f; /* 0x003f - 16 bit unknown */
5291 usr->unknown_5 = 0x003c; /* 0x003c - 16 bit unknown */
5293 ZERO_STRUCT(usr->padding_7); /* 0 - padding 16 bytes */
5294 usr->padding_8 = 0; /* 0 - padding 4 bytes */
5296 init_unistr2(&usr->uni_mach_acct, mach_acct, UNI_FLAGS_NONE); /* unicode string for machine account */
5297 init_uni_hdr(&usr->hdr_mach_acct, &usr->uni_mach_acct); /* unicode header for machine account */
5300 /*******************************************************************
5301 reads or writes a structure.
5302 ********************************************************************/
5304 static BOOL sam_io_user_info17(const char *desc, SAM_USER_INFO_17 * usr,
5305 prs_struct *ps, int depth)
5307 if (usr == NULL)
5308 return False;
5310 prs_debug(ps, depth, desc, "samr_io_r_unknown_17");
5311 depth++;
5313 if(!prs_align(ps))
5314 return False;
5316 if(!prs_uint8s(False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)))
5317 return False;
5319 if(!smb_io_time("time", &usr->expiry, ps, depth))
5320 return False;
5322 if(!prs_uint8s(False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)))
5323 return False;
5325 if(!smb_io_unihdr("unihdr", &usr->hdr_mach_acct, ps, depth))
5326 return False;
5328 if(!prs_uint32("padding_2", ps, depth, &usr->padding_2))
5329 return False;
5331 if(!prs_uint32("ptr_1 ", ps, depth, &usr->ptr_1))
5332 return False;
5333 if(!prs_uint8s(False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)))
5334 return False;
5336 if(!prs_uint32("padding_4", ps, depth, &usr->padding_4))
5337 return False;
5339 if(!prs_uint32("ptr_2 ", ps, depth, &usr->ptr_2))
5340 return False;
5341 if(!prs_uint32("padding_5", ps, depth, &usr->padding_5))
5342 return False;
5344 if(!prs_uint32("ptr_3 ", ps, depth, &usr->ptr_3))
5345 return False;
5346 if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6,sizeof(usr->padding_6)))
5347 return False;
5349 if(!prs_uint32("rid_user ", ps, depth, &usr->rid_user))
5350 return False;
5351 if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
5352 return False;
5353 if(!prs_uint16("acct_ctrl", ps, depth, &usr->acct_ctrl))
5354 return False;
5355 if(!prs_uint16("unknown_3", ps, depth, &usr->unknown_3))
5356 return False;
5357 if(!prs_uint16("unknown_4", ps, depth, &usr->unknown_4))
5358 return False;
5359 if(!prs_uint16("unknown_5", ps, depth, &usr->unknown_5))
5360 return False;
5362 if(!prs_uint8s(False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)))
5363 return False;
5365 if(!prs_uint32("padding_8", ps, depth, &(usr->padding_8)))
5366 return False;
5368 if(!smb_io_unistr2("unistr2", &usr->uni_mach_acct, True, ps, depth))
5369 return False;
5371 if(!prs_align(ps))
5372 return False;
5374 if(!prs_uint8s(False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9)))
5375 return False;
5377 return True;
5380 /*************************************************************************
5381 init_sam_user_infoa
5382 *************************************************************************/
5384 void init_sam_user_info24(SAM_USER_INFO_24 * usr, char newpass[516], uint16 pw_len)
5386 DEBUG(10, ("init_sam_user_info24:\n"));
5387 memcpy(usr->pass, newpass, sizeof(usr->pass));
5388 usr->pw_len = pw_len;
5391 /*******************************************************************
5392 reads or writes a structure.
5393 ********************************************************************/
5395 static BOOL sam_io_user_info24(const char *desc, SAM_USER_INFO_24 * usr,
5396 prs_struct *ps, int depth)
5398 if (usr == NULL)
5399 return False;
5401 prs_debug(ps, depth, desc, "sam_io_user_info24");
5402 depth++;
5404 if(!prs_align(ps))
5405 return False;
5407 if(!prs_uint8s(False, "password", ps, depth, usr->pass,
5408 sizeof(usr->pass)))
5409 return False;
5411 if (MARSHALLING(ps) && (usr->pw_len != 0)) {
5412 if (!prs_uint16("pw_len", ps, depth, &usr->pw_len))
5413 return False;
5414 } else if (UNMARSHALLING(ps)) {
5415 if (!prs_uint16("pw_len", ps, depth, &usr->pw_len))
5416 return False;
5419 return True;
5422 /*******************************************************************
5423 reads or writes a structure.
5424 ********************************************************************/
5426 static BOOL sam_io_user_info26(const char *desc, SAM_USER_INFO_26 * usr,
5427 prs_struct *ps, int depth)
5429 if (usr == NULL)
5430 return False;
5432 prs_debug(ps, depth, desc, "sam_io_user_info26");
5433 depth++;
5435 if(!prs_align(ps))
5436 return False;
5438 if(!prs_uint8s(False, "password", ps, depth, usr->pass,
5439 sizeof(usr->pass)))
5440 return False;
5442 if (!prs_uint8("pw_len", ps, depth, &usr->pw_len))
5443 return False;
5445 return True;
5449 /*************************************************************************
5450 init_sam_user_info23
5452 unknown_6 = 0x0000 04ec
5454 *************************************************************************/
5456 void init_sam_user_info23W(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5457 NTTIME * logoff_time, /* all zeros */
5458 NTTIME * kickoff_time, /* all zeros */
5459 NTTIME * pass_last_set_time, /* all zeros */
5460 NTTIME * pass_can_change_time, /* all zeros */
5461 NTTIME * pass_must_change_time, /* all zeros */
5462 UNISTR2 *user_name,
5463 UNISTR2 *full_name,
5464 UNISTR2 *home_dir,
5465 UNISTR2 *dir_drive,
5466 UNISTR2 *log_scr,
5467 UNISTR2 *prof_path,
5468 UNISTR2 *desc,
5469 UNISTR2 *wkstas,
5470 UNISTR2 *unk_str,
5471 UNISTR2 *mung_dial,
5472 uint32 user_rid, /* 0x0000 0000 */
5473 uint32 group_rid,
5474 uint32 acb_info,
5475 uint32 fields_present,
5476 uint16 logon_divs,
5477 LOGON_HRS * hrs,
5478 uint16 bad_password_count,
5479 uint16 logon_count,
5480 char newpass[516])
5482 usr->logon_time = *logon_time; /* all zeros */
5483 usr->logoff_time = *logoff_time; /* all zeros */
5484 usr->kickoff_time = *kickoff_time; /* all zeros */
5485 usr->pass_last_set_time = *pass_last_set_time; /* all zeros */
5486 usr->pass_can_change_time = *pass_can_change_time; /* all zeros */
5487 usr->pass_must_change_time = *pass_must_change_time; /* all zeros */
5489 ZERO_STRUCT(usr->nt_pwd);
5490 ZERO_STRUCT(usr->lm_pwd);
5492 usr->user_rid = user_rid; /* 0x0000 0000 */
5493 usr->group_rid = group_rid;
5494 usr->acb_info = acb_info;
5495 usr->fields_present = fields_present; /* 09f8 27fa */
5497 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
5498 usr->ptr_logon_hrs = hrs ? 1 : 0;
5500 if (nt_time_is_zero(pass_must_change_time)) {
5501 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5502 } else {
5503 usr->passmustchange=0;
5506 ZERO_STRUCT(usr->padding1);
5507 ZERO_STRUCT(usr->padding2);
5509 usr->bad_password_count = bad_password_count;
5510 usr->logon_count = logon_count;
5512 memcpy(usr->pass, newpass, sizeof(usr->pass));
5514 copy_unistr2(&usr->uni_user_name, user_name);
5515 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
5517 copy_unistr2(&usr->uni_full_name, full_name);
5518 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
5520 copy_unistr2(&usr->uni_home_dir, home_dir);
5521 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
5523 copy_unistr2(&usr->uni_dir_drive, dir_drive);
5524 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
5526 copy_unistr2(&usr->uni_logon_script, log_scr);
5527 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
5529 copy_unistr2(&usr->uni_profile_path, prof_path);
5530 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
5532 copy_unistr2(&usr->uni_acct_desc, desc);
5533 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
5535 copy_unistr2(&usr->uni_workstations, wkstas);
5536 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
5538 copy_unistr2(&usr->uni_unknown_str, unk_str);
5539 init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
5541 copy_unistr2(&usr->uni_munged_dial, mung_dial);
5542 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
5544 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5547 /*************************************************************************
5548 init_sam_user_info23
5550 unknown_6 = 0x0000 04ec
5552 *************************************************************************/
5554 void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5555 NTTIME * logoff_time, /* all zeros */
5556 NTTIME * kickoff_time, /* all zeros */
5557 NTTIME * pass_last_set_time, /* all zeros */
5558 NTTIME * pass_can_change_time, /* all zeros */
5559 NTTIME * pass_must_change_time, /* all zeros */
5560 char *user_name, /* NULL */
5561 char *full_name,
5562 char *home_dir, char *dir_drive, char *log_scr,
5563 char *prof_path, const char *desc, char *wkstas,
5564 char *unk_str, char *mung_dial, uint32 user_rid, /* 0x0000 0000 */
5565 uint32 group_rid, uint32 acb_info,
5566 uint32 fields_present, uint16 logon_divs,
5567 LOGON_HRS * hrs, uint16 bad_password_count, uint16 logon_count,
5568 char newpass[516])
5570 DATA_BLOB blob = base64_decode_data_blob(mung_dial);
5572 usr->logon_time = *logon_time; /* all zeros */
5573 usr->logoff_time = *logoff_time; /* all zeros */
5574 usr->kickoff_time = *kickoff_time; /* all zeros */
5575 usr->pass_last_set_time = *pass_last_set_time; /* all zeros */
5576 usr->pass_can_change_time = *pass_can_change_time; /* all zeros */
5577 usr->pass_must_change_time = *pass_must_change_time; /* all zeros */
5579 ZERO_STRUCT(usr->nt_pwd);
5580 ZERO_STRUCT(usr->lm_pwd);
5582 usr->user_rid = user_rid; /* 0x0000 0000 */
5583 usr->group_rid = group_rid;
5584 usr->acb_info = acb_info;
5585 usr->fields_present = fields_present; /* 09f8 27fa */
5587 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
5588 usr->ptr_logon_hrs = hrs ? 1 : 0;
5590 if (nt_time_is_zero(pass_must_change_time)) {
5591 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5592 } else {
5593 usr->passmustchange=0;
5596 ZERO_STRUCT(usr->padding1);
5597 ZERO_STRUCT(usr->padding2);
5599 usr->bad_password_count = bad_password_count;
5600 usr->logon_count = logon_count;
5602 memcpy(usr->pass, newpass, sizeof(usr->pass));
5604 init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
5605 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
5607 init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
5608 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
5610 init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
5611 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
5613 init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
5614 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
5616 init_unistr2(&usr->uni_logon_script, log_scr, UNI_FLAGS_NONE);
5617 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
5619 init_unistr2(&usr->uni_profile_path, prof_path, UNI_FLAGS_NONE);
5620 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
5622 init_unistr2(&usr->uni_acct_desc, desc, UNI_FLAGS_NONE);
5623 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
5625 init_unistr2(&usr->uni_workstations, wkstas, UNI_FLAGS_NONE);
5626 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
5628 init_unistr2(&usr->uni_unknown_str, unk_str, UNI_FLAGS_NONE);
5629 init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
5631 init_unistr2_from_datablob(&usr->uni_munged_dial, &blob);
5632 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
5634 data_blob_free(&blob);
5636 if (hrs) {
5637 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5638 } else {
5639 ZERO_STRUCT(usr->logon_hrs);
5643 /*******************************************************************
5644 reads or writes a structure.
5645 ********************************************************************/
5647 static BOOL sam_io_user_info23(const char *desc, SAM_USER_INFO_23 * usr,
5648 prs_struct *ps, int depth)
5650 if (usr == NULL)
5651 return False;
5653 prs_debug(ps, depth, desc, "sam_io_user_info23");
5654 depth++;
5656 if(!prs_align(ps))
5657 return False;
5659 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
5660 return False;
5661 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
5662 return False;
5663 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
5664 return False;
5665 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps, depth))
5666 return False;
5667 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5668 return False;
5669 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5670 return False;
5672 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
5673 return False;
5674 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
5675 return False;
5676 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
5677 return False;
5678 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
5679 return False;
5680 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
5681 return False;
5682 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
5683 return False;
5684 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
5685 return False;
5686 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
5687 return False;
5688 if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
5689 return False;
5690 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
5691 return False;
5693 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5694 return False;
5695 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5696 return False;
5698 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
5699 return False;
5700 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
5701 return False;
5702 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
5703 return False;
5705 if(!prs_uint32("fields_present ", ps, depth, &usr->fields_present))
5706 return False;
5707 if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */
5708 return False;
5709 if(!prs_align(ps))
5710 return False;
5711 if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
5712 return False;
5714 if(!prs_uint16("bad_password_count ", ps, depth, &usr->bad_password_count))
5715 return False;
5716 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count))
5717 return False;
5719 if(!prs_uint8s(False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)))
5720 return False;
5721 if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
5722 return False;
5723 if(!prs_uint8("padding2 ", ps, depth, &usr->padding2))
5724 return False;
5727 if(!prs_uint8s(False, "password ", ps, depth, usr->pass, sizeof(usr->pass)))
5728 return False;
5730 /* here begins pointed-to data */
5732 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
5733 return False;
5735 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
5736 return False;
5738 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
5739 return False;
5741 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
5742 return False;
5744 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
5745 return False;
5747 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
5748 return False;
5750 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
5751 return False;
5753 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
5754 return False;
5756 if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth)) /* unknown string */
5757 return False;
5759 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5760 return False;
5762 /* ok, this is only guess-work (as usual) */
5763 if (usr->ptr_logon_hrs) {
5764 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5765 return False;
5768 return True;
5771 /*******************************************************************
5772 reads or writes a structure.
5773 NB. This structure is *definately* incorrect. It's my best guess
5774 currently for W2K SP2. The password field is encrypted in a different
5775 way than normal... And there are definately other problems. JRA.
5776 ********************************************************************/
5778 static BOOL sam_io_user_info25(const char *desc, SAM_USER_INFO_25 * usr, prs_struct *ps, int depth)
5780 if (usr == NULL)
5781 return False;
5783 prs_debug(ps, depth, desc, "sam_io_user_info25");
5784 depth++;
5786 if(!prs_align(ps))
5787 return False;
5789 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
5790 return False;
5791 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
5792 return False;
5793 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
5794 return False;
5795 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps, depth))
5796 return False;
5797 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5798 return False;
5799 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5800 return False;
5802 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
5803 return False;
5804 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
5805 return False;
5806 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
5807 return False;
5808 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
5809 return False;
5810 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
5811 return False;
5812 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
5813 return False;
5814 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
5815 return False;
5816 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
5817 return False;
5818 if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
5819 return False;
5820 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
5821 return False;
5823 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5824 return False;
5825 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5826 return False;
5828 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
5829 return False;
5830 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
5831 return False;
5832 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
5833 return False;
5835 if(!prs_uint32s(False, "unknown_6 ", ps, depth, usr->unknown_6, 6))
5836 return False;
5838 if(!prs_uint8s(False, "password ", ps, depth, usr->pass, sizeof(usr->pass)))
5839 return False;
5841 /* here begins pointed-to data */
5843 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
5844 return False;
5846 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
5847 return False;
5849 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
5850 return False;
5852 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
5853 return False;
5855 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
5856 return False;
5858 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
5859 return False;
5861 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
5862 return False;
5864 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
5865 return False;
5867 if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth)) /* unknown string */
5868 return False;
5870 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5871 return False;
5873 #if 0 /* JRA - unknown... */
5874 /* ok, this is only guess-work (as usual) */
5875 if (usr->ptr_logon_hrs) {
5876 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5877 return False;
5879 #endif
5881 return True;
5885 /*************************************************************************
5886 init_sam_user_info21W
5888 unknown_6 = 0x0000 04ec
5890 *************************************************************************/
5892 void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
5893 NTTIME * logon_time,
5894 NTTIME * logoff_time,
5895 NTTIME * kickoff_time,
5896 NTTIME * pass_last_set_time,
5897 NTTIME * pass_can_change_time,
5898 NTTIME * pass_must_change_time,
5899 UNISTR2 *user_name,
5900 UNISTR2 *full_name,
5901 UNISTR2 *home_dir,
5902 UNISTR2 *dir_drive,
5903 UNISTR2 *log_scr,
5904 UNISTR2 *prof_path,
5905 UNISTR2 *desc,
5906 UNISTR2 *wkstas,
5907 UNISTR2 *unk_str,
5908 UNISTR2 *mung_dial,
5909 uchar lm_pwd[16],
5910 uchar nt_pwd[16],
5911 uint32 user_rid,
5912 uint32 group_rid,
5913 uint32 acb_info,
5914 uint32 fields_present,
5915 uint16 logon_divs,
5916 LOGON_HRS * hrs,
5917 uint16 bad_password_count,
5918 uint16 logon_count)
5920 usr->logon_time = *logon_time;
5921 usr->logoff_time = *logoff_time;
5922 usr->kickoff_time = *kickoff_time;
5923 usr->pass_last_set_time = *pass_last_set_time;
5924 usr->pass_can_change_time = *pass_can_change_time;
5925 usr->pass_must_change_time = *pass_must_change_time;
5927 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd));
5928 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd));
5930 usr->user_rid = user_rid;
5931 usr->group_rid = group_rid;
5932 usr->acb_info = acb_info;
5933 usr->fields_present = fields_present; /* 0x00ff ffff */
5935 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
5936 usr->ptr_logon_hrs = hrs ? 1 : 0;
5937 usr->bad_password_count = bad_password_count;
5938 usr->logon_count = logon_count;
5940 if (nt_time_is_zero(pass_must_change_time)) {
5941 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5942 } else {
5943 usr->passmustchange=0;
5946 ZERO_STRUCT(usr->padding1);
5947 ZERO_STRUCT(usr->padding2);
5949 copy_unistr2(&usr->uni_user_name, user_name);
5950 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
5952 copy_unistr2(&usr->uni_full_name, full_name);
5953 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
5955 copy_unistr2(&usr->uni_home_dir, home_dir);
5956 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
5958 copy_unistr2(&usr->uni_dir_drive, dir_drive);
5959 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
5961 copy_unistr2(&usr->uni_logon_script, log_scr);
5962 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
5964 copy_unistr2(&usr->uni_profile_path, prof_path);
5965 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
5967 copy_unistr2(&usr->uni_acct_desc, desc);
5968 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
5970 copy_unistr2(&usr->uni_workstations, wkstas);
5971 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
5973 copy_unistr2(&usr->uni_unknown_str, unk_str);
5974 init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
5976 copy_unistr2(&usr->uni_munged_dial, mung_dial);
5977 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
5979 if (hrs) {
5980 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5981 } else {
5982 ZERO_STRUCT(usr->logon_hrs);
5986 /*************************************************************************
5987 init_sam_user_info21
5989 unknown_6 = 0x0000 04ec
5991 *************************************************************************/
5993 NTSTATUS init_sam_user_info21A(SAM_USER_INFO_21 *usr, struct samu *pw, DOM_SID *domain_sid)
5995 NTTIME logon_time, logoff_time, kickoff_time,
5996 pass_last_set_time, pass_can_change_time,
5997 pass_must_change_time;
5999 const char* user_name = pdb_get_username(pw);
6000 const char* full_name = pdb_get_fullname(pw);
6001 const char* home_dir = pdb_get_homedir(pw);
6002 const char* dir_drive = pdb_get_dir_drive(pw);
6003 const char* logon_script = pdb_get_logon_script(pw);
6004 const char* profile_path = pdb_get_profile_path(pw);
6005 const char* description = pdb_get_acct_desc(pw);
6006 const char* workstations = pdb_get_workstations(pw);
6007 const char* munged_dial = pdb_get_munged_dial(pw);
6008 DATA_BLOB munged_dial_blob;
6010 uint32 user_rid;
6011 const DOM_SID *user_sid;
6013 uint32 group_rid;
6014 const DOM_SID *group_sid;
6016 if (munged_dial) {
6017 munged_dial_blob = base64_decode_data_blob(munged_dial);
6018 } else {
6019 munged_dial_blob = data_blob(NULL, 0);
6022 /* Create NTTIME structs */
6023 unix_to_nt_time (&logon_time, pdb_get_logon_time(pw));
6024 unix_to_nt_time (&logoff_time, pdb_get_logoff_time(pw));
6025 unix_to_nt_time (&kickoff_time, pdb_get_kickoff_time(pw));
6026 unix_to_nt_time (&pass_last_set_time, pdb_get_pass_last_set_time(pw));
6027 unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(pw));
6028 unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(pw));
6030 /* structure assignment */
6031 usr->logon_time = logon_time;
6032 usr->logoff_time = logoff_time;
6033 usr->kickoff_time = kickoff_time;
6034 usr->pass_last_set_time = pass_last_set_time;
6035 usr->pass_can_change_time = pass_can_change_time;
6036 usr->pass_must_change_time = pass_must_change_time;
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 data_blob_free(&munged_dial_blob);
6052 return NT_STATUS_UNSUCCESSFUL;
6055 group_sid = pdb_get_group_sid(pw);
6057 if (!sid_peek_check_rid(domain_sid, group_sid, &group_rid)) {
6058 fstring group_sid_string;
6059 fstring domain_sid_string;
6060 DEBUG(0, ("init_sam_user_info_21A: User %s has Primary Group SID %s, \n"
6061 "which conflicts with the domain sid %s. Failing operation.\n",
6062 user_name,
6063 sid_to_string(group_sid_string, group_sid),
6064 sid_to_string(domain_sid_string, domain_sid)));
6065 data_blob_free(&munged_dial_blob);
6066 return NT_STATUS_UNSUCCESSFUL;
6069 usr->user_rid = user_rid;
6070 usr->group_rid = group_rid;
6071 usr->acb_info = pdb_get_acct_ctrl(pw);
6074 Look at a user on a real NT4 PDC with usrmgr, press
6075 'ok'. Then you will see that fields_present is set to
6076 0x08f827fa. Look at the user immediately after that again,
6077 and you will see that 0x00fffff is returned. This solves
6078 the problem that you get access denied after having looked
6079 at the user.
6080 -- Volker
6082 usr->fields_present = pdb_build_fields_present(pw);
6084 usr->logon_divs = pdb_get_logon_divs(pw);
6085 usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
6086 usr->bad_password_count = pdb_get_bad_password_count(pw);
6087 usr->logon_count = pdb_get_logon_count(pw);
6089 if (pdb_get_pass_must_change_time(pw) == 0) {
6090 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
6091 } else {
6092 usr->passmustchange=0;
6095 ZERO_STRUCT(usr->padding1);
6096 ZERO_STRUCT(usr->padding2);
6098 init_unistr2(&usr->uni_user_name, user_name, UNI_STR_TERMINATE);
6099 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
6101 init_unistr2(&usr->uni_full_name, full_name, UNI_STR_TERMINATE);
6102 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
6104 init_unistr2(&usr->uni_home_dir, home_dir, UNI_STR_TERMINATE);
6105 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
6107 init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_STR_TERMINATE);
6108 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
6110 init_unistr2(&usr->uni_logon_script, logon_script, UNI_STR_TERMINATE);
6111 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
6113 init_unistr2(&usr->uni_profile_path, profile_path, UNI_STR_TERMINATE);
6114 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
6116 init_unistr2(&usr->uni_acct_desc, description, UNI_STR_TERMINATE);
6117 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
6119 init_unistr2(&usr->uni_workstations, workstations, UNI_STR_TERMINATE);
6120 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
6122 init_unistr2(&usr->uni_unknown_str, NULL, UNI_STR_TERMINATE);
6123 init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
6125 init_unistr2_from_datablob(&usr->uni_munged_dial, &munged_dial_blob);
6126 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
6127 data_blob_free(&munged_dial_blob);
6129 if (pdb_get_hours(pw)) {
6130 usr->logon_hrs.max_len = 1260;
6131 usr->logon_hrs.offset = 0;
6132 usr->logon_hrs.len = pdb_get_hours_len(pw);
6133 memcpy(&usr->logon_hrs.hours, pdb_get_hours(pw), MAX_HOURS_LEN);
6134 } else {
6135 usr->logon_hrs.max_len = 1260;
6136 usr->logon_hrs.offset = 0;
6137 usr->logon_hrs.len = 0;
6138 memset(&usr->logon_hrs, 0xff, sizeof(usr->logon_hrs));
6141 return NT_STATUS_OK;
6144 /*******************************************************************
6145 reads or writes a structure.
6146 ********************************************************************/
6148 static BOOL sam_io_user_info21(const char *desc, SAM_USER_INFO_21 * usr,
6149 prs_struct *ps, int depth)
6151 if (usr == NULL)
6152 return False;
6154 prs_debug(ps, depth, desc, "sam_io_user_info21");
6155 depth++;
6157 if(!prs_align(ps))
6158 return False;
6160 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
6161 return False;
6162 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
6163 return False;
6164 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps,depth))
6165 return False;
6166 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
6167 return False;
6168 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps,depth))
6169 return False;
6170 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
6171 return False;
6173 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
6174 return False;
6175 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
6176 return False;
6177 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
6178 return False;
6179 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
6180 return False;
6181 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
6182 return False;
6183 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
6184 return False;
6185 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
6186 return False;
6187 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
6188 return False;
6189 if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
6190 return False;
6191 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
6192 return False;
6194 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
6195 return False;
6196 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
6197 return False;
6199 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
6200 return False;
6201 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
6202 return False;
6203 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
6204 return False;
6206 if(!prs_uint32("fields_present ", ps, depth, &usr->fields_present))
6207 return False;
6208 if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */
6209 return False;
6210 if(!prs_align(ps))
6211 return False;
6212 if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
6213 return False;
6215 if(!prs_uint16("bad_password_count ", ps, depth, &usr->bad_password_count))
6216 return False;
6217 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count))
6218 return False;
6220 if(!prs_uint8s(False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)))
6221 return False;
6222 if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
6223 return False;
6224 if(!prs_uint8("padding2 ", ps, depth, &usr->padding2))
6225 return False;
6227 /* here begins pointed-to data */
6229 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name,usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
6230 return False;
6231 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
6232 return False;
6233 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
6234 return False;
6235 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
6236 return False;
6237 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
6238 return False;
6239 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
6240 return False;
6241 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
6242 return False;
6243 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
6244 return False;
6245 if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth)) /* unknown string */
6246 return False;
6247 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth)) /* worksations user can log on from */
6248 return False;
6250 /* ok, this is only guess-work (as usual) */
6251 if (usr->ptr_logon_hrs) {
6252 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
6253 return False;
6256 return True;
6259 void init_sam_user_info20A(SAM_USER_INFO_20 *usr, struct samu *pw)
6261 const char *munged_dial = pdb_get_munged_dial(pw);
6262 DATA_BLOB blob = base64_decode_data_blob(munged_dial);
6264 init_unistr2_from_datablob(&usr->uni_munged_dial, &blob);
6265 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
6266 data_blob_free(&blob);
6269 /*******************************************************************
6270 reads or writes a structure.
6271 ********************************************************************/
6273 static BOOL sam_io_user_info20(const char *desc, SAM_USER_INFO_20 *usr,
6274 prs_struct *ps, int depth)
6276 if (usr == NULL)
6277 return False;
6279 prs_debug(ps, depth, desc, "sam_io_user_info20");
6280 depth++;
6282 if(!prs_align(ps))
6283 return False;
6285 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
6286 return False;
6288 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth)) /* worksations user can log on from */
6289 return False;
6291 return True;
6294 /*******************************************************************
6295 inits a SAM_USERINFO_CTR structure.
6296 ********************************************************************/
6298 NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
6299 uint16 switch_value,
6300 SAM_USER_INFO_21 * usr)
6302 DEBUG(5, ("make_samr_userinfo_ctr_usr21\n"));
6304 ctr->switch_value = switch_value;
6305 ctr->info.id = NULL;
6307 switch (switch_value) {
6308 case 16:
6309 ctr->info.id16 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_16);
6310 if (ctr->info.id16 == NULL)
6311 return NT_STATUS_NO_MEMORY;
6313 init_sam_user_info16(ctr->info.id16, usr->acb_info);
6314 break;
6315 #if 0
6316 /* whoops - got this wrong. i think. or don't understand what's happening. */
6317 case 17:
6319 NTTIME expire;
6320 info = (void *)&id11;
6322 expire.low = 0xffffffff;
6323 expire.high = 0x7fffffff;
6325 ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_17);
6326 init_sam_user_info11(ctr->info.id17, &expire,
6327 "BROOKFIELDS$", /* name */
6328 0x03ef, /* user rid */
6329 0x201, /* group rid */
6330 0x0080); /* acb info */
6332 break;
6334 #endif
6335 case 18:
6336 ctr->info.id18 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_18);
6337 if (ctr->info.id18 == NULL)
6338 return NT_STATUS_NO_MEMORY;
6340 init_sam_user_info18(ctr->info.id18, usr->lm_pwd, usr->nt_pwd);
6341 break;
6342 case 21:
6344 SAM_USER_INFO_21 *cusr;
6345 cusr = TALLOC_ZERO_P(ctx,SAM_USER_INFO_21);
6346 ctr->info.id21 = cusr;
6347 if (ctr->info.id21 == NULL)
6348 return NT_STATUS_NO_MEMORY;
6349 memcpy(cusr, usr, sizeof(*usr));
6350 memset(cusr->lm_pwd, 0, sizeof(cusr->lm_pwd));
6351 memset(cusr->nt_pwd, 0, sizeof(cusr->nt_pwd));
6352 break;
6354 default:
6355 DEBUG(4,("make_samr_userinfo_ctr: unsupported info\n"));
6356 return NT_STATUS_INVALID_INFO_CLASS;
6359 return NT_STATUS_OK;
6362 /*******************************************************************
6363 inits a SAM_USERINFO_CTR structure.
6364 ********************************************************************/
6366 static void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, DATA_BLOB *sess_key,
6367 uint16 switch_value, void *info)
6369 DEBUG(5, ("init_samr_userinfo_ctr\n"));
6371 ctr->switch_value = switch_value;
6372 ctr->info.id = info;
6374 switch (switch_value) {
6375 case 0x18:
6376 SamOEMhashBlob(ctr->info.id24->pass, 516, sess_key);
6377 dump_data(100, (char *)sess_key->data, sess_key->length);
6378 dump_data(100, (char *)ctr->info.id24->pass, 516);
6379 break;
6380 case 0x17:
6381 SamOEMhashBlob(ctr->info.id23->pass, 516, sess_key);
6382 dump_data(100, (char *)sess_key->data, sess_key->length);
6383 dump_data(100, (char *)ctr->info.id23->pass, 516);
6384 break;
6385 case 0x07:
6386 break;
6387 default:
6388 DEBUG(4,("init_samr_userinfo_ctr: unsupported switch level: %d\n", switch_value));
6392 /*******************************************************************
6393 reads or writes a structure.
6394 ********************************************************************/
6396 static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
6397 prs_struct *ps, int depth)
6399 BOOL ret;
6400 SAM_USERINFO_CTR *ctr;
6402 prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
6403 depth++;
6405 if (UNMARSHALLING(ps)) {
6406 ctr = PRS_ALLOC_MEM(ps,SAM_USERINFO_CTR,1);
6407 if (ctr == NULL)
6408 return False;
6409 *ppctr = ctr;
6410 } else {
6411 ctr = *ppctr;
6414 /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
6416 if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
6417 return False;
6418 if(!prs_align(ps))
6419 return False;
6421 ret = False;
6423 switch (ctr->switch_value) {
6424 case 7:
6425 if (UNMARSHALLING(ps))
6426 ctr->info.id7 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_7,1);
6427 if (ctr->info.id7 == NULL) {
6428 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6429 return False;
6431 ret = sam_io_user_info7("", ctr->info.id7, ps, depth);
6432 break;
6433 case 9:
6434 if (UNMARSHALLING(ps))
6435 ctr->info.id9 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_9,1);
6436 if (ctr->info.id9 == NULL) {
6437 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6438 return False;
6440 ret = sam_io_user_info9("", ctr->info.id9, ps, depth);
6441 break;
6442 case 16:
6443 if (UNMARSHALLING(ps))
6444 ctr->info.id16 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_16,1);
6445 if (ctr->info.id16 == NULL) {
6446 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6447 return False;
6449 ret = sam_io_user_info16("", ctr->info.id16, ps, depth);
6450 break;
6451 case 17:
6452 if (UNMARSHALLING(ps))
6453 ctr->info.id17 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_17,1);
6455 if (ctr->info.id17 == NULL) {
6456 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6457 return False;
6459 ret = sam_io_user_info17("", ctr->info.id17, ps, depth);
6460 break;
6461 case 18:
6462 if (UNMARSHALLING(ps))
6463 ctr->info.id18 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_18,1);
6465 if (ctr->info.id18 == NULL) {
6466 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6467 return False;
6469 ret = sam_io_user_info18("", ctr->info.id18, ps, depth);
6470 break;
6471 case 20:
6472 if (UNMARSHALLING(ps))
6473 ctr->info.id20 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_20,1);
6475 if (ctr->info.id20 == NULL) {
6476 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6477 return False;
6479 ret = sam_io_user_info20("", ctr->info.id20, ps, depth);
6480 break;
6481 case 21:
6482 if (UNMARSHALLING(ps))
6483 ctr->info.id21 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_21,1);
6485 if (ctr->info.id21 == NULL) {
6486 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6487 return False;
6489 ret = sam_io_user_info21("", ctr->info.id21, ps, depth);
6490 break;
6491 case 23:
6492 if (UNMARSHALLING(ps))
6493 ctr->info.id23 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_23,1);
6495 if (ctr->info.id23 == NULL) {
6496 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6497 return False;
6499 ret = sam_io_user_info23("", ctr->info.id23, ps, depth);
6500 break;
6501 case 24:
6502 if (UNMARSHALLING(ps))
6503 ctr->info.id24 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_24,1);
6505 if (ctr->info.id24 == NULL) {
6506 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6507 return False;
6509 ret = sam_io_user_info24("", ctr->info.id24, ps, depth);
6510 break;
6511 case 25:
6512 if (UNMARSHALLING(ps))
6513 ctr->info.id25 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_25,1);
6515 if (ctr->info.id25 == NULL) {
6516 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6517 return False;
6519 ret = sam_io_user_info25("", ctr->info.id25, ps, depth);
6520 break;
6521 case 26:
6522 if (UNMARSHALLING(ps))
6523 ctr->info.id26 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_26,1);
6525 if (ctr->info.id26 == NULL) {
6526 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6527 return False;
6529 ret = sam_io_user_info26("", ctr->info.id26, ps, depth);
6530 break;
6531 default:
6532 DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
6533 ret = False;
6534 break;
6537 return ret;
6540 /*******************************************************************
6541 inits a SAMR_R_QUERY_USERINFO structure.
6542 ********************************************************************/
6544 void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
6545 SAM_USERINFO_CTR * ctr, NTSTATUS status)
6547 DEBUG(5, ("init_samr_r_query_userinfo\n"));
6549 r_u->ptr = 0;
6550 r_u->ctr = NULL;
6552 if (NT_STATUS_IS_OK(status)) {
6553 r_u->ptr = 1;
6554 r_u->ctr = ctr;
6557 r_u->status = status; /* return status */
6560 /*******************************************************************
6561 reads or writes a structure.
6562 ********************************************************************/
6564 BOOL samr_io_r_query_userinfo(const char *desc, SAMR_R_QUERY_USERINFO * r_u,
6565 prs_struct *ps, int depth)
6567 if (r_u == NULL)
6568 return False;
6570 prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
6571 depth++;
6573 if(!prs_align(ps))
6574 return False;
6576 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
6577 return False;
6579 if (r_u->ptr != 0) {
6580 if(!samr_io_userinfo_ctr("ctr", &r_u->ctr, ps, depth))
6581 return False;
6584 if(!prs_align(ps))
6585 return False;
6586 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6587 return False;
6589 return True;
6592 /*******************************************************************
6593 inits a SAMR_Q_SET_USERINFO structure.
6594 ********************************************************************/
6596 void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
6597 const POLICY_HND *hnd, DATA_BLOB *sess_key,
6598 uint16 switch_value, void *info)
6600 DEBUG(5, ("init_samr_q_set_userinfo\n"));
6602 q_u->pol = *hnd;
6603 q_u->switch_value = switch_value;
6604 init_samr_userinfo_ctr(q_u->ctr, sess_key, switch_value, info);
6607 /*******************************************************************
6608 reads or writes a structure.
6609 ********************************************************************/
6611 BOOL samr_io_q_set_userinfo(const char *desc, SAMR_Q_SET_USERINFO * q_u,
6612 prs_struct *ps, int depth)
6614 if (q_u == NULL)
6615 return False;
6617 prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
6618 depth++;
6620 if(!prs_align(ps))
6621 return False;
6623 smb_io_pol_hnd("pol", &(q_u->pol), ps, depth);
6625 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6626 return False;
6627 if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6628 return False;
6630 return True;
6633 /*******************************************************************
6634 inits a SAMR_R_SET_USERINFO structure.
6635 ********************************************************************/
6637 void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, NTSTATUS status)
6639 DEBUG(5, ("init_samr_r_set_userinfo\n"));
6641 r_u->status = status; /* return status */
6644 /*******************************************************************
6645 reads or writes a structure.
6646 ********************************************************************/
6648 BOOL samr_io_r_set_userinfo(const char *desc, SAMR_R_SET_USERINFO * r_u,
6649 prs_struct *ps, int depth)
6651 if (r_u == NULL)
6652 return False;
6654 prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
6655 depth++;
6657 if(!prs_align(ps))
6658 return False;
6660 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6661 return False;
6663 return True;
6666 /*******************************************************************
6667 inits a SAMR_Q_SET_USERINFO2 structure.
6668 ********************************************************************/
6670 void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
6671 const POLICY_HND *hnd, DATA_BLOB *sess_key,
6672 uint16 switch_value, SAM_USERINFO_CTR * ctr)
6674 DEBUG(5, ("init_samr_q_set_userinfo2\n"));
6676 q_u->pol = *hnd;
6677 q_u->switch_value = switch_value;
6678 q_u->ctr = ctr;
6680 if (q_u->ctr != NULL)
6681 q_u->ctr->switch_value = switch_value;
6683 switch (switch_value) {
6684 case 18:
6685 SamOEMhashBlob(ctr->info.id18->lm_pwd, 16, sess_key);
6686 SamOEMhashBlob(ctr->info.id18->nt_pwd, 16, sess_key);
6687 dump_data(100, (char *)sess_key->data, sess_key->length);
6688 dump_data(100, (char *)ctr->info.id18->lm_pwd, 16);
6689 dump_data(100, (char *)ctr->info.id18->nt_pwd, 16);
6690 break;
6694 /*******************************************************************
6695 reads or writes a structure.
6696 ********************************************************************/
6698 BOOL samr_io_q_set_userinfo2(const char *desc, SAMR_Q_SET_USERINFO2 * q_u,
6699 prs_struct *ps, int depth)
6701 if (q_u == NULL)
6702 return False;
6704 prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
6705 depth++;
6707 if(!prs_align(ps))
6708 return False;
6710 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
6711 return False;
6713 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6714 return False;
6715 if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6716 return False;
6718 return True;
6721 /*******************************************************************
6722 inits a SAMR_R_SET_USERINFO2 structure.
6723 ********************************************************************/
6725 void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, NTSTATUS status)
6727 DEBUG(5, ("init_samr_r_set_userinfo2\n"));
6729 r_u->status = status; /* return status */
6732 /*******************************************************************
6733 reads or writes a structure.
6734 ********************************************************************/
6736 BOOL samr_io_r_set_userinfo2(const char *desc, SAMR_R_SET_USERINFO2 * r_u,
6737 prs_struct *ps, int depth)
6739 if (r_u == NULL)
6740 return False;
6742 prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
6743 depth++;
6745 if(!prs_align(ps))
6746 return False;
6748 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6749 return False;
6751 return True;
6754 /*******************************************************************
6755 inits a SAMR_Q_CONNECT structure.
6756 ********************************************************************/
6758 void init_samr_q_connect(SAMR_Q_CONNECT * q_u,
6759 char *srv_name, uint32 access_mask)
6761 DEBUG(5, ("init_samr_q_connect\n"));
6763 /* make PDC server name \\server */
6764 q_u->ptr_srv_name = (srv_name != NULL && *srv_name) ? 1 : 0;
6765 init_unistr2(&q_u->uni_srv_name, srv_name, UNI_STR_TERMINATE);
6767 /* example values: 0x0000 0002 */
6768 q_u->access_mask = access_mask;
6771 /*******************************************************************
6772 reads or writes a structure.
6773 ********************************************************************/
6775 BOOL samr_io_q_connect(const char *desc, SAMR_Q_CONNECT * q_u,
6776 prs_struct *ps, int depth)
6778 if (q_u == NULL)
6779 return False;
6781 prs_debug(ps, depth, desc, "samr_io_q_connect");
6782 depth++;
6784 if(!prs_align(ps))
6785 return False;
6787 if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6788 return False;
6789 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6790 return False;
6792 if(!prs_align(ps))
6793 return False;
6794 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6795 return False;
6797 return True;
6800 /*******************************************************************
6801 reads or writes a structure.
6802 ********************************************************************/
6804 BOOL samr_io_r_connect(const char *desc, SAMR_R_CONNECT * r_u,
6805 prs_struct *ps, int depth)
6807 if (r_u == NULL)
6808 return False;
6810 prs_debug(ps, depth, desc, "samr_io_r_connect");
6811 depth++;
6813 if(!prs_align(ps))
6814 return False;
6816 if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6817 return False;
6819 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6820 return False;
6822 return True;
6825 /*******************************************************************
6826 inits a SAMR_Q_CONNECT4 structure.
6827 ********************************************************************/
6829 void init_samr_q_connect4(SAMR_Q_CONNECT4 * q_u,
6830 char *srv_name, uint32 access_mask)
6832 DEBUG(5, ("init_samr_q_connect4\n"));
6834 /* make PDC server name \\server */
6835 q_u->ptr_srv_name = (srv_name != NULL && *srv_name) ? 1 : 0;
6836 init_unistr2(&q_u->uni_srv_name, srv_name, UNI_STR_TERMINATE);
6838 /* Only value we've seen, possibly an address type ? */
6839 q_u->unk_0 = 2;
6841 /* example values: 0x0000 0002 */
6842 q_u->access_mask = access_mask;
6845 /*******************************************************************
6846 reads or writes a structure.
6847 ********************************************************************/
6849 BOOL samr_io_q_connect4(const char *desc, SAMR_Q_CONNECT4 * q_u,
6850 prs_struct *ps, int depth)
6852 if (q_u == NULL)
6853 return False;
6855 prs_debug(ps, depth, desc, "samr_io_q_connect4");
6856 depth++;
6858 if(!prs_align(ps))
6859 return False;
6861 if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6862 return False;
6863 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6864 return False;
6866 if(!prs_align(ps))
6867 return False;
6868 if(!prs_uint32("unk_0", ps, depth, &q_u->unk_0))
6869 return False;
6870 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6871 return False;
6873 return True;
6876 /*******************************************************************
6877 reads or writes a structure.
6878 ********************************************************************/
6880 BOOL samr_io_r_connect4(const char *desc, SAMR_R_CONNECT4 * r_u,
6881 prs_struct *ps, int depth)
6883 if (r_u == NULL)
6884 return False;
6886 prs_debug(ps, depth, desc, "samr_io_r_connect4");
6887 depth++;
6889 if(!prs_align(ps))
6890 return False;
6892 if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6893 return False;
6895 if(!prs_ntstatus("status", ps, depth, &r_u->status))
6896 return False;
6898 return True;
6901 /*******************************************************************
6902 inits a SAMR_Q_CONNECT5 structure.
6903 ********************************************************************/
6905 void init_samr_q_connect5(SAMR_Q_CONNECT5 * q_u,
6906 char *srv_name, uint32 access_mask)
6908 DEBUG(5, ("init_samr_q_connect5\n"));
6910 /* make PDC server name \\server */
6911 q_u->ptr_srv_name = (srv_name != NULL && *srv_name) ? 1 : 0;
6912 init_unistr2(&q_u->uni_srv_name, srv_name, UNI_STR_TERMINATE);
6914 /* example values: 0x0000 0002 */
6915 q_u->access_mask = access_mask;
6917 q_u->level = 1;
6918 q_u->info1_unk1 = 3;
6919 q_u->info1_unk2 = 0;
6922 /*******************************************************************
6923 inits a SAMR_R_CONNECT5 structure.
6924 ********************************************************************/
6926 void init_samr_r_connect5(SAMR_R_CONNECT5 * r_u, POLICY_HND *pol, NTSTATUS status)
6928 DEBUG(5, ("init_samr_q_connect5\n"));
6930 r_u->level = 1;
6931 r_u->info1_unk1 = 3;
6932 r_u->info1_unk2 = 0;
6934 r_u->connect_pol = *pol;
6935 r_u->status = status;
6938 /*******************************************************************
6939 reads or writes a structure.
6940 ********************************************************************/
6942 BOOL samr_io_q_connect5(const char *desc, SAMR_Q_CONNECT5 * q_u,
6943 prs_struct *ps, int depth)
6945 if (q_u == NULL)
6946 return False;
6948 prs_debug(ps, depth, desc, "samr_io_q_connect5");
6949 depth++;
6951 if(!prs_align(ps))
6952 return False;
6954 if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6955 return False;
6956 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6957 return False;
6959 if(!prs_align(ps))
6960 return False;
6961 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6962 return False;
6964 if(!prs_uint32("level", ps, depth, &q_u->level))
6965 return False;
6966 if(!prs_uint32("level", ps, depth, &q_u->level))
6967 return False;
6969 if(!prs_uint32("info1_unk1", ps, depth, &q_u->info1_unk1))
6970 return False;
6971 if(!prs_uint32("info1_unk2", ps, depth, &q_u->info1_unk2))
6972 return False;
6974 return True;
6977 /*******************************************************************
6978 reads or writes a structure.
6979 ********************************************************************/
6981 BOOL samr_io_r_connect5(const char *desc, SAMR_R_CONNECT5 * r_u,
6982 prs_struct *ps, int depth)
6984 if (r_u == NULL)
6985 return False;
6987 prs_debug(ps, depth, desc, "samr_io_r_connect5");
6988 depth++;
6990 if(!prs_align(ps))
6991 return False;
6993 if(!prs_uint32("level", ps, depth, &r_u->level))
6994 return False;
6995 if(!prs_uint32("level", ps, depth, &r_u->level))
6996 return False;
6997 if(!prs_uint32("info1_unk1", ps, depth, &r_u->info1_unk1))
6998 return False;
6999 if(!prs_uint32("info1_unk2", ps, depth, &r_u->info1_unk2))
7000 return False;
7002 if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
7003 return False;
7005 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7006 return False;
7008 return True;
7011 /*******************************************************************
7012 inits a SAMR_Q_CONNECT_ANON structure.
7013 ********************************************************************/
7015 void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON * q_u)
7017 DEBUG(5, ("init_samr_q_connect_anon\n"));
7019 q_u->ptr = 1;
7020 q_u->unknown_0 = 0x5c; /* server name (?!!) */
7021 q_u->access_mask = MAXIMUM_ALLOWED_ACCESS;
7024 /*******************************************************************
7025 reads or writes a structure.
7026 ********************************************************************/
7028 BOOL samr_io_q_connect_anon(const char *desc, SAMR_Q_CONNECT_ANON * q_u,
7029 prs_struct *ps, int depth)
7031 if (q_u == NULL)
7032 return False;
7034 prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
7035 depth++;
7037 if(!prs_align(ps))
7038 return False;
7040 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
7041 return False;
7042 if (q_u->ptr) {
7043 if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0))
7044 return False;
7046 if(!prs_align(ps))
7047 return False;
7048 if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
7049 return False;
7051 return True;
7054 /*******************************************************************
7055 reads or writes a structure.
7056 ********************************************************************/
7058 BOOL samr_io_r_connect_anon(const char *desc, SAMR_R_CONNECT_ANON * r_u,
7059 prs_struct *ps, int depth)
7061 if (r_u == NULL)
7062 return False;
7064 prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
7065 depth++;
7067 if(!prs_align(ps))
7068 return False;
7070 if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
7071 return False;
7073 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7074 return False;
7076 return True;
7079 /*******************************************************************
7080 inits a SAMR_Q_GET_DOM_PWINFO structure.
7081 ********************************************************************/
7083 void init_samr_q_get_dom_pwinfo(SAMR_Q_GET_DOM_PWINFO * q_u,
7084 char *srv_name)
7086 DEBUG(5, ("init_samr_q_get_dom_pwinfo\n"));
7088 q_u->ptr = 1;
7089 init_unistr2(&q_u->uni_srv_name, srv_name, UNI_FLAGS_NONE);
7090 init_uni_hdr(&q_u->hdr_srv_name, &q_u->uni_srv_name);
7093 /*******************************************************************
7094 reads or writes a structure.
7095 ********************************************************************/
7097 BOOL samr_io_q_get_dom_pwinfo(const char *desc, SAMR_Q_GET_DOM_PWINFO * q_u,
7098 prs_struct *ps, int depth)
7100 if (q_u == NULL)
7101 return False;
7103 prs_debug(ps, depth, desc, "samr_io_q_get_dom_pwinfo");
7104 depth++;
7106 if(!prs_align(ps))
7107 return False;
7109 if(!prs_uint32("ptr", ps, depth, &q_u->ptr))
7110 return False;
7111 if (q_u->ptr != 0) {
7112 if(!smb_io_unihdr("", &q_u->hdr_srv_name, ps, depth))
7113 return False;
7114 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth))
7115 return False;
7118 return True;
7121 /*******************************************************************
7122 reads or writes a structure.
7123 ********************************************************************/
7125 BOOL samr_io_r_get_dom_pwinfo(const char *desc, SAMR_R_GET_DOM_PWINFO * r_u,
7126 prs_struct *ps, int depth)
7128 if (r_u == NULL)
7129 return False;
7131 prs_debug(ps, depth, desc, "samr_io_r_get_dom_pwinfo");
7132 depth++;
7134 if(!prs_align(ps))
7135 return False;
7137 if(!prs_uint16("min_pwd_length", ps, depth, &r_u->min_pwd_length))
7138 return False;
7139 if(!prs_align(ps))
7140 return False;
7141 if(!prs_uint32("password_properties", ps, depth, &r_u->password_properties))
7142 return False;
7144 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7145 return False;
7147 return True;
7150 /*******************************************************************
7151 make a SAMR_ENC_PASSWD structure.
7152 ********************************************************************/
7154 void init_enc_passwd(SAMR_ENC_PASSWD * pwd, const char pass[512])
7156 ZERO_STRUCTP(pwd);
7158 if (pass == NULL) {
7159 pwd->ptr = 0;
7160 } else {
7161 pwd->ptr = 1;
7162 memcpy(pwd->pass, pass, sizeof(pwd->pass));
7166 /*******************************************************************
7167 reads or writes a SAMR_ENC_PASSWD structure.
7168 ********************************************************************/
7170 BOOL samr_io_enc_passwd(const char *desc, SAMR_ENC_PASSWD * pwd,
7171 prs_struct *ps, int depth)
7173 if (pwd == NULL)
7174 return False;
7176 prs_debug(ps, depth, desc, "samr_io_enc_passwd");
7177 depth++;
7179 if(!prs_align(ps))
7180 return False;
7182 if(!prs_uint32("ptr", ps, depth, &pwd->ptr))
7183 return False;
7185 if (pwd->ptr != 0) {
7186 if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)))
7187 return False;
7190 return True;
7193 /*******************************************************************
7194 inits a SAMR_ENC_HASH structure.
7195 ********************************************************************/
7197 void init_enc_hash(SAMR_ENC_HASH * hsh, const uchar hash[16])
7199 ZERO_STRUCTP(hsh);
7201 if (hash == NULL) {
7202 hsh->ptr = 0;
7203 } else {
7204 hsh->ptr = 1;
7205 memcpy(hsh->hash, hash, sizeof(hsh->hash));
7209 /*******************************************************************
7210 reads or writes a SAMR_ENC_HASH structure.
7211 ********************************************************************/
7213 BOOL samr_io_enc_hash(const char *desc, SAMR_ENC_HASH * hsh,
7214 prs_struct *ps, int depth)
7216 if (hsh == NULL)
7217 return False;
7219 prs_debug(ps, depth, desc, "samr_io_enc_hash");
7220 depth++;
7222 if(!prs_align(ps))
7223 return False;
7225 if(!prs_uint32("ptr ", ps, depth, &hsh->ptr))
7226 return False;
7227 if (hsh->ptr != 0) {
7228 if(!prs_uint8s(False, "hash", ps, depth, hsh->hash,sizeof(hsh->hash)))
7229 return False;
7232 return True;
7235 /*******************************************************************
7236 inits a SAMR_Q_CHGPASSWD_USER structure.
7237 ********************************************************************/
7239 void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u,
7240 const char *dest_host, const char *user_name,
7241 const uchar nt_newpass[516],
7242 const uchar nt_oldhash[16],
7243 const uchar lm_newpass[516],
7244 const uchar lm_oldhash[16])
7246 DEBUG(5, ("init_samr_q_chgpasswd_user\n"));
7248 q_u->ptr_0 = 1;
7249 init_unistr2(&q_u->uni_dest_host, dest_host, UNI_FLAGS_NONE);
7250 init_uni_hdr(&q_u->hdr_dest_host, &q_u->uni_dest_host);
7252 init_unistr2(&q_u->uni_user_name, user_name, UNI_FLAGS_NONE);
7253 init_uni_hdr(&q_u->hdr_user_name, &q_u->uni_user_name);
7255 init_enc_passwd(&q_u->nt_newpass, (const char *)nt_newpass);
7256 init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
7258 q_u->unknown = 0x01;
7260 init_enc_passwd(&q_u->lm_newpass, (const char *)lm_newpass);
7261 init_enc_hash(&q_u->lm_oldhash, lm_oldhash);
7264 /*******************************************************************
7265 reads or writes a structure.
7266 ********************************************************************/
7268 BOOL samr_io_q_chgpasswd_user(const char *desc, SAMR_Q_CHGPASSWD_USER * q_u,
7269 prs_struct *ps, int depth)
7271 if (q_u == NULL)
7272 return False;
7274 prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user");
7275 depth++;
7277 if(!prs_align(ps))
7278 return False;
7280 if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
7281 return False;
7283 if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth))
7284 return False;
7285 if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
7286 return False;
7288 if(!prs_align(ps))
7289 return False;
7290 if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth))
7291 return False;
7292 if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth))
7293 return False;
7295 if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
7296 return False;
7297 if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth))
7298 return False;
7300 if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
7301 return False;
7303 if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
7304 return False;
7305 if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
7306 return False;
7308 return True;
7311 /*******************************************************************
7312 inits a SAMR_R_CHGPASSWD_USER structure.
7313 ********************************************************************/
7315 void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER * r_u, NTSTATUS status)
7317 DEBUG(5, ("init_samr_r_chgpasswd_user\n"));
7319 r_u->status = status;
7322 /*******************************************************************
7323 reads or writes a structure.
7324 ********************************************************************/
7326 BOOL samr_io_r_chgpasswd_user(const char *desc, SAMR_R_CHGPASSWD_USER * r_u,
7327 prs_struct *ps, int depth)
7329 if (r_u == NULL)
7330 return False;
7332 prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user");
7333 depth++;
7335 if(!prs_align(ps))
7336 return False;
7338 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7339 return False;
7341 return True;
7344 /*******************************************************************
7345 inits a SAMR_Q_CHGPASSWD3 structure.
7346 ********************************************************************/
7348 void init_samr_q_chgpasswd_user3(SAMR_Q_CHGPASSWD_USER3 * q_u,
7349 const char *dest_host, const char *user_name,
7350 const uchar nt_newpass[516],
7351 const uchar nt_oldhash[16],
7352 const uchar lm_newpass[516],
7353 const uchar lm_oldhash[16])
7355 DEBUG(5, ("init_samr_q_chgpasswd_user3\n"));
7357 q_u->ptr_0 = 1;
7358 init_unistr2(&q_u->uni_dest_host, dest_host, UNI_FLAGS_NONE);
7359 init_uni_hdr(&q_u->hdr_dest_host, &q_u->uni_dest_host);
7361 init_unistr2(&q_u->uni_user_name, user_name, UNI_FLAGS_NONE);
7362 init_uni_hdr(&q_u->hdr_user_name, &q_u->uni_user_name);
7364 init_enc_passwd(&q_u->nt_newpass, (const char *)nt_newpass);
7365 init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
7367 q_u->lm_change = 0x01;
7369 init_enc_passwd(&q_u->lm_newpass, (const char *)lm_newpass);
7370 init_enc_hash(&q_u->lm_oldhash, lm_oldhash);
7372 init_enc_passwd(&q_u->password3, NULL);
7375 /*******************************************************************
7376 reads or writes a structure.
7377 ********************************************************************/
7379 BOOL samr_io_q_chgpasswd_user3(const char *desc, SAMR_Q_CHGPASSWD_USER3 * q_u,
7380 prs_struct *ps, int depth)
7382 if (q_u == NULL)
7383 return False;
7385 prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user3");
7386 depth++;
7388 if(!prs_align(ps))
7389 return False;
7391 if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
7392 return False;
7394 if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth))
7395 return False;
7396 if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
7397 return False;
7399 if(!prs_align(ps))
7400 return False;
7401 if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth))
7402 return False;
7403 if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth))
7404 return False;
7406 if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
7407 return False;
7408 if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth))
7409 return False;
7411 if(!prs_uint32("lm_change", ps, depth, &q_u->lm_change))
7412 return False;
7414 if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
7415 return False;
7416 if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
7417 return False;
7419 if(!samr_io_enc_passwd("password3", &q_u->password3, ps, depth))
7420 return False;
7422 return True;
7425 /*******************************************************************
7426 inits a SAMR_R_CHGPASSWD_USER3 structure.
7427 ********************************************************************/
7429 void init_samr_r_chgpasswd_user3(SAMR_R_CHGPASSWD_USER3 *r_u, NTSTATUS status,
7430 SAMR_CHANGE_REJECT *reject, SAM_UNK_INFO_1 *info)
7432 DEBUG(5, ("init_samr_r_chgpasswd_user3\n"));
7434 r_u->status = status;
7435 r_u->info = 0;
7436 r_u->ptr_info = 0;
7437 r_u->reject = 0;
7438 r_u->ptr_reject = 0;
7440 if (info) {
7441 r_u->info = info;
7442 r_u->ptr_info = 1;
7444 if (reject && (reject->reject_reason != Undefined)) {
7445 r_u->reject = reject;
7446 r_u->ptr_reject = 1;
7450 /*******************************************************************
7451 Reads or writes an SAMR_CHANGE_REJECT structure.
7452 ********************************************************************/
7454 BOOL samr_io_change_reject(const char *desc, SAMR_CHANGE_REJECT *reject, prs_struct *ps, int depth)
7456 if (reject == NULL)
7457 return False;
7459 prs_debug(ps, depth, desc, "samr_io_change_reject");
7460 depth++;
7462 if(!prs_align(ps))
7463 return False;
7465 if(UNMARSHALLING(ps))
7466 ZERO_STRUCTP(reject);
7468 if (!prs_uint32("reject_reason", ps, depth, &reject->reject_reason))
7469 return False;
7471 if (!prs_uint32("unknown1", ps, depth, &reject->unknown1))
7472 return False;
7474 if (!prs_uint32("unknown2", ps, depth, &reject->unknown2))
7475 return False;
7477 return True;
7480 /*******************************************************************
7481 reads or writes a structure.
7482 ********************************************************************/
7484 BOOL samr_io_r_chgpasswd_user3(const char *desc, SAMR_R_CHGPASSWD_USER3 *r_u,
7485 prs_struct *ps, int depth)
7487 if (r_u == NULL)
7488 return False;
7490 prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user3");
7491 depth++;
7493 if (!prs_align(ps))
7494 return False;
7496 if (!prs_uint32("ptr_info", ps, depth, &r_u->ptr_info))
7497 return False;
7499 if (r_u->ptr_info && r_u->info != NULL) {
7500 /* SAM_UNK_INFO_1 */
7501 if (!sam_io_unk_info1("info", r_u->info, ps, depth))
7502 return False;
7505 if (!prs_uint32("ptr_reject", ps, depth, &r_u->ptr_reject))
7506 return False;
7508 if (r_u->ptr_reject && r_u->reject != NULL) {
7509 /* SAMR_CHANGE_REJECT */
7510 if (!samr_io_change_reject("reject", r_u->reject, ps, depth))
7511 return False;
7514 if (!prs_ntstatus("status", ps, depth, &r_u->status))
7515 return False;
7517 return True;
7520 /*******************************************************************
7521 reads or writes a structure.
7522 ********************************************************************/
7524 void init_samr_q_query_domain_info2(SAMR_Q_QUERY_DOMAIN_INFO2 *q_u,
7525 POLICY_HND *domain_pol, uint16 switch_value)
7527 DEBUG(5, ("init_samr_q_query_domain_info2\n"));
7529 q_u->domain_pol = *domain_pol;
7530 q_u->switch_value = switch_value;
7533 /*******************************************************************
7534 reads or writes a structure.
7535 ********************************************************************/
7537 BOOL samr_io_q_query_domain_info2(const char *desc, SAMR_Q_QUERY_DOMAIN_INFO2 *q_u,
7538 prs_struct *ps, int depth)
7540 if (q_u == NULL)
7541 return False;
7543 prs_debug(ps, depth, desc, "samr_io_q_query_domain_info2");
7544 depth++;
7546 if(!prs_align(ps))
7547 return False;
7549 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7550 return False;
7552 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7553 return False;
7555 return True;
7558 /*******************************************************************
7559 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7560 ********************************************************************/
7562 void init_samr_r_samr_query_domain_info2(SAMR_R_QUERY_DOMAIN_INFO2 * r_u,
7563 uint16 switch_value, SAM_UNK_CTR * ctr,
7564 NTSTATUS status)
7566 DEBUG(5, ("init_samr_r_samr_query_domain_info2\n"));
7568 r_u->ptr_0 = 0;
7569 r_u->switch_value = 0;
7570 r_u->status = status; /* return status */
7572 if (NT_STATUS_IS_OK(status)) {
7573 r_u->switch_value = switch_value;
7574 r_u->ptr_0 = 1;
7575 r_u->ctr = ctr;
7579 /*******************************************************************
7580 reads or writes a structure.
7581 ********************************************************************/
7583 BOOL samr_io_r_samr_query_domain_info2(const char *desc, SAMR_R_QUERY_DOMAIN_INFO2 * r_u,
7584 prs_struct *ps, int depth)
7586 if (r_u == NULL)
7587 return False;
7589 prs_debug(ps, depth, desc, "samr_io_r_samr_query_domain_info2");
7590 depth++;
7592 if(!prs_align(ps))
7593 return False;
7595 if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
7596 return False;
7598 if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
7599 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
7600 return False;
7601 if(!prs_align(ps))
7602 return False;
7604 switch (r_u->switch_value) {
7605 case 0x0c:
7606 if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
7607 return False;
7608 break;
7609 case 0x07:
7610 if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
7611 return False;
7612 break;
7613 case 0x06:
7614 if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
7615 return False;
7616 break;
7617 case 0x05:
7618 if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
7619 return False;
7620 break;
7621 case 0x03:
7622 if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
7623 return False;
7624 break;
7625 case 0x02:
7626 if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
7627 return False;
7628 break;
7629 case 0x01:
7630 if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
7631 return False;
7632 break;
7633 default:
7634 DEBUG(0, ("samr_io_r_samr_query_domain_info2: unknown switch level 0x%x\n",
7635 r_u->switch_value));
7636 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
7637 return False;
7641 if(!prs_align(ps))
7642 return False;
7644 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7645 return False;
7647 return True;
7651 /*******************************************************************
7652 reads or writes a structure.
7653 ********************************************************************/
7655 void init_samr_q_set_domain_info(SAMR_Q_SET_DOMAIN_INFO *q_u,
7656 POLICY_HND *domain_pol, uint16 switch_value, SAM_UNK_CTR *ctr)
7658 DEBUG(5, ("init_samr_q_set_domain_info\n"));
7660 q_u->domain_pol = *domain_pol;
7661 q_u->switch_value0 = switch_value;
7663 q_u->switch_value = switch_value;
7664 q_u->ctr = ctr;
7668 /*******************************************************************
7669 reads or writes a structure.
7670 ********************************************************************/
7672 BOOL samr_io_q_set_domain_info(const char *desc, SAMR_Q_SET_DOMAIN_INFO *q_u,
7673 prs_struct *ps, int depth)
7675 if (q_u == NULL)
7676 return False;
7678 prs_debug(ps, depth, desc, "samr_io_q_set_domain_info");
7679 depth++;
7681 if(!prs_align(ps))
7682 return False;
7684 if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7685 return False;
7687 if(!prs_uint16("switch_value0", ps, depth, &q_u->switch_value0))
7688 return False;
7690 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7691 return False;
7693 if(!prs_align(ps))
7694 return False;
7696 if (UNMARSHALLING(ps)) {
7697 if ((q_u->ctr = PRS_ALLOC_MEM(ps, SAM_UNK_CTR, 1)) == NULL)
7698 return False;
7701 switch (q_u->switch_value) {
7703 case 0x0c:
7704 if(!sam_io_unk_info12("unk_inf12", &q_u->ctr->info.inf12, ps, depth))
7705 return False;
7706 break;
7707 case 0x07:
7708 if(!sam_io_unk_info7("unk_inf7",&q_u->ctr->info.inf7, ps,depth))
7709 return False;
7710 break;
7711 case 0x06:
7712 if(!sam_io_unk_info6("unk_inf6",&q_u->ctr->info.inf6, ps,depth))
7713 return False;
7714 break;
7715 case 0x05:
7716 if(!sam_io_unk_info5("unk_inf5",&q_u->ctr->info.inf5, ps,depth))
7717 return False;
7718 break;
7719 case 0x03:
7720 if(!sam_io_unk_info3("unk_inf3",&q_u->ctr->info.inf3, ps,depth))
7721 return False;
7722 break;
7723 case 0x02:
7724 if(!sam_io_unk_info2("unk_inf2",&q_u->ctr->info.inf2, ps,depth))
7725 return False;
7726 break;
7727 case 0x01:
7728 if(!sam_io_unk_info1("unk_inf1",&q_u->ctr->info.inf1, ps,depth))
7729 return False;
7730 break;
7731 default:
7732 DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7733 q_u->switch_value));
7734 return False;
7737 return True;
7740 /*******************************************************************
7741 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7742 ********************************************************************/
7744 void init_samr_r_set_domain_info(SAMR_R_SET_DOMAIN_INFO * r_u, NTSTATUS status)
7746 DEBUG(5, ("init_samr_r_set_domain_info\n"));
7748 r_u->status = status; /* return status */
7751 /*******************************************************************
7752 reads or writes a structure.
7753 ********************************************************************/
7755 BOOL samr_io_r_set_domain_info(const char *desc, SAMR_R_SET_DOMAIN_INFO * r_u,
7756 prs_struct *ps, int depth)
7758 if (r_u == NULL)
7759 return False;
7761 prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7762 depth++;
7764 if(!prs_align(ps))
7765 return False;
7767 if(!prs_ntstatus("status", ps, depth, &r_u->status))
7768 return False;
7770 return True;