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",
149 sid_string_dbg(domain_sid) ));
154 /* Marshall data and send request */
156 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
158 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_DOMAIN,
161 samr_io_q_open_domain,
162 samr_io_r_open_domain,
163 NT_STATUS_UNSUCCESSFUL);
165 /* Return output parameters */
167 if (NT_STATUS_IS_OK(result = r.status)) {
168 *domain_pol = r.domain_pol;
170 domain_pol->marker = malloc(1);
177 NTSTATUS rpccli_samr_open_user(struct rpc_pipe_client *cli,
179 POLICY_HND *domain_pol, uint32 access_mask,
180 uint32 user_rid, POLICY_HND *user_pol)
182 prs_struct qbuf, rbuf;
185 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
187 DEBUG(10,("cli_samr_open_user with rid 0x%x\n", user_rid ));
192 /* Marshall data and send request */
194 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
196 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_USER,
201 NT_STATUS_UNSUCCESSFUL);
203 /* Return output parameters */
205 if (NT_STATUS_IS_OK(result = r.status)) {
206 *user_pol = r.user_pol;
208 user_pol->marker = malloc(1);
215 /* Open handle on a group */
217 NTSTATUS rpccli_samr_open_group(struct rpc_pipe_client *cli,
219 POLICY_HND *domain_pol, uint32 access_mask,
220 uint32 group_rid, POLICY_HND *group_pol)
222 prs_struct qbuf, rbuf;
225 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
227 DEBUG(10,("cli_samr_open_group with rid 0x%x\n", group_rid ));
232 /* Marshall data and send request */
234 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
236 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_GROUP,
239 samr_io_q_open_group,
240 samr_io_r_open_group,
241 NT_STATUS_UNSUCCESSFUL);
243 /* Return output parameters */
245 if (NT_STATUS_IS_OK(result = r.status)) {
248 group_pol->marker = malloc(1);
255 /* Create domain group */
257 NTSTATUS rpccli_samr_create_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
258 POLICY_HND *domain_pol,
259 const char *group_name,
260 uint32 access_mask, POLICY_HND *group_pol)
262 prs_struct qbuf, rbuf;
263 SAMR_Q_CREATE_DOM_GROUP q;
264 SAMR_R_CREATE_DOM_GROUP r;
265 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
267 DEBUG(10,("cli_samr_create_dom_group\n"));
272 /* Marshall data and send request */
274 init_samr_q_create_dom_group(&q, domain_pol, group_name, access_mask);
276 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_GROUP,
279 samr_io_q_create_dom_group,
280 samr_io_r_create_dom_group,
281 NT_STATUS_UNSUCCESSFUL);
283 /* Return output parameters */
287 if (NT_STATUS_IS_OK(result))
293 /* Add a domain group member */
295 NTSTATUS rpccli_samr_add_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
296 POLICY_HND *group_pol, uint32 rid)
298 prs_struct qbuf, rbuf;
299 SAMR_Q_ADD_GROUPMEM q;
300 SAMR_R_ADD_GROUPMEM r;
301 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
303 DEBUG(10,("cli_samr_add_groupmem\n"));
308 /* Marshall data and send request */
310 init_samr_q_add_groupmem(&q, group_pol, rid);
312 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_GROUPMEM,
315 samr_io_q_add_groupmem,
316 samr_io_r_add_groupmem,
317 NT_STATUS_UNSUCCESSFUL);
319 /* Return output parameters */
326 /* Delete a domain group member */
328 NTSTATUS rpccli_samr_del_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
329 POLICY_HND *group_pol, uint32 rid)
331 prs_struct qbuf, rbuf;
332 SAMR_Q_DEL_GROUPMEM q;
333 SAMR_R_DEL_GROUPMEM r;
334 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
336 DEBUG(10,("cli_samr_del_groupmem\n"));
341 /* Marshall data and send request */
343 init_samr_q_del_groupmem(&q, group_pol, rid);
345 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_GROUPMEM,
348 samr_io_q_del_groupmem,
349 samr_io_r_del_groupmem,
350 NT_STATUS_UNSUCCESSFUL);
352 /* Return output parameters */
359 /* Query user info */
361 NTSTATUS rpccli_samr_query_userinfo(struct rpc_pipe_client *cli,
363 const POLICY_HND *user_pol,
365 SAM_USERINFO_CTR **ctr)
367 prs_struct qbuf, rbuf;
368 SAMR_Q_QUERY_USERINFO q;
369 SAMR_R_QUERY_USERINFO r;
370 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
372 DEBUG(10,("cli_samr_query_userinfo\n"));
377 /* Marshall data and send request */
379 init_samr_q_query_userinfo(&q, user_pol, switch_value);
381 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERINFO,
384 samr_io_q_query_userinfo,
385 samr_io_r_query_userinfo,
386 NT_STATUS_UNSUCCESSFUL);
388 /* Return output parameters */
398 NTSTATUS rpccli_samr_set_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
399 POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
401 prs_struct qbuf, rbuf;
402 SAMR_Q_SET_GROUPINFO q;
403 SAMR_R_SET_GROUPINFO r;
404 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
406 DEBUG(10,("cli_samr_set_groupinfo\n"));
411 /* Marshall data and send request */
413 init_samr_q_set_groupinfo(&q, group_pol, ctr);
415 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_GROUPINFO,
418 samr_io_q_set_groupinfo,
419 samr_io_r_set_groupinfo,
420 NT_STATUS_UNSUCCESSFUL);
422 /* Return output parameters */
429 /* Query group info */
431 NTSTATUS rpccli_samr_query_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
432 POLICY_HND *group_pol, uint32 info_level,
433 GROUP_INFO_CTR **ctr)
435 prs_struct qbuf, rbuf;
436 SAMR_Q_QUERY_GROUPINFO q;
437 SAMR_R_QUERY_GROUPINFO r;
438 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
440 DEBUG(10,("cli_samr_query_groupinfo\n"));
445 /* Marshall data and send request */
447 init_samr_q_query_groupinfo(&q, group_pol, info_level);
449 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPINFO,
452 samr_io_q_query_groupinfo,
453 samr_io_r_query_groupinfo,
454 NT_STATUS_UNSUCCESSFUL);
458 /* Return output parameters */
465 /* Query user groups */
467 NTSTATUS rpccli_samr_query_usergroups(struct rpc_pipe_client *cli,
469 POLICY_HND *user_pol,
473 prs_struct qbuf, rbuf;
474 SAMR_Q_QUERY_USERGROUPS q;
475 SAMR_R_QUERY_USERGROUPS r;
476 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
478 DEBUG(10,("cli_samr_query_usergroups\n"));
483 /* Marshall data and send request */
485 init_samr_q_query_usergroups(&q, user_pol);
487 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERGROUPS,
490 samr_io_q_query_usergroups,
491 samr_io_r_query_usergroups,
492 NT_STATUS_UNSUCCESSFUL);
494 /* Return output parameters */
496 if (NT_STATUS_IS_OK(result = r.status)) {
497 *num_groups = r.num_entries;
506 NTSTATUS rpccli_samr_set_aliasinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
507 POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
509 prs_struct qbuf, rbuf;
510 SAMR_Q_SET_ALIASINFO q;
511 SAMR_R_SET_ALIASINFO r;
512 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
514 DEBUG(10,("cli_samr_set_aliasinfo\n"));
519 /* Marshall data and send request */
521 init_samr_q_set_aliasinfo(&q, alias_pol, ctr);
523 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_ALIASINFO,
526 samr_io_q_set_aliasinfo,
527 samr_io_r_set_aliasinfo,
528 NT_STATUS_UNSUCCESSFUL);
530 /* Return output parameters */
537 /* Query user aliases */
539 NTSTATUS rpccli_samr_query_useraliases(struct rpc_pipe_client *cli,
541 POLICY_HND *dom_pol, uint32 num_sids,
543 uint32 *num_aliases, uint32 **als_rids)
545 prs_struct qbuf, rbuf;
546 SAMR_Q_QUERY_USERALIASES q;
547 SAMR_R_QUERY_USERALIASES r;
548 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
552 DEBUG(10,("cli_samr_query_useraliases\n"));
558 sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
559 if (sid_ptrs == NULL)
560 return NT_STATUS_NO_MEMORY;
565 for (i=0; i<num_sids; i++)
568 /* Marshall data and send request */
570 init_samr_q_query_useraliases(&q, dom_pol, num_sids, sid_ptrs, sid);
572 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERALIASES,
575 samr_io_q_query_useraliases,
576 samr_io_r_query_useraliases,
577 NT_STATUS_UNSUCCESSFUL);
579 /* Return output parameters */
581 if (NT_STATUS_IS_OK(result = r.status)) {
582 *num_aliases = r.num_entries;
589 /* Query user groups */
591 NTSTATUS rpccli_samr_query_groupmem(struct rpc_pipe_client *cli,
593 POLICY_HND *group_pol, uint32 *num_mem,
594 uint32 **rid, uint32 **attr)
596 prs_struct qbuf, rbuf;
597 SAMR_Q_QUERY_GROUPMEM q;
598 SAMR_R_QUERY_GROUPMEM r;
599 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
601 DEBUG(10,("cli_samr_query_groupmem\n"));
606 /* Marshall data and send request */
608 init_samr_q_query_groupmem(&q, group_pol);
610 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPMEM,
613 samr_io_q_query_groupmem,
614 samr_io_r_query_groupmem,
615 NT_STATUS_UNSUCCESSFUL);
617 /* Return output parameters */
619 if (NT_STATUS_IS_OK(result = r.status)) {
620 *num_mem = r.num_entries;
629 * Enumerate domain users
631 * @param cli client state structure
632 * @param mem_ctx talloc context
633 * @param pol opened domain policy handle
634 * @param start_idx starting index of enumeration, returns context for
636 * @param acb_mask account control bit mask (to enumerate some particular
638 * @param size max acceptable size of response
639 * @param dom_users returned array of domain user names
640 * @param rids returned array of domain user RIDs
641 * @param num_dom_users numer returned entries
643 * @return NTSTATUS returned in rpc response
646 NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
647 POLICY_HND *pol, uint32 *start_idx, uint32 acb_mask,
648 uint32 size, char ***dom_users, uint32 **rids,
649 uint32 *num_dom_users)
653 SAMR_Q_ENUM_DOM_USERS q;
654 SAMR_R_ENUM_DOM_USERS r;
655 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
658 DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
663 /* always init this */
666 /* Fill query structure with parameters */
668 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, size);
670 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_USERS,
673 samr_io_q_enum_dom_users,
674 samr_io_r_enum_dom_users,
675 NT_STATUS_UNSUCCESSFUL);
679 if (!NT_STATUS_IS_OK(result) &&
680 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
683 *start_idx = r.next_idx;
684 *num_dom_users = r.num_entries2;
686 if (r.num_entries2) {
687 /* allocate memory needed to return received data */
688 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
690 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
691 return NT_STATUS_NO_MEMORY;
694 *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
696 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
697 return NT_STATUS_NO_MEMORY;
700 /* fill output buffers with rpc response */
701 for (i = 0; i < r.num_entries2; i++) {
704 (*rids)[i] = r.sam[i].rid;
705 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf));
706 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
714 /* Enumerate domain groups */
716 NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli,
718 POLICY_HND *pol, uint32 *start_idx,
719 uint32 size, struct acct_info **dom_groups,
720 uint32 *num_dom_groups)
722 prs_struct qbuf, rbuf;
723 SAMR_Q_ENUM_DOM_GROUPS q;
724 SAMR_R_ENUM_DOM_GROUPS r;
725 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
728 DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
733 /* Marshall data and send request */
735 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
737 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_GROUPS,
740 samr_io_q_enum_dom_groups,
741 samr_io_r_enum_dom_groups,
742 NT_STATUS_UNSUCCESSFUL);
744 /* Return output parameters */
748 if (!NT_STATUS_IS_OK(result) &&
749 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
752 *num_dom_groups = r.num_entries2;
754 if (*num_dom_groups == 0)
757 if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
758 result = NT_STATUS_NO_MEMORY;
762 memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
766 for (i = 0; i < *num_dom_groups; i++) {
768 (*dom_groups)[i].rid = r.sam[i].rid;
770 if (r.sam[i].hdr_name.buffer) {
771 unistr2_to_ascii((*dom_groups)[i].acct_name,
772 &r.uni_grp_name[name_idx],
773 sizeof((*dom_groups)[i].acct_name));
777 *start_idx = r.next_idx;
784 /* Enumerate domain groups */
786 NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli,
788 POLICY_HND *pol, uint32 *start_idx,
789 uint32 size, struct acct_info **dom_aliases,
790 uint32 *num_dom_aliases)
792 prs_struct qbuf, rbuf;
793 SAMR_Q_ENUM_DOM_ALIASES q;
794 SAMR_R_ENUM_DOM_ALIASES r;
795 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
798 DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
803 /* Marshall data and send request */
805 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
807 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_ALIASES,
810 samr_io_q_enum_dom_aliases,
811 samr_io_r_enum_dom_aliases,
812 NT_STATUS_UNSUCCESSFUL);
814 /* Return output parameters */
818 if (!NT_STATUS_IS_OK(result) &&
819 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
823 *num_dom_aliases = r.num_entries2;
825 if (*num_dom_aliases == 0)
828 if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
829 result = NT_STATUS_NO_MEMORY;
833 memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
837 for (i = 0; i < *num_dom_aliases; i++) {
839 (*dom_aliases)[i].rid = r.sam[i].rid;
841 if (r.sam[i].hdr_name.buffer) {
842 unistr2_to_ascii((*dom_aliases)[i].acct_name,
843 &r.uni_grp_name[name_idx],
844 sizeof((*dom_aliases)[i].acct_name));
848 *start_idx = r.next_idx;
855 /* Query alias members */
857 NTSTATUS rpccli_samr_query_aliasmem(struct rpc_pipe_client *cli,
859 POLICY_HND *alias_pol, uint32 *num_mem,
862 prs_struct qbuf, rbuf;
863 SAMR_Q_QUERY_ALIASMEM q;
864 SAMR_R_QUERY_ALIASMEM r;
865 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
868 DEBUG(10,("cli_samr_query_aliasmem\n"));
873 /* Marshall data and send request */
875 init_samr_q_query_aliasmem(&q, alias_pol);
877 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASMEM,
880 samr_io_q_query_aliasmem,
881 samr_io_r_query_aliasmem,
882 NT_STATUS_UNSUCCESSFUL);
884 /* Return output parameters */
886 if (!NT_STATUS_IS_OK(result = r.status)) {
890 *num_mem = r.num_sids;
894 result = NT_STATUS_OK;
898 if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
899 result = NT_STATUS_UNSUCCESSFUL;
903 for (i = 0; i < *num_mem; i++) {
904 (*sids)[i] = r.sid[i].sid;
911 /* Open handle on an alias */
913 NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli,
915 POLICY_HND *domain_pol, uint32 access_mask,
916 uint32 alias_rid, POLICY_HND *alias_pol)
918 prs_struct qbuf, rbuf;
923 DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
928 /* Marshall data and send request */
930 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
932 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_ALIAS,
935 samr_io_q_open_alias,
936 samr_io_r_open_alias,
937 NT_STATUS_UNSUCCESSFUL);
939 /* Return output parameters */
941 if (NT_STATUS_IS_OK(result = r.status)) {
944 alias_pol->marker = malloc(1);
951 /* Create an alias */
953 NTSTATUS rpccli_samr_create_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
954 POLICY_HND *domain_pol, const char *name,
955 POLICY_HND *alias_pol)
957 prs_struct qbuf, rbuf;
958 SAMR_Q_CREATE_DOM_ALIAS q;
959 SAMR_R_CREATE_DOM_ALIAS r;
962 DEBUG(10,("cli_samr_create_dom_alias named %s\n", name));
967 /* Marshall data and send request */
969 init_samr_q_create_dom_alias(&q, domain_pol, name);
971 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_ALIAS,
974 samr_io_q_create_dom_alias,
975 samr_io_r_create_dom_alias,
976 NT_STATUS_UNSUCCESSFUL);
978 /* Return output parameters */
980 if (NT_STATUS_IS_OK(result = r.status)) {
981 *alias_pol = r.alias_pol;
987 /* Add an alias member */
989 NTSTATUS rpccli_samr_add_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
990 POLICY_HND *alias_pol, DOM_SID *member)
992 prs_struct qbuf, rbuf;
993 SAMR_Q_ADD_ALIASMEM q;
994 SAMR_R_ADD_ALIASMEM r;
997 DEBUG(10,("cli_samr_add_aliasmem"));
1002 /* Marshall data and send request */
1004 init_samr_q_add_aliasmem(&q, alias_pol, member);
1006 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_ALIASMEM,
1009 samr_io_q_add_aliasmem,
1010 samr_io_r_add_aliasmem,
1011 NT_STATUS_UNSUCCESSFUL);
1018 /* Delete an alias member */
1020 NTSTATUS rpccli_samr_del_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1021 POLICY_HND *alias_pol, DOM_SID *member)
1023 prs_struct qbuf, rbuf;
1024 SAMR_Q_DEL_ALIASMEM q;
1025 SAMR_R_DEL_ALIASMEM r;
1028 DEBUG(10,("cli_samr_del_aliasmem"));
1033 /* Marshall data and send request */
1035 init_samr_q_del_aliasmem(&q, alias_pol, member);
1037 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_ALIASMEM,
1040 samr_io_q_del_aliasmem,
1041 samr_io_r_del_aliasmem,
1042 NT_STATUS_UNSUCCESSFUL);
1049 /* Query alias info */
1051 NTSTATUS rpccli_samr_query_alias_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1052 POLICY_HND *alias_pol, uint16 switch_value,
1053 ALIAS_INFO_CTR *ctr)
1055 prs_struct qbuf, rbuf;
1056 SAMR_Q_QUERY_ALIASINFO q;
1057 SAMR_R_QUERY_ALIASINFO r;
1058 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1060 DEBUG(10,("cli_samr_query_alias_info\n"));
1065 /* Marshall data and send request */
1067 init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
1069 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASINFO,
1072 samr_io_q_query_aliasinfo,
1073 samr_io_r_query_aliasinfo,
1074 NT_STATUS_UNSUCCESSFUL);
1076 /* Return output parameters */
1078 if (!NT_STATUS_IS_OK(result = r.status)) {
1089 /* Query domain info */
1091 NTSTATUS rpccli_samr_query_dom_info(struct rpc_pipe_client *cli,
1092 TALLOC_CTX *mem_ctx,
1093 POLICY_HND *domain_pol,
1094 uint16 switch_value,
1097 prs_struct qbuf, rbuf;
1098 SAMR_Q_QUERY_DOMAIN_INFO q;
1099 SAMR_R_QUERY_DOMAIN_INFO r;
1100 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1102 DEBUG(10,("cli_samr_query_dom_info\n"));
1107 /* Marshall data and send request */
1109 init_samr_q_query_domain_info(&q, domain_pol, switch_value);
1113 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO,
1116 samr_io_q_query_domain_info,
1117 samr_io_r_query_domain_info,
1118 NT_STATUS_UNSUCCESSFUL);
1120 /* Return output parameters */
1122 if (!NT_STATUS_IS_OK(result = r.status)) {
1131 /* Query domain info2 */
1133 NTSTATUS rpccli_samr_query_dom_info2(struct rpc_pipe_client *cli,
1134 TALLOC_CTX *mem_ctx,
1135 POLICY_HND *domain_pol,
1136 uint16 switch_value,
1139 prs_struct qbuf, rbuf;
1140 SAMR_Q_QUERY_DOMAIN_INFO2 q;
1141 SAMR_R_QUERY_DOMAIN_INFO2 r;
1142 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1144 DEBUG(10,("cli_samr_query_dom_info2\n"));
1149 /* Marshall data and send request */
1151 init_samr_q_query_domain_info2(&q, domain_pol, switch_value);
1155 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO2,
1158 samr_io_q_query_domain_info2,
1159 samr_io_r_query_domain_info2,
1160 NT_STATUS_UNSUCCESSFUL);
1162 /* Return output parameters */
1164 if (!NT_STATUS_IS_OK(result = r.status)) {
1173 /* Set domain info */
1175 NTSTATUS rpccli_samr_set_domain_info(struct rpc_pipe_client *cli,
1176 TALLOC_CTX *mem_ctx,
1177 POLICY_HND *domain_pol,
1178 uint16 switch_value,
1181 prs_struct qbuf, rbuf;
1182 SAMR_Q_SET_DOMAIN_INFO q;
1183 SAMR_R_SET_DOMAIN_INFO r;
1184 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1186 DEBUG(10,("cli_samr_set_domain_info\n"));
1191 /* Marshall data and send request */
1193 init_samr_q_set_domain_info(&q, domain_pol, switch_value, ctr);
1195 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_DOMAIN_INFO,
1198 samr_io_q_set_domain_info,
1199 samr_io_r_set_domain_info,
1200 NT_STATUS_UNSUCCESSFUL);
1202 /* Return output parameters */
1204 if (!NT_STATUS_IS_OK(result = r.status)) {
1213 /* User change password */
1215 NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli,
1216 TALLOC_CTX *mem_ctx,
1217 const char *username,
1218 const char *newpassword,
1219 const char *oldpassword )
1221 prs_struct qbuf, rbuf;
1222 SAMR_Q_CHGPASSWD_USER q;
1223 SAMR_R_CHGPASSWD_USER r;
1224 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1226 uchar new_nt_password[516];
1227 uchar new_lm_password[516];
1228 uchar old_nt_hash[16];
1229 uchar old_lanman_hash[16];
1230 uchar old_nt_hash_enc[16];
1231 uchar old_lanman_hash_enc[16];
1233 uchar new_nt_hash[16];
1234 uchar new_lanman_hash[16];
1236 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1238 DEBUG(10,("rpccli_samr_chgpasswd_user\n"));
1243 /* Calculate the MD4 hash (NT compatible) of the password */
1244 E_md4hash(oldpassword, old_nt_hash);
1245 E_md4hash(newpassword, new_nt_hash);
1247 if (lp_client_lanman_auth()
1248 && E_deshash(newpassword, new_lanman_hash)
1249 && E_deshash(oldpassword, old_lanman_hash)) {
1250 /* E_deshash returns false for 'long' passwords (> 14
1251 DOS chars). This allows us to match Win2k, which
1252 does not store a LM hash for these passwords (which
1253 would reduce the effective password length to 14) */
1255 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1257 SamOEMhash( new_lm_password, old_nt_hash, 516);
1258 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1260 ZERO_STRUCT(new_lm_password);
1261 ZERO_STRUCT(old_lanman_hash_enc);
1264 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1266 SamOEMhash( new_nt_password, old_nt_hash, 516);
1267 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1269 /* Marshall data and send request */
1271 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1275 old_lanman_hash_enc);
1277 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1280 samr_io_q_chgpasswd_user,
1281 samr_io_r_chgpasswd_user,
1282 NT_STATUS_UNSUCCESSFUL);
1284 /* Return output parameters */
1286 if (!NT_STATUS_IS_OK(result = r.status)) {
1295 /* User change password given blobs */
1297 NTSTATUS rpccli_samr_chng_pswd_auth_crap(struct rpc_pipe_client *cli,
1298 TALLOC_CTX *mem_ctx,
1299 const char *username,
1300 DATA_BLOB new_nt_password,
1301 DATA_BLOB old_nt_hash_enc,
1302 DATA_BLOB new_lm_password,
1303 DATA_BLOB old_lm_hash_enc)
1305 prs_struct qbuf, rbuf;
1306 SAMR_Q_CHGPASSWD_USER q;
1307 SAMR_R_CHGPASSWD_USER r;
1308 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1310 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1312 DEBUG(10,("rpccli_samr_chng_pswd_auth_crap\n"));
1317 /* Marshall data and send request */
1319 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1320 new_nt_password.data,
1321 old_nt_hash_enc.data,
1322 new_lm_password.data,
1323 old_lm_hash_enc.data);
1325 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1328 samr_io_q_chgpasswd_user,
1329 samr_io_r_chgpasswd_user,
1330 NT_STATUS_UNSUCCESSFUL);
1332 /* Return output parameters */
1334 if (!NT_STATUS_IS_OK(result = r.status)) {
1344 /* change password 3 */
1346 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
1347 TALLOC_CTX *mem_ctx,
1348 const char *username,
1349 const char *newpassword,
1350 const char *oldpassword,
1351 SAM_UNK_INFO_1 *info,
1352 SAMR_CHANGE_REJECT *reject)
1354 prs_struct qbuf, rbuf;
1355 SAMR_Q_CHGPASSWD_USER3 q;
1356 SAMR_R_CHGPASSWD_USER3 r;
1358 uchar new_nt_password[516];
1359 uchar new_lm_password[516];
1360 uchar old_nt_hash[16];
1361 uchar old_lanman_hash[16];
1362 uchar old_nt_hash_enc[16];
1363 uchar old_lanman_hash_enc[16];
1365 uchar new_nt_hash[16];
1366 uchar new_lanman_hash[16];
1368 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1370 DEBUG(10,("rpccli_samr_chgpasswd_user3\n"));
1375 /* Calculate the MD4 hash (NT compatible) of the password */
1376 E_md4hash(oldpassword, old_nt_hash);
1377 E_md4hash(newpassword, new_nt_hash);
1379 if (lp_client_lanman_auth()
1380 && E_deshash(newpassword, new_lanman_hash)
1381 && E_deshash(oldpassword, old_lanman_hash)) {
1382 /* E_deshash returns false for 'long' passwords (> 14
1383 DOS chars). This allows us to match Win2k, which
1384 does not store a LM hash for these passwords (which
1385 would reduce the effective password length to 14) */
1387 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1389 SamOEMhash( new_lm_password, old_nt_hash, 516);
1390 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1392 ZERO_STRUCT(new_lm_password);
1393 ZERO_STRUCT(old_lanman_hash_enc);
1396 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1398 SamOEMhash( new_nt_password, old_nt_hash, 516);
1399 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1401 /* Marshall data and send request */
1403 init_samr_q_chgpasswd_user3(&q, srv_name_slash, username,
1407 old_lanman_hash_enc);
1411 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER3,
1414 samr_io_q_chgpasswd_user3,
1415 samr_io_r_chgpasswd_user3,
1416 NT_STATUS_UNSUCCESSFUL);
1418 /* Return output parameters */
1423 /* This function returns the bizzare set of (max_entries, max_size) required
1424 for the QueryDisplayInfo RPC to actually work against a domain controller
1425 with large (10k and higher) numbers of users. These values were
1426 obtained by inspection using ethereal and NT4 running User Manager. */
1428 void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
1431 switch(loop_count) {
1437 *max_entries = 1024;
1441 *max_entries = 2048;
1445 *max_entries = 4096;
1448 default: /* loop_count >= 4 */
1449 *max_entries = 4096;
1455 /* Query display info */
1457 NTSTATUS rpccli_samr_query_dispinfo(struct rpc_pipe_client *cli,
1458 TALLOC_CTX *mem_ctx,
1459 POLICY_HND *domain_pol, uint32 *start_idx,
1460 uint16 switch_value, uint32 *num_entries,
1461 uint32 max_entries, uint32 max_size,
1462 SAM_DISPINFO_CTR *ctr)
1464 prs_struct qbuf, rbuf;
1465 SAMR_Q_QUERY_DISPINFO q;
1466 SAMR_R_QUERY_DISPINFO r;
1467 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1469 DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
1476 /* Marshall data and send request */
1478 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1479 *start_idx, max_entries, max_size);
1483 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO,
1486 samr_io_q_query_dispinfo,
1487 samr_io_r_query_dispinfo,
1488 NT_STATUS_UNSUCCESSFUL);
1490 /* Return output parameters */
1494 if (!NT_STATUS_IS_OK(result) &&
1495 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1499 *num_entries = r.num_entries;
1500 *start_idx += r.num_entries; /* No next_idx in this structure! */
1506 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1507 looked up in one packet. */
1509 NTSTATUS rpccli_samr_lookup_rids(struct rpc_pipe_client *cli,
1510 TALLOC_CTX *mem_ctx,
1511 POLICY_HND *domain_pol,
1512 uint32 num_rids, uint32 *rids,
1513 uint32 *num_names, char ***names,
1514 uint32 **name_types)
1516 prs_struct qbuf, rbuf;
1517 SAMR_Q_LOOKUP_RIDS q;
1518 SAMR_R_LOOKUP_RIDS r;
1519 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1522 DEBUG(10,("cli_samr_lookup_rids\n"));
1524 if (num_rids > 1000) {
1525 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1526 "more than ~1000 rids are looked up at once.\n"));
1532 /* Marshall data and send request */
1534 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, 1000, num_rids, rids);
1536 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_RIDS,
1539 samr_io_q_lookup_rids,
1540 samr_io_r_lookup_rids,
1541 NT_STATUS_UNSUCCESSFUL);
1543 /* Return output parameters */
1547 if (!NT_STATUS_IS_OK(result) &&
1548 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1551 if (r.num_names1 == 0) {
1557 *num_names = r.num_names1;
1558 *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
1559 *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
1561 if ((*names == NULL) || (*name_types == NULL)) {
1562 TALLOC_FREE(*names);
1563 TALLOC_FREE(*name_types);
1564 return NT_STATUS_NO_MEMORY;
1567 for (i = 0; i < r.num_names1; i++) {
1570 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp));
1571 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1572 (*name_types)[i] = r.type[i];
1582 NTSTATUS rpccli_samr_lookup_names(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1583 POLICY_HND *domain_pol, uint32 flags,
1584 uint32 num_names, const char **names,
1585 uint32 *num_rids, uint32 **rids,
1588 prs_struct qbuf, rbuf;
1589 SAMR_Q_LOOKUP_NAMES q;
1590 SAMR_R_LOOKUP_NAMES r;
1591 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1594 DEBUG(10,("cli_samr_lookup_names\n"));
1599 /* Marshall data and send request */
1601 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1604 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_NAMES,
1607 samr_io_q_lookup_names,
1608 samr_io_r_lookup_names,
1609 NT_STATUS_UNSUCCESSFUL);
1611 /* Return output parameters */
1613 if (!NT_STATUS_IS_OK(result = r.status)) {
1617 if (r.num_rids1 == 0) {
1622 *num_rids = r.num_rids1;
1623 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1624 *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1626 if ((*rids == NULL) || (*rid_types == NULL)) {
1628 TALLOC_FREE(*rid_types);
1629 return NT_STATUS_NO_MEMORY;
1632 for (i = 0; i < r.num_rids1; i++) {
1633 (*rids)[i] = r.rids[i];
1634 (*rid_types)[i] = r.types[i];
1642 /* Create a domain user */
1644 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1645 POLICY_HND *domain_pol, const char *acct_name,
1646 uint32 acb_info, uint32 access_mask,
1647 POLICY_HND *user_pol, uint32 *rid)
1649 prs_struct qbuf, rbuf;
1650 SAMR_Q_CREATE_USER q;
1651 SAMR_R_CREATE_USER r;
1652 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1654 DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
1659 /* Marshall data and send request */
1661 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, access_mask);
1663 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
1666 samr_io_q_create_user,
1667 samr_io_r_create_user,
1668 NT_STATUS_UNSUCCESSFUL);
1670 /* Return output parameters */
1672 if (!NT_STATUS_IS_OK(result = r.status)) {
1677 *user_pol = r.user_pol;
1689 NTSTATUS rpccli_samr_set_userinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1690 const POLICY_HND *user_pol, uint16 switch_value,
1691 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1693 prs_struct qbuf, rbuf;
1694 SAMR_Q_SET_USERINFO q;
1695 SAMR_R_SET_USERINFO r;
1696 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1698 DEBUG(10,("cli_samr_set_userinfo\n"));
1703 if (!sess_key->length) {
1704 DEBUG(1, ("No user session key\n"));
1705 return NT_STATUS_NO_USER_SESSION_KEY;
1708 /* Initialise parse structures */
1710 prs_init(&qbuf, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1711 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1713 /* Marshall data and send request */
1717 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1720 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO,
1723 samr_io_q_set_userinfo,
1724 samr_io_r_set_userinfo,
1725 NT_STATUS_UNSUCCESSFUL);
1727 /* Return output parameters */
1729 if (!NT_STATUS_IS_OK(result = r.status)) {
1740 NTSTATUS rpccli_samr_set_userinfo2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1741 const POLICY_HND *user_pol, uint16 switch_value,
1742 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1744 prs_struct qbuf, rbuf;
1745 SAMR_Q_SET_USERINFO2 q;
1746 SAMR_R_SET_USERINFO2 r;
1747 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1749 DEBUG(10,("cli_samr_set_userinfo2\n"));
1751 if (!sess_key->length) {
1752 DEBUG(1, ("No user session key\n"));
1753 return NT_STATUS_NO_USER_SESSION_KEY;
1759 /* Marshall data and send request */
1761 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1763 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO2,
1766 samr_io_q_set_userinfo2,
1767 samr_io_r_set_userinfo2,
1768 NT_STATUS_UNSUCCESSFUL);
1770 /* Return output parameters */
1772 if (!NT_STATUS_IS_OK(result = r.status)) {
1781 /* Delete domain group */
1783 NTSTATUS rpccli_samr_delete_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1784 POLICY_HND *group_pol)
1786 prs_struct qbuf, rbuf;
1787 SAMR_Q_DELETE_DOM_GROUP q;
1788 SAMR_R_DELETE_DOM_GROUP r;
1789 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1791 DEBUG(10,("cli_samr_delete_dom_group\n"));
1796 /* Marshall data and send request */
1798 init_samr_q_delete_dom_group(&q, group_pol);
1800 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_GROUP,
1803 samr_io_q_delete_dom_group,
1804 samr_io_r_delete_dom_group,
1805 NT_STATUS_UNSUCCESSFUL);
1807 /* Return output parameters */
1814 /* Delete domain alias */
1816 NTSTATUS rpccli_samr_delete_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1817 POLICY_HND *alias_pol)
1819 prs_struct qbuf, rbuf;
1820 SAMR_Q_DELETE_DOM_ALIAS q;
1821 SAMR_R_DELETE_DOM_ALIAS r;
1822 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1824 DEBUG(10,("cli_samr_delete_dom_alias\n"));
1829 /* Marshall data and send request */
1831 init_samr_q_delete_dom_alias(&q, alias_pol);
1833 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_ALIAS,
1836 samr_io_q_delete_dom_alias,
1837 samr_io_r_delete_dom_alias,
1838 NT_STATUS_UNSUCCESSFUL);
1840 /* Return output parameters */
1847 /* Delete domain user */
1849 NTSTATUS rpccli_samr_delete_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1850 POLICY_HND *user_pol)
1852 prs_struct qbuf, rbuf;
1853 SAMR_Q_DELETE_DOM_USER q;
1854 SAMR_R_DELETE_DOM_USER r;
1855 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1857 DEBUG(10,("cli_samr_delete_dom_user\n"));
1862 /* Marshall data and send request */
1864 init_samr_q_delete_dom_user(&q, user_pol);
1866 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_USER,
1869 samr_io_q_delete_dom_user,
1870 samr_io_r_delete_dom_user,
1871 NT_STATUS_UNSUCCESSFUL);
1873 /* Return output parameters */
1880 /* Remove foreign SID */
1882 NTSTATUS rpccli_samr_remove_sid_foreign_domain(struct rpc_pipe_client *cli,
1883 TALLOC_CTX *mem_ctx,
1884 POLICY_HND *user_pol,
1887 prs_struct qbuf, rbuf;
1888 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN q;
1889 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN r;
1890 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1892 DEBUG(10,("cli_samr_remove_sid_foreign_domain\n"));
1897 /* Marshall data and send request */
1899 init_samr_q_remove_sid_foreign_domain(&q, user_pol, sid);
1901 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_REMOVE_SID_FOREIGN_DOMAIN,
1904 samr_io_q_remove_sid_foreign_domain,
1905 samr_io_r_remove_sid_foreign_domain,
1906 NT_STATUS_UNSUCCESSFUL);
1908 /* Return output parameters */
1915 /* Query user security object */
1917 NTSTATUS rpccli_samr_query_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1918 POLICY_HND *user_pol, uint32 sec_info,
1919 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1921 prs_struct qbuf, rbuf;
1922 SAMR_Q_QUERY_SEC_OBJ q;
1923 SAMR_R_QUERY_SEC_OBJ r;
1924 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1926 DEBUG(10,("cli_samr_query_sec_obj\n"));
1931 /* Marshall data and send request */
1933 init_samr_q_query_sec_obj(&q, user_pol, sec_info);
1935 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_SEC_OBJECT,
1938 samr_io_q_query_sec_obj,
1939 samr_io_r_query_sec_obj,
1940 NT_STATUS_UNSUCCESSFUL);
1942 /* Return output parameters */
1945 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1950 /* Set user security object */
1952 NTSTATUS rpccli_samr_set_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1953 POLICY_HND *user_pol, uint32 sec_info,
1954 SEC_DESC_BUF *sec_desc_buf)
1956 prs_struct qbuf, rbuf;
1957 SAMR_Q_SET_SEC_OBJ q;
1958 SAMR_R_SET_SEC_OBJ r;
1959 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1961 DEBUG(10,("cli_samr_set_sec_obj\n"));
1966 /* Marshall data and send request */
1968 init_samr_q_set_sec_obj(&q, user_pol, sec_info, sec_desc_buf);
1970 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_SEC_OBJECT,
1973 samr_io_q_set_sec_obj,
1974 samr_io_r_set_sec_obj,
1975 NT_STATUS_UNSUCCESSFUL);
1977 /* Return output parameters */
1985 /* Get domain password info */
1987 NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1988 uint16 *min_pwd_length, uint32 *password_properties)
1990 prs_struct qbuf, rbuf;
1991 SAMR_Q_GET_DOM_PWINFO q;
1992 SAMR_R_GET_DOM_PWINFO r;
1993 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1995 DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
2000 /* Marshall data and send request */
2002 init_samr_q_get_dom_pwinfo(&q, cli->cli->desthost);
2004 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DOM_PWINFO,
2007 samr_io_q_get_dom_pwinfo,
2008 samr_io_r_get_dom_pwinfo,
2009 NT_STATUS_UNSUCCESSFUL);
2011 /* Return output parameters */
2015 if (NT_STATUS_IS_OK(result)) {
2017 *min_pwd_length = r.min_pwd_length;
2018 if (password_properties)
2019 *password_properties = r.password_properties;
2025 /* Get domain password info */
2027 NTSTATUS rpccli_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2028 POLICY_HND *pol, uint16 *min_pwd_length,
2029 uint32 *password_properties, uint32 *unknown1)
2031 prs_struct qbuf, rbuf;
2032 SAMR_Q_GET_USRDOM_PWINFO q;
2033 SAMR_R_GET_USRDOM_PWINFO r;
2034 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2036 DEBUG(10,("cli_samr_get_usrdom_pwinfo\n"));
2041 /* Marshall data and send request */
2043 init_samr_q_get_usrdom_pwinfo(&q, pol);
2045 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_USRDOM_PWINFO,
2048 samr_io_q_get_usrdom_pwinfo,
2049 samr_io_r_get_usrdom_pwinfo,
2050 NT_STATUS_UNSUCCESSFUL);
2052 /* Return output parameters */
2056 if (NT_STATUS_IS_OK(result)) {
2058 *min_pwd_length = r.min_pwd_length;
2059 if (password_properties)
2060 *password_properties = r.password_properties;
2062 *unknown1 = r.unknown_1;
2069 /* Lookup Domain Name */
2071 NTSTATUS rpccli_samr_lookup_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2072 POLICY_HND *user_pol, char *domain_name,
2075 prs_struct qbuf, rbuf;
2076 SAMR_Q_LOOKUP_DOMAIN q;
2077 SAMR_R_LOOKUP_DOMAIN r;
2078 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2080 DEBUG(10,("cli_samr_lookup_domain\n"));
2085 /* Marshall data and send request */
2087 init_samr_q_lookup_domain(&q, user_pol, domain_name);
2089 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_DOMAIN,
2092 samr_io_q_lookup_domain,
2093 samr_io_r_lookup_domain,
2094 NT_STATUS_UNSUCCESSFUL);
2096 /* Return output parameters */
2100 if (NT_STATUS_IS_OK(result))
2101 sid_copy(sid, &r.dom_sid.sid);