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 LSA_TRANS_NAME_ENUM t_names;
185 NTSTATUS result = NT_STATUS_OK;
191 init_q_lookup_sids(mem_ctx, &q, pol, num_sids, sids, 1);
194 ZERO_STRUCT(t_names);
199 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPSIDS,
202 lsa_io_q_lookup_sids,
203 lsa_io_r_lookup_sids,
204 NT_STATUS_UNSUCCESSFUL );
206 if (!NT_STATUS_IS_OK(r.status) &&
207 NT_STATUS_V(r.status) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
209 /* An actual error occured */
215 /* Return output parameters */
217 if (r.mapped_count == 0) {
218 result = NT_STATUS_NONE_MAPPED;
222 if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
223 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
224 result = NT_STATUS_UNSUCCESSFUL;
228 if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
229 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
230 result = NT_STATUS_UNSUCCESSFUL;
234 if (!((*types) = TALLOC_ARRAY(mem_ctx, uint32, num_sids))) {
235 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
236 result = NT_STATUS_UNSUCCESSFUL;
240 for (i = 0; i < num_sids; i++) {
241 fstring name, dom_name;
242 uint32 dom_idx = t_names.name[i].domain_idx;
244 /* Translate optimised name through domain index array */
246 if (dom_idx != 0xffffffff) {
248 rpcstr_pull_unistr2_fstring(
249 dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
250 rpcstr_pull_unistr2_fstring(
251 name, &t_names.uni_name[i]);
253 (*names)[i] = talloc_strdup(mem_ctx, name);
254 (*domains)[i] = talloc_strdup(mem_ctx, dom_name);
255 (*types)[i] = t_names.name[i].sid_name_use;
257 if (((*names)[i] == NULL) || ((*domains)[i] == NULL)) {
258 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
259 result = NT_STATUS_UNSUCCESSFUL;
265 (*domains)[i] = NULL;
266 (*types)[i] = SID_NAME_UNKNOWN;
275 /** Lookup a list of names */
277 NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
279 POLICY_HND *pol, int num_names,
280 const char **names, DOM_SID **sids,
283 prs_struct qbuf, rbuf;
284 LSA_Q_LOOKUP_NAMES q;
285 LSA_R_LOOKUP_NAMES r;
296 init_q_lookup_names(mem_ctx, &q, pol, num_names, names);
298 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPNAMES,
301 lsa_io_q_lookup_names,
302 lsa_io_r_lookup_names,
303 NT_STATUS_UNSUCCESSFUL);
307 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
308 NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
310 /* An actual error occured */
315 /* Return output parameters */
317 if (r.mapped_count == 0) {
318 result = NT_STATUS_NONE_MAPPED;
322 if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
323 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
324 result = NT_STATUS_UNSUCCESSFUL;
328 if (!((*types = TALLOC_ARRAY(mem_ctx, uint32, num_names)))) {
329 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
330 result = NT_STATUS_UNSUCCESSFUL;
334 for (i = 0; i < num_names; i++) {
335 DOM_RID2 *t_rids = r.dom_rid;
336 uint32 dom_idx = t_rids[i].rid_idx;
337 uint32 dom_rid = t_rids[i].rid;
338 DOM_SID *sid = &(*sids)[i];
340 /* Translate optimised sid through domain index array */
342 if (dom_idx != 0xffffffff) {
344 sid_copy(sid, &ref.ref_dom[dom_idx].ref_dom.sid);
346 if (dom_rid != 0xffffffff) {
347 sid_append_rid(sid, dom_rid);
350 (*types)[i] = t_rids[i].type;
353 (*types)[i] = SID_NAME_UNKNOWN;
362 /** Query info policy
364 * @param domain_sid - returned remote server's domain sid */
366 NTSTATUS rpccli_lsa_query_info_policy(struct rpc_pipe_client *cli,
368 POLICY_HND *pol, uint16 info_class,
369 char **domain_name, DOM_SID **domain_sid)
371 prs_struct qbuf, rbuf;
379 init_q_query(&q, pol, info_class);
381 CLI_DO_RPC(cli, mem_ctx, PI_LSARPC, LSA_QUERYINFOPOLICY,
386 NT_STATUS_UNSUCCESSFUL);
390 if (!NT_STATUS_IS_OK(result)) {
394 /* Return output parameters */
396 switch (info_class) {
399 if (domain_name && (r.dom.id3.buffer_dom_name != 0)) {
400 *domain_name = unistr2_tdup(mem_ctx,
405 if (domain_sid && (r.dom.id3.buffer_dom_sid != 0)) {
406 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
408 sid_copy(*domain_sid, &r.dom.id3.dom_sid.sid);
416 if (domain_name && (r.dom.id5.buffer_dom_name != 0)) {
417 *domain_name = unistr2_tdup(mem_ctx,
422 if (domain_sid && (r.dom.id5.buffer_dom_sid != 0)) {
423 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
425 sid_copy(*domain_sid, &r.dom.id5.dom_sid.sid);
431 DEBUG(3, ("unknown info class %d\n", info_class));
440 /** Query info policy2
442 * @param domain_name - returned remote server's domain name
443 * @param dns_name - returned remote server's dns domain name
444 * @param forest_name - returned remote server's forest name
445 * @param domain_guid - returned remote server's domain guid
446 * @param domain_sid - returned remote server's domain sid */
448 NTSTATUS rpccli_lsa_query_info_policy2(struct rpc_pipe_client *cli,
450 POLICY_HND *pol, uint16 info_class,
451 char **domain_name, char **dns_name,
453 struct uuid **domain_guid,
454 DOM_SID **domain_sid)
456 prs_struct qbuf, rbuf;
459 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
461 if (info_class != 12)
467 init_q_query2(&q, pol, info_class);
469 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYINFO2,
472 lsa_io_q_query_info2,
473 lsa_io_r_query_info2,
474 NT_STATUS_UNSUCCESSFUL);
478 if (!NT_STATUS_IS_OK(result)) {
482 /* Return output parameters */
484 ZERO_STRUCTP(domain_guid);
486 if (domain_name && r.info.dns_dom_info.hdr_nb_dom_name.buffer) {
487 *domain_name = unistr2_tdup(mem_ctx,
491 if (dns_name && r.info.dns_dom_info.hdr_dns_dom_name.buffer) {
492 *dns_name = unistr2_tdup(mem_ctx,
496 if (forest_name && r.info.dns_dom_info.hdr_forest_name.buffer) {
497 *forest_name = unistr2_tdup(mem_ctx,
503 *domain_guid = TALLOC_P(mem_ctx, struct uuid);
505 &r.info.dns_dom_info.dom_guid,
506 sizeof(struct uuid));
509 if (domain_sid && r.info.dns_dom_info.ptr_dom_sid != 0) {
510 *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
512 sid_copy(*domain_sid,
513 &r.info.dns_dom_info.dom_sid.sid);
523 * Enumerate list of trusted domains
525 * @param cli client state (cli_state) structure of the connection
526 * @param mem_ctx memory context
527 * @param pol opened lsa policy handle
528 * @param enum_ctx enumeration context ie. index of first returned domain entry
529 * @param pref_num_domains preferred max number of entries returned in one response
530 * @param num_domains total number of trusted domains returned by response
531 * @param domain_names returned trusted domain names
532 * @param domain_sids returned trusted domain sids
534 * @return nt status code of response
537 NTSTATUS rpccli_lsa_enum_trust_dom(struct rpc_pipe_client *cli,
539 POLICY_HND *pol, uint32 *enum_ctx,
541 char ***domain_names, DOM_SID **domain_sids)
543 prs_struct qbuf, rbuf;
544 LSA_Q_ENUM_TRUST_DOM in;
545 LSA_R_ENUM_TRUST_DOM out;
552 /* 64k is enough for about 2000 trusted domains */
554 init_q_enum_trust_dom(&in, pol, *enum_ctx, 0x10000);
556 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMTRUSTDOM,
559 lsa_io_q_enum_trust_dom,
560 lsa_io_r_enum_trust_dom,
561 NT_STATUS_UNSUCCESSFUL );
564 /* check for an actual error */
566 if ( !NT_STATUS_IS_OK(out.status)
567 && !NT_STATUS_EQUAL(out.status, NT_STATUS_NO_MORE_ENTRIES)
568 && !NT_STATUS_EQUAL(out.status, STATUS_MORE_ENTRIES) )
573 /* Return output parameters */
575 *num_domains = out.count;
576 *enum_ctx = out.enum_context;
580 /* Allocate memory for trusted domain names and sids */
582 if ( !(*domain_names = TALLOC_ARRAY(mem_ctx, char *, out.count)) ) {
583 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
584 return NT_STATUS_NO_MEMORY;
587 if ( !(*domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, out.count)) ) {
588 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
589 return NT_STATUS_NO_MEMORY;
592 /* Copy across names and sids */
594 for (i = 0; i < out.count; i++) {
596 rpcstr_pull( tmp, out.domlist->domains[i].name.string->buffer,
597 sizeof(tmp), out.domlist->domains[i].name.length, 0);
598 (*domain_names)[i] = talloc_strdup(mem_ctx, tmp);
600 sid_copy(&(*domain_sids)[i], &out.domlist->domains[i].sid->sid );
607 /** Enumerate privileges*/
609 NTSTATUS rpccli_lsa_enum_privilege(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
610 POLICY_HND *pol, uint32 *enum_context, uint32 pref_max_length,
611 uint32 *count, char ***privs_name, uint32 **privs_high, uint32 **privs_low)
613 prs_struct qbuf, rbuf;
622 init_q_enum_privs(&q, pol, *enum_context, pref_max_length);
624 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUM_PRIVS,
629 NT_STATUS_UNSUCCESSFUL);
633 if (!NT_STATUS_IS_OK(result)) {
637 /* Return output parameters */
639 *enum_context = r.enum_context;
642 if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
643 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
644 result = NT_STATUS_UNSUCCESSFUL;
648 if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
649 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
650 result = NT_STATUS_UNSUCCESSFUL;
654 if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
655 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
656 result = NT_STATUS_UNSUCCESSFUL;
660 for (i = 0; i < r.count; i++) {
663 rpcstr_pull_unistr2_fstring( name, &r.privs[i].name);
665 (*privs_name)[i] = talloc_strdup(mem_ctx, name);
667 (*privs_high)[i] = r.privs[i].luid_high;
668 (*privs_low)[i] = r.privs[i].luid_low;
676 /** Get privilege name */
678 NTSTATUS rpccli_lsa_get_dispname(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
679 POLICY_HND *pol, const char *name,
680 uint16 lang_id, uint16 lang_id_sys,
681 fstring description, uint16 *lang_id_desc)
683 prs_struct qbuf, rbuf;
684 LSA_Q_PRIV_GET_DISPNAME q;
685 LSA_R_PRIV_GET_DISPNAME r;
691 init_lsa_priv_get_dispname(&q, pol, name, lang_id, lang_id_sys);
693 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_PRIV_GET_DISPNAME,
696 lsa_io_q_priv_get_dispname,
697 lsa_io_r_priv_get_dispname,
698 NT_STATUS_UNSUCCESSFUL);
702 if (!NT_STATUS_IS_OK(result)) {
706 /* Return output parameters */
708 rpcstr_pull_unistr2_fstring(description , &r.desc);
709 *lang_id_desc = r.lang_id;
716 /** Enumerate list of SIDs */
718 NTSTATUS rpccli_lsa_enum_sids(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
719 POLICY_HND *pol, uint32 *enum_ctx, uint32 pref_max_length,
720 uint32 *num_sids, DOM_SID **sids)
722 prs_struct qbuf, rbuf;
723 LSA_Q_ENUM_ACCOUNTS q;
724 LSA_R_ENUM_ACCOUNTS r;
731 init_lsa_q_enum_accounts(&q, pol, *enum_ctx, pref_max_length);
733 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUM_ACCOUNTS,
736 lsa_io_q_enum_accounts,
737 lsa_io_r_enum_accounts,
738 NT_STATUS_UNSUCCESSFUL);
742 if (!NT_STATUS_IS_OK(result)) {
746 if (r.sids.num_entries==0)
749 /* Return output parameters */
751 *sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.sids.num_entries);
753 DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
754 result = NT_STATUS_UNSUCCESSFUL;
758 /* Copy across names and sids */
760 for (i = 0; i < r.sids.num_entries; i++) {
761 sid_copy(&(*sids)[i], &r.sids.sid[i].sid);
764 *num_sids= r.sids.num_entries;
765 *enum_ctx = r.enum_context;
772 /** Create a LSA user handle
774 * @param cli Handle on an initialised SMB connection
776 * FIXME: The code is actually identical to open account
777 * TODO: Check and code what the function should exactly do
781 NTSTATUS rpccli_lsa_create_account(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
782 POLICY_HND *dom_pol, DOM_SID *sid, uint32 desired_access,
783 POLICY_HND *user_pol)
785 prs_struct qbuf, rbuf;
786 LSA_Q_CREATEACCOUNT q;
787 LSA_R_CREATEACCOUNT r;
793 /* Initialise input parameters */
795 init_lsa_q_create_account(&q, dom_pol, sid, desired_access);
797 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_CREATEACCOUNT,
800 lsa_io_q_create_account,
801 lsa_io_r_create_account,
802 NT_STATUS_UNSUCCESSFUL);
804 /* Return output parameters */
808 if (NT_STATUS_IS_OK(result)) {
815 /** Open a LSA user handle
817 * @param cli Handle on an initialised SMB connection */
819 NTSTATUS rpccli_lsa_open_account(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
820 POLICY_HND *dom_pol, DOM_SID *sid, uint32 des_access,
821 POLICY_HND *user_pol)
823 prs_struct qbuf, rbuf;
831 /* Initialise input parameters */
833 init_lsa_q_open_account(&q, dom_pol, sid, des_access);
835 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENACCOUNT,
838 lsa_io_q_open_account,
839 lsa_io_r_open_account,
840 NT_STATUS_UNSUCCESSFUL);
842 /* Return output parameters */
846 if (NT_STATUS_IS_OK(result)) {
853 /** Enumerate user privileges
855 * @param cli Handle on an initialised SMB connection */
857 NTSTATUS rpccli_lsa_enum_privsaccount(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
858 POLICY_HND *pol, uint32 *count, LUID_ATTR **set)
860 prs_struct qbuf, rbuf;
861 LSA_Q_ENUMPRIVSACCOUNT q;
862 LSA_R_ENUMPRIVSACCOUNT r;
869 /* Initialise input parameters */
871 init_lsa_q_enum_privsaccount(&q, pol);
873 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMPRIVSACCOUNT,
876 lsa_io_q_enum_privsaccount,
877 lsa_io_r_enum_privsaccount,
878 NT_STATUS_UNSUCCESSFUL);
880 /* Return output parameters */
884 if (!NT_STATUS_IS_OK(result)) {
891 if (!((*set = TALLOC_ARRAY(mem_ctx, LUID_ATTR, r.count)))) {
892 DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
893 result = NT_STATUS_UNSUCCESSFUL;
897 for (i=0; i<r.count; i++) {
898 (*set)[i].luid.low = r.set.set[i].luid.low;
899 (*set)[i].luid.high = r.set.set[i].luid.high;
900 (*set)[i].attr = r.set.set[i].attr;
909 /** Get a privilege value given its name */
911 NTSTATUS rpccli_lsa_lookup_priv_value(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
912 POLICY_HND *pol, const char *name, LUID *luid)
914 prs_struct qbuf, rbuf;
915 LSA_Q_LOOKUP_PRIV_VALUE q;
916 LSA_R_LOOKUP_PRIV_VALUE r;
922 /* Marshall data and send request */
924 init_lsa_q_lookup_priv_value(&q, pol, name);
926 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPPRIVVALUE,
929 lsa_io_q_lookup_priv_value,
930 lsa_io_r_lookup_priv_value,
931 NT_STATUS_UNSUCCESSFUL);
935 if (!NT_STATUS_IS_OK(result)) {
939 /* Return output parameters */
941 (*luid).low=r.luid.low;
942 (*luid).high=r.luid.high;
949 /** Query LSA security object */
951 NTSTATUS rpccli_lsa_query_secobj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
952 POLICY_HND *pol, uint32 sec_info,
955 prs_struct qbuf, rbuf;
956 LSA_Q_QUERY_SEC_OBJ q;
957 LSA_R_QUERY_SEC_OBJ r;
963 /* Marshall data and send request */
965 init_q_query_sec_obj(&q, pol, sec_info);
967 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYSECOBJ,
970 lsa_io_q_query_sec_obj,
971 lsa_io_r_query_sec_obj,
972 NT_STATUS_UNSUCCESSFUL);
976 if (!NT_STATUS_IS_OK(result)) {
980 /* Return output parameters */
991 /* Enumerate account rights This is similar to enum_privileges but
992 takes a SID directly, avoiding the open_account call.
995 NTSTATUS rpccli_lsa_enum_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
996 POLICY_HND *pol, DOM_SID *sid,
997 uint32 *count, char ***priv_names)
999 prs_struct qbuf, rbuf;
1000 LSA_Q_ENUM_ACCT_RIGHTS q;
1001 LSA_R_ENUM_ACCT_RIGHTS r;
1004 fstring *privileges;
1010 /* Marshall data and send request */
1011 init_q_enum_acct_rights(&q, pol, 2, sid);
1013 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMACCTRIGHTS,
1016 lsa_io_q_enum_acct_rights,
1017 lsa_io_r_enum_acct_rights,
1018 NT_STATUS_UNSUCCESSFUL);
1022 if (!NT_STATUS_IS_OK(result)) {
1032 privileges = TALLOC_ARRAY( mem_ctx, fstring, *count );
1033 names = TALLOC_ARRAY( mem_ctx, char *, *count );
1035 for ( i=0; i<*count; i++ ) {
1036 UNISTR4 *uni_string = &r.rights->strings[i];
1038 if ( !uni_string->string )
1041 rpcstr_pull( privileges[i], uni_string->string->buffer, sizeof(privileges[i]), -1, STR_TERMINATE );
1043 /* now copy to the return array */
1044 names[i] = talloc_strdup( mem_ctx, privileges[i] );
1047 *priv_names = names;
1056 /* add account rights to an account. */
1058 NTSTATUS rpccli_lsa_add_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1059 POLICY_HND *pol, DOM_SID sid,
1060 uint32 count, const char **privs_name)
1062 prs_struct qbuf, rbuf;
1063 LSA_Q_ADD_ACCT_RIGHTS q;
1064 LSA_R_ADD_ACCT_RIGHTS r;
1070 /* Marshall data and send request */
1071 init_q_add_acct_rights(&q, pol, &sid, count, privs_name);
1073 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ADDACCTRIGHTS,
1076 lsa_io_q_add_acct_rights,
1077 lsa_io_r_add_acct_rights,
1078 NT_STATUS_UNSUCCESSFUL);
1082 if (!NT_STATUS_IS_OK(result)) {
1091 /* remove account rights for an account. */
1093 NTSTATUS rpccli_lsa_remove_account_rights(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1094 POLICY_HND *pol, DOM_SID sid, BOOL removeall,
1095 uint32 count, const char **privs_name)
1097 prs_struct qbuf, rbuf;
1098 LSA_Q_REMOVE_ACCT_RIGHTS q;
1099 LSA_R_REMOVE_ACCT_RIGHTS r;
1105 /* Marshall data and send request */
1106 init_q_remove_acct_rights(&q, pol, &sid, removeall?1:0, count, privs_name);
1108 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_REMOVEACCTRIGHTS,
1111 lsa_io_q_remove_acct_rights,
1112 lsa_io_r_remove_acct_rights,
1113 NT_STATUS_UNSUCCESSFUL);
1117 if (!NT_STATUS_IS_OK(result)) {
1128 /** An example of how to use the routines in this file. Fetch a DOMAIN
1129 sid. Does complete cli setup / teardown anonymously. */
1131 BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid)
1133 extern pstring global_myname;
1134 struct cli_state cli;
1140 if(cli_initialise(&cli) == False) {
1141 DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
1145 if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
1146 DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
1150 if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
1151 DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
1152 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1156 if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
1157 DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
1162 cli.protocol = PROTOCOL_NT1;
1164 if (!cli_negprot(&cli)) {
1165 DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \
1166 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1170 if (cli.protocol != PROTOCOL_NT1) {
1171 DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
1177 * Do an anonymous session setup.
1180 if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
1181 DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \
1182 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1186 if (!(cli.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
1187 DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n",
1192 if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
1193 DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \
1194 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1198 /* Fetch domain sid */
1200 if (!cli_nt_session_open(&cli, PI_LSARPC)) {
1201 DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n"));
1205 result = cli_lsa_open_policy(&cli, cli.mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
1206 if (!NT_STATUS_IS_OK(result)) {
1207 DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n",
1208 nt_errstr(result) ));
1212 result = cli_lsa_query_info_policy(&cli, cli.mem_ctx, &lsa_pol, 5, domain, psid);
1213 if (!NT_STATUS_IS_OK(result)) {
1214 DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n",
1215 nt_errstr(result) ));
1229 NTSTATUS rpccli_lsa_open_trusted_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1230 POLICY_HND *pol, DOM_SID *dom_sid, uint32 access_mask,
1231 POLICY_HND *trustdom_pol)
1233 prs_struct qbuf, rbuf;
1234 LSA_Q_OPEN_TRUSTED_DOMAIN q;
1235 LSA_R_OPEN_TRUSTED_DOMAIN r;
1241 /* Initialise input parameters */
1243 init_lsa_q_open_trusted_domain(&q, pol, dom_sid, access_mask);
1245 /* Marshall data and send request */
1247 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_OPENTRUSTDOM,
1250 lsa_io_q_open_trusted_domain,
1251 lsa_io_r_open_trusted_domain,
1252 NT_STATUS_UNSUCCESSFUL);
1254 /* Return output parameters */
1258 if (NT_STATUS_IS_OK(result)) {
1259 *trustdom_pol = r.handle;
1265 NTSTATUS rpccli_lsa_query_trusted_domain_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1267 uint16 info_class, DOM_SID *dom_sid,
1268 LSA_TRUSTED_DOMAIN_INFO **info)
1270 prs_struct qbuf, rbuf;
1271 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO q;
1272 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1273 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1278 /* Marshall data and send request */
1280 init_q_query_trusted_domain_info(&q, pol, info_class);
1282 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFO,
1285 lsa_io_q_query_trusted_domain_info,
1286 lsa_io_r_query_trusted_domain_info,
1287 NT_STATUS_UNSUCCESSFUL);
1291 if (!NT_STATUS_IS_OK(result)) {
1302 NTSTATUS rpccli_lsa_query_trusted_domain_info_by_sid(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1304 uint16 info_class, DOM_SID *dom_sid,
1305 LSA_TRUSTED_DOMAIN_INFO **info)
1307 prs_struct qbuf, rbuf;
1308 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID q;
1309 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1310 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1315 /* Marshall data and send request */
1317 init_q_query_trusted_domain_info_by_sid(&q, pol, info_class, dom_sid);
1319 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFOBYSID,
1322 lsa_io_q_query_trusted_domain_info_by_sid,
1323 lsa_io_r_query_trusted_domain_info,
1324 NT_STATUS_UNSUCCESSFUL);
1328 if (!NT_STATUS_IS_OK(result)) {
1339 NTSTATUS rpccli_lsa_query_trusted_domain_info_by_name(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1341 uint16 info_class, const char *domain_name,
1342 LSA_TRUSTED_DOMAIN_INFO **info)
1344 prs_struct qbuf, rbuf;
1345 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME q;
1346 LSA_R_QUERY_TRUSTED_DOMAIN_INFO r;
1347 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1352 /* Marshall data and send request */
1354 init_q_query_trusted_domain_info_by_name(&q, pol, info_class, domain_name);
1356 CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_QUERYTRUSTDOMINFOBYNAME,
1359 lsa_io_q_query_trusted_domain_info_by_name,
1360 lsa_io_r_query_trusted_domain_info,
1361 NT_STATUS_UNSUCCESSFUL);
1365 if (!NT_STATUS_IS_OK(result)) {