2 Unix SMB/CIFS implementation.
4 Copyright (C) Tim Potter 2000-2001,
5 Copyright (C) Andrew Tridgell 1992-1997,2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
7 Copyright (C) Paul Ashton 1997,2000,
8 Copyright (C) Elrond 2000,
9 Copyright (C) Rafal Szczesniak 2002
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /** @defgroup lsa LSA - Local Security Architecture
37 * RPC client routines for the LSA RPC pipe. LSA means "local
38 * security authority", which is half of a password database.
41 /** Open a LSA policy handle
43 * @param cli Handle on an initialised SMB connection */
45 NTSTATUS cli_lsa_open_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
46 BOOL sec_qos, uint32 des_access, POLICY_HND *pol)
48 prs_struct qbuf, rbuf;
57 /* Initialise parse structures */
59 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
60 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
62 /* Initialise input parameters */
65 init_lsa_sec_qos(&qos, 2, 1, 0);
66 init_q_open_pol(&q, '\\', 0, des_access, &qos);
68 init_q_open_pol(&q, '\\', 0, des_access, NULL);
71 /* Marshall data and send request */
73 if (!lsa_io_q_open_pol("", &q, &qbuf, 0) ||
74 !rpc_api_pipe_req(cli, LSA_OPENPOLICY, &qbuf, &rbuf)) {
75 result = NT_STATUS_UNSUCCESSFUL;
79 /* Unmarshall response */
81 if (!lsa_io_r_open_pol("", &r, &rbuf, 0)) {
82 result = NT_STATUS_UNSUCCESSFUL;
86 /* Return output parameters */
88 if (NT_STATUS_IS_OK(result = r.status)) {
91 pol->marker = malloc(1);
102 /** Open a LSA policy handle
104 * @param cli Handle on an initialised SMB connection
107 NTSTATUS cli_lsa_open_policy2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
108 BOOL sec_qos, uint32 des_access, POLICY_HND *pol)
110 prs_struct qbuf, rbuf;
119 /* Initialise parse structures */
121 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
122 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
124 /* Initialise input parameters */
127 init_lsa_sec_qos(&qos, 2, 1, 0);
128 init_q_open_pol2(&q, cli->srv_name_slash, 0, des_access,
131 init_q_open_pol2(&q, cli->srv_name_slash, 0, des_access,
135 /* Marshall data and send request */
137 if (!lsa_io_q_open_pol2("", &q, &qbuf, 0) ||
138 !rpc_api_pipe_req(cli, LSA_OPENPOLICY2, &qbuf, &rbuf)) {
139 result = NT_STATUS_UNSUCCESSFUL;
143 /* Unmarshall response */
145 if (!lsa_io_r_open_pol2("", &r, &rbuf, 0)) {
146 result = NT_STATUS_UNSUCCESSFUL;
150 /* Return output parameters */
152 if (NT_STATUS_IS_OK(result = r.status)) {
155 pol->marker = (char *)malloc(1);
166 /** Close a LSA policy handle */
168 NTSTATUS cli_lsa_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
171 prs_struct qbuf, rbuf;
179 /* Initialise parse structures */
181 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
182 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
184 /* Marshall data and send request */
186 init_lsa_q_close(&q, pol);
188 if (!lsa_io_q_close("", &q, &qbuf, 0) ||
189 !rpc_api_pipe_req(cli, LSA_CLOSE, &qbuf, &rbuf)) {
190 result = NT_STATUS_UNSUCCESSFUL;
194 /* Unmarshall response */
196 if (!lsa_io_r_close("", &r, &rbuf, 0)) {
197 result = NT_STATUS_UNSUCCESSFUL;
201 /* Return output parameters */
203 if (NT_STATUS_IS_OK(result = r.status)) {
205 SAFE_FREE(pol->marker);
217 /** Lookup a list of sids */
219 NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
220 POLICY_HND *pol, int num_sids, DOM_SID *sids,
221 char ***domains, char ***names, uint32 **types)
223 prs_struct qbuf, rbuf;
227 LSA_TRANS_NAME_ENUM t_names;
234 /* Initialise parse structures */
236 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
237 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
239 /* Marshall data and send request */
241 init_q_lookup_sids(mem_ctx, &q, pol, num_sids, sids, 1);
243 if (!lsa_io_q_lookup_sids("", &q, &qbuf, 0) ||
244 !rpc_api_pipe_req(cli, LSA_LOOKUPSIDS, &qbuf, &rbuf)) {
245 result = NT_STATUS_UNSUCCESSFUL;
249 /* Unmarshall response */
252 ZERO_STRUCT(t_names);
257 if (!lsa_io_r_lookup_sids("", &r, &rbuf, 0)) {
258 result = NT_STATUS_UNSUCCESSFUL;
264 if (!NT_STATUS_IS_OK(result) &&
265 NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
267 /* An actual error occured */
272 /* Return output parameters */
274 if (r.mapped_count == 0) {
275 result = NT_STATUS_NONE_MAPPED;
279 if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) *
281 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
282 result = NT_STATUS_UNSUCCESSFUL;
286 if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
288 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
289 result = NT_STATUS_UNSUCCESSFUL;
293 if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
295 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
296 result = NT_STATUS_UNSUCCESSFUL;
300 for (i = 0; i < num_sids; i++) {
301 fstring name, dom_name;
302 uint32 dom_idx = t_names.name[i].domain_idx;
304 /* Translate optimised name through domain index array */
306 if (dom_idx != 0xffffffff) {
308 rpcstr_pull_unistr2_fstring(
309 dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
310 rpcstr_pull_unistr2_fstring(
311 name, &t_names.uni_name[i]);
313 (*names)[i] = talloc_strdup(mem_ctx, name);
314 (*domains)[i] = talloc_strdup(mem_ctx, dom_name);
315 (*types)[i] = t_names.name[i].sid_name_use;
317 if (((*names)[i] == NULL) || ((*domains)[i] == NULL)) {
318 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
319 result = NT_STATUS_UNSUCCESSFUL;
325 (*types)[i] = SID_NAME_UNKNOWN;
336 /** Lookup a list of names */
338 NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
339 POLICY_HND *pol, int num_names,
340 const char **names, DOM_SID **sids,
343 prs_struct qbuf, rbuf;
344 LSA_Q_LOOKUP_NAMES q;
345 LSA_R_LOOKUP_NAMES r;
353 /* Initialise parse structures */
355 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
356 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
358 /* Marshall data and send request */
360 init_q_lookup_names(mem_ctx, &q, pol, num_names, names);
362 if (!lsa_io_q_lookup_names("", &q, &qbuf, 0) ||
363 !rpc_api_pipe_req(cli, LSA_LOOKUPNAMES, &qbuf, &rbuf)) {
364 result = NT_STATUS_UNSUCCESSFUL;
368 /* Unmarshall response */
373 if (!lsa_io_r_lookup_names("", &r, &rbuf, 0)) {
374 result = NT_STATUS_UNSUCCESSFUL;
380 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
381 NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
383 /* An actual error occured */
388 /* Return output parameters */
390 if (r.mapped_count == 0) {
391 result = NT_STATUS_NONE_MAPPED;
395 if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
397 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
398 result = NT_STATUS_UNSUCCESSFUL;
402 if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
404 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
405 result = NT_STATUS_UNSUCCESSFUL;
409 for (i = 0; i < num_names; i++) {
410 DOM_RID2 *t_rids = r.dom_rid;
411 uint32 dom_idx = t_rids[i].rid_idx;
412 uint32 dom_rid = t_rids[i].rid;
413 DOM_SID *sid = &(*sids)[i];
415 /* Translate optimised sid through domain index array */
417 if (dom_idx != 0xffffffff) {
419 sid_copy(sid, &ref.ref_dom[dom_idx].ref_dom.sid);
421 if (dom_rid != 0xffffffff) {
422 sid_append_rid(sid, dom_rid);
425 (*types)[i] = t_rids[i].type;
428 (*types)[i] = SID_NAME_UNKNOWN;
439 /** Query info policy
441 * @param domain_sid - returned remote server's domain sid */
443 NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
444 POLICY_HND *pol, uint16 info_class,
445 fstring domain_name, DOM_SID *domain_sid)
447 prs_struct qbuf, rbuf;
455 /* Initialise parse structures */
457 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
458 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
460 /* Marshall data and send request */
462 init_q_query(&q, pol, info_class);
464 if (!lsa_io_q_query("", &q, &qbuf, 0) ||
465 !rpc_api_pipe_req(cli, LSA_QUERYINFOPOLICY, &qbuf, &rbuf)) {
466 result = NT_STATUS_UNSUCCESSFUL;
470 /* Unmarshall response */
472 if (!lsa_io_r_query("", &r, &rbuf, 0)) {
473 result = NT_STATUS_UNSUCCESSFUL;
477 if (!NT_STATUS_IS_OK(result = r.status)) {
481 /* Return output parameters */
483 ZERO_STRUCTP(domain_sid);
484 domain_name[0] = '\0';
486 switch (info_class) {
489 if (r.dom.id3.buffer_dom_name != 0) {
490 unistr2_to_ascii(domain_name,
493 sizeof (fstring) - 1);
496 if (r.dom.id3.buffer_dom_sid != 0) {
497 *domain_sid = r.dom.id3.dom_sid.sid;
504 if (r.dom.id5.buffer_dom_name != 0) {
505 unistr2_to_ascii(domain_name, &r.dom.id5.
507 sizeof (fstring) - 1);
510 if (r.dom.id5.buffer_dom_sid != 0) {
511 *domain_sid = r.dom.id5.dom_sid.sid;
517 DEBUG(3, ("unknown info class %d\n", info_class));
529 * Enumerate list of trusted domains
531 * @param cli client state (cli_state) structure of the connection
532 * @param mem_ctx memory context
533 * @param pol opened lsa policy handle
534 * @param enum_ctx enumeration context ie. index of first returned domain entry
535 * @param pref_num_domains preferred max number of entries returned in one response
536 * @param num_domains total number of trusted domains returned by response
537 * @param domain_names returned trusted domain names
538 * @param domain_sids returned trusted domain sids
540 * @return nt status code of response
543 NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx,
544 POLICY_HND *pol, uint32 *enum_ctx,
545 uint32 *pref_num_domains, uint32 *num_domains,
546 char ***domain_names, DOM_SID **domain_sids)
548 prs_struct qbuf, rbuf;
549 LSA_Q_ENUM_TRUST_DOM q;
550 LSA_R_ENUM_TRUST_DOM r;
557 /* Initialise parse structures */
559 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
560 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
562 /* Marshall data and send request */
564 init_q_enum_trust_dom(&q, pol, *enum_ctx, *pref_num_domains);
566 if (!lsa_io_q_enum_trust_dom("", &q, &qbuf, 0) ||
567 !rpc_api_pipe_req(cli, LSA_ENUMTRUSTDOM, &qbuf, &rbuf)) {
568 result = NT_STATUS_UNSUCCESSFUL;
572 /* Unmarshall response */
574 if (!lsa_io_r_enum_trust_dom("", &r, &rbuf, 0)) {
575 result = NT_STATUS_UNSUCCESSFUL;
581 if (!NT_STATUS_IS_OK(result) &&
582 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
583 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
585 /* An actual error ocured */
590 /* Return output parameters */
594 /* Allocate memory for trusted domain names and sids */
596 *domain_names = (char **)talloc(mem_ctx, sizeof(char *) *
599 if (!*domain_names) {
600 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
601 result = NT_STATUS_NO_MEMORY;
605 *domain_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
608 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
609 result = NT_STATUS_NO_MEMORY;
613 /* Copy across names and sids */
615 for (i = 0; i < r.num_domains; i++) {
618 unistr2_to_ascii(tmp, &r.uni_domain_name[i],
620 (*domain_names)[i] = talloc_strdup(mem_ctx, tmp);
621 sid_copy(&(*domain_sids)[i], &r.domain_sid[i].sid);
625 *num_domains = r.num_domains;
626 *enum_ctx = r.enum_context;
636 /** Enumerate privileges*/
638 NTSTATUS cli_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx,
639 POLICY_HND *pol, uint32 *enum_context, uint32 pref_max_length,
640 uint32 *count, char ***privs_name, uint32 **privs_high, uint32 **privs_low)
642 prs_struct qbuf, rbuf;
651 /* Initialise parse structures */
653 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
654 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
656 /* Marshall data and send request */
658 init_q_enum_privs(&q, pol, *enum_context, pref_max_length);
660 if (!lsa_io_q_enum_privs("", &q, &qbuf, 0) ||
661 !rpc_api_pipe_req(cli, LSA_ENUM_PRIVS, &qbuf, &rbuf)) {
662 result = NT_STATUS_UNSUCCESSFUL;
666 /* Unmarshall response */
668 if (!lsa_io_r_enum_privs("", &r, &rbuf, 0)) {
669 result = NT_STATUS_UNSUCCESSFUL;
673 if (!NT_STATUS_IS_OK(result = r.status)) {
677 /* Return output parameters */
679 *enum_context = r.enum_context;
682 if (!((*privs_name = (char **)talloc(mem_ctx, sizeof(char *) * r.count)))) {
683 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
684 result = NT_STATUS_UNSUCCESSFUL;
688 if (!((*privs_high = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
689 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
690 result = NT_STATUS_UNSUCCESSFUL;
694 if (!((*privs_low = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
695 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
696 result = NT_STATUS_UNSUCCESSFUL;
700 for (i = 0; i < r.count; i++) {
703 rpcstr_pull_unistr2_fstring( name, &r.privs[i].name);
705 (*privs_name)[i] = talloc_strdup(mem_ctx, name);
707 (*privs_high)[i] = r.privs[i].luid_high;
708 (*privs_low)[i] = r.privs[i].luid_low;
718 /** Get privilege name */
720 NTSTATUS cli_lsa_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx,
721 POLICY_HND *pol, char *name, uint16 lang_id, uint16 lang_id_sys,
722 fstring description, uint16 *lang_id_desc)
724 prs_struct qbuf, rbuf;
725 LSA_Q_PRIV_GET_DISPNAME q;
726 LSA_R_PRIV_GET_DISPNAME r;
732 /* Initialise parse structures */
734 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
735 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
737 /* Marshall data and send request */
739 init_lsa_priv_get_dispname(&q, pol, name, lang_id, lang_id_sys);
741 if (!lsa_io_q_priv_get_dispname("", &q, &qbuf, 0) ||
742 !rpc_api_pipe_req(cli, LSA_PRIV_GET_DISPNAME, &qbuf, &rbuf)) {
743 result = NT_STATUS_UNSUCCESSFUL;
747 /* Unmarshall response */
749 if (!lsa_io_r_priv_get_dispname("", &r, &rbuf, 0)) {
750 result = NT_STATUS_UNSUCCESSFUL;
754 if (!NT_STATUS_IS_OK(result = r.status)) {
758 /* Return output parameters */
760 rpcstr_pull_unistr2_fstring(description , &r.desc);
761 *lang_id_desc = r.lang_id;
770 /** Enumerate list of SIDs */
772 NTSTATUS cli_lsa_enum_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
773 POLICY_HND *pol, uint32 *enum_ctx, uint32 pref_max_length,
774 uint32 *num_sids, DOM_SID **sids)
776 prs_struct qbuf, rbuf;
777 LSA_Q_ENUM_ACCOUNTS q;
778 LSA_R_ENUM_ACCOUNTS r;
785 /* Initialise parse structures */
787 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
788 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
790 /* Marshall data and send request */
792 init_lsa_q_enum_accounts(&q, pol, *enum_ctx, pref_max_length);
794 if (!lsa_io_q_enum_accounts("", &q, &qbuf, 0) ||
795 !rpc_api_pipe_req(cli, LSA_ENUM_ACCOUNTS, &qbuf, &rbuf)) {
796 result = NT_STATUS_UNSUCCESSFUL;
800 /* Unmarshall response */
802 if (!lsa_io_r_enum_accounts("", &r, &rbuf, 0)) {
803 result = NT_STATUS_UNSUCCESSFUL;
809 if (!NT_STATUS_IS_OK(result = r.status)) {
813 if (r.sids.num_entries==0)
816 /* Return output parameters */
818 *sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.sids.num_entries);
820 DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
821 result = NT_STATUS_UNSUCCESSFUL;
825 /* Copy across names and sids */
827 for (i = 0; i < r.sids.num_entries; i++) {
828 sid_copy(&(*sids)[i], &r.sids.sid[i].sid);
831 *num_sids= r.sids.num_entries;
832 *enum_ctx = r.enum_context;
841 /** Open a LSA user handle
843 * @param cli Handle on an initialised SMB connection */
845 NTSTATUS cli_lsa_open_account(struct cli_state *cli, TALLOC_CTX *mem_ctx,
846 POLICY_HND *dom_pol, DOM_SID *sid, uint32 des_access,
847 POLICY_HND *user_pol)
849 prs_struct qbuf, rbuf;
857 /* Initialise parse structures */
859 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
860 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
862 /* Initialise input parameters */
864 init_lsa_q_open_account(&q, dom_pol, sid, des_access);
866 /* Marshall data and send request */
868 if (!lsa_io_q_open_account("", &q, &qbuf, 0) ||
869 !rpc_api_pipe_req(cli, LSA_OPENACCOUNT, &qbuf, &rbuf)) {
870 result = NT_STATUS_UNSUCCESSFUL;
874 /* Unmarshall response */
876 if (!lsa_io_r_open_account("", &r, &rbuf, 0)) {
877 result = NT_STATUS_UNSUCCESSFUL;
881 /* Return output parameters */
883 if (NT_STATUS_IS_OK(result = r.status)) {
894 /** Enumerate user privileges
896 * @param cli Handle on an initialised SMB connection */
898 NTSTATUS cli_lsa_enum_privsaccount(struct cli_state *cli, TALLOC_CTX *mem_ctx,
899 POLICY_HND *pol, uint32 *count, LUID_ATTR **set)
901 prs_struct qbuf, rbuf;
902 LSA_Q_ENUMPRIVSACCOUNT q;
903 LSA_R_ENUMPRIVSACCOUNT r;
910 /* Initialise parse structures */
912 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
913 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
915 /* Initialise input parameters */
917 init_lsa_q_enum_privsaccount(&q, pol);
919 /* Marshall data and send request */
921 if (!lsa_io_q_enum_privsaccount("", &q, &qbuf, 0) ||
922 !rpc_api_pipe_req(cli, LSA_ENUMPRIVSACCOUNT, &qbuf, &rbuf)) {
923 result = NT_STATUS_UNSUCCESSFUL;
927 /* Unmarshall response */
929 if (!lsa_io_r_enum_privsaccount("", &r, &rbuf, 0)) {
930 result = NT_STATUS_UNSUCCESSFUL;
934 /* Return output parameters */
936 if (!NT_STATUS_IS_OK(result = r.status)) {
943 if (!((*set = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR) * r.count)))) {
944 DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
945 result = NT_STATUS_UNSUCCESSFUL;
949 for (i=0; i<r.count; i++) {
950 (*set)[i].luid.low = r.set.set[i].luid.low;
951 (*set)[i].luid.high = r.set.set[i].luid.high;
952 (*set)[i].attr = r.set.set[i].attr;
963 /** Get a privilege value given its name */
965 NTSTATUS cli_lsa_lookupprivvalue(struct cli_state *cli, TALLOC_CTX *mem_ctx,
966 POLICY_HND *pol, char *name, LUID *luid)
968 prs_struct qbuf, rbuf;
969 LSA_Q_LOOKUPPRIVVALUE q;
970 LSA_R_LOOKUPPRIVVALUE r;
976 /* Initialise parse structures */
978 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
979 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
981 /* Marshall data and send request */
983 init_lsa_q_lookupprivvalue(&q, pol, name);
985 if (!lsa_io_q_lookupprivvalue("", &q, &qbuf, 0) ||
986 !rpc_api_pipe_req(cli, LSA_LOOKUPPRIVVALUE, &qbuf, &rbuf)) {
987 result = NT_STATUS_UNSUCCESSFUL;
991 /* Unmarshall response */
993 if (!lsa_io_r_lookupprivvalue("", &r, &rbuf, 0)) {
994 result = NT_STATUS_UNSUCCESSFUL;
998 if (!NT_STATUS_IS_OK(result = r.status)) {
1002 /* Return output parameters */
1004 (*luid).low=r.luid.low;
1005 (*luid).high=r.luid.high;
1008 prs_mem_free(&qbuf);
1009 prs_mem_free(&rbuf);
1014 /** Query LSA security object */
1016 NTSTATUS cli_lsa_query_secobj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1017 POLICY_HND *pol, uint32 sec_info,
1018 SEC_DESC_BUF **psdb)
1020 prs_struct qbuf, rbuf;
1021 LSA_Q_QUERY_SEC_OBJ q;
1022 LSA_R_QUERY_SEC_OBJ r;
1028 /* Initialise parse structures */
1030 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1031 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1033 /* Marshall data and send request */
1035 init_q_query_sec_obj(&q, pol, sec_info);
1037 if (!lsa_io_q_query_sec_obj("", &q, &qbuf, 0) ||
1038 !rpc_api_pipe_req(cli, LSA_QUERYSECOBJ, &qbuf, &rbuf)) {
1039 result = NT_STATUS_UNSUCCESSFUL;
1043 /* Unmarshall response */
1045 if (!lsa_io_r_query_sec_obj("", &r, &rbuf, 0)) {
1046 result = NT_STATUS_UNSUCCESSFUL;
1050 if (!NT_STATUS_IS_OK(result = r.status)) {
1054 /* Return output parameters */
1060 prs_mem_free(&qbuf);
1061 prs_mem_free(&rbuf);
1068 /** An example of how to use the routines in this file. Fetch a DOMAIN
1069 sid. Does complete cli setup / teardown anonymously. */
1071 BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid)
1073 extern pstring global_myname;
1074 struct cli_state cli;
1080 if(cli_initialise(&cli) == False) {
1081 DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
1085 if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
1086 DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
1090 if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
1091 DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
1092 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1096 if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
1097 DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
1102 cli.protocol = PROTOCOL_NT1;
1104 if (!cli_negprot(&cli)) {
1105 DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \
1106 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1110 if (cli.protocol != PROTOCOL_NT1) {
1111 DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
1117 * Do an anonymous session setup.
1120 if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
1121 DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \
1122 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1126 if (!(cli.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
1127 DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n",
1132 if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
1133 DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \
1134 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1138 /* Fetch domain sid */
1140 if (!cli_nt_session_open(&cli, PIPE_LSARPC)) {
1141 DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n"));
1145 result = cli_lsa_open_policy(&cli, cli.mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
1146 if (!NT_STATUS_IS_OK(result)) {
1147 DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n",
1148 nt_errstr(result) ));
1152 result = cli_lsa_query_info_policy(&cli, cli.mem_ctx, &lsa_pol, 5, domain, psid);
1153 if (!NT_STATUS_IS_OK(result)) {
1154 DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n",
1155 nt_errstr(result) ));