2 Unix SMB/Netbios implementation.
5 Copyright (C) Tim Potter 2000-2001,
6 Copyright (C) Andrew Tridgell 1992-1997,2000,
7 Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
8 Copyright (C) Paul Ashton 1997,2000,
9 Copyright (C) Elrond 2000.
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 /* Opens a SMB connection to the SAMR pipe */
30 struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
31 struct ntuser_creds *creds)
33 struct in_addr dest_ip;
34 struct nmb_name calling, called;
36 extern pstring global_myname;
37 struct ntuser_creds anon;
39 /* Initialise cli_state information */
41 if (!cli_initialise(cli)) {
47 anon.pwd.null_pwd = 1;
51 cli_init_creds(cli, creds);
53 /* Establish a SMB connection */
55 if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
59 make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
60 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
62 if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
63 &called, "IPC$", "IPC", False, True)) {
67 /* Open a NT session thingy */
69 if (!cli_nt_session_open(cli, PIPE_SAMR)) {
77 /* Shut down a SMB connection to the SAMR pipe */
79 void cli_samr_shutdown(struct cli_state *cli)
81 if (cli->fd != -1) cli_ulogoff(cli);
85 /* Connect to SAMR database */
87 uint32 cli_samr_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
88 uint32 access_mask, POLICY_HND *connect_pol)
90 prs_struct qbuf, rbuf;
93 uint32 result = NT_STATUS_UNSUCCESSFUL;
98 /* Initialise parse structures */
100 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
101 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
103 /* Marshall data and send request */
105 init_samr_q_connect(&q, cli->desthost, access_mask);
107 if (!samr_io_q_connect("", &q, &qbuf, 0) ||
108 !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf)) {
112 /* Unmarshall response */
114 if (!samr_io_r_connect("", &r, &rbuf, 0)) {
118 /* Return output parameters */
120 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
121 *connect_pol = r.connect_pol;
131 /* Close SAMR handle */
133 uint32 cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
134 POLICY_HND *connect_pol)
136 prs_struct qbuf, rbuf;
139 uint32 result = NT_STATUS_UNSUCCESSFUL;
144 /* Initialise parse structures */
146 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
147 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
149 /* Marshall data and send request */
151 init_samr_q_close_hnd(&q, connect_pol);
153 if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
154 !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf)) {
158 /* Unmarshall response */
160 if (!samr_io_r_close_hnd("", &r, &rbuf, 0)) {
164 /* Return output parameters */
166 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
167 *connect_pol = r.pol;
177 /* Open handle on a domain */
179 uint32 cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
180 POLICY_HND *connect_pol, uint32 access_mask,
181 DOM_SID *domain_sid, POLICY_HND *domain_pol)
183 prs_struct qbuf, rbuf;
184 SAMR_Q_OPEN_DOMAIN q;
185 SAMR_R_OPEN_DOMAIN r;
186 uint32 result = NT_STATUS_UNSUCCESSFUL;
191 /* Initialise parse structures */
193 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
194 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
196 /* Marshall data and send request */
198 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
200 if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
201 !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf)) {
205 /* Unmarshall response */
207 if (!samr_io_r_open_domain("", &r, &rbuf, 0)) {
211 /* Return output parameters */
213 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
214 *domain_pol = r.domain_pol;
224 /* Open handle on a user */
226 uint32 cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
227 POLICY_HND *domain_pol, uint32 access_mask,
228 uint32 user_rid, POLICY_HND *user_pol)
230 prs_struct qbuf, rbuf;
233 uint32 result = NT_STATUS_UNSUCCESSFUL;
238 /* Initialise parse structures */
240 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
241 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
243 /* Marshall data and send request */
245 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
247 if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
248 !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf)) {
252 /* Unmarshall response */
254 if (!samr_io_r_open_user("", &r, &rbuf, 0)) {
258 /* Return output parameters */
260 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
261 *user_pol = r.user_pol;
271 /* Open handle on a group */
273 uint32 cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
274 POLICY_HND *domain_pol, uint32 access_mask,
275 uint32 group_rid, POLICY_HND *group_pol)
277 prs_struct qbuf, rbuf;
280 uint32 result = NT_STATUS_UNSUCCESSFUL;
285 /* Initialise parse structures */
287 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
288 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
290 /* Marshall data and send request */
292 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
294 if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
295 !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf)) {
299 /* Unmarshall response */
301 if (!samr_io_r_open_group("", &r, &rbuf, 0)) {
305 /* Return output parameters */
307 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
318 /* Query user info */
320 uint32 cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
321 POLICY_HND *user_pol, uint16 switch_value,
322 SAM_USERINFO_CTR **ctr)
324 prs_struct qbuf, rbuf;
325 SAMR_Q_QUERY_USERINFO q;
326 SAMR_R_QUERY_USERINFO r;
327 uint32 result = NT_STATUS_UNSUCCESSFUL;
332 /* Initialise parse structures */
334 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
335 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
337 /* Marshall data and send request */
339 init_samr_q_query_userinfo(&q, user_pol, switch_value);
341 if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
342 !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf)) {
346 /* Unmarshall response */
348 if (!samr_io_r_query_userinfo("", &r, &rbuf, 0)) {
352 /* Return output parameters */
364 /* Query group info */
366 uint32 cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
367 POLICY_HND *group_pol, uint32 info_level,
370 prs_struct qbuf, rbuf;
371 SAMR_Q_QUERY_GROUPINFO q;
372 SAMR_R_QUERY_GROUPINFO r;
373 uint32 result = NT_STATUS_UNSUCCESSFUL;
378 /* Initialise parse structures */
380 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
381 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
383 /* Marshall data and send request */
385 init_samr_q_query_groupinfo(&q, group_pol, info_level);
387 if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
388 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf)) {
392 /* Unmarshall response */
396 if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0)) {
400 /* Return output parameters */
411 /* Query user groups */
413 uint32 cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
414 POLICY_HND *user_pol, uint32 *num_groups,
417 prs_struct qbuf, rbuf;
418 SAMR_Q_QUERY_USERGROUPS q;
419 SAMR_R_QUERY_USERGROUPS r;
420 uint32 result = NT_STATUS_UNSUCCESSFUL;
425 /* Initialise parse structures */
427 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
428 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
430 /* Marshall data and send request */
432 init_samr_q_query_usergroups(&q, user_pol);
434 if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
435 !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf)) {
439 /* Unmarshall response */
441 if (!samr_io_r_query_usergroups("", &r, &rbuf, 0)) {
445 /* Return output parameters */
447 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
448 *num_groups = r.num_entries;
459 /* Query user groups */
461 uint32 cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
462 POLICY_HND *group_pol, uint32 *num_mem,
463 uint32 **rid, uint32 **attr)
465 prs_struct qbuf, rbuf;
466 SAMR_Q_QUERY_GROUPMEM q;
467 SAMR_R_QUERY_GROUPMEM r;
468 uint32 result = NT_STATUS_UNSUCCESSFUL;
473 /* Initialise parse structures */
475 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
476 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
478 /* Marshall data and send request */
480 init_samr_q_query_groupmem(&q, group_pol);
482 if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
483 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf)) {
487 /* Unmarshall response */
489 if (!samr_io_r_query_groupmem("", &r, &rbuf, 0)) {
493 /* Return output parameters */
495 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
496 *num_mem = r.num_entries;
508 /* Enumerate domain groups */
510 uint32 cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
511 POLICY_HND *pol, uint32 *start_idx,
512 uint32 size, struct acct_info **dom_groups,
513 uint32 *num_dom_groups)
515 prs_struct qbuf, rbuf;
516 SAMR_Q_ENUM_DOM_GROUPS q;
517 SAMR_R_ENUM_DOM_GROUPS r;
518 uint32 result = NT_STATUS_UNSUCCESSFUL, name_idx, i;
523 /* Initialise parse structures */
525 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
526 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
528 /* Marshall data and send request */
530 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
532 if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
533 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf)) {
537 /* Unmarshall response */
539 if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0)) {
543 /* Return output parameters */
547 if (result != NT_STATUS_NOPROBLEMO &&
548 result != STATUS_MORE_ENTRIES) {
552 *num_dom_groups = r.num_entries2;
554 if (!((*dom_groups) = (struct acct_info *)
555 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
556 result = NT_STATUS_UNSUCCESSFUL;
560 memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
564 for (i = 0; i < *num_dom_groups; i++) {
566 (*dom_groups)[i].rid = r.sam[i].rid;
568 if (r.sam[i].hdr_name.buffer) {
569 unistr2_to_ascii((*dom_groups)[i].acct_name,
570 &r.uni_grp_name[name_idx],
571 sizeof(fstring) - 1);
575 *start_idx = r.next_idx;
585 /* Query alias members */
587 uint32 cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
588 POLICY_HND *alias_pol, uint32 *num_mem,
591 prs_struct qbuf, rbuf;
592 SAMR_Q_QUERY_ALIASMEM q;
593 SAMR_R_QUERY_ALIASMEM r;
594 uint32 result = NT_STATUS_UNSUCCESSFUL, i;
599 /* Initialise parse structures */
601 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
602 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
604 /* Marshall data and send request */
606 init_samr_q_query_aliasmem(&q, alias_pol);
608 if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
609 !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
613 /* Unmarshall response */
615 if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
619 /* Return output parameters */
621 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
625 *num_mem = r.num_sids;
627 if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
628 result = NT_STATUS_UNSUCCESSFUL;
632 for (i = 0; i < *num_mem; i++) {
633 (*sids)[i] = r.sid[i].sid;
643 /* Open handle on an alias */
645 uint32 cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
646 POLICY_HND *domain_pol, uint32 access_mask,
647 uint32 alias_rid, POLICY_HND *alias_pol)
649 prs_struct qbuf, rbuf;
657 /* Initialise parse structures */
659 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
660 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
662 /* Marshall data and send request */
664 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
666 if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
667 !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
668 result = NT_STATUS_UNSUCCESSFUL;
672 /* Unmarshall response */
674 if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
675 result = NT_STATUS_UNSUCCESSFUL;
679 /* Return output parameters */
681 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
692 /* Query domain info */
694 uint32 cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
695 POLICY_HND *domain_pol, uint16 switch_value,
698 prs_struct qbuf, rbuf;
699 SAMR_Q_QUERY_DOMAIN_INFO q;
700 SAMR_R_QUERY_DOMAIN_INFO r;
701 uint32 result = NT_STATUS_UNSUCCESSFUL;
706 /* Initialise parse structures */
708 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
709 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
711 /* Marshall data and send request */
713 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
715 if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
716 !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
720 /* Unmarshall response */
724 if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
728 /* Return output parameters */
730 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
741 /* Query display info */
743 uint32 cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
744 POLICY_HND *domain_pol, uint32 *start_idx,
745 uint16 switch_value, uint32 *num_entries,
746 uint32 max_entries, SAM_DISPINFO_CTR *ctr)
748 prs_struct qbuf, rbuf;
749 SAMR_Q_QUERY_DISPINFO q;
750 SAMR_R_QUERY_DISPINFO r;
751 uint32 result = NT_STATUS_UNSUCCESSFUL;
756 /* Initialise parse structures */
758 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
759 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
761 /* Marshall data and send request */
763 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
764 *start_idx, max_entries);
766 if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
767 !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
771 /* Unmarshall response */
775 if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
779 /* Return output parameters */
781 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
785 *num_entries = r.num_entries;
786 *start_idx += r.num_entries; /* No next_idx in this structure! */
795 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
796 looked up in one packet. */
798 uint32 cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
799 POLICY_HND *domain_pol, uint32 flags,
800 uint32 num_rids, uint32 *rids,
801 uint32 *num_names, char ***names,
804 prs_struct qbuf, rbuf;
805 SAMR_Q_LOOKUP_RIDS q;
806 SAMR_R_LOOKUP_RIDS r;
807 uint32 result = NT_STATUS_UNSUCCESSFUL, i;
809 if (num_rids > 1000) {
810 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
811 "more than ~1000 rids are looked up at once.\n"));
817 /* Initialise parse structures */
819 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
820 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
822 /* Marshall data and send request */
824 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
827 if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
828 !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
832 /* Unmarshall response */
834 if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
838 /* Return output parameters */
840 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
844 if (r.num_names1 == 0) {
850 *num_names = r.num_names1;
851 *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
852 *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
854 for (i = 0; i < r.num_names1; i++) {
857 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
858 (*names)[i] = talloc_strdup(mem_ctx, tmp);
859 (*name_types)[i] = r.type[i];
871 uint32 cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
872 POLICY_HND *domain_pol, uint32 flags,
873 uint32 num_names, char **names,
874 uint32 *num_rids, uint32 **rids,
877 prs_struct qbuf, rbuf;
878 SAMR_Q_LOOKUP_NAMES q;
879 SAMR_R_LOOKUP_NAMES r;
880 uint32 result = NT_STATUS_UNSUCCESSFUL, i;
885 /* Initialise parse structures */
887 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
888 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
890 /* Marshall data and send request */
892 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
895 if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
896 !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
900 /* Unmarshall response */
902 if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
906 /* Return output parameters */
908 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
912 if (r.num_rids1 == 0) {
917 *num_rids = r.num_rids1;
918 *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
919 *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
921 for (i = 0; i < r.num_rids1; i++) {
922 (*rids)[i] = r.rids[i];
923 (*rid_types)[i] = r.types[i];
933 /* Create a domain user */
935 uint32 cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
936 POLICY_HND *domain_pol, char *acct_name,
937 uint32 acb_info, uint32 unknown,
938 POLICY_HND *user_pol, uint32 *rid)
940 prs_struct qbuf, rbuf;
941 SAMR_Q_CREATE_USER q;
942 SAMR_R_CREATE_USER r;
943 uint32 result = NT_STATUS_UNSUCCESSFUL;
948 /* Initialise parse structures */
950 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
951 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
953 /* Marshall data and send request */
955 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
957 if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
958 !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
962 /* Unmarshall response */
964 if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
968 /* Return output parameters */
970 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
975 *user_pol = r.user_pol;
989 uint32 cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
990 POLICY_HND *user_pol, uint16 switch_value,
991 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
993 prs_struct qbuf, rbuf;
994 SAMR_Q_SET_USERINFO q;
995 SAMR_R_SET_USERINFO r;
996 uint32 result = NT_STATUS_UNSUCCESSFUL;
1001 /* Initialise parse structures */
1003 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1004 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1006 /* Marshall data and send request */
1010 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1013 if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
1014 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
1018 /* Unmarshall response */
1020 if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
1024 /* Return output parameters */
1026 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
1031 prs_mem_free(&qbuf);
1032 prs_mem_free(&rbuf);
1039 uint32 cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1040 POLICY_HND *user_pol, uint16 switch_value,
1041 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1043 prs_struct qbuf, rbuf;
1044 SAMR_Q_SET_USERINFO2 q;
1045 SAMR_R_SET_USERINFO2 r;
1046 uint32 result = NT_STATUS_UNSUCCESSFUL;
1051 /* Initialise parse structures */
1053 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1054 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1056 /* Marshall data and send request */
1058 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1060 if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
1061 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
1065 /* Unmarshall response */
1067 if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
1071 /* Return output parameters */
1073 if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
1078 prs_mem_free(&qbuf);
1079 prs_mem_free(&rbuf);
1084 /* Delete domain user */
1086 uint32 cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1087 POLICY_HND *user_pol)
1089 prs_struct qbuf, rbuf;
1090 SAMR_Q_DELETE_DOM_USER q;
1091 SAMR_R_DELETE_DOM_USER r;
1092 uint32 result = NT_STATUS_UNSUCCESSFUL;
1097 /* Initialise parse structures */
1099 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1100 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1102 /* Marshall data and send request */
1104 init_samr_q_delete_dom_user(&q, user_pol);
1106 if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
1107 !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
1111 /* Unmarshall response */
1113 if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
1117 /* Return output parameters */
1122 prs_mem_free(&qbuf);
1123 prs_mem_free(&rbuf);