2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997,
7 * Copyright (C) Andrew Bartlett 2002,
8 * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002.
9 * Copyright (C) Gerald )Jerry) Carter 2005
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #define DBGC_CLASS DBGC_RPC_PARSE
30 static bool lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth);
31 static bool lsa_io_trans_names2(const char *desc, LSA_TRANS_NAME_ENUM2 *trn, prs_struct *ps, int depth);
33 /*******************************************************************
34 Inits a LSA_TRANS_NAME structure.
35 ********************************************************************/
37 void init_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name,
38 uint16 sid_name_use, const char *name, uint32 idx)
40 trn->sid_name_use = sid_name_use;
41 init_unistr2(uni_name, name, UNI_FLAGS_NONE);
42 init_uni_hdr(&trn->hdr_name, uni_name);
43 trn->domain_idx = idx;
46 /*******************************************************************
47 Reads or writes a LSA_TRANS_NAME structure.
48 ********************************************************************/
50 static bool lsa_io_trans_name(const char *desc, LSA_TRANS_NAME *trn, prs_struct *ps,
53 prs_debug(ps, depth, desc, "lsa_io_trans_name");
59 if(!prs_uint16("sid_name_use", ps, depth, &trn->sid_name_use))
64 if(!smb_io_unihdr ("hdr_name", &trn->hdr_name, ps, depth))
66 if(!prs_uint32("domain_idx ", ps, depth, &trn->domain_idx))
72 /*******************************************************************
73 Inits a LSA_TRANS_NAME2 structure.
74 ********************************************************************/
76 void init_lsa_trans_name2(LSA_TRANS_NAME2 *trn, UNISTR2 *uni_name,
77 uint16 sid_name_use, const char *name, uint32 idx)
79 trn->sid_name_use = sid_name_use;
80 init_unistr2(uni_name, name, UNI_FLAGS_NONE);
81 init_uni_hdr(&trn->hdr_name, uni_name);
82 trn->domain_idx = idx;
86 /*******************************************************************
87 Reads or writes a LSA_TRANS_NAME2 structure.
88 ********************************************************************/
90 static bool lsa_io_trans_name2(const char *desc, LSA_TRANS_NAME2 *trn, prs_struct *ps,
93 prs_debug(ps, depth, desc, "lsa_io_trans_name2");
99 if(!prs_uint16("sid_name_use", ps, depth, &trn->sid_name_use))
104 if(!smb_io_unihdr ("hdr_name", &trn->hdr_name, ps, depth))
106 if(!prs_uint32("domain_idx ", ps, depth, &trn->domain_idx))
108 if(!prs_uint32("unknown ", ps, depth, &trn->unknown))
114 /*******************************************************************
115 Reads or writes a DOM_R_REF structure.
116 ********************************************************************/
118 static bool lsa_io_dom_r_ref(const char *desc, DOM_R_REF *dom, prs_struct *ps, int depth)
122 prs_debug(ps, depth, desc, "lsa_io_dom_r_ref");
128 if(!prs_uint32("num_ref_doms_1", ps, depth, &dom->num_ref_doms_1)) /* num referenced domains? */
130 if(!prs_uint32("ptr_ref_dom ", ps, depth, &dom->ptr_ref_dom)) /* undocumented buffer pointer. */
132 if(!prs_uint32("max_entries ", ps, depth, &dom->max_entries)) /* 32 - max number of entries */
135 SMB_ASSERT_ARRAY(dom->hdr_ref_dom, dom->num_ref_doms_1);
137 if (dom->ptr_ref_dom != 0) {
139 if(!prs_uint32("num_ref_doms_2", ps, depth, &dom->num_ref_doms_2)) /* 4 - num referenced domains? */
142 SMB_ASSERT_ARRAY(dom->ref_dom, dom->num_ref_doms_2);
144 for (i = 0; i < dom->num_ref_doms_1; i++) {
147 slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
148 if(!smb_io_unihdr(t, &dom->hdr_ref_dom[i].hdr_dom_name, ps, depth))
151 slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
152 if(!prs_uint32(t, ps, depth, &dom->hdr_ref_dom[i].ptr_dom_sid))
156 for (i = 0; i < dom->num_ref_doms_2; i++) {
159 if (dom->hdr_ref_dom[i].hdr_dom_name.buffer != 0) {
160 slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
161 if(!smb_io_unistr2(t, &dom->ref_dom[i].uni_dom_name, True, ps, depth)) /* domain name unicode string */
167 if (dom->hdr_ref_dom[i].ptr_dom_sid != 0) {
168 slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
169 if(!smb_io_dom_sid2(t, &dom->ref_dom[i].ref_dom, ps, depth)) /* referenced domain SIDs */
178 /*******************************************************************
179 Inits a LSA_SID_ENUM structure.
180 ********************************************************************/
182 static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen,
183 int num_entries, const DOM_SID *sids)
187 DEBUG(5, ("init_lsa_sid_enum\n"));
189 sen->num_entries = num_entries;
190 sen->ptr_sid_enum = (num_entries != 0);
191 sen->num_entries2 = num_entries;
193 /* Allocate memory for sids and sid pointers */
196 if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
197 DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
201 if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
202 DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
207 /* Copy across SIDs and SID pointers */
209 for (i = 0; i < num_entries; i++) {
211 init_dom_sid2(&sen->sid[i], &sids[i]);
215 /*******************************************************************
216 Reads or writes a LSA_SID_ENUM structure.
217 ********************************************************************/
219 static bool lsa_io_sid_enum(const char *desc, LSA_SID_ENUM *sen, prs_struct *ps,
224 prs_debug(ps, depth, desc, "lsa_io_sid_enum");
230 if(!prs_uint32("num_entries ", ps, depth, &sen->num_entries))
232 if(!prs_uint32("ptr_sid_enum", ps, depth, &sen->ptr_sid_enum))
236 if the ptr is NULL, leave here. checked from a real w2k trace.
240 if (sen->ptr_sid_enum==0)
243 if(!prs_uint32("num_entries2", ps, depth, &sen->num_entries2))
246 /* Mallocate memory if we're unpacking from the wire */
248 if (UNMARSHALLING(ps) && sen->num_entries) {
249 if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
250 DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
255 if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries)) == NULL) {
256 DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
262 for (i = 0; i < sen->num_entries; i++) {
265 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
266 if(!prs_uint32(temp, ps, depth, &sen->ptr_sid[i])) {
271 for (i = 0; i < sen->num_entries; i++) {
274 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
275 if(!smb_io_dom_sid2(temp, &sen->sid[i], ps, depth)) {
283 /*******************************************************************
284 Inits an LSA_R_ENUM_TRUST_DOM structure.
285 ********************************************************************/
287 void init_q_lookup_sids(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_SIDS *q_l,
288 POLICY_HND *hnd, int num_sids, const DOM_SID *sids,
291 DEBUG(5, ("init_q_lookup_sids\n"));
295 memcpy(&q_l->pol, hnd, sizeof(q_l->pol));
296 init_lsa_sid_enum(mem_ctx, &q_l->sids, num_sids, sids);
301 /*******************************************************************
302 Reads or writes a LSA_Q_LOOKUP_SIDS structure.
303 ********************************************************************/
305 bool lsa_io_q_lookup_sids(const char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps,
308 prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
314 if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */
316 if(!lsa_io_sid_enum("sids ", &q_s->sids, ps, depth)) /* sids to be looked up */
318 if(!lsa_io_trans_names("names ", &q_s->names, ps, depth)) /* translated names */
321 if(!prs_uint16("level", ps, depth, &q_s->level)) /* lookup level */
326 if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
332 /*******************************************************************
333 Reads or writes a LSA_Q_LOOKUP_SIDS2 structure.
334 ********************************************************************/
336 bool lsa_io_q_lookup_sids2(const char *desc, LSA_Q_LOOKUP_SIDS2 *q_s, prs_struct *ps,
339 prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids2");
345 if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */
347 if(!lsa_io_sid_enum("sids ", &q_s->sids, ps, depth)) /* sids to be looked up */
349 if(!lsa_io_trans_names2("names ", &q_s->names, ps, depth)) /* translated names */
352 if(!prs_uint16("level", ps, depth, &q_s->level)) /* lookup level */
357 if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
359 if(!prs_uint32("unknown1", ps, depth, &q_s->unknown1))
361 if(!prs_uint32("unknown2", ps, depth, &q_s->unknown2))
367 /*******************************************************************
368 Reads or writes a LSA_Q_LOOKUP_SIDS3 structure.
369 ********************************************************************/
371 bool lsa_io_q_lookup_sids3(const char *desc, LSA_Q_LOOKUP_SIDS3 *q_s, prs_struct *ps,
374 prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids3");
380 if(!lsa_io_sid_enum("sids ", &q_s->sids, ps, depth)) /* sids to be looked up */
382 if(!lsa_io_trans_names2("names ", &q_s->names, ps, depth)) /* translated names */
385 if(!prs_uint16("level", ps, depth, &q_s->level)) /* lookup level */
390 if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
392 if(!prs_uint32("unknown1", ps, depth, &q_s->unknown1))
394 if(!prs_uint32("unknown2", ps, depth, &q_s->unknown2))
401 /*******************************************************************
402 Reads or writes a structure.
403 ********************************************************************/
405 static bool lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn,
406 prs_struct *ps, int depth)
410 prs_debug(ps, depth, desc, "lsa_io_trans_names");
416 if(!prs_uint32("num_entries ", ps, depth, &trn->num_entries))
418 if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names))
421 if (trn->ptr_trans_names != 0) {
422 if(!prs_uint32("num_entries2 ", ps, depth,
426 if (trn->num_entries2 != trn->num_entries) {
431 if (UNMARSHALLING(ps) && trn->num_entries2) {
432 if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries2)) == NULL) {
436 if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries2)) == NULL) {
441 for (i = 0; i < trn->num_entries2; i++) {
443 slprintf(t, sizeof(t) - 1, "name[%d] ", i);
445 if(!lsa_io_trans_name(t, &trn->name[i], ps, depth)) /* translated name */
449 for (i = 0; i < trn->num_entries2; i++) {
451 slprintf(t, sizeof(t) - 1, "name[%d] ", i);
453 if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth))
463 /*******************************************************************
464 Reads or writes a structure.
465 ********************************************************************/
467 static bool lsa_io_trans_names2(const char *desc, LSA_TRANS_NAME_ENUM2 *trn,
468 prs_struct *ps, int depth)
472 prs_debug(ps, depth, desc, "lsa_io_trans_names2");
478 if(!prs_uint32("num_entries ", ps, depth, &trn->num_entries))
480 if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names))
483 if (trn->ptr_trans_names != 0) {
484 if(!prs_uint32("num_entries2 ", ps, depth,
488 if (trn->num_entries2 != trn->num_entries) {
493 if (UNMARSHALLING(ps) && trn->num_entries2) {
494 if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME2, trn->num_entries2)) == NULL) {
498 if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries2)) == NULL) {
503 for (i = 0; i < trn->num_entries2; i++) {
505 slprintf(t, sizeof(t) - 1, "name[%d] ", i);
507 if(!lsa_io_trans_name2(t, &trn->name[i], ps, depth)) /* translated name */
511 for (i = 0; i < trn->num_entries2; i++) {
513 slprintf(t, sizeof(t) - 1, "name[%d] ", i);
515 if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth))
526 /*******************************************************************
527 Reads or writes a structure.
528 ********************************************************************/
530 bool lsa_io_r_lookup_sids(const char *desc, LSA_R_LOOKUP_SIDS *r_s,
531 prs_struct *ps, int depth)
533 prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
539 if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
542 if (r_s->ptr_dom_ref != 0)
543 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
546 if(!lsa_io_trans_names("names ", &r_s->names, ps, depth)) /* translated names */
552 if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
555 if(!prs_ntstatus("status ", ps, depth, &r_s->status))
561 /*******************************************************************
562 Reads or writes a structure.
563 ********************************************************************/
565 bool lsa_io_r_lookup_sids2(const char *desc, LSA_R_LOOKUP_SIDS2 *r_s,
566 prs_struct *ps, int depth)
568 prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids2");
574 if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
577 if (r_s->ptr_dom_ref != 0)
578 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
581 if(!lsa_io_trans_names2("names ", &r_s->names, ps, depth)) /* translated names */
587 if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
590 if(!prs_ntstatus("status ", ps, depth, &r_s->status))
597 /*******************************************************************
598 Reads or writes a structure.
599 ********************************************************************/
601 bool lsa_io_r_lookup_sids3(const char *desc, LSA_R_LOOKUP_SIDS3 *r_s,
602 prs_struct *ps, int depth)
604 prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids3");
610 if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
613 if (r_s->ptr_dom_ref != 0)
614 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
617 if(!lsa_io_trans_names2("names ", &r_s->names, ps, depth)) /* translated names */
623 if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
626 if(!prs_ntstatus("status ", ps, depth, &r_s->status))
632 /*******************************************************************
634 ********************************************************************/
636 void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l,
637 POLICY_HND *hnd, int num_names, const char **names,
642 DEBUG(5, ("init_q_lookup_names\n"));
647 q_l->num_entries = num_names;
648 q_l->num_entries2 = num_names;
649 q_l->lookup_level = level;
652 if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
653 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
657 if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
658 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
662 q_l->uni_name = NULL;
663 q_l->hdr_name = NULL;
666 for (i = 0; i < num_names; i++) {
667 init_unistr2(&q_l->uni_name[i], names[i], UNI_FLAGS_NONE);
668 init_uni_hdr(&q_l->hdr_name[i], &q_l->uni_name[i]);
672 /*******************************************************************
673 reads or writes a structure.
674 ********************************************************************/
676 bool lsa_io_q_lookup_names(const char *desc, LSA_Q_LOOKUP_NAMES *q_r,
677 prs_struct *ps, int depth)
681 prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
687 if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
692 if(!prs_uint32("num_entries ", ps, depth, &q_r->num_entries))
694 if(!prs_uint32("num_entries2 ", ps, depth, &q_r->num_entries2))
697 if (UNMARSHALLING(ps)) {
698 if (q_r->num_entries) {
699 if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
701 if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
706 for (i = 0; i < q_r->num_entries; i++) {
709 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
713 for (i = 0; i < q_r->num_entries; i++) {
716 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
722 if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
724 if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
726 if(!prs_uint16("lookup_level ", ps, depth, &q_r->lookup_level))
730 if(!prs_uint32("mapped_count ", ps, depth, &q_r->mapped_count))
736 /*******************************************************************
737 reads or writes a structure.
738 ********************************************************************/
740 bool lsa_io_r_lookup_names(const char *desc, LSA_R_LOOKUP_NAMES *out, prs_struct *ps, int depth)
744 prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
750 if(!prs_uint32("ptr_dom_ref", ps, depth, &out->ptr_dom_ref))
753 if (out->ptr_dom_ref != 0)
754 if(!lsa_io_dom_r_ref("", out->dom_ref, ps, depth))
757 if(!prs_uint32("num_entries", ps, depth, &out->num_entries))
759 if(!prs_uint32("ptr_entries", ps, depth, &out->ptr_entries))
762 if (out->ptr_entries != 0) {
763 if(!prs_uint32("num_entries2", ps, depth, &out->num_entries2))
766 if (out->num_entries2 != out->num_entries) {
771 if (UNMARSHALLING(ps) && out->num_entries2) {
772 if ((out->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID, out->num_entries2))
774 DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
779 for (i = 0; i < out->num_entries2; i++)
780 if(!smb_io_dom_rid("", &out->dom_rid[i], ps, depth)) /* domain RIDs being looked up */
784 if(!prs_uint32("mapped_count", ps, depth, &out->mapped_count))
787 if(!prs_ntstatus("status ", ps, depth, &out->status))
793 /*******************************************************************
794 reads or writes a structure.
795 ********************************************************************/
797 bool lsa_io_q_lookup_names2(const char *desc, LSA_Q_LOOKUP_NAMES2 *q_r,
798 prs_struct *ps, int depth)
802 prs_debug(ps, depth, desc, "lsa_io_q_lookup_names2");
808 if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
813 if(!prs_uint32("num_entries ", ps, depth, &q_r->num_entries))
815 if(!prs_uint32("num_entries2 ", ps, depth, &q_r->num_entries2))
818 if (UNMARSHALLING(ps)) {
819 if (q_r->num_entries) {
820 if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
822 if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
827 for (i = 0; i < q_r->num_entries; i++) {
830 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
834 for (i = 0; i < q_r->num_entries; i++) {
837 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
843 if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
845 if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
847 if(!prs_uint16("lookup_level ", ps, depth, &q_r->lookup_level))
851 if(!prs_uint32("mapped_count ", ps, depth, &q_r->mapped_count))
853 if(!prs_uint32("unknown1 ", ps, depth, &q_r->unknown1))
855 if(!prs_uint32("unknown2 ", ps, depth, &q_r->unknown2))
861 /*******************************************************************
862 reads or writes a structure.
863 ********************************************************************/
865 bool lsa_io_r_lookup_names2(const char *desc, LSA_R_LOOKUP_NAMES2 *out, prs_struct *ps, int depth)
869 prs_debug(ps, depth, desc, "lsa_io_r_lookup_names2");
875 if(!prs_uint32("ptr_dom_ref", ps, depth, &out->ptr_dom_ref))
878 if (out->ptr_dom_ref != 0)
879 if(!lsa_io_dom_r_ref("", out->dom_ref, ps, depth))
882 if(!prs_uint32("num_entries", ps, depth, &out->num_entries))
884 if(!prs_uint32("ptr_entries", ps, depth, &out->ptr_entries))
887 if (out->ptr_entries != 0) {
888 if(!prs_uint32("num_entries2", ps, depth, &out->num_entries2))
891 if (out->num_entries2 != out->num_entries) {
896 if (UNMARSHALLING(ps) && out->num_entries2) {
897 if ((out->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, out->num_entries2))
899 DEBUG(3, ("lsa_io_r_lookup_names2(): out of memory\n"));
904 for (i = 0; i < out->num_entries2; i++)
905 if(!smb_io_dom_rid2("", &out->dom_rid[i], ps, depth)) /* domain RIDs being looked up */
909 if(!prs_uint32("mapped_count", ps, depth, &out->mapped_count))
912 if(!prs_ntstatus("status ", ps, depth, &out->status))
918 /*******************************************************************
919 Internal lsa data type io.
920 Following pass must read DOM_SID2 types.
921 ********************************************************************/
923 bool smb_io_lsa_translated_sids3(const char *desc, LSA_TRANSLATED_SID3 *q_r,
924 prs_struct *ps, int depth)
926 prs_debug(ps, depth, desc, "smb_io_lsa_translated_sids3");
931 if(!prs_uint8 ("sid_type ", ps, depth, &q_r->sid_type ))
935 /* Second pass will read/write these. */
936 if (!smb_io_dom_sid2_p("sid_header", ps, depth, &q_r->sid2))
938 if(!prs_uint32("sid_idx ", ps, depth, &q_r->sid_idx ))
940 if(!prs_uint32("unknown ", ps, depth, &q_r->unknown ))
946 /*******************************************************************
947 Identical to lsa_io_q_lookup_names2.
948 ********************************************************************/
950 bool lsa_io_q_lookup_names3(const char *desc, LSA_Q_LOOKUP_NAMES3 *q_r,
951 prs_struct *ps, int depth)
955 prs_debug(ps, depth, desc, "lsa_io_q_lookup_names3");
961 if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
966 if(!prs_uint32("num_entries ", ps, depth, &q_r->num_entries))
968 if(!prs_uint32("num_entries2 ", ps, depth, &q_r->num_entries2))
971 if (UNMARSHALLING(ps)) {
972 if (q_r->num_entries) {
973 if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
975 if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
980 for (i = 0; i < q_r->num_entries; i++) {
983 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
987 for (i = 0; i < q_r->num_entries; i++) {
990 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
996 if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
998 if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
1000 if(!prs_uint16("lookup_level ", ps, depth, &q_r->lookup_level))
1004 if(!prs_uint32("mapped_count ", ps, depth, &q_r->mapped_count))
1006 if(!prs_uint32("unknown1 ", ps, depth, &q_r->unknown1))
1008 if(!prs_uint32("unknown2 ", ps, depth, &q_r->unknown2))
1014 /*******************************************************************
1015 reads or writes a structure.
1016 ********************************************************************/
1018 bool lsa_io_r_lookup_names3(const char *desc, LSA_R_LOOKUP_NAMES3 *out, prs_struct *ps, int depth)
1022 prs_debug(ps, depth, desc, "lsa_io_r_lookup_names3");
1028 if(!prs_uint32("ptr_dom_ref", ps, depth, &out->ptr_dom_ref))
1031 if (out->ptr_dom_ref != 0)
1032 if(!lsa_io_dom_r_ref("", out->dom_ref, ps, depth))
1035 if(!prs_uint32("num_entries", ps, depth, &out->num_entries))
1037 if(!prs_uint32("ptr_entries", ps, depth, &out->ptr_entries))
1040 if (out->ptr_entries != 0) {
1041 if(!prs_uint32("num_entries2", ps, depth, &out->num_entries2))
1044 if (out->num_entries2 != out->num_entries) {
1049 if (UNMARSHALLING(ps) && out->num_entries2) {
1050 if ((out->trans_sids = PRS_ALLOC_MEM(ps, LSA_TRANSLATED_SID3, out->num_entries2))
1052 DEBUG(3, ("lsa_io_r_lookup_names3(): out of memory\n"));
1057 for (i = 0; i < out->num_entries2; i++) {
1058 if(!smb_io_lsa_translated_sids3("", &out->trans_sids[i], ps, depth)) {
1062 /* Now process the DOM_SID2 entries. */
1063 for (i = 0; i < out->num_entries2; i++) {
1064 if (out->trans_sids[i].sid2) {
1065 if( !smb_io_dom_sid2("sid2", out->trans_sids[i].sid2, ps, depth) ) {
1072 if(!prs_uint32("mapped_count", ps, depth, &out->mapped_count))
1075 if(!prs_ntstatus("status ", ps, depth, &out->status))
1081 /*******************************************************************
1082 ********************************************************************/
1084 bool lsa_io_q_lookup_names4(const char *desc, LSA_Q_LOOKUP_NAMES4 *q_r,
1085 prs_struct *ps, int depth)
1089 prs_debug(ps, depth, desc, "lsa_io_q_lookup_names4");
1095 if(!prs_uint32("num_entries ", ps, depth, &q_r->num_entries))
1097 if(!prs_uint32("num_entries2 ", ps, depth, &q_r->num_entries2))
1100 if (UNMARSHALLING(ps)) {
1101 if (q_r->num_entries) {
1102 if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
1104 if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
1109 for (i = 0; i < q_r->num_entries; i++) {
1112 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
1116 for (i = 0; i < q_r->num_entries; i++) {
1119 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
1125 if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
1127 if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
1129 if(!prs_uint16("lookup_level ", ps, depth, &q_r->lookup_level))
1133 if(!prs_uint32("mapped_count ", ps, depth, &q_r->mapped_count))
1135 if(!prs_uint32("unknown1 ", ps, depth, &q_r->unknown1))
1137 if(!prs_uint32("unknown2 ", ps, depth, &q_r->unknown2))
1143 /*******************************************************************
1144 Identical to lsa_io_r_lookup_names3.
1145 ********************************************************************/
1147 bool lsa_io_r_lookup_names4(const char *desc, LSA_R_LOOKUP_NAMES4 *out, prs_struct *ps, int depth)
1151 prs_debug(ps, depth, desc, "lsa_io_r_lookup_names4");
1157 if(!prs_uint32("ptr_dom_ref", ps, depth, &out->ptr_dom_ref))
1160 if (out->ptr_dom_ref != 0)
1161 if(!lsa_io_dom_r_ref("", out->dom_ref, ps, depth))
1164 if(!prs_uint32("num_entries", ps, depth, &out->num_entries))
1166 if(!prs_uint32("ptr_entries", ps, depth, &out->ptr_entries))
1169 if (out->ptr_entries != 0) {
1170 if(!prs_uint32("num_entries2", ps, depth, &out->num_entries2))
1173 if (out->num_entries2 != out->num_entries) {
1178 if (UNMARSHALLING(ps) && out->num_entries2) {
1179 if ((out->trans_sids = PRS_ALLOC_MEM(ps, LSA_TRANSLATED_SID3, out->num_entries2))
1181 DEBUG(3, ("lsa_io_r_lookup_names4(): out of memory\n"));
1186 for (i = 0; i < out->num_entries2; i++) {
1187 if(!smb_io_lsa_translated_sids3("", &out->trans_sids[i], ps, depth)) {
1191 /* Now process the DOM_SID2 entries. */
1192 for (i = 0; i < out->num_entries2; i++) {
1193 if (out->trans_sids[i].sid2) {
1194 if( !smb_io_dom_sid2("sid2", out->trans_sids[i].sid2, ps, depth) ) {
1201 if(!prs_uint32("mapped_count", ps, depth, &out->mapped_count))
1204 if(!prs_ntstatus("status ", ps, depth, &out->status))
1210 /*******************************************************************
1211 Reads or writes an LUID structure.
1212 ********************************************************************/
1214 static bool lsa_io_luid(const char *desc, LUID *out, prs_struct *ps, int depth)
1216 prs_debug(ps, depth, desc, "lsa_io_luid");
1222 if(!prs_uint32("low", ps, depth, &out->low))
1225 if(!prs_uint32("high", ps, depth, &out->high))
1231 /*******************************************************************
1232 Reads or writes an LUID_ATTR structure.
1233 ********************************************************************/
1235 static bool lsa_io_luid_attr(const char *desc, LUID_ATTR *out, prs_struct *ps, int depth)
1237 prs_debug(ps, depth, desc, "lsa_io_luid_attr");
1243 if (!lsa_io_luid(desc, &out->luid, ps, depth))
1246 if(!prs_uint32("attr", ps, depth, &out->attr))
1252 /*******************************************************************
1253 Reads or writes an PRIVILEGE_SET structure.
1254 ********************************************************************/
1256 static bool lsa_io_privilege_set(const char *desc, PRIVILEGE_SET *out, prs_struct *ps, int depth)
1260 prs_debug(ps, depth, desc, "lsa_io_privilege_set");
1266 if(!prs_uint32("count", ps, depth, &dummy))
1268 if(!prs_uint32("control", ps, depth, &out->control))
1271 for (i=0; i<out->count; i++) {
1272 if (!lsa_io_luid_attr(desc, &out->set[i], ps, depth))
1279 void init_lsa_string( LSA_STRING *uni, const char *string )
1281 init_unistr2(&uni->unistring, string, UNI_FLAGS_NONE);
1282 init_uni_hdr(&uni->hdr, &uni->unistring);
1285 void init_lsa_q_lookup_priv_value(LSA_Q_LOOKUP_PRIV_VALUE *q_u, POLICY_HND *hnd, const char *name)
1287 memcpy(&q_u->pol, hnd, sizeof(q_u->pol));
1288 init_lsa_string( &q_u->privname, name );
1291 bool smb_io_lsa_string( const char *desc, LSA_STRING *string, prs_struct *ps, int depth )
1293 prs_debug(ps, depth, desc, "smb_io_lsa_string");
1296 if(!smb_io_unihdr ("hdr", &string->hdr, ps, depth))
1298 if(!smb_io_unistr2("unistring", &string->unistring, string->hdr.buffer, ps, depth))
1304 /*******************************************************************
1305 Reads or writes an LSA_Q_LOOKUP_PRIV_VALUE structure.
1306 ********************************************************************/
1308 bool lsa_io_q_lookup_priv_value(const char *desc, LSA_Q_LOOKUP_PRIV_VALUE *out, prs_struct *ps, int depth)
1310 prs_debug(ps, depth, desc, "lsa_io_q_lookup_priv_value");
1316 if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1318 if(!smb_io_lsa_string("privname", &out->privname, ps, depth))
1324 /*******************************************************************
1325 Reads or writes an LSA_R_LOOKUP_PRIV_VALUE structure.
1326 ********************************************************************/
1328 bool lsa_io_r_lookup_priv_value(const char *desc, LSA_R_LOOKUP_PRIV_VALUE *out, prs_struct *ps, int depth)
1330 prs_debug(ps, depth, desc, "lsa_io_r_lookup_priv_value");
1336 if(!lsa_io_luid("luid", &out->luid, ps, depth))
1339 if(!prs_ntstatus("status", ps, depth, &out->status))
1346 /*******************************************************************
1347 Reads or writes an LSA_Q_ADDPRIVS structure.
1348 ********************************************************************/
1350 bool lsa_io_q_addprivs(const char *desc, LSA_Q_ADDPRIVS *out, prs_struct *ps, int depth)
1352 prs_debug(ps, depth, desc, "lsa_io_q_addprivs");
1358 if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1361 if(!prs_uint32("count", ps, depth, &out->count))
1364 if (UNMARSHALLING(ps) && out->count!=0) {
1365 if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
1368 if (!(out->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, out->count)))
1372 if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
1378 /*******************************************************************
1379 Reads or writes an LSA_R_ADDPRIVS structure.
1380 ********************************************************************/
1382 bool lsa_io_r_addprivs(const char *desc, LSA_R_ADDPRIVS *out, prs_struct *ps, int depth)
1384 prs_debug(ps, depth, desc, "lsa_io_r_addprivs");
1390 if(!prs_ntstatus("status", ps, depth, &out->status))
1396 /*******************************************************************
1397 Reads or writes an LSA_Q_REMOVEPRIVS structure.
1398 ********************************************************************/
1400 bool lsa_io_q_removeprivs(const char *desc, LSA_Q_REMOVEPRIVS *out, prs_struct *ps, int depth)
1402 prs_debug(ps, depth, desc, "lsa_io_q_removeprivs");
1408 if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1411 if(!prs_uint32("allrights", ps, depth, &out->allrights))
1414 if(!prs_uint32("ptr", ps, depth, &out->ptr))
1418 * JFM: I'm not sure at all if the count is inside the ptr
1419 * never seen one with ptr=0
1423 if(!prs_uint32("count", ps, depth, &out->count))
1426 if (UNMARSHALLING(ps) && out->count!=0) {
1427 if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
1430 if (!(out->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, out->count)))
1434 if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
1441 /*******************************************************************
1442 Reads or writes an LSA_R_REMOVEPRIVS structure.
1443 ********************************************************************/
1445 bool lsa_io_r_removeprivs(const char *desc, LSA_R_REMOVEPRIVS *out, prs_struct *ps, int depth)
1447 prs_debug(ps, depth, desc, "lsa_io_r_removeprivs");
1453 if(!prs_ntstatus("status", ps, depth, &out->status))
1459 bool policy_handle_is_valid(const POLICY_HND *hnd)
1461 POLICY_HND zero_pol;
1463 ZERO_STRUCT(zero_pol);
1464 return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? False : True );
1467 /*******************************************************************
1468 Inits an LSA_Q_ENUM_ACCT_RIGHTS structure.
1469 ********************************************************************/
1470 void init_q_enum_acct_rights(LSA_Q_ENUM_ACCT_RIGHTS *in,
1475 DEBUG(5, ("init_q_enum_acct_rights\n"));
1478 init_dom_sid2(&in->sid, sid);
1481 /*******************************************************************
1482 ********************************************************************/
1483 NTSTATUS init_r_enum_acct_rights( LSA_R_ENUM_ACCT_RIGHTS *out, PRIVILEGE_SET *privileges )
1486 const char *privname;
1487 const char **privname_array = NULL;
1490 for ( i=0; i<privileges->count; i++ ) {
1491 privname = luid_to_privilege_name( &privileges->set[i].luid );
1493 if ( !add_string_to_array( talloc_tos(), privname, &privname_array, &num_priv ) )
1494 return NT_STATUS_NO_MEMORY;
1499 out->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
1501 return NT_STATUS_NO_MEMORY;
1504 if ( !init_unistr4_array( out->rights, num_priv, privname_array ) )
1505 return NT_STATUS_NO_MEMORY;
1507 out->count = num_priv;
1510 return NT_STATUS_OK;
1513 /*******************************************************************
1514 reads or writes a LSA_Q_ENUM_ACCT_RIGHTS structure.
1515 ********************************************************************/
1516 bool lsa_io_q_enum_acct_rights(const char *desc, LSA_Q_ENUM_ACCT_RIGHTS *in, prs_struct *ps, int depth)
1522 prs_debug(ps, depth, desc, "lsa_io_q_enum_acct_rights");
1525 if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1528 if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
1535 /*******************************************************************
1536 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
1537 ********************************************************************/
1538 bool lsa_io_r_enum_acct_rights(const char *desc, LSA_R_ENUM_ACCT_RIGHTS *out, prs_struct *ps, int depth)
1540 prs_debug(ps, depth, desc, "lsa_io_r_enum_acct_rights");
1543 if(!prs_uint32("count ", ps, depth, &out->count))
1546 if ( !prs_pointer("rights", ps, depth, (void*)&out->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
1552 if(!prs_ntstatus("status", ps, depth, &out->status))
1559 /*******************************************************************
1560 Inits an LSA_Q_ADD_ACCT_RIGHTS structure.
1561 ********************************************************************/
1562 void init_q_add_acct_rights( LSA_Q_ADD_ACCT_RIGHTS *in, POLICY_HND *hnd,
1563 DOM_SID *sid, uint32 count, const char **rights )
1565 DEBUG(5, ("init_q_add_acct_rights\n"));
1568 init_dom_sid2(&in->sid, sid);
1570 in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
1572 smb_panic("init_q_add_acct_rights: talloc fail\n");
1575 init_unistr4_array( in->rights, count, rights );
1581 /*******************************************************************
1582 reads or writes a LSA_Q_ADD_ACCT_RIGHTS structure.
1583 ********************************************************************/
1584 bool lsa_io_q_add_acct_rights(const char *desc, LSA_Q_ADD_ACCT_RIGHTS *in, prs_struct *ps, int depth)
1586 prs_debug(ps, depth, desc, "lsa_io_q_add_acct_rights");
1589 if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1592 if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
1595 if(!prs_uint32("count", ps, depth, &in->count))
1598 if ( !prs_pointer("rights", ps, depth, (void*)&in->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
1604 /*******************************************************************
1605 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
1606 ********************************************************************/
1607 bool lsa_io_r_add_acct_rights(const char *desc, LSA_R_ADD_ACCT_RIGHTS *out, prs_struct *ps, int depth)
1609 prs_debug(ps, depth, desc, "lsa_io_r_add_acct_rights");
1612 if(!prs_ntstatus("status", ps, depth, &out->status))
1618 /*******************************************************************
1619 Inits an LSA_Q_REMOVE_ACCT_RIGHTS structure.
1620 ********************************************************************/
1622 void init_q_remove_acct_rights(LSA_Q_REMOVE_ACCT_RIGHTS *in,
1627 const char **rights)
1629 DEBUG(5, ("init_q_remove_acct_rights\n"));
1633 init_dom_sid2(&in->sid, sid);
1635 in->removeall = removeall;
1638 in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
1640 smb_panic("init_q_remove_acct_rights: talloc fail\n");
1643 init_unistr4_array( in->rights, count, rights );
1646 /*******************************************************************
1647 reads or writes a LSA_Q_REMOVE_ACCT_RIGHTS structure.
1648 ********************************************************************/
1650 bool lsa_io_q_remove_acct_rights(const char *desc, LSA_Q_REMOVE_ACCT_RIGHTS *in, prs_struct *ps, int depth)
1652 prs_debug(ps, depth, desc, "lsa_io_q_remove_acct_rights");
1655 if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1658 if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
1661 if(!prs_uint32("removeall", ps, depth, &in->removeall))
1664 if(!prs_uint32("count", ps, depth, &in->count))
1667 if ( !prs_pointer("rights", ps, depth, (void*)&in->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
1673 /*******************************************************************
1674 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
1675 ********************************************************************/
1676 bool lsa_io_r_remove_acct_rights(const char *desc, LSA_R_REMOVE_ACCT_RIGHTS *out, prs_struct *ps, int depth)
1678 prs_debug(ps, depth, desc, "lsa_io_r_remove_acct_rights");
1681 if(!prs_ntstatus("status", ps, depth, &out->status))