2 Unix SMB/CIFS implementation.
4 Copyright (C) Tim Potter 2000-2001,
5 Copyright (C) Andrew Tridgell 1992-1997,2000,
6 Copyright (C) Rafal Szczesniak 2002.
7 Copyright (C) Jeremy Allison 2005.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /* Connect to SAMR database */
28 NTSTATUS rpccli_samr_connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
29 uint32 access_mask, POLICY_HND *connect_pol)
31 prs_struct qbuf, rbuf;
34 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
36 DEBUG(10,("cli_samr_connect to %s\n", cli->cli->desthost));
41 /* Marshall data and send request */
43 init_samr_q_connect(&q, cli->cli->desthost, access_mask);
45 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT,
50 NT_STATUS_UNSUCCESSFUL);
51 /* Return output parameters */
53 if (NT_STATUS_IS_OK(result = r.status)) {
54 *connect_pol = r.connect_pol;
60 /* Connect to SAMR database */
62 NTSTATUS rpccli_samr_connect4(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
63 uint32 access_mask, POLICY_HND *connect_pol)
65 prs_struct qbuf, rbuf;
68 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
73 /* Marshall data and send request */
75 init_samr_q_connect4(&q, cli->cli->desthost, access_mask);
77 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT4,
82 NT_STATUS_UNSUCCESSFUL);
84 /* Return output parameters */
86 if (NT_STATUS_IS_OK(result = r.status)) {
87 *connect_pol = r.connect_pol;
93 /* Close SAMR handle */
95 NTSTATUS rpccli_samr_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
96 POLICY_HND *connect_pol)
98 prs_struct qbuf, rbuf;
101 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
103 DEBUG(10,("cli_samr_close\n"));
108 /* Marshall data and send request */
110 init_samr_q_close_hnd(&q, connect_pol);
112 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CLOSE_HND,
117 NT_STATUS_UNSUCCESSFUL);
119 /* Return output parameters */
121 if (NT_STATUS_IS_OK(result = r.status)) {
122 *connect_pol = r.pol;
128 /* Open handle on a domain */
130 NTSTATUS rpccli_samr_open_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
131 POLICY_HND *connect_pol, uint32 access_mask,
132 const DOM_SID *domain_sid,
133 POLICY_HND *domain_pol)
135 prs_struct qbuf, rbuf;
136 SAMR_Q_OPEN_DOMAIN q;
137 SAMR_R_OPEN_DOMAIN r;
138 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
140 DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(domain_sid) ));
145 /* Marshall data and send request */
147 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
149 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_DOMAIN,
152 samr_io_q_open_domain,
153 samr_io_r_open_domain,
154 NT_STATUS_UNSUCCESSFUL);
156 /* Return output parameters */
158 if (NT_STATUS_IS_OK(result = r.status)) {
159 *domain_pol = r.domain_pol;
165 NTSTATUS rpccli_samr_open_user(struct rpc_pipe_client *cli,
167 POLICY_HND *domain_pol, uint32 access_mask,
168 uint32 user_rid, POLICY_HND *user_pol)
170 prs_struct qbuf, rbuf;
173 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
175 DEBUG(10,("cli_samr_open_user with rid 0x%x\n", user_rid ));
180 /* Marshall data and send request */
182 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
184 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_USER,
189 NT_STATUS_UNSUCCESSFUL);
191 /* Return output parameters */
193 if (NT_STATUS_IS_OK(result = r.status)) {
194 *user_pol = r.user_pol;
200 /* Open handle on a group */
202 NTSTATUS rpccli_samr_open_group(struct rpc_pipe_client *cli,
204 POLICY_HND *domain_pol, uint32 access_mask,
205 uint32 group_rid, POLICY_HND *group_pol)
207 prs_struct qbuf, rbuf;
210 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
212 DEBUG(10,("cli_samr_open_group with rid 0x%x\n", group_rid ));
217 /* Marshall data and send request */
219 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
221 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_GROUP,
224 samr_io_q_open_group,
225 samr_io_r_open_group,
226 NT_STATUS_UNSUCCESSFUL);
228 /* Return output parameters */
230 if (NT_STATUS_IS_OK(result = r.status)) {
237 /* Create domain group */
239 NTSTATUS rpccli_samr_create_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
240 POLICY_HND *domain_pol,
241 const char *group_name,
242 uint32 access_mask, POLICY_HND *group_pol)
244 prs_struct qbuf, rbuf;
245 SAMR_Q_CREATE_DOM_GROUP q;
246 SAMR_R_CREATE_DOM_GROUP r;
247 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
249 DEBUG(10,("cli_samr_create_dom_group\n"));
254 /* Marshall data and send request */
256 init_samr_q_create_dom_group(&q, domain_pol, group_name, access_mask);
258 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_GROUP,
261 samr_io_q_create_dom_group,
262 samr_io_r_create_dom_group,
263 NT_STATUS_UNSUCCESSFUL);
265 /* Return output parameters */
269 if (NT_STATUS_IS_OK(result))
275 /* Add a domain group member */
277 NTSTATUS rpccli_samr_add_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
278 POLICY_HND *group_pol, uint32 rid)
280 prs_struct qbuf, rbuf;
281 SAMR_Q_ADD_GROUPMEM q;
282 SAMR_R_ADD_GROUPMEM r;
283 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
285 DEBUG(10,("cli_samr_add_groupmem\n"));
290 /* Marshall data and send request */
292 init_samr_q_add_groupmem(&q, group_pol, rid);
294 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_GROUPMEM,
297 samr_io_q_add_groupmem,
298 samr_io_r_add_groupmem,
299 NT_STATUS_UNSUCCESSFUL);
301 /* Return output parameters */
308 /* Delete a domain group member */
310 NTSTATUS rpccli_samr_del_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
311 POLICY_HND *group_pol, uint32 rid)
313 prs_struct qbuf, rbuf;
314 SAMR_Q_DEL_GROUPMEM q;
315 SAMR_R_DEL_GROUPMEM r;
316 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
318 DEBUG(10,("cli_samr_del_groupmem\n"));
323 /* Marshall data and send request */
325 init_samr_q_del_groupmem(&q, group_pol, rid);
327 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_GROUPMEM,
330 samr_io_q_del_groupmem,
331 samr_io_r_del_groupmem,
332 NT_STATUS_UNSUCCESSFUL);
334 /* Return output parameters */
341 /* Query user info */
343 NTSTATUS rpccli_samr_query_userinfo(struct rpc_pipe_client *cli,
345 const POLICY_HND *user_pol,
347 SAM_USERINFO_CTR **ctr)
349 prs_struct qbuf, rbuf;
350 SAMR_Q_QUERY_USERINFO q;
351 SAMR_R_QUERY_USERINFO r;
352 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
354 DEBUG(10,("cli_samr_query_userinfo\n"));
359 /* Marshall data and send request */
361 init_samr_q_query_userinfo(&q, user_pol, switch_value);
363 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERINFO,
366 samr_io_q_query_userinfo,
367 samr_io_r_query_userinfo,
368 NT_STATUS_UNSUCCESSFUL);
370 /* Return output parameters */
380 NTSTATUS rpccli_samr_set_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
381 POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
383 prs_struct qbuf, rbuf;
384 SAMR_Q_SET_GROUPINFO q;
385 SAMR_R_SET_GROUPINFO r;
386 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
388 DEBUG(10,("cli_samr_set_groupinfo\n"));
393 /* Marshall data and send request */
395 init_samr_q_set_groupinfo(&q, group_pol, ctr);
397 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_GROUPINFO,
400 samr_io_q_set_groupinfo,
401 samr_io_r_set_groupinfo,
402 NT_STATUS_UNSUCCESSFUL);
404 /* Return output parameters */
411 /* Query group info */
413 NTSTATUS rpccli_samr_query_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
414 POLICY_HND *group_pol, uint32 info_level,
415 GROUP_INFO_CTR **ctr)
417 prs_struct qbuf, rbuf;
418 SAMR_Q_QUERY_GROUPINFO q;
419 SAMR_R_QUERY_GROUPINFO r;
420 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
422 DEBUG(10,("cli_samr_query_groupinfo\n"));
427 /* Marshall data and send request */
429 init_samr_q_query_groupinfo(&q, group_pol, info_level);
431 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPINFO,
434 samr_io_q_query_groupinfo,
435 samr_io_r_query_groupinfo,
436 NT_STATUS_UNSUCCESSFUL);
440 /* Return output parameters */
447 /* Query user groups */
449 NTSTATUS rpccli_samr_query_usergroups(struct rpc_pipe_client *cli,
451 POLICY_HND *user_pol,
455 prs_struct qbuf, rbuf;
456 SAMR_Q_QUERY_USERGROUPS q;
457 SAMR_R_QUERY_USERGROUPS r;
458 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
460 DEBUG(10,("cli_samr_query_usergroups\n"));
465 /* Marshall data and send request */
467 init_samr_q_query_usergroups(&q, user_pol);
469 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERGROUPS,
472 samr_io_q_query_usergroups,
473 samr_io_r_query_usergroups,
474 NT_STATUS_UNSUCCESSFUL);
476 /* Return output parameters */
478 if (NT_STATUS_IS_OK(result = r.status)) {
479 *num_groups = r.num_entries;
488 NTSTATUS rpccli_samr_set_aliasinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
489 POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
491 prs_struct qbuf, rbuf;
492 SAMR_Q_SET_ALIASINFO q;
493 SAMR_R_SET_ALIASINFO r;
494 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
496 DEBUG(10,("cli_samr_set_aliasinfo\n"));
501 /* Marshall data and send request */
503 init_samr_q_set_aliasinfo(&q, alias_pol, ctr);
505 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_ALIASINFO,
508 samr_io_q_set_aliasinfo,
509 samr_io_r_set_aliasinfo,
510 NT_STATUS_UNSUCCESSFUL);
512 /* Return output parameters */
519 /* Query user aliases */
521 NTSTATUS rpccli_samr_query_useraliases(struct rpc_pipe_client *cli,
523 POLICY_HND *dom_pol, uint32 num_sids,
525 uint32 *num_aliases, uint32 **als_rids)
527 prs_struct qbuf, rbuf;
528 SAMR_Q_QUERY_USERALIASES q;
529 SAMR_R_QUERY_USERALIASES r;
530 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
534 DEBUG(10,("cli_samr_query_useraliases\n"));
539 sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
540 if (sid_ptrs == NULL)
541 return NT_STATUS_NO_MEMORY;
543 for (i=0; i<num_sids; i++)
546 /* Marshall data and send request */
548 init_samr_q_query_useraliases(&q, dom_pol, num_sids, sid_ptrs, sid);
550 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERALIASES,
553 samr_io_q_query_useraliases,
554 samr_io_r_query_useraliases,
555 NT_STATUS_UNSUCCESSFUL);
557 /* Return output parameters */
559 if (NT_STATUS_IS_OK(result = r.status)) {
560 *num_aliases = r.num_entries;
567 /* Query user groups */
569 NTSTATUS rpccli_samr_query_groupmem(struct rpc_pipe_client *cli,
571 POLICY_HND *group_pol, uint32 *num_mem,
572 uint32 **rid, uint32 **attr)
574 prs_struct qbuf, rbuf;
575 SAMR_Q_QUERY_GROUPMEM q;
576 SAMR_R_QUERY_GROUPMEM r;
577 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
579 DEBUG(10,("cli_samr_query_groupmem\n"));
584 /* Marshall data and send request */
586 init_samr_q_query_groupmem(&q, group_pol);
588 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPMEM,
591 samr_io_q_query_groupmem,
592 samr_io_r_query_groupmem,
593 NT_STATUS_UNSUCCESSFUL);
595 /* Return output parameters */
597 if (NT_STATUS_IS_OK(result = r.status)) {
598 *num_mem = r.num_entries;
607 * Enumerate domain users
609 * @param cli client state structure
610 * @param mem_ctx talloc context
611 * @param pol opened domain policy handle
612 * @param start_idx starting index of enumeration, returns context for
614 * @param acb_mask account control bit mask (to enumerate some particular
616 * @param size max acceptable size of response
617 * @param dom_users returned array of domain user names
618 * @param rids returned array of domain user RIDs
619 * @param num_dom_users numer returned entries
621 * @return NTSTATUS returned in rpc response
624 NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
625 POLICY_HND *pol, uint32 *start_idx, uint32 acb_mask,
626 uint32 size, char ***dom_users, uint32 **rids,
627 uint32 *num_dom_users)
631 SAMR_Q_ENUM_DOM_USERS q;
632 SAMR_R_ENUM_DOM_USERS r;
633 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
636 DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
641 /* always init this */
644 /* Fill query structure with parameters */
646 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, size);
648 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_USERS,
651 samr_io_q_enum_dom_users,
652 samr_io_r_enum_dom_users,
653 NT_STATUS_UNSUCCESSFUL);
657 if (!NT_STATUS_IS_OK(result) &&
658 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
661 *start_idx = r.next_idx;
662 *num_dom_users = r.num_entries2;
664 if (r.num_entries2) {
665 /* allocate memory needed to return received data */
666 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
668 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
669 return NT_STATUS_NO_MEMORY;
672 *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
674 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
675 return NT_STATUS_NO_MEMORY;
678 /* fill output buffers with rpc response */
679 for (i = 0; i < r.num_entries2; i++) {
682 (*rids)[i] = r.sam[i].rid;
683 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
684 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
692 /* Enumerate domain groups */
694 NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli,
696 POLICY_HND *pol, uint32 *start_idx,
697 uint32 size, struct acct_info **dom_groups,
698 uint32 *num_dom_groups)
700 prs_struct qbuf, rbuf;
701 SAMR_Q_ENUM_DOM_GROUPS q;
702 SAMR_R_ENUM_DOM_GROUPS r;
703 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
706 DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
711 /* Marshall data and send request */
713 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
715 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_GROUPS,
718 samr_io_q_enum_dom_groups,
719 samr_io_r_enum_dom_groups,
720 NT_STATUS_UNSUCCESSFUL);
722 /* Return output parameters */
726 if (!NT_STATUS_IS_OK(result) &&
727 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
730 *num_dom_groups = r.num_entries2;
732 if (*num_dom_groups == 0)
735 if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
736 result = NT_STATUS_NO_MEMORY;
740 memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
744 for (i = 0; i < *num_dom_groups; i++) {
746 (*dom_groups)[i].rid = r.sam[i].rid;
748 if (r.sam[i].hdr_name.buffer) {
749 unistr2_to_ascii((*dom_groups)[i].acct_name,
750 &r.uni_grp_name[name_idx],
751 sizeof(fstring) - 1);
755 *start_idx = r.next_idx;
762 /* Enumerate domain groups */
764 NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli,
766 POLICY_HND *pol, uint32 *start_idx,
767 uint32 size, struct acct_info **dom_aliases,
768 uint32 *num_dom_aliases)
770 prs_struct qbuf, rbuf;
771 SAMR_Q_ENUM_DOM_ALIASES q;
772 SAMR_R_ENUM_DOM_ALIASES r;
773 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
776 DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
781 /* Marshall data and send request */
783 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
785 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_ALIASES,
788 samr_io_q_enum_dom_aliases,
789 samr_io_r_enum_dom_aliases,
790 NT_STATUS_UNSUCCESSFUL);
792 /* Return output parameters */
796 if (!NT_STATUS_IS_OK(result) &&
797 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
801 *num_dom_aliases = r.num_entries2;
803 if (*num_dom_aliases == 0)
806 if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
807 result = NT_STATUS_NO_MEMORY;
811 memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
815 for (i = 0; i < *num_dom_aliases; i++) {
817 (*dom_aliases)[i].rid = r.sam[i].rid;
819 if (r.sam[i].hdr_name.buffer) {
820 unistr2_to_ascii((*dom_aliases)[i].acct_name,
821 &r.uni_grp_name[name_idx],
822 sizeof(fstring) - 1);
826 *start_idx = r.next_idx;
833 /* Query alias members */
835 NTSTATUS rpccli_samr_query_aliasmem(struct rpc_pipe_client *cli,
837 POLICY_HND *alias_pol, uint32 *num_mem,
840 prs_struct qbuf, rbuf;
841 SAMR_Q_QUERY_ALIASMEM q;
842 SAMR_R_QUERY_ALIASMEM r;
843 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
846 DEBUG(10,("cli_samr_query_aliasmem\n"));
851 /* Marshall data and send request */
853 init_samr_q_query_aliasmem(&q, alias_pol);
855 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASMEM,
858 samr_io_q_query_aliasmem,
859 samr_io_r_query_aliasmem,
860 NT_STATUS_UNSUCCESSFUL);
862 /* Return output parameters */
864 if (!NT_STATUS_IS_OK(result = r.status)) {
868 *num_mem = r.num_sids;
872 result = NT_STATUS_OK;
876 if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
877 result = NT_STATUS_UNSUCCESSFUL;
881 for (i = 0; i < *num_mem; i++) {
882 (*sids)[i] = r.sid[i].sid;
889 /* Open handle on an alias */
891 NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli,
893 POLICY_HND *domain_pol, uint32 access_mask,
894 uint32 alias_rid, POLICY_HND *alias_pol)
896 prs_struct qbuf, rbuf;
901 DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
906 /* Marshall data and send request */
908 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
910 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_ALIAS,
913 samr_io_q_open_alias,
914 samr_io_r_open_alias,
915 NT_STATUS_UNSUCCESSFUL);
917 /* Return output parameters */
919 if (NT_STATUS_IS_OK(result = r.status)) {
926 /* Create an alias */
928 NTSTATUS rpccli_samr_create_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
929 POLICY_HND *domain_pol, const char *name,
930 POLICY_HND *alias_pol)
932 prs_struct qbuf, rbuf;
933 SAMR_Q_CREATE_DOM_ALIAS q;
934 SAMR_R_CREATE_DOM_ALIAS r;
937 DEBUG(10,("cli_samr_create_dom_alias named %s\n", name));
942 /* Marshall data and send request */
944 init_samr_q_create_dom_alias(&q, domain_pol, name);
946 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_ALIAS,
949 samr_io_q_create_dom_alias,
950 samr_io_r_create_dom_alias,
951 NT_STATUS_UNSUCCESSFUL);
953 /* Return output parameters */
955 if (NT_STATUS_IS_OK(result = r.status)) {
956 *alias_pol = r.alias_pol;
962 /* Add an alias member */
964 NTSTATUS rpccli_samr_add_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
965 POLICY_HND *alias_pol, DOM_SID *member)
967 prs_struct qbuf, rbuf;
968 SAMR_Q_ADD_ALIASMEM q;
969 SAMR_R_ADD_ALIASMEM r;
972 DEBUG(10,("cli_samr_add_aliasmem"));
977 /* Marshall data and send request */
979 init_samr_q_add_aliasmem(&q, alias_pol, member);
981 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_ALIASMEM,
984 samr_io_q_add_aliasmem,
985 samr_io_r_add_aliasmem,
986 NT_STATUS_UNSUCCESSFUL);
993 /* Delete an alias member */
995 NTSTATUS rpccli_samr_del_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
996 POLICY_HND *alias_pol, DOM_SID *member)
998 prs_struct qbuf, rbuf;
999 SAMR_Q_DEL_ALIASMEM q;
1000 SAMR_R_DEL_ALIASMEM r;
1003 DEBUG(10,("cli_samr_del_aliasmem"));
1008 /* Marshall data and send request */
1010 init_samr_q_del_aliasmem(&q, alias_pol, member);
1012 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_ALIASMEM,
1015 samr_io_q_del_aliasmem,
1016 samr_io_r_del_aliasmem,
1017 NT_STATUS_UNSUCCESSFUL);
1024 /* Query alias info */
1026 NTSTATUS rpccli_samr_query_alias_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1027 POLICY_HND *alias_pol, uint16 switch_value,
1028 ALIAS_INFO_CTR *ctr)
1030 prs_struct qbuf, rbuf;
1031 SAMR_Q_QUERY_ALIASINFO q;
1032 SAMR_R_QUERY_ALIASINFO r;
1033 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1035 DEBUG(10,("cli_samr_query_alias_info\n"));
1040 /* Marshall data and send request */
1042 init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
1044 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASINFO,
1047 samr_io_q_query_aliasinfo,
1048 samr_io_r_query_aliasinfo,
1049 NT_STATUS_UNSUCCESSFUL);
1051 /* Return output parameters */
1053 if (!NT_STATUS_IS_OK(result = r.status)) {
1064 /* Query domain info */
1066 NTSTATUS rpccli_samr_query_dom_info(struct rpc_pipe_client *cli,
1067 TALLOC_CTX *mem_ctx,
1068 POLICY_HND *domain_pol,
1069 uint16 switch_value,
1072 prs_struct qbuf, rbuf;
1073 SAMR_Q_QUERY_DOMAIN_INFO q;
1074 SAMR_R_QUERY_DOMAIN_INFO r;
1075 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1077 DEBUG(10,("cli_samr_query_dom_info\n"));
1082 /* Marshall data and send request */
1084 init_samr_q_query_domain_info(&q, domain_pol, switch_value);
1088 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO,
1091 samr_io_q_query_domain_info,
1092 samr_io_r_query_domain_info,
1093 NT_STATUS_UNSUCCESSFUL);
1095 /* Return output parameters */
1097 if (!NT_STATUS_IS_OK(result = r.status)) {
1106 /* Query domain info2 */
1108 NTSTATUS rpccli_samr_query_dom_info2(struct rpc_pipe_client *cli,
1109 TALLOC_CTX *mem_ctx,
1110 POLICY_HND *domain_pol,
1111 uint16 switch_value,
1114 prs_struct qbuf, rbuf;
1115 SAMR_Q_QUERY_DOMAIN_INFO2 q;
1116 SAMR_R_QUERY_DOMAIN_INFO2 r;
1117 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1119 DEBUG(10,("cli_samr_query_dom_info2\n"));
1124 /* Marshall data and send request */
1126 init_samr_q_query_domain_info2(&q, domain_pol, switch_value);
1130 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO2,
1133 samr_io_q_query_domain_info2,
1134 samr_io_r_query_domain_info2,
1135 NT_STATUS_UNSUCCESSFUL);
1137 /* Return output parameters */
1139 if (!NT_STATUS_IS_OK(result = r.status)) {
1148 /* Set domain info */
1150 NTSTATUS rpccli_samr_set_domain_info(struct rpc_pipe_client *cli,
1151 TALLOC_CTX *mem_ctx,
1152 POLICY_HND *domain_pol,
1153 uint16 switch_value,
1156 prs_struct qbuf, rbuf;
1157 SAMR_Q_SET_DOMAIN_INFO q;
1158 SAMR_R_SET_DOMAIN_INFO r;
1159 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1161 DEBUG(10,("cli_samr_set_domain_info\n"));
1166 /* Marshall data and send request */
1168 init_samr_q_set_domain_info(&q, domain_pol, switch_value, ctr);
1170 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_DOMAIN_INFO,
1173 samr_io_q_set_domain_info,
1174 samr_io_r_set_domain_info,
1175 NT_STATUS_UNSUCCESSFUL);
1177 /* Return output parameters */
1179 if (!NT_STATUS_IS_OK(result = r.status)) {
1188 /* User change password */
1190 NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli,
1191 TALLOC_CTX *mem_ctx,
1192 const char *username,
1193 const char *newpassword,
1194 const char *oldpassword )
1196 uchar new_nt_password[516];
1197 uchar new_lm_password[516];
1198 uchar old_nt_hash[16];
1199 uchar old_lanman_hash[16];
1200 uchar old_nt_hash_enc[16];
1201 uchar old_lanman_hash_enc[16];
1203 uchar new_nt_hash[16];
1204 uchar new_lanman_hash[16];
1206 DEBUG(10,("rpccli_samr_chgpasswd_user\n"));
1208 /* Calculate the MD4 hash (NT compatible) of the password */
1209 E_md4hash(oldpassword, old_nt_hash);
1210 E_md4hash(newpassword, new_nt_hash);
1212 if (lp_client_lanman_auth()
1213 && E_deshash(newpassword, new_lanman_hash)
1214 && E_deshash(oldpassword, old_lanman_hash)) {
1215 /* E_deshash returns false for 'long' passwords (> 14
1216 DOS chars). This allows us to match Win2k, which
1217 does not store a LM hash for these passwords (which
1218 would reduce the effective password length to 14) */
1220 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1222 SamOEMhash( new_lm_password, old_nt_hash, 516);
1223 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1225 ZERO_STRUCT(new_lm_password);
1226 ZERO_STRUCT(old_lanman_hash_enc);
1229 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1231 SamOEMhash( new_nt_password, old_nt_hash, 516);
1232 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1234 return rpccli_samr_chng_pswd_auth_crap(cli, mem_ctx, username,
1235 data_blob_const(new_nt_password,sizeof(new_nt_password)),
1236 data_blob_const(old_nt_hash_enc,sizeof(old_nt_hash_enc)),
1237 data_blob_const(new_lm_password,sizeof(new_lm_password)),
1238 data_blob_const(old_lanman_hash_enc,sizeof(old_lanman_hash_enc)));
1241 /* User change passwd with auth crap */
1243 NTSTATUS rpccli_samr_chng_pswd_auth_crap(struct rpc_pipe_client *cli,
1244 TALLOC_CTX *mem_ctx,
1245 const char *username,
1246 DATA_BLOB new_nt_password,
1247 DATA_BLOB old_nt_hash_enc,
1248 DATA_BLOB new_lm_password,
1249 DATA_BLOB old_lm_hash_enc)
1251 prs_struct qbuf, rbuf;
1252 SAMR_Q_CHGPASSWD_USER q;
1253 SAMR_R_CHGPASSWD_USER r;
1254 char *srv_name_slash;
1256 if (!(srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s",
1257 cli->cli->desthost))) {
1258 return NT_STATUS_NO_MEMORY;
1261 DEBUG(5,("rpccli_samr_chng_pswd_auth_crap on server: %s\n",
1267 /* Marshall data and send request */
1269 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1270 new_nt_password.data,
1271 old_nt_hash_enc.data,
1272 new_lm_password.data,
1273 old_lm_hash_enc.data);
1275 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1278 samr_io_q_chgpasswd_user,
1279 samr_io_r_chgpasswd_user,
1280 NT_STATUS_UNSUCCESSFUL);
1285 /* change password 3 */
1287 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
1288 TALLOC_CTX *mem_ctx,
1289 const char *username,
1290 const char *newpassword,
1291 const char *oldpassword,
1292 SAM_UNK_INFO_1 *info,
1293 SAMR_CHANGE_REJECT *reject)
1295 prs_struct qbuf, rbuf;
1296 SAMR_Q_CHGPASSWD_USER3 q;
1297 SAMR_R_CHGPASSWD_USER3 r;
1299 uchar new_nt_password[516];
1300 uchar new_lm_password[516];
1301 uchar old_nt_hash[16];
1302 uchar old_lanman_hash[16];
1303 uchar old_nt_hash_enc[16];
1304 uchar old_lanman_hash_enc[16];
1306 uchar new_nt_hash[16];
1307 uchar new_lanman_hash[16];
1309 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1311 DEBUG(10,("rpccli_samr_chgpasswd_user3\n"));
1316 /* Calculate the MD4 hash (NT compatible) of the password */
1317 E_md4hash(oldpassword, old_nt_hash);
1318 E_md4hash(newpassword, new_nt_hash);
1320 if (lp_client_lanman_auth()
1321 && E_deshash(newpassword, new_lanman_hash)
1322 && E_deshash(oldpassword, old_lanman_hash)) {
1323 /* E_deshash returns false for 'long' passwords (> 14
1324 DOS chars). This allows us to match Win2k, which
1325 does not store a LM hash for these passwords (which
1326 would reduce the effective password length to 14) */
1328 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1330 SamOEMhash( new_lm_password, old_nt_hash, 516);
1331 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1333 ZERO_STRUCT(new_lm_password);
1334 ZERO_STRUCT(old_lanman_hash_enc);
1337 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1339 SamOEMhash( new_nt_password, old_nt_hash, 516);
1340 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1342 /* Marshall data and send request */
1344 init_samr_q_chgpasswd_user3(&q, srv_name_slash, username,
1348 old_lanman_hash_enc);
1352 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER3,
1355 samr_io_q_chgpasswd_user3,
1356 samr_io_r_chgpasswd_user3,
1357 NT_STATUS_UNSUCCESSFUL);
1359 /* Return output parameters */
1364 /* This function returns the bizzare set of (max_entries, max_size) required
1365 for the QueryDisplayInfo RPC to actually work against a domain controller
1366 with large (10k and higher) numbers of users. These values were
1367 obtained by inspection using ethereal and NT4 running User Manager. */
1369 void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
1372 switch(loop_count) {
1378 *max_entries = 1024;
1382 *max_entries = 2048;
1386 *max_entries = 4096;
1389 default: /* loop_count >= 4 */
1390 *max_entries = 4096;
1396 /* Query display info */
1398 NTSTATUS rpccli_samr_query_dispinfo(struct rpc_pipe_client *cli,
1399 TALLOC_CTX *mem_ctx,
1400 POLICY_HND *domain_pol, uint32 *start_idx,
1401 uint16 switch_value, uint32 *num_entries,
1402 uint32 max_entries, uint32 max_size,
1403 SAM_DISPINFO_CTR *ctr)
1405 prs_struct qbuf, rbuf;
1406 SAMR_Q_QUERY_DISPINFO q;
1407 SAMR_R_QUERY_DISPINFO r;
1408 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1410 DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
1417 /* Marshall data and send request */
1419 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1420 *start_idx, max_entries, max_size);
1424 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO,
1427 samr_io_q_query_dispinfo,
1428 samr_io_r_query_dispinfo,
1429 NT_STATUS_UNSUCCESSFUL);
1431 /* Return output parameters */
1435 if (!NT_STATUS_IS_OK(result) &&
1436 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1440 *num_entries = r.num_entries;
1441 *start_idx += r.num_entries; /* No next_idx in this structure! */
1448 /* Query display info2 */
1450 NTSTATUS rpccli_samr_query_dispinfo2(struct rpc_pipe_client *cli,
1451 TALLOC_CTX *mem_ctx,
1452 POLICY_HND *domain_pol, uint32 *start_idx,
1453 uint16 switch_value, uint32 *num_entries,
1454 uint32 max_entries, uint32 max_size,
1455 SAM_DISPINFO_CTR *ctr)
1457 prs_struct qbuf, rbuf;
1458 SAMR_Q_QUERY_DISPINFO q;
1459 SAMR_R_QUERY_DISPINFO r;
1460 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1462 DEBUG(10,("cli_samr_query_dispinfo2 for start_idx = %u\n", *start_idx));
1469 /* Marshall data and send request */
1471 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1472 *start_idx, max_entries, max_size);
1476 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO2,
1479 samr_io_q_query_dispinfo,
1480 samr_io_r_query_dispinfo,
1481 NT_STATUS_UNSUCCESSFUL);
1483 /* Return output parameters */
1487 if (!NT_STATUS_IS_OK(result) &&
1488 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1492 *num_entries = r.num_entries;
1493 *start_idx += r.num_entries; /* No next_idx in this structure! */
1499 /* Query display info */
1501 NTSTATUS rpccli_samr_query_dispinfo3(struct rpc_pipe_client *cli,
1502 TALLOC_CTX *mem_ctx,
1503 POLICY_HND *domain_pol, uint32 *start_idx,
1504 uint16 switch_value, uint32 *num_entries,
1505 uint32 max_entries, uint32 max_size,
1506 SAM_DISPINFO_CTR *ctr)
1508 prs_struct qbuf, rbuf;
1509 SAMR_Q_QUERY_DISPINFO q;
1510 SAMR_R_QUERY_DISPINFO r;
1511 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1513 DEBUG(10,("cli_samr_query_dispinfo3 for start_idx = %u\n", *start_idx));
1520 /* Marshall data and send request */
1522 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1523 *start_idx, max_entries, max_size);
1527 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO3,
1530 samr_io_q_query_dispinfo,
1531 samr_io_r_query_dispinfo,
1532 NT_STATUS_UNSUCCESSFUL);
1534 /* Return output parameters */
1538 if (!NT_STATUS_IS_OK(result) &&
1539 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1543 *num_entries = r.num_entries;
1544 *start_idx += r.num_entries; /* No next_idx in this structure! */
1550 /* Query display info index */
1552 NTSTATUS rpccli_samr_get_dispenum_index(struct rpc_pipe_client *cli,
1553 TALLOC_CTX *mem_ctx,
1554 POLICY_HND *domain_pol,
1555 uint16 switch_value,
1559 prs_struct qbuf, rbuf;
1560 SAMR_Q_GET_DISPENUM_INDEX q;
1561 SAMR_R_GET_DISPENUM_INDEX r;
1562 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1564 DEBUG(10,("cli_samr_get_dispenum_index for name = %s\n", name));
1569 /* Marshall data and send request */
1571 init_samr_q_get_dispenum_index(&q, domain_pol, switch_value, name);
1573 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DISPENUM_INDEX,
1576 samr_io_q_get_dispenum_index,
1577 samr_io_r_get_dispenum_index,
1578 NT_STATUS_UNSUCCESSFUL);
1580 /* Return output parameters */
1586 if (!NT_STATUS_IS_ERR(result)) {
1593 NTSTATUS rpccli_samr_get_dispenum_index2(struct rpc_pipe_client *cli,
1594 TALLOC_CTX *mem_ctx,
1595 POLICY_HND *domain_pol,
1596 uint16 switch_value,
1600 prs_struct qbuf, rbuf;
1601 SAMR_Q_GET_DISPENUM_INDEX q;
1602 SAMR_R_GET_DISPENUM_INDEX r;
1603 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1605 DEBUG(10,("cli_samr_get_dispenum_index2 for name = %s\n", name));
1610 /* Marshall data and send request */
1612 init_samr_q_get_dispenum_index(&q, domain_pol, switch_value, name);
1614 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DISPENUM_INDEX2,
1617 samr_io_q_get_dispenum_index,
1618 samr_io_r_get_dispenum_index,
1619 NT_STATUS_UNSUCCESSFUL);
1621 /* Return output parameters */
1627 if (!NT_STATUS_IS_ERR(result)) {
1635 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1636 looked up in one packet. */
1638 NTSTATUS rpccli_samr_lookup_rids(struct rpc_pipe_client *cli,
1639 TALLOC_CTX *mem_ctx,
1640 POLICY_HND *domain_pol,
1641 uint32 num_rids, uint32 *rids,
1642 uint32 *num_names, char ***names,
1643 uint32 **name_types)
1645 prs_struct qbuf, rbuf;
1646 SAMR_Q_LOOKUP_RIDS q;
1647 SAMR_R_LOOKUP_RIDS r;
1648 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1651 DEBUG(10,("cli_samr_lookup_rids\n"));
1653 if (num_rids > 1000) {
1654 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1655 "more than ~1000 rids are looked up at once.\n"));
1661 /* Marshall data and send request */
1663 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, 1000, num_rids, rids);
1665 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_RIDS,
1668 samr_io_q_lookup_rids,
1669 samr_io_r_lookup_rids,
1670 NT_STATUS_UNSUCCESSFUL);
1672 /* Return output parameters */
1676 if (!NT_STATUS_IS_OK(result) &&
1677 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1680 if (r.num_names1 == 0) {
1686 *num_names = r.num_names1;
1687 *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
1688 *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
1690 if ((*names == NULL) || (*name_types == NULL)) {
1691 TALLOC_FREE(*names);
1692 TALLOC_FREE(*name_types);
1693 return NT_STATUS_NO_MEMORY;
1696 for (i = 0; i < r.num_names1; i++) {
1699 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
1700 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1701 (*name_types)[i] = r.type[i];
1711 NTSTATUS rpccli_samr_lookup_names(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1712 POLICY_HND *domain_pol, uint32 flags,
1713 uint32 num_names, const char **names,
1714 uint32 *num_rids, uint32 **rids,
1717 prs_struct qbuf, rbuf;
1718 SAMR_Q_LOOKUP_NAMES q;
1719 SAMR_R_LOOKUP_NAMES r;
1720 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1723 DEBUG(10,("cli_samr_lookup_names\n"));
1728 /* Marshall data and send request */
1730 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1733 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_NAMES,
1736 samr_io_q_lookup_names,
1737 samr_io_r_lookup_names,
1738 NT_STATUS_UNSUCCESSFUL);
1740 /* Return output parameters */
1742 if (!NT_STATUS_IS_OK(result = r.status)) {
1746 if (r.num_rids1 == 0) {
1751 *num_rids = r.num_rids1;
1752 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1753 *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1755 if ((*rids == NULL) || (*rid_types == NULL)) {
1757 TALLOC_FREE(*rid_types);
1758 return NT_STATUS_NO_MEMORY;
1761 for (i = 0; i < r.num_rids1; i++) {
1762 (*rids)[i] = r.rids[i];
1763 (*rid_types)[i] = r.types[i];
1771 /* Create a domain user */
1773 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1774 POLICY_HND *domain_pol, const char *acct_name,
1775 uint32 acb_info, uint32 unknown,
1776 POLICY_HND *user_pol, uint32 *rid)
1778 prs_struct qbuf, rbuf;
1779 SAMR_Q_CREATE_USER q;
1780 SAMR_R_CREATE_USER r;
1781 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1783 DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
1788 /* Marshall data and send request */
1790 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1792 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
1795 samr_io_q_create_user,
1796 samr_io_r_create_user,
1797 NT_STATUS_UNSUCCESSFUL);
1799 /* Return output parameters */
1801 if (!NT_STATUS_IS_OK(result = r.status)) {
1806 *user_pol = r.user_pol;
1818 NTSTATUS rpccli_samr_set_userinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1819 const POLICY_HND *user_pol, uint16 switch_value,
1820 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1822 prs_struct qbuf, rbuf;
1823 SAMR_Q_SET_USERINFO q;
1824 SAMR_R_SET_USERINFO r;
1825 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1827 DEBUG(10,("cli_samr_set_userinfo\n"));
1832 if (!sess_key->length) {
1833 DEBUG(1, ("No user session key\n"));
1834 return NT_STATUS_NO_USER_SESSION_KEY;
1837 /* Initialise parse structures */
1839 prs_init(&qbuf, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1840 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1842 /* Marshall data and send request */
1846 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1849 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO,
1852 samr_io_q_set_userinfo,
1853 samr_io_r_set_userinfo,
1854 NT_STATUS_UNSUCCESSFUL);
1856 /* Return output parameters */
1858 if (!NT_STATUS_IS_OK(result = r.status)) {
1869 NTSTATUS rpccli_samr_set_userinfo2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1870 const POLICY_HND *user_pol, uint16 switch_value,
1871 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1873 prs_struct qbuf, rbuf;
1874 SAMR_Q_SET_USERINFO2 q;
1875 SAMR_R_SET_USERINFO2 r;
1876 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1878 DEBUG(10,("cli_samr_set_userinfo2\n"));
1880 if (!sess_key->length) {
1881 DEBUG(1, ("No user session key\n"));
1882 return NT_STATUS_NO_USER_SESSION_KEY;
1888 /* Marshall data and send request */
1890 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1892 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO2,
1895 samr_io_q_set_userinfo2,
1896 samr_io_r_set_userinfo2,
1897 NT_STATUS_UNSUCCESSFUL);
1899 /* Return output parameters */
1901 if (!NT_STATUS_IS_OK(result = r.status)) {
1910 /* Delete domain group */
1912 NTSTATUS rpccli_samr_delete_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1913 POLICY_HND *group_pol)
1915 prs_struct qbuf, rbuf;
1916 SAMR_Q_DELETE_DOM_GROUP q;
1917 SAMR_R_DELETE_DOM_GROUP r;
1918 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1920 DEBUG(10,("cli_samr_delete_dom_group\n"));
1925 /* Marshall data and send request */
1927 init_samr_q_delete_dom_group(&q, group_pol);
1929 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_GROUP,
1932 samr_io_q_delete_dom_group,
1933 samr_io_r_delete_dom_group,
1934 NT_STATUS_UNSUCCESSFUL);
1936 /* Return output parameters */
1943 /* Delete domain alias */
1945 NTSTATUS rpccli_samr_delete_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1946 POLICY_HND *alias_pol)
1948 prs_struct qbuf, rbuf;
1949 SAMR_Q_DELETE_DOM_ALIAS q;
1950 SAMR_R_DELETE_DOM_ALIAS r;
1951 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1953 DEBUG(10,("cli_samr_delete_dom_alias\n"));
1958 /* Marshall data and send request */
1960 init_samr_q_delete_dom_alias(&q, alias_pol);
1962 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_ALIAS,
1965 samr_io_q_delete_dom_alias,
1966 samr_io_r_delete_dom_alias,
1967 NT_STATUS_UNSUCCESSFUL);
1969 /* Return output parameters */
1976 /* Delete domain user */
1978 NTSTATUS rpccli_samr_delete_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1979 POLICY_HND *user_pol)
1981 prs_struct qbuf, rbuf;
1982 SAMR_Q_DELETE_DOM_USER q;
1983 SAMR_R_DELETE_DOM_USER r;
1984 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1986 DEBUG(10,("cli_samr_delete_dom_user\n"));
1991 /* Marshall data and send request */
1993 init_samr_q_delete_dom_user(&q, user_pol);
1995 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_USER,
1998 samr_io_q_delete_dom_user,
1999 samr_io_r_delete_dom_user,
2000 NT_STATUS_UNSUCCESSFUL);
2002 /* Return output parameters */
2009 /* Remove foreign SID */
2011 NTSTATUS rpccli_samr_remove_sid_foreign_domain(struct rpc_pipe_client *cli,
2012 TALLOC_CTX *mem_ctx,
2013 POLICY_HND *user_pol,
2016 prs_struct qbuf, rbuf;
2017 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN q;
2018 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN r;
2019 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2021 DEBUG(10,("cli_samr_remove_sid_foreign_domain\n"));
2026 /* Marshall data and send request */
2028 init_samr_q_remove_sid_foreign_domain(&q, user_pol, sid);
2030 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_REMOVE_SID_FOREIGN_DOMAIN,
2033 samr_io_q_remove_sid_foreign_domain,
2034 samr_io_r_remove_sid_foreign_domain,
2035 NT_STATUS_UNSUCCESSFUL);
2037 /* Return output parameters */
2044 /* Query user security object */
2046 NTSTATUS rpccli_samr_query_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2047 POLICY_HND *user_pol, uint32 sec_info,
2048 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
2050 prs_struct qbuf, rbuf;
2051 SAMR_Q_QUERY_SEC_OBJ q;
2052 SAMR_R_QUERY_SEC_OBJ r;
2053 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2055 DEBUG(10,("cli_samr_query_sec_obj\n"));
2060 /* Marshall data and send request */
2062 init_samr_q_query_sec_obj(&q, user_pol, sec_info);
2064 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_SEC_OBJECT,
2067 samr_io_q_query_sec_obj,
2068 samr_io_r_query_sec_obj,
2069 NT_STATUS_UNSUCCESSFUL);
2071 /* Return output parameters */
2074 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
2079 /* Set user security object */
2081 NTSTATUS rpccli_samr_set_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2082 POLICY_HND *user_pol, uint32 sec_info,
2083 SEC_DESC_BUF *sec_desc_buf)
2085 prs_struct qbuf, rbuf;
2086 SAMR_Q_SET_SEC_OBJ q;
2087 SAMR_R_SET_SEC_OBJ r;
2088 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2090 DEBUG(10,("cli_samr_set_sec_obj\n"));
2095 /* Marshall data and send request */
2097 init_samr_q_set_sec_obj(&q, user_pol, sec_info, sec_desc_buf);
2099 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_SEC_OBJECT,
2102 samr_io_q_set_sec_obj,
2103 samr_io_r_set_sec_obj,
2104 NT_STATUS_UNSUCCESSFUL);
2106 /* Return output parameters */
2114 /* Get domain password info */
2116 NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2117 uint16 *min_pwd_length, uint32 *password_properties)
2119 prs_struct qbuf, rbuf;
2120 SAMR_Q_GET_DOM_PWINFO q;
2121 SAMR_R_GET_DOM_PWINFO r;
2122 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2124 DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
2129 /* Marshall data and send request */
2131 init_samr_q_get_dom_pwinfo(&q, cli->cli->desthost);
2133 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DOM_PWINFO,
2136 samr_io_q_get_dom_pwinfo,
2137 samr_io_r_get_dom_pwinfo,
2138 NT_STATUS_UNSUCCESSFUL);
2140 /* Return output parameters */
2144 if (NT_STATUS_IS_OK(result)) {
2146 *min_pwd_length = r.min_pwd_length;
2147 if (password_properties)
2148 *password_properties = r.password_properties;
2154 /* Get domain password info */
2156 NTSTATUS rpccli_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2157 POLICY_HND *pol, uint16 *min_pwd_length,
2158 uint32 *password_properties, uint32 *unknown1)
2160 prs_struct qbuf, rbuf;
2161 SAMR_Q_GET_USRDOM_PWINFO q;
2162 SAMR_R_GET_USRDOM_PWINFO r;
2163 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2165 DEBUG(10,("cli_samr_get_usrdom_pwinfo\n"));
2170 /* Marshall data and send request */
2172 init_samr_q_get_usrdom_pwinfo(&q, pol);
2174 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_USRDOM_PWINFO,
2177 samr_io_q_get_usrdom_pwinfo,
2178 samr_io_r_get_usrdom_pwinfo,
2179 NT_STATUS_UNSUCCESSFUL);
2181 /* Return output parameters */
2185 if (NT_STATUS_IS_OK(result)) {
2187 *min_pwd_length = r.min_pwd_length;
2188 if (password_properties)
2189 *password_properties = r.password_properties;
2191 *unknown1 = r.unknown_1;
2198 /* Lookup Domain Name */
2200 NTSTATUS rpccli_samr_lookup_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2201 POLICY_HND *user_pol, char *domain_name,
2204 prs_struct qbuf, rbuf;
2205 SAMR_Q_LOOKUP_DOMAIN q;
2206 SAMR_R_LOOKUP_DOMAIN r;
2207 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2209 DEBUG(10,("cli_samr_lookup_domain\n"));
2214 /* Marshall data and send request */
2216 init_samr_q_lookup_domain(&q, user_pol, domain_name);
2218 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_DOMAIN,
2221 samr_io_q_lookup_domain,
2222 samr_io_r_lookup_domain,
2223 NT_STATUS_UNSUCCESSFUL);
2225 /* Return output parameters */
2229 if (NT_STATUS_IS_OK(result))
2230 sid_copy(sid, &r.dom_sid.sid);