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 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"));
557 sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
558 if (sid_ptrs == NULL)
559 return NT_STATUS_NO_MEMORY;
561 for (i=0; i<num_sids; i++)
564 /* Marshall data and send request */
566 init_samr_q_query_useraliases(&q, dom_pol, num_sids, sid_ptrs, sid);
568 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERALIASES,
571 samr_io_q_query_useraliases,
572 samr_io_r_query_useraliases,
573 NT_STATUS_UNSUCCESSFUL);
575 /* Return output parameters */
577 if (NT_STATUS_IS_OK(result = r.status)) {
578 *num_aliases = r.num_entries;
585 /* Query user groups */
587 NTSTATUS rpccli_samr_query_groupmem(struct rpc_pipe_client *cli,
589 POLICY_HND *group_pol, uint32 *num_mem,
590 uint32 **rid, uint32 **attr)
592 prs_struct qbuf, rbuf;
593 SAMR_Q_QUERY_GROUPMEM q;
594 SAMR_R_QUERY_GROUPMEM r;
595 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
597 DEBUG(10,("cli_samr_query_groupmem\n"));
602 /* Marshall data and send request */
604 init_samr_q_query_groupmem(&q, group_pol);
606 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPMEM,
609 samr_io_q_query_groupmem,
610 samr_io_r_query_groupmem,
611 NT_STATUS_UNSUCCESSFUL);
613 /* Return output parameters */
615 if (NT_STATUS_IS_OK(result = r.status)) {
616 *num_mem = r.num_entries;
625 * Enumerate domain users
627 * @param cli client state structure
628 * @param mem_ctx talloc context
629 * @param pol opened domain policy handle
630 * @param start_idx starting index of enumeration, returns context for
632 * @param acb_mask account control bit mask (to enumerate some particular
634 * @param size max acceptable size of response
635 * @param dom_users returned array of domain user names
636 * @param rids returned array of domain user RIDs
637 * @param num_dom_users numer returned entries
639 * @return NTSTATUS returned in rpc response
642 NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
643 POLICY_HND *pol, uint32 *start_idx, uint16 acb_mask,
644 uint32 size, char ***dom_users, uint32 **rids,
645 uint32 *num_dom_users)
649 SAMR_Q_ENUM_DOM_USERS q;
650 SAMR_R_ENUM_DOM_USERS r;
651 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
654 DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
659 /* always init this */
662 /* Fill query structure with parameters */
664 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, 0, size);
666 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_USERS,
669 samr_io_q_enum_dom_users,
670 samr_io_r_enum_dom_users,
671 NT_STATUS_UNSUCCESSFUL);
675 if (!NT_STATUS_IS_OK(result) &&
676 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
679 *start_idx = r.next_idx;
680 *num_dom_users = r.num_entries2;
682 if (r.num_entries2) {
683 /* allocate memory needed to return received data */
684 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
686 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
687 return NT_STATUS_NO_MEMORY;
690 *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
692 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
693 return NT_STATUS_NO_MEMORY;
696 /* fill output buffers with rpc response */
697 for (i = 0; i < r.num_entries2; i++) {
700 (*rids)[i] = r.sam[i].rid;
701 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
702 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
710 /* Enumerate domain groups */
712 NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli,
714 POLICY_HND *pol, uint32 *start_idx,
715 uint32 size, struct acct_info **dom_groups,
716 uint32 *num_dom_groups)
718 prs_struct qbuf, rbuf;
719 SAMR_Q_ENUM_DOM_GROUPS q;
720 SAMR_R_ENUM_DOM_GROUPS r;
721 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
724 DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
729 /* Marshall data and send request */
731 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
733 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_GROUPS,
736 samr_io_q_enum_dom_groups,
737 samr_io_r_enum_dom_groups,
738 NT_STATUS_UNSUCCESSFUL);
740 /* Return output parameters */
744 if (!NT_STATUS_IS_OK(result) &&
745 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
748 *num_dom_groups = r.num_entries2;
750 if (*num_dom_groups == 0)
753 if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
754 result = NT_STATUS_NO_MEMORY;
758 memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
762 for (i = 0; i < *num_dom_groups; i++) {
764 (*dom_groups)[i].rid = r.sam[i].rid;
766 if (r.sam[i].hdr_name.buffer) {
767 unistr2_to_ascii((*dom_groups)[i].acct_name,
768 &r.uni_grp_name[name_idx],
769 sizeof(fstring) - 1);
773 *start_idx = r.next_idx;
780 /* Enumerate domain groups */
782 NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli,
784 POLICY_HND *pol, uint32 *start_idx,
785 uint32 size, struct acct_info **dom_aliases,
786 uint32 *num_dom_aliases)
788 prs_struct qbuf, rbuf;
789 SAMR_Q_ENUM_DOM_ALIASES q;
790 SAMR_R_ENUM_DOM_ALIASES r;
791 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
794 DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
799 /* Marshall data and send request */
801 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
803 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_ALIASES,
806 samr_io_q_enum_dom_aliases,
807 samr_io_r_enum_dom_aliases,
808 NT_STATUS_UNSUCCESSFUL);
810 /* Return output parameters */
814 if (!NT_STATUS_IS_OK(result) &&
815 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
819 *num_dom_aliases = r.num_entries2;
821 if (*num_dom_aliases == 0)
824 if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
825 result = NT_STATUS_NO_MEMORY;
829 memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
833 for (i = 0; i < *num_dom_aliases; i++) {
835 (*dom_aliases)[i].rid = r.sam[i].rid;
837 if (r.sam[i].hdr_name.buffer) {
838 unistr2_to_ascii((*dom_aliases)[i].acct_name,
839 &r.uni_grp_name[name_idx],
840 sizeof(fstring) - 1);
844 *start_idx = r.next_idx;
851 /* Query alias members */
853 NTSTATUS rpccli_samr_query_aliasmem(struct rpc_pipe_client *cli,
855 POLICY_HND *alias_pol, uint32 *num_mem,
858 prs_struct qbuf, rbuf;
859 SAMR_Q_QUERY_ALIASMEM q;
860 SAMR_R_QUERY_ALIASMEM r;
861 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
864 DEBUG(10,("cli_samr_query_aliasmem\n"));
869 /* Marshall data and send request */
871 init_samr_q_query_aliasmem(&q, alias_pol);
873 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASMEM,
876 samr_io_q_query_aliasmem,
877 samr_io_r_query_aliasmem,
878 NT_STATUS_UNSUCCESSFUL);
880 /* Return output parameters */
882 if (!NT_STATUS_IS_OK(result = r.status)) {
886 *num_mem = r.num_sids;
890 result = NT_STATUS_OK;
894 if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
895 result = NT_STATUS_UNSUCCESSFUL;
899 for (i = 0; i < *num_mem; i++) {
900 (*sids)[i] = r.sid[i].sid;
907 /* Open handle on an alias */
909 NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli,
911 POLICY_HND *domain_pol, uint32 access_mask,
912 uint32 alias_rid, POLICY_HND *alias_pol)
914 prs_struct qbuf, rbuf;
919 DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
924 /* Marshall data and send request */
926 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
928 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_ALIAS,
931 samr_io_q_open_alias,
932 samr_io_r_open_alias,
933 NT_STATUS_UNSUCCESSFUL);
935 /* Return output parameters */
937 if (NT_STATUS_IS_OK(result = r.status)) {
940 alias_pol->marker = malloc(1);
947 /* Create an alias */
949 NTSTATUS rpccli_samr_create_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
950 POLICY_HND *domain_pol, const char *name,
951 POLICY_HND *alias_pol)
953 prs_struct qbuf, rbuf;
954 SAMR_Q_CREATE_DOM_ALIAS q;
955 SAMR_R_CREATE_DOM_ALIAS r;
958 DEBUG(10,("cli_samr_create_dom_alias named %s\n", name));
963 /* Marshall data and send request */
965 init_samr_q_create_dom_alias(&q, domain_pol, name);
967 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_ALIAS,
970 samr_io_q_create_dom_alias,
971 samr_io_r_create_dom_alias,
972 NT_STATUS_UNSUCCESSFUL);
974 /* Return output parameters */
976 if (NT_STATUS_IS_OK(result = r.status)) {
977 *alias_pol = r.alias_pol;
983 /* Add an alias member */
985 NTSTATUS rpccli_samr_add_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
986 POLICY_HND *alias_pol, DOM_SID *member)
988 prs_struct qbuf, rbuf;
989 SAMR_Q_ADD_ALIASMEM q;
990 SAMR_R_ADD_ALIASMEM r;
993 DEBUG(10,("cli_samr_add_aliasmem"));
998 /* Marshall data and send request */
1000 init_samr_q_add_aliasmem(&q, alias_pol, member);
1002 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_ALIASMEM,
1005 samr_io_q_add_aliasmem,
1006 samr_io_r_add_aliasmem,
1007 NT_STATUS_UNSUCCESSFUL);
1014 /* Delete an alias member */
1016 NTSTATUS rpccli_samr_del_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1017 POLICY_HND *alias_pol, DOM_SID *member)
1019 prs_struct qbuf, rbuf;
1020 SAMR_Q_DEL_ALIASMEM q;
1021 SAMR_R_DEL_ALIASMEM r;
1024 DEBUG(10,("cli_samr_del_aliasmem"));
1029 /* Marshall data and send request */
1031 init_samr_q_del_aliasmem(&q, alias_pol, member);
1033 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_ALIASMEM,
1036 samr_io_q_del_aliasmem,
1037 samr_io_r_del_aliasmem,
1038 NT_STATUS_UNSUCCESSFUL);
1045 /* Query alias info */
1047 NTSTATUS rpccli_samr_query_alias_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1048 POLICY_HND *alias_pol, uint16 switch_value,
1049 ALIAS_INFO_CTR *ctr)
1051 prs_struct qbuf, rbuf;
1052 SAMR_Q_QUERY_ALIASINFO q;
1053 SAMR_R_QUERY_ALIASINFO r;
1054 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1056 DEBUG(10,("cli_samr_query_alias_info\n"));
1061 /* Marshall data and send request */
1063 init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
1065 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASINFO,
1068 samr_io_q_query_aliasinfo,
1069 samr_io_r_query_aliasinfo,
1070 NT_STATUS_UNSUCCESSFUL);
1072 /* Return output parameters */
1074 if (!NT_STATUS_IS_OK(result = r.status)) {
1085 /* Query domain info */
1087 NTSTATUS rpccli_samr_query_dom_info(struct rpc_pipe_client *cli,
1088 TALLOC_CTX *mem_ctx,
1089 POLICY_HND *domain_pol,
1090 uint16 switch_value,
1093 prs_struct qbuf, rbuf;
1094 SAMR_Q_QUERY_DOMAIN_INFO q;
1095 SAMR_R_QUERY_DOMAIN_INFO r;
1096 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1098 DEBUG(10,("cli_samr_query_dom_info\n"));
1103 /* Marshall data and send request */
1105 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
1109 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO,
1112 samr_io_q_query_dom_info,
1113 samr_io_r_query_dom_info,
1114 NT_STATUS_UNSUCCESSFUL);
1116 /* Return output parameters */
1118 if (!NT_STATUS_IS_OK(result = r.status)) {
1127 /* User change password */
1129 NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli,
1130 TALLOC_CTX *mem_ctx,
1131 const char *username,
1132 const char *newpassword,
1133 const char *oldpassword )
1135 prs_struct qbuf, rbuf;
1136 SAMR_Q_CHGPASSWD_USER q;
1137 SAMR_R_CHGPASSWD_USER r;
1138 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1140 uchar new_nt_password[516];
1141 uchar new_lm_password[516];
1142 uchar old_nt_hash[16];
1143 uchar old_lanman_hash[16];
1144 uchar old_nt_hash_enc[16];
1145 uchar old_lanman_hash_enc[16];
1147 uchar new_nt_hash[16];
1148 uchar new_lanman_hash[16];
1150 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1152 DEBUG(10,("rpccli_samr_chgpasswd_user\n"));
1157 /* Calculate the MD4 hash (NT compatible) of the password */
1158 E_md4hash(oldpassword, old_nt_hash);
1159 E_md4hash(newpassword, new_nt_hash);
1161 if (lp_client_lanman_auth()
1162 && E_deshash(newpassword, new_lanman_hash)
1163 && E_deshash(oldpassword, old_lanman_hash)) {
1164 /* E_deshash returns false for 'long' passwords (> 14
1165 DOS chars). This allows us to match Win2k, which
1166 does not store a LM hash for these passwords (which
1167 would reduce the effective password length to 14) */
1169 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1171 SamOEMhash( new_lm_password, old_nt_hash, 516);
1172 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1174 ZERO_STRUCT(new_lm_password);
1175 ZERO_STRUCT(old_lanman_hash_enc);
1178 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1180 SamOEMhash( new_nt_password, old_nt_hash, 516);
1181 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1183 /* Marshall data and send request */
1185 init_samr_q_chgpasswd_user(&q, srv_name_slash, username,
1189 old_lanman_hash_enc);
1191 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
1194 samr_io_q_chgpasswd_user,
1195 samr_io_r_chgpasswd_user,
1196 NT_STATUS_UNSUCCESSFUL);
1198 /* Return output parameters */
1200 if (!NT_STATUS_IS_OK(result = r.status)) {
1209 /* change password 3 */
1211 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
1212 TALLOC_CTX *mem_ctx,
1213 const char *username,
1214 const char *newpassword,
1215 const char *oldpassword,
1216 SAM_UNK_INFO_1 **info,
1217 SAMR_CHANGE_REJECT **reject)
1219 prs_struct qbuf, rbuf;
1220 SAMR_Q_CHGPASSWD3 q;
1221 SAMR_R_CHGPASSWD3 r;
1222 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1224 uchar new_nt_password[516];
1225 uchar new_lm_password[516];
1226 uchar old_nt_hash[16];
1227 uchar old_lanman_hash[16];
1228 uchar old_nt_hash_enc[16];
1229 uchar old_lanman_hash_enc[16];
1231 uchar new_nt_hash[16];
1232 uchar new_lanman_hash[16];
1234 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
1236 DEBUG(10,("rpccli_samr_chgpasswd3\n"));
1244 /* Calculate the MD4 hash (NT compatible) of the password */
1245 E_md4hash(oldpassword, old_nt_hash);
1246 E_md4hash(newpassword, new_nt_hash);
1248 if (lp_client_lanman_auth()
1249 && E_deshash(newpassword, new_lanman_hash)
1250 && E_deshash(oldpassword, old_lanman_hash)) {
1251 /* E_deshash returns false for 'long' passwords (> 14
1252 DOS chars). This allows us to match Win2k, which
1253 does not store a LM hash for these passwords (which
1254 would reduce the effective password length to 14) */
1256 encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
1258 SamOEMhash( new_lm_password, old_nt_hash, 516);
1259 E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
1261 ZERO_STRUCT(new_lm_password);
1262 ZERO_STRUCT(old_lanman_hash_enc);
1265 encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
1267 SamOEMhash( new_nt_password, old_nt_hash, 516);
1268 E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
1270 /* Marshall data and send request */
1272 init_samr_q_chgpasswd3(&q, srv_name_slash, username,
1276 old_lanman_hash_enc);
1278 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD3,
1281 samr_io_q_chgpasswd3,
1282 samr_io_r_chgpasswd3,
1283 NT_STATUS_UNSUCCESSFUL);
1285 /* Return output parameters */
1287 if (!NT_STATUS_IS_OK(result = r.status)) {
1289 *reject = &r.reject;
1298 /* This function returns the bizzare set of (max_entries, max_size) required
1299 for the QueryDisplayInfo RPC to actually work against a domain controller
1300 with large (10k and higher) numbers of users. These values were
1301 obtained by inspection using ethereal and NT4 running User Manager. */
1303 void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
1306 switch(loop_count) {
1312 *max_entries = 1024;
1316 *max_entries = 2048;
1320 *max_entries = 4096;
1323 default: /* loop_count >= 4 */
1324 *max_entries = 4096;
1330 /* Query display info */
1332 NTSTATUS rpccli_samr_query_dispinfo(struct rpc_pipe_client *cli,
1333 TALLOC_CTX *mem_ctx,
1334 POLICY_HND *domain_pol, uint32 *start_idx,
1335 uint16 switch_value, uint32 *num_entries,
1336 uint32 max_entries, uint32 max_size,
1337 SAM_DISPINFO_CTR *ctr)
1339 prs_struct qbuf, rbuf;
1340 SAMR_Q_QUERY_DISPINFO q;
1341 SAMR_R_QUERY_DISPINFO r;
1342 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1344 DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
1351 /* Marshall data and send request */
1353 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1354 *start_idx, max_entries, max_size);
1358 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO,
1361 samr_io_q_query_dispinfo,
1362 samr_io_r_query_dispinfo,
1363 NT_STATUS_UNSUCCESSFUL);
1365 /* Return output parameters */
1369 if (!NT_STATUS_IS_OK(result) &&
1370 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1374 *num_entries = r.num_entries;
1375 *start_idx += r.num_entries; /* No next_idx in this structure! */
1381 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1382 looked up in one packet. */
1384 NTSTATUS rpccli_samr_lookup_rids(struct rpc_pipe_client *cli,
1385 TALLOC_CTX *mem_ctx,
1386 POLICY_HND *domain_pol,
1387 uint32 num_rids, uint32 *rids,
1388 uint32 *num_names, char ***names,
1389 uint32 **name_types)
1391 prs_struct qbuf, rbuf;
1392 SAMR_Q_LOOKUP_RIDS q;
1393 SAMR_R_LOOKUP_RIDS r;
1394 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1397 DEBUG(10,("cli_samr_lookup_rids\n"));
1399 if (num_rids > 1000) {
1400 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1401 "more than ~1000 rids are looked up at once.\n"));
1407 /* Marshall data and send request */
1409 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, 1000, num_rids, rids);
1411 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_RIDS,
1414 samr_io_q_lookup_rids,
1415 samr_io_r_lookup_rids,
1416 NT_STATUS_UNSUCCESSFUL);
1418 /* Return output parameters */
1422 if (!NT_STATUS_IS_OK(result) &&
1423 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1426 if (r.num_names1 == 0) {
1432 *num_names = r.num_names1;
1433 *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
1434 *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
1436 for (i = 0; i < r.num_names1; i++) {
1439 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
1440 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1441 (*name_types)[i] = r.type[i];
1451 NTSTATUS rpccli_samr_lookup_names(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1452 POLICY_HND *domain_pol, uint32 flags,
1453 uint32 num_names, const char **names,
1454 uint32 *num_rids, uint32 **rids,
1457 prs_struct qbuf, rbuf;
1458 SAMR_Q_LOOKUP_NAMES q;
1459 SAMR_R_LOOKUP_NAMES r;
1460 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1463 DEBUG(10,("cli_samr_lookup_names\n"));
1468 /* Marshall data and send request */
1470 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1473 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_NAMES,
1476 samr_io_q_lookup_names,
1477 samr_io_r_lookup_names,
1478 NT_STATUS_UNSUCCESSFUL);
1480 /* Return output parameters */
1482 if (!NT_STATUS_IS_OK(result = r.status)) {
1486 if (r.num_rids1 == 0) {
1491 *num_rids = r.num_rids1;
1492 *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1493 *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
1495 for (i = 0; i < r.num_rids1; i++) {
1496 (*rids)[i] = r.rids[i];
1497 (*rid_types)[i] = r.types[i];
1505 /* Create a domain user */
1507 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1508 POLICY_HND *domain_pol, const char *acct_name,
1509 uint32 acb_info, uint32 unknown,
1510 POLICY_HND *user_pol, uint32 *rid)
1512 prs_struct qbuf, rbuf;
1513 SAMR_Q_CREATE_USER q;
1514 SAMR_R_CREATE_USER r;
1515 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1517 DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
1522 /* Marshall data and send request */
1524 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1526 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
1529 samr_io_q_create_user,
1530 samr_io_r_create_user,
1531 NT_STATUS_UNSUCCESSFUL);
1533 /* Return output parameters */
1535 if (!NT_STATUS_IS_OK(result = r.status)) {
1540 *user_pol = r.user_pol;
1552 NTSTATUS rpccli_samr_set_userinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1553 const POLICY_HND *user_pol, uint16 switch_value,
1554 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1556 prs_struct qbuf, rbuf;
1557 SAMR_Q_SET_USERINFO q;
1558 SAMR_R_SET_USERINFO r;
1559 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1561 DEBUG(10,("cli_samr_set_userinfo\n"));
1566 if (!sess_key->length) {
1567 DEBUG(1, ("No user session key\n"));
1568 return NT_STATUS_NO_USER_SESSION_KEY;
1571 /* Initialise parse structures */
1573 prs_init(&qbuf, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1574 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1576 /* Marshall data and send request */
1580 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1583 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO,
1586 samr_io_q_set_userinfo,
1587 samr_io_r_set_userinfo,
1588 NT_STATUS_UNSUCCESSFUL);
1590 /* Return output parameters */
1592 if (!NT_STATUS_IS_OK(result = r.status)) {
1603 NTSTATUS rpccli_samr_set_userinfo2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1604 const POLICY_HND *user_pol, uint16 switch_value,
1605 DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
1607 prs_struct qbuf, rbuf;
1608 SAMR_Q_SET_USERINFO2 q;
1609 SAMR_R_SET_USERINFO2 r;
1610 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1612 DEBUG(10,("cli_samr_set_userinfo2\n"));
1614 if (!sess_key->length) {
1615 DEBUG(1, ("No user session key\n"));
1616 return NT_STATUS_NO_USER_SESSION_KEY;
1622 /* Marshall data and send request */
1624 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1626 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_USERINFO2,
1629 samr_io_q_set_userinfo2,
1630 samr_io_r_set_userinfo2,
1631 NT_STATUS_UNSUCCESSFUL);
1633 /* Return output parameters */
1635 if (!NT_STATUS_IS_OK(result = r.status)) {
1644 /* Delete domain group */
1646 NTSTATUS rpccli_samr_delete_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1647 POLICY_HND *group_pol)
1649 prs_struct qbuf, rbuf;
1650 SAMR_Q_DELETE_DOM_GROUP q;
1651 SAMR_R_DELETE_DOM_GROUP r;
1652 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1654 DEBUG(10,("cli_samr_delete_dom_group\n"));
1659 /* Marshall data and send request */
1661 init_samr_q_delete_dom_group(&q, group_pol);
1663 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_GROUP,
1666 samr_io_q_delete_dom_group,
1667 samr_io_r_delete_dom_group,
1668 NT_STATUS_UNSUCCESSFUL);
1670 /* Return output parameters */
1677 /* Delete domain alias */
1679 NTSTATUS rpccli_samr_delete_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1680 POLICY_HND *alias_pol)
1682 prs_struct qbuf, rbuf;
1683 SAMR_Q_DELETE_DOM_ALIAS q;
1684 SAMR_R_DELETE_DOM_ALIAS r;
1685 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1687 DEBUG(10,("cli_samr_delete_dom_alias\n"));
1692 /* Marshall data and send request */
1694 init_samr_q_delete_dom_alias(&q, alias_pol);
1696 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_ALIAS,
1699 samr_io_q_delete_dom_alias,
1700 samr_io_r_delete_dom_alias,
1701 NT_STATUS_UNSUCCESSFUL);
1703 /* Return output parameters */
1710 /* Delete domain user */
1712 NTSTATUS rpccli_samr_delete_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1713 POLICY_HND *user_pol)
1715 prs_struct qbuf, rbuf;
1716 SAMR_Q_DELETE_DOM_USER q;
1717 SAMR_R_DELETE_DOM_USER r;
1718 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1720 DEBUG(10,("cli_samr_delete_dom_user\n"));
1725 /* Marshall data and send request */
1727 init_samr_q_delete_dom_user(&q, user_pol);
1729 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DELETE_DOM_USER,
1732 samr_io_q_delete_dom_user,
1733 samr_io_r_delete_dom_user,
1734 NT_STATUS_UNSUCCESSFUL);
1736 /* Return output parameters */
1743 /* Remove foreign SID */
1745 NTSTATUS rpccli_samr_remove_sid_foreign_domain(struct rpc_pipe_client *cli,
1746 TALLOC_CTX *mem_ctx,
1747 POLICY_HND *user_pol,
1750 prs_struct qbuf, rbuf;
1751 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN q;
1752 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN r;
1753 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1755 DEBUG(10,("cli_samr_remove_sid_foreign_domain\n"));
1760 /* Marshall data and send request */
1762 init_samr_q_remove_sid_foreign_domain(&q, user_pol, sid);
1764 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_REMOVE_SID_FOREIGN_DOMAIN,
1767 samr_io_q_remove_sid_foreign_domain,
1768 samr_io_r_remove_sid_foreign_domain,
1769 NT_STATUS_UNSUCCESSFUL);
1771 /* Return output parameters */
1778 /* Query user security object */
1780 NTSTATUS rpccli_samr_query_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1781 POLICY_HND *user_pol, uint16 switch_value,
1782 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1784 prs_struct qbuf, rbuf;
1785 SAMR_Q_QUERY_SEC_OBJ q;
1786 SAMR_R_QUERY_SEC_OBJ r;
1787 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1789 DEBUG(10,("cli_samr_query_sec_obj\n"));
1794 /* Marshall data and send request */
1796 init_samr_q_query_sec_obj(&q, user_pol, switch_value);
1798 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_SEC_OBJECT,
1801 samr_io_q_query_sec_obj,
1802 samr_io_r_query_sec_obj,
1803 NT_STATUS_UNSUCCESSFUL);
1805 /* Return output parameters */
1808 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1813 /* Get domain password info */
1815 NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1816 uint16 *min_pwd_length, uint32 *password_properties)
1818 prs_struct qbuf, rbuf;
1819 SAMR_Q_GET_DOM_PWINFO q;
1820 SAMR_R_GET_DOM_PWINFO r;
1821 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1823 DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
1828 /* Marshall data and send request */
1830 init_samr_q_get_dom_pwinfo(&q, cli->cli->desthost);
1832 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DOM_PWINFO,
1835 samr_io_q_get_dom_pwinfo,
1836 samr_io_r_get_dom_pwinfo,
1837 NT_STATUS_UNSUCCESSFUL);
1839 /* Return output parameters */
1843 if (NT_STATUS_IS_OK(result)) {
1845 *min_pwd_length = r.min_pwd_length;
1846 if (password_properties)
1847 *password_properties = r.password_properties;
1853 /* Lookup Domain Name */
1855 NTSTATUS rpccli_samr_lookup_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1856 POLICY_HND *user_pol, char *domain_name,
1859 prs_struct qbuf, rbuf;
1860 SAMR_Q_LOOKUP_DOMAIN q;
1861 SAMR_R_LOOKUP_DOMAIN r;
1862 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1864 DEBUG(10,("cli_samr_lookup_domain\n"));
1869 /* Marshall data and send request */
1871 init_samr_q_lookup_domain(&q, user_pol, domain_name);
1873 CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_LOOKUP_DOMAIN,
1876 samr_io_q_lookup_domain,
1877 samr_io_r_lookup_domain,
1878 NT_STATUS_UNSUCCESSFUL);
1880 /* Return output parameters */
1884 if (NT_STATUS_IS_OK(result))
1885 sid_copy(sid, &r.dom_sid.sid);