[GLUE] Rsync SAMBA_3_0 SVN r25598 in order to create the v3-0-test branch.
[Samba.git] / source / rpc_client / cli_lsarpc.c
blob4dfce1814303a442ee08b88b06e090dccc491f1f
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) 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.
24 #include "includes.h"
26 /** @defgroup lsa LSA - Local Security Architecture
27 * @ingroup rpc_client
29 * @{
30 **/
32 /**
33 * @file cli_lsarpc.c
35 * RPC client routines for the LSA RPC pipe. LSA means "local
36 * security authority", which is half of a password database.
37 **/
39 /** Open a LSA policy handle
41 * @param cli Handle on an initialised SMB connection */
43 NTSTATUS rpccli_lsa_open_policy(struct rpc_pipe_client *cli,
44 TALLOC_CTX *mem_ctx,
45 BOOL sec_qos, uint32 des_access,
46 POLICY_HND *pol)
48 prs_struct qbuf, rbuf;
49 LSA_Q_OPEN_POL q;
50 LSA_R_OPEN_POL r;
51 LSA_SEC_QOS qos;
52 NTSTATUS result;
54 ZERO_STRUCT(q);
55 ZERO_STRUCT(r);
57 /* Initialise input parameters */
59 if (sec_qos) {
60 init_lsa_sec_qos(&qos, 2, 1, 0);
61 init_q_open_pol(&q, '\\', 0, des_access, &qos);
62 } else {
63 init_q_open_pol(&q, '\\', 0, des_access, NULL);
66 /* Marshall data and send request */
68 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENPOLICY,
69 q, r,
70 qbuf, rbuf,
71 lsa_io_q_open_pol,
72 lsa_io_r_open_pol,
73 NT_STATUS_UNSUCCESSFUL );
75 /* Return output parameters */
77 result = r.status;
79 if (NT_STATUS_IS_OK(result)) {
80 *pol = r.pol;
81 #ifdef __INSURE__
82 pol->marker = MALLOC(1);
83 #endif
86 return result;
89 /** Open a LSA policy handle
91 * @param cli Handle on an initialised SMB connection
94 NTSTATUS rpccli_lsa_open_policy2(struct rpc_pipe_client *cli,
95 TALLOC_CTX *mem_ctx, BOOL sec_qos,
96 uint32 des_access, POLICY_HND *pol)
98 prs_struct qbuf, rbuf;
99 LSA_Q_OPEN_POL2 q;
100 LSA_R_OPEN_POL2 r;
101 LSA_SEC_QOS qos;
102 NTSTATUS result;
103 char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
105 ZERO_STRUCT(q);
106 ZERO_STRUCT(r);
108 if (sec_qos) {
109 init_lsa_sec_qos(&qos, 2, 1, 0);
110 init_q_open_pol2(&q, srv_name_slash, 0, des_access, &qos);
111 } else {
112 init_q_open_pol2(&q, srv_name_slash, 0, des_access, NULL);
115 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENPOLICY2,
116 q, r,
117 qbuf, rbuf,
118 lsa_io_q_open_pol2,
119 lsa_io_r_open_pol2,
120 NT_STATUS_UNSUCCESSFUL );
122 /* Return output parameters */
124 result = r.status;
126 if (NT_STATUS_IS_OK(result)) {
127 *pol = r.pol;
128 #ifdef __INSURE__
129 pol->marker = (char *)malloc(1);
130 #endif
133 return result;
136 /** Close a LSA policy handle */
138 NTSTATUS rpccli_lsa_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
139 POLICY_HND *pol)
141 prs_struct qbuf, rbuf;
142 LSA_Q_CLOSE q;
143 LSA_R_CLOSE r;
144 NTSTATUS result;
146 ZERO_STRUCT(q);
147 ZERO_STRUCT(r);
149 init_lsa_q_close(&q, pol);
151 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_CLOSE,
152 q, r,
153 qbuf, rbuf,
154 lsa_io_q_close,
155 lsa_io_r_close,
156 NT_STATUS_UNSUCCESSFUL );
158 /* Return output parameters */
160 result = r.status;
162 if (NT_STATUS_IS_OK(result)) {
163 #ifdef __INSURE__
164 SAFE_FREE(pol->marker);
165 #endif
166 *pol = r.pol;
169 return result;
172 /** Lookup a list of sids */
174 NTSTATUS rpccli_lsa_lookup_sids(struct rpc_pipe_client *cli,
175 TALLOC_CTX *mem_ctx,
176 POLICY_HND *pol, int num_sids,
177 const DOM_SID *sids,
178 char ***domains, char ***names, uint32 **types)
180 prs_struct qbuf, rbuf;
181 LSA_Q_LOOKUP_SIDS q;
182 LSA_R_LOOKUP_SIDS r;
183 DOM_R_REF ref;
184 NTSTATUS result = NT_STATUS_OK;
185 int i;
187 ZERO_STRUCT(q);
188 ZERO_STRUCT(r);
190 init_q_lookup_sids(mem_ctx, &q, pol, num_sids, sids, 1);
192 ZERO_STRUCT(ref);
194 r.dom_ref = &ref;
196 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPSIDS,
197 q, r,
198 qbuf, rbuf,
199 lsa_io_q_lookup_sids,
200 lsa_io_r_lookup_sids,
201 NT_STATUS_UNSUCCESSFUL );
203 if (!NT_STATUS_IS_OK(r.status) &&
204 NT_STATUS_V(r.status) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
206 /* An actual error occured */
207 result = r.status;
209 goto done;
212 /* Return output parameters */
214 if (r.mapped_count == 0) {
215 result = NT_STATUS_NONE_MAPPED;
216 goto done;
219 if (num_sids) {
220 if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
221 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
222 result = NT_STATUS_NO_MEMORY;
223 goto done;
226 if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
227 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
228 result = NT_STATUS_NO_MEMORY;
229 goto done;
232 if (!((*types) = TALLOC_ARRAY(mem_ctx, uint32, num_sids))) {
233 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
234 result = NT_STATUS_NO_MEMORY;
235 goto done;
237 } else {
238 (*domains) = NULL;
239 (*names) = NULL;
240 (*types) = NULL;
243 for (i = 0; i < num_sids; i++) {
244 fstring name, dom_name;
245 uint32 dom_idx = r.names.name[i].domain_idx;
247 /* Translate optimised name through domain index array */
249 if (dom_idx != 0xffffffff) {
251 rpcstr_pull_unistr2_fstring(
252 dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
253 rpcstr_pull_unistr2_fstring(
254 name, &r.names.uni_name[i]);
256 (*names)[i] = talloc_strdup(mem_ctx, name);
257 (*domains)[i] = talloc_strdup(mem_ctx, dom_name);
258 (*types)[i] = r.names.name[i].sid_name_use;
260 if (((*names)[i] == NULL) || ((*domains)[i] == NULL)) {
261 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
262 result = NT_STATUS_UNSUCCESSFUL;
263 goto done;
266 } else {
267 (*names)[i] = NULL;
268 (*domains)[i] = NULL;
269 (*types)[i] = SID_NAME_UNKNOWN;
273 done:
275 return result;
278 /** Lookup a list of names */
280 NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
281 TALLOC_CTX *mem_ctx,
282 POLICY_HND *pol, int num_names,
283 const char **names,
284 const char ***dom_names,
285 DOM_SID **sids,
286 uint32 **types)
288 prs_struct qbuf, rbuf;
289 LSA_Q_LOOKUP_NAMES q;
290 LSA_R_LOOKUP_NAMES r;
291 DOM_R_REF ref;
292 NTSTATUS result;
293 int i;
295 ZERO_STRUCT(q);
296 ZERO_STRUCT(r);
298 ZERO_STRUCT(ref);
299 r.dom_ref = &ref;
301 init_q_lookup_names(mem_ctx, &q, pol, num_names, names);
303 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPNAMES,
304 q, r,
305 qbuf, rbuf,
306 lsa_io_q_lookup_names,
307 lsa_io_r_lookup_names,
308 NT_STATUS_UNSUCCESSFUL);
310 result = r.status;
312 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
313 NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
315 /* An actual error occured */
317 goto done;
320 /* Return output parameters */
322 if (r.mapped_count == 0) {
323 result = NT_STATUS_NONE_MAPPED;
324 goto done;
327 if (num_names) {
328 if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
329 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
330 result = NT_STATUS_NO_MEMORY;
331 goto done;
334 if (!((*types = TALLOC_ARRAY(mem_ctx, uint32, num_names)))) {
335 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
336 result = NT_STATUS_NO_MEMORY;
337 goto done;
340 if (dom_names != NULL) {
341 *dom_names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
342 if (*dom_names == NULL) {
343 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
344 result = NT_STATUS_NO_MEMORY;
345 goto done;
348 } else {
349 *sids = NULL;
350 *types = NULL;
351 if (dom_names != NULL) {
352 *dom_names = NULL;
356 for (i = 0; i < num_names; i++) {
357 DOM_RID *t_rids = r.dom_rid;
358 uint32 dom_idx = t_rids[i].rid_idx;
359 uint32 dom_rid = t_rids[i].rid;
360 DOM_SID *sid = &(*sids)[i];
362 /* Translate optimised sid through domain index array */
364 if (dom_idx == 0xffffffff) {
365 /* Nothing to do, this is unknown */
366 ZERO_STRUCTP(sid);
367 (*types)[i] = SID_NAME_UNKNOWN;
368 continue;
371 sid_copy(sid, &ref.ref_dom[dom_idx].ref_dom.sid);
373 if (dom_rid != 0xffffffff) {
374 sid_append_rid(sid, dom_rid);
377 (*types)[i] = t_rids[i].type;
379 if (dom_names == NULL) {
380 continue;
383 (*dom_names)[i] = rpcstr_pull_unistr2_talloc(
384 *dom_names, &ref.ref_dom[dom_idx].uni_dom_name);
387 done:
389 return result;
392 NTSTATUS rpccli_lsa_query_info_policy_new(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
393 POLICY_HND *pol, uint16 info_class,
394 LSA_INFO_CTR *ctr)
396 prs_struct qbuf, rbuf;
397 LSA_Q_QUERY_INFO q;
398 LSA_R_QUERY_INFO r;
399 NTSTATUS result;
401 ZERO_STRUCT(q);
402 ZERO_STRUCT(r);
404 init_q_query(&q, pol, info_class);
406 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_QUERYINFOPOLICY,
407 q, r,
408 qbuf, rbuf,
409 lsa_io_q_query,
410 lsa_io_r_query,
411 NT_STATUS_UNSUCCESSFUL);
413 result = r.status;
415 if (!NT_STATUS_IS_OK(result)) {
416 goto done;
419 done:
421 *ctr = r.ctr;
423 return result;
426 NTSTATUS rpccli_lsa_query_info_policy2_new(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
427 POLICY_HND *pol, uint16 info_class,
428 LSA_INFO_CTR2 *ctr)
430 prs_struct qbuf, rbuf;
431 LSA_Q_QUERY_INFO2 q;
432 LSA_R_QUERY_INFO2 r;
433 NTSTATUS result;
435 ZERO_STRUCT(q);
436 ZERO_STRUCT(r);
438 init_q_query2(&q, pol, info_class);
440 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_QUERYINFO2,
441 q, r,
442 qbuf, rbuf,
443 lsa_io_q_query_info2,
444 lsa_io_r_query_info2,
445 NT_STATUS_UNSUCCESSFUL);
447 result = r.status;
449 if (!NT_STATUS_IS_OK(result)) {
450 goto done;
453 done:
455 *ctr = r.ctr;
457 return result;
462 /** Query info policy
464 * @param domain_sid - returned remote server's domain sid */
466 NTSTATUS rpccli_lsa_query_info_policy(struct rpc_pipe_client *cli,
467 TALLOC_CTX *mem_ctx,
468 POLICY_HND *pol, uint16 info_class,
469 char **domain_name, DOM_SID **domain_sid)
471 prs_struct qbuf, rbuf;
472 LSA_Q_QUERY_INFO q;
473 LSA_R_QUERY_INFO r;
474 NTSTATUS result;
476 ZERO_STRUCT(q);
477 ZERO_STRUCT(r);
479 init_q_query(&q, pol, info_class);
481 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_QUERYINFOPOLICY,
482 q, r,
483 qbuf, rbuf,
484 lsa_io_q_query,
485 lsa_io_r_query,
486 NT_STATUS_UNSUCCESSFUL);
488 result = r.status;
490 if (!NT_STATUS_IS_OK(result)) {
491 goto done;
494 /* Return output parameters */
496 switch (info_class) {
498 case 3:
499 if (domain_name && (r.ctr.info.id3.buffer_dom_name != 0)) {
500 *domain_name = unistr2_tdup(mem_ctx,
501 &r.ctr.info.id3.
502 uni_domain_name);
503 if (!*domain_name) {
504 return NT_STATUS_NO_MEMORY;
508 if (domain_sid && (r.ctr.info.id3.buffer_dom_sid != 0)) {
509 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
510 if (!*domain_sid) {
511 return NT_STATUS_NO_MEMORY;
513 sid_copy(*domain_sid, &r.ctr.info.id3.dom_sid.sid);
516 break;
518 case 5:
520 if (domain_name && (r.ctr.info.id5.buffer_dom_name != 0)) {
521 *domain_name = unistr2_tdup(mem_ctx,
522 &r.ctr.info.id5.
523 uni_domain_name);
524 if (!*domain_name) {
525 return NT_STATUS_NO_MEMORY;
529 if (domain_sid && (r.ctr.info.id5.buffer_dom_sid != 0)) {
530 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
531 if (!*domain_sid) {
532 return NT_STATUS_NO_MEMORY;
534 sid_copy(*domain_sid, &r.ctr.info.id5.dom_sid.sid);
536 break;
538 default:
539 DEBUG(3, ("unknown info class %d\n", info_class));
540 break;
543 done:
545 return result;
548 /** Query info policy2
550 * @param domain_name - returned remote server's domain name
551 * @param dns_name - returned remote server's dns domain name
552 * @param forest_name - returned remote server's forest name
553 * @param domain_guid - returned remote server's domain guid
554 * @param domain_sid - returned remote server's domain sid */
556 NTSTATUS rpccli_lsa_query_info_policy2(struct rpc_pipe_client *cli,
557 TALLOC_CTX *mem_ctx,
558 POLICY_HND *pol, uint16 info_class,
559 char **domain_name, char **dns_name,
560 char **forest_name,
561 struct GUID **domain_guid,
562 DOM_SID **domain_sid)
564 prs_struct qbuf, rbuf;
565 LSA_Q_QUERY_INFO2 q;
566 LSA_R_QUERY_INFO2 r;
567 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
569 if (info_class != 12)
570 goto done;
572 ZERO_STRUCT(q);
573 ZERO_STRUCT(r);
575 init_q_query2(&q, pol, info_class);
577 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYINFO2,
578 q, r,
579 qbuf, rbuf,
580 lsa_io_q_query_info2,
581 lsa_io_r_query_info2,
582 NT_STATUS_UNSUCCESSFUL);
584 result = r.status;
586 if (!NT_STATUS_IS_OK(result)) {
587 goto done;
590 /* Return output parameters */
592 ZERO_STRUCTP(domain_guid);
594 if (domain_name && r.ctr.info.id12.hdr_nb_dom_name.buffer) {
595 *domain_name = unistr2_tdup(mem_ctx,
596 &r.ctr.info.id12
597 .uni_nb_dom_name);
598 if (!*domain_name) {
599 return NT_STATUS_NO_MEMORY;
602 if (dns_name && r.ctr.info.id12.hdr_dns_dom_name.buffer) {
603 *dns_name = unistr2_tdup(mem_ctx,
604 &r.ctr.info.id12
605 .uni_dns_dom_name);
606 if (!*dns_name) {
607 return NT_STATUS_NO_MEMORY;
610 if (forest_name && r.ctr.info.id12.hdr_forest_name.buffer) {
611 *forest_name = unistr2_tdup(mem_ctx,
612 &r.ctr.info.id12
613 .uni_forest_name);
614 if (!*forest_name) {
615 return NT_STATUS_NO_MEMORY;
619 if (domain_guid) {
620 *domain_guid = TALLOC_P(mem_ctx, struct GUID);
621 if (!*domain_guid) {
622 return NT_STATUS_NO_MEMORY;
624 memcpy(*domain_guid,
625 &r.ctr.info.id12.dom_guid,
626 sizeof(struct GUID));
629 if (domain_sid && r.ctr.info.id12.ptr_dom_sid != 0) {
630 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
631 if (!*domain_sid) {
632 return NT_STATUS_NO_MEMORY;
634 sid_copy(*domain_sid,
635 &r.ctr.info.id12.dom_sid.sid);
638 done:
640 return result;
643 NTSTATUS rpccli_lsa_set_info_policy(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
644 POLICY_HND *pol, uint16 info_class,
645 LSA_INFO_CTR ctr)
647 prs_struct qbuf, rbuf;
648 LSA_Q_SET_INFO q;
649 LSA_R_SET_INFO r;
650 NTSTATUS result;
652 ZERO_STRUCT(q);
653 ZERO_STRUCT(r);
655 init_q_set(&q, pol, info_class, ctr);
657 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_SETINFOPOLICY,
658 q, r,
659 qbuf, rbuf,
660 lsa_io_q_set,
661 lsa_io_r_set,
662 NT_STATUS_UNSUCCESSFUL);
664 result = r.status;
666 if (!NT_STATUS_IS_OK(result)) {
667 goto done;
670 /* Return output parameters */
672 done:
674 return result;
679 * Enumerate list of trusted domains
681 * @param cli client state (cli_state) structure of the connection
682 * @param mem_ctx memory context
683 * @param pol opened lsa policy handle
684 * @param enum_ctx enumeration context ie. index of first returned domain entry
685 * @param pref_num_domains preferred max number of entries returned in one response
686 * @param num_domains total number of trusted domains returned by response
687 * @param domain_names returned trusted domain names
688 * @param domain_sids returned trusted domain sids
690 * @return nt status code of response
693 NTSTATUS rpccli_lsa_enum_trust_dom(struct rpc_pipe_client *cli,
694 TALLOC_CTX *mem_ctx,
695 POLICY_HND *pol, uint32 *enum_ctx,
696 uint32 *num_domains,
697 char ***domain_names, DOM_SID **domain_sids)
699 prs_struct qbuf, rbuf;
700 LSA_Q_ENUM_TRUST_DOM in;
701 LSA_R_ENUM_TRUST_DOM out;
702 int i;
703 fstring tmp;
705 ZERO_STRUCT(in);
706 ZERO_STRUCT(out);
708 /* 64k is enough for about 2000 trusted domains */
710 init_q_enum_trust_dom(&in, pol, *enum_ctx, 0x10000);
712 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMTRUSTDOM,
713 in, out,
714 qbuf, rbuf,
715 lsa_io_q_enum_trust_dom,
716 lsa_io_r_enum_trust_dom,
717 NT_STATUS_UNSUCCESSFUL );
720 /* check for an actual error */
722 if ( !NT_STATUS_IS_OK(out.status)
723 && !NT_STATUS_EQUAL(out.status, NT_STATUS_NO_MORE_ENTRIES)
724 && !NT_STATUS_EQUAL(out.status, STATUS_MORE_ENTRIES) )
726 return out.status;
729 /* Return output parameters */
731 *num_domains = out.count;
732 *enum_ctx = out.enum_context;
734 if ( out.count ) {
736 /* Allocate memory for trusted domain names and sids */
738 if ( !(*domain_names = TALLOC_ARRAY(mem_ctx, char *, out.count)) ) {
739 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
740 return NT_STATUS_NO_MEMORY;
743 if ( !(*domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, out.count)) ) {
744 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
745 return NT_STATUS_NO_MEMORY;
748 /* Copy across names and sids */
750 for (i = 0; i < out.count; i++) {
752 rpcstr_pull( tmp, out.domlist->domains[i].name.string->buffer,
753 sizeof(tmp), out.domlist->domains[i].name.length, 0);
754 (*domain_names)[i] = talloc_strdup(mem_ctx, tmp);
756 sid_copy(&(*domain_sids)[i], &out.domlist->domains[i].sid->sid );
760 return out.status;
763 /** Enumerate privileges*/
765 NTSTATUS rpccli_lsa_enum_privilege(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
766 POLICY_HND *pol, uint32 *enum_context, uint32 pref_max_length,
767 uint32 *count, char ***privs_name, uint32 **privs_high, uint32 **privs_low)
769 prs_struct qbuf, rbuf;
770 LSA_Q_ENUM_PRIVS q;
771 LSA_R_ENUM_PRIVS r;
772 NTSTATUS result;
773 int i;
775 ZERO_STRUCT(q);
776 ZERO_STRUCT(r);
778 init_q_enum_privs(&q, pol, *enum_context, pref_max_length);
780 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUM_PRIVS,
781 q, r,
782 qbuf, rbuf,
783 lsa_io_q_enum_privs,
784 lsa_io_r_enum_privs,
785 NT_STATUS_UNSUCCESSFUL);
787 result = r.status;
789 if (!NT_STATUS_IS_OK(result)) {
790 goto done;
793 /* Return output parameters */
795 *enum_context = r.enum_context;
796 *count = r.count;
798 if (r.count) {
799 if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
800 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
801 result = NT_STATUS_UNSUCCESSFUL;
802 goto done;
805 if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
806 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
807 result = NT_STATUS_UNSUCCESSFUL;
808 goto done;
811 if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
812 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
813 result = NT_STATUS_UNSUCCESSFUL;
814 goto done;
816 } else {
817 *privs_name = NULL;
818 *privs_high = NULL;
819 *privs_low = NULL;
822 for (i = 0; i < r.count; i++) {
823 fstring name;
825 rpcstr_pull_unistr2_fstring( name, &r.privs[i].name);
827 (*privs_name)[i] = talloc_strdup(mem_ctx, name);
829 (*privs_high)[i] = r.privs[i].luid_high;
830 (*privs_low)[i] = r.privs[i].luid_low;
833 done:
835 return result;
838 /** Get privilege name */
840 NTSTATUS rpccli_lsa_get_dispname(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
841 POLICY_HND *pol, const char *name,
842 uint16 lang_id, uint16 lang_id_sys,
843 fstring description, uint16 *lang_id_desc)
845 prs_struct qbuf, rbuf;
846 LSA_Q_PRIV_GET_DISPNAME q;
847 LSA_R_PRIV_GET_DISPNAME r;
848 NTSTATUS result;
850 ZERO_STRUCT(q);
851 ZERO_STRUCT(r);
853 init_lsa_priv_get_dispname(&q, pol, name, lang_id, lang_id_sys);
855 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_PRIV_GET_DISPNAME,
856 q, r,
857 qbuf, rbuf,
858 lsa_io_q_priv_get_dispname,
859 lsa_io_r_priv_get_dispname,
860 NT_STATUS_UNSUCCESSFUL);
862 result = r.status;
864 if (!NT_STATUS_IS_OK(result)) {
865 goto done;
868 /* Return output parameters */
870 rpcstr_pull_unistr2_fstring(description , &r.desc);
871 *lang_id_desc = r.lang_id;
873 done:
875 return result;
878 /** Enumerate list of SIDs */
880 NTSTATUS rpccli_lsa_enum_sids(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
881 POLICY_HND *pol, uint32 *enum_ctx, uint32 pref_max_length,
882 uint32 *num_sids, DOM_SID **sids)
884 prs_struct qbuf, rbuf;
885 LSA_Q_ENUM_ACCOUNTS q;
886 LSA_R_ENUM_ACCOUNTS r;
887 NTSTATUS result;
888 int i;
890 ZERO_STRUCT(q);
891 ZERO_STRUCT(r);
893 init_lsa_q_enum_accounts(&q, pol, *enum_ctx, pref_max_length);
895 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUM_ACCOUNTS,
896 q, r,
897 qbuf, rbuf,
898 lsa_io_q_enum_accounts,
899 lsa_io_r_enum_accounts,
900 NT_STATUS_UNSUCCESSFUL);
902 result = r.status;
904 if (!NT_STATUS_IS_OK(result)) {
905 goto done;
908 if (r.sids.num_entries==0)
909 goto done;
911 /* Return output parameters */
913 *sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.sids.num_entries);
914 if (!*sids) {
915 DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
916 result = NT_STATUS_UNSUCCESSFUL;
917 goto done;
920 /* Copy across names and sids */
922 for (i = 0; i < r.sids.num_entries; i++) {
923 sid_copy(&(*sids)[i], &r.sids.sid[i].sid);
926 *num_sids= r.sids.num_entries;
927 *enum_ctx = r.enum_context;
929 done:
931 return result;
934 /** Create a LSA user handle
936 * @param cli Handle on an initialised SMB connection
938 * FIXME: The code is actually identical to open account
939 * TODO: Check and code what the function should exactly do
941 * */
943 NTSTATUS rpccli_lsa_create_account(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
944 POLICY_HND *dom_pol, DOM_SID *sid, uint32 desired_access,
945 POLICY_HND *user_pol)
947 prs_struct qbuf, rbuf;
948 LSA_Q_CREATEACCOUNT q;
949 LSA_R_CREATEACCOUNT r;
950 NTSTATUS result;
952 ZERO_STRUCT(q);
953 ZERO_STRUCT(r);
955 /* Initialise input parameters */
957 init_lsa_q_create_account(&q, dom_pol, sid, desired_access);
959 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_CREATEACCOUNT,
960 q, r,
961 qbuf, rbuf,
962 lsa_io_q_create_account,
963 lsa_io_r_create_account,
964 NT_STATUS_UNSUCCESSFUL);
966 /* Return output parameters */
968 result = r.status;
970 if (NT_STATUS_IS_OK(result)) {
971 *user_pol = r.pol;
974 return result;
977 /** Open a LSA user handle
979 * @param cli Handle on an initialised SMB connection */
981 NTSTATUS rpccli_lsa_open_account(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
982 POLICY_HND *dom_pol, DOM_SID *sid, uint32 des_access,
983 POLICY_HND *user_pol)
985 prs_struct qbuf, rbuf;
986 LSA_Q_OPENACCOUNT q;
987 LSA_R_OPENACCOUNT r;
988 NTSTATUS result;
990 ZERO_STRUCT(q);
991 ZERO_STRUCT(r);
993 /* Initialise input parameters */
995 init_lsa_q_open_account(&q, dom_pol, sid, des_access);
997 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENACCOUNT,
998 q, r,
999 qbuf, rbuf,
1000 lsa_io_q_open_account,
1001 lsa_io_r_open_account,
1002 NT_STATUS_UNSUCCESSFUL);
1004 /* Return output parameters */
1006 result = r.status;
1008 if (NT_STATUS_IS_OK(result)) {
1009 *user_pol = r.pol;
1012 return result;
1015 /** Enumerate user privileges
1017 * @param cli Handle on an initialised SMB connection */
1019 NTSTATUS rpccli_lsa_enum_privsaccount(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1020 POLICY_HND *pol, uint32 *count, LUID_ATTR **set)
1022 prs_struct qbuf, rbuf;
1023 LSA_Q_ENUMPRIVSACCOUNT q;
1024 LSA_R_ENUMPRIVSACCOUNT r;
1025 NTSTATUS result;
1026 int i;
1028 ZERO_STRUCT(q);
1029 ZERO_STRUCT(r);
1031 /* Initialise input parameters */
1033 init_lsa_q_enum_privsaccount(&q, pol);
1035 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMPRIVSACCOUNT,
1036 q, r,
1037 qbuf, rbuf,
1038 lsa_io_q_enum_privsaccount,
1039 lsa_io_r_enum_privsaccount,
1040 NT_STATUS_UNSUCCESSFUL);
1042 /* Return output parameters */
1044 result = r.status;
1046 if (!NT_STATUS_IS_OK(result)) {
1047 goto done;
1050 if (r.count == 0)
1051 goto done;
1053 if (!((*set = TALLOC_ARRAY(mem_ctx, LUID_ATTR, r.count)))) {
1054 DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
1055 result = NT_STATUS_UNSUCCESSFUL;
1056 goto done;
1059 for (i=0; i<r.count; i++) {
1060 (*set)[i].luid.low = r.set.set[i].luid.low;
1061 (*set)[i].luid.high = r.set.set[i].luid.high;
1062 (*set)[i].attr = r.set.set[i].attr;
1065 *count=r.count;
1066 done:
1068 return result;
1071 /** Get a privilege value given its name */
1073 NTSTATUS rpccli_lsa_lookup_priv_value(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1074 POLICY_HND *pol, const char *name, LUID *luid)
1076 prs_struct qbuf, rbuf;
1077 LSA_Q_LOOKUP_PRIV_VALUE q;
1078 LSA_R_LOOKUP_PRIV_VALUE r;
1079 NTSTATUS result;
1081 ZERO_STRUCT(q);
1082 ZERO_STRUCT(r);
1084 /* Marshall data and send request */
1086 init_lsa_q_lookup_priv_value(&q, pol, name);
1088 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPPRIVVALUE,
1089 q, r,
1090 qbuf, rbuf,
1091 lsa_io_q_lookup_priv_value,
1092 lsa_io_r_lookup_priv_value,
1093 NT_STATUS_UNSUCCESSFUL);
1095 result = r.status;
1097 if (!NT_STATUS_IS_OK(result)) {
1098 goto done;
1101 /* Return output parameters */
1103 (*luid).low=r.luid.low;
1104 (*luid).high=r.luid.high;
1106 done:
1108 return result;
1111 /** Query LSA security object */
1113 NTSTATUS rpccli_lsa_query_secobj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1114 POLICY_HND *pol, uint32 sec_info,
1115 SEC_DESC_BUF **psdb)
1117 prs_struct qbuf, rbuf;
1118 LSA_Q_QUERY_SEC_OBJ q;
1119 LSA_R_QUERY_SEC_OBJ r;
1120 NTSTATUS result;
1122 ZERO_STRUCT(q);
1123 ZERO_STRUCT(r);
1125 /* Marshall data and send request */
1127 init_q_query_sec_obj(&q, pol, sec_info);
1129 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYSECOBJ,
1130 q, r,
1131 qbuf, rbuf,
1132 lsa_io_q_query_sec_obj,
1133 lsa_io_r_query_sec_obj,
1134 NT_STATUS_UNSUCCESSFUL);
1136 result = r.status;
1138 if (!NT_STATUS_IS_OK(result)) {
1139 goto done;
1142 /* Return output parameters */
1144 if (psdb)
1145 *psdb = r.buf;
1147 done:
1149 return result;
1153 /* Enumerate account rights This is similar to enum_privileges but
1154 takes a SID directly, avoiding the open_account call.
1157 NTSTATUS rpccli_lsa_enum_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1158 POLICY_HND *pol, DOM_SID *sid,
1159 uint32 *count, char ***priv_names)
1161 prs_struct qbuf, rbuf;
1162 LSA_Q_ENUM_ACCT_RIGHTS q;
1163 LSA_R_ENUM_ACCT_RIGHTS r;
1164 NTSTATUS result;
1165 int i;
1166 fstring *privileges;
1167 char **names;
1169 ZERO_STRUCT(q);
1170 ZERO_STRUCT(r);
1172 /* Marshall data and send request */
1173 init_q_enum_acct_rights(&q, pol, 2, sid);
1175 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMACCTRIGHTS,
1176 q, r,
1177 qbuf, rbuf,
1178 lsa_io_q_enum_acct_rights,
1179 lsa_io_r_enum_acct_rights,
1180 NT_STATUS_UNSUCCESSFUL);
1182 result = r.status;
1184 if (!NT_STATUS_IS_OK(result)) {
1185 goto done;
1188 *count = r.count;
1189 if (! *count) {
1190 goto done;
1194 privileges = TALLOC_ARRAY( mem_ctx, fstring, *count );
1195 names = TALLOC_ARRAY( mem_ctx, char *, *count );
1197 if ((privileges == NULL) || (names == NULL)) {
1198 TALLOC_FREE(privileges);
1199 TALLOC_FREE(names);
1200 return NT_STATUS_NO_MEMORY;
1203 for ( i=0; i<*count; i++ ) {
1204 UNISTR4 *uni_string = &r.rights->strings[i];
1206 if ( !uni_string->string )
1207 continue;
1209 rpcstr_pull( privileges[i], uni_string->string->buffer, sizeof(privileges[i]), -1, STR_TERMINATE );
1211 /* now copy to the return array */
1212 names[i] = talloc_strdup( mem_ctx, privileges[i] );
1215 *priv_names = names;
1217 done:
1219 return result;
1224 /* add account rights to an account. */
1226 NTSTATUS rpccli_lsa_add_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1227 POLICY_HND *pol, DOM_SID sid,
1228 uint32 count, const char **privs_name)
1230 prs_struct qbuf, rbuf;
1231 LSA_Q_ADD_ACCT_RIGHTS q;
1232 LSA_R_ADD_ACCT_RIGHTS r;
1233 NTSTATUS result;
1235 ZERO_STRUCT(q);
1236 ZERO_STRUCT(r);
1238 /* Marshall data and send request */
1239 init_q_add_acct_rights(&q, pol, &sid, count, privs_name);
1241 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ADDACCTRIGHTS,
1242 q, r,
1243 qbuf, rbuf,
1244 lsa_io_q_add_acct_rights,
1245 lsa_io_r_add_acct_rights,
1246 NT_STATUS_UNSUCCESSFUL);
1248 result = r.status;
1250 if (!NT_STATUS_IS_OK(result)) {
1251 goto done;
1253 done:
1255 return result;
1259 /* remove account rights for an account. */
1261 NTSTATUS rpccli_lsa_remove_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1262 POLICY_HND *pol, DOM_SID sid, BOOL removeall,
1263 uint32 count, const char **privs_name)
1265 prs_struct qbuf, rbuf;
1266 LSA_Q_REMOVE_ACCT_RIGHTS q;
1267 LSA_R_REMOVE_ACCT_RIGHTS r;
1268 NTSTATUS result;
1270 ZERO_STRUCT(q);
1271 ZERO_STRUCT(r);
1273 /* Marshall data and send request */
1274 init_q_remove_acct_rights(&q, pol, &sid, removeall?1:0, count, privs_name);
1276 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_REMOVEACCTRIGHTS,
1277 q, r,
1278 qbuf, rbuf,
1279 lsa_io_q_remove_acct_rights,
1280 lsa_io_r_remove_acct_rights,
1281 NT_STATUS_UNSUCCESSFUL);
1283 result = r.status;
1285 if (!NT_STATUS_IS_OK(result)) {
1286 goto done;
1288 done:
1290 return result;
1294 #if 0
1296 /** An example of how to use the routines in this file. Fetch a DOMAIN
1297 sid. Does complete cli setup / teardown anonymously. */
1299 BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid)
1301 extern pstring global_myname;
1302 struct cli_state cli;
1303 NTSTATUS result;
1304 POLICY_HND lsa_pol;
1305 BOOL ret = False;
1307 ZERO_STRUCT(cli);
1308 if(cli_initialise(&cli) == False) {
1309 DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
1310 return False;
1313 if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
1314 DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
1315 goto done;
1318 if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
1319 DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
1320 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1321 goto done;
1324 if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
1325 DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
1326 remote_machine));
1327 goto done;
1330 cli.protocol = PROTOCOL_NT1;
1332 if (!cli_negprot(&cli)) {
1333 DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \
1334 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1335 goto done;
1338 if (cli.protocol != PROTOCOL_NT1) {
1339 DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
1340 remote_machine));
1341 goto done;
1345 * Do an anonymous session setup.
1348 if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
1349 DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \
1350 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1351 goto done;
1354 if (!(cli.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
1355 DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n",
1356 remote_machine));
1357 goto done;
1360 if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
1361 DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \
1362 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1363 goto done;
1366 /* Fetch domain sid */
1368 if (!cli_nt_session_open(&cli, PI_LSARPC)) {
1369 DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n"));
1370 goto done;
1373 result = cli_lsa_open_policy(&cli, cli.mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
1374 if (!NT_STATUS_IS_OK(result)) {
1375 DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n",
1376 nt_errstr(result) ));
1377 goto done;
1380 result = cli_lsa_query_info_policy(&cli, cli.mem_ctx, &lsa_pol, 5, domain, psid);
1381 if (!NT_STATUS_IS_OK(result)) {
1382 DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n",
1383 nt_errstr(result) ));
1384 goto done;
1387 ret = True;
1389 done:
1391 cli_shutdown(&cli);
1392 return ret;
1395 #endif
1397 NTSTATUS rpccli_lsa_open_trusted_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1398 POLICY_HND *pol, DOM_SID *dom_sid, uint32 access_mask,
1399 POLICY_HND *trustdom_pol)
1401 prs_struct qbuf, rbuf;
1402 LSA_Q_OPEN_TRUSTED_DOMAIN q;
1403 LSA_R_OPEN_TRUSTED_DOMAIN r;
1404 NTSTATUS result;
1406 ZERO_STRUCT(q);
1407 ZERO_STRUCT(r);
1409 /* Initialise input parameters */
1411 init_lsa_q_open_trusted_domain(&q, pol, dom_sid, access_mask);
1413 /* Marshall data and send request */
1415 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENTRUSTDOM,
1416 q, r,
1417 qbuf, rbuf,
1418 lsa_io_q_open_trusted_domain,
1419 lsa_io_r_open_trusted_domain,
1420 NT_STATUS_UNSUCCESSFUL);
1422 /* Return output parameters */
1424 result = r.status;
1426 if (NT_STATUS_IS_OK(result)) {
1427 *trustdom_pol = r.handle;
1430 return result;
1433 NTSTATUS rpccli_lsa_query_trusted_domain_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1434 POLICY_HND *pol,
1435 uint16 info_class,
1436 LSA_TRUSTED_DOMAIN_INFO **info)
1438 prs_struct qbuf, rbuf;
1439 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO q;
1440 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1441 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1443 ZERO_STRUCT(q);
1444 ZERO_STRUCT(r);
1446 /* Marshall data and send request */
1448 init_q_query_trusted_domain_info(&q, pol, info_class);
1450 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFO,
1451 q, r,
1452 qbuf, rbuf,
1453 lsa_io_q_query_trusted_domain_info,
1454 lsa_io_r_query_trusted_domain_info,
1455 NT_STATUS_UNSUCCESSFUL);
1457 result = r.status;
1459 if (!NT_STATUS_IS_OK(result)) {
1460 goto done;
1463 *info = r.info;
1465 done:
1466 return result;
1469 NTSTATUS rpccli_lsa_open_trusted_domain_by_name(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1470 POLICY_HND *pol, const char *name, uint32 access_mask,
1471 POLICY_HND *trustdom_pol)
1473 prs_struct qbuf, rbuf;
1474 LSA_Q_OPEN_TRUSTED_DOMAIN_BY_NAME q;
1475 LSA_R_OPEN_TRUSTED_DOMAIN_BY_NAME r;
1476 NTSTATUS result;
1478 ZERO_STRUCT(q);
1479 ZERO_STRUCT(r);
1481 /* Initialise input parameters */
1483 init_lsa_q_open_trusted_domain_by_name(&q, pol, name, access_mask);
1485 /* Marshall data and send request */
1487 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENTRUSTDOMBYNAME,
1488 q, r,
1489 qbuf, rbuf,
1490 lsa_io_q_open_trusted_domain_by_name,
1491 lsa_io_r_open_trusted_domain_by_name,
1492 NT_STATUS_UNSUCCESSFUL);
1494 /* Return output parameters */
1496 result = r.status;
1498 if (NT_STATUS_IS_OK(result)) {
1499 *trustdom_pol = r.handle;
1502 return result;
1506 NTSTATUS rpccli_lsa_query_trusted_domain_info_by_sid(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1507 POLICY_HND *pol,
1508 uint16 info_class, DOM_SID *dom_sid,
1509 LSA_TRUSTED_DOMAIN_INFO **info)
1511 prs_struct qbuf, rbuf;
1512 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID q;
1513 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1514 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1516 ZERO_STRUCT(q);
1517 ZERO_STRUCT(r);
1519 /* Marshall data and send request */
1521 init_q_query_trusted_domain_info_by_sid(&q, pol, info_class, dom_sid);
1523 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFOBYSID,
1524 q, r,
1525 qbuf, rbuf,
1526 lsa_io_q_query_trusted_domain_info_by_sid,
1527 lsa_io_r_query_trusted_domain_info,
1528 NT_STATUS_UNSUCCESSFUL);
1530 result = r.status;
1532 if (!NT_STATUS_IS_OK(result)) {
1533 goto done;
1536 *info = r.info;
1538 done:
1540 return result;
1543 NTSTATUS rpccli_lsa_query_trusted_domain_info_by_name(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1544 POLICY_HND *pol,
1545 uint16 info_class, const char *domain_name,
1546 LSA_TRUSTED_DOMAIN_INFO **info)
1548 prs_struct qbuf, rbuf;
1549 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME q;
1550 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1551 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1553 ZERO_STRUCT(q);
1554 ZERO_STRUCT(r);
1556 /* Marshall data and send request */
1558 init_q_query_trusted_domain_info_by_name(&q, pol, info_class, domain_name);
1560 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFOBYNAME,
1561 q, r,
1562 qbuf, rbuf,
1563 lsa_io_q_query_trusted_domain_info_by_name,
1564 lsa_io_r_query_trusted_domain_info,
1565 NT_STATUS_UNSUCCESSFUL);
1567 result = r.status;
1569 if (!NT_STATUS_IS_OK(result)) {
1570 goto done;
1573 *info = r.info;
1575 done:
1577 return result;
1580 NTSTATUS cli_lsa_query_domain_info_policy(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1581 POLICY_HND *pol,
1582 uint16 info_class, LSA_DOM_INFO_UNION **info)
1584 prs_struct qbuf, rbuf;
1585 LSA_Q_QUERY_DOM_INFO_POLICY q;
1586 LSA_R_QUERY_DOM_INFO_POLICY r;
1587 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1589 ZERO_STRUCT(q);
1590 ZERO_STRUCT(r);
1592 /* Marshall data and send request */
1594 init_q_query_dom_info(&q, pol, info_class);
1596 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYDOMINFOPOL,
1597 q, r,
1598 qbuf, rbuf,
1599 lsa_io_q_query_dom_info,
1600 lsa_io_r_query_dom_info,
1601 NT_STATUS_UNSUCCESSFUL);
1603 result = r.status;
1605 if (!NT_STATUS_IS_OK(result)) {
1606 goto done;
1609 *info = r.info;
1611 done:
1612 return result;