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 3 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, see <http://www.gnu.org/licenses/>.
25 /* Connect to SAMR database */
27 NTSTATUS rpccli_samr_connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
28 uint32 access_mask, POLICY_HND *connect_pol)
30 prs_struct qbuf, rbuf;
33 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
35 DEBUG(10,("cli_samr_connect to %s\n", cli->cli->desthost));
40 /* Marshall data and send request */
42 init_samr_q_connect(&q, cli->cli->desthost, access_mask);
44 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT,
49 NT_STATUS_UNSUCCESSFUL);
50 /* Return output parameters */
52 if (NT_STATUS_IS_OK(result = r.status)) {
53 *connect_pol = r.connect_pol;
59 /* Connect to SAMR database */
61 NTSTATUS rpccli_samr_connect4(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
62 uint32 access_mask, POLICY_HND *connect_pol)
64 prs_struct qbuf, rbuf;
67 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
72 /* Marshall data and send request */
74 init_samr_q_connect4(&q, cli->cli->desthost, access_mask);
76 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT4,
81 NT_STATUS_UNSUCCESSFUL);
83 /* Return output parameters */
85 if (NT_STATUS_IS_OK(result = r.status)) {
86 *connect_pol = r.connect_pol;
92 /* Close SAMR handle */
94 NTSTATUS rpccli_samr_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
95 POLICY_HND *connect_pol)
97 prs_struct qbuf, rbuf;
100 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
102 DEBUG(10,("cli_samr_close\n"));
107 /* Marshall data and send request */
109 init_samr_q_close_hnd(&q, connect_pol);
111 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CLOSE_HND,
116 NT_STATUS_UNSUCCESSFUL);
118 /* Return output parameters */
120 if (NT_STATUS_IS_OK(result = r.status)) {
121 *connect_pol = r.pol;
127 /* Open handle on a domain */
129 NTSTATUS rpccli_samr_open_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
130 POLICY_HND *connect_pol, uint32 access_mask,
131 const DOM_SID *domain_sid,
132 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;
139 DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(domain_sid) ));
144 /* Marshall data and send request */
146 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
148 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_DOMAIN,
151 samr_io_q_open_domain,
152 samr_io_r_open_domain,
153 NT_STATUS_UNSUCCESSFUL);
155 /* Return output parameters */
157 if (NT_STATUS_IS_OK(result = r.status)) {
158 *domain_pol = r.domain_pol;
164 NTSTATUS rpccli_samr_open_user(struct rpc_pipe_client *cli,
166 POLICY_HND *domain_pol, uint32 access_mask,
167 uint32 user_rid, POLICY_HND *user_pol)
169 prs_struct qbuf, rbuf;
172 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
174 DEBUG(10,("cli_samr_open_user with rid 0x%x\n", user_rid ));
179 /* Marshall data and send request */
181 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
183 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_USER,
188 NT_STATUS_UNSUCCESSFUL);
190 /* Return output parameters */
192 if (NT_STATUS_IS_OK(result = r.status)) {
193 *user_pol = r.user_pol;
199 /* Open handle on a group */
201 NTSTATUS rpccli_samr_open_group(struct rpc_pipe_client *cli,
203 POLICY_HND *domain_pol, uint32 access_mask,
204 uint32 group_rid, POLICY_HND *group_pol)
206 prs_struct qbuf, rbuf;
209 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
211 DEBUG(10,("cli_samr_open_group with rid 0x%x\n", group_rid ));
216 /* Marshall data and send request */
218 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
220 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_GROUP,
223 samr_io_q_open_group,
224 samr_io_r_open_group,
225 NT_STATUS_UNSUCCESSFUL);
227 /* Return output parameters */
229 if (NT_STATUS_IS_OK(result = r.status)) {
236 /* Create domain group */
238 NTSTATUS rpccli_samr_create_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
239 POLICY_HND *domain_pol,
240 const char *group_name,
241 uint32 access_mask, POLICY_HND *group_pol)
243 prs_struct qbuf, rbuf;
244 SAMR_Q_CREATE_DOM_GROUP q;
245 SAMR_R_CREATE_DOM_GROUP r;
246 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
248 DEBUG(10,("cli_samr_create_dom_group\n"));
253 /* Marshall data and send request */
255 init_samr_q_create_dom_group(&q, domain_pol, group_name, access_mask);
257 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_GROUP,
260 samr_io_q_create_dom_group,
261 samr_io_r_create_dom_group,
262 NT_STATUS_UNSUCCESSFUL);
264 /* Return output parameters */
268 if (NT_STATUS_IS_OK(result))
274 /* Add a domain group member */
276 NTSTATUS rpccli_samr_add_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
277 POLICY_HND *group_pol, uint32 rid)
279 prs_struct qbuf, rbuf;
280 SAMR_Q_ADD_GROUPMEM q;
281 SAMR_R_ADD_GROUPMEM r;
282 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
284 DEBUG(10,("cli_samr_add_groupmem\n"));
289 /* Marshall data and send request */
291 init_samr_q_add_groupmem(&q, group_pol, rid);
293 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_GROUPMEM,
296 samr_io_q_add_groupmem,
297 samr_io_r_add_groupmem,
298 NT_STATUS_UNSUCCESSFUL);
300 /* Return output parameters */
307 /* Delete a domain group member */
309 NTSTATUS rpccli_samr_del_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
310 POLICY_HND *group_pol, uint32 rid)
312 prs_struct qbuf, rbuf;
313 SAMR_Q_DEL_GROUPMEM q;
314 SAMR_R_DEL_GROUPMEM r;
315 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
317 DEBUG(10,("cli_samr_del_groupmem\n"));
322 /* Marshall data and send request */
324 init_samr_q_del_groupmem(&q, group_pol, rid);
326 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_GROUPMEM,
329 samr_io_q_del_groupmem,
330 samr_io_r_del_groupmem,
331 NT_STATUS_UNSUCCESSFUL);
333 /* Return output parameters */
340 /* Query user info */
342 NTSTATUS rpccli_samr_query_userinfo(struct rpc_pipe_client *cli,
344 const POLICY_HND *user_pol,
346 SAM_USERINFO_CTR **ctr)
348 prs_struct qbuf, rbuf;
349 SAMR_Q_QUERY_USERINFO q;
350 SAMR_R_QUERY_USERINFO r;
351 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
353 DEBUG(10,("cli_samr_query_userinfo\n"));
358 /* Marshall data and send request */
360 init_samr_q_query_userinfo(&q, user_pol, switch_value);
362 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERINFO,
365 samr_io_q_query_userinfo,
366 samr_io_r_query_userinfo,
367 NT_STATUS_UNSUCCESSFUL);
369 /* Return output parameters */
379 NTSTATUS rpccli_samr_set_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
380 POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
382 prs_struct qbuf, rbuf;
383 SAMR_Q_SET_GROUPINFO q;
384 SAMR_R_SET_GROUPINFO r;
385 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
387 DEBUG(10,("cli_samr_set_groupinfo\n"));
392 /* Marshall data and send request */
394 init_samr_q_set_groupinfo(&q, group_pol, ctr);
396 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_GROUPINFO,
399 samr_io_q_set_groupinfo,
400 samr_io_r_set_groupinfo,
401 NT_STATUS_UNSUCCESSFUL);
403 /* Return output parameters */
410 /* Query group info */
412 NTSTATUS rpccli_samr_query_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
413 POLICY_HND *group_pol, uint32 info_level,
414 GROUP_INFO_CTR **ctr)
416 prs_struct qbuf, rbuf;
417 SAMR_Q_QUERY_GROUPINFO q;
418 SAMR_R_QUERY_GROUPINFO r;
419 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
421 DEBUG(10,("cli_samr_query_groupinfo\n"));
426 /* Marshall data and send request */
428 init_samr_q_query_groupinfo(&q, group_pol, info_level);
430 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPINFO,
433 samr_io_q_query_groupinfo,
434 samr_io_r_query_groupinfo,
435 NT_STATUS_UNSUCCESSFUL);
439 /* Return output parameters */
446 /* Query user groups */
448 NTSTATUS rpccli_samr_query_usergroups(struct rpc_pipe_client *cli,
450 POLICY_HND *user_pol,
454 prs_struct qbuf, rbuf;
455 SAMR_Q_QUERY_USERGROUPS q;
456 SAMR_R_QUERY_USERGROUPS r;
457 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
459 DEBUG(10,("cli_samr_query_usergroups\n"));
464 /* Marshall data and send request */
466 init_samr_q_query_usergroups(&q, user_pol);
468 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERGROUPS,
471 samr_io_q_query_usergroups,
472 samr_io_r_query_usergroups,
473 NT_STATUS_UNSUCCESSFUL);
475 /* Return output parameters */
477 if (NT_STATUS_IS_OK(result = r.status)) {
478 *num_groups = r.num_entries;
487 NTSTATUS rpccli_samr_set_aliasinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
488 POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
490 prs_struct qbuf, rbuf;
491 SAMR_Q_SET_ALIASINFO q;
492 SAMR_R_SET_ALIASINFO r;
493 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
495 DEBUG(10,("cli_samr_set_aliasinfo\n"));
500 /* Marshall data and send request */
502 init_samr_q_set_aliasinfo(&q, alias_pol, ctr);
504 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_ALIASINFO,
507 samr_io_q_set_aliasinfo,
508 samr_io_r_set_aliasinfo,
509 NT_STATUS_UNSUCCESSFUL);
511 /* Return output parameters */
518 /* Query user aliases */
520 NTSTATUS rpccli_samr_query_useraliases(struct rpc_pipe_client *cli,
522 POLICY_HND *dom_pol, uint32 num_sids,
524 uint32 *num_aliases, uint32 **als_rids)
526 prs_struct qbuf, rbuf;
527 SAMR_Q_QUERY_USERALIASES q;
528 SAMR_R_QUERY_USERALIASES r;
529 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
533 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;
546 for (i=0; i<num_sids; i++)
549 /* Marshall data and send request */
551 init_samr_q_query_useraliases(&q, dom_pol, num_sids, sid_ptrs, sid);
553 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERALIASES,
556 samr_io_q_query_useraliases,
557 samr_io_r_query_useraliases,
558 NT_STATUS_UNSUCCESSFUL);
560 /* Return output parameters */
562 if (NT_STATUS_IS_OK(result = r.status)) {
563 *num_aliases = r.num_entries;
570 /* Query user groups */
572 NTSTATUS rpccli_samr_query_groupmem(struct rpc_pipe_client *cli,
574 POLICY_HND *group_pol, uint32 *num_mem,
575 uint32 **rid, uint32 **attr)
577 prs_struct qbuf, rbuf;
578 SAMR_Q_QUERY_GROUPMEM q;
579 SAMR_R_QUERY_GROUPMEM r;
580 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
582 DEBUG(10,("cli_samr_query_groupmem\n"));
587 /* Marshall data and send request */
589 init_samr_q_query_groupmem(&q, group_pol);
591 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPMEM,
594 samr_io_q_query_groupmem,
595 samr_io_r_query_groupmem,
596 NT_STATUS_UNSUCCESSFUL);
598 /* Return output parameters */
600 if (NT_STATUS_IS_OK(result = r.status)) {
601 *num_mem = r.num_entries;
610 * Enumerate domain users
612 * @param cli client state structure
613 * @param mem_ctx talloc context
614 * @param pol opened domain policy handle
615 * @param start_idx starting index of enumeration, returns context for
617 * @param acb_mask account control bit mask (to enumerate some particular
619 * @param size max acceptable size of response
620 * @param dom_users returned array of domain user names
621 * @param rids returned array of domain user RIDs
622 * @param num_dom_users numer returned entries
624 * @return NTSTATUS returned in rpc response
627 NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
628 POLICY_HND *pol, uint32 *start_idx, uint32 acb_mask,
629 uint32 size, char ***dom_users, uint32 **rids,
630 uint32 *num_dom_users)
634 SAMR_Q_ENUM_DOM_USERS q;
635 SAMR_R_ENUM_DOM_USERS r;
636 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
639 DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
644 /* always init this */
647 /* Fill query structure with parameters */
649 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, size);
651 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_USERS,
654 samr_io_q_enum_dom_users,
655 samr_io_r_enum_dom_users,
656 NT_STATUS_UNSUCCESSFUL);
660 if (!NT_STATUS_IS_OK(result) &&
661 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
664 *start_idx = r.next_idx;
665 *num_dom_users = r.num_entries2;
667 if (r.num_entries2) {
668 /* allocate memory needed to return received data */
669 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
671 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
672 return NT_STATUS_NO_MEMORY;
675 *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
677 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
678 return NT_STATUS_NO_MEMORY;
681 /* fill output buffers with rpc response */
682 for (i = 0; i < r.num_entries2; i++) {
685 (*rids)[i] = r.sam[i].rid;
686 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
687 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
695 /* Enumerate domain groups */
697 NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli,
699 POLICY_HND *pol, uint32 *start_idx,
700 uint32 size, struct acct_info **dom_groups,
701 uint32 *num_dom_groups)
703 prs_struct qbuf, rbuf;
704 SAMR_Q_ENUM_DOM_GROUPS q;
705 SAMR_R_ENUM_DOM_GROUPS r;
706 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
709 DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
714 /* Marshall data and send request */
716 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
718 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_GROUPS,
721 samr_io_q_enum_dom_groups,
722 samr_io_r_enum_dom_groups,
723 NT_STATUS_UNSUCCESSFUL);
725 /* Return output parameters */
729 if (!NT_STATUS_IS_OK(result) &&
730 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
733 *num_dom_groups = r.num_entries2;
735 if (*num_dom_groups == 0)
738 if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
739 result = NT_STATUS_NO_MEMORY;
743 memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
747 for (i = 0; i < *num_dom_groups; i++) {
749 (*dom_groups)[i].rid = r.sam[i].rid;
751 if (r.sam[i].hdr_name.buffer) {
752 unistr2_to_ascii((*dom_groups)[i].acct_name,
753 &r.uni_grp_name[name_idx],
754 sizeof(fstring) - 1);
758 *start_idx = r.next_idx;
765 /* Enumerate domain groups */
767 NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli,
769 POLICY_HND *pol, uint32 *start_idx,
770 uint32 size, struct acct_info **dom_aliases,
771 uint32 *num_dom_aliases)
773 prs_struct qbuf, rbuf;
774 SAMR_Q_ENUM_DOM_ALIASES q;
775 SAMR_R_ENUM_DOM_ALIASES r;
776 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
779 DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
784 /* Marshall data and send request */
786 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
788 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_ALIASES,
791 samr_io_q_enum_dom_aliases,
792 samr_io_r_enum_dom_aliases,
793 NT_STATUS_UNSUCCESSFUL);
795 /* Return output parameters */
799 if (!NT_STATUS_IS_OK(result) &&
800 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
804 *num_dom_aliases = r.num_entries2;
806 if (*num_dom_aliases == 0)
809 if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
810 result = NT_STATUS_NO_MEMORY;
814 memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
818 for (i = 0; i < *num_dom_aliases; i++) {
820 (*dom_aliases)[i].rid = r.sam[i].rid;
822 if (r.sam[i].hdr_name.buffer) {
823 unistr2_to_ascii((*dom_aliases)[i].acct_name,
824 &r.uni_grp_name[name_idx],
825 sizeof(fstring) - 1);
829 *start_idx = r.next_idx;
836 /* Query alias members */
838 NTSTATUS rpccli_samr_query_aliasmem(struct rpc_pipe_client *cli,
840 POLICY_HND *alias_pol, uint32 *num_mem,
843 prs_struct qbuf, rbuf;
844 SAMR_Q_QUERY_ALIASMEM q;
845 SAMR_R_QUERY_ALIASMEM r;
846 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
849 DEBUG(10,("cli_samr_query_aliasmem\n"));
854 /* Marshall data and send request */
856 init_samr_q_query_aliasmem(&q, alias_pol);
858 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASMEM,
861 samr_io_q_query_aliasmem,
862 samr_io_r_query_aliasmem,
863 NT_STATUS_UNSUCCESSFUL);
865 /* Return output parameters */
867 if (!NT_STATUS_IS_OK(result = r.status)) {
871 *num_mem = r.num_sids;
875 result = NT_STATUS_OK;
879 if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
880 result = NT_STATUS_UNSUCCESSFUL;
884 for (i = 0; i < *num_mem; i++) {
885 (*sids)[i] = r.sid[i].sid;
892 /* Open handle on an alias */
894 NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli,
896 POLICY_HND *domain_pol, uint32 access_mask,
897 uint32 alias_rid, POLICY_HND *alias_pol)
899 prs_struct qbuf, rbuf;
904 DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
909 /* Marshall data and send request */
911 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
913 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_ALIAS,
916 samr_io_q_open_alias,
917 samr_io_r_open_alias,
918 NT_STATUS_UNSUCCESSFUL);
920 /* Return output parameters */
922 if (NT_STATUS_IS_OK(result = r.status)) {
929 /* Create an alias */
931 NTSTATUS rpccli_samr_create_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
932 POLICY_HND *domain_pol, const char *name,
933 POLICY_HND *alias_pol)
935 prs_struct qbuf, rbuf;
936 SAMR_Q_CREATE_DOM_ALIAS q;
937 SAMR_R_CREATE_DOM_ALIAS r;
940 DEBUG(10,("cli_samr_create_dom_alias named %s\n", name));
945 /* Marshall data and send request */
947 init_samr_q_create_dom_alias(&q, domain_pol, name);
949 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_ALIAS,
952 samr_io_q_create_dom_alias,
953 samr_io_r_create_dom_alias,
954 NT_STATUS_UNSUCCESSFUL);
956 /* Return output parameters */
958 if (NT_STATUS_IS_OK(result = r.status)) {
959 *alias_pol = r.alias_pol;
965 /* Add an alias member */
967 NTSTATUS rpccli_samr_add_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
968 POLICY_HND *alias_pol, DOM_SID *member)
970 prs_struct qbuf, rbuf;
971 SAMR_Q_ADD_ALIASMEM q;
972 SAMR_R_ADD_ALIASMEM r;
975 DEBUG(10,("cli_samr_add_aliasmem"));
980 /* Marshall data and send request */
982 init_samr_q_add_aliasmem(&q, alias_pol, member);
984 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_ALIASMEM,
987 samr_io_q_add_aliasmem,
988 samr_io_r_add_aliasmem,
989 NT_STATUS_UNSUCCESSFUL);
996 /* Delete an alias member */
998 NTSTATUS rpccli_samr_del_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
999 POLICY_HND *alias_pol, DOM_SID *member)
1001 prs_struct qbuf, rbuf;
1002 SAMR_Q_DEL_ALIASMEM q;
1003 SAMR_R_DEL_ALIASMEM r;
1006 DEBUG(10,("cli_samr_del_aliasmem"));
1011 /* Marshall data and send request */
1013 init_samr_q_del_aliasmem(&q, alias_pol, member);
1015 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_ALIASMEM,
1018 samr_io_q_del_aliasmem,
1019 samr_io_r_del_aliasmem,
1020 NT_STATUS_UNSUCCESSFUL);
1027 /* Query alias info */
1029 NTSTATUS rpccli_samr_query_alias_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1030 POLICY_HND *alias_pol, uint16 switch_value,
1031 ALIAS_INFO_CTR *ctr)
1033 prs_struct qbuf, rbuf;
1034 SAMR_Q_QUERY_ALIASINFO q;
1035 SAMR_R_QUERY_ALIASINFO r;
1036 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1038 DEBUG(10,("cli_samr_query_alias_info\n"));
1043 /* Marshall data and send request */
1045 init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
1047 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASINFO,
1050 samr_io_q_query_aliasinfo,
1051 samr_io_r_query_aliasinfo,
1052 NT_STATUS_UNSUCCESSFUL);
1054 /* Return output parameters */
1056 if (!NT_STATUS_IS_OK(result = r.status)) {
1067 /* Query domain info */
1069 NTSTATUS rpccli_samr_query_dom_info(struct rpc_pipe_client *cli,
1070 TALLOC_CTX *mem_ctx,
1071 POLICY_HND *domain_pol,
1072 uint16 switch_value,
1075 prs_struct qbuf, rbuf;
1076 SAMR_Q_QUERY_DOMAIN_INFO q;
1077 SAMR_R_QUERY_DOMAIN_INFO r;
1078 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1080 DEBUG(10,("cli_samr_query_dom_info\n"));
1085 /* Marshall data and send request */
1087 init_samr_q_query_domain_info(&q, domain_pol, switch_value);
1091 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO,
1094 samr_io_q_query_domain_info,
1095 samr_io_r_query_domain_info,
1096 NT_STATUS_UNSUCCESSFUL);
1098 /* Return output parameters */
1100 if (!NT_STATUS_IS_OK(result = r.status)) {
1109 /* Query domain info2 */
1111 NTSTATUS rpccli_samr_query_dom_info2(struct rpc_pipe_client *cli,
1112 TALLOC_CTX *mem_ctx,
1113 POLICY_HND *domain_pol,
1114 uint16 switch_value,
1117 prs_struct qbuf, rbuf;
1118 SAMR_Q_QUERY_DOMAIN_INFO2 q;
1119 SAMR_R_QUERY_DOMAIN_INFO2 r;
1120 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1122 DEBUG(10,("cli_samr_query_dom_info2\n"));
1127 /* Marshall data and send request */
1129 init_samr_q_query_domain_info2(&q, domain_pol, switch_value);
1133 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO2,
1136 samr_io_q_query_domain_info2,
1137 samr_io_r_query_domain_info2,
1138 NT_STATUS_UNSUCCESSFUL);
1140 /* Return output parameters */
1142 if (!NT_STATUS_IS_OK(result = r.status)) {
1151 /* Set domain info */
1153 NTSTATUS rpccli_samr_set_domain_info(struct rpc_pipe_client *cli,
1154 TALLOC_CTX *mem_ctx,
1155 POLICY_HND *domain_pol,
1156 uint16 switch_value,
1159 prs_struct qbuf, rbuf;
1160 SAMR_Q_SET_DOMAIN_INFO q;
1161 SAMR_R_SET_DOMAIN_INFO r;
1162 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1164 DEBUG(10,("cli_samr_set_domain_info\n"));
1169 /* Marshall data and send request */
1171 init_samr_q_set_domain_info(&q, domain_pol, switch_value, ctr);
1173 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_DOMAIN_INFO,
1176 samr_io_q_set_domain_info,
1177 samr_io_r_set_domain_info,
1178 NT_STATUS_UNSUCCESSFUL);
1180 /* Return output parameters */
1182 if (!NT_STATUS_IS_OK(result = r.status)) {
1191 /* User change password */
1193 NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli,
1194 TALLOC_CTX *mem_ctx,
1195 const char *username,
1196 const char *newpassword,
1197 const char *oldpassword )
1199 uchar new_nt_password[516];
1200 uchar new_lm_password[516];
1201 uchar old_nt_hash[16];
1202 uchar old_lanman_hash[16];
1203 uchar old_nt_hash_enc[16];
1204 uchar old_lanman_hash_enc[16];
1206 uchar new_nt_hash[16];
1207 uchar new_lanman_hash[16];
1209 DEBUG(10,("rpccli_samr_chgpasswd_user\n"));
1211 /* Calculate the MD4 hash (NT compatible) of the password */
1212 E_md4hash(oldpassword, old_nt_hash);
1213 E_md4hash(newpassword, new_nt_hash);
1215 if (lp_client_lanman_auth()
1216 && E_deshash(newpassword, new_lanman_hash)
1217 && E_deshash(oldpassword, old_lanman_hash)) {
1218 /* E_deshash returns false for 'long' passwords (> 14
1219 DOS chars). This allows us to match Win2k, which
1220 does not store a LM hash for these passwords (which
1221 would reduce the effective password length to 14) */
1223 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1225 SamOEMhash( new_lm_password, old_nt_hash, 516);
1226 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1228 ZERO_STRUCT(new_lm_password);
1229 ZERO_STRUCT(old_lanman_hash_enc);
1232 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1234 SamOEMhash( new_nt_password, old_nt_hash, 516);
1235 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1237 return rpccli_samr_chng_pswd_auth_crap(cli, mem_ctx, username,
1238 data_blob_const(new_nt_password,sizeof(new_nt_password)),
1239 data_blob_const(old_nt_hash_enc,sizeof(old_nt_hash_enc)),
1240 data_blob_const(new_lm_password,sizeof(new_lm_password)),
1241 data_blob_const(old_lanman_hash_enc,sizeof(old_lanman_hash_enc)));
1244 /* User change passwd with auth crap */
1246 NTSTATUS rpccli_samr_chng_pswd_auth_crap(struct rpc_pipe_client *cli,
1247 TALLOC_CTX *mem_ctx,
1248 const char *username,
1249 DATA_BLOB new_nt_password,
1250 DATA_BLOB old_nt_hash_enc,
1251 DATA_BLOB new_lm_password,
1252 DATA_BLOB old_lm_hash_enc)
1254 prs_struct qbuf, rbuf;
1255 SAMR_Q_CHGPASSWD_USER q;
1256 SAMR_R_CHGPASSWD_USER r;
1257 char *srv_name_slash;
1259 if (!(srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s",
1260 cli->cli->desthost))) {
1261 return NT_STATUS_NO_MEMORY;
1264 DEBUG(5,("rpccli_samr_chng_pswd_auth_crap on server: %s\n",
1270 /* Marshall data and send request */
1272 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1273 new_nt_password.data,
1274 old_nt_hash_enc.data,
1275 new_lm_password.data,
1276 old_lm_hash_enc.data);
1278 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1281 samr_io_q_chgpasswd_user,
1282 samr_io_r_chgpasswd_user,
1283 NT_STATUS_UNSUCCESSFUL);
1288 /* change password 3 */
1290 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
1291 TALLOC_CTX *mem_ctx,
1292 const char *username,
1293 const char *newpassword,
1294 const char *oldpassword,
1295 SAM_UNK_INFO_1 *info,
1296 SAMR_CHANGE_REJECT *reject)
1298 prs_struct qbuf, rbuf;
1299 SAMR_Q_CHGPASSWD_USER3 q;
1300 SAMR_R_CHGPASSWD_USER3 r;
1302 uchar new_nt_password[516];
1303 uchar new_lm_password[516];
1304 uchar old_nt_hash[16];
1305 uchar old_lanman_hash[16];
1306 uchar old_nt_hash_enc[16];
1307 uchar old_lanman_hash_enc[16];
1309 uchar new_nt_hash[16];
1310 uchar new_lanman_hash[16];
1312 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1314 DEBUG(10,("rpccli_samr_chgpasswd_user3\n"));
1319 /* Calculate the MD4 hash (NT compatible) of the password */
1320 E_md4hash(oldpassword, old_nt_hash);
1321 E_md4hash(newpassword, new_nt_hash);
1323 if (lp_client_lanman_auth()
1324 && E_deshash(newpassword, new_lanman_hash)
1325 && E_deshash(oldpassword, old_lanman_hash)) {
1326 /* E_deshash returns false for 'long' passwords (> 14
1327 DOS chars). This allows us to match Win2k, which
1328 does not store a LM hash for these passwords (which
1329 would reduce the effective password length to 14) */
1331 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1333 SamOEMhash( new_lm_password, old_nt_hash, 516);
1334 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1336 ZERO_STRUCT(new_lm_password);
1337 ZERO_STRUCT(old_lanman_hash_enc);
1340 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1342 SamOEMhash( new_nt_password, old_nt_hash, 516);
1343 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1345 /* Marshall data and send request */
1347 init_samr_q_chgpasswd_user3(&q, srv_name_slash, username,
1351 old_lanman_hash_enc);
1355 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER3,
1358 samr_io_q_chgpasswd_user3,
1359 samr_io_r_chgpasswd_user3,
1360 NT_STATUS_UNSUCCESSFUL);
1362 /* Return output parameters */
1367 /* This function returns the bizzare set of (max_entries, max_size) required
1368 for the QueryDisplayInfo RPC to actually work against a domain controller
1369 with large (10k and higher) numbers of users. These values were
1370 obtained by inspection using ethereal and NT4 running User Manager. */
1372 void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
1375 switch(loop_count) {
1381 *max_entries = 1024;
1385 *max_entries = 2048;
1389 *max_entries = 4096;
1392 default: /* loop_count >= 4 */
1393 *max_entries = 4096;
1399 /* Query display info */
1401 NTSTATUS rpccli_samr_query_dispinfo(struct rpc_pipe_client *cli,
1402 TALLOC_CTX *mem_ctx,
1403 POLICY_HND *domain_pol, uint32 *start_idx,
1404 uint16 switch_value, uint32 *num_entries,
1405 uint32 max_entries, uint32 max_size,
1406 SAM_DISPINFO_CTR *ctr)
1408 prs_struct qbuf, rbuf;
1409 SAMR_Q_QUERY_DISPINFO q;
1410 SAMR_R_QUERY_DISPINFO r;
1411 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1413 DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
1420 /* Marshall data and send request */
1422 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1423 *start_idx, max_entries, max_size);
1427 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO,
1430 samr_io_q_query_dispinfo,
1431 samr_io_r_query_dispinfo,
1432 NT_STATUS_UNSUCCESSFUL);
1434 /* Return output parameters */
1438 if (!NT_STATUS_IS_OK(result) &&
1439 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1443 *num_entries = r.num_entries;
1444 *start_idx += r.num_entries; /* No next_idx in this structure! */
1451 /* Query display info2 */
1453 NTSTATUS rpccli_samr_query_dispinfo2(struct rpc_pipe_client *cli,
1454 TALLOC_CTX *mem_ctx,
1455 POLICY_HND *domain_pol, uint32 *start_idx,
1456 uint16 switch_value, uint32 *num_entries,
1457 uint32 max_entries, uint32 max_size,
1458 SAM_DISPINFO_CTR *ctr)
1460 prs_struct qbuf, rbuf;
1461 SAMR_Q_QUERY_DISPINFO q;
1462 SAMR_R_QUERY_DISPINFO r;
1463 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1465 DEBUG(10,("cli_samr_query_dispinfo2 for start_idx = %u\n", *start_idx));
1472 /* Marshall data and send request */
1474 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1475 *start_idx, max_entries, max_size);
1479 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO2,
1482 samr_io_q_query_dispinfo,
1483 samr_io_r_query_dispinfo,
1484 NT_STATUS_UNSUCCESSFUL);
1486 /* Return output parameters */
1490 if (!NT_STATUS_IS_OK(result) &&
1491 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1495 *num_entries = r.num_entries;
1496 *start_idx += r.num_entries; /* No next_idx in this structure! */
1502 /* Query display info */
1504 NTSTATUS rpccli_samr_query_dispinfo3(struct rpc_pipe_client *cli,
1505 TALLOC_CTX *mem_ctx,
1506 POLICY_HND *domain_pol, uint32 *start_idx,
1507 uint16 switch_value, uint32 *num_entries,
1508 uint32 max_entries, uint32 max_size,
1509 SAM_DISPINFO_CTR *ctr)
1511 prs_struct qbuf, rbuf;
1512 SAMR_Q_QUERY_DISPINFO q;
1513 SAMR_R_QUERY_DISPINFO r;
1514 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1516 DEBUG(10,("cli_samr_query_dispinfo3 for start_idx = %u\n", *start_idx));
1523 /* Marshall data and send request */
1525 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1526 *start_idx, max_entries, max_size);
1530 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO3,
1533 samr_io_q_query_dispinfo,
1534 samr_io_r_query_dispinfo,
1535 NT_STATUS_UNSUCCESSFUL);
1537 /* Return output parameters */
1541 if (!NT_STATUS_IS_OK(result) &&
1542 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1546 *num_entries = r.num_entries;
1547 *start_idx += r.num_entries; /* No next_idx in this structure! */
1553 /* Query display info index */
1555 NTSTATUS rpccli_samr_get_dispenum_index(struct rpc_pipe_client *cli,
1556 TALLOC_CTX *mem_ctx,
1557 POLICY_HND *domain_pol,
1558 uint16 switch_value,
1562 prs_struct qbuf, rbuf;
1563 SAMR_Q_GET_DISPENUM_INDEX q;
1564 SAMR_R_GET_DISPENUM_INDEX r;
1565 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1567 DEBUG(10,("cli_samr_get_dispenum_index for name = %s\n", name));
1572 /* Marshall data and send request */
1574 init_samr_q_get_dispenum_index(&q, domain_pol, switch_value, name);
1576 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DISPENUM_INDEX,
1579 samr_io_q_get_dispenum_index,
1580 samr_io_r_get_dispenum_index,
1581 NT_STATUS_UNSUCCESSFUL);
1583 /* Return output parameters */
1589 if (!NT_STATUS_IS_ERR(result)) {
1596 NTSTATUS rpccli_samr_get_dispenum_index2(struct rpc_pipe_client *cli,
1597 TALLOC_CTX *mem_ctx,
1598 POLICY_HND *domain_pol,
1599 uint16 switch_value,
1603 prs_struct qbuf, rbuf;
1604 SAMR_Q_GET_DISPENUM_INDEX q;
1605 SAMR_R_GET_DISPENUM_INDEX r;
1606 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1608 DEBUG(10,("cli_samr_get_dispenum_index2 for name = %s\n", name));
1613 /* Marshall data and send request */
1615 init_samr_q_get_dispenum_index(&q, domain_pol, switch_value, name);
1617 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DISPENUM_INDEX2,
1620 samr_io_q_get_dispenum_index,
1621 samr_io_r_get_dispenum_index,
1622 NT_STATUS_UNSUCCESSFUL);
1624 /* Return output parameters */
1630 if (!NT_STATUS_IS_ERR(result)) {
1638 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1639 looked up in one packet. */
1641 NTSTATUS rpccli_samr_lookup_rids(struct rpc_pipe_client *cli,
1642 TALLOC_CTX *mem_ctx,
1643 POLICY_HND *domain_pol,
1644 uint32 num_rids, uint32 *rids,
1645 uint32 *num_names, char ***names,
1646 uint32 **name_types)
1648 prs_struct qbuf, rbuf;
1649 SAMR_Q_LOOKUP_RIDS q;
1650 SAMR_R_LOOKUP_RIDS r;
1651 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1654 DEBUG(10,("cli_samr_lookup_rids\n"));
1656 if (num_rids > 1000) {
1657 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1658 "more than ~1000 rids are looked up at once.\n"));
1664 /* Marshall data and send request */
1666 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, 1000, num_rids, rids);
1668 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_RIDS,
1671 samr_io_q_lookup_rids,
1672 samr_io_r_lookup_rids,
1673 NT_STATUS_UNSUCCESSFUL);
1675 /* Return output parameters */
1679 if (!NT_STATUS_IS_OK(result) &&
1680 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1683 if (r.num_names1 == 0) {
1689 *num_names = r.num_names1;
1690 *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
1691 *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
1693 if ((*names == NULL) || (*name_types == NULL)) {
1694 TALLOC_FREE(*names);
1695 TALLOC_FREE(*name_types);
1696 return NT_STATUS_NO_MEMORY;
1699 for (i = 0; i < r.num_names1; i++) {
1702 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
1703 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1704 (*name_types)[i] = r.type[i];
1714 NTSTATUS rpccli_samr_lookup_names(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1715 POLICY_HND *domain_pol, uint32 flags,
1716 uint32 num_names, const char **names,
1717 uint32 *num_rids, uint32 **rids,
1720 prs_struct qbuf, rbuf;
1721 SAMR_Q_LOOKUP_NAMES q;
1722 SAMR_R_LOOKUP_NAMES r;
1723 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1726 DEBUG(10,("cli_samr_lookup_names\n"));
1731 /* Marshall data and send request */
1733 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1736 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_NAMES,
1739 samr_io_q_lookup_names,
1740 samr_io_r_lookup_names,
1741 NT_STATUS_UNSUCCESSFUL);
1743 /* Return output parameters */
1745 if (!NT_STATUS_IS_OK(result = r.status)) {
1749 if (r.num_rids1 == 0) {
1754 *num_rids = r.num_rids1;
1755 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1756 *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1758 if ((*rids == NULL) || (*rid_types == NULL)) {
1760 TALLOC_FREE(*rid_types);
1761 return NT_STATUS_NO_MEMORY;
1764 for (i = 0; i < r.num_rids1; i++) {
1765 (*rids)[i] = r.rids[i];
1766 (*rid_types)[i] = r.types[i];
1774 /* Create a domain user */
1776 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1777 POLICY_HND *domain_pol, const char *acct_name,
1778 uint32 acb_info, uint32 unknown,
1779 POLICY_HND *user_pol, uint32 *rid)
1781 prs_struct qbuf, rbuf;
1782 SAMR_Q_CREATE_USER q;
1783 SAMR_R_CREATE_USER r;
1784 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1786 DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
1791 /* Marshall data and send request */
1793 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1795 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
1798 samr_io_q_create_user,
1799 samr_io_r_create_user,
1800 NT_STATUS_UNSUCCESSFUL);
1802 /* Return output parameters */
1804 if (!NT_STATUS_IS_OK(result = r.status)) {
1809 *user_pol = r.user_pol;
1821 NTSTATUS rpccli_samr_set_userinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1822 const POLICY_HND *user_pol, uint16 switch_value,
1823 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1825 prs_struct qbuf, rbuf;
1826 SAMR_Q_SET_USERINFO q;
1827 SAMR_R_SET_USERINFO r;
1828 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1830 DEBUG(10,("cli_samr_set_userinfo\n"));
1835 if (!sess_key->length) {
1836 DEBUG(1, ("No user session key\n"));
1837 return NT_STATUS_NO_USER_SESSION_KEY;
1840 /* Initialise parse structures */
1842 prs_init(&qbuf, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1843 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1845 /* Marshall data and send request */
1849 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1852 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO,
1855 samr_io_q_set_userinfo,
1856 samr_io_r_set_userinfo,
1857 NT_STATUS_UNSUCCESSFUL);
1859 /* Return output parameters */
1861 if (!NT_STATUS_IS_OK(result = r.status)) {
1872 NTSTATUS rpccli_samr_set_userinfo2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1873 const POLICY_HND *user_pol, uint16 switch_value,
1874 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1876 prs_struct qbuf, rbuf;
1877 SAMR_Q_SET_USERINFO2 q;
1878 SAMR_R_SET_USERINFO2 r;
1879 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1881 DEBUG(10,("cli_samr_set_userinfo2\n"));
1883 if (!sess_key->length) {
1884 DEBUG(1, ("No user session key\n"));
1885 return NT_STATUS_NO_USER_SESSION_KEY;
1891 /* Marshall data and send request */
1893 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1895 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO2,
1898 samr_io_q_set_userinfo2,
1899 samr_io_r_set_userinfo2,
1900 NT_STATUS_UNSUCCESSFUL);
1902 /* Return output parameters */
1904 if (!NT_STATUS_IS_OK(result = r.status)) {
1913 /* Delete domain group */
1915 NTSTATUS rpccli_samr_delete_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1916 POLICY_HND *group_pol)
1918 prs_struct qbuf, rbuf;
1919 SAMR_Q_DELETE_DOM_GROUP q;
1920 SAMR_R_DELETE_DOM_GROUP r;
1921 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1923 DEBUG(10,("cli_samr_delete_dom_group\n"));
1928 /* Marshall data and send request */
1930 init_samr_q_delete_dom_group(&q, group_pol);
1932 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_GROUP,
1935 samr_io_q_delete_dom_group,
1936 samr_io_r_delete_dom_group,
1937 NT_STATUS_UNSUCCESSFUL);
1939 /* Return output parameters */
1946 /* Delete domain alias */
1948 NTSTATUS rpccli_samr_delete_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1949 POLICY_HND *alias_pol)
1951 prs_struct qbuf, rbuf;
1952 SAMR_Q_DELETE_DOM_ALIAS q;
1953 SAMR_R_DELETE_DOM_ALIAS r;
1954 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1956 DEBUG(10,("cli_samr_delete_dom_alias\n"));
1961 /* Marshall data and send request */
1963 init_samr_q_delete_dom_alias(&q, alias_pol);
1965 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_ALIAS,
1968 samr_io_q_delete_dom_alias,
1969 samr_io_r_delete_dom_alias,
1970 NT_STATUS_UNSUCCESSFUL);
1972 /* Return output parameters */
1979 /* Delete domain user */
1981 NTSTATUS rpccli_samr_delete_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1982 POLICY_HND *user_pol)
1984 prs_struct qbuf, rbuf;
1985 SAMR_Q_DELETE_DOM_USER q;
1986 SAMR_R_DELETE_DOM_USER r;
1987 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1989 DEBUG(10,("cli_samr_delete_dom_user\n"));
1994 /* Marshall data and send request */
1996 init_samr_q_delete_dom_user(&q, user_pol);
1998 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_USER,
2001 samr_io_q_delete_dom_user,
2002 samr_io_r_delete_dom_user,
2003 NT_STATUS_UNSUCCESSFUL);
2005 /* Return output parameters */
2012 /* Remove foreign SID */
2014 NTSTATUS rpccli_samr_remove_sid_foreign_domain(struct rpc_pipe_client *cli,
2015 TALLOC_CTX *mem_ctx,
2016 POLICY_HND *user_pol,
2019 prs_struct qbuf, rbuf;
2020 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN q;
2021 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN r;
2022 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2024 DEBUG(10,("cli_samr_remove_sid_foreign_domain\n"));
2029 /* Marshall data and send request */
2031 init_samr_q_remove_sid_foreign_domain(&q, user_pol, sid);
2033 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_REMOVE_SID_FOREIGN_DOMAIN,
2036 samr_io_q_remove_sid_foreign_domain,
2037 samr_io_r_remove_sid_foreign_domain,
2038 NT_STATUS_UNSUCCESSFUL);
2040 /* Return output parameters */
2047 /* Query user security object */
2049 NTSTATUS rpccli_samr_query_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2050 POLICY_HND *user_pol, uint32 sec_info,
2051 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
2053 prs_struct qbuf, rbuf;
2054 SAMR_Q_QUERY_SEC_OBJ q;
2055 SAMR_R_QUERY_SEC_OBJ r;
2056 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2058 DEBUG(10,("cli_samr_query_sec_obj\n"));
2063 /* Marshall data and send request */
2065 init_samr_q_query_sec_obj(&q, user_pol, sec_info);
2067 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_SEC_OBJECT,
2070 samr_io_q_query_sec_obj,
2071 samr_io_r_query_sec_obj,
2072 NT_STATUS_UNSUCCESSFUL);
2074 /* Return output parameters */
2077 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
2082 /* Set user security object */
2084 NTSTATUS rpccli_samr_set_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2085 POLICY_HND *user_pol, uint32 sec_info,
2086 SEC_DESC_BUF *sec_desc_buf)
2088 prs_struct qbuf, rbuf;
2089 SAMR_Q_SET_SEC_OBJ q;
2090 SAMR_R_SET_SEC_OBJ r;
2091 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2093 DEBUG(10,("cli_samr_set_sec_obj\n"));
2098 /* Marshall data and send request */
2100 init_samr_q_set_sec_obj(&q, user_pol, sec_info, sec_desc_buf);
2102 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_SEC_OBJECT,
2105 samr_io_q_set_sec_obj,
2106 samr_io_r_set_sec_obj,
2107 NT_STATUS_UNSUCCESSFUL);
2109 /* Return output parameters */
2117 /* Get domain password info */
2119 NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2120 uint16 *min_pwd_length, uint32 *password_properties)
2122 prs_struct qbuf, rbuf;
2123 SAMR_Q_GET_DOM_PWINFO q;
2124 SAMR_R_GET_DOM_PWINFO r;
2125 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2127 DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
2132 /* Marshall data and send request */
2134 init_samr_q_get_dom_pwinfo(&q, cli->cli->desthost);
2136 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DOM_PWINFO,
2139 samr_io_q_get_dom_pwinfo,
2140 samr_io_r_get_dom_pwinfo,
2141 NT_STATUS_UNSUCCESSFUL);
2143 /* Return output parameters */
2147 if (NT_STATUS_IS_OK(result)) {
2149 *min_pwd_length = r.min_pwd_length;
2150 if (password_properties)
2151 *password_properties = r.password_properties;
2157 /* Get domain password info */
2159 NTSTATUS rpccli_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2160 POLICY_HND *pol, uint16 *min_pwd_length,
2161 uint32 *password_properties, uint32 *unknown1)
2163 prs_struct qbuf, rbuf;
2164 SAMR_Q_GET_USRDOM_PWINFO q;
2165 SAMR_R_GET_USRDOM_PWINFO r;
2166 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2168 DEBUG(10,("cli_samr_get_usrdom_pwinfo\n"));
2173 /* Marshall data and send request */
2175 init_samr_q_get_usrdom_pwinfo(&q, pol);
2177 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_USRDOM_PWINFO,
2180 samr_io_q_get_usrdom_pwinfo,
2181 samr_io_r_get_usrdom_pwinfo,
2182 NT_STATUS_UNSUCCESSFUL);
2184 /* Return output parameters */
2188 if (NT_STATUS_IS_OK(result)) {
2190 *min_pwd_length = r.min_pwd_length;
2191 if (password_properties)
2192 *password_properties = r.password_properties;
2194 *unknown1 = r.unknown_1;
2201 /* Lookup Domain Name */
2203 NTSTATUS rpccli_samr_lookup_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2204 POLICY_HND *user_pol, char *domain_name,
2207 prs_struct qbuf, rbuf;
2208 SAMR_Q_LOOKUP_DOMAIN q;
2209 SAMR_R_LOOKUP_DOMAIN r;
2210 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2212 DEBUG(10,("cli_samr_lookup_domain\n"));
2217 /* Marshall data and send request */
2219 init_samr_q_lookup_domain(&q, user_pol, domain_name);
2221 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_DOMAIN,
2224 samr_io_q_lookup_domain,
2225 samr_io_r_lookup_domain,
2226 NT_STATUS_UNSUCCESSFUL);
2228 /* Return output parameters */
2232 if (NT_STATUS_IS_OK(result))
2233 sid_copy(sid, &r.dom_sid.sid);