Remove unused marshalling for SAMR_QUERY_ALIAS_INFO.
[Samba/gebeck_regimport.git] / source / rpc_parse / parse_samr.c
blob436e284fd5d1dc256b5d09c2b8689989d1885e1b
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 3 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, see <http://www.gnu.org/licenses/>.
26 #include "includes.h"
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_PARSE
31 /*******************************************************************
32 inits a structure.
33 ********************************************************************/
35 static void init_lsa_String(struct lsa_String *name, const char *s)
37 name->string = s;
40 /*******************************************************************
41 inits a structure.
42 ********************************************************************/
44 void init_samr_DomInfo1(struct samr_DomInfo1 *r,
45 uint16_t min_password_length,
46 uint16_t password_history_length,
47 uint32_t password_properties,
48 int64_t max_password_age,
49 int64_t min_password_age)
51 r->min_password_length = min_password_length;
52 r->password_history_length = password_history_length;
53 r->password_properties = password_properties;
54 r->max_password_age = max_password_age;
55 r->min_password_age = min_password_age;
58 /*******************************************************************
59 inits a structure.
60 ********************************************************************/
62 void init_samr_DomInfo2(struct samr_DomInfo2 *r,
63 NTTIME force_logoff_time,
64 const char *comment,
65 const char *domain_name,
66 const char *primary,
67 uint64_t sequence_num,
68 uint32_t unknown2,
69 enum samr_Role role,
70 uint32_t unknown3,
71 uint32_t num_users,
72 uint32_t num_groups,
73 uint32_t num_aliases)
75 r->force_logoff_time = force_logoff_time;
76 init_lsa_String(&r->comment, comment);
77 init_lsa_String(&r->domain_name, domain_name);
78 init_lsa_String(&r->primary, primary);
79 r->sequence_num = sequence_num;
80 r->unknown2 = unknown2;
81 r->role = role;
82 r->unknown3 = unknown3;
83 r->num_users = num_users;
84 r->num_groups = num_groups;
85 r->num_aliases = num_aliases;
88 /*******************************************************************
89 inits a structure.
90 ********************************************************************/
92 void init_samr_DomInfo3(struct samr_DomInfo3 *r,
93 NTTIME force_logoff_time)
95 r->force_logoff_time = force_logoff_time;
98 /*******************************************************************
99 inits a structure.
100 ********************************************************************/
102 void init_samr_DomInfo4(struct samr_DomInfo4 *r,
103 const char *comment)
105 init_lsa_String(&r->comment, comment);
108 /*******************************************************************
109 inits a structure.
110 ********************************************************************/
112 void init_samr_DomInfo5(struct samr_DomInfo5 *r,
113 const char *domain_name)
115 init_lsa_String(&r->domain_name, domain_name);
118 /*******************************************************************
119 inits a structure.
120 ********************************************************************/
122 void init_samr_DomInfo6(struct samr_DomInfo6 *r,
123 const char *primary)
125 init_lsa_String(&r->primary, primary);
128 /*******************************************************************
129 inits a structure.
130 ********************************************************************/
132 void init_samr_DomInfo7(struct samr_DomInfo7 *r,
133 enum samr_Role role)
135 r->role = role;
138 /*******************************************************************
139 inits a structure.
140 ********************************************************************/
142 void init_samr_DomInfo8(struct samr_DomInfo8 *r,
143 uint64_t sequence_num,
144 NTTIME domain_create_time)
146 r->sequence_num = sequence_num;
147 r->domain_create_time = domain_create_time;
150 /*******************************************************************
151 inits a structure.
152 ********************************************************************/
154 void init_samr_DomInfo9(struct samr_DomInfo9 *r,
155 uint32_t unknown)
157 r->unknown = unknown;
160 /*******************************************************************
161 inits a structure.
162 ********************************************************************/
164 void init_samr_DomInfo12(struct samr_DomInfo12 *r,
165 uint64_t lockout_duration,
166 uint64_t lockout_window,
167 uint16_t lockout_threshold)
169 r->lockout_duration = lockout_duration;
170 r->lockout_window = lockout_window;
171 r->lockout_threshold = lockout_threshold;
174 /*******************************************************************
175 reads or writes a SAM_STR1 structure.
176 ********************************************************************/
178 static bool sam_io_sam_str1(const char *desc, SAM_STR1 * sam, uint32 acct_buf,
179 uint32 name_buf, uint32 desc_buf,
180 prs_struct *ps, int depth)
182 if (sam == NULL)
183 return False;
185 prs_debug(ps, depth, desc, "sam_io_sam_str1");
186 depth++;
188 if(!prs_align(ps))
189 return False;
190 if (!smb_io_unistr2("name", &sam->uni_acct_name, acct_buf, ps, depth))
191 return False;
193 if (!smb_io_unistr2("desc", &sam->uni_acct_desc, desc_buf, ps, depth))
194 return False;
196 if (!smb_io_unistr2("full", &sam->uni_full_name, name_buf, ps, depth))
197 return False;
199 return True;
202 /*******************************************************************
203 inits a SAM_ENTRY1 structure.
204 ********************************************************************/
206 static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx,
207 UNISTR2 *sam_name, UNISTR2 *sam_full,
208 UNISTR2 *sam_desc, uint32 rid_user,
209 uint32 acb_info)
211 DEBUG(5, ("init_sam_entry1\n"));
213 ZERO_STRUCTP(sam);
215 sam->user_idx = user_idx;
216 sam->rid_user = rid_user;
217 sam->acb_info = acb_info;
219 init_uni_hdr(&sam->hdr_acct_name, sam_name);
220 init_uni_hdr(&sam->hdr_user_name, sam_full);
221 init_uni_hdr(&sam->hdr_user_desc, sam_desc);
224 /*******************************************************************
225 reads or writes a SAM_ENTRY1 structure.
226 ********************************************************************/
228 static bool sam_io_sam_entry1(const char *desc, SAM_ENTRY1 * sam,
229 prs_struct *ps, int depth)
231 if (sam == NULL)
232 return False;
234 prs_debug(ps, depth, desc, "sam_io_sam_entry1");
235 depth++;
237 if(!prs_align(ps))
238 return False;
240 if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
241 return False;
243 if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
244 return False;
245 if(!prs_uint32("acb_info ", ps, depth, &sam->acb_info))
246 return False;
248 if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
249 return False;
250 if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
251 return False;
252 if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
253 return False;
255 return True;
258 /*******************************************************************
259 reads or writes a SAM_STR2 structure.
260 ********************************************************************/
262 static bool sam_io_sam_str2(const char *desc, SAM_STR2 * sam, uint32 acct_buf,
263 uint32 desc_buf, prs_struct *ps, int depth)
265 if (sam == NULL)
266 return False;
268 prs_debug(ps, depth, desc, "sam_io_sam_str2");
269 depth++;
271 if(!prs_align(ps))
272 return False;
274 if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
275 return False;
276 if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth)) /* account desc unicode string */
277 return False;
279 return True;
282 /*******************************************************************
283 inits a SAM_ENTRY2 structure.
284 ********************************************************************/
285 static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
286 UNISTR2 *sam_name, UNISTR2 *sam_desc,
287 uint32 rid_user, uint32 acb_info)
289 DEBUG(5, ("init_sam_entry2\n"));
291 sam->user_idx = user_idx;
292 sam->rid_user = rid_user;
293 sam->acb_info = acb_info;
295 init_uni_hdr(&sam->hdr_srv_name, sam_name);
296 init_uni_hdr(&sam->hdr_srv_desc, sam_desc);
299 /*******************************************************************
300 reads or writes a SAM_ENTRY2 structure.
301 ********************************************************************/
303 static bool sam_io_sam_entry2(const char *desc, SAM_ENTRY2 * sam,
304 prs_struct *ps, int depth)
306 if (sam == NULL)
307 return False;
309 prs_debug(ps, depth, desc, "sam_io_sam_entry2");
310 depth++;
312 if(!prs_align(ps))
313 return False;
315 if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
316 return False;
318 if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
319 return False;
320 if(!prs_uint32("acb_info ", ps, depth, &sam->acb_info))
321 return False;
323 if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth)) /* account name unicode string header */
324 return False;
325 if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth)) /* account name unicode string header */
326 return False;
328 return True;
331 /*******************************************************************
332 reads or writes a SAM_STR3 structure.
333 ********************************************************************/
335 static bool sam_io_sam_str3(const char *desc, SAM_STR3 * sam, uint32 acct_buf,
336 uint32 desc_buf, prs_struct *ps, int depth)
338 if (sam == NULL)
339 return False;
341 prs_debug(ps, depth, desc, "sam_io_sam_str3");
342 depth++;
344 if(!prs_align(ps))
345 return False;
347 if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth)) /* account name unicode string */
348 return False;
349 if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth)) /* account desc unicode string */
350 return False;
352 return True;
355 /*******************************************************************
356 inits a SAM_ENTRY3 structure.
357 ********************************************************************/
359 static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
360 UNISTR2 *grp_name, UNISTR2 *grp_desc,
361 uint32 rid_grp)
363 DEBUG(5, ("init_sam_entry3\n"));
365 sam->grp_idx = grp_idx;
366 sam->rid_grp = rid_grp;
367 sam->attr = 0x07; /* group rid attributes - gets ignored by nt 4.0 */
369 init_uni_hdr(&sam->hdr_grp_name, grp_name);
370 init_uni_hdr(&sam->hdr_grp_desc, grp_desc);
373 /*******************************************************************
374 reads or writes a SAM_ENTRY3 structure.
375 ********************************************************************/
377 static bool sam_io_sam_entry3(const char *desc, SAM_ENTRY3 * sam,
378 prs_struct *ps, int depth)
380 if (sam == NULL)
381 return False;
383 prs_debug(ps, depth, desc, "sam_io_sam_entry3");
384 depth++;
386 if(!prs_align(ps))
387 return False;
389 if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
390 return False;
392 if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp))
393 return False;
394 if(!prs_uint32("attr ", ps, depth, &sam->attr))
395 return False;
397 if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth)) /* account name unicode string header */
398 return False;
399 if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth)) /* account name unicode string header */
400 return False;
402 return True;
405 /*******************************************************************
406 inits a SAM_ENTRY4 structure.
407 ********************************************************************/
409 static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
410 uint32 len_acct_name)
412 DEBUG(5, ("init_sam_entry4\n"));
414 sam->user_idx = user_idx;
415 init_str_hdr(&sam->hdr_acct_name, len_acct_name+1, len_acct_name, len_acct_name != 0);
418 /*******************************************************************
419 reads or writes a SAM_ENTRY4 structure.
420 ********************************************************************/
422 static bool sam_io_sam_entry4(const char *desc, SAM_ENTRY4 * sam,
423 prs_struct *ps, int depth)
425 if (sam == NULL)
426 return False;
428 prs_debug(ps, depth, desc, "sam_io_sam_entry4");
429 depth++;
431 if(!prs_align(ps))
432 return False;
434 if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
435 return False;
436 if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
437 return False;
439 return True;
442 /*******************************************************************
443 inits a SAM_ENTRY5 structure.
444 ********************************************************************/
446 static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
447 uint32 len_grp_name)
449 DEBUG(5, ("init_sam_entry5\n"));
451 sam->grp_idx = grp_idx;
452 init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
453 len_grp_name != 0);
456 /*******************************************************************
457 reads or writes a SAM_ENTRY5 structure.
458 ********************************************************************/
460 static bool sam_io_sam_entry5(const char *desc, SAM_ENTRY5 * sam,
461 prs_struct *ps, int depth)
463 if (sam == NULL)
464 return False;
466 prs_debug(ps, depth, desc, "sam_io_sam_entry5");
467 depth++;
469 if(!prs_align(ps))
470 return False;
472 if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
473 return False;
474 if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
475 return False;
477 return True;
480 /*******************************************************************
481 inits a SAM_ENTRY structure.
482 ********************************************************************/
484 void init_sam_entry(SAM_ENTRY *sam, UNISTR2 *uni2, uint32 rid)
486 DEBUG(10, ("init_sam_entry: %d\n", rid));
488 sam->rid = rid;
489 init_uni_hdr(&sam->hdr_name, uni2);
492 /*******************************************************************
493 reads or writes a SAM_ENTRY structure.
494 ********************************************************************/
496 static bool sam_io_sam_entry(const char *desc, SAM_ENTRY * sam,
497 prs_struct *ps, int depth)
499 if (sam == NULL)
500 return False;
502 prs_debug(ps, depth, desc, "sam_io_sam_entry");
503 depth++;
505 if(!prs_align(ps))
506 return False;
507 if(!prs_uint32("rid", ps, depth, &sam->rid))
508 return False;
509 if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
510 return False;
512 return True;
515 /*******************************************************************
516 inits a SAMR_Q_ENUM_DOM_USERS structure.
517 ********************************************************************/
519 void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
520 uint32 start_idx,
521 uint32 acb_mask, uint32 size)
523 DEBUG(5, ("init_samr_q_enum_dom_users\n"));
525 q_e->pol = *pol;
527 q_e->start_idx = start_idx; /* zero indicates lots */
528 q_e->acb_mask = acb_mask;
529 q_e->max_size = size;
532 /*******************************************************************
533 reads or writes a structure.
534 ********************************************************************/
536 bool samr_io_q_enum_dom_users(const char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
537 prs_struct *ps, int depth)
539 if (q_e == NULL)
540 return False;
542 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
543 depth++;
545 if(!prs_align(ps))
546 return False;
548 if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
549 return False;
551 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
552 return False;
553 if(!prs_uint32("acb_mask ", ps, depth, &q_e->acb_mask))
554 return False;
556 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
557 return False;
559 return True;
563 /*******************************************************************
564 inits a SAMR_R_ENUM_DOM_USERS structure.
565 ********************************************************************/
567 void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
568 uint32 next_idx, uint32 num_sam_entries)
570 DEBUG(5, ("init_samr_r_enum_dom_users\n"));
572 r_u->next_idx = next_idx;
574 if (num_sam_entries != 0) {
575 r_u->ptr_entries1 = 1;
576 r_u->ptr_entries2 = 1;
577 r_u->num_entries2 = num_sam_entries;
578 r_u->num_entries3 = num_sam_entries;
580 r_u->num_entries4 = num_sam_entries;
581 } else {
582 r_u->ptr_entries1 = 0;
583 r_u->num_entries2 = num_sam_entries;
584 r_u->ptr_entries2 = 1;
588 /*******************************************************************
589 reads or writes a structure.
590 ********************************************************************/
592 bool samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
593 prs_struct *ps, int depth)
595 uint32 i;
597 if (r_u == NULL)
598 return False;
600 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
601 depth++;
603 if(!prs_align(ps))
604 return False;
606 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
607 return False;
608 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
609 return False;
611 if (r_u->ptr_entries1 != 0) {
612 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
613 return False;
614 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
615 return False;
616 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
617 return False;
619 if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
620 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
621 r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
624 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
625 DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
626 r_u->num_entries4 = 0;
627 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
628 return False;
631 for (i = 0; i < r_u->num_entries2; i++) {
632 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
633 return False;
636 for (i = 0; i < r_u->num_entries2; i++) {
637 if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
638 return False;
643 if(!prs_align(ps))
644 return False;
646 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
647 return False;
648 if(!prs_ntstatus("status", ps, depth, &r_u->status))
649 return False;
651 return True;
654 /*******************************************************************
655 inits a SAMR_Q_QUERY_DISPINFO structure.
656 ********************************************************************/
658 void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
659 uint16 switch_level, uint32 start_idx,
660 uint32 max_entries, uint32 max_size)
662 DEBUG(5, ("init_samr_q_query_dispinfo\n"));
664 q_e->domain_pol = *pol;
666 q_e->switch_level = switch_level;
668 q_e->start_idx = start_idx;
669 q_e->max_entries = max_entries;
670 q_e->max_size = max_size;
673 /*******************************************************************
674 reads or writes a structure.
675 ********************************************************************/
677 bool samr_io_q_query_dispinfo(const char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
678 prs_struct *ps, int depth)
680 if (q_e == NULL)
681 return False;
683 prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
684 depth++;
686 if(!prs_align(ps))
687 return False;
689 if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
690 return False;
692 if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
693 return False;
694 if(!prs_align(ps))
695 return False;
697 if(!prs_uint32("start_idx ", ps, depth, &q_e->start_idx))
698 return False;
699 if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
700 return False;
701 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
702 return False;
704 return True;
707 /*******************************************************************
708 inits a SAM_DISPINFO_1 structure.
709 ********************************************************************/
711 NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 **sam,
712 uint32 num_entries, uint32 start_idx,
713 struct samr_displayentry *entries)
715 uint32 i;
717 DEBUG(10, ("init_sam_dispinfo_1: num_entries: %d\n", num_entries));
719 if (num_entries==0)
720 return NT_STATUS_OK;
722 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_1, num_entries);
723 if (*sam == NULL)
724 return NT_STATUS_NO_MEMORY;
726 (*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
727 if ((*sam)->sam == NULL)
728 return NT_STATUS_NO_MEMORY;
730 (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
731 if ((*sam)->str == NULL)
732 return NT_STATUS_NO_MEMORY;
734 for (i = 0; i < num_entries ; i++) {
735 init_unistr2(&(*sam)->str[i].uni_acct_name,
736 entries[i].account_name, UNI_FLAGS_NONE);
737 init_unistr2(&(*sam)->str[i].uni_full_name,
738 entries[i].fullname, UNI_FLAGS_NONE);
739 init_unistr2(&(*sam)->str[i].uni_acct_desc,
740 entries[i].description, UNI_FLAGS_NONE);
742 init_sam_entry1(&(*sam)->sam[i], start_idx+i+1,
743 &(*sam)->str[i].uni_acct_name,
744 &(*sam)->str[i].uni_full_name,
745 &(*sam)->str[i].uni_acct_desc,
746 entries[i].rid, entries[i].acct_flags);
749 return NT_STATUS_OK;
752 /*******************************************************************
753 reads or writes a structure.
754 ********************************************************************/
756 static bool sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
757 uint32 num_entries,
758 prs_struct *ps, int depth)
760 uint32 i;
762 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
763 depth++;
765 if(!prs_align(ps))
766 return False;
768 if (UNMARSHALLING(ps) && num_entries > 0) {
770 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
771 DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
772 return False;
775 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
776 DEBUG(0, ("out of memory allocating SAM_STR1\n"));
777 return False;
781 for (i = 0; i < num_entries; i++) {
782 if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
783 return False;
786 for (i = 0; i < num_entries; i++) {
787 if(!sam_io_sam_str1("", &sam->str[i],
788 sam->sam[i].hdr_acct_name.buffer,
789 sam->sam[i].hdr_user_name.buffer,
790 sam->sam[i].hdr_user_desc.buffer, ps, depth))
791 return False;
794 return True;
797 /*******************************************************************
798 inits a SAM_DISPINFO_2 structure.
799 ********************************************************************/
801 NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 **sam,
802 uint32 num_entries, uint32 start_idx,
803 struct samr_displayentry *entries)
805 uint32 i;
807 DEBUG(10, ("init_sam_dispinfo_2: num_entries: %d\n", num_entries));
809 if (num_entries==0)
810 return NT_STATUS_OK;
812 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_2, num_entries);
813 if (*sam == NULL)
814 return NT_STATUS_NO_MEMORY;
816 (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries);
817 if ((*sam)->sam == NULL)
818 return NT_STATUS_NO_MEMORY;
820 (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries);
821 if ((*sam)->str == NULL)
822 return NT_STATUS_NO_MEMORY;
824 for (i = 0; i < num_entries; i++) {
825 init_unistr2(&(*sam)->str[i].uni_srv_name,
826 entries[i].account_name, UNI_FLAGS_NONE);
827 init_unistr2(&(*sam)->str[i].uni_srv_desc,
828 entries[i].description, UNI_FLAGS_NONE);
830 init_sam_entry2(&(*sam)->sam[i], start_idx + i + 1,
831 &(*sam)->str[i].uni_srv_name,
832 &(*sam)->str[i].uni_srv_desc,
833 entries[i].rid, entries[i].acct_flags);
836 return NT_STATUS_OK;
839 /*******************************************************************
840 reads or writes a structure.
841 ********************************************************************/
843 static bool sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
844 uint32 num_entries,
845 prs_struct *ps, int depth)
847 uint32 i;
849 if (sam == NULL)
850 return False;
852 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
853 depth++;
855 if(!prs_align(ps))
856 return False;
858 if (UNMARSHALLING(ps) && num_entries > 0) {
860 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
861 DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
862 return False;
865 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
866 DEBUG(0, ("out of memory allocating SAM_STR2\n"));
867 return False;
871 for (i = 0; i < num_entries; i++) {
872 if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
873 return False;
876 for (i = 0; i < num_entries; i++) {
877 if(!sam_io_sam_str2("", &sam->str[i],
878 sam->sam[i].hdr_srv_name.buffer,
879 sam->sam[i].hdr_srv_desc.buffer, ps, depth))
880 return False;
883 return True;
886 /*******************************************************************
887 inits a SAM_DISPINFO_3 structure.
888 ********************************************************************/
890 NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 **sam,
891 uint32 num_entries, uint32 start_idx,
892 struct samr_displayentry *entries)
894 uint32 i;
896 DEBUG(5, ("init_sam_dispinfo_3: num_entries: %d\n", num_entries));
898 if (num_entries==0)
899 return NT_STATUS_OK;
901 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_3, num_entries);
902 if (*sam == NULL)
903 return NT_STATUS_NO_MEMORY;
905 if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
906 return NT_STATUS_NO_MEMORY;
908 if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
909 return NT_STATUS_NO_MEMORY;
911 for (i = 0; i < num_entries; i++) {
912 DEBUG(11, ("init_sam_dispinfo_3: entry: %d\n",i));
914 init_unistr2(&(*sam)->str[i].uni_grp_name,
915 entries[i].account_name, UNI_FLAGS_NONE);
916 init_unistr2(&(*sam)->str[i].uni_grp_desc,
917 entries[i].description, UNI_FLAGS_NONE);
919 init_sam_entry3(&(*sam)->sam[i], start_idx+i+1,
920 &(*sam)->str[i].uni_grp_name,
921 &(*sam)->str[i].uni_grp_desc,
922 entries[i].rid);
925 return NT_STATUS_OK;
928 /*******************************************************************
929 reads or writes a structure.
930 ********************************************************************/
932 static bool sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
933 uint32 num_entries,
934 prs_struct *ps, int depth)
936 uint32 i;
938 if (sam == NULL)
939 return False;
941 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
942 depth++;
944 if(!prs_align(ps))
945 return False;
947 if (UNMARSHALLING(ps) && num_entries > 0) {
949 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
950 DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
951 return False;
954 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
955 DEBUG(0, ("out of memory allocating SAM_STR3\n"));
956 return False;
960 for (i = 0; i < num_entries; i++) {
961 if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
962 return False;
965 for (i = 0; i < num_entries; i++) {
966 if(!sam_io_sam_str3("", &sam->str[i],
967 sam->sam[i].hdr_grp_name.buffer,
968 sam->sam[i].hdr_grp_desc.buffer, ps, depth))
969 return False;
972 return True;
975 /*******************************************************************
976 inits a SAM_DISPINFO_4 structure.
977 ********************************************************************/
979 NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 **sam,
980 uint32 num_entries, uint32 start_idx,
981 struct samr_displayentry *entries)
983 uint32 i;
985 DEBUG(5, ("init_sam_dispinfo_4: num_entries: %d\n", num_entries));
987 if (num_entries==0)
988 return NT_STATUS_OK;
990 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_4, num_entries);
991 if (*sam == NULL)
992 return NT_STATUS_NO_MEMORY;
994 (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries);
995 if ((*sam)->sam == NULL)
996 return NT_STATUS_NO_MEMORY;
998 (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries);
999 if ((*sam)->str == NULL)
1000 return NT_STATUS_NO_MEMORY;
1002 for (i = 0; i < num_entries; i++) {
1003 size_t len_sam_name = strlen(entries[i].account_name);
1005 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1007 init_sam_entry4(&(*sam)->sam[i], start_idx + i + 1,
1008 len_sam_name);
1010 init_string2(&(*sam)->str[i].acct_name,
1011 entries[i].account_name, len_sam_name+1,
1012 len_sam_name);
1015 return NT_STATUS_OK;
1018 /*******************************************************************
1019 reads or writes a structure.
1020 ********************************************************************/
1022 static bool sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
1023 uint32 num_entries,
1024 prs_struct *ps, int depth)
1026 uint32 i;
1028 if (sam == NULL)
1029 return False;
1031 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1032 depth++;
1034 if(!prs_align(ps))
1035 return False;
1037 if (UNMARSHALLING(ps) && num_entries > 0) {
1039 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
1040 DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1041 return False;
1044 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
1045 DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1046 return False;
1050 for (i = 0; i < num_entries; i++) {
1051 if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
1052 return False;
1055 for (i = 0; i < num_entries; i++) {
1056 if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
1057 sam->sam[i].hdr_acct_name.buffer, ps, depth))
1058 return False;
1061 return True;
1064 /*******************************************************************
1065 inits a SAM_DISPINFO_5 structure.
1066 ********************************************************************/
1068 NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 **sam,
1069 uint32 num_entries, uint32 start_idx,
1070 struct samr_displayentry *entries)
1072 uint32 len_sam_name;
1073 uint32 i;
1075 DEBUG(5, ("init_sam_dispinfo_5: num_entries: %d\n", num_entries));
1077 if (num_entries==0)
1078 return NT_STATUS_OK;
1080 *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_5, num_entries);
1081 if (*sam == NULL)
1082 return NT_STATUS_NO_MEMORY;
1084 if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
1085 return NT_STATUS_NO_MEMORY;
1087 if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
1088 return NT_STATUS_NO_MEMORY;
1090 for (i = 0; i < num_entries; i++) {
1091 DEBUG(11, ("init_sam_dispinfo_5: entry: %d\n",i));
1093 len_sam_name = strlen(entries[i].account_name);
1095 init_sam_entry5(&(*sam)->sam[i], start_idx+i+1, len_sam_name);
1096 init_string2(&(*sam)->str[i].grp_name, entries[i].account_name,
1097 len_sam_name+1, len_sam_name);
1100 return NT_STATUS_OK;
1103 /*******************************************************************
1104 reads or writes a structure.
1105 ********************************************************************/
1107 static bool sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
1108 uint32 num_entries,
1109 prs_struct *ps, int depth)
1111 uint32 i;
1113 if (sam == NULL)
1114 return False;
1116 prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
1117 depth++;
1119 if(!prs_align(ps))
1120 return False;
1122 if (UNMARSHALLING(ps) && num_entries > 0) {
1124 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
1125 DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
1126 return False;
1129 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
1130 DEBUG(0, ("out of memory allocating SAM_STR5\n"));
1131 return False;
1135 for (i = 0; i < num_entries; i++) {
1136 if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
1137 return False;
1140 for (i = 0; i < num_entries; i++) {
1141 if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
1142 sam->sam[i].hdr_grp_name.buffer, ps, depth))
1143 return False;
1146 return True;
1149 /*******************************************************************
1150 inits a SAMR_R_QUERY_DISPINFO structure.
1151 ********************************************************************/
1153 void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
1154 uint32 num_entries, uint32 total_size, uint32 data_size,
1155 uint16 switch_level, SAM_DISPINFO_CTR * ctr,
1156 NTSTATUS status)
1158 DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
1160 r_u->total_size = total_size;
1162 r_u->data_size = data_size;
1164 r_u->switch_level = switch_level;
1165 r_u->num_entries = num_entries;
1167 if (num_entries==0)
1168 r_u->ptr_entries = 0;
1169 else
1170 r_u->ptr_entries = 1;
1172 r_u->num_entries2 = num_entries;
1173 r_u->ctr = ctr;
1175 r_u->status = status;
1178 /*******************************************************************
1179 reads or writes a structure.
1180 ********************************************************************/
1182 bool samr_io_r_query_dispinfo(const char *desc, SAMR_R_QUERY_DISPINFO * r_u,
1183 prs_struct *ps, int depth)
1185 if (r_u == NULL)
1186 return False;
1188 prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
1189 depth++;
1191 if(!prs_align(ps))
1192 return False;
1194 if(!prs_uint32("total_size ", ps, depth, &r_u->total_size))
1195 return False;
1196 if(!prs_uint32("data_size ", ps, depth, &r_u->data_size))
1197 return False;
1198 if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
1199 return False;
1200 if(!prs_align(ps))
1201 return False;
1203 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
1204 return False;
1205 if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
1206 return False;
1208 if (r_u->ptr_entries==0) {
1209 if(!prs_align(ps))
1210 return False;
1211 if(!prs_ntstatus("status", ps, depth, &r_u->status))
1212 return False;
1214 return True;
1217 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1218 return False;
1220 switch (r_u->switch_level) {
1221 case 0x1:
1222 if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
1223 r_u->num_entries, ps, depth))
1224 return False;
1225 break;
1226 case 0x2:
1227 if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
1228 r_u->num_entries, ps, depth))
1229 return False;
1230 break;
1231 case 0x3:
1232 if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
1233 r_u->num_entries, ps, depth))
1234 return False;
1235 break;
1236 case 0x4:
1237 if(!sam_io_sam_dispinfo_4("user list",
1238 r_u->ctr->sam.info4,
1239 r_u->num_entries, ps, depth))
1240 return False;
1241 break;
1242 case 0x5:
1243 if(!sam_io_sam_dispinfo_5("group list",
1244 r_u->ctr->sam.info5,
1245 r_u->num_entries, ps, depth))
1246 return False;
1247 break;
1248 default:
1249 DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
1250 break;
1253 if(!prs_align(ps))
1254 return False;
1255 if(!prs_ntstatus("status", ps, depth, &r_u->status))
1256 return False;
1258 return True;
1261 /*******************************************************************
1262 inits a GROUP_INFO1 structure.
1263 ********************************************************************/
1265 void init_samr_group_info1(GROUP_INFO1 * gr1,
1266 char *acct_name, char *acct_desc,
1267 uint32 num_members)
1269 DEBUG(5, ("init_samr_group_info1\n"));
1271 gr1->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
1272 gr1->num_members = num_members;
1274 init_unistr2(&gr1->uni_acct_name, acct_name, UNI_FLAGS_NONE);
1275 init_uni_hdr(&gr1->hdr_acct_name, &gr1->uni_acct_name);
1276 init_unistr2(&gr1->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
1277 init_uni_hdr(&gr1->hdr_acct_desc, &gr1->uni_acct_desc);
1280 /*******************************************************************
1281 reads or writes a structure.
1282 ********************************************************************/
1284 bool samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
1285 prs_struct *ps, int depth)
1287 uint16 dummy = 1;
1289 if (gr1 == NULL)
1290 return False;
1292 prs_debug(ps, depth, desc, "samr_io_group_info1");
1293 depth++;
1295 if(!prs_uint16("level", ps, depth, &dummy))
1296 return False;
1298 if(!prs_align(ps))
1299 return False;
1301 if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
1302 return False;
1304 if(!prs_uint32("group_attr", ps, depth, &gr1->group_attr))
1305 return False;
1306 if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
1307 return False;
1309 if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
1310 return False;
1312 if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
1313 gr1->hdr_acct_name.buffer, ps, depth))
1314 return False;
1316 if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
1317 gr1->hdr_acct_desc.buffer, ps, depth))
1318 return False;
1320 return True;
1323 /*******************************************************************
1324 inits a GROUP_INFO2 structure.
1325 ********************************************************************/
1327 void init_samr_group_info2(GROUP_INFO2 * gr2, const char *acct_name)
1329 DEBUG(5, ("init_samr_group_info2\n"));
1331 gr2->level = 2;
1332 init_unistr2(&gr2->uni_acct_name, acct_name, UNI_FLAGS_NONE);
1333 init_uni_hdr(&gr2->hdr_acct_name, &gr2->uni_acct_name);
1336 /*******************************************************************
1337 reads or writes a structure.
1338 ********************************************************************/
1340 bool samr_io_group_info2(const char *desc, GROUP_INFO2 *gr2, prs_struct *ps, int depth)
1342 if (gr2 == NULL)
1343 return False;
1345 prs_debug(ps, depth, desc, "samr_io_group_info2");
1346 depth++;
1348 if(!prs_uint16("hdr_level", ps, depth, &gr2->level))
1349 return False;
1351 if(!smb_io_unihdr("hdr_acct_name", &gr2->hdr_acct_name, ps, depth))
1352 return False;
1353 if(!smb_io_unistr2("uni_acct_name", &gr2->uni_acct_name,
1354 gr2->hdr_acct_name.buffer, ps, depth))
1355 return False;
1357 return True;
1360 /*******************************************************************
1361 inits a GROUP_INFO3 structure.
1362 ********************************************************************/
1364 void init_samr_group_info3(GROUP_INFO3 *gr3)
1366 DEBUG(5, ("init_samr_group_info3\n"));
1368 gr3->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
1371 /*******************************************************************
1372 reads or writes a structure.
1373 ********************************************************************/
1375 bool samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int depth)
1377 if (gr3 == NULL)
1378 return False;
1380 prs_debug(ps, depth, desc, "samr_io_group_info3");
1381 depth++;
1383 if(!prs_align(ps))
1384 return False;
1386 if(!prs_uint32("group_attr", ps, depth, &gr3->group_attr))
1387 return False;
1389 return True;
1392 /*******************************************************************
1393 inits a GROUP_INFO4 structure.
1394 ********************************************************************/
1396 void init_samr_group_info4(GROUP_INFO4 * gr4, const char *acct_desc)
1398 DEBUG(5, ("init_samr_group_info4\n"));
1400 gr4->level = 4;
1401 init_unistr2(&gr4->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
1402 init_uni_hdr(&gr4->hdr_acct_desc, &gr4->uni_acct_desc);
1405 /*******************************************************************
1406 reads or writes a structure.
1407 ********************************************************************/
1409 bool samr_io_group_info4(const char *desc, GROUP_INFO4 * gr4,
1410 prs_struct *ps, int depth)
1412 if (gr4 == NULL)
1413 return False;
1415 prs_debug(ps, depth, desc, "samr_io_group_info4");
1416 depth++;
1418 if(!prs_uint16("hdr_level", ps, depth, &gr4->level))
1419 return False;
1420 if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
1421 return False;
1422 if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
1423 gr4->hdr_acct_desc.buffer, ps, depth))
1424 return False;
1426 return True;
1429 /*******************************************************************
1430 inits a GROUP_INFO5 structure.
1431 ********************************************************************/
1433 void init_samr_group_info5(GROUP_INFO5 * gr5,
1434 char *acct_name, char *acct_desc,
1435 uint32 num_members)
1437 DEBUG(5, ("init_samr_group_info5\n"));
1439 gr5->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
1440 gr5->num_members = num_members;
1442 init_unistr2(&gr5->uni_acct_name, acct_name, UNI_FLAGS_NONE);
1443 init_uni_hdr(&gr5->hdr_acct_name, &gr5->uni_acct_name);
1444 init_unistr2(&gr5->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
1445 init_uni_hdr(&gr5->hdr_acct_desc, &gr5->uni_acct_desc);
1448 /*******************************************************************
1449 reads or writes a structure.
1450 ********************************************************************/
1452 bool samr_io_group_info5(const char *desc, GROUP_INFO5 * gr5,
1453 prs_struct *ps, int depth)
1455 uint16 dummy = 1;
1457 if (gr5 == NULL)
1458 return False;
1460 prs_debug(ps, depth, desc, "samr_io_group_info5");
1461 depth++;
1463 if(!prs_uint16("level", ps, depth, &dummy))
1464 return False;
1466 if(!prs_align(ps))
1467 return False;
1469 if(!smb_io_unihdr("hdr_acct_name", &gr5->hdr_acct_name, ps, depth))
1470 return False;
1472 if(!prs_uint32("group_attr", ps, depth, &gr5->group_attr))
1473 return False;
1474 if(!prs_uint32("num_members", ps, depth, &gr5->num_members))
1475 return False;
1477 if(!smb_io_unihdr("hdr_acct_desc", &gr5->hdr_acct_desc, ps, depth))
1478 return False;
1480 if(!smb_io_unistr2("uni_acct_name", &gr5->uni_acct_name,
1481 gr5->hdr_acct_name.buffer, ps, depth))
1482 return False;
1484 if(!smb_io_unistr2("uni_acct_desc", &gr5->uni_acct_desc,
1485 gr5->hdr_acct_desc.buffer, ps, depth))
1486 return False;
1488 return True;
1492 /*******************************************************************
1493 reads or writes a structure.
1494 ********************************************************************/
1496 static bool samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
1497 prs_struct *ps, int depth)
1499 if (UNMARSHALLING(ps))
1500 *ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
1502 if (*ctr == NULL)
1503 return False;
1505 prs_debug(ps, depth, desc, "samr_group_info_ctr");
1506 depth++;
1508 if(!prs_uint16("switch_value1", ps, depth, &(*ctr)->switch_value1))
1509 return False;
1511 switch ((*ctr)->switch_value1) {
1512 case 1:
1513 if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
1514 return False;
1515 break;
1516 case 2:
1517 if(!samr_io_group_info2("group_info2", &(*ctr)->group.info2, ps, depth))
1518 return False;
1519 break;
1520 case 3:
1521 if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
1522 return False;
1523 break;
1524 case 4:
1525 if(!samr_io_group_info4("group_info4", &(*ctr)->group.info4, ps, depth))
1526 return False;
1527 break;
1528 case 5:
1529 if(!samr_io_group_info5("group_info5", &(*ctr)->group.info5, ps, depth))
1530 return False;
1531 break;
1532 default:
1533 DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
1534 break;
1537 return True;
1540 /*******************************************************************
1541 inits a SAMR_Q_QUERY_GROUPINFO structure.
1542 ********************************************************************/
1544 void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
1545 POLICY_HND *pol, uint16 switch_level)
1547 DEBUG(5, ("init_samr_q_query_groupinfo\n"));
1549 q_e->pol = *pol;
1551 q_e->switch_level = switch_level;
1554 /*******************************************************************
1555 reads or writes a structure.
1556 ********************************************************************/
1558 bool samr_io_q_query_groupinfo(const char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
1559 prs_struct *ps, int depth)
1561 if (q_e == NULL)
1562 return False;
1564 prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
1565 depth++;
1567 if(!prs_align(ps))
1568 return False;
1570 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
1571 return False;
1573 if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
1574 return False;
1576 return True;
1579 /*******************************************************************
1580 inits a SAMR_R_QUERY_GROUPINFO structure.
1581 ********************************************************************/
1583 void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
1584 GROUP_INFO_CTR * ctr, NTSTATUS status)
1586 DEBUG(5, ("init_samr_r_query_groupinfo\n"));
1588 r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
1589 r_u->ctr = ctr;
1590 r_u->status = status;
1593 /*******************************************************************
1594 reads or writes a structure.
1595 ********************************************************************/
1597 bool samr_io_r_query_groupinfo(const char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
1598 prs_struct *ps, int depth)
1600 if (r_u == NULL)
1601 return False;
1603 prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
1604 depth++;
1606 if(!prs_align(ps))
1607 return False;
1609 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
1610 return False;
1612 if (r_u->ptr != 0) {
1613 if(!samr_group_info_ctr("ctr", &r_u->ctr, ps, depth))
1614 return False;
1617 if(!prs_align(ps))
1618 return False;
1619 if(!prs_ntstatus("status", ps, depth, &r_u->status))
1620 return False;
1622 return True;
1625 /*******************************************************************
1626 inits a SAMR_Q_QUERY_USERGROUPS structure.
1627 ********************************************************************/
1629 void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
1630 POLICY_HND *hnd)
1632 DEBUG(5, ("init_samr_q_query_usergroups\n"));
1634 q_u->pol = *hnd;
1637 /*******************************************************************
1638 reads or writes a structure.
1639 ********************************************************************/
1641 bool samr_io_q_query_usergroups(const char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
1642 prs_struct *ps, int depth)
1644 if (q_u == NULL)
1645 return False;
1647 prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
1648 depth++;
1650 if(!prs_align(ps))
1651 return False;
1653 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
1654 return False;
1656 return True;
1659 /*******************************************************************
1660 inits a SAMR_R_QUERY_USERGROUPS structure.
1661 ********************************************************************/
1663 void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
1664 uint32 num_gids, DOM_GID * gid,
1665 NTSTATUS status)
1667 DEBUG(5, ("init_samr_r_query_usergroups\n"));
1669 if (NT_STATUS_IS_OK(status)) {
1670 r_u->ptr_0 = 1;
1671 r_u->num_entries = num_gids;
1672 r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
1673 r_u->num_entries2 = num_gids;
1675 r_u->gid = gid;
1676 } else {
1677 r_u->ptr_0 = 0;
1678 r_u->num_entries = 0;
1679 r_u->ptr_1 = 0;
1680 r_u->gid = NULL;
1683 r_u->status = status;
1686 /*******************************************************************
1687 reads or writes a structure.
1688 ********************************************************************/
1690 bool samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
1691 prs_struct *ps, int depth)
1693 uint32 i;
1694 if (gid == NULL)
1695 return False;
1697 prs_debug(ps, depth, desc, "samr_io_gids");
1698 depth++;
1700 if(!prs_align(ps))
1701 return False;
1703 if(!prs_uint32("num_gids", ps, depth, num_gids))
1704 return False;
1706 if ((*num_gids) != 0) {
1707 if (UNMARSHALLING(ps)) {
1708 (*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
1711 if ((*gid) == NULL) {
1712 return False;
1715 for (i = 0; i < (*num_gids); i++) {
1716 if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
1717 return False;
1721 return True;
1724 /*******************************************************************
1725 reads or writes a structure.
1726 ********************************************************************/
1728 bool samr_io_r_query_usergroups(const char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
1729 prs_struct *ps, int depth)
1731 if (r_u == NULL)
1732 return False;
1734 prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
1735 depth++;
1737 if(!prs_align(ps))
1738 return False;
1740 if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
1741 return False;
1743 if (r_u->ptr_0 != 0) {
1744 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
1745 return False;
1746 if(!prs_uint32("ptr_1 ", ps, depth, &r_u->ptr_1))
1747 return False;
1749 if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
1750 if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
1751 return False;
1755 if(!prs_align(ps))
1756 return False;
1757 if(!prs_ntstatus("status", ps, depth, &r_u->status))
1758 return False;
1760 return True;
1763 /*******************************************************************
1764 inits a SAMR_Q_ENUM_DOMAINS structure.
1765 ********************************************************************/
1767 void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
1768 POLICY_HND *pol,
1769 uint32 start_idx, uint32 size)
1771 DEBUG(5, ("init_samr_q_enum_domains\n"));
1773 q_e->pol = *pol;
1775 q_e->start_idx = start_idx;
1776 q_e->max_size = size;
1779 /*******************************************************************
1780 reads or writes a structure.
1781 ********************************************************************/
1783 bool samr_io_q_enum_domains(const char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
1784 prs_struct *ps, int depth)
1786 if (q_e == NULL)
1787 return False;
1789 prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
1790 depth++;
1792 if(!prs_align(ps))
1793 return False;
1795 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
1796 return False;
1798 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1799 return False;
1800 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1801 return False;
1803 return True;
1806 /*******************************************************************
1807 inits a SAMR_R_ENUM_DOMAINS structure.
1808 ********************************************************************/
1810 void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
1811 uint32 next_idx, uint32 num_sam_entries)
1813 DEBUG(5, ("init_samr_r_enum_domains\n"));
1815 r_u->next_idx = next_idx;
1817 if (num_sam_entries != 0) {
1818 r_u->ptr_entries1 = 1;
1819 r_u->ptr_entries2 = 1;
1820 r_u->num_entries2 = num_sam_entries;
1821 r_u->num_entries3 = num_sam_entries;
1823 r_u->num_entries4 = num_sam_entries;
1824 } else {
1825 r_u->ptr_entries1 = 0;
1826 r_u->num_entries2 = num_sam_entries;
1827 r_u->ptr_entries2 = 1;
1831 /*******************************************************************
1832 reads or writes a structure.
1833 ********************************************************************/
1835 bool samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
1836 prs_struct *ps, int depth)
1838 uint32 i;
1840 if (r_u == NULL)
1841 return False;
1843 prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
1844 depth++;
1846 if(!prs_align(ps))
1847 return False;
1849 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
1850 return False;
1851 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1852 return False;
1854 if (r_u->ptr_entries1 != 0) {
1855 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1856 return False;
1857 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1858 return False;
1859 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1860 return False;
1862 if (UNMARSHALLING(ps) && r_u->num_entries2) {
1863 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
1864 r_u->uni_dom_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
1867 if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
1868 DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
1869 r_u->num_entries4 = 0;
1870 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
1871 return False;
1874 for (i = 0; i < r_u->num_entries2; i++) {
1875 fstring tmp;
1876 slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
1877 if(!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
1878 return False;
1881 for (i = 0; i < r_u->num_entries2; i++) {
1882 fstring tmp;
1883 slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
1884 if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i],
1885 r_u->sam[i].hdr_name.buffer, ps,
1886 depth))
1887 return False;
1892 if(!prs_align(ps))
1893 return False;
1894 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
1895 return False;
1896 if(!prs_ntstatus("status", ps, depth, &r_u->status))
1897 return False;
1899 return True;
1902 /*******************************************************************
1903 inits a SAMR_Q_ENUM_DOM_GROUPS structure.
1904 ********************************************************************/
1906 void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
1907 POLICY_HND *pol,
1908 uint32 start_idx, uint32 size)
1910 DEBUG(5, ("init_samr_q_enum_dom_groups\n"));
1912 q_e->pol = *pol;
1914 q_e->start_idx = start_idx;
1915 q_e->max_size = size;
1918 /*******************************************************************
1919 reads or writes a structure.
1920 ********************************************************************/
1922 bool samr_io_q_enum_dom_groups(const char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
1923 prs_struct *ps, int depth)
1925 if (q_e == NULL)
1926 return False;
1928 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
1929 depth++;
1931 if(!prs_align(ps))
1932 return False;
1934 if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
1935 return False;
1937 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1938 return False;
1939 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1940 return False;
1942 return True;
1945 /*******************************************************************
1946 inits a SAMR_R_ENUM_DOM_GROUPS structure.
1947 ********************************************************************/
1949 void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
1950 uint32 next_idx, uint32 num_sam_entries)
1952 DEBUG(5, ("init_samr_r_enum_dom_groups\n"));
1954 r_u->next_idx = next_idx;
1956 if (num_sam_entries != 0) {
1957 r_u->ptr_entries1 = 1;
1958 r_u->ptr_entries2 = 1;
1959 r_u->num_entries2 = num_sam_entries;
1960 r_u->num_entries3 = num_sam_entries;
1962 r_u->num_entries4 = num_sam_entries;
1963 } else {
1964 r_u->ptr_entries1 = 0;
1965 r_u->num_entries2 = num_sam_entries;
1966 r_u->ptr_entries2 = 1;
1970 /*******************************************************************
1971 reads or writes a structure.
1972 ********************************************************************/
1974 bool samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
1975 prs_struct *ps, int depth)
1977 uint32 i;
1979 if (r_u == NULL)
1980 return False;
1982 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
1983 depth++;
1985 if(!prs_align(ps))
1986 return False;
1988 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
1989 return False;
1990 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1991 return False;
1993 if (r_u->ptr_entries1 != 0) {
1994 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1995 return False;
1996 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1997 return False;
1998 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1999 return False;
2001 if (UNMARSHALLING(ps) && r_u->num_entries2) {
2002 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
2003 r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
2006 if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
2007 DEBUG(0,
2008 ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n"));
2009 r_u->num_entries4 = 0;
2010 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
2011 return False;
2014 for (i = 0; i < r_u->num_entries2; i++) {
2015 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
2016 return False;
2019 for (i = 0; i < r_u->num_entries2; i++) {
2020 if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
2021 r_u->sam[i].hdr_name.buffer, ps, depth))
2022 return False;
2026 if(!prs_align(ps))
2027 return False;
2028 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
2029 return False;
2030 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2031 return False;
2033 return True;
2036 /*******************************************************************
2037 inits a SAMR_Q_ENUM_DOM_ALIASES structure.
2038 ********************************************************************/
2040 void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
2041 POLICY_HND *pol, uint32 start_idx,
2042 uint32 size)
2044 DEBUG(5, ("init_samr_q_enum_dom_aliases\n"));
2046 q_e->pol = *pol;
2048 q_e->start_idx = start_idx;
2049 q_e->max_size = size;
2053 /*******************************************************************
2054 reads or writes a structure.
2055 ********************************************************************/
2057 bool samr_io_q_enum_dom_aliases(const char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
2058 prs_struct *ps, int depth)
2060 if (q_e == NULL)
2061 return False;
2063 prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
2064 depth++;
2066 if(!prs_align(ps))
2067 return False;
2069 if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2070 return False;
2072 if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
2073 return False;
2074 if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
2075 return False;
2077 return True;
2080 /*******************************************************************
2081 inits a SAMR_R_ENUM_DOM_ALIASES structure.
2082 ********************************************************************/
2084 void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries)
2086 DEBUG(5, ("init_samr_r_enum_dom_aliases\n"));
2088 r_u->next_idx = next_idx;
2090 if (num_sam_entries != 0) {
2091 r_u->ptr_entries1 = 1;
2092 r_u->ptr_entries2 = 1;
2093 r_u->num_entries2 = num_sam_entries;
2094 r_u->num_entries3 = num_sam_entries;
2096 r_u->num_entries4 = num_sam_entries;
2097 } else {
2098 r_u->ptr_entries1 = 0;
2099 r_u->num_entries2 = num_sam_entries;
2100 r_u->ptr_entries2 = 1;
2104 /*******************************************************************
2105 reads or writes a structure.
2106 ********************************************************************/
2108 bool samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
2109 prs_struct *ps, int depth)
2111 uint32 i;
2113 if (r_u == NULL)
2114 return False;
2116 prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
2117 depth++;
2119 if(!prs_align(ps))
2120 return False;
2122 if(!prs_uint32("next_idx ", ps, depth, &r_u->next_idx))
2123 return False;
2124 if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
2125 return False;
2127 if (r_u->ptr_entries1 != 0) {
2128 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
2129 return False;
2130 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
2131 return False;
2132 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
2133 return False;
2135 if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
2136 r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
2137 r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
2140 if (r_u->num_entries2 != 0 &&
2141 (r_u->sam == NULL || r_u->uni_grp_name == NULL)) {
2142 DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n"));
2143 r_u->num_entries4 = 0;
2144 r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
2145 return False;
2148 for (i = 0; i < r_u->num_entries2; i++) {
2149 if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
2150 return False;
2153 for (i = 0; i < r_u->num_entries2; i++) {
2154 if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
2155 r_u->sam[i].hdr_name.buffer, ps,
2156 depth))
2157 return False;
2161 if(!prs_align(ps))
2162 return False;
2163 if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
2164 return False;
2165 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2166 return False;
2168 return True;
2171 /*******************************************************************
2172 inits a samr_AliasInfoAll structure.
2173 ********************************************************************/
2175 void init_samr_alias_info1(struct samr_AliasInfoAll *r,
2176 const char *name,
2177 uint32_t num_members,
2178 const char *description)
2180 DEBUG(5, ("init_samr_alias_info1\n"));
2182 init_lsa_String(&r->name, name);
2183 r->num_members = num_members;
2184 init_lsa_String(&r->description, description);
2187 /*******************************************************************
2188 inits a lsa_String structure.
2189 ********************************************************************/
2191 void init_samr_alias_info3(struct lsa_String *r,
2192 const char *description)
2194 DEBUG(5, ("init_samr_alias_info3\n"));
2196 init_lsa_String(r, description);
2199 /*******************************************************************
2200 inits a SAMR_Q_LOOKUP_RIDS structure.
2201 ********************************************************************/
2203 void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
2204 POLICY_HND *pol, uint32 flags,
2205 uint32 num_rids, uint32 *rid)
2207 DEBUG(5, ("init_samr_q_lookup_rids\n"));
2209 q_u->pol = *pol;
2211 q_u->num_rids1 = num_rids;
2212 q_u->flags = flags;
2213 q_u->ptr = 0;
2214 q_u->num_rids2 = num_rids;
2215 if (num_rids) {
2216 q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
2217 } else {
2218 q_u->rid = NULL;
2220 if (q_u->rid == NULL) {
2221 q_u->num_rids1 = 0;
2222 q_u->num_rids2 = 0;
2223 } else {
2224 memcpy(q_u->rid, rid, num_rids * sizeof(q_u->rid[0]));
2228 /*******************************************************************
2229 reads or writes a structure.
2230 ********************************************************************/
2232 bool samr_io_q_lookup_rids(const char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
2233 prs_struct *ps, int depth)
2235 uint32 i;
2236 fstring tmp;
2238 if (q_u == NULL)
2239 return False;
2241 prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
2242 depth++;
2244 if (UNMARSHALLING(ps))
2245 ZERO_STRUCTP(q_u);
2247 if(!prs_align(ps))
2248 return False;
2250 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2251 return False;
2253 if(!prs_uint32("num_rids1", ps, depth, &q_u->num_rids1))
2254 return False;
2255 if(!prs_uint32("flags ", ps, depth, &q_u->flags))
2256 return False;
2257 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
2258 return False;
2259 if(!prs_uint32("num_rids2", ps, depth, &q_u->num_rids2))
2260 return False;
2262 if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
2263 q_u->rid = PRS_ALLOC_MEM(ps, uint32, q_u->num_rids2);
2264 if (q_u->rid == NULL)
2265 return False;
2268 for (i = 0; i < q_u->num_rids2; i++) {
2269 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i);
2270 if(!prs_uint32(tmp, ps, depth, &q_u->rid[i]))
2271 return False;
2274 return True;
2277 /*******************************************************************
2278 inits a SAMR_R_LOOKUP_RIDS structure.
2279 ********************************************************************/
2281 void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS * r_u,
2282 uint32 num_names, UNIHDR * hdr_name,
2283 UNISTR2 *uni_name, uint32 *type)
2285 DEBUG(5, ("init_samr_r_lookup_rids\n"));
2287 r_u->hdr_name = NULL;
2288 r_u->uni_name = NULL;
2289 r_u->type = NULL;
2291 if (num_names != 0) {
2292 r_u->num_names1 = num_names;
2293 r_u->ptr_names = 1;
2294 r_u->num_names2 = num_names;
2296 r_u->num_types1 = num_names;
2297 r_u->ptr_types = 1;
2298 r_u->num_types2 = num_names;
2300 r_u->hdr_name = hdr_name;
2301 r_u->uni_name = uni_name;
2302 r_u->type = type;
2303 } else {
2304 r_u->num_names1 = num_names;
2305 r_u->ptr_names = 0;
2306 r_u->num_names2 = num_names;
2308 r_u->num_types1 = num_names;
2309 r_u->ptr_types = 0;
2310 r_u->num_types2 = num_names;
2314 /*******************************************************************
2315 reads or writes a structure.
2316 ********************************************************************/
2318 bool samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
2319 prs_struct *ps, int depth)
2321 uint32 i;
2322 fstring tmp;
2323 if (r_u == NULL)
2324 return False;
2326 prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
2327 depth++;
2329 if(!prs_align(ps))
2330 return False;
2332 if(!prs_uint32("num_names1", ps, depth, &r_u->num_names1))
2333 return False;
2334 if(!prs_uint32("ptr_names ", ps, depth, &r_u->ptr_names))
2335 return False;
2337 if (r_u->ptr_names != 0) {
2339 if(!prs_uint32("num_names2", ps, depth, &r_u->num_names2))
2340 return False;
2343 if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
2344 r_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, r_u->num_names2);
2345 if (r_u->hdr_name == NULL)
2346 return False;
2348 r_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, r_u->num_names2);
2349 if (r_u->uni_name == NULL)
2350 return False;
2353 for (i = 0; i < r_u->num_names2; i++) {
2354 slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d] ", i);
2355 if(!smb_io_unihdr("", &r_u->hdr_name[i], ps, depth))
2356 return False;
2358 for (i = 0; i < r_u->num_names2; i++) {
2359 slprintf(tmp, sizeof(tmp) - 1, "str[%02d] ", i);
2360 if(!smb_io_unistr2("", &r_u->uni_name[i], r_u->hdr_name[i].buffer, ps, depth))
2361 return False;
2366 if(!prs_align(ps))
2367 return False;
2368 if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
2369 return False;
2370 if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
2371 return False;
2373 if (r_u->ptr_types != 0) {
2375 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
2376 return False;
2378 if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
2379 r_u->type = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
2380 if (r_u->type == NULL)
2381 return False;
2384 for (i = 0; i < r_u->num_types2; i++) {
2385 slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i);
2386 if(!prs_uint32(tmp, ps, depth, &r_u->type[i]))
2387 return False;
2391 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2392 return False;
2394 return True;
2397 /*******************************************************************
2398 inits a SAMR_Q_LOOKUP_NAMES structure.
2399 ********************************************************************/
2401 NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
2402 POLICY_HND *pol, uint32 flags,
2403 uint32 num_names, const char **name)
2405 uint32 i;
2407 DEBUG(5, ("init_samr_q_lookup_names\n"));
2409 q_u->pol = *pol;
2411 q_u->num_names1 = num_names;
2412 q_u->flags = flags;
2413 q_u->ptr = 0;
2414 q_u->num_names2 = num_names;
2416 if (num_names) {
2417 if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
2418 return NT_STATUS_NO_MEMORY;
2420 if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
2421 return NT_STATUS_NO_MEMORY;
2422 } else {
2423 q_u->hdr_name = NULL;
2424 q_u->uni_name = NULL;
2427 for (i = 0; i < num_names; i++) {
2428 init_unistr2(&q_u->uni_name[i], name[i], UNI_FLAGS_NONE); /* unicode string for machine account */
2429 init_uni_hdr(&q_u->hdr_name[i], &q_u->uni_name[i]); /* unicode header for user_name */
2432 return NT_STATUS_OK;
2435 /*******************************************************************
2436 reads or writes a structure.
2437 ********************************************************************/
2439 bool samr_io_q_lookup_names(const char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
2440 prs_struct *ps, int depth)
2442 uint32 i;
2444 if (q_u == NULL)
2445 return False;
2447 prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
2448 depth++;
2450 if (UNMARSHALLING(ps))
2451 ZERO_STRUCTP(q_u);
2453 if(!prs_align(ps))
2454 return False;
2456 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2457 return False;
2459 if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1))
2460 return False;
2461 if(!prs_uint32("flags ", ps, depth, &q_u->flags))
2462 return False;
2463 if(!prs_uint32("ptr ", ps, depth, &q_u->ptr))
2464 return False;
2465 if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2))
2466 return False;
2468 if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
2469 q_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_u->num_names2);
2470 q_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_u->num_names2);
2471 if (!q_u->hdr_name || !q_u->uni_name)
2472 return False;
2475 for (i = 0; i < q_u->num_names2; i++) {
2476 if(!smb_io_unihdr("", &q_u->hdr_name[i], ps, depth))
2477 return False;
2480 for (i = 0; i < q_u->num_names2; i++) {
2481 if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth))
2482 return False;
2485 return True;
2488 /*******************************************************************
2489 inits a SAMR_R_LOOKUP_NAMES structure.
2490 ********************************************************************/
2492 NTSTATUS init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
2493 uint32 num_rids,
2494 uint32 *rid, enum lsa_SidType *type,
2495 NTSTATUS status)
2497 DEBUG(5, ("init_samr_r_lookup_names\n"));
2499 if (NT_STATUS_IS_OK(status) && (num_rids != 0)) {
2500 uint32 i;
2502 r_u->num_types1 = num_rids;
2503 r_u->ptr_types = 1;
2504 r_u->num_types2 = num_rids;
2506 r_u->num_rids1 = num_rids;
2507 r_u->ptr_rids = 1;
2508 r_u->num_rids2 = num_rids;
2510 if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
2511 return NT_STATUS_NO_MEMORY;
2512 if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
2513 return NT_STATUS_NO_MEMORY;
2515 for (i = 0; i < num_rids; i++) {
2516 r_u->rids[i] = rid[i];
2517 r_u->types[i] = type[i];
2519 } else {
2521 r_u->num_types1 = 0;
2522 r_u->ptr_types = 0;
2523 r_u->num_types2 = 0;
2525 r_u->num_rids1 = 0;
2526 r_u->ptr_rids = 0;
2527 r_u->num_rids2 = 0;
2529 r_u->rids = NULL;
2530 r_u->types = NULL;
2533 r_u->status = status;
2535 return NT_STATUS_OK;
2538 /*******************************************************************
2539 reads or writes a structure.
2540 ********************************************************************/
2542 bool samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
2543 prs_struct *ps, int depth)
2545 uint32 i;
2546 fstring tmp;
2548 if (r_u == NULL)
2549 return False;
2551 prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
2552 depth++;
2554 if (UNMARSHALLING(ps))
2555 ZERO_STRUCTP(r_u);
2557 if(!prs_align(ps))
2558 return False;
2560 if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1))
2561 return False;
2562 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
2563 return False;
2565 if (r_u->ptr_rids != 0) {
2566 if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2))
2567 return False;
2569 if (r_u->num_rids2 != r_u->num_rids1) {
2570 /* RPC fault */
2571 return False;
2574 if (UNMARSHALLING(ps) && r_u->num_rids2) {
2575 r_u->rids = PRS_ALLOC_MEM(ps, uint32, r_u->num_rids2);
2577 if (!r_u->rids) {
2578 DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
2579 return False;
2583 for (i = 0; i < r_u->num_rids2; i++) {
2584 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i);
2585 if(!prs_uint32(tmp, ps, depth, &r_u->rids[i]))
2586 return False;
2590 if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
2591 return False;
2592 if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
2593 return False;
2595 if (r_u->ptr_types != 0) {
2596 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
2597 return False;
2599 if (r_u->num_types2 != r_u->num_types1) {
2600 /* RPC fault */
2601 return False;
2604 if (UNMARSHALLING(ps) && r_u->num_types2) {
2605 r_u->types = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
2607 if (!r_u->types) {
2608 DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
2609 return False;
2613 for (i = 0; i < r_u->num_types2; i++) {
2614 slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i);
2615 if(!prs_uint32(tmp, ps, depth, &r_u->types[i]))
2616 return False;
2620 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2621 return False;
2623 return True;
2626 /*******************************************************************
2627 inits a SAMR_Q_QUERY_USERINFO structure.
2628 ********************************************************************/
2630 void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
2631 const POLICY_HND *hnd, uint16 switch_value)
2633 DEBUG(5, ("init_samr_q_query_userinfo\n"));
2635 q_u->pol = *hnd;
2636 q_u->switch_value = switch_value;
2639 /*******************************************************************
2640 reads or writes a structure.
2641 ********************************************************************/
2643 bool samr_io_q_query_userinfo(const char *desc, SAMR_Q_QUERY_USERINFO * q_u,
2644 prs_struct *ps, int depth)
2646 if (q_u == NULL)
2647 return False;
2649 prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
2650 depth++;
2652 if(!prs_align(ps))
2653 return False;
2655 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2656 return False;
2658 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */
2659 return False;
2661 return True;
2664 /*******************************************************************
2665 reads or writes a LOGON_HRS structure.
2666 ********************************************************************/
2668 static bool sam_io_logon_hrs(const char *desc, LOGON_HRS * hrs,
2669 prs_struct *ps, int depth)
2671 if (hrs == NULL)
2672 return False;
2674 prs_debug(ps, depth, desc, "sam_io_logon_hrs");
2675 depth++;
2677 if(!prs_align(ps))
2678 return False;
2680 if(!prs_uint32("maxlen", ps, depth, &hrs->max_len))
2681 return False;
2683 if(!prs_uint32("offset", ps, depth, &hrs->offset))
2684 return False;
2686 if(!prs_uint32("len ", ps, depth, &hrs->len))
2687 return False;
2689 if (hrs->len > sizeof(hrs->hours)) {
2690 DEBUG(3, ("sam_io_logon_hrs: truncating length from %d\n", hrs->len));
2691 hrs->len = sizeof(hrs->hours);
2694 if(!prs_uint8s(False, "hours", ps, depth, hrs->hours, hrs->len))
2695 return False;
2697 return True;
2700 /*******************************************************************
2701 inits a SAM_USER_INFO_18 structure.
2702 ********************************************************************/
2704 void init_sam_user_info18(SAM_USER_INFO_18 * usr,
2705 const uint8 lm_pwd[16], const uint8 nt_pwd[16])
2707 DEBUG(5, ("init_sam_user_info18\n"));
2709 usr->lm_pwd_active =
2710 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd)) ? 1 : 0;
2711 usr->nt_pwd_active =
2712 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd)) ? 1 : 0;
2715 /*******************************************************************
2716 reads or writes a structure.
2717 ********************************************************************/
2719 static bool sam_io_user_info18(const char *desc, SAM_USER_INFO_18 * u,
2720 prs_struct *ps, int depth)
2722 if (u == NULL)
2723 return False;
2725 prs_debug(ps, depth, desc, "samr_io_r_user_info18");
2726 depth++;
2728 if(!prs_align(ps))
2729 return False;
2731 if(!prs_uint8s(False, "lm_pwd", ps, depth, u->lm_pwd, sizeof(u->lm_pwd)))
2732 return False;
2733 if(!prs_uint8s(False, "nt_pwd", ps, depth, u->nt_pwd, sizeof(u->nt_pwd)))
2734 return False;
2736 if(!prs_uint8("lm_pwd_active", ps, depth, &u->lm_pwd_active))
2737 return False;
2738 if(!prs_uint8("nt_pwd_active", ps, depth, &u->nt_pwd_active))
2739 return False;
2741 return True;
2744 /*******************************************************************
2745 inits a SAM_USER_INFO_7 structure.
2746 ********************************************************************/
2748 void init_sam_user_info7(SAM_USER_INFO_7 * usr, const char *name)
2750 DEBUG(5, ("init_sam_user_info7\n"));
2752 init_unistr2(&usr->uni_name, name, UNI_FLAGS_NONE); /* unicode string for name */
2753 init_uni_hdr(&usr->hdr_name, &usr->uni_name); /* unicode header for name */
2757 /*******************************************************************
2758 reads or writes a structure.
2759 ********************************************************************/
2761 static bool sam_io_user_info7(const char *desc, SAM_USER_INFO_7 * usr,
2762 prs_struct *ps, int depth)
2764 if (usr == NULL)
2765 return False;
2767 prs_debug(ps, depth, desc, "samr_io_r_user_info7");
2768 depth++;
2770 if(!prs_align(ps))
2771 return False;
2773 if(!smb_io_unihdr("unihdr", &usr->hdr_name, ps, depth))
2774 return False;
2776 if(!smb_io_unistr2("unistr2", &usr->uni_name, True, ps, depth))
2777 return False;
2779 return True;
2782 /*******************************************************************
2783 inits a SAM_USER_INFO_9 structure.
2784 ********************************************************************/
2786 void init_sam_user_info9(SAM_USER_INFO_9 * usr, uint32 rid_group)
2788 DEBUG(5, ("init_sam_user_info9\n"));
2790 usr->rid_group = rid_group;
2793 /*******************************************************************
2794 reads or writes a structure.
2795 ********************************************************************/
2797 static bool sam_io_user_info9(const char *desc, SAM_USER_INFO_9 * usr,
2798 prs_struct *ps, int depth)
2800 if (usr == NULL)
2801 return False;
2803 prs_debug(ps, depth, desc, "samr_io_r_user_info9");
2804 depth++;
2806 if(!prs_align(ps))
2807 return False;
2809 if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
2810 return False;
2812 return True;
2815 /*******************************************************************
2816 inits a SAM_USER_INFO_16 structure.
2817 ********************************************************************/
2819 void init_sam_user_info16(SAM_USER_INFO_16 * usr, uint32 acb_info)
2821 DEBUG(5, ("init_sam_user_info16\n"));
2823 usr->acb_info = acb_info;
2826 /*******************************************************************
2827 reads or writes a structure.
2828 ********************************************************************/
2830 static bool sam_io_user_info16(const char *desc, SAM_USER_INFO_16 * usr,
2831 prs_struct *ps, int depth)
2833 if (usr == NULL)
2834 return False;
2836 prs_debug(ps, depth, desc, "samr_io_r_user_info16");
2837 depth++;
2839 if(!prs_align(ps))
2840 return False;
2842 if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
2843 return False;
2845 return True;
2848 /*******************************************************************
2849 inits a SAM_USER_INFO_17 structure.
2850 ********************************************************************/
2852 void init_sam_user_info17(SAM_USER_INFO_17 * usr,
2853 NTTIME * expiry,
2854 char *mach_acct,
2855 uint32 rid_user, uint32 rid_group, uint16 acct_ctrl)
2857 DEBUG(5, ("init_sam_user_info17\n"));
2859 memcpy(&usr->expiry, expiry, sizeof(usr->expiry)); /* expiry time or something? */
2860 ZERO_STRUCT(usr->padding_1); /* 0 - padding 24 bytes */
2862 usr->padding_2 = 0; /* 0 - padding 4 bytes */
2864 usr->ptr_1 = 1; /* pointer */
2865 ZERO_STRUCT(usr->padding_3); /* 0 - padding 32 bytes */
2866 usr->padding_4 = 0; /* 0 - padding 4 bytes */
2868 usr->ptr_2 = 1; /* pointer */
2869 usr->padding_5 = 0; /* 0 - padding 4 bytes */
2871 usr->ptr_3 = 1; /* pointer */
2872 ZERO_STRUCT(usr->padding_6); /* 0 - padding 32 bytes */
2874 usr->rid_user = rid_user;
2875 usr->rid_group = rid_group;
2877 usr->acct_ctrl = acct_ctrl;
2878 usr->unknown_3 = 0x0000;
2880 usr->unknown_4 = 0x003f; /* 0x003f - 16 bit unknown */
2881 usr->unknown_5 = 0x003c; /* 0x003c - 16 bit unknown */
2883 ZERO_STRUCT(usr->padding_7); /* 0 - padding 16 bytes */
2884 usr->padding_8 = 0; /* 0 - padding 4 bytes */
2886 init_unistr2(&usr->uni_mach_acct, mach_acct, UNI_FLAGS_NONE); /* unicode string for machine account */
2887 init_uni_hdr(&usr->hdr_mach_acct, &usr->uni_mach_acct); /* unicode header for machine account */
2890 /*******************************************************************
2891 reads or writes a structure.
2892 ********************************************************************/
2894 static bool sam_io_user_info17(const char *desc, SAM_USER_INFO_17 * usr,
2895 prs_struct *ps, int depth)
2897 if (usr == NULL)
2898 return False;
2900 prs_debug(ps, depth, desc, "samr_io_r_unknown_17");
2901 depth++;
2903 if(!prs_align(ps))
2904 return False;
2906 if(!prs_uint8s(False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)))
2907 return False;
2909 if(!smb_io_time("time", &usr->expiry, ps, depth))
2910 return False;
2912 if(!prs_uint8s(False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)))
2913 return False;
2915 if(!smb_io_unihdr("unihdr", &usr->hdr_mach_acct, ps, depth))
2916 return False;
2918 if(!prs_uint32("padding_2", ps, depth, &usr->padding_2))
2919 return False;
2921 if(!prs_uint32("ptr_1 ", ps, depth, &usr->ptr_1))
2922 return False;
2923 if(!prs_uint8s(False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)))
2924 return False;
2926 if(!prs_uint32("padding_4", ps, depth, &usr->padding_4))
2927 return False;
2929 if(!prs_uint32("ptr_2 ", ps, depth, &usr->ptr_2))
2930 return False;
2931 if(!prs_uint32("padding_5", ps, depth, &usr->padding_5))
2932 return False;
2934 if(!prs_uint32("ptr_3 ", ps, depth, &usr->ptr_3))
2935 return False;
2936 if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6,sizeof(usr->padding_6)))
2937 return False;
2939 if(!prs_uint32("rid_user ", ps, depth, &usr->rid_user))
2940 return False;
2941 if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
2942 return False;
2943 if(!prs_uint16("acct_ctrl", ps, depth, &usr->acct_ctrl))
2944 return False;
2945 if(!prs_uint16("unknown_3", ps, depth, &usr->unknown_3))
2946 return False;
2947 if(!prs_uint16("unknown_4", ps, depth, &usr->unknown_4))
2948 return False;
2949 if(!prs_uint16("unknown_5", ps, depth, &usr->unknown_5))
2950 return False;
2952 if(!prs_uint8s(False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)))
2953 return False;
2955 if(!prs_uint32("padding_8", ps, depth, &(usr->padding_8)))
2956 return False;
2958 if(!smb_io_unistr2("unistr2", &usr->uni_mach_acct, True, ps, depth))
2959 return False;
2961 if(!prs_align(ps))
2962 return False;
2964 if(!prs_uint8s(False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9)))
2965 return False;
2967 return True;
2970 /*************************************************************************
2971 init_sam_user_infoa
2972 *************************************************************************/
2974 void init_sam_user_info24(SAM_USER_INFO_24 * usr, char newpass[516],
2975 uint8 pw_len)
2977 DEBUG(10, ("init_sam_user_info24:\n"));
2978 memcpy(usr->pass, newpass, sizeof(usr->pass));
2979 usr->pw_len = pw_len;
2982 /*******************************************************************
2983 reads or writes a structure.
2984 ********************************************************************/
2986 static bool sam_io_user_info24(const char *desc, SAM_USER_INFO_24 * usr,
2987 prs_struct *ps, int depth)
2989 if (usr == NULL)
2990 return False;
2992 prs_debug(ps, depth, desc, "sam_io_user_info24");
2993 depth++;
2995 if(!prs_align(ps))
2996 return False;
2998 if(!prs_uint8s(False, "password", ps, depth, usr->pass,
2999 sizeof(usr->pass)))
3000 return False;
3002 if (MARSHALLING(ps) && (usr->pw_len != 0)) {
3003 if (!prs_uint8("pw_len", ps, depth, &usr->pw_len))
3004 return False;
3005 } else if (UNMARSHALLING(ps)) {
3006 if (!prs_uint8("pw_len", ps, depth, &usr->pw_len))
3007 return False;
3010 return True;
3013 /*******************************************************************
3014 reads or writes a structure.
3015 ********************************************************************/
3017 static bool sam_io_user_info26(const char *desc, SAM_USER_INFO_26 * usr,
3018 prs_struct *ps, int depth)
3020 if (usr == NULL)
3021 return False;
3023 prs_debug(ps, depth, desc, "sam_io_user_info26");
3024 depth++;
3026 if(!prs_align(ps))
3027 return False;
3029 if(!prs_uint8s(False, "password", ps, depth, usr->pass,
3030 sizeof(usr->pass)))
3031 return False;
3033 if (!prs_uint8("pw_len", ps, depth, &usr->pw_len))
3034 return False;
3036 return True;
3040 /*************************************************************************
3041 init_sam_user_info23
3043 unknown_6 = 0x0000 04ec
3045 *************************************************************************/
3047 void init_sam_user_info23W(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
3048 NTTIME * logoff_time, /* all zeros */
3049 NTTIME * kickoff_time, /* all zeros */
3050 NTTIME * pass_last_set_time, /* all zeros */
3051 NTTIME * pass_can_change_time, /* all zeros */
3052 NTTIME * pass_must_change_time, /* all zeros */
3053 UNISTR2 *user_name,
3054 UNISTR2 *full_name,
3055 UNISTR2 *home_dir,
3056 UNISTR2 *dir_drive,
3057 UNISTR2 *log_scr,
3058 UNISTR2 *prof_path,
3059 UNISTR2 *desc,
3060 UNISTR2 *wkstas,
3061 UNISTR2 *unk_str,
3062 UNISTR2 *mung_dial,
3063 uint32 user_rid, /* 0x0000 0000 */
3064 uint32 group_rid,
3065 uint32 acb_info,
3066 uint32 fields_present,
3067 uint16 logon_divs,
3068 LOGON_HRS * hrs,
3069 uint16 bad_password_count,
3070 uint16 logon_count,
3071 char newpass[516])
3073 usr->logon_time = *logon_time; /* all zeros */
3074 usr->logoff_time = *logoff_time; /* all zeros */
3075 usr->kickoff_time = *kickoff_time; /* all zeros */
3076 usr->pass_last_set_time = *pass_last_set_time; /* all zeros */
3077 usr->pass_can_change_time = *pass_can_change_time; /* all zeros */
3078 usr->pass_must_change_time = *pass_must_change_time; /* all zeros */
3080 ZERO_STRUCT(usr->nt_pwd);
3081 ZERO_STRUCT(usr->lm_pwd);
3083 usr->user_rid = user_rid; /* 0x0000 0000 */
3084 usr->group_rid = group_rid;
3085 usr->acb_info = acb_info;
3086 usr->fields_present = fields_present; /* 09f8 27fa */
3088 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
3089 usr->ptr_logon_hrs = hrs ? 1 : 0;
3091 if (nt_time_is_zero(pass_must_change_time)) {
3092 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
3093 } else {
3094 usr->passmustchange=0;
3097 ZERO_STRUCT(usr->padding1);
3098 ZERO_STRUCT(usr->padding2);
3100 usr->bad_password_count = bad_password_count;
3101 usr->logon_count = logon_count;
3103 memcpy(usr->pass, newpass, sizeof(usr->pass));
3105 copy_unistr2(&usr->uni_user_name, user_name);
3106 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
3108 copy_unistr2(&usr->uni_full_name, full_name);
3109 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
3111 copy_unistr2(&usr->uni_home_dir, home_dir);
3112 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
3114 copy_unistr2(&usr->uni_dir_drive, dir_drive);
3115 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
3117 copy_unistr2(&usr->uni_logon_script, log_scr);
3118 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
3120 copy_unistr2(&usr->uni_profile_path, prof_path);
3121 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
3123 copy_unistr2(&usr->uni_acct_desc, desc);
3124 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
3126 copy_unistr2(&usr->uni_workstations, wkstas);
3127 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
3129 copy_unistr2(&usr->uni_comment, unk_str);
3130 init_uni_hdr(&usr->hdr_comment, &usr->uni_comment);
3132 copy_unistr2(&usr->uni_munged_dial, mung_dial);
3133 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
3135 if (hrs) {
3136 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
3137 } else {
3138 ZERO_STRUCT(usr->logon_hrs);
3142 /*************************************************************************
3143 init_sam_user_info23
3145 unknown_6 = 0x0000 04ec
3147 *************************************************************************/
3149 void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
3150 NTTIME * logoff_time, /* all zeros */
3151 NTTIME * kickoff_time, /* all zeros */
3152 NTTIME * pass_last_set_time, /* all zeros */
3153 NTTIME * pass_can_change_time, /* all zeros */
3154 NTTIME * pass_must_change_time, /* all zeros */
3155 char *user_name, /* NULL */
3156 char *full_name,
3157 char *home_dir, char *dir_drive, char *log_scr,
3158 char *prof_path, const char *desc, char *wkstas,
3159 char *unk_str, char *mung_dial, uint32 user_rid, /* 0x0000 0000 */
3160 uint32 group_rid, uint32 acb_info,
3161 uint32 fields_present, uint16 logon_divs,
3162 LOGON_HRS * hrs, uint16 bad_password_count, uint16 logon_count,
3163 char newpass[516])
3165 DATA_BLOB blob = base64_decode_data_blob(mung_dial);
3167 usr->logon_time = *logon_time; /* all zeros */
3168 usr->logoff_time = *logoff_time; /* all zeros */
3169 usr->kickoff_time = *kickoff_time; /* all zeros */
3170 usr->pass_last_set_time = *pass_last_set_time; /* all zeros */
3171 usr->pass_can_change_time = *pass_can_change_time; /* all zeros */
3172 usr->pass_must_change_time = *pass_must_change_time; /* all zeros */
3174 ZERO_STRUCT(usr->nt_pwd);
3175 ZERO_STRUCT(usr->lm_pwd);
3177 usr->user_rid = user_rid; /* 0x0000 0000 */
3178 usr->group_rid = group_rid;
3179 usr->acb_info = acb_info;
3180 usr->fields_present = fields_present; /* 09f8 27fa */
3182 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
3183 usr->ptr_logon_hrs = hrs ? 1 : 0;
3185 if (nt_time_is_zero(pass_must_change_time)) {
3186 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
3187 } else {
3188 usr->passmustchange=0;
3191 ZERO_STRUCT(usr->padding1);
3192 ZERO_STRUCT(usr->padding2);
3194 usr->bad_password_count = bad_password_count;
3195 usr->logon_count = logon_count;
3197 memcpy(usr->pass, newpass, sizeof(usr->pass));
3199 init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
3200 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
3202 init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
3203 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
3205 init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
3206 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
3208 init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
3209 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
3211 init_unistr2(&usr->uni_logon_script, log_scr, UNI_FLAGS_NONE);
3212 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
3214 init_unistr2(&usr->uni_profile_path, prof_path, UNI_FLAGS_NONE);
3215 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
3217 init_unistr2(&usr->uni_acct_desc, desc, UNI_FLAGS_NONE);
3218 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
3220 init_unistr2(&usr->uni_workstations, wkstas, UNI_FLAGS_NONE);
3221 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
3223 init_unistr2(&usr->uni_comment, unk_str, UNI_FLAGS_NONE);
3224 init_uni_hdr(&usr->hdr_comment, &usr->uni_comment);
3226 init_unistr2_from_datablob(&usr->uni_munged_dial, &blob);
3227 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
3229 data_blob_free(&blob);
3231 if (hrs) {
3232 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
3233 } else {
3234 ZERO_STRUCT(usr->logon_hrs);
3239 /*************************************************************************
3240 init_samr_user_info25P
3241 fields_present = ACCT_NT_PWD_SET | ACCT_LM_PWD_SET | ACCT_FLAGS
3242 *************************************************************************/
3244 void init_sam_user_info25P(SAM_USER_INFO_25 * usr,
3245 uint32 fields_present, uint32 acb_info,
3246 char newpass[532])
3248 usr->fields_present = fields_present;
3249 ZERO_STRUCT(usr->padding1);
3250 ZERO_STRUCT(usr->padding2);
3252 usr->acb_info = acb_info;
3253 memcpy(usr->pass, newpass, sizeof(usr->pass));
3257 /*******************************************************************
3258 reads or writes a structure.
3259 ********************************************************************/
3261 static bool sam_io_user_info23(const char *desc, SAM_USER_INFO_23 * usr,
3262 prs_struct *ps, int depth)
3264 if (usr == NULL)
3265 return False;
3267 prs_debug(ps, depth, desc, "sam_io_user_info23");
3268 depth++;
3270 if(!prs_align(ps))
3271 return False;
3273 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
3274 return False;
3275 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
3276 return False;
3277 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
3278 return False;
3279 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps, depth))
3280 return False;
3281 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
3282 return False;
3283 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
3284 return False;
3286 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
3287 return False;
3288 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
3289 return False;
3290 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
3291 return False;
3292 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
3293 return False;
3294 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
3295 return False;
3296 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
3297 return False;
3298 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
3299 return False;
3300 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
3301 return False;
3302 if(!smb_io_unihdr("hdr_comment ", &usr->hdr_comment, ps, depth)) /* unknown string */
3303 return False;
3304 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
3305 return False;
3307 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
3308 return False;
3309 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
3310 return False;
3312 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
3313 return False;
3314 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
3315 return False;
3316 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
3317 return False;
3319 if(!prs_uint32("fields_present ", ps, depth, &usr->fields_present))
3320 return False;
3321 if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */
3322 return False;
3323 if(!prs_align(ps))
3324 return False;
3325 if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
3326 return False;
3328 if(!prs_uint16("bad_password_count ", ps, depth, &usr->bad_password_count))
3329 return False;
3330 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count))
3331 return False;
3333 if(!prs_uint8s(False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)))
3334 return False;
3335 if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
3336 return False;
3337 if(!prs_uint8("padding2 ", ps, depth, &usr->padding2))
3338 return False;
3341 if(!prs_uint8s(False, "password ", ps, depth, usr->pass, sizeof(usr->pass)))
3342 return False;
3344 /* here begins pointed-to data */
3346 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
3347 return False;
3349 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
3350 return False;
3352 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
3353 return False;
3355 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
3356 return False;
3358 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
3359 return False;
3361 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
3362 return False;
3364 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
3365 return False;
3367 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
3368 return False;
3370 if(!smb_io_unistr2("uni_comment ", &usr->uni_comment, usr->hdr_comment.buffer, ps, depth)) /* unknown string */
3371 return False;
3373 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
3374 return False;
3376 /* ok, this is only guess-work (as usual) */
3377 if (usr->ptr_logon_hrs) {
3378 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
3379 return False;
3382 return True;
3385 /*******************************************************************
3386 reads or writes a structure.
3387 NB. This structure is *definately* incorrect. It's my best guess
3388 currently for W2K SP2. The password field is encrypted in a different
3389 way than normal... And there are definately other problems. JRA.
3390 ********************************************************************/
3392 static bool sam_io_user_info25(const char *desc, SAM_USER_INFO_25 * usr, prs_struct *ps, int depth)
3394 if (usr == NULL)
3395 return False;
3397 prs_debug(ps, depth, desc, "sam_io_user_info25");
3398 depth++;
3400 if(!prs_align(ps))
3401 return False;
3403 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
3404 return False;
3405 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
3406 return False;
3407 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
3408 return False;
3409 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps, depth))
3410 return False;
3411 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
3412 return False;
3413 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
3414 return False;
3416 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
3417 return False;
3418 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
3419 return False;
3420 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
3421 return False;
3422 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
3423 return False;
3424 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
3425 return False;
3426 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
3427 return False;
3428 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
3429 return False;
3430 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
3431 return False;
3432 if(!smb_io_unihdr("hdr_comment ", &usr->hdr_comment, ps, depth)) /* unknown string */
3433 return False;
3434 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
3435 return False;
3437 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
3438 return False;
3439 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
3440 return False;
3442 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
3443 return False;
3444 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
3445 return False;
3446 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
3447 return False;
3448 if(!prs_uint32("fields_present ", ps, depth, &usr->fields_present))
3449 return False;
3451 if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */
3452 return False;
3453 if(!prs_align(ps))
3454 return False;
3455 if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
3456 return False;
3458 if(!prs_uint16("bad_password_count ", ps, depth, &usr->bad_password_count))
3459 return False;
3460 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count))
3461 return False;
3463 if(!prs_uint8s(False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)))
3464 return False;
3465 if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
3466 return False;
3467 if(!prs_uint8("padding2 ", ps, depth, &usr->padding2))
3468 return False;
3471 if(!prs_uint8s(False, "password ", ps, depth, usr->pass, sizeof(usr->pass)))
3472 return False;
3474 /* here begins pointed-to data */
3476 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
3477 return False;
3479 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
3480 return False;
3482 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
3483 return False;
3485 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
3486 return False;
3488 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
3489 return False;
3491 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
3492 return False;
3494 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
3495 return False;
3497 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
3498 return False;
3500 if(!smb_io_unistr2("uni_comment ", &usr->uni_comment, usr->hdr_comment.buffer, ps, depth)) /* unknown string */
3501 return False;
3503 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
3504 return False;
3506 /* ok, this is only guess-work (as usual) */
3507 if (usr->ptr_logon_hrs) {
3508 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
3509 return False;
3512 return True;
3516 /*************************************************************************
3517 init_sam_user_info21W
3519 unknown_6 = 0x0000 04ec
3521 *************************************************************************/
3523 void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
3524 NTTIME * logon_time,
3525 NTTIME * logoff_time,
3526 NTTIME * kickoff_time,
3527 NTTIME * pass_last_set_time,
3528 NTTIME * pass_can_change_time,
3529 NTTIME * pass_must_change_time,
3530 UNISTR2 *user_name,
3531 UNISTR2 *full_name,
3532 UNISTR2 *home_dir,
3533 UNISTR2 *dir_drive,
3534 UNISTR2 *log_scr,
3535 UNISTR2 *prof_path,
3536 UNISTR2 *desc,
3537 UNISTR2 *wkstas,
3538 UNISTR2 *unk_str,
3539 UNISTR2 *mung_dial,
3540 uchar lm_pwd[16],
3541 uchar nt_pwd[16],
3542 uint32 user_rid,
3543 uint32 group_rid,
3544 uint32 acb_info,
3545 uint32 fields_present,
3546 uint16 logon_divs,
3547 LOGON_HRS * hrs,
3548 uint16 bad_password_count,
3549 uint16 logon_count)
3551 usr->logon_time = *logon_time;
3552 usr->logoff_time = *logoff_time;
3553 usr->kickoff_time = *kickoff_time;
3554 usr->pass_last_set_time = *pass_last_set_time;
3555 usr->pass_can_change_time = *pass_can_change_time;
3556 usr->pass_must_change_time = *pass_must_change_time;
3558 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd));
3559 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd));
3561 usr->user_rid = user_rid;
3562 usr->group_rid = group_rid;
3563 usr->acb_info = acb_info;
3564 usr->fields_present = fields_present; /* 0x00ff ffff */
3566 usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
3567 usr->ptr_logon_hrs = hrs ? 1 : 0;
3568 usr->bad_password_count = bad_password_count;
3569 usr->logon_count = logon_count;
3571 if (nt_time_is_zero(pass_must_change_time)) {
3572 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
3573 } else {
3574 usr->passmustchange=0;
3577 ZERO_STRUCT(usr->padding1);
3578 ZERO_STRUCT(usr->padding2);
3580 copy_unistr2(&usr->uni_user_name, user_name);
3581 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
3583 copy_unistr2(&usr->uni_full_name, full_name);
3584 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
3586 copy_unistr2(&usr->uni_home_dir, home_dir);
3587 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
3589 copy_unistr2(&usr->uni_dir_drive, dir_drive);
3590 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
3592 copy_unistr2(&usr->uni_logon_script, log_scr);
3593 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
3595 copy_unistr2(&usr->uni_profile_path, prof_path);
3596 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
3598 copy_unistr2(&usr->uni_acct_desc, desc);
3599 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
3601 copy_unistr2(&usr->uni_workstations, wkstas);
3602 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
3604 copy_unistr2(&usr->uni_comment, unk_str);
3605 init_uni_hdr(&usr->hdr_comment, &usr->uni_comment);
3607 copy_unistr2(&usr->uni_munged_dial, mung_dial);
3608 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
3610 if (hrs) {
3611 memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
3612 } else {
3613 ZERO_STRUCT(usr->logon_hrs);
3617 /*************************************************************************
3618 init_sam_user_info21
3620 unknown_6 = 0x0000 04ec
3622 *************************************************************************/
3624 NTSTATUS init_sam_user_info21A(SAM_USER_INFO_21 *usr, struct samu *pw, DOM_SID *domain_sid)
3626 NTTIME logon_time, logoff_time, kickoff_time,
3627 pass_last_set_time, pass_can_change_time,
3628 pass_must_change_time;
3630 time_t must_change_time;
3631 const char* user_name = pdb_get_username(pw);
3632 const char* full_name = pdb_get_fullname(pw);
3633 const char* home_dir = pdb_get_homedir(pw);
3634 const char* dir_drive = pdb_get_dir_drive(pw);
3635 const char* logon_script = pdb_get_logon_script(pw);
3636 const char* profile_path = pdb_get_profile_path(pw);
3637 const char* description = pdb_get_acct_desc(pw);
3638 const char* workstations = pdb_get_workstations(pw);
3639 const char* munged_dial = pdb_get_munged_dial(pw);
3640 DATA_BLOB munged_dial_blob;
3642 uint32 user_rid;
3643 const DOM_SID *user_sid;
3645 uint32 group_rid;
3646 const DOM_SID *group_sid;
3648 if (munged_dial) {
3649 munged_dial_blob = base64_decode_data_blob(munged_dial);
3650 } else {
3651 munged_dial_blob = data_blob_null;
3654 /* Create NTTIME structs */
3655 unix_to_nt_time (&logon_time, pdb_get_logon_time(pw));
3656 unix_to_nt_time (&logoff_time, pdb_get_logoff_time(pw));
3657 unix_to_nt_time (&kickoff_time, pdb_get_kickoff_time(pw));
3658 unix_to_nt_time (&pass_last_set_time, pdb_get_pass_last_set_time(pw));
3659 unix_to_nt_time (&pass_can_change_time,pdb_get_pass_can_change_time(pw));
3660 must_change_time = pdb_get_pass_must_change_time(pw);
3661 if (must_change_time == get_time_t_max())
3662 unix_to_nt_time_abs(&pass_must_change_time, must_change_time);
3663 else
3664 unix_to_nt_time(&pass_must_change_time, must_change_time);
3666 /* structure assignment */
3667 usr->logon_time = logon_time;
3668 usr->logoff_time = logoff_time;
3669 usr->kickoff_time = kickoff_time;
3670 usr->pass_last_set_time = pass_last_set_time;
3671 usr->pass_can_change_time = pass_can_change_time;
3672 usr->pass_must_change_time = pass_must_change_time;
3674 ZERO_STRUCT(usr->nt_pwd);
3675 ZERO_STRUCT(usr->lm_pwd);
3677 user_sid = pdb_get_user_sid(pw);
3679 if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
3680 DEBUG(0, ("init_sam_user_info_21A: User %s has SID %s, \nwhich conflicts with "
3681 "the domain sid %s. Failing operation.\n",
3682 user_name, sid_string_dbg(user_sid),
3683 sid_string_dbg(domain_sid)));
3684 data_blob_free(&munged_dial_blob);
3685 return NT_STATUS_UNSUCCESSFUL;
3688 become_root();
3689 group_sid = pdb_get_group_sid(pw);
3690 unbecome_root();
3692 if (!sid_peek_check_rid(domain_sid, group_sid, &group_rid)) {
3693 DEBUG(0, ("init_sam_user_info_21A: User %s has Primary Group SID %s, \n"
3694 "which conflicts with the domain sid %s. Failing operation.\n",
3695 user_name, sid_string_dbg(group_sid),
3696 sid_string_dbg(domain_sid)));
3697 data_blob_free(&munged_dial_blob);
3698 return NT_STATUS_UNSUCCESSFUL;
3701 usr->user_rid = user_rid;
3702 usr->group_rid = group_rid;
3703 usr->acb_info = pdb_get_acct_ctrl(pw);
3706 Look at a user on a real NT4 PDC with usrmgr, press
3707 'ok'. Then you will see that fields_present is set to
3708 0x08f827fa. Look at the user immediately after that again,
3709 and you will see that 0x00fffff is returned. This solves
3710 the problem that you get access denied after having looked
3711 at the user.
3712 -- Volker
3714 usr->fields_present = pdb_build_fields_present(pw);
3716 usr->logon_divs = pdb_get_logon_divs(pw);
3717 usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
3718 usr->bad_password_count = pdb_get_bad_password_count(pw);
3719 usr->logon_count = pdb_get_logon_count(pw);
3721 if (pdb_get_pass_must_change_time(pw) == 0) {
3722 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
3723 } else {
3724 usr->passmustchange=0;
3727 ZERO_STRUCT(usr->padding1);
3728 ZERO_STRUCT(usr->padding2);
3730 init_unistr2(&usr->uni_user_name, user_name, UNI_STR_TERMINATE);
3731 init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
3733 init_unistr2(&usr->uni_full_name, full_name, UNI_STR_TERMINATE);
3734 init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
3736 init_unistr2(&usr->uni_home_dir, home_dir, UNI_STR_TERMINATE);
3737 init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
3739 init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_STR_TERMINATE);
3740 init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
3742 init_unistr2(&usr->uni_logon_script, logon_script, UNI_STR_TERMINATE);
3743 init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
3745 init_unistr2(&usr->uni_profile_path, profile_path, UNI_STR_TERMINATE);
3746 init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
3748 init_unistr2(&usr->uni_acct_desc, description, UNI_STR_TERMINATE);
3749 init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
3751 init_unistr2(&usr->uni_workstations, workstations, UNI_STR_TERMINATE);
3752 init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
3754 init_unistr2(&usr->uni_comment, NULL, UNI_STR_TERMINATE);
3755 init_uni_hdr(&usr->hdr_comment, &usr->uni_comment);
3757 init_unistr2_from_datablob(&usr->uni_munged_dial, &munged_dial_blob);
3758 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
3759 data_blob_free(&munged_dial_blob);
3761 if (pdb_get_hours(pw)) {
3762 usr->logon_hrs.max_len = 1260;
3763 usr->logon_hrs.offset = 0;
3764 usr->logon_hrs.len = pdb_get_hours_len(pw);
3765 memcpy(&usr->logon_hrs.hours, pdb_get_hours(pw), MAX_HOURS_LEN);
3766 } else {
3767 usr->logon_hrs.max_len = 1260;
3768 usr->logon_hrs.offset = 0;
3769 usr->logon_hrs.len = 0;
3770 memset(&usr->logon_hrs, 0xff, sizeof(usr->logon_hrs));
3773 return NT_STATUS_OK;
3776 /*******************************************************************
3777 reads or writes a structure.
3778 ********************************************************************/
3780 static bool sam_io_user_info21(const char *desc, SAM_USER_INFO_21 * usr,
3781 prs_struct *ps, int depth)
3783 if (usr == NULL)
3784 return False;
3786 prs_debug(ps, depth, desc, "sam_io_user_info21");
3787 depth++;
3789 if(!prs_align(ps))
3790 return False;
3792 if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth))
3793 return False;
3794 if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth))
3795 return False;
3796 if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps,depth))
3797 return False;
3798 if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth))
3799 return False;
3800 if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps,depth))
3801 return False;
3802 if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
3803 return False;
3805 if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
3806 return False;
3807 if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
3808 return False;
3809 if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
3810 return False;
3811 if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
3812 return False;
3813 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
3814 return False;
3815 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
3816 return False;
3817 if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account desc */
3818 return False;
3819 if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* wkstas user can log on from */
3820 return False;
3821 if(!smb_io_unihdr("hdr_comment ", &usr->hdr_comment, ps, depth)) /* unknown string */
3822 return False;
3823 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
3824 return False;
3826 if(!prs_uint8s(False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
3827 return False;
3828 if(!prs_uint8s(False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
3829 return False;
3831 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */
3832 return False;
3833 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */
3834 return False;
3835 if(!prs_uint32("acb_info ", ps, depth, &usr->acb_info))
3836 return False;
3838 if(!prs_uint32("fields_present ", ps, depth, &usr->fields_present))
3839 return False;
3840 if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */
3841 return False;
3842 if(!prs_align(ps))
3843 return False;
3844 if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
3845 return False;
3847 if(!prs_uint16("bad_password_count ", ps, depth, &usr->bad_password_count))
3848 return False;
3849 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count))
3850 return False;
3852 if(!prs_uint8s(False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)))
3853 return False;
3854 if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
3855 return False;
3856 if(!prs_uint8("padding2 ", ps, depth, &usr->padding2))
3857 return False;
3859 /* here begins pointed-to data */
3861 if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name,usr->hdr_user_name.buffer, ps, depth))
3862 return False;
3863 if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))
3864 return False;
3865 if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))
3866 return False;
3867 if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))
3868 return False;
3869 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))
3870 return False;
3871 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))
3872 return False;
3873 if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))
3874 return False;
3875 if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))
3876 return False;
3877 if(!smb_io_unistr2("uni_comment", &usr->uni_comment, usr->hdr_comment.buffer, ps, depth))
3878 return False;
3879 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))
3880 return False;
3882 /* ok, this is only guess-work (as usual) */
3883 if (usr->ptr_logon_hrs) {
3884 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
3885 return False;
3888 return True;
3891 void init_sam_user_info20A(SAM_USER_INFO_20 *usr, struct samu *pw)
3893 const char *munged_dial = pdb_get_munged_dial(pw);
3894 DATA_BLOB blob;
3896 if (munged_dial) {
3897 blob = base64_decode_data_blob(munged_dial);
3898 } else {
3899 blob = data_blob_null;
3902 init_unistr2_from_datablob(&usr->uni_munged_dial, &blob);
3903 init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
3904 data_blob_free(&blob);
3907 /*******************************************************************
3908 reads or writes a structure.
3909 ********************************************************************/
3911 static bool sam_io_user_info20(const char *desc, SAM_USER_INFO_20 *usr,
3912 prs_struct *ps, int depth)
3914 if (usr == NULL)
3915 return False;
3917 prs_debug(ps, depth, desc, "sam_io_user_info20");
3918 depth++;
3920 if(!prs_align(ps))
3921 return False;
3923 if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
3924 return False;
3926 if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth)) /* worksations user can log on from */
3927 return False;
3929 return True;
3932 /*******************************************************************
3933 inits a SAM_USERINFO_CTR structure.
3934 ********************************************************************/
3936 NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
3937 uint16 switch_value,
3938 SAM_USER_INFO_21 * usr)
3940 DEBUG(5, ("make_samr_userinfo_ctr_usr21\n"));
3942 ctr->switch_value = switch_value;
3943 ctr->info.id = NULL;
3945 switch (switch_value) {
3946 case 16:
3947 ctr->info.id16 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_16);
3948 if (ctr->info.id16 == NULL)
3949 return NT_STATUS_NO_MEMORY;
3951 init_sam_user_info16(ctr->info.id16, usr->acb_info);
3952 break;
3953 #if 0
3954 /* whoops - got this wrong. i think. or don't understand what's happening. */
3955 case 17:
3957 NTTIME expire;
3958 info = (void *)&id11;
3960 expire.low = 0xffffffff;
3961 expire.high = 0x7fffffff;
3963 ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_17);
3964 init_sam_user_info11(ctr->info.id17, &expire,
3965 "BROOKFIELDS$", /* name */
3966 0x03ef, /* user rid */
3967 0x201, /* group rid */
3968 0x0080); /* acb info */
3970 break;
3972 #endif
3973 case 18:
3974 ctr->info.id18 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_18);
3975 if (ctr->info.id18 == NULL)
3976 return NT_STATUS_NO_MEMORY;
3978 init_sam_user_info18(ctr->info.id18, usr->lm_pwd, usr->nt_pwd);
3979 break;
3980 case 21:
3982 SAM_USER_INFO_21 *cusr;
3983 cusr = TALLOC_ZERO_P(ctx,SAM_USER_INFO_21);
3984 ctr->info.id21 = cusr;
3985 if (ctr->info.id21 == NULL)
3986 return NT_STATUS_NO_MEMORY;
3987 memcpy(cusr, usr, sizeof(*usr));
3988 memset(cusr->lm_pwd, 0, sizeof(cusr->lm_pwd));
3989 memset(cusr->nt_pwd, 0, sizeof(cusr->nt_pwd));
3990 break;
3992 default:
3993 DEBUG(4,("make_samr_userinfo_ctr: unsupported info\n"));
3994 return NT_STATUS_INVALID_INFO_CLASS;
3997 return NT_STATUS_OK;
4000 /*******************************************************************
4001 inits a SAM_USERINFO_CTR structure.
4002 ********************************************************************/
4004 static void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, DATA_BLOB *sess_key,
4005 uint16 switch_value, void *info)
4007 DEBUG(5, ("init_samr_userinfo_ctr\n"));
4009 ctr->switch_value = switch_value;
4010 ctr->info.id = info;
4012 switch (switch_value) {
4013 case 0x18:
4014 SamOEMhashBlob(ctr->info.id24->pass, 516, sess_key);
4015 dump_data(100, sess_key->data, sess_key->length);
4016 dump_data(100, ctr->info.id24->pass, 516);
4017 break;
4018 case 0x17:
4019 SamOEMhashBlob(ctr->info.id23->pass, 516, sess_key);
4020 dump_data(100, sess_key->data, sess_key->length);
4021 dump_data(100, ctr->info.id23->pass, 516);
4022 break;
4023 case 0x07:
4024 break;
4025 default:
4026 DEBUG(4,("init_samr_userinfo_ctr: unsupported switch level: %d\n", switch_value));
4030 /*******************************************************************
4031 reads or writes a structure.
4032 ********************************************************************/
4034 static bool samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
4035 prs_struct *ps, int depth)
4037 bool ret;
4038 SAM_USERINFO_CTR *ctr;
4040 prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
4041 depth++;
4043 if (UNMARSHALLING(ps)) {
4044 ctr = PRS_ALLOC_MEM(ps,SAM_USERINFO_CTR,1);
4045 if (ctr == NULL)
4046 return False;
4047 *ppctr = ctr;
4048 } else {
4049 ctr = *ppctr;
4052 /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
4054 if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
4055 return False;
4056 if(!prs_align(ps))
4057 return False;
4059 ret = False;
4061 switch (ctr->switch_value) {
4062 case 7:
4063 if (UNMARSHALLING(ps))
4064 ctr->info.id7 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_7,1);
4065 if (ctr->info.id7 == NULL) {
4066 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4067 return False;
4069 ret = sam_io_user_info7("", ctr->info.id7, ps, depth);
4070 break;
4071 case 9:
4072 if (UNMARSHALLING(ps))
4073 ctr->info.id9 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_9,1);
4074 if (ctr->info.id9 == NULL) {
4075 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4076 return False;
4078 ret = sam_io_user_info9("", ctr->info.id9, ps, depth);
4079 break;
4080 case 16:
4081 if (UNMARSHALLING(ps))
4082 ctr->info.id16 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_16,1);
4083 if (ctr->info.id16 == NULL) {
4084 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4085 return False;
4087 ret = sam_io_user_info16("", ctr->info.id16, ps, depth);
4088 break;
4089 case 17:
4090 if (UNMARSHALLING(ps))
4091 ctr->info.id17 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_17,1);
4093 if (ctr->info.id17 == NULL) {
4094 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4095 return False;
4097 ret = sam_io_user_info17("", ctr->info.id17, ps, depth);
4098 break;
4099 case 18:
4100 if (UNMARSHALLING(ps))
4101 ctr->info.id18 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_18,1);
4103 if (ctr->info.id18 == NULL) {
4104 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4105 return False;
4107 ret = sam_io_user_info18("", ctr->info.id18, ps, depth);
4108 break;
4109 case 20:
4110 if (UNMARSHALLING(ps))
4111 ctr->info.id20 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_20,1);
4113 if (ctr->info.id20 == NULL) {
4114 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4115 return False;
4117 ret = sam_io_user_info20("", ctr->info.id20, ps, depth);
4118 break;
4119 case 21:
4120 if (UNMARSHALLING(ps))
4121 ctr->info.id21 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_21,1);
4123 if (ctr->info.id21 == NULL) {
4124 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4125 return False;
4127 ret = sam_io_user_info21("", ctr->info.id21, ps, depth);
4128 break;
4129 case 23:
4130 if (UNMARSHALLING(ps))
4131 ctr->info.id23 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_23,1);
4133 if (ctr->info.id23 == NULL) {
4134 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4135 return False;
4137 ret = sam_io_user_info23("", ctr->info.id23, ps, depth);
4138 break;
4139 case 24:
4140 if (UNMARSHALLING(ps))
4141 ctr->info.id24 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_24,1);
4143 if (ctr->info.id24 == NULL) {
4144 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4145 return False;
4147 ret = sam_io_user_info24("", ctr->info.id24, ps, depth);
4148 break;
4149 case 25:
4150 if (UNMARSHALLING(ps))
4151 ctr->info.id25 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_25,1);
4153 if (ctr->info.id25 == NULL) {
4154 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4155 return False;
4157 ret = sam_io_user_info25("", ctr->info.id25, ps, depth);
4158 break;
4159 case 26:
4160 if (UNMARSHALLING(ps))
4161 ctr->info.id26 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_26,1);
4163 if (ctr->info.id26 == NULL) {
4164 DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
4165 return False;
4167 ret = sam_io_user_info26("", ctr->info.id26, ps, depth);
4168 break;
4169 default:
4170 DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
4171 ret = False;
4172 break;
4175 return ret;
4178 /*******************************************************************
4179 inits a SAMR_R_QUERY_USERINFO structure.
4180 ********************************************************************/
4182 void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
4183 SAM_USERINFO_CTR * ctr, NTSTATUS status)
4185 DEBUG(5, ("init_samr_r_query_userinfo\n"));
4187 r_u->ptr = 0;
4188 r_u->ctr = NULL;
4190 if (NT_STATUS_IS_OK(status)) {
4191 r_u->ptr = 1;
4192 r_u->ctr = ctr;
4195 r_u->status = status; /* return status */
4198 /*******************************************************************
4199 reads or writes a structure.
4200 ********************************************************************/
4202 bool samr_io_r_query_userinfo(const char *desc, SAMR_R_QUERY_USERINFO * r_u,
4203 prs_struct *ps, int depth)
4205 if (r_u == NULL)
4206 return False;
4208 prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
4209 depth++;
4211 if(!prs_align(ps))
4212 return False;
4214 if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
4215 return False;
4217 if (r_u->ptr != 0) {
4218 if(!samr_io_userinfo_ctr("ctr", &r_u->ctr, ps, depth))
4219 return False;
4222 if(!prs_align(ps))
4223 return False;
4224 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4225 return False;
4227 return True;
4230 /*******************************************************************
4231 inits a SAMR_Q_SET_USERINFO structure.
4232 ********************************************************************/
4234 void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
4235 const POLICY_HND *hnd, DATA_BLOB *sess_key,
4236 uint16 switch_value, void *info)
4238 DEBUG(5, ("init_samr_q_set_userinfo\n"));
4240 q_u->pol = *hnd;
4241 q_u->switch_value = switch_value;
4242 init_samr_userinfo_ctr(q_u->ctr, sess_key, switch_value, info);
4245 /*******************************************************************
4246 reads or writes a structure.
4247 ********************************************************************/
4249 bool samr_io_q_set_userinfo(const char *desc, SAMR_Q_SET_USERINFO * q_u,
4250 prs_struct *ps, int depth)
4252 if (q_u == NULL)
4253 return False;
4255 prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
4256 depth++;
4258 if(!prs_align(ps))
4259 return False;
4261 smb_io_pol_hnd("pol", &(q_u->pol), ps, depth);
4263 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
4264 return False;
4265 if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
4266 return False;
4268 return True;
4271 /*******************************************************************
4272 inits a SAMR_R_SET_USERINFO structure.
4273 ********************************************************************/
4275 void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, NTSTATUS status)
4277 DEBUG(5, ("init_samr_r_set_userinfo\n"));
4279 r_u->status = status; /* return status */
4282 /*******************************************************************
4283 reads or writes a structure.
4284 ********************************************************************/
4286 bool samr_io_r_set_userinfo(const char *desc, SAMR_R_SET_USERINFO * r_u,
4287 prs_struct *ps, int depth)
4289 if (r_u == NULL)
4290 return False;
4292 prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
4293 depth++;
4295 if(!prs_align(ps))
4296 return False;
4298 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4299 return False;
4301 return True;
4304 /*******************************************************************
4305 inits a SAMR_Q_SET_USERINFO2 structure.
4306 ********************************************************************/
4308 void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
4309 const POLICY_HND *hnd, DATA_BLOB *sess_key,
4310 uint16 switch_value, SAM_USERINFO_CTR * ctr)
4312 DEBUG(5, ("init_samr_q_set_userinfo2\n"));
4314 q_u->pol = *hnd;
4315 q_u->switch_value = switch_value;
4316 q_u->ctr = ctr;
4318 q_u->ctr->switch_value = switch_value;
4320 switch (switch_value) {
4321 case 18:
4322 SamOEMhashBlob(ctr->info.id18->lm_pwd, 16, sess_key);
4323 SamOEMhashBlob(ctr->info.id18->nt_pwd, 16, sess_key);
4324 dump_data(100, sess_key->data, sess_key->length);
4325 dump_data(100, ctr->info.id18->lm_pwd, 16);
4326 dump_data(100, ctr->info.id18->nt_pwd, 16);
4327 break;
4331 /*******************************************************************
4332 reads or writes a structure.
4333 ********************************************************************/
4335 bool samr_io_q_set_userinfo2(const char *desc, SAMR_Q_SET_USERINFO2 * q_u,
4336 prs_struct *ps, int depth)
4338 if (q_u == NULL)
4339 return False;
4341 prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
4342 depth++;
4344 if(!prs_align(ps))
4345 return False;
4347 if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4348 return False;
4350 if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
4351 return False;
4352 if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
4353 return False;
4355 return True;
4358 /*******************************************************************
4359 inits a SAMR_R_SET_USERINFO2 structure.
4360 ********************************************************************/
4362 void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, NTSTATUS status)
4364 DEBUG(5, ("init_samr_r_set_userinfo2\n"));
4366 r_u->status = status; /* return status */
4369 /*******************************************************************
4370 reads or writes a structure.
4371 ********************************************************************/
4373 bool samr_io_r_set_userinfo2(const char *desc, SAMR_R_SET_USERINFO2 * r_u,
4374 prs_struct *ps, int depth)
4376 if (r_u == NULL)
4377 return False;
4379 prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
4380 depth++;
4382 if(!prs_align(ps))
4383 return False;
4385 if(!prs_ntstatus("status", ps, depth, &r_u->status))
4386 return False;
4388 return True;