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;
55 connect_pol->marker = malloc(1);
62 /* Connect to SAMR database */
64 NTSTATUS rpccli_samr_connect4(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
65 uint32 access_mask, POLICY_HND *connect_pol)
67 prs_struct qbuf, rbuf;
70 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
75 /* Marshall data and send request */
77 init_samr_q_connect4(&q, cli->cli->desthost, access_mask);
79 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT4,
84 NT_STATUS_UNSUCCESSFUL);
86 /* Return output parameters */
88 if (NT_STATUS_IS_OK(result = r.status)) {
89 *connect_pol = r.connect_pol;
91 connect_pol->marker = malloc(1);
98 /* Close SAMR handle */
100 NTSTATUS rpccli_samr_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
101 POLICY_HND *connect_pol)
103 prs_struct qbuf, rbuf;
106 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
108 DEBUG(10,("cli_samr_close\n"));
113 /* Marshall data and send request */
115 init_samr_q_close_hnd(&q, connect_pol);
117 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CLOSE_HND,
122 NT_STATUS_UNSUCCESSFUL);
124 /* Return output parameters */
126 if (NT_STATUS_IS_OK(result = r.status)) {
128 SAFE_FREE(connect_pol->marker);
130 *connect_pol = r.pol;
136 /* Open handle on a domain */
138 NTSTATUS rpccli_samr_open_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
139 POLICY_HND *connect_pol, uint32 access_mask,
140 const DOM_SID *domain_sid,
141 POLICY_HND *domain_pol)
143 prs_struct qbuf, rbuf;
144 SAMR_Q_OPEN_DOMAIN q;
145 SAMR_R_OPEN_DOMAIN r;
146 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
148 DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(domain_sid) ));
153 /* Marshall data and send request */
155 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
157 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_DOMAIN,
160 samr_io_q_open_domain,
161 samr_io_r_open_domain,
162 NT_STATUS_UNSUCCESSFUL);
164 /* Return output parameters */
166 if (NT_STATUS_IS_OK(result = r.status)) {
167 *domain_pol = r.domain_pol;
169 domain_pol->marker = malloc(1);
176 NTSTATUS rpccli_samr_open_user(struct rpc_pipe_client *cli,
178 POLICY_HND *domain_pol, uint32 access_mask,
179 uint32 user_rid, POLICY_HND *user_pol)
181 prs_struct qbuf, rbuf;
184 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
186 DEBUG(10,("cli_samr_open_user with rid 0x%x\n", user_rid ));
191 /* Marshall data and send request */
193 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
195 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_USER,
200 NT_STATUS_UNSUCCESSFUL);
202 /* Return output parameters */
204 if (NT_STATUS_IS_OK(result = r.status)) {
205 *user_pol = r.user_pol;
207 user_pol->marker = malloc(1);
214 /* Open handle on a group */
216 NTSTATUS rpccli_samr_open_group(struct rpc_pipe_client *cli,
218 POLICY_HND *domain_pol, uint32 access_mask,
219 uint32 group_rid, POLICY_HND *group_pol)
221 prs_struct qbuf, rbuf;
224 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
226 DEBUG(10,("cli_samr_open_group with rid 0x%x\n", group_rid ));
231 /* Marshall data and send request */
233 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
235 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_GROUP,
238 samr_io_q_open_group,
239 samr_io_r_open_group,
240 NT_STATUS_UNSUCCESSFUL);
242 /* Return output parameters */
244 if (NT_STATUS_IS_OK(result = r.status)) {
247 group_pol->marker = malloc(1);
254 /* Create domain group */
256 NTSTATUS rpccli_samr_create_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
257 POLICY_HND *domain_pol,
258 const char *group_name,
259 uint32 access_mask, POLICY_HND *group_pol)
261 prs_struct qbuf, rbuf;
262 SAMR_Q_CREATE_DOM_GROUP q;
263 SAMR_R_CREATE_DOM_GROUP r;
264 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
266 DEBUG(10,("cli_samr_create_dom_group\n"));
271 /* Marshall data and send request */
273 init_samr_q_create_dom_group(&q, domain_pol, group_name, access_mask);
275 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_GROUP,
278 samr_io_q_create_dom_group,
279 samr_io_r_create_dom_group,
280 NT_STATUS_UNSUCCESSFUL);
282 /* Return output parameters */
286 if (NT_STATUS_IS_OK(result))
292 /* Add a domain group member */
294 NTSTATUS rpccli_samr_add_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
295 POLICY_HND *group_pol, uint32 rid)
297 prs_struct qbuf, rbuf;
298 SAMR_Q_ADD_GROUPMEM q;
299 SAMR_R_ADD_GROUPMEM r;
300 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
302 DEBUG(10,("cli_samr_add_groupmem\n"));
307 /* Marshall data and send request */
309 init_samr_q_add_groupmem(&q, group_pol, rid);
311 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_GROUPMEM,
314 samr_io_q_add_groupmem,
315 samr_io_r_add_groupmem,
316 NT_STATUS_UNSUCCESSFUL);
318 /* Return output parameters */
325 /* Delete a domain group member */
327 NTSTATUS rpccli_samr_del_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
328 POLICY_HND *group_pol, uint32 rid)
330 prs_struct qbuf, rbuf;
331 SAMR_Q_DEL_GROUPMEM q;
332 SAMR_R_DEL_GROUPMEM r;
333 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
335 DEBUG(10,("cli_samr_del_groupmem\n"));
340 /* Marshall data and send request */
342 init_samr_q_del_groupmem(&q, group_pol, rid);
344 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_GROUPMEM,
347 samr_io_q_del_groupmem,
348 samr_io_r_del_groupmem,
349 NT_STATUS_UNSUCCESSFUL);
351 /* Return output parameters */
358 /* Query user info */
360 NTSTATUS rpccli_samr_query_userinfo(struct rpc_pipe_client *cli,
362 const POLICY_HND *user_pol,
364 SAM_USERINFO_CTR **ctr)
366 prs_struct qbuf, rbuf;
367 SAMR_Q_QUERY_USERINFO q;
368 SAMR_R_QUERY_USERINFO r;
369 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
371 DEBUG(10,("cli_samr_query_userinfo\n"));
376 /* Marshall data and send request */
378 init_samr_q_query_userinfo(&q, user_pol, switch_value);
380 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERINFO,
383 samr_io_q_query_userinfo,
384 samr_io_r_query_userinfo,
385 NT_STATUS_UNSUCCESSFUL);
387 /* Return output parameters */
397 NTSTATUS rpccli_samr_set_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
398 POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
400 prs_struct qbuf, rbuf;
401 SAMR_Q_SET_GROUPINFO q;
402 SAMR_R_SET_GROUPINFO r;
403 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
405 DEBUG(10,("cli_samr_set_groupinfo\n"));
410 /* Marshall data and send request */
412 init_samr_q_set_groupinfo(&q, group_pol, ctr);
414 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_GROUPINFO,
417 samr_io_q_set_groupinfo,
418 samr_io_r_set_groupinfo,
419 NT_STATUS_UNSUCCESSFUL);
421 /* Return output parameters */
428 /* Query group info */
430 NTSTATUS rpccli_samr_query_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
431 POLICY_HND *group_pol, uint32 info_level,
432 GROUP_INFO_CTR **ctr)
434 prs_struct qbuf, rbuf;
435 SAMR_Q_QUERY_GROUPINFO q;
436 SAMR_R_QUERY_GROUPINFO r;
437 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
439 DEBUG(10,("cli_samr_query_groupinfo\n"));
444 /* Marshall data and send request */
446 init_samr_q_query_groupinfo(&q, group_pol, info_level);
448 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPINFO,
451 samr_io_q_query_groupinfo,
452 samr_io_r_query_groupinfo,
453 NT_STATUS_UNSUCCESSFUL);
457 /* Return output parameters */
464 /* Query user groups */
466 NTSTATUS rpccli_samr_query_usergroups(struct rpc_pipe_client *cli,
468 POLICY_HND *user_pol,
472 prs_struct qbuf, rbuf;
473 SAMR_Q_QUERY_USERGROUPS q;
474 SAMR_R_QUERY_USERGROUPS r;
475 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
477 DEBUG(10,("cli_samr_query_usergroups\n"));
482 /* Marshall data and send request */
484 init_samr_q_query_usergroups(&q, user_pol);
486 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERGROUPS,
489 samr_io_q_query_usergroups,
490 samr_io_r_query_usergroups,
491 NT_STATUS_UNSUCCESSFUL);
493 /* Return output parameters */
495 if (NT_STATUS_IS_OK(result = r.status)) {
496 *num_groups = r.num_entries;
505 NTSTATUS rpccli_samr_set_aliasinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
506 POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
508 prs_struct qbuf, rbuf;
509 SAMR_Q_SET_ALIASINFO q;
510 SAMR_R_SET_ALIASINFO r;
511 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
513 DEBUG(10,("cli_samr_set_aliasinfo\n"));
518 /* Marshall data and send request */
520 init_samr_q_set_aliasinfo(&q, alias_pol, ctr);
522 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_ALIASINFO,
525 samr_io_q_set_aliasinfo,
526 samr_io_r_set_aliasinfo,
527 NT_STATUS_UNSUCCESSFUL);
529 /* Return output parameters */
536 /* Query user aliases */
538 NTSTATUS rpccli_samr_query_useraliases(struct rpc_pipe_client *cli,
540 POLICY_HND *dom_pol, uint32 num_sids,
542 uint32 *num_aliases, uint32 **als_rids)
544 prs_struct qbuf, rbuf;
545 SAMR_Q_QUERY_USERALIASES q;
546 SAMR_R_QUERY_USERALIASES r;
547 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
551 DEBUG(10,("cli_samr_query_useraliases\n"));
557 sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
558 if (sid_ptrs == NULL)
559 return NT_STATUS_NO_MEMORY;
564 for (i=0; i<num_sids; i++)
567 /* Marshall data and send request */
569 init_samr_q_query_useraliases(&q, dom_pol, num_sids, sid_ptrs, sid);
571 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERALIASES,
574 samr_io_q_query_useraliases,
575 samr_io_r_query_useraliases,
576 NT_STATUS_UNSUCCESSFUL);
578 /* Return output parameters */
580 if (NT_STATUS_IS_OK(result = r.status)) {
581 *num_aliases = r.num_entries;
588 /* Query user groups */
590 NTSTATUS rpccli_samr_query_groupmem(struct rpc_pipe_client *cli,
592 POLICY_HND *group_pol, uint32 *num_mem,
593 uint32 **rid, uint32 **attr)
595 prs_struct qbuf, rbuf;
596 SAMR_Q_QUERY_GROUPMEM q;
597 SAMR_R_QUERY_GROUPMEM r;
598 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
600 DEBUG(10,("cli_samr_query_groupmem\n"));
605 /* Marshall data and send request */
607 init_samr_q_query_groupmem(&q, group_pol);
609 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPMEM,
612 samr_io_q_query_groupmem,
613 samr_io_r_query_groupmem,
614 NT_STATUS_UNSUCCESSFUL);
616 /* Return output parameters */
618 if (NT_STATUS_IS_OK(result = r.status)) {
619 *num_mem = r.num_entries;
628 * Enumerate domain users
630 * @param cli client state structure
631 * @param mem_ctx talloc context
632 * @param pol opened domain policy handle
633 * @param start_idx starting index of enumeration, returns context for
635 * @param acb_mask account control bit mask (to enumerate some particular
637 * @param size max acceptable size of response
638 * @param dom_users returned array of domain user names
639 * @param rids returned array of domain user RIDs
640 * @param num_dom_users numer returned entries
642 * @return NTSTATUS returned in rpc response
645 NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
646 POLICY_HND *pol, uint32 *start_idx, uint32 acb_mask,
647 uint32 size, char ***dom_users, uint32 **rids,
648 uint32 *num_dom_users)
652 SAMR_Q_ENUM_DOM_USERS q;
653 SAMR_R_ENUM_DOM_USERS r;
654 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
657 DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
662 /* always init this */
665 /* Fill query structure with parameters */
667 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, size);
669 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_USERS,
672 samr_io_q_enum_dom_users,
673 samr_io_r_enum_dom_users,
674 NT_STATUS_UNSUCCESSFUL);
678 if (!NT_STATUS_IS_OK(result) &&
679 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
682 *start_idx = r.next_idx;
683 *num_dom_users = r.num_entries2;
685 if (r.num_entries2) {
686 /* allocate memory needed to return received data */
687 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
689 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
690 return NT_STATUS_NO_MEMORY;
693 *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
695 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
696 return NT_STATUS_NO_MEMORY;
699 /* fill output buffers with rpc response */
700 for (i = 0; i < r.num_entries2; i++) {
703 (*rids)[i] = r.sam[i].rid;
704 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf));
705 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
713 /* Enumerate domain groups */
715 NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli,
717 POLICY_HND *pol, uint32 *start_idx,
718 uint32 size, struct acct_info **dom_groups,
719 uint32 *num_dom_groups)
721 prs_struct qbuf, rbuf;
722 SAMR_Q_ENUM_DOM_GROUPS q;
723 SAMR_R_ENUM_DOM_GROUPS r;
724 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
727 DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
732 /* Marshall data and send request */
734 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
736 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_GROUPS,
739 samr_io_q_enum_dom_groups,
740 samr_io_r_enum_dom_groups,
741 NT_STATUS_UNSUCCESSFUL);
743 /* Return output parameters */
747 if (!NT_STATUS_IS_OK(result) &&
748 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
751 *num_dom_groups = r.num_entries2;
753 if (*num_dom_groups == 0)
756 if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
757 result = NT_STATUS_NO_MEMORY;
761 memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
765 for (i = 0; i < *num_dom_groups; i++) {
767 (*dom_groups)[i].rid = r.sam[i].rid;
769 if (r.sam[i].hdr_name.buffer) {
770 unistr2_to_ascii((*dom_groups)[i].acct_name,
771 &r.uni_grp_name[name_idx],
772 sizeof((*dom_groups)[i].acct_name));
776 *start_idx = r.next_idx;
783 /* Enumerate domain groups */
785 NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli,
787 POLICY_HND *pol, uint32 *start_idx,
788 uint32 size, struct acct_info **dom_aliases,
789 uint32 *num_dom_aliases)
791 prs_struct qbuf, rbuf;
792 SAMR_Q_ENUM_DOM_ALIASES q;
793 SAMR_R_ENUM_DOM_ALIASES r;
794 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
797 DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
802 /* Marshall data and send request */
804 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
806 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_ALIASES,
809 samr_io_q_enum_dom_aliases,
810 samr_io_r_enum_dom_aliases,
811 NT_STATUS_UNSUCCESSFUL);
813 /* Return output parameters */
817 if (!NT_STATUS_IS_OK(result) &&
818 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
822 *num_dom_aliases = r.num_entries2;
824 if (*num_dom_aliases == 0)
827 if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
828 result = NT_STATUS_NO_MEMORY;
832 memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
836 for (i = 0; i < *num_dom_aliases; i++) {
838 (*dom_aliases)[i].rid = r.sam[i].rid;
840 if (r.sam[i].hdr_name.buffer) {
841 unistr2_to_ascii((*dom_aliases)[i].acct_name,
842 &r.uni_grp_name[name_idx],
843 sizeof((*dom_aliases)[i].acct_name));
847 *start_idx = r.next_idx;
854 /* Query alias members */
856 NTSTATUS rpccli_samr_query_aliasmem(struct rpc_pipe_client *cli,
858 POLICY_HND *alias_pol, uint32 *num_mem,
861 prs_struct qbuf, rbuf;
862 SAMR_Q_QUERY_ALIASMEM q;
863 SAMR_R_QUERY_ALIASMEM r;
864 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
867 DEBUG(10,("cli_samr_query_aliasmem\n"));
872 /* Marshall data and send request */
874 init_samr_q_query_aliasmem(&q, alias_pol);
876 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASMEM,
879 samr_io_q_query_aliasmem,
880 samr_io_r_query_aliasmem,
881 NT_STATUS_UNSUCCESSFUL);
883 /* Return output parameters */
885 if (!NT_STATUS_IS_OK(result = r.status)) {
889 *num_mem = r.num_sids;
893 result = NT_STATUS_OK;
897 if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
898 result = NT_STATUS_UNSUCCESSFUL;
902 for (i = 0; i < *num_mem; i++) {
903 (*sids)[i] = r.sid[i].sid;
910 /* Open handle on an alias */
912 NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli,
914 POLICY_HND *domain_pol, uint32 access_mask,
915 uint32 alias_rid, POLICY_HND *alias_pol)
917 prs_struct qbuf, rbuf;
922 DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
927 /* Marshall data and send request */
929 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
931 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_ALIAS,
934 samr_io_q_open_alias,
935 samr_io_r_open_alias,
936 NT_STATUS_UNSUCCESSFUL);
938 /* Return output parameters */
940 if (NT_STATUS_IS_OK(result = r.status)) {
943 alias_pol->marker = malloc(1);
950 /* Create an alias */
952 NTSTATUS rpccli_samr_create_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
953 POLICY_HND *domain_pol, const char *name,
954 POLICY_HND *alias_pol)
956 prs_struct qbuf, rbuf;
957 SAMR_Q_CREATE_DOM_ALIAS q;
958 SAMR_R_CREATE_DOM_ALIAS r;
961 DEBUG(10,("cli_samr_create_dom_alias named %s\n", name));
966 /* Marshall data and send request */
968 init_samr_q_create_dom_alias(&q, domain_pol, name);
970 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_ALIAS,
973 samr_io_q_create_dom_alias,
974 samr_io_r_create_dom_alias,
975 NT_STATUS_UNSUCCESSFUL);
977 /* Return output parameters */
979 if (NT_STATUS_IS_OK(result = r.status)) {
980 *alias_pol = r.alias_pol;
986 /* Add an alias member */
988 NTSTATUS rpccli_samr_add_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
989 POLICY_HND *alias_pol, DOM_SID *member)
991 prs_struct qbuf, rbuf;
992 SAMR_Q_ADD_ALIASMEM q;
993 SAMR_R_ADD_ALIASMEM r;
996 DEBUG(10,("cli_samr_add_aliasmem"));
1001 /* Marshall data and send request */
1003 init_samr_q_add_aliasmem(&q, alias_pol, member);
1005 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_ALIASMEM,
1008 samr_io_q_add_aliasmem,
1009 samr_io_r_add_aliasmem,
1010 NT_STATUS_UNSUCCESSFUL);
1017 /* Delete an alias member */
1019 NTSTATUS rpccli_samr_del_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1020 POLICY_HND *alias_pol, DOM_SID *member)
1022 prs_struct qbuf, rbuf;
1023 SAMR_Q_DEL_ALIASMEM q;
1024 SAMR_R_DEL_ALIASMEM r;
1027 DEBUG(10,("cli_samr_del_aliasmem"));
1032 /* Marshall data and send request */
1034 init_samr_q_del_aliasmem(&q, alias_pol, member);
1036 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_ALIASMEM,
1039 samr_io_q_del_aliasmem,
1040 samr_io_r_del_aliasmem,
1041 NT_STATUS_UNSUCCESSFUL);
1048 /* Query alias info */
1050 NTSTATUS rpccli_samr_query_alias_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1051 POLICY_HND *alias_pol, uint16 switch_value,
1052 ALIAS_INFO_CTR *ctr)
1054 prs_struct qbuf, rbuf;
1055 SAMR_Q_QUERY_ALIASINFO q;
1056 SAMR_R_QUERY_ALIASINFO r;
1057 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1059 DEBUG(10,("cli_samr_query_alias_info\n"));
1064 /* Marshall data and send request */
1066 init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
1068 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASINFO,
1071 samr_io_q_query_aliasinfo,
1072 samr_io_r_query_aliasinfo,
1073 NT_STATUS_UNSUCCESSFUL);
1075 /* Return output parameters */
1077 if (!NT_STATUS_IS_OK(result = r.status)) {
1088 /* Query domain info */
1090 NTSTATUS rpccli_samr_query_dom_info(struct rpc_pipe_client *cli,
1091 TALLOC_CTX *mem_ctx,
1092 POLICY_HND *domain_pol,
1093 uint16 switch_value,
1096 prs_struct qbuf, rbuf;
1097 SAMR_Q_QUERY_DOMAIN_INFO q;
1098 SAMR_R_QUERY_DOMAIN_INFO r;
1099 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1101 DEBUG(10,("cli_samr_query_dom_info\n"));
1106 /* Marshall data and send request */
1108 init_samr_q_query_domain_info(&q, domain_pol, switch_value);
1112 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO,
1115 samr_io_q_query_domain_info,
1116 samr_io_r_query_domain_info,
1117 NT_STATUS_UNSUCCESSFUL);
1119 /* Return output parameters */
1121 if (!NT_STATUS_IS_OK(result = r.status)) {
1130 /* Query domain info2 */
1132 NTSTATUS rpccli_samr_query_dom_info2(struct rpc_pipe_client *cli,
1133 TALLOC_CTX *mem_ctx,
1134 POLICY_HND *domain_pol,
1135 uint16 switch_value,
1138 prs_struct qbuf, rbuf;
1139 SAMR_Q_QUERY_DOMAIN_INFO2 q;
1140 SAMR_R_QUERY_DOMAIN_INFO2 r;
1141 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1143 DEBUG(10,("cli_samr_query_dom_info2\n"));
1148 /* Marshall data and send request */
1150 init_samr_q_query_domain_info2(&q, domain_pol, switch_value);
1154 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO2,
1157 samr_io_q_query_domain_info2,
1158 samr_io_r_query_domain_info2,
1159 NT_STATUS_UNSUCCESSFUL);
1161 /* Return output parameters */
1163 if (!NT_STATUS_IS_OK(result = r.status)) {
1172 /* Set domain info */
1174 NTSTATUS rpccli_samr_set_domain_info(struct rpc_pipe_client *cli,
1175 TALLOC_CTX *mem_ctx,
1176 POLICY_HND *domain_pol,
1177 uint16 switch_value,
1180 prs_struct qbuf, rbuf;
1181 SAMR_Q_SET_DOMAIN_INFO q;
1182 SAMR_R_SET_DOMAIN_INFO r;
1183 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1185 DEBUG(10,("cli_samr_set_domain_info\n"));
1190 /* Marshall data and send request */
1192 init_samr_q_set_domain_info(&q, domain_pol, switch_value, ctr);
1194 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_DOMAIN_INFO,
1197 samr_io_q_set_domain_info,
1198 samr_io_r_set_domain_info,
1199 NT_STATUS_UNSUCCESSFUL);
1201 /* Return output parameters */
1203 if (!NT_STATUS_IS_OK(result = r.status)) {
1212 /* User change password */
1214 NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli,
1215 TALLOC_CTX *mem_ctx,
1216 const char *username,
1217 const char *newpassword,
1218 const char *oldpassword )
1220 prs_struct qbuf, rbuf;
1221 SAMR_Q_CHGPASSWD_USER q;
1222 SAMR_R_CHGPASSWD_USER r;
1223 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1225 uchar new_nt_password[516];
1226 uchar new_lm_password[516];
1227 uchar old_nt_hash[16];
1228 uchar old_lanman_hash[16];
1229 uchar old_nt_hash_enc[16];
1230 uchar old_lanman_hash_enc[16];
1232 uchar new_nt_hash[16];
1233 uchar new_lanman_hash[16];
1235 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1237 DEBUG(10,("rpccli_samr_chgpasswd_user\n"));
1242 /* Calculate the MD4 hash (NT compatible) of the password */
1243 E_md4hash(oldpassword, old_nt_hash);
1244 E_md4hash(newpassword, new_nt_hash);
1246 if (lp_client_lanman_auth()
1247 && E_deshash(newpassword, new_lanman_hash)
1248 && E_deshash(oldpassword, old_lanman_hash)) {
1249 /* E_deshash returns false for 'long' passwords (> 14
1250 DOS chars). This allows us to match Win2k, which
1251 does not store a LM hash for these passwords (which
1252 would reduce the effective password length to 14) */
1254 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1256 SamOEMhash( new_lm_password, old_nt_hash, 516);
1257 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1259 ZERO_STRUCT(new_lm_password);
1260 ZERO_STRUCT(old_lanman_hash_enc);
1263 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1265 SamOEMhash( new_nt_password, old_nt_hash, 516);
1266 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1268 /* Marshall data and send request */
1270 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1274 old_lanman_hash_enc);
1276 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1279 samr_io_q_chgpasswd_user,
1280 samr_io_r_chgpasswd_user,
1281 NT_STATUS_UNSUCCESSFUL);
1283 /* Return output parameters */
1285 if (!NT_STATUS_IS_OK(result = r.status)) {
1294 /* User change password given blobs */
1296 NTSTATUS rpccli_samr_chng_pswd_auth_crap(struct rpc_pipe_client *cli,
1297 TALLOC_CTX *mem_ctx,
1298 const char *username,
1299 DATA_BLOB new_nt_password,
1300 DATA_BLOB old_nt_hash_enc,
1301 DATA_BLOB new_lm_password,
1302 DATA_BLOB old_lm_hash_enc)
1304 prs_struct qbuf, rbuf;
1305 SAMR_Q_CHGPASSWD_USER q;
1306 SAMR_R_CHGPASSWD_USER r;
1307 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1309 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1311 DEBUG(10,("rpccli_samr_chng_pswd_auth_crap\n"));
1316 /* Marshall data and send request */
1318 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1319 new_nt_password.data,
1320 old_nt_hash_enc.data,
1321 new_lm_password.data,
1322 old_lm_hash_enc.data);
1324 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1327 samr_io_q_chgpasswd_user,
1328 samr_io_r_chgpasswd_user,
1329 NT_STATUS_UNSUCCESSFUL);
1331 /* Return output parameters */
1333 if (!NT_STATUS_IS_OK(result = r.status)) {
1343 /* change password 3 */
1345 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
1346 TALLOC_CTX *mem_ctx,
1347 const char *username,
1348 const char *newpassword,
1349 const char *oldpassword,
1350 SAM_UNK_INFO_1 *info,
1351 SAMR_CHANGE_REJECT *reject)
1353 prs_struct qbuf, rbuf;
1354 SAMR_Q_CHGPASSWD_USER3 q;
1355 SAMR_R_CHGPASSWD_USER3 r;
1357 uchar new_nt_password[516];
1358 uchar new_lm_password[516];
1359 uchar old_nt_hash[16];
1360 uchar old_lanman_hash[16];
1361 uchar old_nt_hash_enc[16];
1362 uchar old_lanman_hash_enc[16];
1364 uchar new_nt_hash[16];
1365 uchar new_lanman_hash[16];
1367 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1369 DEBUG(10,("rpccli_samr_chgpasswd_user3\n"));
1374 /* Calculate the MD4 hash (NT compatible) of the password */
1375 E_md4hash(oldpassword, old_nt_hash);
1376 E_md4hash(newpassword, new_nt_hash);
1378 if (lp_client_lanman_auth()
1379 && E_deshash(newpassword, new_lanman_hash)
1380 && E_deshash(oldpassword, old_lanman_hash)) {
1381 /* E_deshash returns false for 'long' passwords (> 14
1382 DOS chars). This allows us to match Win2k, which
1383 does not store a LM hash for these passwords (which
1384 would reduce the effective password length to 14) */
1386 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1388 SamOEMhash( new_lm_password, old_nt_hash, 516);
1389 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1391 ZERO_STRUCT(new_lm_password);
1392 ZERO_STRUCT(old_lanman_hash_enc);
1395 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1397 SamOEMhash( new_nt_password, old_nt_hash, 516);
1398 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1400 /* Marshall data and send request */
1402 init_samr_q_chgpasswd_user3(&q, srv_name_slash, username,
1406 old_lanman_hash_enc);
1410 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER3,
1413 samr_io_q_chgpasswd_user3,
1414 samr_io_r_chgpasswd_user3,
1415 NT_STATUS_UNSUCCESSFUL);
1417 /* Return output parameters */
1422 /* This function returns the bizzare set of (max_entries, max_size) required
1423 for the QueryDisplayInfo RPC to actually work against a domain controller
1424 with large (10k and higher) numbers of users. These values were
1425 obtained by inspection using ethereal and NT4 running User Manager. */
1427 void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
1430 switch(loop_count) {
1436 *max_entries = 1024;
1440 *max_entries = 2048;
1444 *max_entries = 4096;
1447 default: /* loop_count >= 4 */
1448 *max_entries = 4096;
1454 /* Query display info */
1456 NTSTATUS rpccli_samr_query_dispinfo(struct rpc_pipe_client *cli,
1457 TALLOC_CTX *mem_ctx,
1458 POLICY_HND *domain_pol, uint32 *start_idx,
1459 uint16 switch_value, uint32 *num_entries,
1460 uint32 max_entries, uint32 max_size,
1461 SAM_DISPINFO_CTR *ctr)
1463 prs_struct qbuf, rbuf;
1464 SAMR_Q_QUERY_DISPINFO q;
1465 SAMR_R_QUERY_DISPINFO r;
1466 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1468 DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
1475 /* Marshall data and send request */
1477 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1478 *start_idx, max_entries, max_size);
1482 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO,
1485 samr_io_q_query_dispinfo,
1486 samr_io_r_query_dispinfo,
1487 NT_STATUS_UNSUCCESSFUL);
1489 /* Return output parameters */
1493 if (!NT_STATUS_IS_OK(result) &&
1494 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1498 *num_entries = r.num_entries;
1499 *start_idx += r.num_entries; /* No next_idx in this structure! */
1505 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1506 looked up in one packet. */
1508 NTSTATUS rpccli_samr_lookup_rids(struct rpc_pipe_client *cli,
1509 TALLOC_CTX *mem_ctx,
1510 POLICY_HND *domain_pol,
1511 uint32 num_rids, uint32 *rids,
1512 uint32 *num_names, char ***names,
1513 uint32 **name_types)
1515 prs_struct qbuf, rbuf;
1516 SAMR_Q_LOOKUP_RIDS q;
1517 SAMR_R_LOOKUP_RIDS r;
1518 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1521 DEBUG(10,("cli_samr_lookup_rids\n"));
1523 if (num_rids > 1000) {
1524 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1525 "more than ~1000 rids are looked up at once.\n"));
1531 /* Marshall data and send request */
1533 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, 1000, num_rids, rids);
1535 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_RIDS,
1538 samr_io_q_lookup_rids,
1539 samr_io_r_lookup_rids,
1540 NT_STATUS_UNSUCCESSFUL);
1542 /* Return output parameters */
1546 if (!NT_STATUS_IS_OK(result) &&
1547 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1550 if (r.num_names1 == 0) {
1556 *num_names = r.num_names1;
1557 *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
1558 *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
1560 if ((*names == NULL) || (*name_types == NULL)) {
1561 TALLOC_FREE(*names);
1562 TALLOC_FREE(*name_types);
1563 return NT_STATUS_NO_MEMORY;
1566 for (i = 0; i < r.num_names1; i++) {
1569 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp));
1570 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1571 (*name_types)[i] = r.type[i];
1581 NTSTATUS rpccli_samr_lookup_names(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1582 POLICY_HND *domain_pol, uint32 flags,
1583 uint32 num_names, const char **names,
1584 uint32 *num_rids, uint32 **rids,
1587 prs_struct qbuf, rbuf;
1588 SAMR_Q_LOOKUP_NAMES q;
1589 SAMR_R_LOOKUP_NAMES r;
1590 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1593 DEBUG(10,("cli_samr_lookup_names\n"));
1598 /* Marshall data and send request */
1600 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1603 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_NAMES,
1606 samr_io_q_lookup_names,
1607 samr_io_r_lookup_names,
1608 NT_STATUS_UNSUCCESSFUL);
1610 /* Return output parameters */
1612 if (!NT_STATUS_IS_OK(result = r.status)) {
1616 if (r.num_rids1 == 0) {
1621 *num_rids = r.num_rids1;
1622 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1623 *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1625 if ((*rids == NULL) || (*rid_types == NULL)) {
1627 TALLOC_FREE(*rid_types);
1628 return NT_STATUS_NO_MEMORY;
1631 for (i = 0; i < r.num_rids1; i++) {
1632 (*rids)[i] = r.rids[i];
1633 (*rid_types)[i] = r.types[i];
1641 /* Create a domain user */
1643 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1644 POLICY_HND *domain_pol, const char *acct_name,
1645 uint32 acb_info, uint32 unknown,
1646 POLICY_HND *user_pol, uint32 *rid)
1648 prs_struct qbuf, rbuf;
1649 SAMR_Q_CREATE_USER q;
1650 SAMR_R_CREATE_USER r;
1651 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1653 DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
1658 /* Marshall data and send request */
1660 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1662 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
1665 samr_io_q_create_user,
1666 samr_io_r_create_user,
1667 NT_STATUS_UNSUCCESSFUL);
1669 /* Return output parameters */
1671 if (!NT_STATUS_IS_OK(result = r.status)) {
1676 *user_pol = r.user_pol;
1688 NTSTATUS rpccli_samr_set_userinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1689 const POLICY_HND *user_pol, uint16 switch_value,
1690 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1692 prs_struct qbuf, rbuf;
1693 SAMR_Q_SET_USERINFO q;
1694 SAMR_R_SET_USERINFO r;
1695 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1697 DEBUG(10,("cli_samr_set_userinfo\n"));
1702 if (!sess_key->length) {
1703 DEBUG(1, ("No user session key\n"));
1704 return NT_STATUS_NO_USER_SESSION_KEY;
1707 /* Initialise parse structures */
1709 prs_init(&qbuf, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1710 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1712 /* Marshall data and send request */
1716 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1719 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO,
1722 samr_io_q_set_userinfo,
1723 samr_io_r_set_userinfo,
1724 NT_STATUS_UNSUCCESSFUL);
1726 /* Return output parameters */
1728 if (!NT_STATUS_IS_OK(result = r.status)) {
1739 NTSTATUS rpccli_samr_set_userinfo2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1740 const POLICY_HND *user_pol, uint16 switch_value,
1741 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1743 prs_struct qbuf, rbuf;
1744 SAMR_Q_SET_USERINFO2 q;
1745 SAMR_R_SET_USERINFO2 r;
1746 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1748 DEBUG(10,("cli_samr_set_userinfo2\n"));
1750 if (!sess_key->length) {
1751 DEBUG(1, ("No user session key\n"));
1752 return NT_STATUS_NO_USER_SESSION_KEY;
1758 /* Marshall data and send request */
1760 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1762 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO2,
1765 samr_io_q_set_userinfo2,
1766 samr_io_r_set_userinfo2,
1767 NT_STATUS_UNSUCCESSFUL);
1769 /* Return output parameters */
1771 if (!NT_STATUS_IS_OK(result = r.status)) {
1780 /* Delete domain group */
1782 NTSTATUS rpccli_samr_delete_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1783 POLICY_HND *group_pol)
1785 prs_struct qbuf, rbuf;
1786 SAMR_Q_DELETE_DOM_GROUP q;
1787 SAMR_R_DELETE_DOM_GROUP r;
1788 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1790 DEBUG(10,("cli_samr_delete_dom_group\n"));
1795 /* Marshall data and send request */
1797 init_samr_q_delete_dom_group(&q, group_pol);
1799 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_GROUP,
1802 samr_io_q_delete_dom_group,
1803 samr_io_r_delete_dom_group,
1804 NT_STATUS_UNSUCCESSFUL);
1806 /* Return output parameters */
1813 /* Delete domain alias */
1815 NTSTATUS rpccli_samr_delete_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1816 POLICY_HND *alias_pol)
1818 prs_struct qbuf, rbuf;
1819 SAMR_Q_DELETE_DOM_ALIAS q;
1820 SAMR_R_DELETE_DOM_ALIAS r;
1821 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1823 DEBUG(10,("cli_samr_delete_dom_alias\n"));
1828 /* Marshall data and send request */
1830 init_samr_q_delete_dom_alias(&q, alias_pol);
1832 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_ALIAS,
1835 samr_io_q_delete_dom_alias,
1836 samr_io_r_delete_dom_alias,
1837 NT_STATUS_UNSUCCESSFUL);
1839 /* Return output parameters */
1846 /* Delete domain user */
1848 NTSTATUS rpccli_samr_delete_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1849 POLICY_HND *user_pol)
1851 prs_struct qbuf, rbuf;
1852 SAMR_Q_DELETE_DOM_USER q;
1853 SAMR_R_DELETE_DOM_USER r;
1854 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1856 DEBUG(10,("cli_samr_delete_dom_user\n"));
1861 /* Marshall data and send request */
1863 init_samr_q_delete_dom_user(&q, user_pol);
1865 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_USER,
1868 samr_io_q_delete_dom_user,
1869 samr_io_r_delete_dom_user,
1870 NT_STATUS_UNSUCCESSFUL);
1872 /* Return output parameters */
1879 /* Remove foreign SID */
1881 NTSTATUS rpccli_samr_remove_sid_foreign_domain(struct rpc_pipe_client *cli,
1882 TALLOC_CTX *mem_ctx,
1883 POLICY_HND *user_pol,
1886 prs_struct qbuf, rbuf;
1887 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN q;
1888 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN r;
1889 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1891 DEBUG(10,("cli_samr_remove_sid_foreign_domain\n"));
1896 /* Marshall data and send request */
1898 init_samr_q_remove_sid_foreign_domain(&q, user_pol, sid);
1900 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_REMOVE_SID_FOREIGN_DOMAIN,
1903 samr_io_q_remove_sid_foreign_domain,
1904 samr_io_r_remove_sid_foreign_domain,
1905 NT_STATUS_UNSUCCESSFUL);
1907 /* Return output parameters */
1914 /* Query user security object */
1916 NTSTATUS rpccli_samr_query_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1917 POLICY_HND *user_pol, uint32 sec_info,
1918 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1920 prs_struct qbuf, rbuf;
1921 SAMR_Q_QUERY_SEC_OBJ q;
1922 SAMR_R_QUERY_SEC_OBJ r;
1923 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1925 DEBUG(10,("cli_samr_query_sec_obj\n"));
1930 /* Marshall data and send request */
1932 init_samr_q_query_sec_obj(&q, user_pol, sec_info);
1934 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_SEC_OBJECT,
1937 samr_io_q_query_sec_obj,
1938 samr_io_r_query_sec_obj,
1939 NT_STATUS_UNSUCCESSFUL);
1941 /* Return output parameters */
1944 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1949 /* Set user security object */
1951 NTSTATUS rpccli_samr_set_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1952 POLICY_HND *user_pol, uint32 sec_info,
1953 SEC_DESC_BUF *sec_desc_buf)
1955 prs_struct qbuf, rbuf;
1956 SAMR_Q_SET_SEC_OBJ q;
1957 SAMR_R_SET_SEC_OBJ r;
1958 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1960 DEBUG(10,("cli_samr_set_sec_obj\n"));
1965 /* Marshall data and send request */
1967 init_samr_q_set_sec_obj(&q, user_pol, sec_info, sec_desc_buf);
1969 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_SEC_OBJECT,
1972 samr_io_q_set_sec_obj,
1973 samr_io_r_set_sec_obj,
1974 NT_STATUS_UNSUCCESSFUL);
1976 /* Return output parameters */
1984 /* Get domain password info */
1986 NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1987 uint16 *min_pwd_length, uint32 *password_properties)
1989 prs_struct qbuf, rbuf;
1990 SAMR_Q_GET_DOM_PWINFO q;
1991 SAMR_R_GET_DOM_PWINFO r;
1992 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1994 DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
1999 /* Marshall data and send request */
2001 init_samr_q_get_dom_pwinfo(&q, cli->cli->desthost);
2003 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DOM_PWINFO,
2006 samr_io_q_get_dom_pwinfo,
2007 samr_io_r_get_dom_pwinfo,
2008 NT_STATUS_UNSUCCESSFUL);
2010 /* Return output parameters */
2014 if (NT_STATUS_IS_OK(result)) {
2016 *min_pwd_length = r.min_pwd_length;
2017 if (password_properties)
2018 *password_properties = r.password_properties;
2024 /* Get domain password info */
2026 NTSTATUS rpccli_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2027 POLICY_HND *pol, uint16 *min_pwd_length,
2028 uint32 *password_properties, uint32 *unknown1)
2030 prs_struct qbuf, rbuf;
2031 SAMR_Q_GET_USRDOM_PWINFO q;
2032 SAMR_R_GET_USRDOM_PWINFO r;
2033 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2035 DEBUG(10,("cli_samr_get_usrdom_pwinfo\n"));
2040 /* Marshall data and send request */
2042 init_samr_q_get_usrdom_pwinfo(&q, pol);
2044 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_USRDOM_PWINFO,
2047 samr_io_q_get_usrdom_pwinfo,
2048 samr_io_r_get_usrdom_pwinfo,
2049 NT_STATUS_UNSUCCESSFUL);
2051 /* Return output parameters */
2055 if (NT_STATUS_IS_OK(result)) {
2057 *min_pwd_length = r.min_pwd_length;
2058 if (password_properties)
2059 *password_properties = r.password_properties;
2061 *unknown1 = r.unknown_1;
2068 /* Lookup Domain Name */
2070 NTSTATUS rpccli_samr_lookup_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2071 POLICY_HND *user_pol, char *domain_name,
2074 prs_struct qbuf, rbuf;
2075 SAMR_Q_LOOKUP_DOMAIN q;
2076 SAMR_R_LOOKUP_DOMAIN r;
2077 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2079 DEBUG(10,("cli_samr_lookup_domain\n"));
2084 /* Marshall data and send request */
2086 init_samr_q_lookup_domain(&q, user_pol, domain_name);
2088 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_DOMAIN,
2091 samr_io_q_lookup_domain,
2092 samr_io_r_lookup_domain,
2093 NT_STATUS_UNSUCCESSFUL);
2095 /* Return output parameters */
2099 if (NT_STATUS_IS_OK(result))
2100 sid_copy(sid, &r.dom_sid.sid);