2 Unix SMB/CIFS implementation.
4 Copyright (C) Tim Potter 2000-2001,
5 Copyright (C) Andrew Tridgell 1992-1997,2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
7 Copyright (C) Paul Ashton 1997,2000,
8 Copyright (C) Elrond 2000,
9 Copyright (C) Rafal Szczesniak 2002.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /* Connect to SAMR database */
30 NTSTATUS cli_samr_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
31 uint32 access_mask, POLICY_HND *connect_pol)
33 prs_struct qbuf, rbuf;
36 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
41 /* Initialise parse structures */
43 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
44 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
46 /* Marshall data and send request */
48 init_samr_q_connect(&q, cli->desthost, access_mask);
50 if (!samr_io_q_connect("", &q, &qbuf, 0) ||
51 !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf))
54 /* Unmarshall response */
56 if (!samr_io_r_connect("", &r, &rbuf, 0))
59 /* Return output parameters */
61 if (NT_STATUS_IS_OK(result = r.status)) {
62 *connect_pol = r.connect_pol;
64 connect_pol->marker = malloc(1);
75 /* Connect to SAMR database */
77 NTSTATUS cli_samr_connect4(struct cli_state *cli, TALLOC_CTX *mem_ctx,
78 uint32 access_mask, POLICY_HND *connect_pol)
80 prs_struct qbuf, rbuf;
83 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
88 /* Initialise parse structures */
90 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
91 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
93 /* Marshall data and send request */
95 init_samr_q_connect4(&q, cli->desthost, access_mask);
97 if (!samr_io_q_connect4("", &q, &qbuf, 0) ||
98 !rpc_api_pipe_req(cli, SAMR_CONNECT4, &qbuf, &rbuf))
101 /* Unmarshall response */
103 if (!samr_io_r_connect4("", &r, &rbuf, 0))
106 /* Return output parameters */
108 if (NT_STATUS_IS_OK(result = r.status)) {
109 *connect_pol = r.connect_pol;
111 connect_pol->marker = malloc(1);
122 /* Close SAMR handle */
124 NTSTATUS cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
125 POLICY_HND *connect_pol)
127 prs_struct qbuf, rbuf;
130 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
135 /* Initialise parse structures */
137 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
138 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
140 /* Marshall data and send request */
142 init_samr_q_close_hnd(&q, connect_pol);
144 if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
145 !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf))
148 /* Unmarshall response */
150 if (!samr_io_r_close_hnd("", &r, &rbuf, 0))
153 /* Return output parameters */
155 if (NT_STATUS_IS_OK(result = r.status)) {
157 SAFE_FREE(connect_pol->marker);
159 *connect_pol = r.pol;
169 /* Open handle on a domain */
171 NTSTATUS cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
172 POLICY_HND *connect_pol, uint32 access_mask,
173 const DOM_SID *domain_sid, POLICY_HND *domain_pol)
175 prs_struct qbuf, rbuf;
176 SAMR_Q_OPEN_DOMAIN q;
177 SAMR_R_OPEN_DOMAIN r;
178 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
183 /* Initialise parse structures */
185 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
186 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
188 /* Marshall data and send request */
190 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
192 if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
193 !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf))
196 /* Unmarshall response */
198 if (!samr_io_r_open_domain("", &r, &rbuf, 0))
201 /* Return output parameters */
203 if (NT_STATUS_IS_OK(result = r.status)) {
204 *domain_pol = r.domain_pol;
206 domain_pol->marker = malloc(1);
217 /* Open handle on a user */
219 NTSTATUS cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
220 POLICY_HND *domain_pol, uint32 access_mask,
221 uint32 user_rid, POLICY_HND *user_pol)
223 prs_struct qbuf, rbuf;
226 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
231 /* Initialise parse structures */
233 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
234 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
236 /* Marshall data and send request */
238 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
240 if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
241 !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf))
244 /* Unmarshall response */
246 if (!samr_io_r_open_user("", &r, &rbuf, 0))
249 /* Return output parameters */
251 if (NT_STATUS_IS_OK(result = r.status)) {
252 *user_pol = r.user_pol;
254 user_pol->marker = malloc(1);
265 /* Open handle on a group */
267 NTSTATUS cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
268 POLICY_HND *domain_pol, uint32 access_mask,
269 uint32 group_rid, POLICY_HND *group_pol)
271 prs_struct qbuf, rbuf;
274 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
279 /* Initialise parse structures */
281 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
282 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
284 /* Marshall data and send request */
286 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
288 if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
289 !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf))
292 /* Unmarshall response */
294 if (!samr_io_r_open_group("", &r, &rbuf, 0))
297 /* Return output parameters */
299 if (NT_STATUS_IS_OK(result = r.status)) {
302 group_pol->marker = malloc(1);
313 /* Query user info */
315 NTSTATUS cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
316 POLICY_HND *user_pol, uint16 switch_value,
317 SAM_USERINFO_CTR **ctr)
319 prs_struct qbuf, rbuf;
320 SAMR_Q_QUERY_USERINFO q;
321 SAMR_R_QUERY_USERINFO r;
322 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
327 /* Initialise parse structures */
329 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
330 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
332 /* Marshall data and send request */
334 init_samr_q_query_userinfo(&q, user_pol, switch_value);
336 if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
337 !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf))
340 /* Unmarshall response */
342 if (!samr_io_r_query_userinfo("", &r, &rbuf, 0))
345 /* Return output parameters */
357 /* Query group info */
359 NTSTATUS cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
360 POLICY_HND *group_pol, uint32 info_level,
361 GROUP_INFO_CTR **ctr)
363 prs_struct qbuf, rbuf;
364 SAMR_Q_QUERY_GROUPINFO q;
365 SAMR_R_QUERY_GROUPINFO r;
366 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
371 /* Initialise parse structures */
373 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
374 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
376 /* Marshall data and send request */
378 init_samr_q_query_groupinfo(&q, group_pol, info_level);
380 if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
381 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf))
384 /* Unmarshall response */
386 if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0))
391 /* Return output parameters */
402 /* Query user groups */
404 NTSTATUS cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
405 POLICY_HND *user_pol, uint32 *num_groups,
408 prs_struct qbuf, rbuf;
409 SAMR_Q_QUERY_USERGROUPS q;
410 SAMR_R_QUERY_USERGROUPS r;
411 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
416 /* Initialise parse structures */
418 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
419 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
421 /* Marshall data and send request */
423 init_samr_q_query_usergroups(&q, user_pol);
425 if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
426 !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf))
429 /* Unmarshall response */
431 if (!samr_io_r_query_usergroups("", &r, &rbuf, 0))
434 /* Return output parameters */
436 if (NT_STATUS_IS_OK(result = r.status)) {
437 *num_groups = r.num_entries;
448 /* Query user aliases */
450 NTSTATUS cli_samr_query_useraliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
451 POLICY_HND *user_pol, uint32 num_sids, DOM_SID2 *sid,
452 uint32 *num_aliases, uint32 **als_rids)
454 prs_struct qbuf, rbuf;
455 SAMR_Q_QUERY_USERALIASES q;
456 SAMR_R_QUERY_USERALIASES r;
457 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
463 /* Initialise parse structures */
465 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
466 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
468 /* Marshall data and send request */
470 init_samr_q_query_useraliases(&q, user_pol, num_sids, &ptr, sid);
472 if (!samr_io_q_query_useraliases("", &q, &qbuf, 0) ||
473 !rpc_api_pipe_req(cli, SAMR_QUERY_USERALIASES, &qbuf, &rbuf))
476 /* Unmarshall response */
478 if (!samr_io_r_query_useraliases("", &r, &rbuf, 0))
481 /* Return output parameters */
483 if (NT_STATUS_IS_OK(result = r.status)) {
484 *num_aliases = r.num_entries;
495 /* Query user groups */
497 NTSTATUS cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
498 POLICY_HND *group_pol, uint32 *num_mem,
499 uint32 **rid, uint32 **attr)
501 prs_struct qbuf, rbuf;
502 SAMR_Q_QUERY_GROUPMEM q;
503 SAMR_R_QUERY_GROUPMEM r;
504 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
509 /* Initialise parse structures */
511 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
512 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
514 /* Marshall data and send request */
516 init_samr_q_query_groupmem(&q, group_pol);
518 if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
519 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf))
522 /* Unmarshall response */
524 if (!samr_io_r_query_groupmem("", &r, &rbuf, 0))
527 /* Return output parameters */
529 if (NT_STATUS_IS_OK(result = r.status)) {
530 *num_mem = r.num_entries;
543 * Enumerate domain users
545 * @param cli client state structure
546 * @param mem_ctx talloc context
547 * @param pol opened domain policy handle
548 * @param start_idx starting index of enumeration, returns context for
550 * @param acb_mask account control bit mask (to enumerate some particular
552 * @param size max acceptable size of response
553 * @param dom_users returned array of domain user names
554 * @param rids returned array of domain user RIDs
555 * @param num_dom_users numer returned entries
557 * @return NTSTATUS returned in rpc response
559 NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx,
560 POLICY_HND *pol, uint32 *start_idx, uint16 acb_mask,
561 uint32 size, char ***dom_users, uint32 **rids,
562 uint32 *num_dom_users)
566 SAMR_Q_ENUM_DOM_USERS q;
567 SAMR_R_ENUM_DOM_USERS r;
568 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
574 if (cli == NULL || pol == NULL)
577 /* initialise parse structures */
578 prs_init(&qdata, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
579 prs_init(&rdata, 0, mem_ctx, UNMARSHALL);
581 DEBUG(4, ("SAMR Enum Domain Users. start_idx: %d, acb: %d, size: %d\n",
582 *start_idx, acb_mask, size));
584 /* fill query structure with parameters */
585 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, 0, size);
587 /* prepare query stream */
588 if (!samr_io_q_enum_dom_users("", &q, &qdata, 0)) {
589 prs_mem_free(&qdata);
590 prs_mem_free(&rdata);
594 /* send rpc call over the pipe */
595 if (!rpc_api_pipe_req(cli, SAMR_ENUM_DOM_USERS, &qdata, &rdata)) {
596 prs_mem_free(&qdata);
597 prs_mem_free(&rdata);
601 /* unpack received stream */
602 if(!samr_io_r_enum_dom_users("", &r, &rdata, 0)) {
603 prs_mem_free(&qdata);
604 prs_mem_free(&rdata);
609 /* return the data obtained in response */
610 if (!NT_STATUS_IS_OK(r.status) &&
611 (NT_STATUS_EQUAL(r.status, STATUS_MORE_ENTRIES) ||
612 NT_STATUS_EQUAL(r.status, NT_STATUS_NO_MORE_ENTRIES))) {
616 *start_idx = r.next_idx;
617 *num_dom_users = r.num_entries2;
620 if (r.num_entries2) {
621 /* allocate memory needed to return received data */
622 *rids = (uint32*)talloc(mem_ctx, sizeof(uint32) * r.num_entries2);
624 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
625 return NT_STATUS_NO_MEMORY;
628 *dom_users = (char**)talloc(mem_ctx, sizeof(char*) * r.num_entries2);
630 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
631 return NT_STATUS_NO_MEMORY;
634 /* fill output buffers with rpc response */
635 for (i = 0; i < r.num_entries2; i++) {
638 (*rids)[i] = r.sam[i].rid;
639 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
640 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
644 prs_mem_free(&qdata);
645 prs_mem_free(&rdata);
651 /* Enumerate domain groups */
653 NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
654 POLICY_HND *pol, uint32 *start_idx,
655 uint32 size, struct acct_info **dom_groups,
656 uint32 *num_dom_groups)
658 prs_struct qbuf, rbuf;
659 SAMR_Q_ENUM_DOM_GROUPS q;
660 SAMR_R_ENUM_DOM_GROUPS r;
661 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
667 /* Initialise parse structures */
669 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
670 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
672 /* Marshall data and send request */
674 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
676 if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
677 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf))
680 /* Unmarshall response */
682 if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0))
685 /* Return output parameters */
689 if (!NT_STATUS_IS_OK(result) &&
690 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
693 *num_dom_groups = r.num_entries2;
695 if (!((*dom_groups) = (struct acct_info *)
696 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
697 result = NT_STATUS_UNSUCCESSFUL;
701 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
705 for (i = 0; i < *num_dom_groups; i++) {
707 (*dom_groups)[i].rid = r.sam[i].rid;
709 if (r.sam[i].hdr_name.buffer) {
710 unistr2_to_ascii((*dom_groups)[i].acct_name,
711 &r.uni_grp_name[name_idx],
712 sizeof(fstring) - 1);
716 *start_idx = r.next_idx;
726 /* Enumerate domain groups */
728 NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
729 POLICY_HND *pol, uint32 *start_idx,
730 uint32 size, struct acct_info **dom_groups,
731 uint32 *num_dom_groups)
733 prs_struct qbuf, rbuf;
734 SAMR_Q_ENUM_DOM_ALIASES q;
735 SAMR_R_ENUM_DOM_ALIASES r;
736 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
742 /* Initialise parse structures */
744 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
745 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
747 /* Marshall data and send request */
749 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
751 if (!samr_io_q_enum_dom_aliases("", &q, &qbuf, 0) ||
752 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_ALIASES, &qbuf, &rbuf)) {
756 /* Unmarshall response */
758 if (!samr_io_r_enum_dom_aliases("", &r, &rbuf, 0)) {
762 /* Return output parameters */
766 if (!NT_STATUS_IS_OK(result) &&
767 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
771 *num_dom_groups = r.num_entries2;
773 if (!((*dom_groups) = (struct acct_info *)
774 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
775 result = NT_STATUS_UNSUCCESSFUL;
779 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
783 for (i = 0; i < *num_dom_groups; i++) {
785 (*dom_groups)[i].rid = r.sam[i].rid;
787 if (r.sam[i].hdr_name.buffer) {
788 unistr2_to_ascii((*dom_groups)[i].acct_name,
789 &r.uni_grp_name[name_idx],
790 sizeof(fstring) - 1);
794 *start_idx = r.next_idx;
804 /* Query alias members */
806 NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
807 POLICY_HND *alias_pol, uint32 *num_mem,
810 prs_struct qbuf, rbuf;
811 SAMR_Q_QUERY_ALIASMEM q;
812 SAMR_R_QUERY_ALIASMEM r;
813 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
819 /* Initialise parse structures */
821 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
822 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
824 /* Marshall data and send request */
826 init_samr_q_query_aliasmem(&q, alias_pol);
828 if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
829 !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
833 /* Unmarshall response */
835 if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
839 /* Return output parameters */
841 if (!NT_STATUS_IS_OK(result = r.status)) {
845 *num_mem = r.num_sids;
847 if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
848 result = NT_STATUS_UNSUCCESSFUL;
852 for (i = 0; i < *num_mem; i++) {
853 (*sids)[i] = r.sid[i].sid;
863 /* Open handle on an alias */
865 NTSTATUS cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
866 POLICY_HND *domain_pol, uint32 access_mask,
867 uint32 alias_rid, POLICY_HND *alias_pol)
869 prs_struct qbuf, rbuf;
877 /* Initialise parse structures */
879 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
880 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
882 /* Marshall data and send request */
884 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
886 if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
887 !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
888 result = NT_STATUS_UNSUCCESSFUL;
892 /* Unmarshall response */
894 if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
895 result = NT_STATUS_UNSUCCESSFUL;
899 /* Return output parameters */
901 if (NT_STATUS_IS_OK(result = r.status)) {
904 alias_pol->marker = malloc(1);
915 /* Query domain info */
917 NTSTATUS cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
918 POLICY_HND *domain_pol, uint16 switch_value,
921 prs_struct qbuf, rbuf;
922 SAMR_Q_QUERY_DOMAIN_INFO q;
923 SAMR_R_QUERY_DOMAIN_INFO r;
924 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
929 /* Initialise parse structures */
931 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
932 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
934 /* Marshall data and send request */
936 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
938 if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
939 !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
943 /* Unmarshall response */
947 if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
951 /* Return output parameters */
953 if (!NT_STATUS_IS_OK(result = r.status)) {
964 /* Query display info */
966 NTSTATUS cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
967 POLICY_HND *domain_pol, uint32 *start_idx,
968 uint16 switch_value, uint32 *num_entries,
969 uint32 max_entries, SAM_DISPINFO_CTR *ctr)
971 prs_struct qbuf, rbuf;
972 SAMR_Q_QUERY_DISPINFO q;
973 SAMR_R_QUERY_DISPINFO r;
974 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
979 /* Initialise parse structures */
981 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
982 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
984 /* Marshall data and send request */
986 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
987 *start_idx, max_entries);
989 if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
990 !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
994 /* Unmarshall response */
998 if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
1002 /* Return output parameters */
1006 if (!NT_STATUS_IS_OK(result) &&
1007 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1011 *num_entries = r.num_entries;
1012 *start_idx += r.num_entries; /* No next_idx in this structure! */
1015 prs_mem_free(&qbuf);
1016 prs_mem_free(&rbuf);
1021 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1022 looked up in one packet. */
1024 NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1025 POLICY_HND *domain_pol, uint32 flags,
1026 uint32 num_rids, uint32 *rids,
1027 uint32 *num_names, char ***names,
1028 uint32 **name_types)
1030 prs_struct qbuf, rbuf;
1031 SAMR_Q_LOOKUP_RIDS q;
1032 SAMR_R_LOOKUP_RIDS r;
1033 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1036 if (num_rids > 1000) {
1037 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1038 "more than ~1000 rids are looked up at once.\n"));
1044 /* Initialise parse structures */
1046 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1047 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1049 /* Marshall data and send request */
1051 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
1054 if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
1055 !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
1059 /* Unmarshall response */
1061 if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
1065 /* Return output parameters */
1067 if (!NT_STATUS_IS_OK(result = r.status)) {
1071 if (r.num_names1 == 0) {
1077 *num_names = r.num_names1;
1078 *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
1079 *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
1081 for (i = 0; i < r.num_names1; i++) {
1084 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
1085 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1086 (*name_types)[i] = r.type[i];
1090 prs_mem_free(&qbuf);
1091 prs_mem_free(&rbuf);
1098 NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1099 POLICY_HND *domain_pol, uint32 flags,
1100 uint32 num_names, const char **names,
1101 uint32 *num_rids, uint32 **rids,
1104 prs_struct qbuf, rbuf;
1105 SAMR_Q_LOOKUP_NAMES q;
1106 SAMR_R_LOOKUP_NAMES r;
1107 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1113 /* Initialise parse structures */
1115 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1116 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1118 /* Marshall data and send request */
1120 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1123 if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
1124 !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
1128 /* Unmarshall response */
1130 if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
1134 /* Return output parameters */
1136 if (!NT_STATUS_IS_OK(result = r.status)) {
1140 if (r.num_rids1 == 0) {
1145 *num_rids = r.num_rids1;
1146 *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1147 *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1149 for (i = 0; i < r.num_rids1; i++) {
1150 (*rids)[i] = r.rids[i];
1151 (*rid_types)[i] = r.types[i];
1155 prs_mem_free(&qbuf);
1156 prs_mem_free(&rbuf);
1161 /* Create a domain user */
1163 NTSTATUS cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1164 POLICY_HND *domain_pol, const char *acct_name,
1165 uint32 acb_info, uint32 unknown,
1166 POLICY_HND *user_pol, uint32 *rid)
1168 prs_struct qbuf, rbuf;
1169 SAMR_Q_CREATE_USER q;
1170 SAMR_R_CREATE_USER r;
1171 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1176 /* Initialise parse structures */
1178 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1179 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1181 /* Marshall data and send request */
1183 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1185 if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
1186 !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
1190 /* Unmarshall response */
1192 if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
1196 /* Return output parameters */
1198 if (!NT_STATUS_IS_OK(result = r.status)) {
1203 *user_pol = r.user_pol;
1209 prs_mem_free(&qbuf);
1210 prs_mem_free(&rbuf);
1217 NTSTATUS cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1218 POLICY_HND *user_pol, uint16 switch_value,
1219 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1221 prs_struct qbuf, rbuf;
1222 SAMR_Q_SET_USERINFO q;
1223 SAMR_R_SET_USERINFO r;
1224 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1229 /* Initialise parse structures */
1231 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1232 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1234 /* Marshall data and send request */
1238 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1241 if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
1242 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
1246 /* Unmarshall response */
1248 if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
1252 /* Return output parameters */
1254 if (!NT_STATUS_IS_OK(result = r.status)) {
1259 prs_mem_free(&qbuf);
1260 prs_mem_free(&rbuf);
1267 NTSTATUS cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1268 POLICY_HND *user_pol, uint16 switch_value,
1269 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1271 prs_struct qbuf, rbuf;
1272 SAMR_Q_SET_USERINFO2 q;
1273 SAMR_R_SET_USERINFO2 r;
1274 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1279 /* Initialise parse structures */
1281 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1282 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1284 /* Marshall data and send request */
1286 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1288 if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
1289 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
1293 /* Unmarshall response */
1295 if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
1299 /* Return output parameters */
1301 if (!NT_STATUS_IS_OK(result = r.status)) {
1306 prs_mem_free(&qbuf);
1307 prs_mem_free(&rbuf);
1312 /* Delete domain user */
1314 NTSTATUS cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1315 POLICY_HND *user_pol)
1317 prs_struct qbuf, rbuf;
1318 SAMR_Q_DELETE_DOM_USER q;
1319 SAMR_R_DELETE_DOM_USER r;
1320 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1325 /* Initialise parse structures */
1327 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1328 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1330 /* Marshall data and send request */
1332 init_samr_q_delete_dom_user(&q, user_pol);
1334 if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
1335 !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
1339 /* Unmarshall response */
1341 if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
1345 /* Return output parameters */
1350 prs_mem_free(&qbuf);
1351 prs_mem_free(&rbuf);
1356 /* Query user security object */
1358 NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1359 POLICY_HND *user_pol, uint16 switch_value,
1360 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1362 prs_struct qbuf, rbuf;
1363 SAMR_Q_QUERY_SEC_OBJ q;
1364 SAMR_R_QUERY_SEC_OBJ r;
1365 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1370 /* Initialise parse structures */
1372 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1373 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1375 /* Marshall data and send request */
1377 init_samr_q_query_sec_obj(&q, user_pol, switch_value);
1379 if (!samr_io_q_query_sec_obj("", &q, &qbuf, 0) ||
1380 !rpc_api_pipe_req(cli, SAMR_QUERY_SEC_OBJECT, &qbuf, &rbuf)) {
1384 /* Unmarshall response */
1386 if (!samr_io_r_query_sec_obj("", &r, &rbuf, 0)) {
1390 /* Return output parameters */
1393 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1396 prs_mem_free(&qbuf);
1397 prs_mem_free(&rbuf);
1402 /* Get domain password info */
1404 NTSTATUS cli_samr_get_dom_pwinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1405 uint16 *unk_0, uint16 *unk_1, uint16 *unk_2)
1407 prs_struct qbuf, rbuf;
1408 SAMR_Q_GET_DOM_PWINFO q;
1409 SAMR_R_GET_DOM_PWINFO r;
1410 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1415 /* Initialise parse structures */
1417 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1418 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1420 /* Marshall data and send request */
1422 init_samr_q_get_dom_pwinfo(&q, cli->desthost);
1424 if (!samr_io_q_get_dom_pwinfo("", &q, &qbuf, 0) ||
1425 !rpc_api_pipe_req(cli, SAMR_GET_DOM_PWINFO, &qbuf, &rbuf))
1428 /* Unmarshall response */
1430 if (!samr_io_r_get_dom_pwinfo("", &r, &rbuf, 0))
1433 /* Return output parameters */
1437 if (NT_STATUS_IS_OK(result)) {
1447 prs_mem_free(&qbuf);
1448 prs_mem_free(&rbuf);