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,
180 enum lsa_SidType **types)
182 prs_struct qbuf, rbuf;
186 LSA_TRANS_NAME_ENUM t_names;
187 NTSTATUS result = NT_STATUS_OK;
193 init_q_lookup_sids(mem_ctx, &q, pol, num_sids, sids, 1);
196 ZERO_STRUCT(t_names);
201 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPSIDS,
204 lsa_io_q_lookup_sids,
205 lsa_io_r_lookup_sids,
206 NT_STATUS_UNSUCCESSFUL );
208 if (!NT_STATUS_IS_OK(r.status) &&
209 NT_STATUS_V(r.status) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
211 /* An actual error occured */
217 /* Return output parameters */
219 if (r.mapped_count == 0) {
220 result = NT_STATUS_NONE_MAPPED;
224 if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
225 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
226 result = NT_STATUS_NO_MEMORY;
230 if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
231 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
232 result = NT_STATUS_NO_MEMORY;
236 if (!((*types) = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_sids))) {
237 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
238 result = NT_STATUS_NO_MEMORY;
242 for (i = 0; i < num_sids; i++) {
243 fstring name, dom_name;
244 uint32 dom_idx = t_names.name[i].domain_idx;
246 /* Translate optimised name through domain index array */
248 if (dom_idx != 0xffffffff) {
250 rpcstr_pull_unistr2_fstring(
251 dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
252 rpcstr_pull_unistr2_fstring(
253 name, &t_names.uni_name[i]);
255 (*names)[i] = talloc_strdup(mem_ctx, name);
256 (*domains)[i] = talloc_strdup(mem_ctx, dom_name);
257 (*types)[i] = (enum lsa_SidType)t_names.name[i].sid_name_use;
259 if (((*names)[i] == NULL) || ((*domains)[i] == NULL)) {
260 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
261 result = NT_STATUS_UNSUCCESSFUL;
267 (*domains)[i] = NULL;
268 (*types)[i] = SID_NAME_UNKNOWN;
277 /** Lookup a list of names */
279 NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
281 POLICY_HND *pol, int num_names,
283 const char ***dom_names,
285 enum lsa_SidType **types)
287 prs_struct qbuf, rbuf;
288 LSA_Q_LOOKUP_NAMES q;
289 LSA_R_LOOKUP_NAMES r;
300 init_q_lookup_names(mem_ctx, &q, pol, num_names, names);
302 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPNAMES,
305 lsa_io_q_lookup_names,
306 lsa_io_r_lookup_names,
307 NT_STATUS_UNSUCCESSFUL);
311 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
312 NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
314 /* An actual error occured */
319 /* Return output parameters */
321 if (r.mapped_count == 0) {
322 result = NT_STATUS_NONE_MAPPED;
326 if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
327 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
328 result = NT_STATUS_NO_MEMORY;
332 if (!((*types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_names)))) {
333 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
334 result = NT_STATUS_NO_MEMORY;
338 if (dom_names != NULL) {
339 *dom_names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
340 if (*dom_names == NULL) {
341 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
342 result = NT_STATUS_NO_MEMORY;
347 for (i = 0; i < num_names; i++) {
348 DOM_RID *t_rids = r.dom_rid;
349 uint32 dom_idx = t_rids[i].rid_idx;
350 uint32 dom_rid = t_rids[i].rid;
351 DOM_SID *sid = &(*sids)[i];
353 /* Translate optimised sid through domain index array */
355 if (dom_idx == 0xffffffff) {
356 /* Nothing to do, this is unknown */
358 (*types)[i] = SID_NAME_UNKNOWN;
362 sid_copy(sid, &ref.ref_dom[dom_idx].ref_dom.sid);
364 if (dom_rid != 0xffffffff) {
365 sid_append_rid(sid, dom_rid);
368 (*types)[i] = (enum lsa_SidType)t_rids[i].type;
370 if (dom_names == NULL) {
374 (*dom_names)[i] = rpcstr_pull_unistr2_talloc(
375 *dom_names, &ref.ref_dom[dom_idx].uni_dom_name);
383 NTSTATUS rpccli_lsa_query_info_policy_new(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
384 POLICY_HND *pol, uint16 info_class,
387 prs_struct qbuf, rbuf;
395 init_q_query(&q, pol, info_class);
397 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_QUERYINFOPOLICY,
402 NT_STATUS_UNSUCCESSFUL);
406 if (!NT_STATUS_IS_OK(result)) {
417 NTSTATUS rpccli_lsa_query_info_policy2_new(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
418 POLICY_HND *pol, uint16 info_class,
421 prs_struct qbuf, rbuf;
429 init_q_query2(&q, pol, info_class);
431 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_QUERYINFO2,
434 lsa_io_q_query_info2,
435 lsa_io_r_query_info2,
436 NT_STATUS_UNSUCCESSFUL);
440 if (!NT_STATUS_IS_OK(result)) {
453 /** Query info policy
455 * @param domain_sid - returned remote server's domain sid */
457 NTSTATUS rpccli_lsa_query_info_policy(struct rpc_pipe_client *cli,
459 POLICY_HND *pol, uint16 info_class,
460 char **domain_name, DOM_SID **domain_sid)
462 prs_struct qbuf, rbuf;
470 init_q_query(&q, pol, info_class);
472 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_QUERYINFOPOLICY,
477 NT_STATUS_UNSUCCESSFUL);
481 if (!NT_STATUS_IS_OK(result)) {
485 /* Return output parameters */
487 switch (info_class) {
490 if (domain_name && (r.ctr.info.id3.buffer_dom_name != 0)) {
491 *domain_name = unistr2_tdup(mem_ctx,
495 return NT_STATUS_NO_MEMORY;
499 if (domain_sid && (r.ctr.info.id3.buffer_dom_sid != 0)) {
500 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
502 return NT_STATUS_NO_MEMORY;
504 sid_copy(*domain_sid, &r.ctr.info.id3.dom_sid.sid);
511 if (domain_name && (r.ctr.info.id5.buffer_dom_name != 0)) {
512 *domain_name = unistr2_tdup(mem_ctx,
516 return NT_STATUS_NO_MEMORY;
520 if (domain_sid && (r.ctr.info.id5.buffer_dom_sid != 0)) {
521 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
523 return NT_STATUS_NO_MEMORY;
525 sid_copy(*domain_sid, &r.ctr.info.id5.dom_sid.sid);
530 DEBUG(3, ("unknown info class %d\n", info_class));
539 /** Query info policy2
541 * @param domain_name - returned remote server's domain name
542 * @param dns_name - returned remote server's dns domain name
543 * @param forest_name - returned remote server's forest name
544 * @param domain_guid - returned remote server's domain guid
545 * @param domain_sid - returned remote server's domain sid */
547 NTSTATUS rpccli_lsa_query_info_policy2(struct rpc_pipe_client *cli,
549 POLICY_HND *pol, uint16 info_class,
550 char **domain_name, char **dns_name,
552 struct uuid **domain_guid,
553 DOM_SID **domain_sid)
555 prs_struct qbuf, rbuf;
558 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
560 if (info_class != 12)
566 init_q_query2(&q, pol, info_class);
568 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYINFO2,
571 lsa_io_q_query_info2,
572 lsa_io_r_query_info2,
573 NT_STATUS_UNSUCCESSFUL);
577 if (!NT_STATUS_IS_OK(result)) {
581 /* Return output parameters */
583 ZERO_STRUCTP(domain_guid);
585 if (domain_name && r.ctr.info.id12.hdr_nb_dom_name.buffer) {
586 *domain_name = unistr2_tdup(mem_ctx,
590 return NT_STATUS_NO_MEMORY;
593 if (dns_name && r.ctr.info.id12.hdr_dns_dom_name.buffer) {
594 *dns_name = unistr2_tdup(mem_ctx,
598 return NT_STATUS_NO_MEMORY;
601 if (forest_name && r.ctr.info.id12.hdr_forest_name.buffer) {
602 *forest_name = unistr2_tdup(mem_ctx,
606 return NT_STATUS_NO_MEMORY;
611 *domain_guid = TALLOC_P(mem_ctx, struct uuid);
613 return NT_STATUS_NO_MEMORY;
616 &r.ctr.info.id12.dom_guid,
617 sizeof(struct uuid));
620 if (domain_sid && r.ctr.info.id12.ptr_dom_sid != 0) {
621 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
623 return NT_STATUS_NO_MEMORY;
625 sid_copy(*domain_sid,
626 &r.ctr.info.id12.dom_sid.sid);
634 NTSTATUS rpccli_lsa_set_info_policy(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
635 POLICY_HND *pol, uint16 info_class,
638 prs_struct qbuf, rbuf;
646 init_q_set(&q, pol, info_class, ctr);
648 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_SETINFOPOLICY,
653 NT_STATUS_UNSUCCESSFUL);
657 if (!NT_STATUS_IS_OK(result)) {
661 /* Return output parameters */
670 * Enumerate list of trusted domains
672 * @param cli client state (cli_state) structure of the connection
673 * @param mem_ctx memory context
674 * @param pol opened lsa policy handle
675 * @param enum_ctx enumeration context ie. index of first returned domain entry
676 * @param pref_num_domains preferred max number of entries returned in one response
677 * @param num_domains total number of trusted domains returned by response
678 * @param domain_names returned trusted domain names
679 * @param domain_sids returned trusted domain sids
681 * @return nt status code of response
684 NTSTATUS rpccli_lsa_enum_trust_dom(struct rpc_pipe_client *cli,
686 POLICY_HND *pol, uint32 *enum_ctx,
688 char ***domain_names, DOM_SID **domain_sids)
690 prs_struct qbuf, rbuf;
691 LSA_Q_ENUM_TRUST_DOM in;
692 LSA_R_ENUM_TRUST_DOM out;
699 /* 64k is enough for about 2000 trusted domains */
701 init_q_enum_trust_dom(&in, pol, *enum_ctx, 0x10000);
703 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMTRUSTDOM,
706 lsa_io_q_enum_trust_dom,
707 lsa_io_r_enum_trust_dom,
708 NT_STATUS_UNSUCCESSFUL );
711 /* check for an actual error */
713 if ( !NT_STATUS_IS_OK(out.status)
714 && !NT_STATUS_EQUAL(out.status, NT_STATUS_NO_MORE_ENTRIES)
715 && !NT_STATUS_EQUAL(out.status, STATUS_MORE_ENTRIES) )
720 /* Return output parameters */
722 *num_domains = out.count;
723 *enum_ctx = out.enum_context;
727 /* Allocate memory for trusted domain names and sids */
729 if ( !(*domain_names = TALLOC_ARRAY(mem_ctx, char *, out.count)) ) {
730 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
731 return NT_STATUS_NO_MEMORY;
734 if ( !(*domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, out.count)) ) {
735 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
736 return NT_STATUS_NO_MEMORY;
739 /* Copy across names and sids */
741 for (i = 0; i < out.count; i++) {
743 rpcstr_pull( tmp, out.domlist->domains[i].name.string->buffer,
744 sizeof(tmp), out.domlist->domains[i].name.length, 0);
745 (*domain_names)[i] = talloc_strdup(mem_ctx, tmp);
747 sid_copy(&(*domain_sids)[i], &out.domlist->domains[i].sid->sid );
754 /** Enumerate privileges*/
756 NTSTATUS rpccli_lsa_enum_privilege(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
757 POLICY_HND *pol, uint32 *enum_context, uint32 pref_max_length,
758 uint32 *count, char ***privs_name, uint32 **privs_high, uint32 **privs_low)
760 prs_struct qbuf, rbuf;
769 init_q_enum_privs(&q, pol, *enum_context, pref_max_length);
771 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUM_PRIVS,
776 NT_STATUS_UNSUCCESSFUL);
780 if (!NT_STATUS_IS_OK(result)) {
784 /* Return output parameters */
786 *enum_context = r.enum_context;
789 if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
790 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
791 result = NT_STATUS_UNSUCCESSFUL;
795 if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
796 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
797 result = NT_STATUS_UNSUCCESSFUL;
801 if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
802 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
803 result = NT_STATUS_UNSUCCESSFUL;
807 for (i = 0; i < r.count; i++) {
810 rpcstr_pull_unistr2_fstring( name, &r.privs[i].name);
812 (*privs_name)[i] = talloc_strdup(mem_ctx, name);
814 (*privs_high)[i] = r.privs[i].luid_high;
815 (*privs_low)[i] = r.privs[i].luid_low;
823 /** Get privilege name */
825 NTSTATUS rpccli_lsa_get_dispname(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
826 POLICY_HND *pol, const char *name,
827 uint16 lang_id, uint16 lang_id_sys,
828 fstring description, uint16 *lang_id_desc)
830 prs_struct qbuf, rbuf;
831 LSA_Q_PRIV_GET_DISPNAME q;
832 LSA_R_PRIV_GET_DISPNAME r;
838 init_lsa_priv_get_dispname(&q, pol, name, lang_id, lang_id_sys);
840 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_PRIV_GET_DISPNAME,
843 lsa_io_q_priv_get_dispname,
844 lsa_io_r_priv_get_dispname,
845 NT_STATUS_UNSUCCESSFUL);
849 if (!NT_STATUS_IS_OK(result)) {
853 /* Return output parameters */
855 rpcstr_pull_unistr2_fstring(description , &r.desc);
856 *lang_id_desc = r.lang_id;
863 /** Enumerate list of SIDs */
865 NTSTATUS rpccli_lsa_enum_sids(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
866 POLICY_HND *pol, uint32 *enum_ctx, uint32 pref_max_length,
867 uint32 *num_sids, DOM_SID **sids)
869 prs_struct qbuf, rbuf;
870 LSA_Q_ENUM_ACCOUNTS q;
871 LSA_R_ENUM_ACCOUNTS r;
878 init_lsa_q_enum_accounts(&q, pol, *enum_ctx, pref_max_length);
880 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUM_ACCOUNTS,
883 lsa_io_q_enum_accounts,
884 lsa_io_r_enum_accounts,
885 NT_STATUS_UNSUCCESSFUL);
889 if (!NT_STATUS_IS_OK(result)) {
893 if (r.sids.num_entries==0)
896 /* Return output parameters */
898 *sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.sids.num_entries);
900 DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
901 result = NT_STATUS_UNSUCCESSFUL;
905 /* Copy across names and sids */
907 for (i = 0; i < r.sids.num_entries; i++) {
908 sid_copy(&(*sids)[i], &r.sids.sid[i].sid);
911 *num_sids= r.sids.num_entries;
912 *enum_ctx = r.enum_context;
919 /** Create a LSA user handle
921 * @param cli Handle on an initialised SMB connection
923 * FIXME: The code is actually identical to open account
924 * TODO: Check and code what the function should exactly do
928 NTSTATUS rpccli_lsa_create_account(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
929 POLICY_HND *dom_pol, DOM_SID *sid, uint32 desired_access,
930 POLICY_HND *user_pol)
932 prs_struct qbuf, rbuf;
933 LSA_Q_CREATEACCOUNT q;
934 LSA_R_CREATEACCOUNT r;
940 /* Initialise input parameters */
942 init_lsa_q_create_account(&q, dom_pol, sid, desired_access);
944 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_CREATEACCOUNT,
947 lsa_io_q_create_account,
948 lsa_io_r_create_account,
949 NT_STATUS_UNSUCCESSFUL);
951 /* Return output parameters */
955 if (NT_STATUS_IS_OK(result)) {
962 /** Open a LSA user handle
964 * @param cli Handle on an initialised SMB connection */
966 NTSTATUS rpccli_lsa_open_account(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
967 POLICY_HND *dom_pol, DOM_SID *sid, uint32 des_access,
968 POLICY_HND *user_pol)
970 prs_struct qbuf, rbuf;
978 /* Initialise input parameters */
980 init_lsa_q_open_account(&q, dom_pol, sid, des_access);
982 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENACCOUNT,
985 lsa_io_q_open_account,
986 lsa_io_r_open_account,
987 NT_STATUS_UNSUCCESSFUL);
989 /* Return output parameters */
993 if (NT_STATUS_IS_OK(result)) {
1000 /** Enumerate user privileges
1002 * @param cli Handle on an initialised SMB connection */
1004 NTSTATUS rpccli_lsa_enum_privsaccount(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1005 POLICY_HND *pol, uint32 *count, LUID_ATTR **set)
1007 prs_struct qbuf, rbuf;
1008 LSA_Q_ENUMPRIVSACCOUNT q;
1009 LSA_R_ENUMPRIVSACCOUNT r;
1016 /* Initialise input parameters */
1018 init_lsa_q_enum_privsaccount(&q, pol);
1020 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMPRIVSACCOUNT,
1023 lsa_io_q_enum_privsaccount,
1024 lsa_io_r_enum_privsaccount,
1025 NT_STATUS_UNSUCCESSFUL);
1027 /* Return output parameters */
1031 if (!NT_STATUS_IS_OK(result)) {
1038 if (!((*set = TALLOC_ARRAY(mem_ctx, LUID_ATTR, r.count)))) {
1039 DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
1040 result = NT_STATUS_UNSUCCESSFUL;
1044 for (i=0; i<r.count; i++) {
1045 (*set)[i].luid.low = r.set.set[i].luid.low;
1046 (*set)[i].luid.high = r.set.set[i].luid.high;
1047 (*set)[i].attr = r.set.set[i].attr;
1056 /** Get a privilege value given its name */
1058 NTSTATUS rpccli_lsa_lookup_priv_value(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1059 POLICY_HND *pol, const char *name, LUID *luid)
1061 prs_struct qbuf, rbuf;
1062 LSA_Q_LOOKUP_PRIV_VALUE q;
1063 LSA_R_LOOKUP_PRIV_VALUE r;
1069 /* Marshall data and send request */
1071 init_lsa_q_lookup_priv_value(&q, pol, name);
1073 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPPRIVVALUE,
1076 lsa_io_q_lookup_priv_value,
1077 lsa_io_r_lookup_priv_value,
1078 NT_STATUS_UNSUCCESSFUL);
1082 if (!NT_STATUS_IS_OK(result)) {
1086 /* Return output parameters */
1088 (*luid).low=r.luid.low;
1089 (*luid).high=r.luid.high;
1096 /** Query LSA security object */
1098 NTSTATUS rpccli_lsa_query_secobj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1099 POLICY_HND *pol, uint32 sec_info,
1100 SEC_DESC_BUF **psdb)
1102 prs_struct qbuf, rbuf;
1103 LSA_Q_QUERY_SEC_OBJ q;
1104 LSA_R_QUERY_SEC_OBJ r;
1110 /* Marshall data and send request */
1112 init_q_query_sec_obj(&q, pol, sec_info);
1114 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYSECOBJ,
1117 lsa_io_q_query_sec_obj,
1118 lsa_io_r_query_sec_obj,
1119 NT_STATUS_UNSUCCESSFUL);
1123 if (!NT_STATUS_IS_OK(result)) {
1127 /* Return output parameters */
1138 /* Enumerate account rights This is similar to enum_privileges but
1139 takes a SID directly, avoiding the open_account call.
1142 NTSTATUS rpccli_lsa_enum_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1143 POLICY_HND *pol, DOM_SID *sid,
1144 uint32 *count, char ***priv_names)
1146 prs_struct qbuf, rbuf;
1147 LSA_Q_ENUM_ACCT_RIGHTS q;
1148 LSA_R_ENUM_ACCT_RIGHTS r;
1151 fstring *privileges;
1157 /* Marshall data and send request */
1158 init_q_enum_acct_rights(&q, pol, 2, sid);
1160 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMACCTRIGHTS,
1163 lsa_io_q_enum_acct_rights,
1164 lsa_io_r_enum_acct_rights,
1165 NT_STATUS_UNSUCCESSFUL);
1169 if (!NT_STATUS_IS_OK(result)) {
1179 privileges = TALLOC_ARRAY( mem_ctx, fstring, *count );
1180 names = TALLOC_ARRAY( mem_ctx, char *, *count );
1182 if ((privileges == NULL) || (names == NULL)) {
1183 TALLOC_FREE(privileges);
1185 return NT_STATUS_NO_MEMORY;
1188 for ( i=0; i<*count; i++ ) {
1189 UNISTR4 *uni_string = &r.rights->strings[i];
1191 if ( !uni_string->string )
1194 rpcstr_pull( privileges[i], uni_string->string->buffer, sizeof(privileges[i]), -1, STR_TERMINATE );
1196 /* now copy to the return array */
1197 names[i] = talloc_strdup( mem_ctx, privileges[i] );
1200 *priv_names = names;
1209 /* add account rights to an account. */
1211 NTSTATUS rpccli_lsa_add_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1212 POLICY_HND *pol, DOM_SID sid,
1213 uint32 count, const char **privs_name)
1215 prs_struct qbuf, rbuf;
1216 LSA_Q_ADD_ACCT_RIGHTS q;
1217 LSA_R_ADD_ACCT_RIGHTS r;
1223 /* Marshall data and send request */
1224 init_q_add_acct_rights(&q, pol, &sid, count, privs_name);
1226 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ADDACCTRIGHTS,
1229 lsa_io_q_add_acct_rights,
1230 lsa_io_r_add_acct_rights,
1231 NT_STATUS_UNSUCCESSFUL);
1235 if (!NT_STATUS_IS_OK(result)) {
1244 /* remove account rights for an account. */
1246 NTSTATUS rpccli_lsa_remove_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1247 POLICY_HND *pol, DOM_SID sid, BOOL removeall,
1248 uint32 count, const char **privs_name)
1250 prs_struct qbuf, rbuf;
1251 LSA_Q_REMOVE_ACCT_RIGHTS q;
1252 LSA_R_REMOVE_ACCT_RIGHTS r;
1258 /* Marshall data and send request */
1259 init_q_remove_acct_rights(&q, pol, &sid, removeall?1:0, count, privs_name);
1261 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_REMOVEACCTRIGHTS,
1264 lsa_io_q_remove_acct_rights,
1265 lsa_io_r_remove_acct_rights,
1266 NT_STATUS_UNSUCCESSFUL);
1270 if (!NT_STATUS_IS_OK(result)) {
1281 /** An example of how to use the routines in this file. Fetch a DOMAIN
1282 sid. Does complete cli setup / teardown anonymously. */
1284 BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid)
1286 extern pstring global_myname;
1287 struct cli_state *cli;
1293 if((cli = cli_initialise()) == NULL) {
1294 DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
1298 if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
1299 DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
1303 if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
1304 DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
1305 machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
1309 if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
1310 DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
1315 cli->protocol = PROTOCOL_NT1;
1317 if (!cli_negprot(cli)) {
1318 DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \
1319 Error was : %s.\n", remote_machine, cli_errstr(cli) ));
1323 if (cli->protocol != PROTOCOL_NT1) {
1324 DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
1330 * Do an anonymous session setup.
1333 if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
1334 DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \
1335 Error was : %s.\n", remote_machine, cli_errstr(cli) ));
1339 if (!(cli->sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
1340 DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n",
1345 if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
1346 DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \
1347 Error was : %s.\n", remote_machine, cli_errstr(cli) ));
1351 /* Fetch domain sid */
1353 if (!cli_nt_session_open(cli, PI_LSARPC)) {
1354 DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n"));
1358 result = cli_lsa_open_policy(cli, cli->mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
1359 if (!NT_STATUS_IS_OK(result)) {
1360 DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n",
1361 nt_errstr(result) ));
1365 result = cli_lsa_query_info_policy(cli, cli->mem_ctx, &lsa_pol, 5, domain, psid);
1366 if (!NT_STATUS_IS_OK(result)) {
1367 DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n",
1368 nt_errstr(result) ));
1382 NTSTATUS rpccli_lsa_open_trusted_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1383 POLICY_HND *pol, DOM_SID *dom_sid, uint32 access_mask,
1384 POLICY_HND *trustdom_pol)
1386 prs_struct qbuf, rbuf;
1387 LSA_Q_OPEN_TRUSTED_DOMAIN q;
1388 LSA_R_OPEN_TRUSTED_DOMAIN r;
1394 /* Initialise input parameters */
1396 init_lsa_q_open_trusted_domain(&q, pol, dom_sid, access_mask);
1398 /* Marshall data and send request */
1400 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENTRUSTDOM,
1403 lsa_io_q_open_trusted_domain,
1404 lsa_io_r_open_trusted_domain,
1405 NT_STATUS_UNSUCCESSFUL);
1407 /* Return output parameters */
1411 if (NT_STATUS_IS_OK(result)) {
1412 *trustdom_pol = r.handle;
1418 NTSTATUS rpccli_lsa_query_trusted_domain_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1421 LSA_TRUSTED_DOMAIN_INFO **info)
1423 prs_struct qbuf, rbuf;
1424 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO q;
1425 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1426 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1431 /* Marshall data and send request */
1433 init_q_query_trusted_domain_info(&q, pol, info_class);
1435 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFO,
1438 lsa_io_q_query_trusted_domain_info,
1439 lsa_io_r_query_trusted_domain_info,
1440 NT_STATUS_UNSUCCESSFUL);
1444 if (!NT_STATUS_IS_OK(result)) {
1454 NTSTATUS rpccli_lsa_open_trusted_domain_by_name(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1455 POLICY_HND *pol, const char *name, uint32 access_mask,
1456 POLICY_HND *trustdom_pol)
1458 prs_struct qbuf, rbuf;
1459 LSA_Q_OPEN_TRUSTED_DOMAIN_BY_NAME q;
1460 LSA_R_OPEN_TRUSTED_DOMAIN_BY_NAME r;
1466 /* Initialise input parameters */
1468 init_lsa_q_open_trusted_domain_by_name(&q, pol, name, access_mask);
1470 /* Marshall data and send request */
1472 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENTRUSTDOMBYNAME,
1475 lsa_io_q_open_trusted_domain_by_name,
1476 lsa_io_r_open_trusted_domain_by_name,
1477 NT_STATUS_UNSUCCESSFUL);
1479 /* Return output parameters */
1483 if (NT_STATUS_IS_OK(result)) {
1484 *trustdom_pol = r.handle;
1491 NTSTATUS rpccli_lsa_query_trusted_domain_info_by_sid(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1493 uint16 info_class, DOM_SID *dom_sid,
1494 LSA_TRUSTED_DOMAIN_INFO **info)
1496 prs_struct qbuf, rbuf;
1497 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID q;
1498 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1499 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1504 /* Marshall data and send request */
1506 init_q_query_trusted_domain_info_by_sid(&q, pol, info_class, dom_sid);
1508 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFOBYSID,
1511 lsa_io_q_query_trusted_domain_info_by_sid,
1512 lsa_io_r_query_trusted_domain_info,
1513 NT_STATUS_UNSUCCESSFUL);
1517 if (!NT_STATUS_IS_OK(result)) {
1528 NTSTATUS rpccli_lsa_query_trusted_domain_info_by_name(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1530 uint16 info_class, const char *domain_name,
1531 LSA_TRUSTED_DOMAIN_INFO **info)
1533 prs_struct qbuf, rbuf;
1534 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME q;
1535 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1536 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1541 /* Marshall data and send request */
1543 init_q_query_trusted_domain_info_by_name(&q, pol, info_class, domain_name);
1545 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFOBYNAME,
1548 lsa_io_q_query_trusted_domain_info_by_name,
1549 lsa_io_r_query_trusted_domain_info,
1550 NT_STATUS_UNSUCCESSFUL);
1554 if (!NT_STATUS_IS_OK(result)) {
1565 NTSTATUS cli_lsa_query_domain_info_policy(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1567 uint16 info_class, LSA_DOM_INFO_UNION **info)
1569 prs_struct qbuf, rbuf;
1570 LSA_Q_QUERY_DOM_INFO_POLICY q;
1571 LSA_R_QUERY_DOM_INFO_POLICY r;
1572 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1577 /* Marshall data and send request */
1579 init_q_query_dom_info(&q, pol, info_class);
1581 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYDOMINFOPOL,
1584 lsa_io_q_query_dom_info,
1585 lsa_io_r_query_dom_info,
1586 NT_STATUS_UNSUCCESSFUL);
1590 if (!NT_STATUS_IS_OK(result)) {