A fix to allow configure to find iconv on a number of systems including those
[Samba/gebeck_regimport.git] / source3 / rpc_client / cli_samr.c
blobe5e67f39dc9a7b0164c7446e7506f8b919df96a1
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
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.
26 #include "includes.h"
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;
34 SAMR_Q_CONNECT q;
35 SAMR_R_CONNECT r;
36 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
38 DEBUG(10,("cli_samr_connect to %s\n", cli->desthost));
40 ZERO_STRUCT(q);
41 ZERO_STRUCT(r);
43 /* Initialise parse structures */
45 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
46 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
48 /* Marshall data and send request */
50 init_samr_q_connect(&q, cli->desthost, access_mask);
52 if (!samr_io_q_connect("", &q, &qbuf, 0) ||
53 !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf))
54 goto done;
56 /* Unmarshall response */
58 if (!samr_io_r_connect("", &r, &rbuf, 0))
59 goto done;
61 /* Return output parameters */
63 if (NT_STATUS_IS_OK(result = r.status)) {
64 *connect_pol = r.connect_pol;
65 #ifdef __INSURE__
66 connect_pol->marker = malloc(1);
67 #endif
70 done:
71 prs_mem_free(&qbuf);
72 prs_mem_free(&rbuf);
74 return result;
77 /* Connect to SAMR database */
79 NTSTATUS cli_samr_connect4(struct cli_state *cli, TALLOC_CTX *mem_ctx,
80 uint32 access_mask, POLICY_HND *connect_pol)
82 prs_struct qbuf, rbuf;
83 SAMR_Q_CONNECT4 q;
84 SAMR_R_CONNECT4 r;
85 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
87 DEBUG(10,("cli_samr_connect4 to %s\n", cli->desthost));
89 ZERO_STRUCT(q);
90 ZERO_STRUCT(r);
92 /* Initialise parse structures */
94 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
95 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
97 /* Marshall data and send request */
99 init_samr_q_connect4(&q, cli->desthost, access_mask);
101 if (!samr_io_q_connect4("", &q, &qbuf, 0) ||
102 !rpc_api_pipe_req(cli, SAMR_CONNECT4, &qbuf, &rbuf))
103 goto done;
105 /* Unmarshall response */
107 if (!samr_io_r_connect4("", &r, &rbuf, 0))
108 goto done;
110 /* Return output parameters */
112 if (NT_STATUS_IS_OK(result = r.status)) {
113 *connect_pol = r.connect_pol;
114 #ifdef __INSURE__
115 connect_pol->marker = malloc(1);
116 #endif
119 done:
120 prs_mem_free(&qbuf);
121 prs_mem_free(&rbuf);
123 return result;
126 /* Close SAMR handle */
128 NTSTATUS cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
129 POLICY_HND *connect_pol)
131 prs_struct qbuf, rbuf;
132 SAMR_Q_CLOSE_HND q;
133 SAMR_R_CLOSE_HND r;
134 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
136 DEBUG(10,("cli_samr_close\n"));
138 ZERO_STRUCT(q);
139 ZERO_STRUCT(r);
141 /* Initialise parse structures */
143 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
144 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
146 /* Marshall data and send request */
148 init_samr_q_close_hnd(&q, connect_pol);
150 if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
151 !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf))
152 goto done;
154 /* Unmarshall response */
156 if (!samr_io_r_close_hnd("", &r, &rbuf, 0))
157 goto done;
159 /* Return output parameters */
161 if (NT_STATUS_IS_OK(result = r.status)) {
162 #ifdef __INSURE__
163 SAFE_FREE(connect_pol->marker);
164 #endif
165 *connect_pol = r.pol;
168 done:
169 prs_mem_free(&qbuf);
170 prs_mem_free(&rbuf);
172 return result;
175 /* Open handle on a domain */
177 NTSTATUS cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
178 POLICY_HND *connect_pol, uint32 access_mask,
179 const DOM_SID *domain_sid, POLICY_HND *domain_pol)
181 prs_struct qbuf, rbuf;
182 SAMR_Q_OPEN_DOMAIN q;
183 SAMR_R_OPEN_DOMAIN r;
184 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
186 DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(domain_sid) ));
188 ZERO_STRUCT(q);
189 ZERO_STRUCT(r);
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))
202 goto done;
204 /* Unmarshall response */
206 if (!samr_io_r_open_domain("", &r, &rbuf, 0))
207 goto done;
209 /* Return output parameters */
211 if (NT_STATUS_IS_OK(result = r.status)) {
212 *domain_pol = r.domain_pol;
213 #ifdef __INSURE__
214 domain_pol->marker = malloc(1);
215 #endif
218 done:
219 prs_mem_free(&qbuf);
220 prs_mem_free(&rbuf);
222 return result;
225 /* Open handle on a user */
227 NTSTATUS cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
228 POLICY_HND *domain_pol, uint32 access_mask,
229 uint32 user_rid, POLICY_HND *user_pol)
231 prs_struct qbuf, rbuf;
232 SAMR_Q_OPEN_USER q;
233 SAMR_R_OPEN_USER r;
234 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
236 DEBUG(10,("cli_samr_open_user with rid 0x%x\n", user_rid ));
238 ZERO_STRUCT(q);
239 ZERO_STRUCT(r);
241 /* Initialise parse structures */
243 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
244 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
246 /* Marshall data and send request */
248 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
250 if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
251 !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf))
252 goto done;
254 /* Unmarshall response */
256 if (!samr_io_r_open_user("", &r, &rbuf, 0))
257 goto done;
259 /* Return output parameters */
261 if (NT_STATUS_IS_OK(result = r.status)) {
262 *user_pol = r.user_pol;
263 #ifdef __INSURE__
264 user_pol->marker = malloc(1);
265 #endif
268 done:
269 prs_mem_free(&qbuf);
270 prs_mem_free(&rbuf);
272 return result;
275 /* Open handle on a group */
277 NTSTATUS cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
278 POLICY_HND *domain_pol, uint32 access_mask,
279 uint32 group_rid, POLICY_HND *group_pol)
281 prs_struct qbuf, rbuf;
282 SAMR_Q_OPEN_GROUP q;
283 SAMR_R_OPEN_GROUP r;
284 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
286 DEBUG(10,("cli_samr_open_group with rid 0x%x\n", group_rid ));
288 ZERO_STRUCT(q);
289 ZERO_STRUCT(r);
291 /* Initialise parse structures */
293 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
294 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
296 /* Marshall data and send request */
298 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
300 if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
301 !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf))
302 goto done;
304 /* Unmarshall response */
306 if (!samr_io_r_open_group("", &r, &rbuf, 0))
307 goto done;
309 /* Return output parameters */
311 if (NT_STATUS_IS_OK(result = r.status)) {
312 *group_pol = r.pol;
313 #ifdef __INSURE__
314 group_pol->marker = malloc(1);
315 #endif
318 done:
319 prs_mem_free(&qbuf);
320 prs_mem_free(&rbuf);
322 return result;
325 /* Query user info */
327 NTSTATUS cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
328 POLICY_HND *user_pol, uint16 switch_value,
329 SAM_USERINFO_CTR **ctr)
331 prs_struct qbuf, rbuf;
332 SAMR_Q_QUERY_USERINFO q;
333 SAMR_R_QUERY_USERINFO r;
334 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
336 DEBUG(10,("cli_samr_query_userinfo\n"));
338 ZERO_STRUCT(q);
339 ZERO_STRUCT(r);
341 /* Initialise parse structures */
343 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
344 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
346 /* Marshall data and send request */
348 init_samr_q_query_userinfo(&q, user_pol, switch_value);
350 if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
351 !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf))
352 goto done;
354 /* Unmarshall response */
356 if (!samr_io_r_query_userinfo("", &r, &rbuf, 0))
357 goto done;
359 /* Return output parameters */
361 result = r.status;
362 *ctr = r.ctr;
364 done:
365 prs_mem_free(&qbuf);
366 prs_mem_free(&rbuf);
368 return result;
371 /* Query group info */
373 NTSTATUS cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
374 POLICY_HND *group_pol, uint32 info_level,
375 GROUP_INFO_CTR **ctr)
377 prs_struct qbuf, rbuf;
378 SAMR_Q_QUERY_GROUPINFO q;
379 SAMR_R_QUERY_GROUPINFO r;
380 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
382 DEBUG(10,("cli_samr_query_groupinfo\n"));
384 ZERO_STRUCT(q);
385 ZERO_STRUCT(r);
387 /* Initialise parse structures */
389 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
390 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
392 /* Marshall data and send request */
394 init_samr_q_query_groupinfo(&q, group_pol, info_level);
396 if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
397 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf))
398 goto done;
400 /* Unmarshall response */
402 if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0))
403 goto done;
405 *ctr = r.ctr;
407 /* Return output parameters */
409 result = r.status;
411 done:
412 prs_mem_free(&qbuf);
413 prs_mem_free(&rbuf);
415 return result;
418 /* Query user groups */
420 NTSTATUS cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
421 POLICY_HND *user_pol, uint32 *num_groups,
422 DOM_GID **gid)
424 prs_struct qbuf, rbuf;
425 SAMR_Q_QUERY_USERGROUPS q;
426 SAMR_R_QUERY_USERGROUPS r;
427 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
429 DEBUG(10,("cli_samr_query_usergroups\n"));
431 ZERO_STRUCT(q);
432 ZERO_STRUCT(r);
434 /* Initialise parse structures */
436 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
437 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
439 /* Marshall data and send request */
441 init_samr_q_query_usergroups(&q, user_pol);
443 if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
444 !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf))
445 goto done;
447 /* Unmarshall response */
449 if (!samr_io_r_query_usergroups("", &r, &rbuf, 0))
450 goto done;
452 /* Return output parameters */
454 if (NT_STATUS_IS_OK(result = r.status)) {
455 *num_groups = r.num_entries;
456 *gid = r.gid;
459 done:
460 prs_mem_free(&qbuf);
461 prs_mem_free(&rbuf);
463 return result;
466 /* Query user aliases */
468 NTSTATUS cli_samr_query_useraliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
469 POLICY_HND *user_pol, uint32 num_sids, DOM_SID2 *sid,
470 uint32 *num_aliases, uint32 **als_rids)
472 prs_struct qbuf, rbuf;
473 SAMR_Q_QUERY_USERALIASES q;
474 SAMR_R_QUERY_USERALIASES r;
475 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
476 unsigned int ptr=1;
478 DEBUG(10,("cli_samr_query_useraliases\n"));
480 ZERO_STRUCT(q);
481 ZERO_STRUCT(r);
483 /* Initialise parse structures */
485 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
486 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
488 /* Marshall data and send request */
490 init_samr_q_query_useraliases(&q, user_pol, num_sids, &ptr, sid);
492 if (!samr_io_q_query_useraliases("", &q, &qbuf, 0) ||
493 !rpc_api_pipe_req(cli, SAMR_QUERY_USERALIASES, &qbuf, &rbuf))
494 goto done;
496 /* Unmarshall response */
498 if (!samr_io_r_query_useraliases("", &r, &rbuf, 0))
499 goto done;
501 /* Return output parameters */
503 if (NT_STATUS_IS_OK(result = r.status)) {
504 *num_aliases = r.num_entries;
505 *als_rids = r.rid;
508 done:
509 prs_mem_free(&qbuf);
510 prs_mem_free(&rbuf);
512 return result;
515 /* Query user groups */
517 NTSTATUS cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
518 POLICY_HND *group_pol, uint32 *num_mem,
519 uint32 **rid, uint32 **attr)
521 prs_struct qbuf, rbuf;
522 SAMR_Q_QUERY_GROUPMEM q;
523 SAMR_R_QUERY_GROUPMEM r;
524 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
526 DEBUG(10,("cli_samr_query_groupmem\n"));
528 ZERO_STRUCT(q);
529 ZERO_STRUCT(r);
531 /* Initialise parse structures */
533 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
534 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
536 /* Marshall data and send request */
538 init_samr_q_query_groupmem(&q, group_pol);
540 if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
541 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf))
542 goto done;
544 /* Unmarshall response */
546 if (!samr_io_r_query_groupmem("", &r, &rbuf, 0))
547 goto done;
549 /* Return output parameters */
551 if (NT_STATUS_IS_OK(result = r.status)) {
552 *num_mem = r.num_entries;
553 *rid = r.rid;
554 *attr = r.attr;
557 done:
558 prs_mem_free(&qbuf);
559 prs_mem_free(&rbuf);
561 return result;
565 * Enumerate domain users
567 * @param cli client state structure
568 * @param mem_ctx talloc context
569 * @param pol opened domain policy handle
570 * @param start_idx starting index of enumeration, returns context for
571 next enumeration
572 * @param acb_mask account control bit mask (to enumerate some particular
573 * kind of accounts)
574 * @param size max acceptable size of response
575 * @param dom_users returned array of domain user names
576 * @param rids returned array of domain user RIDs
577 * @param num_dom_users numer returned entries
579 * @return NTSTATUS returned in rpc response
581 NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx,
582 POLICY_HND *pol, uint32 *start_idx, uint16 acb_mask,
583 uint32 size, char ***dom_users, uint32 **rids,
584 uint32 *num_dom_users)
586 prs_struct qbuf;
587 prs_struct rbuf;
588 SAMR_Q_ENUM_DOM_USERS q;
589 SAMR_R_ENUM_DOM_USERS r;
590 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
591 int i;
593 DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
595 ZERO_STRUCT(q);
596 ZERO_STRUCT(r);
598 /* always init this */
599 *num_dom_users = 0;
601 /* Initialise parse structures */
603 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
604 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
606 /* Fill query structure with parameters */
608 init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, 0, size);
610 if (!samr_io_q_enum_dom_users("", &q, &qbuf, 0) ||
611 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_USERS, &qbuf, &rbuf)) {
612 goto done;
615 /* unpack received stream */
617 if(!samr_io_r_enum_dom_users("", &r, &rbuf, 0))
618 goto done;
620 result = r.status;
622 if (!NT_STATUS_IS_OK(result) &&
623 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
624 goto done;
626 *start_idx = r.next_idx;
627 *num_dom_users = r.num_entries2;
629 if (r.num_entries2) {
630 /* allocate memory needed to return received data */
631 *rids = (uint32*)talloc(mem_ctx, sizeof(uint32) * r.num_entries2);
632 if (!*rids) {
633 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
634 return NT_STATUS_NO_MEMORY;
637 *dom_users = (char**)talloc(mem_ctx, sizeof(char*) * r.num_entries2);
638 if (!*dom_users) {
639 DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
640 return NT_STATUS_NO_MEMORY;
643 /* fill output buffers with rpc response */
644 for (i = 0; i < r.num_entries2; i++) {
645 fstring conv_buf;
647 (*rids)[i] = r.sam[i].rid;
648 unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
649 (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
653 done:
654 prs_mem_free(&qbuf);
655 prs_mem_free(&rbuf);
657 return result;
660 /* Enumerate domain groups */
662 NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
663 POLICY_HND *pol, uint32 *start_idx,
664 uint32 size, struct acct_info **dom_groups,
665 uint32 *num_dom_groups)
667 prs_struct qbuf, rbuf;
668 SAMR_Q_ENUM_DOM_GROUPS q;
669 SAMR_R_ENUM_DOM_GROUPS r;
670 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
671 uint32 name_idx, i;
673 DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
675 ZERO_STRUCT(q);
676 ZERO_STRUCT(r);
678 /* Initialise parse structures */
680 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
681 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
683 /* Marshall data and send request */
685 init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
687 if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
688 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf))
689 goto done;
691 /* Unmarshall response */
693 if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0))
694 goto done;
696 /* Return output parameters */
698 result = r.status;
700 if (!NT_STATUS_IS_OK(result) &&
701 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
702 goto done;
704 *num_dom_groups = r.num_entries2;
706 if (*num_dom_groups == 0)
707 goto done;
709 if (!((*dom_groups) = (struct acct_info *)
710 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
711 result = NT_STATUS_NO_MEMORY;
712 goto done;
715 memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
717 name_idx = 0;
719 for (i = 0; i < *num_dom_groups; i++) {
721 (*dom_groups)[i].rid = r.sam[i].rid;
723 if (r.sam[i].hdr_name.buffer) {
724 unistr2_to_ascii((*dom_groups)[i].acct_name,
725 &r.uni_grp_name[name_idx],
726 sizeof(fstring) - 1);
727 name_idx++;
730 *start_idx = r.next_idx;
733 done:
734 prs_mem_free(&qbuf);
735 prs_mem_free(&rbuf);
737 return result;
740 /* Enumerate domain groups */
742 NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
743 POLICY_HND *pol, uint32 *start_idx,
744 uint32 size, struct acct_info **dom_aliases,
745 uint32 *num_dom_aliases)
747 prs_struct qbuf, rbuf;
748 SAMR_Q_ENUM_DOM_ALIASES q;
749 SAMR_R_ENUM_DOM_ALIASES r;
750 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
751 uint32 name_idx, i;
753 DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
755 ZERO_STRUCT(q);
756 ZERO_STRUCT(r);
758 /* Initialise parse structures */
760 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
761 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
763 /* Marshall data and send request */
765 init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
767 if (!samr_io_q_enum_dom_aliases("", &q, &qbuf, 0) ||
768 !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_ALIASES, &qbuf, &rbuf)) {
769 goto done;
772 /* Unmarshall response */
774 if (!samr_io_r_enum_dom_aliases("", &r, &rbuf, 0)) {
775 goto done;
778 /* Return output parameters */
780 result = r.status;
782 if (!NT_STATUS_IS_OK(result) &&
783 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
784 goto done;
787 *num_dom_aliases = r.num_entries2;
789 if (*num_dom_aliases == 0)
790 goto done;
792 if (!((*dom_aliases) = (struct acct_info *)
793 talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_aliases))) {
794 result = NT_STATUS_NO_MEMORY;
795 goto done;
798 memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
800 name_idx = 0;
802 for (i = 0; i < *num_dom_aliases; i++) {
804 (*dom_aliases)[i].rid = r.sam[i].rid;
806 if (r.sam[i].hdr_name.buffer) {
807 unistr2_to_ascii((*dom_aliases)[i].acct_name,
808 &r.uni_grp_name[name_idx],
809 sizeof(fstring) - 1);
810 name_idx++;
813 *start_idx = r.next_idx;
816 done:
817 prs_mem_free(&qbuf);
818 prs_mem_free(&rbuf);
820 return result;
823 /* Query alias members */
825 NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
826 POLICY_HND *alias_pol, uint32 *num_mem,
827 DOM_SID **sids)
829 prs_struct qbuf, rbuf;
830 SAMR_Q_QUERY_ALIASMEM q;
831 SAMR_R_QUERY_ALIASMEM r;
832 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
833 uint32 i;
835 DEBUG(10,("cli_samr_query_aliasmem\n"));
837 ZERO_STRUCT(q);
838 ZERO_STRUCT(r);
840 /* Initialise parse structures */
842 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
843 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
845 /* Marshall data and send request */
847 init_samr_q_query_aliasmem(&q, alias_pol);
849 if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
850 !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
851 goto done;
854 /* Unmarshall response */
856 if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
857 goto done;
860 /* Return output parameters */
862 if (!NT_STATUS_IS_OK(result = r.status)) {
863 goto done;
866 *num_mem = r.num_sids;
868 if (*num_mem == 0) {
869 *sids = NULL;
870 result = NT_STATUS_OK;
871 goto done;
874 if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
875 result = NT_STATUS_UNSUCCESSFUL;
876 goto done;
879 for (i = 0; i < *num_mem; i++) {
880 (*sids)[i] = r.sid[i].sid;
883 done:
884 prs_mem_free(&qbuf);
885 prs_mem_free(&rbuf);
887 return result;
890 /* Open handle on an alias */
892 NTSTATUS cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
893 POLICY_HND *domain_pol, uint32 access_mask,
894 uint32 alias_rid, POLICY_HND *alias_pol)
896 prs_struct qbuf, rbuf;
897 SAMR_Q_OPEN_ALIAS q;
898 SAMR_R_OPEN_ALIAS r;
899 NTSTATUS result;
901 DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
903 ZERO_STRUCT(q);
904 ZERO_STRUCT(r);
906 /* Initialise parse structures */
908 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
909 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
911 /* Marshall data and send request */
913 init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
915 if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
916 !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
917 result = NT_STATUS_UNSUCCESSFUL;
918 goto done;
921 /* Unmarshall response */
923 if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
924 result = NT_STATUS_UNSUCCESSFUL;
925 goto done;
928 /* Return output parameters */
930 if (NT_STATUS_IS_OK(result = r.status)) {
931 *alias_pol = r.pol;
932 #ifdef __INSURE__
933 alias_pol->marker = malloc(1);
934 #endif
937 done:
938 prs_mem_free(&qbuf);
939 prs_mem_free(&rbuf);
941 return result;
944 /* Query alias info */
946 NTSTATUS cli_samr_query_alias_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
947 POLICY_HND *alias_pol, uint16 switch_value,
948 ALIAS_INFO_CTR *ctr)
950 prs_struct qbuf, rbuf;
951 SAMR_Q_QUERY_ALIASINFO q;
952 SAMR_R_QUERY_ALIASINFO r;
953 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
955 DEBUG(10,("cli_samr_query_dom_info\n"));
957 ZERO_STRUCT(q);
958 ZERO_STRUCT(r);
960 /* Initialise parse structures */
962 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
963 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
965 /* Marshall data and send request */
967 init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
969 if (!samr_io_q_query_aliasinfo("", &q, &qbuf, 0) ||
970 !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASINFO, &qbuf, &rbuf)) {
971 goto done;
974 /* Unmarshall response */
976 if (!samr_io_r_query_aliasinfo("", &r, &rbuf, 0)) {
977 goto done;
980 /* Return output parameters */
982 if (!NT_STATUS_IS_OK(result = r.status)) {
983 goto done;
986 *ctr = r.ctr;
988 done:
989 prs_mem_free(&qbuf);
990 prs_mem_free(&rbuf);
992 return result;
995 /* Query domain info */
997 NTSTATUS cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
998 POLICY_HND *domain_pol, uint16 switch_value,
999 SAM_UNK_CTR *ctr)
1001 prs_struct qbuf, rbuf;
1002 SAMR_Q_QUERY_DOMAIN_INFO q;
1003 SAMR_R_QUERY_DOMAIN_INFO r;
1004 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1006 DEBUG(10,("cli_samr_query_dom_info\n"));
1008 ZERO_STRUCT(q);
1009 ZERO_STRUCT(r);
1011 /* Initialise parse structures */
1013 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1014 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1016 /* Marshall data and send request */
1018 init_samr_q_query_dom_info(&q, domain_pol, switch_value);
1020 if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
1021 !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
1022 goto done;
1025 /* Unmarshall response */
1027 r.ctr = ctr;
1029 if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
1030 goto done;
1033 /* Return output parameters */
1035 if (!NT_STATUS_IS_OK(result = r.status)) {
1036 goto done;
1039 done:
1040 prs_mem_free(&qbuf);
1041 prs_mem_free(&rbuf);
1043 return result;
1046 /* This function returns the bizzare set of (max_entries, max_size) required
1047 for the QueryDisplayInfo RPC to actually work against a domain controller
1048 with large (10k and higher) numbers of users. These values were
1049 obtained by inspection using ethereal and NT4 running User Manager. */
1051 void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
1052 uint32 *max_size)
1054 switch(loop_count) {
1055 case 0:
1056 *max_entries = 512;
1057 *max_size = 16383;
1058 break;
1059 case 1:
1060 *max_entries = 1024;
1061 *max_size = 32766;
1062 break;
1063 case 2:
1064 *max_entries = 2048;
1065 *max_size = 65532;
1066 break;
1067 case 3:
1068 *max_entries = 4096;
1069 *max_size = 131064;
1070 break;
1071 default: /* loop_count >= 4 */
1072 *max_entries = 4096;
1073 *max_size = 131071;
1074 break;
1078 /* Query display info */
1080 NTSTATUS cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1081 POLICY_HND *domain_pol, uint32 *start_idx,
1082 uint16 switch_value, uint32 *num_entries,
1083 uint32 max_entries, uint32 max_size,
1084 SAM_DISPINFO_CTR *ctr)
1086 prs_struct qbuf, rbuf;
1087 SAMR_Q_QUERY_DISPINFO q;
1088 SAMR_R_QUERY_DISPINFO r;
1089 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1091 DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
1093 ZERO_STRUCT(q);
1094 ZERO_STRUCT(r);
1096 *num_entries = 0;
1098 /* Initialise parse structures */
1100 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1101 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1103 /* Marshall data and send request */
1105 init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
1106 *start_idx, max_entries, max_size);
1108 if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
1109 !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
1110 goto done;
1113 /* Unmarshall response */
1115 r.ctr = ctr;
1117 if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
1118 goto done;
1121 /* Return output parameters */
1123 result = r.status;
1125 if (!NT_STATUS_IS_OK(result) &&
1126 NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1127 goto done;
1130 *num_entries = r.num_entries;
1131 *start_idx += r.num_entries; /* No next_idx in this structure! */
1133 done:
1134 prs_mem_free(&qbuf);
1135 prs_mem_free(&rbuf);
1137 return result;
1140 /* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
1141 looked up in one packet. */
1143 NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1144 POLICY_HND *domain_pol, uint32 flags,
1145 uint32 num_rids, uint32 *rids,
1146 uint32 *num_names, char ***names,
1147 uint32 **name_types)
1149 prs_struct qbuf, rbuf;
1150 SAMR_Q_LOOKUP_RIDS q;
1151 SAMR_R_LOOKUP_RIDS r;
1152 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1153 uint32 i;
1155 DEBUG(10,("cli_samr_lookup_rids\n"));
1157 if (num_rids > 1000) {
1158 DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
1159 "more than ~1000 rids are looked up at once.\n"));
1162 ZERO_STRUCT(q);
1163 ZERO_STRUCT(r);
1165 /* Initialise parse structures */
1167 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1168 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1170 /* Marshall data and send request */
1172 init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
1173 num_rids, rids);
1175 if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
1176 !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
1177 goto done;
1180 /* Unmarshall response */
1182 if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
1183 goto done;
1186 /* Return output parameters */
1188 if (!NT_STATUS_IS_OK(result = r.status)) {
1189 goto done;
1192 if (r.num_names1 == 0) {
1193 *num_names = 0;
1194 *names = NULL;
1195 goto done;
1198 *num_names = r.num_names1;
1199 *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
1200 *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
1202 for (i = 0; i < r.num_names1; i++) {
1203 fstring tmp;
1205 unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
1206 (*names)[i] = talloc_strdup(mem_ctx, tmp);
1207 (*name_types)[i] = r.type[i];
1210 done:
1211 prs_mem_free(&qbuf);
1212 prs_mem_free(&rbuf);
1214 return result;
1217 /* Lookup names */
1219 NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1220 POLICY_HND *domain_pol, uint32 flags,
1221 uint32 num_names, const char **names,
1222 uint32 *num_rids, uint32 **rids,
1223 uint32 **rid_types)
1225 prs_struct qbuf, rbuf;
1226 SAMR_Q_LOOKUP_NAMES q;
1227 SAMR_R_LOOKUP_NAMES r;
1228 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1229 uint32 i;
1231 DEBUG(10,("cli_samr_lookup_names\n"));
1233 ZERO_STRUCT(q);
1234 ZERO_STRUCT(r);
1236 /* Initialise parse structures */
1238 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1239 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1241 /* Marshall data and send request */
1243 init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
1244 num_names, names);
1246 if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
1247 !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
1248 goto done;
1251 /* Unmarshall response */
1253 if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
1254 goto done;
1257 /* Return output parameters */
1259 if (!NT_STATUS_IS_OK(result = r.status)) {
1260 goto done;
1263 if (r.num_rids1 == 0) {
1264 *num_rids = 0;
1265 goto done;
1268 *num_rids = r.num_rids1;
1269 *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1270 *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
1272 for (i = 0; i < r.num_rids1; i++) {
1273 (*rids)[i] = r.rids[i];
1274 (*rid_types)[i] = r.types[i];
1277 done:
1278 prs_mem_free(&qbuf);
1279 prs_mem_free(&rbuf);
1281 return result;
1284 /* Create a domain user */
1286 NTSTATUS cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1287 POLICY_HND *domain_pol, const char *acct_name,
1288 uint32 acb_info, uint32 unknown,
1289 POLICY_HND *user_pol, uint32 *rid)
1291 prs_struct qbuf, rbuf;
1292 SAMR_Q_CREATE_USER q;
1293 SAMR_R_CREATE_USER r;
1294 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1296 DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
1298 ZERO_STRUCT(q);
1299 ZERO_STRUCT(r);
1301 /* Initialise parse structures */
1303 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1304 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1306 /* Marshall data and send request */
1308 init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
1310 if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
1311 !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
1312 goto done;
1315 /* Unmarshall response */
1317 if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
1318 goto done;
1321 /* Return output parameters */
1323 if (!NT_STATUS_IS_OK(result = r.status)) {
1324 goto done;
1327 if (user_pol)
1328 *user_pol = r.user_pol;
1330 if (rid)
1331 *rid = r.user_rid;
1333 done:
1334 prs_mem_free(&qbuf);
1335 prs_mem_free(&rbuf);
1337 return result;
1340 /* Set userinfo */
1342 NTSTATUS cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1343 POLICY_HND *user_pol, uint16 switch_value,
1344 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1346 prs_struct qbuf, rbuf;
1347 SAMR_Q_SET_USERINFO q;
1348 SAMR_R_SET_USERINFO r;
1349 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1351 DEBUG(10,("cli_samr_set_userinfo\n"));
1353 ZERO_STRUCT(q);
1354 ZERO_STRUCT(r);
1356 /* Initialise parse structures */
1358 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1359 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1361 /* Marshall data and send request */
1363 q.ctr = ctr;
1365 init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
1366 ctr->info.id);
1368 if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
1369 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
1370 goto done;
1373 /* Unmarshall response */
1375 if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
1376 goto done;
1379 /* Return output parameters */
1381 if (!NT_STATUS_IS_OK(result = r.status)) {
1382 goto done;
1385 done:
1386 prs_mem_free(&qbuf);
1387 prs_mem_free(&rbuf);
1389 return result;
1392 /* Set userinfo2 */
1394 NTSTATUS cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1395 POLICY_HND *user_pol, uint16 switch_value,
1396 uchar sess_key[16], SAM_USERINFO_CTR *ctr)
1398 prs_struct qbuf, rbuf;
1399 SAMR_Q_SET_USERINFO2 q;
1400 SAMR_R_SET_USERINFO2 r;
1401 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1403 DEBUG(10,("cli_samr_set_userinfo2\n"));
1405 ZERO_STRUCT(q);
1406 ZERO_STRUCT(r);
1408 /* Initialise parse structures */
1410 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1411 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1413 /* Marshall data and send request */
1415 init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
1417 if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
1418 !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
1419 goto done;
1422 /* Unmarshall response */
1424 if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
1425 goto done;
1428 /* Return output parameters */
1430 if (!NT_STATUS_IS_OK(result = r.status)) {
1431 goto done;
1434 done:
1435 prs_mem_free(&qbuf);
1436 prs_mem_free(&rbuf);
1438 return result;
1441 /* Delete domain user */
1443 NTSTATUS cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1444 POLICY_HND *user_pol)
1446 prs_struct qbuf, rbuf;
1447 SAMR_Q_DELETE_DOM_USER q;
1448 SAMR_R_DELETE_DOM_USER r;
1449 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1451 DEBUG(10,("cli_samr_delete_dom_user\n"));
1453 ZERO_STRUCT(q);
1454 ZERO_STRUCT(r);
1456 /* Initialise parse structures */
1458 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1459 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1461 /* Marshall data and send request */
1463 init_samr_q_delete_dom_user(&q, user_pol);
1465 if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
1466 !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
1467 goto done;
1470 /* Unmarshall response */
1472 if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
1473 goto done;
1476 /* Return output parameters */
1478 result = r.status;
1480 done:
1481 prs_mem_free(&qbuf);
1482 prs_mem_free(&rbuf);
1484 return result;
1487 /* Query user security object */
1489 NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1490 POLICY_HND *user_pol, uint16 switch_value,
1491 TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
1493 prs_struct qbuf, rbuf;
1494 SAMR_Q_QUERY_SEC_OBJ q;
1495 SAMR_R_QUERY_SEC_OBJ r;
1496 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1498 DEBUG(10,("cli_samr_query_sec_obj\n"));
1500 ZERO_STRUCT(q);
1501 ZERO_STRUCT(r);
1503 /* Initialise parse structures */
1505 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1506 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1508 /* Marshall data and send request */
1510 init_samr_q_query_sec_obj(&q, user_pol, switch_value);
1512 if (!samr_io_q_query_sec_obj("", &q, &qbuf, 0) ||
1513 !rpc_api_pipe_req(cli, SAMR_QUERY_SEC_OBJECT, &qbuf, &rbuf)) {
1514 goto done;
1517 /* Unmarshall response */
1519 if (!samr_io_r_query_sec_obj("", &r, &rbuf, 0)) {
1520 goto done;
1523 /* Return output parameters */
1525 result = r.status;
1526 *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
1528 done:
1529 prs_mem_free(&qbuf);
1530 prs_mem_free(&rbuf);
1532 return result;
1535 /* Get domain password info */
1537 NTSTATUS cli_samr_get_dom_pwinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1538 uint16 *unk_0, uint16 *unk_1, uint16 *unk_2)
1540 prs_struct qbuf, rbuf;
1541 SAMR_Q_GET_DOM_PWINFO q;
1542 SAMR_R_GET_DOM_PWINFO r;
1543 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1545 DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
1547 ZERO_STRUCT(q);
1548 ZERO_STRUCT(r);
1550 /* Initialise parse structures */
1552 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1553 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1555 /* Marshall data and send request */
1557 init_samr_q_get_dom_pwinfo(&q, cli->desthost);
1559 if (!samr_io_q_get_dom_pwinfo("", &q, &qbuf, 0) ||
1560 !rpc_api_pipe_req(cli, SAMR_GET_DOM_PWINFO, &qbuf, &rbuf))
1561 goto done;
1563 /* Unmarshall response */
1565 if (!samr_io_r_get_dom_pwinfo("", &r, &rbuf, 0))
1566 goto done;
1568 /* Return output parameters */
1570 result = r.status;
1572 if (NT_STATUS_IS_OK(result)) {
1573 if (unk_0)
1574 *unk_0 = r.unk_0;
1575 if (unk_1)
1576 *unk_1 = r.unk_1;
1577 if (unk_2)
1578 *unk_2 = r.unk_2;
1581 done:
1582 prs_mem_free(&qbuf);
1583 prs_mem_free(&rbuf);
1585 return result;
1588 /* Lookup Domain Name */
1590 NTSTATUS cli_samr_lookup_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1591 POLICY_HND *user_pol, char *domain_name,
1592 DOM_SID *sid)
1594 prs_struct qbuf, rbuf;
1595 SAMR_Q_LOOKUP_DOMAIN q;
1596 SAMR_R_LOOKUP_DOMAIN r;
1597 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1599 DEBUG(10,("cli_samr_lookup_domain\n"));
1601 ZERO_STRUCT(q);
1602 ZERO_STRUCT(r);
1604 /* Initialise parse structures */
1606 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1607 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1609 /* Marshall data and send request */
1611 init_samr_q_lookup_domain(&q, user_pol, domain_name);
1613 if (!samr_io_q_lookup_domain("", &q, &qbuf, 0) ||
1614 !rpc_api_pipe_req(cli, SAMR_LOOKUP_DOMAIN, &qbuf, &rbuf))
1615 goto done;
1617 /* Unmarshall response */
1619 if (!samr_io_r_lookup_domain("", &r, &rbuf, 0))
1620 goto done;
1622 /* Return output parameters */
1624 result = r.status;
1626 if (NT_STATUS_IS_OK(result))
1627 sid_copy(sid, &r.dom_sid.sid);
1629 done:
1630 prs_mem_free(&qbuf);
1631 prs_mem_free(&rbuf);
1633 return result;