2 Unix SMB/CIFS implementation.
4 Copyright (C) Tim Potter 2000-2001,
5 Copyright (C) Andrew Tridgell 1992-1997,2000,
6 Copyright (C) Rafal Szczesniak 2002
7 Copyright (C) Jeremy Allison 2005.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /** @defgroup lsa LSA - Local Security Architecture
35 * RPC client routines for the LSA RPC pipe. LSA means "local
36 * security authority", which is half of a password database.
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
,
45 BOOL sec_qos
, uint32 des_access
,
48 prs_struct qbuf
, rbuf
;
57 /* Initialise input parameters */
60 init_lsa_sec_qos(&qos
, 2, 1, 0);
61 init_q_open_pol(&q
, '\\', 0, des_access
, &qos
);
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
,
73 NT_STATUS_UNSUCCESSFUL
);
75 /* Return output parameters */
79 if (NT_STATUS_IS_OK(result
)) {
82 pol
->marker
= MALLOC(1);
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
;
103 char *srv_name_slash
= talloc_asprintf(mem_ctx
, "\\\\%s", cli
->cli
->desthost
);
109 init_lsa_sec_qos(&qos
, 2, 1, 0);
110 init_q_open_pol2(&q
, srv_name_slash
, 0, des_access
, &qos
);
112 init_q_open_pol2(&q
, srv_name_slash
, 0, des_access
, NULL
);
115 CLI_DO_RPC( cli
, mem_ctx
, PI_LSARPC
, LSA_OPENPOLICY2
,
120 NT_STATUS_UNSUCCESSFUL
);
122 /* Return output parameters */
126 if (NT_STATUS_IS_OK(result
)) {
129 pol
->marker
= (char *)malloc(1);
136 /** Close a LSA policy handle */
138 NTSTATUS
rpccli_lsa_close(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
141 prs_struct qbuf
, rbuf
;
149 init_lsa_q_close(&q
, pol
);
151 CLI_DO_RPC( cli
, mem_ctx
, PI_LSARPC
, LSA_CLOSE
,
156 NT_STATUS_UNSUCCESSFUL
);
158 /* Return output parameters */
162 if (NT_STATUS_IS_OK(result
)) {
164 SAFE_FREE(pol
->marker
);
172 /** Lookup a list of sids */
174 NTSTATUS
rpccli_lsa_lookup_sids(struct rpc_pipe_client
*cli
,
176 POLICY_HND
*pol
, int num_sids
,
178 char ***domains
, char ***names
, uint32
**types
)
180 prs_struct qbuf
, rbuf
;
184 NTSTATUS result
= NT_STATUS_OK
;
190 init_q_lookup_sids(mem_ctx
, &q
, pol
, num_sids
, sids
, 1);
196 CLI_DO_RPC( cli
, mem_ctx
, PI_LSARPC
, LSA_LOOKUPSIDS
,
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 */
212 /* Return output parameters */
214 if (r
.mapped_count
== 0) {
215 result
= NT_STATUS_NONE_MAPPED
;
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
;
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
;
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
;
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
;
268 (*domains
)[i
] = NULL
;
269 (*types
)[i
] = SID_NAME_UNKNOWN
;
278 /** Lookup a list of names */
280 NTSTATUS
rpccli_lsa_lookup_names(struct rpc_pipe_client
*cli
,
282 POLICY_HND
*pol
, int num_names
,
284 const char ***dom_names
,
288 prs_struct qbuf
, rbuf
;
289 LSA_Q_LOOKUP_NAMES q
;
290 LSA_R_LOOKUP_NAMES r
;
301 init_q_lookup_names(mem_ctx
, &q
, pol
, num_names
, names
);
303 CLI_DO_RPC( cli
, mem_ctx
, PI_LSARPC
, LSA_LOOKUPNAMES
,
306 lsa_io_q_lookup_names
,
307 lsa_io_r_lookup_names
,
308 NT_STATUS_UNSUCCESSFUL
);
312 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
313 NT_STATUS_V(STATUS_SOME_UNMAPPED
)) {
315 /* An actual error occured */
320 /* Return output parameters */
322 if (r
.mapped_count
== 0) {
323 result
= NT_STATUS_NONE_MAPPED
;
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
;
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
;
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
;
351 if (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 */
367 (*types
)[i
] = SID_NAME_UNKNOWN
;
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
) {
383 (*dom_names
)[i
] = rpcstr_pull_unistr2_talloc(
384 *dom_names
, &ref
.ref_dom
[dom_idx
].uni_dom_name
);
392 NTSTATUS
rpccli_lsa_query_info_policy_new(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
393 POLICY_HND
*pol
, uint16 info_class
,
396 prs_struct qbuf
, rbuf
;
404 init_q_query(&q
, pol
, info_class
);
406 CLI_DO_RPC(cli
, mem_ctx
, PI_LSARPC
, LSA_QUERYINFOPOLICY
,
411 NT_STATUS_UNSUCCESSFUL
);
415 if (!NT_STATUS_IS_OK(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
,
430 prs_struct qbuf
, rbuf
;
438 init_q_query2(&q
, pol
, info_class
);
440 CLI_DO_RPC(cli
, mem_ctx
, PI_LSARPC
, LSA_QUERYINFO2
,
443 lsa_io_q_query_info2
,
444 lsa_io_r_query_info2
,
445 NT_STATUS_UNSUCCESSFUL
);
449 if (!NT_STATUS_IS_OK(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
,
468 POLICY_HND
*pol
, uint16 info_class
,
469 char **domain_name
, DOM_SID
**domain_sid
)
471 prs_struct qbuf
, rbuf
;
479 init_q_query(&q
, pol
, info_class
);
481 CLI_DO_RPC(cli
, mem_ctx
, PI_LSARPC
, LSA_QUERYINFOPOLICY
,
486 NT_STATUS_UNSUCCESSFUL
);
490 if (!NT_STATUS_IS_OK(result
)) {
494 /* Return output parameters */
496 switch (info_class
) {
499 if (domain_name
&& (r
.ctr
.info
.id3
.buffer_dom_name
!= 0)) {
500 *domain_name
= unistr2_tdup(mem_ctx
,
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
);
511 return NT_STATUS_NO_MEMORY
;
513 sid_copy(*domain_sid
, &r
.ctr
.info
.id3
.dom_sid
.sid
);
520 if (domain_name
&& (r
.ctr
.info
.id5
.buffer_dom_name
!= 0)) {
521 *domain_name
= unistr2_tdup(mem_ctx
,
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
);
532 return NT_STATUS_NO_MEMORY
;
534 sid_copy(*domain_sid
, &r
.ctr
.info
.id5
.dom_sid
.sid
);
539 DEBUG(3, ("unknown info class %d\n", info_class
));
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
,
558 POLICY_HND
*pol
, uint16 info_class
,
559 char **domain_name
, char **dns_name
,
561 struct GUID
**domain_guid
,
562 DOM_SID
**domain_sid
)
564 prs_struct qbuf
, rbuf
;
567 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
569 if (info_class
!= 12)
575 init_q_query2(&q
, pol
, info_class
);
577 CLI_DO_RPC( cli
, mem_ctx
, PI_LSARPC
, LSA_QUERYINFO2
,
580 lsa_io_q_query_info2
,
581 lsa_io_r_query_info2
,
582 NT_STATUS_UNSUCCESSFUL
);
586 if (!NT_STATUS_IS_OK(result
)) {
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
,
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
,
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
,
615 return NT_STATUS_NO_MEMORY
;
620 *domain_guid
= TALLOC_P(mem_ctx
, struct GUID
);
622 return NT_STATUS_NO_MEMORY
;
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
);
632 return NT_STATUS_NO_MEMORY
;
634 sid_copy(*domain_sid
,
635 &r
.ctr
.info
.id12
.dom_sid
.sid
);
643 NTSTATUS
rpccli_lsa_set_info_policy(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
644 POLICY_HND
*pol
, uint16 info_class
,
647 prs_struct qbuf
, rbuf
;
655 init_q_set(&q
, pol
, info_class
, ctr
);
657 CLI_DO_RPC(cli
, mem_ctx
, PI_LSARPC
, LSA_SETINFOPOLICY
,
662 NT_STATUS_UNSUCCESSFUL
);
666 if (!NT_STATUS_IS_OK(result
)) {
670 /* Return output parameters */
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
,
695 POLICY_HND
*pol
, uint32
*enum_ctx
,
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
;
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
,
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
) )
729 /* Return output parameters */
731 *num_domains
= out
.count
;
732 *enum_ctx
= out
.enum_context
;
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
);
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
;
778 init_q_enum_privs(&q
, pol
, *enum_context
, pref_max_length
);
780 CLI_DO_RPC( cli
, mem_ctx
, PI_LSARPC
, LSA_ENUM_PRIVS
,
785 NT_STATUS_UNSUCCESSFUL
);
789 if (!NT_STATUS_IS_OK(result
)) {
793 /* Return output parameters */
795 *enum_context
= r
.enum_context
;
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
;
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
;
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
;
822 for (i
= 0; i
< r
.count
; i
++) {
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
;
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
;
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
,
858 lsa_io_q_priv_get_dispname
,
859 lsa_io_r_priv_get_dispname
,
860 NT_STATUS_UNSUCCESSFUL
);
864 if (!NT_STATUS_IS_OK(result
)) {
868 /* Return output parameters */
870 rpcstr_pull_unistr2_fstring(description
, &r
.desc
);
871 *lang_id_desc
= r
.lang_id
;
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
;
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
,
898 lsa_io_q_enum_accounts
,
899 lsa_io_r_enum_accounts
,
900 NT_STATUS_UNSUCCESSFUL
);
904 if (!NT_STATUS_IS_OK(result
)) {
908 if (r
.sids
.num_entries
==0)
911 /* Return output parameters */
913 *sids
= TALLOC_ARRAY(mem_ctx
, DOM_SID
, r
.sids
.num_entries
);
915 DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
916 result
= NT_STATUS_UNSUCCESSFUL
;
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
;
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
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
;
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
,
962 lsa_io_q_create_account
,
963 lsa_io_r_create_account
,
964 NT_STATUS_UNSUCCESSFUL
);
966 /* Return output parameters */
970 if (NT_STATUS_IS_OK(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
;
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
,
1000 lsa_io_q_open_account
,
1001 lsa_io_r_open_account
,
1002 NT_STATUS_UNSUCCESSFUL
);
1004 /* Return output parameters */
1008 if (NT_STATUS_IS_OK(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
;
1031 /* Initialise input parameters */
1033 init_lsa_q_enum_privsaccount(&q
, pol
);
1035 CLI_DO_RPC( cli
, mem_ctx
, PI_LSARPC
, LSA_ENUMPRIVSACCOUNT
,
1038 lsa_io_q_enum_privsaccount
,
1039 lsa_io_r_enum_privsaccount
,
1040 NT_STATUS_UNSUCCESSFUL
);
1042 /* Return output parameters */
1046 if (!NT_STATUS_IS_OK(result
)) {
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
;
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
;
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
;
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
,
1091 lsa_io_q_lookup_priv_value
,
1092 lsa_io_r_lookup_priv_value
,
1093 NT_STATUS_UNSUCCESSFUL
);
1097 if (!NT_STATUS_IS_OK(result
)) {
1101 /* Return output parameters */
1103 (*luid
).low
=r
.luid
.low
;
1104 (*luid
).high
=r
.luid
.high
;
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
;
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
,
1132 lsa_io_q_query_sec_obj
,
1133 lsa_io_r_query_sec_obj
,
1134 NT_STATUS_UNSUCCESSFUL
);
1138 if (!NT_STATUS_IS_OK(result
)) {
1142 /* Return output parameters */
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
;
1166 fstring
*privileges
;
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
,
1178 lsa_io_q_enum_acct_rights
,
1179 lsa_io_r_enum_acct_rights
,
1180 NT_STATUS_UNSUCCESSFUL
);
1184 if (!NT_STATUS_IS_OK(result
)) {
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
);
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
)
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
;
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
;
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
,
1244 lsa_io_q_add_acct_rights
,
1245 lsa_io_r_add_acct_rights
,
1246 NT_STATUS_UNSUCCESSFUL
);
1250 if (!NT_STATUS_IS_OK(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
;
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
,
1279 lsa_io_q_remove_acct_rights
,
1280 lsa_io_r_remove_acct_rights
,
1281 NT_STATUS_UNSUCCESSFUL
);
1285 if (!NT_STATUS_IS_OK(result
)) {
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
;
1308 if(cli_initialise(&cli
) == False
) {
1309 DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
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
));
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
) ));
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",
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
) ));
1338 if (cli
.protocol
!= PROTOCOL_NT1
) {
1339 DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
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
) ));
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",
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
) ));
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"));
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
) ));
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
) ));
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
;
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
,
1418 lsa_io_q_open_trusted_domain
,
1419 lsa_io_r_open_trusted_domain
,
1420 NT_STATUS_UNSUCCESSFUL
);
1422 /* Return output parameters */
1426 if (NT_STATUS_IS_OK(result
)) {
1427 *trustdom_pol
= r
.handle
;
1433 NTSTATUS
rpccli_lsa_query_trusted_domain_info(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
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
;
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
,
1453 lsa_io_q_query_trusted_domain_info
,
1454 lsa_io_r_query_trusted_domain_info
,
1455 NT_STATUS_UNSUCCESSFUL
);
1459 if (!NT_STATUS_IS_OK(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
;
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
,
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 */
1498 if (NT_STATUS_IS_OK(result
)) {
1499 *trustdom_pol
= r
.handle
;
1506 NTSTATUS
rpccli_lsa_query_trusted_domain_info_by_sid(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
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
;
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
,
1526 lsa_io_q_query_trusted_domain_info_by_sid
,
1527 lsa_io_r_query_trusted_domain_info
,
1528 NT_STATUS_UNSUCCESSFUL
);
1532 if (!NT_STATUS_IS_OK(result
)) {
1543 NTSTATUS
rpccli_lsa_query_trusted_domain_info_by_name(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
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
;
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
,
1563 lsa_io_q_query_trusted_domain_info_by_name
,
1564 lsa_io_r_query_trusted_domain_info
,
1565 NT_STATUS_UNSUCCESSFUL
);
1569 if (!NT_STATUS_IS_OK(result
)) {
1580 NTSTATUS
cli_lsa_query_domain_info_policy(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
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
;
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
,
1599 lsa_io_q_query_dom_info
,
1600 lsa_io_r_query_dom_info
,
1601 NT_STATUS_UNSUCCESSFUL
);
1605 if (!NT_STATUS_IS_OK(result
)) {