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 /* Connect to SAMR database */
29 NTSTATUS cli_samr_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
30 uint32 access_mask, POLICY_HND *connect_pol)
32 prs_struct qbuf, rbuf;
35 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
40 /* Initialise parse structures */
42 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
43 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
45 /* Marshall data and send request */
47 init_samr_q_connect(&q, cli->desthost, access_mask);
49 if (!samr_io_q_connect("", &q, &qbuf, 0) ||
50 !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf))
53 /* Unmarshall response */
55 if (!samr_io_r_connect("", &r, &rbuf, 0))
58 /* Return output parameters */
60 if (NT_STATUS_IS_OK(result = r.status)) {
61 *connect_pol = r.connect_pol;
63 connect_pol->marker = malloc(1);
74 /* Close SAMR handle */
76 NTSTATUS cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
77 POLICY_HND *connect_pol)
79 prs_struct qbuf, rbuf;
82 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
87 /* Initialise parse structures */
89 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
90 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
92 /* Marshall data and send request */
94 init_samr_q_close_hnd(&q, connect_pol);
96 if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
97 !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf))
100 /* Unmarshall response */
102 if (!samr_io_r_close_hnd("", &r, &rbuf, 0))
105 /* Return output parameters */
107 if (NT_STATUS_IS_OK(result = r.status)) {
109 SAFE_FREE(connect_pol->marker);
111 *connect_pol = r.pol;
121 /* Open handle on a domain */
123 NTSTATUS cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
124 POLICY_HND *connect_pol, uint32 access_mask,
125 const DOM_SID *domain_sid, POLICY_HND *domain_pol)
127 prs_struct qbuf, rbuf;
128 SAMR_Q_OPEN_DOMAIN q;
129 SAMR_R_OPEN_DOMAIN r;
130 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
135 /* Initialise parse structures */
137 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
138 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
140 /* Marshall data and send request */
142 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
144 if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
145 !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf))
148 /* Unmarshall response */
150 if (!samr_io_r_open_domain("", &r, &rbuf, 0))
153 /* Return output parameters */
155 if (NT_STATUS_IS_OK(result = r.status)) {
156 *domain_pol = r.domain_pol;
158 domain_pol->marker = malloc(1);
169 /* Open handle on a user */
171 NTSTATUS cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
172 POLICY_HND *domain_pol, uint32 access_mask,
173 uint32 user_rid, POLICY_HND *user_pol)
175 prs_struct qbuf, rbuf;
178 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
183 /* Initialise parse structures */
185 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
186 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
188 /* Marshall data and send request */
190 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
192 if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
193 !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf))
196 /* Unmarshall response */
198 if (!samr_io_r_open_user("", &r, &rbuf, 0))
201 /* Return output parameters */
203 if (NT_STATUS_IS_OK(result = r.status)) {
204 *user_pol = r.user_pol;
206 user_pol->marker = malloc(1);
217 /* Open handle on a group */
219 NTSTATUS cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
220 POLICY_HND *domain_pol, uint32 access_mask,
221 uint32 group_rid, POLICY_HND *group_pol)
223 prs_struct qbuf, rbuf;
226 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
231 /* Initialise parse structures */
233 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
234 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
236 /* Marshall data and send request */
238 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
240 if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
241 !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf))
244 /* Unmarshall response */
246 if (!samr_io_r_open_group("", &r, &rbuf, 0))
249 /* Return output parameters */
251 if (NT_STATUS_IS_OK(result = r.status)) {
254 group_pol->marker = malloc(1);
265 /* Query user info */
267 NTSTATUS cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
268 POLICY_HND *user_pol, uint16 switch_value,
269 SAM_USERINFO_CTR **ctr)
271 prs_struct qbuf, rbuf;
272 SAMR_Q_QUERY_USERINFO q;
273 SAMR_R_QUERY_USERINFO r;
274 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
279 /* Initialise parse structures */
281 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
282 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
284 /* Marshall data and send request */
286 init_samr_q_query_userinfo(&q, user_pol, switch_value);
288 if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
289 !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf))
292 /* Unmarshall response */
294 if (!samr_io_r_query_userinfo("", &r, &rbuf, 0))
297 /* Return output parameters */
309 /* Query group info */
311 NTSTATUS cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
312 POLICY_HND *group_pol, uint32 info_level,
315 prs_struct qbuf, rbuf;
316 SAMR_Q_QUERY_GROUPINFO q;
317 SAMR_R_QUERY_GROUPINFO r;
318 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
323 /* Initialise parse structures */
325 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
326 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
328 /* Marshall data and send request */
330 init_samr_q_query_groupinfo(&q, group_pol, info_level);
332 if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
333 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf))
336 /* Unmarshall response */
340 if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0))
343 /* Return output parameters */
354 /* Query user groups */
356 NTSTATUS cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
357 POLICY_HND *user_pol, uint32 *num_groups,
360 prs_struct qbuf, rbuf;
361 SAMR_Q_QUERY_USERGROUPS q;
362 SAMR_R_QUERY_USERGROUPS r;
363 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
368 /* Initialise parse structures */
370 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
371 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
373 /* Marshall data and send request */
375 init_samr_q_query_usergroups(&q, user_pol);
377 if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
378 !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf))
381 /* Unmarshall response */
383 if (!samr_io_r_query_usergroups("", &r, &rbuf, 0))
386 /* Return output parameters */
388 if (NT_STATUS_IS_OK(result = r.status)) {
389 *num_groups = r.num_entries;
400 /* Query user aliases */
402 NTSTATUS cli_samr_query_useraliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
403 POLICY_HND *user_pol, uint32 num_sids, DOM_SID2 *sid,
404 uint32 *num_aliases, uint32 **als_rids)
406 prs_struct qbuf, rbuf;
407 SAMR_Q_QUERY_USERALIASES q;
408 SAMR_R_QUERY_USERALIASES r;
409 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
415 /* Initialise parse structures */
417 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
418 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
420 /* Marshall data and send request */
422 init_samr_q_query_useraliases(&q, user_pol, num_sids, &ptr, sid);
424 if (!samr_io_q_query_useraliases("", &q, &qbuf, 0) ||
425 !rpc_api_pipe_req(cli, SAMR_QUERY_USERALIASES, &qbuf, &rbuf))
428 /* Unmarshall response */
430 if (!samr_io_r_query_useraliases("", &r, &rbuf, 0))
433 /* Return output parameters */
435 if (NT_STATUS_IS_OK(result = r.status)) {
436 *num_aliases = r.num_entries;
447 /* Query user groups */
449 NTSTATUS cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
450 POLICY_HND *group_pol, uint32 *num_mem,
451 uint32 **rid, uint32 **attr)
453 prs_struct qbuf, rbuf;
454 SAMR_Q_QUERY_GROUPMEM q;
455 SAMR_R_QUERY_GROUPMEM r;
456 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
461 /* Initialise parse structures */
463 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
464 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
466 /* Marshall data and send request */
468 init_samr_q_query_groupmem(&q, group_pol);
470 if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
471 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf))
474 /* Unmarshall response */
476 if (!samr_io_r_query_groupmem("", &r, &rbuf, 0))
479 /* Return output parameters */
481 if (NT_STATUS_IS_OK(result = r.status)) {
482 *num_mem = r.num_entries;
494 /* Enumerate domain groups */
496 NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
497 POLICY_HND *pol, uint32 *start_idx,
498 uint32 size, struct acct_info **dom_groups,
499 uint32 *num_dom_groups)
501 prs_struct qbuf, rbuf;
502 SAMR_Q_ENUM_DOM_GROUPS q;
503 SAMR_R_ENUM_DOM_GROUPS r;
504 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
510 /* Initialise parse structures */
512 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
513 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
515 /* Marshall data and send request */
517 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
519 if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
520 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf))
523 /* Unmarshall response */
525 if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0))
528 /* Return output parameters */
532 if (!NT_STATUS_IS_OK(result) &&
533 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
536 *num_dom_groups = r.num_entries2;
538 if (!((*dom_groups) = (struct acct_info *)
539 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
540 result = NT_STATUS_UNSUCCESSFUL;
544 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
548 for (i = 0; i < *num_dom_groups; i++) {
550 (*dom_groups)[i].rid = r.sam[i].rid;
552 if (r.sam[i].hdr_name.buffer) {
553 unistr2_to_ascii((*dom_groups)[i].acct_name,
554 &r.uni_grp_name[name_idx],
555 sizeof(fstring) - 1);
559 *start_idx = r.next_idx;
569 /* Enumerate domain groups */
571 NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
572 POLICY_HND *pol, uint32 *start_idx,
573 uint32 size, struct acct_info **dom_groups,
574 uint32 *num_dom_groups)
576 prs_struct qbuf, rbuf;
577 SAMR_Q_ENUM_DOM_ALIASES q;
578 SAMR_R_ENUM_DOM_ALIASES r;
579 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
585 /* Initialise parse structures */
587 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
588 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
590 /* Marshall data and send request */
592 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
594 if (!samr_io_q_enum_dom_aliases("", &q, &qbuf, 0) ||
595 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_ALIASES, &qbuf, &rbuf)) {
599 /* Unmarshall response */
601 if (!samr_io_r_enum_dom_aliases("", &r, &rbuf, 0)) {
605 /* Return output parameters */
609 if (!NT_STATUS_IS_OK(result) &&
610 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
614 *num_dom_groups = r.num_entries2;
616 if (!((*dom_groups) = (struct acct_info *)
617 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
618 result = NT_STATUS_UNSUCCESSFUL;
622 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
626 for (i = 0; i < *num_dom_groups; i++) {
628 (*dom_groups)[i].rid = r.sam[i].rid;
630 if (r.sam[i].hdr_name.buffer) {
631 unistr2_to_ascii((*dom_groups)[i].acct_name,
632 &r.uni_grp_name[name_idx],
633 sizeof(fstring) - 1);
637 *start_idx = r.next_idx;
647 /* Query alias members */
649 NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
650 POLICY_HND *alias_pol, uint32 *num_mem,
653 prs_struct qbuf, rbuf;
654 SAMR_Q_QUERY_ALIASMEM q;
655 SAMR_R_QUERY_ALIASMEM r;
656 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
662 /* Initialise parse structures */
664 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
665 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
667 /* Marshall data and send request */
669 init_samr_q_query_aliasmem(&q, alias_pol);
671 if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
672 !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
676 /* Unmarshall response */
678 if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
682 /* Return output parameters */
684 if (!NT_STATUS_IS_OK(result = r.status)) {
688 *num_mem = r.num_sids;
690 if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
691 result = NT_STATUS_UNSUCCESSFUL;
695 for (i = 0; i < *num_mem; i++) {
696 (*sids)[i] = r.sid[i].sid;
706 /* Open handle on an alias */
708 NTSTATUS cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
709 POLICY_HND *domain_pol, uint32 access_mask,
710 uint32 alias_rid, POLICY_HND *alias_pol)
712 prs_struct qbuf, rbuf;
720 /* Initialise parse structures */
722 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
723 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
725 /* Marshall data and send request */
727 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
729 if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
730 !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
731 result = NT_STATUS_UNSUCCESSFUL;
735 /* Unmarshall response */
737 if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
738 result = NT_STATUS_UNSUCCESSFUL;
742 /* Return output parameters */
744 if (NT_STATUS_IS_OK(result = r.status)) {
747 alias_pol->marker = malloc(1);
758 /* Query domain info */
760 NTSTATUS cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
761 POLICY_HND *domain_pol, uint16 switch_value,
764 prs_struct qbuf, rbuf;
765 SAMR_Q_QUERY_DOMAIN_INFO q;
766 SAMR_R_QUERY_DOMAIN_INFO r;
767 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
772 /* Initialise parse structures */
774 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
775 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
777 /* Marshall data and send request */
779 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
781 if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
782 !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
786 /* Unmarshall response */
790 if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
794 /* Return output parameters */
796 if (!NT_STATUS_IS_OK(result = r.status)) {
807 /* Query display info */
809 NTSTATUS cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
810 POLICY_HND *domain_pol, uint32 *start_idx,
811 uint16 switch_value, uint32 *num_entries,
812 uint32 max_entries, SAM_DISPINFO_CTR *ctr)
814 prs_struct qbuf, rbuf;
815 SAMR_Q_QUERY_DISPINFO q;
816 SAMR_R_QUERY_DISPINFO r;
817 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
822 /* Initialise parse structures */
824 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
825 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
827 /* Marshall data and send request */
829 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
830 *start_idx, max_entries);
832 if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
833 !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
837 /* Unmarshall response */
841 if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
845 /* Return output parameters */
849 if (!NT_STATUS_IS_OK(result) &&
850 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
854 *num_entries = r.num_entries;
855 *start_idx += r.num_entries; /* No next_idx in this structure! */
864 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
865 looked up in one packet. */
867 NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
868 POLICY_HND *domain_pol, uint32 flags,
869 uint32 num_rids, uint32 *rids,
870 uint32 *num_names, char ***names,
873 prs_struct qbuf, rbuf;
874 SAMR_Q_LOOKUP_RIDS q;
875 SAMR_R_LOOKUP_RIDS r;
876 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
879 if (num_rids > 1000) {
880 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
881 "more than ~1000 rids are looked up at once.\n"));
887 /* Initialise parse structures */
889 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
890 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
892 /* Marshall data and send request */
894 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
897 if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
898 !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
902 /* Unmarshall response */
904 if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
908 /* Return output parameters */
910 if (!NT_STATUS_IS_OK(result = r.status)) {
914 if (r.num_names1 == 0) {
920 *num_names = r.num_names1;
921 *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
922 *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
924 for (i = 0; i < r.num_names1; i++) {
927 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
928 (*names)[i] = talloc_strdup(mem_ctx, tmp);
929 (*name_types)[i] = r.type[i];
941 NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
942 POLICY_HND *domain_pol, uint32 flags,
943 uint32 num_names, const char **names,
944 uint32 *num_rids, uint32 **rids,
947 prs_struct qbuf, rbuf;
948 SAMR_Q_LOOKUP_NAMES q;
949 SAMR_R_LOOKUP_NAMES r;
950 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
956 /* Initialise parse structures */
958 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
959 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
961 /* Marshall data and send request */
963 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
966 if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
967 !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
971 /* Unmarshall response */
973 if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
977 /* Return output parameters */
979 if (!NT_STATUS_IS_OK(result = r.status)) {
983 if (r.num_rids1 == 0) {
988 *num_rids = r.num_rids1;
989 *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
990 *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
992 for (i = 0; i < r.num_rids1; i++) {
993 (*rids)[i] = r.rids[i];
994 (*rid_types)[i] = r.types[i];
1004 /* Create a domain user */
1006 NTSTATUS cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1007 POLICY_HND *domain_pol, const char *acct_name,
1008 uint32 acb_info, uint32 unknown,
1009 POLICY_HND *user_pol, uint32 *rid)
1011 prs_struct qbuf, rbuf;
1012 SAMR_Q_CREATE_USER q;
1013 SAMR_R_CREATE_USER r;
1014 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1019 /* Initialise parse structures */
1021 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1022 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1024 /* Marshall data and send request */
1026 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1028 if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
1029 !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
1033 /* Unmarshall response */
1035 if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
1039 /* Return output parameters */
1041 if (!NT_STATUS_IS_OK(result = r.status)) {
1046 *user_pol = r.user_pol;
1052 prs_mem_free(&qbuf);
1053 prs_mem_free(&rbuf);
1060 NTSTATUS cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1061 POLICY_HND *user_pol, uint16 switch_value,
1062 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1064 prs_struct qbuf, rbuf;
1065 SAMR_Q_SET_USERINFO q;
1066 SAMR_R_SET_USERINFO r;
1067 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1072 /* Initialise parse structures */
1074 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1075 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1077 /* Marshall data and send request */
1081 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1084 if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
1085 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
1089 /* Unmarshall response */
1091 if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
1095 /* Return output parameters */
1097 if (!NT_STATUS_IS_OK(result = r.status)) {
1102 prs_mem_free(&qbuf);
1103 prs_mem_free(&rbuf);
1110 NTSTATUS cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1111 POLICY_HND *user_pol, uint16 switch_value,
1112 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1114 prs_struct qbuf, rbuf;
1115 SAMR_Q_SET_USERINFO2 q;
1116 SAMR_R_SET_USERINFO2 r;
1117 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1122 /* Initialise parse structures */
1124 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1125 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1127 /* Marshall data and send request */
1129 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1131 if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
1132 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
1136 /* Unmarshall response */
1138 if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
1142 /* Return output parameters */
1144 if (!NT_STATUS_IS_OK(result = r.status)) {
1149 prs_mem_free(&qbuf);
1150 prs_mem_free(&rbuf);
1155 /* Delete domain user */
1157 NTSTATUS cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1158 POLICY_HND *user_pol)
1160 prs_struct qbuf, rbuf;
1161 SAMR_Q_DELETE_DOM_USER q;
1162 SAMR_R_DELETE_DOM_USER r;
1163 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1168 /* Initialise parse structures */
1170 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1171 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1173 /* Marshall data and send request */
1175 init_samr_q_delete_dom_user(&q, user_pol);
1177 if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
1178 !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
1182 /* Unmarshall response */
1184 if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
1188 /* Return output parameters */
1193 prs_mem_free(&qbuf);
1194 prs_mem_free(&rbuf);
1199 /* Query user security object */
1201 NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1202 POLICY_HND *user_pol, uint16 switch_value,
1203 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1205 prs_struct qbuf, rbuf;
1206 SAMR_Q_QUERY_SEC_OBJ q;
1207 SAMR_R_QUERY_SEC_OBJ r;
1208 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1213 /* Initialise parse structures */
1215 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1216 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1218 /* Marshall data and send request */
1220 init_samr_q_query_sec_obj(&q, user_pol, switch_value);
1222 if (!samr_io_q_query_sec_obj("", &q, &qbuf, 0) ||
1223 !rpc_api_pipe_req(cli, SAMR_QUERY_SEC_OBJECT, &qbuf, &rbuf)) {
1227 /* Unmarshall response */
1229 if (!samr_io_r_query_sec_obj("", &r, &rbuf, 0)) {
1233 /* Return output parameters */
1236 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1239 prs_mem_free(&qbuf);
1240 prs_mem_free(&rbuf);
1245 /* Get domain password info */
1247 NTSTATUS cli_samr_get_dom_pwinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1248 uint16 *unk_0, uint16 *unk_1, uint16 *unk_2)
1250 prs_struct qbuf, rbuf;
1251 SAMR_Q_GET_DOM_PWINFO q;
1252 SAMR_R_GET_DOM_PWINFO r;
1253 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1258 /* Initialise parse structures */
1260 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1261 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1263 /* Marshall data and send request */
1265 init_samr_q_get_dom_pwinfo(&q, cli->desthost);
1267 if (!samr_io_q_get_dom_pwinfo("", &q, &qbuf, 0) ||
1268 !rpc_api_pipe_req(cli, SAMR_GET_DOM_PWINFO, &qbuf, &rbuf))
1271 /* Unmarshall response */
1273 if (!samr_io_r_get_dom_pwinfo("", &r, &rbuf, 0))
1276 /* Return output parameters */
1280 if (NT_STATUS_IS_OK(result)) {
1290 prs_mem_free(&qbuf);
1291 prs_mem_free(&rbuf);