2 Unix SMB/CIFS implementation.
4 Copyright (C) Tim Potter 2000-2001,
5 Copyright (C) Andrew Tridgell 1992-1997,2000,
6 Copyright (C) Rafal Szczesniak 2002.
7 Copyright (C) Jeremy Allison 2005.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /* Connect to SAMR database */
28 NTSTATUS rpccli_samr_connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
29 uint32 access_mask, POLICY_HND *connect_pol)
31 prs_struct qbuf, rbuf;
34 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
36 DEBUG(10,("cli_samr_connect to %s\n", cli->cli->desthost));
41 /* Marshall data and send request */
43 init_samr_q_connect(&q, cli->cli->desthost, access_mask);
45 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT,
50 NT_STATUS_UNSUCCESSFUL);
51 /* Return output parameters */
53 if (NT_STATUS_IS_OK(result = r.status)) {
54 *connect_pol = r.connect_pol;
56 connect_pol->marker = malloc(1);
63 /* Connect to SAMR database */
65 NTSTATUS rpccli_samr_connect4(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
66 uint32 access_mask, POLICY_HND *connect_pol)
68 prs_struct qbuf, rbuf;
71 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
76 /* Marshall data and send request */
78 init_samr_q_connect4(&q, cli->cli->desthost, access_mask);
80 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT4,
85 NT_STATUS_UNSUCCESSFUL);
87 /* Return output parameters */
89 if (NT_STATUS_IS_OK(result = r.status)) {
90 *connect_pol = r.connect_pol;
92 connect_pol->marker = malloc(1);
99 /* Close SAMR handle */
101 NTSTATUS rpccli_samr_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
102 POLICY_HND *connect_pol)
104 prs_struct qbuf, rbuf;
107 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
109 DEBUG(10,("cli_samr_close\n"));
114 /* Marshall data and send request */
116 init_samr_q_close_hnd(&q, connect_pol);
118 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CLOSE_HND,
123 NT_STATUS_UNSUCCESSFUL);
125 /* Return output parameters */
127 if (NT_STATUS_IS_OK(result = r.status)) {
129 SAFE_FREE(connect_pol->marker);
131 *connect_pol = r.pol;
137 /* Open handle on a domain */
139 NTSTATUS rpccli_samr_open_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
140 POLICY_HND *connect_pol, uint32 access_mask,
141 const DOM_SID *domain_sid,
142 POLICY_HND *domain_pol)
144 prs_struct qbuf, rbuf;
145 SAMR_Q_OPEN_DOMAIN q;
146 SAMR_R_OPEN_DOMAIN r;
147 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
149 DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(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 POLICY_HND *user_pol, uint16 switch_value,
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"));
556 sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
557 if (sid_ptrs == NULL)
558 return NT_STATUS_NO_MEMORY;
560 for (i=0; i<num_sids; i++)
563 /* Marshall data and send request */
565 init_samr_q_query_useraliases(&q, dom_pol, num_sids, sid_ptrs, sid);
567 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERALIASES,
570 samr_io_q_query_useraliases,
571 samr_io_r_query_useraliases,
572 NT_STATUS_UNSUCCESSFUL);
574 /* Return output parameters */
576 if (NT_STATUS_IS_OK(result = r.status)) {
577 *num_aliases = r.num_entries;
584 /* Query user groups */
586 NTSTATUS rpccli_samr_query_groupmem(struct rpc_pipe_client *cli,
588 POLICY_HND *group_pol, uint32 *num_mem,
589 uint32 **rid, uint32 **attr)
591 prs_struct qbuf, rbuf;
592 SAMR_Q_QUERY_GROUPMEM q;
593 SAMR_R_QUERY_GROUPMEM r;
594 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
596 DEBUG(10,("cli_samr_query_groupmem\n"));
601 /* Marshall data and send request */
603 init_samr_q_query_groupmem(&q, group_pol);
605 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPMEM,
608 samr_io_q_query_groupmem,
609 samr_io_r_query_groupmem,
610 NT_STATUS_UNSUCCESSFUL);
612 /* Return output parameters */
614 if (NT_STATUS_IS_OK(result = r.status)) {
615 *num_mem = r.num_entries;
624 * Enumerate domain users
626 * @param cli client state structure
627 * @param mem_ctx talloc context
628 * @param pol opened domain policy handle
629 * @param start_idx starting index of enumeration, returns context for
631 * @param acb_mask account control bit mask (to enumerate some particular
633 * @param size max acceptable size of response
634 * @param dom_users returned array of domain user names
635 * @param rids returned array of domain user RIDs
636 * @param num_dom_users numer returned entries
638 * @return NTSTATUS returned in rpc response
641 NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
642 POLICY_HND *pol, uint32 *start_idx, uint16 acb_mask,
643 uint32 size, char ***dom_users, uint32 **rids,
644 uint32 *num_dom_users)
648 SAMR_Q_ENUM_DOM_USERS q;
649 SAMR_R_ENUM_DOM_USERS r;
650 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
653 DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
658 /* always init this */
661 /* Fill query structure with parameters */
663 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, 0, size);
665 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_USERS,
668 samr_io_q_enum_dom_users,
669 samr_io_r_enum_dom_users,
670 NT_STATUS_UNSUCCESSFUL);
674 if (!NT_STATUS_IS_OK(result) &&
675 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
678 *start_idx = r.next_idx;
679 *num_dom_users = r.num_entries2;
681 if (r.num_entries2) {
682 /* allocate memory needed to return received data */
683 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
685 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
686 return NT_STATUS_NO_MEMORY;
689 *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
691 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
692 return NT_STATUS_NO_MEMORY;
695 /* fill output buffers with rpc response */
696 for (i = 0; i < r.num_entries2; i++) {
699 (*rids)[i] = r.sam[i].rid;
700 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
701 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
709 /* Enumerate domain groups */
711 NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli,
713 POLICY_HND *pol, uint32 *start_idx,
714 uint32 size, struct acct_info **dom_groups,
715 uint32 *num_dom_groups)
717 prs_struct qbuf, rbuf;
718 SAMR_Q_ENUM_DOM_GROUPS q;
719 SAMR_R_ENUM_DOM_GROUPS r;
720 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
723 DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
728 /* Marshall data and send request */
730 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
732 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_GROUPS,
735 samr_io_q_enum_dom_groups,
736 samr_io_r_enum_dom_groups,
737 NT_STATUS_UNSUCCESSFUL);
739 /* Return output parameters */
743 if (!NT_STATUS_IS_OK(result) &&
744 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
747 *num_dom_groups = r.num_entries2;
749 if (*num_dom_groups == 0)
752 if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
753 result = NT_STATUS_NO_MEMORY;
757 memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
761 for (i = 0; i < *num_dom_groups; i++) {
763 (*dom_groups)[i].rid = r.sam[i].rid;
765 if (r.sam[i].hdr_name.buffer) {
766 unistr2_to_ascii((*dom_groups)[i].acct_name,
767 &r.uni_grp_name[name_idx],
768 sizeof(fstring) - 1);
772 *start_idx = r.next_idx;
779 /* Enumerate domain groups */
781 NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli,
783 POLICY_HND *pol, uint32 *start_idx,
784 uint32 size, struct acct_info **dom_aliases,
785 uint32 *num_dom_aliases)
787 prs_struct qbuf, rbuf;
788 SAMR_Q_ENUM_DOM_ALIASES q;
789 SAMR_R_ENUM_DOM_ALIASES r;
790 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
793 DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
798 /* Marshall data and send request */
800 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
802 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_ALIASES,
805 samr_io_q_enum_dom_aliases,
806 samr_io_r_enum_dom_aliases,
807 NT_STATUS_UNSUCCESSFUL);
809 /* Return output parameters */
813 if (!NT_STATUS_IS_OK(result) &&
814 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
818 *num_dom_aliases = r.num_entries2;
820 if (*num_dom_aliases == 0)
823 if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
824 result = NT_STATUS_NO_MEMORY;
828 memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
832 for (i = 0; i < *num_dom_aliases; i++) {
834 (*dom_aliases)[i].rid = r.sam[i].rid;
836 if (r.sam[i].hdr_name.buffer) {
837 unistr2_to_ascii((*dom_aliases)[i].acct_name,
838 &r.uni_grp_name[name_idx],
839 sizeof(fstring) - 1);
843 *start_idx = r.next_idx;
850 /* Query alias members */
852 NTSTATUS rpccli_samr_query_aliasmem(struct rpc_pipe_client *cli,
854 POLICY_HND *alias_pol, uint32 *num_mem,
857 prs_struct qbuf, rbuf;
858 SAMR_Q_QUERY_ALIASMEM q;
859 SAMR_R_QUERY_ALIASMEM r;
860 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
863 DEBUG(10,("cli_samr_query_aliasmem\n"));
868 /* Marshall data and send request */
870 init_samr_q_query_aliasmem(&q, alias_pol);
872 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASMEM,
875 samr_io_q_query_aliasmem,
876 samr_io_r_query_aliasmem,
877 NT_STATUS_UNSUCCESSFUL);
879 /* Return output parameters */
881 if (!NT_STATUS_IS_OK(result = r.status)) {
885 *num_mem = r.num_sids;
889 result = NT_STATUS_OK;
893 if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
894 result = NT_STATUS_UNSUCCESSFUL;
898 for (i = 0; i < *num_mem; i++) {
899 (*sids)[i] = r.sid[i].sid;
906 /* Open handle on an alias */
908 NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli,
910 POLICY_HND *domain_pol, uint32 access_mask,
911 uint32 alias_rid, POLICY_HND *alias_pol)
913 prs_struct qbuf, rbuf;
918 DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
923 /* Marshall data and send request */
925 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
927 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_ALIAS,
930 samr_io_q_open_alias,
931 samr_io_r_open_alias,
932 NT_STATUS_UNSUCCESSFUL);
934 /* Return output parameters */
936 if (NT_STATUS_IS_OK(result = r.status)) {
939 alias_pol->marker = malloc(1);
946 /* Create an alias */
948 NTSTATUS rpccli_samr_create_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
949 POLICY_HND *domain_pol, const char *name,
950 POLICY_HND *alias_pol)
952 prs_struct qbuf, rbuf;
953 SAMR_Q_CREATE_DOM_ALIAS q;
954 SAMR_R_CREATE_DOM_ALIAS r;
957 DEBUG(10,("cli_samr_create_dom_alias named %s\n", name));
962 /* Marshall data and send request */
964 init_samr_q_create_dom_alias(&q, domain_pol, name);
966 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_ALIAS,
969 samr_io_q_create_dom_alias,
970 samr_io_r_create_dom_alias,
971 NT_STATUS_UNSUCCESSFUL);
973 /* Return output parameters */
975 if (NT_STATUS_IS_OK(result = r.status)) {
976 *alias_pol = r.alias_pol;
982 /* Add an alias member */
984 NTSTATUS rpccli_samr_add_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
985 POLICY_HND *alias_pol, DOM_SID *member)
987 prs_struct qbuf, rbuf;
988 SAMR_Q_ADD_ALIASMEM q;
989 SAMR_R_ADD_ALIASMEM r;
992 DEBUG(10,("cli_samr_add_aliasmem"));
997 /* Marshall data and send request */
999 init_samr_q_add_aliasmem(&q, alias_pol, member);
1001 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_ALIASMEM,
1004 samr_io_q_add_aliasmem,
1005 samr_io_r_add_aliasmem,
1006 NT_STATUS_UNSUCCESSFUL);
1013 /* Delete an alias member */
1015 NTSTATUS rpccli_samr_del_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1016 POLICY_HND *alias_pol, DOM_SID *member)
1018 prs_struct qbuf, rbuf;
1019 SAMR_Q_DEL_ALIASMEM q;
1020 SAMR_R_DEL_ALIASMEM r;
1023 DEBUG(10,("cli_samr_del_aliasmem"));
1028 /* Marshall data and send request */
1030 init_samr_q_del_aliasmem(&q, alias_pol, member);
1032 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_ALIASMEM,
1035 samr_io_q_del_aliasmem,
1036 samr_io_r_del_aliasmem,
1037 NT_STATUS_UNSUCCESSFUL);
1044 /* Query alias info */
1046 NTSTATUS rpccli_samr_query_alias_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1047 POLICY_HND *alias_pol, uint16 switch_value,
1048 ALIAS_INFO_CTR *ctr)
1050 prs_struct qbuf, rbuf;
1051 SAMR_Q_QUERY_ALIASINFO q;
1052 SAMR_R_QUERY_ALIASINFO r;
1053 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1055 DEBUG(10,("cli_samr_query_alias_info\n"));
1060 /* Marshall data and send request */
1062 init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
1064 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASINFO,
1067 samr_io_q_query_aliasinfo,
1068 samr_io_r_query_aliasinfo,
1069 NT_STATUS_UNSUCCESSFUL);
1071 /* Return output parameters */
1073 if (!NT_STATUS_IS_OK(result = r.status)) {
1084 /* Query domain info */
1086 NTSTATUS rpccli_samr_query_dom_info(struct rpc_pipe_client *cli,
1087 TALLOC_CTX *mem_ctx,
1088 POLICY_HND *domain_pol,
1089 uint16 switch_value,
1092 prs_struct qbuf, rbuf;
1093 SAMR_Q_QUERY_DOMAIN_INFO q;
1094 SAMR_R_QUERY_DOMAIN_INFO r;
1095 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1097 DEBUG(10,("cli_samr_query_dom_info\n"));
1102 /* Marshall data and send request */
1104 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
1108 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO,
1111 samr_io_q_query_dom_info,
1112 samr_io_r_query_dom_info,
1113 NT_STATUS_UNSUCCESSFUL);
1115 /* Return output parameters */
1117 if (!NT_STATUS_IS_OK(result = r.status)) {
1126 /* User change password */
1128 NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli,
1129 TALLOC_CTX *mem_ctx,
1130 const char *username,
1131 const char *newpassword,
1132 const char *oldpassword )
1134 prs_struct qbuf, rbuf;
1135 SAMR_Q_CHGPASSWD_USER q;
1136 SAMR_R_CHGPASSWD_USER r;
1137 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1139 uchar new_nt_password[516];
1140 uchar new_lm_password[516];
1141 uchar old_nt_hash[16];
1142 uchar old_lanman_hash[16];
1143 uchar old_nt_hash_enc[16];
1144 uchar old_lanman_hash_enc[16];
1146 uchar new_nt_hash[16];
1147 uchar new_lanman_hash[16];
1149 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1151 DEBUG(10,("rpccli_samr_chgpasswd_user\n"));
1156 /* Calculate the MD4 hash (NT compatible) of the password */
1157 E_md4hash(oldpassword, old_nt_hash);
1158 E_md4hash(newpassword, new_nt_hash);
1160 if (lp_client_lanman_auth()
1161 && E_deshash(newpassword, new_lanman_hash)
1162 && E_deshash(oldpassword, old_lanman_hash)) {
1163 /* E_deshash returns false for 'long' passwords (> 14
1164 DOS chars). This allows us to match Win2k, which
1165 does not store a LM hash for these passwords (which
1166 would reduce the effective password length to 14) */
1168 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1170 SamOEMhash( new_lm_password, old_nt_hash, 516);
1171 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1173 ZERO_STRUCT(new_lm_password);
1174 ZERO_STRUCT(old_lanman_hash_enc);
1177 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1179 SamOEMhash( new_nt_password, old_nt_hash, 516);
1180 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1182 /* Marshall data and send request */
1184 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1188 old_lanman_hash_enc);
1190 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1193 samr_io_q_chgpasswd_user,
1194 samr_io_r_chgpasswd_user,
1195 NT_STATUS_UNSUCCESSFUL);
1197 /* Return output parameters */
1199 if (!NT_STATUS_IS_OK(result = r.status)) {
1208 /* change password 3 */
1210 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
1211 TALLOC_CTX *mem_ctx,
1212 const char *username,
1213 const char *newpassword,
1214 const char *oldpassword,
1215 SAM_UNK_INFO_1 **info,
1216 SAMR_CHANGE_REJECT **reject)
1218 prs_struct qbuf, rbuf;
1219 SAMR_Q_CHGPASSWD3 q;
1220 SAMR_R_CHGPASSWD3 r;
1221 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1223 uchar new_nt_password[516];
1224 uchar new_lm_password[516];
1225 uchar old_nt_hash[16];
1226 uchar old_lanman_hash[16];
1227 uchar old_nt_hash_enc[16];
1228 uchar old_lanman_hash_enc[16];
1230 uchar new_nt_hash[16];
1231 uchar new_lanman_hash[16];
1233 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1235 DEBUG(10,("rpccli_samr_chgpasswd3\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_chgpasswd3(&q, srv_name_slash, username,
1275 old_lanman_hash_enc);
1277 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD3,
1280 samr_io_q_chgpasswd3,
1281 samr_io_r_chgpasswd3,
1282 NT_STATUS_UNSUCCESSFUL);
1284 /* Return output parameters */
1286 if (!NT_STATUS_IS_OK(result = r.status)) {
1288 *reject = &r.reject;
1297 /* This function returns the bizzare set of (max_entries, max_size) required
1298 for the QueryDisplayInfo RPC to actually work against a domain controller
1299 with large (10k and higher) numbers of users. These values were
1300 obtained by inspection using ethereal and NT4 running User Manager. */
1302 void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
1305 switch(loop_count) {
1311 *max_entries = 1024;
1315 *max_entries = 2048;
1319 *max_entries = 4096;
1322 default: /* loop_count >= 4 */
1323 *max_entries = 4096;
1329 /* Query display info */
1331 NTSTATUS rpccli_samr_query_dispinfo(struct rpc_pipe_client *cli,
1332 TALLOC_CTX *mem_ctx,
1333 POLICY_HND *domain_pol, uint32 *start_idx,
1334 uint16 switch_value, uint32 *num_entries,
1335 uint32 max_entries, uint32 max_size,
1336 SAM_DISPINFO_CTR *ctr)
1338 prs_struct qbuf, rbuf;
1339 SAMR_Q_QUERY_DISPINFO q;
1340 SAMR_R_QUERY_DISPINFO r;
1341 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1343 DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
1350 /* Marshall data and send request */
1352 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1353 *start_idx, max_entries, max_size);
1357 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO,
1360 samr_io_q_query_dispinfo,
1361 samr_io_r_query_dispinfo,
1362 NT_STATUS_UNSUCCESSFUL);
1364 /* Return output parameters */
1368 if (!NT_STATUS_IS_OK(result) &&
1369 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1373 *num_entries = r.num_entries;
1374 *start_idx += r.num_entries; /* No next_idx in this structure! */
1380 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1381 looked up in one packet. */
1383 NTSTATUS rpccli_samr_lookup_rids(struct rpc_pipe_client *cli,
1384 TALLOC_CTX *mem_ctx,
1385 POLICY_HND *domain_pol,
1386 uint32 num_rids, uint32 *rids,
1387 uint32 *num_names, char ***names,
1388 uint32 **name_types)
1390 prs_struct qbuf, rbuf;
1391 SAMR_Q_LOOKUP_RIDS q;
1392 SAMR_R_LOOKUP_RIDS r;
1393 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1396 DEBUG(10,("cli_samr_lookup_rids\n"));
1398 if (num_rids > 1000) {
1399 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1400 "more than ~1000 rids are looked up at once.\n"));
1406 /* Marshall data and send request */
1408 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, 1000, num_rids, rids);
1410 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_RIDS,
1413 samr_io_q_lookup_rids,
1414 samr_io_r_lookup_rids,
1415 NT_STATUS_UNSUCCESSFUL);
1417 /* Return output parameters */
1421 if (!NT_STATUS_IS_OK(result) &&
1422 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1425 if (r.num_names1 == 0) {
1431 *num_names = r.num_names1;
1432 *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
1433 *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
1435 for (i = 0; i < r.num_names1; i++) {
1438 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
1439 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1440 (*name_types)[i] = r.type[i];
1450 NTSTATUS rpccli_samr_lookup_names(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1451 POLICY_HND *domain_pol, uint32 flags,
1452 uint32 num_names, const char **names,
1453 uint32 *num_rids, uint32 **rids,
1456 prs_struct qbuf, rbuf;
1457 SAMR_Q_LOOKUP_NAMES q;
1458 SAMR_R_LOOKUP_NAMES r;
1459 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1462 DEBUG(10,("cli_samr_lookup_names\n"));
1467 /* Marshall data and send request */
1469 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1472 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_NAMES,
1475 samr_io_q_lookup_names,
1476 samr_io_r_lookup_names,
1477 NT_STATUS_UNSUCCESSFUL);
1479 /* Return output parameters */
1481 if (!NT_STATUS_IS_OK(result = r.status)) {
1485 if (r.num_rids1 == 0) {
1490 *num_rids = r.num_rids1;
1491 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1492 *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1494 for (i = 0; i < r.num_rids1; i++) {
1495 (*rids)[i] = r.rids[i];
1496 (*rid_types)[i] = r.types[i];
1504 /* Create a domain user */
1506 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1507 POLICY_HND *domain_pol, const char *acct_name,
1508 uint32 acb_info, uint32 unknown,
1509 POLICY_HND *user_pol, uint32 *rid)
1511 prs_struct qbuf, rbuf;
1512 SAMR_Q_CREATE_USER q;
1513 SAMR_R_CREATE_USER r;
1514 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1516 DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
1521 /* Marshall data and send request */
1523 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1525 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
1528 samr_io_q_create_user,
1529 samr_io_r_create_user,
1530 NT_STATUS_UNSUCCESSFUL);
1532 /* Return output parameters */
1534 if (!NT_STATUS_IS_OK(result = r.status)) {
1539 *user_pol = r.user_pol;
1551 NTSTATUS rpccli_samr_set_userinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1552 POLICY_HND *user_pol, uint16 switch_value,
1553 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1555 prs_struct qbuf, rbuf;
1556 SAMR_Q_SET_USERINFO q;
1557 SAMR_R_SET_USERINFO r;
1558 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1560 DEBUG(10,("cli_samr_set_userinfo\n"));
1565 if (!sess_key->length) {
1566 DEBUG(1, ("No user session key\n"));
1567 return NT_STATUS_NO_USER_SESSION_KEY;
1570 /* Initialise parse structures */
1572 prs_init(&qbuf, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1573 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1575 /* Marshall data and send request */
1579 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1582 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO,
1585 samr_io_q_set_userinfo,
1586 samr_io_r_set_userinfo,
1587 NT_STATUS_UNSUCCESSFUL);
1589 /* Return output parameters */
1591 if (!NT_STATUS_IS_OK(result = r.status)) {
1602 NTSTATUS rpccli_samr_set_userinfo2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1603 POLICY_HND *user_pol, uint16 switch_value,
1604 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1606 prs_struct qbuf, rbuf;
1607 SAMR_Q_SET_USERINFO2 q;
1608 SAMR_R_SET_USERINFO2 r;
1609 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1611 DEBUG(10,("cli_samr_set_userinfo2\n"));
1613 if (!sess_key->length) {
1614 DEBUG(1, ("No user session key\n"));
1615 return NT_STATUS_NO_USER_SESSION_KEY;
1621 /* Marshall data and send request */
1623 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1625 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO2,
1628 samr_io_q_set_userinfo2,
1629 samr_io_r_set_userinfo2,
1630 NT_STATUS_UNSUCCESSFUL);
1632 /* Return output parameters */
1634 if (!NT_STATUS_IS_OK(result = r.status)) {
1643 /* Delete domain group */
1645 NTSTATUS rpccli_samr_delete_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1646 POLICY_HND *group_pol)
1648 prs_struct qbuf, rbuf;
1649 SAMR_Q_DELETE_DOM_GROUP q;
1650 SAMR_R_DELETE_DOM_GROUP r;
1651 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1653 DEBUG(10,("cli_samr_delete_dom_group\n"));
1658 /* Marshall data and send request */
1660 init_samr_q_delete_dom_group(&q, group_pol);
1662 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_GROUP,
1665 samr_io_q_delete_dom_group,
1666 samr_io_r_delete_dom_group,
1667 NT_STATUS_UNSUCCESSFUL);
1669 /* Return output parameters */
1676 /* Delete domain alias */
1678 NTSTATUS rpccli_samr_delete_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1679 POLICY_HND *alias_pol)
1681 prs_struct qbuf, rbuf;
1682 SAMR_Q_DELETE_DOM_ALIAS q;
1683 SAMR_R_DELETE_DOM_ALIAS r;
1684 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1686 DEBUG(10,("cli_samr_delete_dom_alias\n"));
1691 /* Marshall data and send request */
1693 init_samr_q_delete_dom_alias(&q, alias_pol);
1695 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_ALIAS,
1698 samr_io_q_delete_dom_alias,
1699 samr_io_r_delete_dom_alias,
1700 NT_STATUS_UNSUCCESSFUL);
1702 /* Return output parameters */
1709 /* Delete domain user */
1711 NTSTATUS rpccli_samr_delete_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1712 POLICY_HND *user_pol)
1714 prs_struct qbuf, rbuf;
1715 SAMR_Q_DELETE_DOM_USER q;
1716 SAMR_R_DELETE_DOM_USER r;
1717 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1719 DEBUG(10,("cli_samr_delete_dom_user\n"));
1724 /* Marshall data and send request */
1726 init_samr_q_delete_dom_user(&q, user_pol);
1728 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_USER,
1731 samr_io_q_delete_dom_user,
1732 samr_io_r_delete_dom_user,
1733 NT_STATUS_UNSUCCESSFUL);
1735 /* Return output parameters */
1742 /* Remove foreign SID */
1744 NTSTATUS rpccli_samr_remove_sid_foreign_domain(struct rpc_pipe_client *cli,
1745 TALLOC_CTX *mem_ctx,
1746 POLICY_HND *user_pol,
1749 prs_struct qbuf, rbuf;
1750 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN q;
1751 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN r;
1752 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1754 DEBUG(10,("cli_samr_remove_sid_foreign_domain\n"));
1759 /* Marshall data and send request */
1761 init_samr_q_remove_sid_foreign_domain(&q, user_pol, sid);
1763 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_REMOVE_SID_FOREIGN_DOMAIN,
1766 samr_io_q_remove_sid_foreign_domain,
1767 samr_io_r_remove_sid_foreign_domain,
1768 NT_STATUS_UNSUCCESSFUL);
1770 /* Return output parameters */
1777 /* Query user security object */
1779 NTSTATUS rpccli_samr_query_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1780 POLICY_HND *user_pol, uint16 switch_value,
1781 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1783 prs_struct qbuf, rbuf;
1784 SAMR_Q_QUERY_SEC_OBJ q;
1785 SAMR_R_QUERY_SEC_OBJ r;
1786 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1788 DEBUG(10,("cli_samr_query_sec_obj\n"));
1793 /* Marshall data and send request */
1795 init_samr_q_query_sec_obj(&q, user_pol, switch_value);
1797 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_SEC_OBJECT,
1800 samr_io_q_query_sec_obj,
1801 samr_io_r_query_sec_obj,
1802 NT_STATUS_UNSUCCESSFUL);
1804 /* Return output parameters */
1807 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1812 /* Get domain password info */
1814 NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1815 uint16 *min_pwd_length, uint32 *password_properties)
1817 prs_struct qbuf, rbuf;
1818 SAMR_Q_GET_DOM_PWINFO q;
1819 SAMR_R_GET_DOM_PWINFO r;
1820 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1822 DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
1827 /* Marshall data and send request */
1829 init_samr_q_get_dom_pwinfo(&q, cli->cli->desthost);
1831 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DOM_PWINFO,
1834 samr_io_q_get_dom_pwinfo,
1835 samr_io_r_get_dom_pwinfo,
1836 NT_STATUS_UNSUCCESSFUL);
1838 /* Return output parameters */
1842 if (NT_STATUS_IS_OK(result)) {
1844 *min_pwd_length = r.min_pwd_length;
1845 if (password_properties)
1846 *password_properties = r.password_properties;
1852 /* Lookup Domain Name */
1854 NTSTATUS rpccli_samr_lookup_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1855 POLICY_HND *user_pol, char *domain_name,
1858 prs_struct qbuf, rbuf;
1859 SAMR_Q_LOOKUP_DOMAIN q;
1860 SAMR_R_LOOKUP_DOMAIN r;
1861 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1863 DEBUG(10,("cli_samr_lookup_domain\n"));
1868 /* Marshall data and send request */
1870 init_samr_q_lookup_domain(&q, user_pol, domain_name);
1872 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_DOMAIN,
1875 samr_io_q_lookup_domain,
1876 samr_io_r_lookup_domain,
1877 NT_STATUS_UNSUCCESSFUL);
1879 /* Return output parameters */
1883 if (NT_STATUS_IS_OK(result))
1884 sid_copy(sid, &r.dom_sid.sid);