2 Unix SMB/CIFS implementation.
4 Copyright (C) Tim Potter 2000-2001,
5 Copyright (C) Andrew Tridgell 1992-1997,2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
7 Copyright (C) Paul Ashton 1997,2000,
8 Copyright (C) Elrond 2000.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /* Opens a SMB connection to the SAMR pipe */
29 struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
30 struct ntuser_creds *creds)
32 return cli_pipe_initialise(cli, system_name, PIPE_SAMR, creds);
35 /* Connect to SAMR database */
37 NTSTATUS cli_samr_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
38 uint32 access_mask, POLICY_HND *connect_pol)
40 prs_struct qbuf, rbuf;
43 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
48 /* Initialise parse structures */
50 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
51 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
53 /* Marshall data and send request */
55 init_samr_q_connect(&q, cli->desthost, access_mask);
57 if (!samr_io_q_connect("", &q, &qbuf, 0) ||
58 !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf)) {
62 /* Unmarshall response */
64 if (!samr_io_r_connect("", &r, &rbuf, 0)) {
68 /* Return output parameters */
70 if (NT_STATUS_IS_OK(result = r.status)) {
71 *connect_pol = r.connect_pol;
73 connect_pol->marker = malloc(1);
84 /* Close SAMR handle */
86 NTSTATUS cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
87 POLICY_HND *connect_pol)
89 prs_struct qbuf, rbuf;
92 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
97 /* Initialise parse structures */
99 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
100 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
102 /* Marshall data and send request */
104 init_samr_q_close_hnd(&q, connect_pol);
106 if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
107 !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf)) {
111 /* Unmarshall response */
113 if (!samr_io_r_close_hnd("", &r, &rbuf, 0)) {
117 /* Return output parameters */
119 if (NT_STATUS_IS_OK(result = r.status)) {
121 SAFE_FREE(connect_pol->marker);
123 *connect_pol = r.pol;
133 /* Open handle on a domain */
135 NTSTATUS cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
136 POLICY_HND *connect_pol, uint32 access_mask,
137 const DOM_SID *domain_sid, POLICY_HND *domain_pol)
139 prs_struct qbuf, rbuf;
140 SAMR_Q_OPEN_DOMAIN q;
141 SAMR_R_OPEN_DOMAIN r;
142 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
147 /* Initialise parse structures */
149 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
150 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
152 /* Marshall data and send request */
154 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
156 if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
157 !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf)) {
161 /* Unmarshall response */
163 if (!samr_io_r_open_domain("", &r, &rbuf, 0)) {
167 /* Return output parameters */
169 if (NT_STATUS_IS_OK(result = r.status)) {
170 *domain_pol = r.domain_pol;
172 domain_pol->marker = malloc(1);
183 /* Open handle on a user */
185 NTSTATUS cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
186 POLICY_HND *domain_pol, uint32 access_mask,
187 uint32 user_rid, POLICY_HND *user_pol)
189 prs_struct qbuf, rbuf;
192 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
197 /* Initialise parse structures */
199 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
200 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
202 /* Marshall data and send request */
204 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
206 if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
207 !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf)) {
211 /* Unmarshall response */
213 if (!samr_io_r_open_user("", &r, &rbuf, 0)) {
217 /* Return output parameters */
219 if (NT_STATUS_IS_OK(result = r.status)) {
220 *user_pol = r.user_pol;
222 user_pol->marker = malloc(1);
233 /* Open handle on a group */
235 NTSTATUS cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
236 POLICY_HND *domain_pol, uint32 access_mask,
237 uint32 group_rid, POLICY_HND *group_pol)
239 prs_struct qbuf, rbuf;
242 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
247 /* Initialise parse structures */
249 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
250 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
252 /* Marshall data and send request */
254 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
256 if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
257 !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf)) {
261 /* Unmarshall response */
263 if (!samr_io_r_open_group("", &r, &rbuf, 0)) {
267 /* Return output parameters */
269 if (NT_STATUS_IS_OK(result = r.status)) {
272 group_pol->marker = malloc(1);
283 /* Query user info */
285 NTSTATUS cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
286 POLICY_HND *user_pol, uint16 switch_value,
287 SAM_USERINFO_CTR **ctr)
289 prs_struct qbuf, rbuf;
290 SAMR_Q_QUERY_USERINFO q;
291 SAMR_R_QUERY_USERINFO r;
292 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
297 /* Initialise parse structures */
299 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
300 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
302 /* Marshall data and send request */
304 init_samr_q_query_userinfo(&q, user_pol, switch_value);
306 if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
307 !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf)) {
311 /* Unmarshall response */
313 if (!samr_io_r_query_userinfo("", &r, &rbuf, 0)) {
317 /* Return output parameters */
329 /* Query group info */
331 NTSTATUS cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
332 POLICY_HND *group_pol, uint32 info_level,
335 prs_struct qbuf, rbuf;
336 SAMR_Q_QUERY_GROUPINFO q;
337 SAMR_R_QUERY_GROUPINFO r;
338 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
343 /* Initialise parse structures */
345 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
346 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
348 /* Marshall data and send request */
350 init_samr_q_query_groupinfo(&q, group_pol, info_level);
352 if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
353 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf)) {
357 /* Unmarshall response */
361 if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0)) {
365 /* Return output parameters */
376 /* Query user groups */
378 NTSTATUS cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
379 POLICY_HND *user_pol, uint32 *num_groups,
382 prs_struct qbuf, rbuf;
383 SAMR_Q_QUERY_USERGROUPS q;
384 SAMR_R_QUERY_USERGROUPS r;
385 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
390 /* Initialise parse structures */
392 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
393 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
395 /* Marshall data and send request */
397 init_samr_q_query_usergroups(&q, user_pol);
399 if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
400 !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf)) {
404 /* Unmarshall response */
406 if (!samr_io_r_query_usergroups("", &r, &rbuf, 0)) {
410 /* Return output parameters */
412 if (NT_STATUS_IS_OK(result = r.status)) {
413 *num_groups = r.num_entries;
424 /* Query user aliases */
426 NTSTATUS cli_samr_query_useraliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
427 POLICY_HND *user_pol, uint32 num_sids, DOM_SID2 *sid,
428 uint32 *num_aliases, uint32 **als_rids)
430 prs_struct qbuf, rbuf;
431 SAMR_Q_QUERY_USERALIASES q;
432 SAMR_R_QUERY_USERALIASES r;
433 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
439 /* Initialise parse structures */
441 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
442 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
444 /* Marshall data and send request */
446 init_samr_q_query_useraliases(&q, user_pol, num_sids, &ptr, sid);
448 if (!samr_io_q_query_useraliases("", &q, &qbuf, 0) ||
449 !rpc_api_pipe_req(cli, SAMR_QUERY_USERALIASES, &qbuf, &rbuf)) {
453 /* Unmarshall response */
455 if (!samr_io_r_query_useraliases("", &r, &rbuf, 0)) {
459 /* Return output parameters */
461 if (NT_STATUS_IS_OK(result = r.status)) {
462 *num_aliases = r.num_entries;
473 /* Query user groups */
475 NTSTATUS cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
476 POLICY_HND *group_pol, uint32 *num_mem,
477 uint32 **rid, uint32 **attr)
479 prs_struct qbuf, rbuf;
480 SAMR_Q_QUERY_GROUPMEM q;
481 SAMR_R_QUERY_GROUPMEM r;
482 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
487 /* Initialise parse structures */
489 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
490 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
492 /* Marshall data and send request */
494 init_samr_q_query_groupmem(&q, group_pol);
496 if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
497 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf)) {
501 /* Unmarshall response */
503 if (!samr_io_r_query_groupmem("", &r, &rbuf, 0)) {
507 /* Return output parameters */
509 if (NT_STATUS_IS_OK(result = r.status)) {
510 *num_mem = r.num_entries;
522 /* Enumerate domain groups */
524 NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
525 POLICY_HND *pol, uint32 *start_idx,
526 uint32 size, struct acct_info **dom_groups,
527 uint32 *num_dom_groups)
529 prs_struct qbuf, rbuf;
530 SAMR_Q_ENUM_DOM_GROUPS q;
531 SAMR_R_ENUM_DOM_GROUPS r;
532 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
538 /* Initialise parse structures */
540 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
541 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
543 /* Marshall data and send request */
545 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
547 if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
548 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf)) {
552 /* Unmarshall response */
554 if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0)) {
558 /* Return output parameters */
562 if (!NT_STATUS_IS_OK(result) &&
563 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
567 *num_dom_groups = r.num_entries2;
569 if (!((*dom_groups) = (struct acct_info *)
570 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
571 result = NT_STATUS_UNSUCCESSFUL;
575 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
579 for (i = 0; i < *num_dom_groups; i++) {
581 (*dom_groups)[i].rid = r.sam[i].rid;
583 if (r.sam[i].hdr_name.buffer) {
584 unistr2_to_ascii((*dom_groups)[i].acct_name,
585 &r.uni_grp_name[name_idx],
586 sizeof(fstring) - 1);
590 *start_idx = r.next_idx;
600 /* Enumerate domain groups */
602 NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
603 POLICY_HND *pol, uint32 *start_idx,
604 uint32 size, struct acct_info **dom_groups,
605 uint32 *num_dom_groups)
607 prs_struct qbuf, rbuf;
608 SAMR_Q_ENUM_DOM_ALIASES q;
609 SAMR_R_ENUM_DOM_ALIASES r;
610 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
616 /* Initialise parse structures */
618 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
619 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
621 /* Marshall data and send request */
623 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
625 if (!samr_io_q_enum_dom_aliases("", &q, &qbuf, 0) ||
626 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_ALIASES, &qbuf, &rbuf)) {
630 /* Unmarshall response */
632 if (!samr_io_r_enum_dom_aliases("", &r, &rbuf, 0)) {
636 /* Return output parameters */
640 if (!NT_STATUS_IS_OK(result) &&
641 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
645 *num_dom_groups = r.num_entries2;
647 if (!((*dom_groups) = (struct acct_info *)
648 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
649 result = NT_STATUS_UNSUCCESSFUL;
653 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
657 for (i = 0; i < *num_dom_groups; i++) {
659 (*dom_groups)[i].rid = r.sam[i].rid;
661 if (r.sam[i].hdr_name.buffer) {
662 unistr2_to_ascii((*dom_groups)[i].acct_name,
663 &r.uni_grp_name[name_idx],
664 sizeof(fstring) - 1);
668 *start_idx = r.next_idx;
678 /* Query alias members */
680 NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
681 POLICY_HND *alias_pol, uint32 *num_mem,
684 prs_struct qbuf, rbuf;
685 SAMR_Q_QUERY_ALIASMEM q;
686 SAMR_R_QUERY_ALIASMEM r;
687 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
693 /* Initialise parse structures */
695 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
696 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
698 /* Marshall data and send request */
700 init_samr_q_query_aliasmem(&q, alias_pol);
702 if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
703 !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
707 /* Unmarshall response */
709 if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
713 /* Return output parameters */
715 if (!NT_STATUS_IS_OK(result = r.status)) {
719 *num_mem = r.num_sids;
721 if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
722 result = NT_STATUS_UNSUCCESSFUL;
726 for (i = 0; i < *num_mem; i++) {
727 (*sids)[i] = r.sid[i].sid;
737 /* Open handle on an alias */
739 NTSTATUS cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
740 POLICY_HND *domain_pol, uint32 access_mask,
741 uint32 alias_rid, POLICY_HND *alias_pol)
743 prs_struct qbuf, rbuf;
751 /* Initialise parse structures */
753 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
754 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
756 /* Marshall data and send request */
758 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
760 if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
761 !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
762 result = NT_STATUS_UNSUCCESSFUL;
766 /* Unmarshall response */
768 if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
769 result = NT_STATUS_UNSUCCESSFUL;
773 /* Return output parameters */
775 if (NT_STATUS_IS_OK(result = r.status)) {
778 alias_pol->marker = malloc(1);
789 /* Query domain info */
791 NTSTATUS cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
792 POLICY_HND *domain_pol, uint16 switch_value,
795 prs_struct qbuf, rbuf;
796 SAMR_Q_QUERY_DOMAIN_INFO q;
797 SAMR_R_QUERY_DOMAIN_INFO r;
798 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
803 /* Initialise parse structures */
805 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
806 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
808 /* Marshall data and send request */
810 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
812 if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
813 !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
817 /* Unmarshall response */
821 if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
825 /* Return output parameters */
827 if (!NT_STATUS_IS_OK(result = r.status)) {
838 /* Query display info */
840 NTSTATUS cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
841 POLICY_HND *domain_pol, uint32 *start_idx,
842 uint16 switch_value, uint32 *num_entries,
843 uint32 max_entries, SAM_DISPINFO_CTR *ctr)
845 prs_struct qbuf, rbuf;
846 SAMR_Q_QUERY_DISPINFO q;
847 SAMR_R_QUERY_DISPINFO r;
848 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
853 /* Initialise parse structures */
855 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
856 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
858 /* Marshall data and send request */
860 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
861 *start_idx, max_entries);
863 if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
864 !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
868 /* Unmarshall response */
872 if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
876 /* Return output parameters */
880 if (!NT_STATUS_IS_OK(result) &&
881 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
885 *num_entries = r.num_entries;
886 *start_idx += r.num_entries; /* No next_idx in this structure! */
895 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
896 looked up in one packet. */
898 NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
899 POLICY_HND *domain_pol, uint32 flags,
900 uint32 num_rids, uint32 *rids,
901 uint32 *num_names, char ***names,
904 prs_struct qbuf, rbuf;
905 SAMR_Q_LOOKUP_RIDS q;
906 SAMR_R_LOOKUP_RIDS r;
907 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
910 if (num_rids > 1000) {
911 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
912 "more than ~1000 rids are looked up at once.\n"));
918 /* Initialise parse structures */
920 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
921 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
923 /* Marshall data and send request */
925 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
928 if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
929 !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
933 /* Unmarshall response */
935 if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
939 /* Return output parameters */
941 if (!NT_STATUS_IS_OK(result = r.status)) {
945 if (r.num_names1 == 0) {
951 *num_names = r.num_names1;
952 *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
953 *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
955 for (i = 0; i < r.num_names1; i++) {
958 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
959 (*names)[i] = talloc_strdup(mem_ctx, tmp);
960 (*name_types)[i] = r.type[i];
972 NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
973 POLICY_HND *domain_pol, uint32 flags,
974 uint32 num_names, char **names,
975 uint32 *num_rids, uint32 **rids,
978 prs_struct qbuf, rbuf;
979 SAMR_Q_LOOKUP_NAMES q;
980 SAMR_R_LOOKUP_NAMES r;
981 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
987 /* Initialise parse structures */
989 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
990 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
992 /* Marshall data and send request */
994 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
997 if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
998 !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
1002 /* Unmarshall response */
1004 if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
1008 /* Return output parameters */
1010 if (!NT_STATUS_IS_OK(result = r.status)) {
1014 if (r.num_rids1 == 0) {
1019 *num_rids = r.num_rids1;
1020 *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1021 *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1023 for (i = 0; i < r.num_rids1; i++) {
1024 (*rids)[i] = r.rids[i];
1025 (*rid_types)[i] = r.types[i];
1029 prs_mem_free(&qbuf);
1030 prs_mem_free(&rbuf);
1035 /* Create a domain user */
1037 NTSTATUS cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1038 POLICY_HND *domain_pol, const char *acct_name,
1039 uint32 acb_info, uint32 unknown,
1040 POLICY_HND *user_pol, uint32 *rid)
1042 prs_struct qbuf, rbuf;
1043 SAMR_Q_CREATE_USER q;
1044 SAMR_R_CREATE_USER r;
1045 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1050 /* Initialise parse structures */
1052 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1053 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1055 /* Marshall data and send request */
1057 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1059 if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
1060 !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
1064 /* Unmarshall response */
1066 if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
1070 /* Return output parameters */
1072 if (!NT_STATUS_IS_OK(result = r.status)) {
1077 *user_pol = r.user_pol;
1083 prs_mem_free(&qbuf);
1084 prs_mem_free(&rbuf);
1091 NTSTATUS cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1092 POLICY_HND *user_pol, uint16 switch_value,
1093 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1095 prs_struct qbuf, rbuf;
1096 SAMR_Q_SET_USERINFO q;
1097 SAMR_R_SET_USERINFO r;
1098 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1103 /* Initialise parse structures */
1105 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1106 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1108 /* Marshall data and send request */
1112 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1115 if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
1116 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
1120 /* Unmarshall response */
1122 if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
1126 /* Return output parameters */
1128 if (!NT_STATUS_IS_OK(result = r.status)) {
1133 prs_mem_free(&qbuf);
1134 prs_mem_free(&rbuf);
1141 NTSTATUS cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1142 POLICY_HND *user_pol, uint16 switch_value,
1143 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1145 prs_struct qbuf, rbuf;
1146 SAMR_Q_SET_USERINFO2 q;
1147 SAMR_R_SET_USERINFO2 r;
1148 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1153 /* Initialise parse structures */
1155 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1156 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1158 /* Marshall data and send request */
1160 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1162 if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
1163 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
1167 /* Unmarshall response */
1169 if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
1173 /* Return output parameters */
1175 if (!NT_STATUS_IS_OK(result = r.status)) {
1180 prs_mem_free(&qbuf);
1181 prs_mem_free(&rbuf);
1186 /* Delete domain user */
1188 NTSTATUS cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1189 POLICY_HND *user_pol)
1191 prs_struct qbuf, rbuf;
1192 SAMR_Q_DELETE_DOM_USER q;
1193 SAMR_R_DELETE_DOM_USER r;
1194 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1199 /* Initialise parse structures */
1201 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1202 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1204 /* Marshall data and send request */
1206 init_samr_q_delete_dom_user(&q, user_pol);
1208 if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
1209 !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
1213 /* Unmarshall response */
1215 if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
1219 /* Return output parameters */
1224 prs_mem_free(&qbuf);
1225 prs_mem_free(&rbuf);
1230 /* Query user security object */
1232 NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1233 POLICY_HND *user_pol, uint16 switch_value,
1234 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1236 prs_struct qbuf, rbuf;
1237 SAMR_Q_QUERY_SEC_OBJ q;
1238 SAMR_R_QUERY_SEC_OBJ r;
1239 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1244 /* Initialise parse structures */
1246 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1247 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1249 /* Marshall data and send request */
1251 init_samr_q_query_sec_obj(&q, user_pol, switch_value);
1253 if (!samr_io_q_query_sec_obj("", &q, &qbuf, 0) ||
1254 !rpc_api_pipe_req(cli, SAMR_QUERY_SEC_OBJECT, &qbuf, &rbuf)) {
1258 /* Unmarshall response */
1260 if (!samr_io_r_query_sec_obj("", &r, &rbuf, 0)) {
1264 /* Return output parameters */
1267 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1270 prs_mem_free(&qbuf);
1271 prs_mem_free(&rbuf);