2 Unix SMB/Netbios implementation.
5 Copyright (C) Tim Potter 2000-2001,
6 Copyright (C) Andrew Tridgell 1992-1997,2000,
7 Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
8 Copyright (C) Paul Ashton 1997,2000,
9 Copyright (C) Elrond 2000.
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 2 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, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /* Opens a SMB connection to the SAMR pipe */
30 struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
31 struct ntuser_creds *creds)
33 return cli_pipe_initialise(cli, system_name, PIPE_SAMR, creds);
36 /* Connect to SAMR database */
38 NTSTATUS cli_samr_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
39 uint32 access_mask, POLICY_HND *connect_pol)
41 prs_struct qbuf, rbuf;
44 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
49 /* Initialise parse structures */
51 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
52 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
54 /* Marshall data and send request */
56 init_samr_q_connect(&q, cli->desthost, access_mask);
58 if (!samr_io_q_connect("", &q, &qbuf, 0) ||
59 !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf)) {
63 /* Unmarshall response */
65 if (!samr_io_r_connect("", &r, &rbuf, 0)) {
69 /* Return output parameters */
71 if (NT_STATUS_IS_OK(result = r.status)) {
72 *connect_pol = r.connect_pol;
82 /* Close SAMR handle */
84 NTSTATUS cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
85 POLICY_HND *connect_pol)
87 prs_struct qbuf, rbuf;
90 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
95 /* Initialise parse structures */
97 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
98 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
100 /* Marshall data and send request */
102 init_samr_q_close_hnd(&q, connect_pol);
104 if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
105 !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf)) {
109 /* Unmarshall response */
111 if (!samr_io_r_close_hnd("", &r, &rbuf, 0)) {
115 /* Return output parameters */
117 if (NT_STATUS_IS_OK(result = r.status)) {
118 *connect_pol = r.pol;
128 /* Open handle on a domain */
130 NTSTATUS cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
131 POLICY_HND *connect_pol, uint32 access_mask,
132 const DOM_SID *domain_sid, POLICY_HND *domain_pol)
134 prs_struct qbuf, rbuf;
135 SAMR_Q_OPEN_DOMAIN q;
136 SAMR_R_OPEN_DOMAIN r;
137 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
142 /* Initialise parse structures */
144 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
145 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
147 /* Marshall data and send request */
149 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
151 if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
152 !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf)) {
156 /* Unmarshall response */
158 if (!samr_io_r_open_domain("", &r, &rbuf, 0)) {
162 /* Return output parameters */
164 if (NT_STATUS_IS_OK(result = r.status)) {
165 *domain_pol = r.domain_pol;
175 /* Open handle on a user */
177 NTSTATUS cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
178 POLICY_HND *domain_pol, uint32 access_mask,
179 uint32 user_rid, POLICY_HND *user_pol)
181 prs_struct qbuf, rbuf;
184 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
189 /* Initialise parse structures */
191 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
192 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
194 /* Marshall data and send request */
196 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
198 if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
199 !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf)) {
203 /* Unmarshall response */
205 if (!samr_io_r_open_user("", &r, &rbuf, 0)) {
209 /* Return output parameters */
211 if (NT_STATUS_IS_OK(result = r.status)) {
212 *user_pol = r.user_pol;
222 /* Open handle on a group */
224 NTSTATUS cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
225 POLICY_HND *domain_pol, uint32 access_mask,
226 uint32 group_rid, POLICY_HND *group_pol)
228 prs_struct qbuf, rbuf;
231 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
236 /* Initialise parse structures */
238 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
239 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
241 /* Marshall data and send request */
243 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
245 if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
246 !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf)) {
250 /* Unmarshall response */
252 if (!samr_io_r_open_group("", &r, &rbuf, 0)) {
256 /* Return output parameters */
258 if (NT_STATUS_IS_OK(result = r.status)) {
269 /* Query user info */
271 NTSTATUS cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
272 POLICY_HND *user_pol, uint16 switch_value,
273 SAM_USERINFO_CTR **ctr)
275 prs_struct qbuf, rbuf;
276 SAMR_Q_QUERY_USERINFO q;
277 SAMR_R_QUERY_USERINFO r;
278 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
283 /* Initialise parse structures */
285 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
286 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
288 /* Marshall data and send request */
290 init_samr_q_query_userinfo(&q, user_pol, switch_value);
292 if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
293 !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf)) {
297 /* Unmarshall response */
299 if (!samr_io_r_query_userinfo("", &r, &rbuf, 0)) {
303 /* Return output parameters */
315 /* Query group info */
317 NTSTATUS cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
318 POLICY_HND *group_pol, uint32 info_level,
321 prs_struct qbuf, rbuf;
322 SAMR_Q_QUERY_GROUPINFO q;
323 SAMR_R_QUERY_GROUPINFO r;
324 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
329 /* Initialise parse structures */
331 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
332 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
334 /* Marshall data and send request */
336 init_samr_q_query_groupinfo(&q, group_pol, info_level);
338 if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
339 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf)) {
343 /* Unmarshall response */
347 if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0)) {
351 /* Return output parameters */
362 /* Query user groups */
364 NTSTATUS cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
365 POLICY_HND *user_pol, uint32 *num_groups,
368 prs_struct qbuf, rbuf;
369 SAMR_Q_QUERY_USERGROUPS q;
370 SAMR_R_QUERY_USERGROUPS r;
371 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
376 /* Initialise parse structures */
378 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
379 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
381 /* Marshall data and send request */
383 init_samr_q_query_usergroups(&q, user_pol);
385 if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
386 !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf)) {
390 /* Unmarshall response */
392 if (!samr_io_r_query_usergroups("", &r, &rbuf, 0)) {
396 /* Return output parameters */
398 if (NT_STATUS_IS_OK(result = r.status)) {
399 *num_groups = r.num_entries;
410 /* Query user aliases */
412 NTSTATUS cli_samr_query_useraliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
413 POLICY_HND *user_pol, uint32 num_sids, DOM_SID2 *sid,
414 uint32 *num_aliases, uint32 **als_rids)
416 prs_struct qbuf, rbuf;
417 SAMR_Q_QUERY_USERALIASES q;
418 SAMR_R_QUERY_USERALIASES r;
419 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
425 /* Initialise parse structures */
427 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
428 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
430 /* Marshall data and send request */
432 init_samr_q_query_useraliases(&q, user_pol, num_sids, &ptr, sid);
434 if (!samr_io_q_query_useraliases("", &q, &qbuf, 0) ||
435 !rpc_api_pipe_req(cli, SAMR_QUERY_USERALIASES, &qbuf, &rbuf)) {
439 /* Unmarshall response */
441 if (!samr_io_r_query_useraliases("", &r, &rbuf, 0)) {
445 /* Return output parameters */
447 if (NT_STATUS_IS_OK(result = r.status)) {
448 *num_aliases = r.num_entries;
459 /* Query user groups */
461 NTSTATUS cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
462 POLICY_HND *group_pol, uint32 *num_mem,
463 uint32 **rid, uint32 **attr)
465 prs_struct qbuf, rbuf;
466 SAMR_Q_QUERY_GROUPMEM q;
467 SAMR_R_QUERY_GROUPMEM r;
468 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
473 /* Initialise parse structures */
475 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
476 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
478 /* Marshall data and send request */
480 init_samr_q_query_groupmem(&q, group_pol);
482 if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
483 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf)) {
487 /* Unmarshall response */
489 if (!samr_io_r_query_groupmem("", &r, &rbuf, 0)) {
493 /* Return output parameters */
495 if (NT_STATUS_IS_OK(result = r.status)) {
496 *num_mem = r.num_entries;
508 /* Enumerate domain groups */
510 NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
511 POLICY_HND *pol, uint32 *start_idx,
512 uint32 size, struct acct_info **dom_groups,
513 uint32 *num_dom_groups)
515 prs_struct qbuf, rbuf;
516 SAMR_Q_ENUM_DOM_GROUPS q;
517 SAMR_R_ENUM_DOM_GROUPS r;
518 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
524 /* Initialise parse structures */
526 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
527 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
529 /* Marshall data and send request */
531 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
533 if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
534 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf)) {
538 /* Unmarshall response */
540 if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0)) {
544 /* Return output parameters */
548 if (!NT_STATUS_IS_OK(result) &&
549 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
553 *num_dom_groups = r.num_entries2;
555 if (!((*dom_groups) = (struct acct_info *)
556 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
557 result = NT_STATUS_UNSUCCESSFUL;
561 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
565 for (i = 0; i < *num_dom_groups; i++) {
567 (*dom_groups)[i].rid = r.sam[i].rid;
569 if (r.sam[i].hdr_name.buffer) {
570 unistr2_to_ascii((*dom_groups)[i].acct_name,
571 &r.uni_grp_name[name_idx],
572 sizeof(fstring) - 1);
576 *start_idx = r.next_idx;
586 /* Enumerate domain groups */
588 NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
589 POLICY_HND *pol, uint32 *start_idx,
590 uint32 size, struct acct_info **dom_groups,
591 uint32 *num_dom_groups)
593 prs_struct qbuf, rbuf;
594 SAMR_Q_ENUM_DOM_ALIASES q;
595 SAMR_R_ENUM_DOM_ALIASES r;
596 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
602 /* Initialise parse structures */
604 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
605 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
607 /* Marshall data and send request */
609 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
611 if (!samr_io_q_enum_dom_aliases("", &q, &qbuf, 0) ||
612 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_ALIASES, &qbuf, &rbuf)) {
616 /* Unmarshall response */
618 if (!samr_io_r_enum_dom_aliases("", &r, &rbuf, 0)) {
622 /* Return output parameters */
626 if (!NT_STATUS_IS_OK(result) &&
627 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
631 *num_dom_groups = r.num_entries2;
633 if (!((*dom_groups) = (struct acct_info *)
634 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
635 result = NT_STATUS_UNSUCCESSFUL;
639 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
643 for (i = 0; i < *num_dom_groups; i++) {
645 (*dom_groups)[i].rid = r.sam[i].rid;
647 if (r.sam[i].hdr_name.buffer) {
648 unistr2_to_ascii((*dom_groups)[i].acct_name,
649 &r.uni_grp_name[name_idx],
650 sizeof(fstring) - 1);
654 *start_idx = r.next_idx;
664 /* Query alias members */
666 NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
667 POLICY_HND *alias_pol, uint32 *num_mem,
670 prs_struct qbuf, rbuf;
671 SAMR_Q_QUERY_ALIASMEM q;
672 SAMR_R_QUERY_ALIASMEM r;
673 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
679 /* Initialise parse structures */
681 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
682 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
684 /* Marshall data and send request */
686 init_samr_q_query_aliasmem(&q, alias_pol);
688 if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
689 !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
693 /* Unmarshall response */
695 if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
699 /* Return output parameters */
701 if (!NT_STATUS_IS_OK(result = r.status)) {
705 *num_mem = r.num_sids;
707 if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
708 result = NT_STATUS_UNSUCCESSFUL;
712 for (i = 0; i < *num_mem; i++) {
713 (*sids)[i] = r.sid[i].sid;
723 /* Open handle on an alias */
725 NTSTATUS cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
726 POLICY_HND *domain_pol, uint32 access_mask,
727 uint32 alias_rid, POLICY_HND *alias_pol)
729 prs_struct qbuf, rbuf;
737 /* Initialise parse structures */
739 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
740 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
742 /* Marshall data and send request */
744 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
746 if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
747 !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
748 result = NT_STATUS_UNSUCCESSFUL;
752 /* Unmarshall response */
754 if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
755 result = NT_STATUS_UNSUCCESSFUL;
759 /* Return output parameters */
761 if (NT_STATUS_IS_OK(result = r.status)) {
772 /* Query domain info */
774 NTSTATUS cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
775 POLICY_HND *domain_pol, uint16 switch_value,
778 prs_struct qbuf, rbuf;
779 SAMR_Q_QUERY_DOMAIN_INFO q;
780 SAMR_R_QUERY_DOMAIN_INFO r;
781 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
786 /* Initialise parse structures */
788 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
789 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
791 /* Marshall data and send request */
793 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
795 if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
796 !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
800 /* Unmarshall response */
804 if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
808 /* Return output parameters */
810 if (!NT_STATUS_IS_OK(result = r.status)) {
821 /* Query display info */
823 NTSTATUS cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
824 POLICY_HND *domain_pol, uint32 *start_idx,
825 uint16 switch_value, uint32 *num_entries,
826 uint32 max_entries, SAM_DISPINFO_CTR *ctr)
828 prs_struct qbuf, rbuf;
829 SAMR_Q_QUERY_DISPINFO q;
830 SAMR_R_QUERY_DISPINFO r;
831 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
836 /* Initialise parse structures */
838 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
839 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
841 /* Marshall data and send request */
843 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
844 *start_idx, max_entries);
846 if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
847 !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
851 /* Unmarshall response */
855 if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
859 /* Return output parameters */
863 if (!NT_STATUS_IS_OK(result) &&
864 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
868 *num_entries = r.num_entries;
869 *start_idx += r.num_entries; /* No next_idx in this structure! */
878 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
879 looked up in one packet. */
881 NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
882 POLICY_HND *domain_pol, uint32 flags,
883 uint32 num_rids, uint32 *rids,
884 uint32 *num_names, char ***names,
887 prs_struct qbuf, rbuf;
888 SAMR_Q_LOOKUP_RIDS q;
889 SAMR_R_LOOKUP_RIDS r;
890 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
893 if (num_rids > 1000) {
894 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
895 "more than ~1000 rids are looked up at once.\n"));
901 /* Initialise parse structures */
903 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
904 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
906 /* Marshall data and send request */
908 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
911 if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
912 !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
916 /* Unmarshall response */
918 if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
922 /* Return output parameters */
924 if (!NT_STATUS_IS_OK(result = r.status)) {
928 if (r.num_names1 == 0) {
934 *num_names = r.num_names1;
935 *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
936 *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
938 for (i = 0; i < r.num_names1; i++) {
941 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
942 (*names)[i] = talloc_strdup(mem_ctx, tmp);
943 (*name_types)[i] = r.type[i];
955 NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
956 POLICY_HND *domain_pol, uint32 flags,
957 uint32 num_names, char **names,
958 uint32 *num_rids, uint32 **rids,
961 prs_struct qbuf, rbuf;
962 SAMR_Q_LOOKUP_NAMES q;
963 SAMR_R_LOOKUP_NAMES r;
964 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
970 /* Initialise parse structures */
972 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
973 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
975 /* Marshall data and send request */
977 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
980 if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
981 !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
985 /* Unmarshall response */
987 if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
991 /* Return output parameters */
993 if (!NT_STATUS_IS_OK(result = r.status)) {
997 if (r.num_rids1 == 0) {
1002 *num_rids = r.num_rids1;
1003 *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1004 *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1006 for (i = 0; i < r.num_rids1; i++) {
1007 (*rids)[i] = r.rids[i];
1008 (*rid_types)[i] = r.types[i];
1012 prs_mem_free(&qbuf);
1013 prs_mem_free(&rbuf);
1018 /* Create a domain user */
1020 NTSTATUS cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1021 POLICY_HND *domain_pol, const char *acct_name,
1022 uint32 acb_info, uint32 unknown,
1023 POLICY_HND *user_pol, uint32 *rid)
1025 prs_struct qbuf, rbuf;
1026 SAMR_Q_CREATE_USER q;
1027 SAMR_R_CREATE_USER r;
1028 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1033 /* Initialise parse structures */
1035 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1036 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1038 /* Marshall data and send request */
1040 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1042 if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
1043 !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
1047 /* Unmarshall response */
1049 if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
1053 /* Return output parameters */
1055 if (!NT_STATUS_IS_OK(result = r.status)) {
1060 *user_pol = r.user_pol;
1066 prs_mem_free(&qbuf);
1067 prs_mem_free(&rbuf);
1074 NTSTATUS cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1075 POLICY_HND *user_pol, uint16 switch_value,
1076 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1078 prs_struct qbuf, rbuf;
1079 SAMR_Q_SET_USERINFO q;
1080 SAMR_R_SET_USERINFO r;
1081 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1086 /* Initialise parse structures */
1088 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1089 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1091 /* Marshall data and send request */
1095 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1098 if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
1099 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
1103 /* Unmarshall response */
1105 if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
1109 /* Return output parameters */
1111 if (!NT_STATUS_IS_OK(result = r.status)) {
1116 prs_mem_free(&qbuf);
1117 prs_mem_free(&rbuf);
1124 NTSTATUS cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1125 POLICY_HND *user_pol, uint16 switch_value,
1126 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1128 prs_struct qbuf, rbuf;
1129 SAMR_Q_SET_USERINFO2 q;
1130 SAMR_R_SET_USERINFO2 r;
1131 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1136 /* Initialise parse structures */
1138 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1139 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1141 /* Marshall data and send request */
1143 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1145 if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
1146 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
1150 /* Unmarshall response */
1152 if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
1156 /* Return output parameters */
1158 if (!NT_STATUS_IS_OK(result = r.status)) {
1163 prs_mem_free(&qbuf);
1164 prs_mem_free(&rbuf);
1169 /* Delete domain user */
1171 NTSTATUS cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1172 POLICY_HND *user_pol)
1174 prs_struct qbuf, rbuf;
1175 SAMR_Q_DELETE_DOM_USER q;
1176 SAMR_R_DELETE_DOM_USER r;
1177 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1182 /* Initialise parse structures */
1184 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1185 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1187 /* Marshall data and send request */
1189 init_samr_q_delete_dom_user(&q, user_pol);
1191 if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
1192 !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
1196 /* Unmarshall response */
1198 if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
1202 /* Return output parameters */
1207 prs_mem_free(&qbuf);
1208 prs_mem_free(&rbuf);
1213 /* Query user security object */
1215 NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1216 POLICY_HND *user_pol, uint16 switch_value,
1217 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1219 prs_struct qbuf, rbuf;
1220 SAMR_Q_QUERY_SEC_OBJ q;
1221 SAMR_R_QUERY_SEC_OBJ r;
1222 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1227 /* Initialise parse structures */
1229 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1230 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1232 /* Marshall data and send request */
1234 init_samr_q_query_sec_obj(&q, user_pol, switch_value);
1236 if (!samr_io_q_query_sec_obj("", &q, &qbuf, 0) ||
1237 !rpc_api_pipe_req(cli, SAMR_QUERY_SEC_OBJECT, &qbuf, &rbuf)) {
1241 /* Unmarshall response */
1243 if (!samr_io_r_query_sec_obj("", &r, &rbuf, 0)) {
1247 /* Return output parameters */
1250 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1253 prs_mem_free(&qbuf);
1254 prs_mem_free(&rbuf);