2 Unix SMB/Netbios 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.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /** @defgroup lsa LSA - Local Security Architecture
36 * RPC client routines for the LSA RPC pipe. LSA means "local
37 * security authority", which is half of a password database.
40 /** Opens a SMB connection and connects to the LSARPC pipe.
42 * @param cli Uninitialised client handle.
43 * @param system_name NETBIOS name of the machine to connect to.
44 * @param creds User credentials to connect as.
45 * @returns Initialised client handle.
47 struct cli_state *cli_lsa_initialise(struct cli_state *cli, char *system_name,
48 struct ntuser_creds *creds)
50 return cli_pipe_initialise(cli, system_name, PIPE_LSARPC, creds);
53 /** Open a LSA policy handle
55 * @param cli Handle on an initialised SMB connection */
57 NTSTATUS cli_lsa_open_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
58 BOOL sec_qos, uint32 des_access, POLICY_HND *pol)
60 prs_struct qbuf, rbuf;
69 /* Initialise parse structures */
71 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
72 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
74 /* Initialise input parameters */
77 init_lsa_sec_qos(&qos, 2, 1, 0);
78 init_q_open_pol(&q, '\\', 0, des_access, &qos);
80 init_q_open_pol(&q, '\\', 0, des_access, NULL);
83 /* Marshall data and send request */
85 if (!lsa_io_q_open_pol("", &q, &qbuf, 0) ||
86 !rpc_api_pipe_req(cli, LSA_OPENPOLICY, &qbuf, &rbuf)) {
87 result = NT_STATUS_UNSUCCESSFUL;
91 /* Unmarshall response */
93 if (!lsa_io_r_open_pol("", &r, &rbuf, 0)) {
94 result = NT_STATUS_UNSUCCESSFUL;
98 /* Return output parameters */
100 if (NT_STATUS_IS_OK(result = r.status)) {
111 /** Open a LSA policy handle */
113 NTSTATUS cli_lsa_open_policy2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
114 BOOL sec_qos, uint32 des_access, POLICY_HND *pol)
116 prs_struct qbuf, rbuf;
125 /* Initialise parse structures */
127 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
128 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
130 /* Initialise input parameters */
133 init_lsa_sec_qos(&qos, 2, 1, 0);
134 init_q_open_pol2(&q, cli->clnt_name_slash, 0, des_access,
137 init_q_open_pol2(&q, cli->clnt_name_slash, 0, des_access,
141 /* Marshall data and send request */
143 if (!lsa_io_q_open_pol2("", &q, &qbuf, 0) ||
144 !rpc_api_pipe_req(cli, LSA_OPENPOLICY2, &qbuf, &rbuf)) {
145 result = NT_STATUS_UNSUCCESSFUL;
149 /* Unmarshall response */
151 if (!lsa_io_r_open_pol2("", &r, &rbuf, 0)) {
152 result = NT_STATUS_UNSUCCESSFUL;
156 /* Return output parameters */
158 if (NT_STATUS_IS_OK(result = r.status)) {
169 /** Close a LSA policy handle */
171 NTSTATUS cli_lsa_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
174 prs_struct qbuf, rbuf;
182 /* Initialise parse structures */
184 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
185 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
187 /* Marshall data and send request */
189 init_lsa_q_close(&q, pol);
191 if (!lsa_io_q_close("", &q, &qbuf, 0) ||
192 !rpc_api_pipe_req(cli, LSA_CLOSE, &qbuf, &rbuf)) {
193 result = NT_STATUS_UNSUCCESSFUL;
197 /* Unmarshall response */
199 if (!lsa_io_r_close("", &r, &rbuf, 0)) {
200 result = NT_STATUS_UNSUCCESSFUL;
204 /* Return output parameters */
206 if (NT_STATUS_IS_OK(result = r.status)) {
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 ***names, uint32 **types, int *num_names)
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(NT_STATUS_FILES_OPEN)) {
266 /* An actual error occured */
272 /* Return output parameters */
274 if (r.mapped_count == 0) {
275 result = NT_STATUS_NONE_MAPPED;
279 (*num_names) = r.mapped_count;
280 result = NT_STATUS_OK;
282 if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) * r.mapped_count))) {
283 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
284 result = NT_STATUS_UNSUCCESSFUL;
288 if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count))) {
289 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
290 result = NT_STATUS_UNSUCCESSFUL;
294 for (i = 0; i < r.mapped_count; i++) {
295 fstring name, dom_name, full_name;
296 uint32 dom_idx = t_names.name[i].domain_idx;
298 /* Translate optimised name through domain index array */
300 if (dom_idx != 0xffffffff) {
302 rpcstr_pull_unistr2_fstring(
303 dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
304 rpcstr_pull_unistr2_fstring(
305 name, &t_names.uni_name[i]);
307 slprintf(full_name, sizeof(full_name) - 1,
309 (dom_name[0] && name[0]) ?
310 lp_winbind_separator() : "", name);
312 (*names)[i] = talloc_strdup(mem_ctx, full_name);
313 (*types)[i] = t_names.name[i].sid_name_use;
317 (*types)[i] = SID_NAME_UNKNOWN;
328 /** Lookup a list of names */
330 NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
331 POLICY_HND *pol, int num_names, const char **names,
332 DOM_SID **sids, uint32 **types, int *num_sids)
334 prs_struct qbuf, rbuf;
335 LSA_Q_LOOKUP_NAMES q;
336 LSA_R_LOOKUP_NAMES r;
344 /* Initialise parse structures */
346 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
347 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
349 /* Marshall data and send request */
351 init_q_lookup_names(mem_ctx, &q, pol, num_names, names);
353 if (!lsa_io_q_lookup_names("", &q, &qbuf, 0) ||
354 !rpc_api_pipe_req(cli, LSA_LOOKUPNAMES, &qbuf, &rbuf)) {
355 result = NT_STATUS_UNSUCCESSFUL;
359 /* Unmarshall response */
364 if (!lsa_io_r_lookup_names("", &r, &rbuf, 0)) {
365 result = NT_STATUS_UNSUCCESSFUL;
371 if (!NT_STATUS_IS_OK(result)) {
372 /* An actual error occured */
378 /* Return output parameters */
380 if (r.mapped_count == 0) {
381 result = NT_STATUS_NONE_MAPPED;
385 (*num_sids) = r.mapped_count;
386 result = NT_STATUS_OK;
388 if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.mapped_count)))) {
389 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
390 result = NT_STATUS_UNSUCCESSFUL;
394 if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count)))) {
395 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
396 result = NT_STATUS_UNSUCCESSFUL;
400 for (i = 0; i < r.mapped_count; i++) {
401 DOM_RID2 *t_rids = r.dom_rid;
402 uint32 dom_idx = t_rids[i].rid_idx;
403 uint32 dom_rid = t_rids[i].rid;
404 DOM_SID *sid = &(*sids)[i];
406 /* Translate optimised sid through domain index array */
408 if (dom_idx != 0xffffffff) {
410 sid_copy(sid, &ref.ref_dom[dom_idx].ref_dom.sid);
412 if (dom_rid != 0xffffffff) {
413 sid_append_rid(sid, dom_rid);
416 (*types)[i] = t_rids[i].type;
419 (*types)[i] = SID_NAME_UNKNOWN;
430 /** Query info policy */
432 NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
433 POLICY_HND *pol, uint16 info_class,
434 fstring domain_name, DOM_SID *domain_sid)
436 prs_struct qbuf, rbuf;
444 /* Initialise parse structures */
446 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
447 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
449 /* Marshall data and send request */
451 init_q_query(&q, pol, info_class);
453 if (!lsa_io_q_query("", &q, &qbuf, 0) ||
454 !rpc_api_pipe_req(cli, LSA_QUERYINFOPOLICY, &qbuf, &rbuf)) {
455 result = NT_STATUS_UNSUCCESSFUL;
459 /* Unmarshall response */
461 if (!lsa_io_r_query("", &r, &rbuf, 0)) {
462 result = NT_STATUS_UNSUCCESSFUL;
466 if (!NT_STATUS_IS_OK(result = r.status)) {
470 /* Return output parameters */
472 ZERO_STRUCTP(domain_sid);
473 domain_name[0] = '\0';
475 switch (info_class) {
478 if (r.dom.id3.buffer_dom_name != 0) {
479 unistr2_to_ascii(domain_name,
482 sizeof (fstring) - 1);
485 if (r.dom.id3.buffer_dom_sid != 0) {
486 *domain_sid = r.dom.id3.dom_sid.sid;
493 if (r.dom.id5.buffer_dom_name != 0) {
494 unistr2_to_ascii(domain_name, &r.dom.id5.
496 sizeof (fstring) - 1);
499 if (r.dom.id5.buffer_dom_sid != 0) {
500 *domain_sid = r.dom.id5.dom_sid.sid;
506 DEBUG(3, ("unknown info class %d\n", info_class));
517 /** Enumerate list of trusted domains */
519 NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx,
520 POLICY_HND *pol, uint32 *enum_ctx,
521 uint32 *num_domains, char ***domain_names,
522 DOM_SID **domain_sids)
524 prs_struct qbuf, rbuf;
525 LSA_Q_ENUM_TRUST_DOM q;
526 LSA_R_ENUM_TRUST_DOM r;
533 /* Initialise parse structures */
535 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
536 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
538 /* Marshall data and send request */
540 init_q_enum_trust_dom(&q, pol, *enum_ctx, 0xffffffff);
542 if (!lsa_io_q_enum_trust_dom("", &q, &qbuf, 0) ||
543 !rpc_api_pipe_req(cli, LSA_ENUMTRUSTDOM, &qbuf, &rbuf)) {
544 result = NT_STATUS_UNSUCCESSFUL;
548 /* Unmarshall response */
550 if (!lsa_io_r_enum_trust_dom("", &r, &rbuf, 0)) {
551 result = NT_STATUS_UNSUCCESSFUL;
557 if (!NT_STATUS_IS_OK(result) &&
558 NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_NO_MORE_ENTRIES)) {
560 /* An actual error ocured */
565 result = NT_STATUS_OK;
567 /* Return output parameters */
571 /* Allocate memory for trusted domain names and sids */
573 *domain_names = (char **)talloc(mem_ctx, sizeof(char *) *
576 if (!*domain_names) {
577 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
578 result = NT_STATUS_UNSUCCESSFUL;
582 *domain_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
585 DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
586 result = NT_STATUS_UNSUCCESSFUL;
590 /* Copy across names and sids */
592 for (i = 0; i < r.num_domains; i++) {
595 unistr2_to_ascii(tmp, &r.uni_domain_name[i],
597 (*domain_names)[i] = strdup(tmp);
598 sid_copy(&(*domain_sids)[i], &r.domain_sid[i].sid);
602 *num_domains = r.num_domains;
603 *enum_ctx = r.enum_context;
612 /** Enumerate privileges*/
614 NTSTATUS cli_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx,
615 POLICY_HND *pol, uint32 *enum_context, uint32 pref_max_length,
616 uint32 *count, char ***privs_name, uint32 **privs_high, uint32 **privs_low)
618 prs_struct qbuf, rbuf;
627 /* Initialise parse structures */
629 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
630 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
632 /* Marshall data and send request */
634 init_q_enum_privs(&q, pol, *enum_context, pref_max_length);
636 if (!lsa_io_q_enum_privs("", &q, &qbuf, 0) ||
637 !rpc_api_pipe_req(cli, LSA_ENUM_PRIVS, &qbuf, &rbuf)) {
638 result = NT_STATUS_UNSUCCESSFUL;
642 /* Unmarshall response */
644 if (!lsa_io_r_enum_privs("", &r, &rbuf, 0)) {
645 result = NT_STATUS_UNSUCCESSFUL;
649 if (!NT_STATUS_IS_OK(result = r.status)) {
653 /* Return output parameters */
655 *enum_context = r.enum_context;
658 if (!((*privs_name = (char **)talloc(mem_ctx, sizeof(char *) * r.count)))) {
659 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
660 result = NT_STATUS_UNSUCCESSFUL;
664 if (!((*privs_high = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
665 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
666 result = NT_STATUS_UNSUCCESSFUL;
670 if (!((*privs_low = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
671 DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
672 result = NT_STATUS_UNSUCCESSFUL;
676 for (i = 0; i < r.count; i++) {
679 rpcstr_pull_unistr2_fstring( name, &r.privs[i].name);
681 (*privs_name)[i] = talloc_strdup(mem_ctx, name);
683 (*privs_high)[i] = r.privs[i].luid_high;
684 (*privs_low)[i] = r.privs[i].luid_low;
694 /** Get privilege name */
696 NTSTATUS cli_lsa_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx,
697 POLICY_HND *pol, char *name, uint16 lang_id, uint16 lang_id_sys,
698 fstring description, uint16 *lang_id_desc)
700 prs_struct qbuf, rbuf;
701 LSA_Q_PRIV_GET_DISPNAME q;
702 LSA_R_PRIV_GET_DISPNAME r;
708 /* Initialise parse structures */
710 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
711 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
713 /* Marshall data and send request */
715 init_lsa_priv_get_dispname(&q, pol, name, lang_id, lang_id_sys);
717 if (!lsa_io_q_priv_get_dispname("", &q, &qbuf, 0) ||
718 !rpc_api_pipe_req(cli, LSA_PRIV_GET_DISPNAME, &qbuf, &rbuf)) {
719 result = NT_STATUS_UNSUCCESSFUL;
723 /* Unmarshall response */
725 if (!lsa_io_r_priv_get_dispname("", &r, &rbuf, 0)) {
726 result = NT_STATUS_UNSUCCESSFUL;
730 if (!NT_STATUS_IS_OK(result = r.status)) {
734 /* Return output parameters */
736 rpcstr_pull_unistr2_fstring(description , &r.desc);
737 *lang_id_desc = r.lang_id;
746 /** Enumerate list of SIDs */
748 NTSTATUS cli_lsa_enum_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
749 POLICY_HND *pol, uint32 *enum_ctx, uint32 pref_max_length,
750 uint32 *num_sids, DOM_SID **sids)
752 prs_struct qbuf, rbuf;
753 LSA_Q_ENUM_ACCOUNTS q;
754 LSA_R_ENUM_ACCOUNTS r;
761 /* Initialise parse structures */
763 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
764 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
766 /* Marshall data and send request */
768 init_lsa_q_enum_accounts(&q, pol, *enum_ctx, pref_max_length);
770 if (!lsa_io_q_enum_accounts("", &q, &qbuf, 0) ||
771 !rpc_api_pipe_req(cli, LSA_ENUM_ACCOUNTS, &qbuf, &rbuf)) {
772 result = NT_STATUS_UNSUCCESSFUL;
776 /* Unmarshall response */
778 if (!lsa_io_r_enum_accounts("", &r, &rbuf, 0)) {
779 result = NT_STATUS_UNSUCCESSFUL;
785 if (!NT_STATUS_IS_OK(result = r.status)) {
789 if (r.sids.num_entries==0)
792 /* Return output parameters */
794 *sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.sids.num_entries);
796 DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
797 result = NT_STATUS_UNSUCCESSFUL;
801 /* Copy across names and sids */
803 for (i = 0; i < r.sids.num_entries; i++) {
804 sid_copy(&(*sids)[i], &r.sids.sid[i].sid);
807 *num_sids= r.sids.num_entries;
808 *enum_ctx = r.enum_context;
817 /** Open a LSA user handle
819 * @param cli Handle on an initialised SMB connection */
821 NTSTATUS cli_lsa_open_account(struct cli_state *cli, TALLOC_CTX *mem_ctx,
822 POLICY_HND *dom_pol, DOM_SID *sid, uint32 des_access,
823 POLICY_HND *user_pol)
825 prs_struct qbuf, rbuf;
833 /* Initialise parse structures */
835 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
836 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
838 /* Initialise input parameters */
840 init_lsa_q_open_account(&q, dom_pol, sid, des_access);
842 /* Marshall data and send request */
844 if (!lsa_io_q_open_account("", &q, &qbuf, 0) ||
845 !rpc_api_pipe_req(cli, LSA_OPENACCOUNT, &qbuf, &rbuf)) {
846 result = NT_STATUS_UNSUCCESSFUL;
850 /* Unmarshall response */
852 if (!lsa_io_r_open_account("", &r, &rbuf, 0)) {
853 result = NT_STATUS_UNSUCCESSFUL;
857 /* Return output parameters */
859 if (NT_STATUS_IS_OK(result = r.status)) {
870 /** Enumerate user privileges
872 * @param cli Handle on an initialised SMB connection */
874 NTSTATUS cli_lsa_enum_privsaccount(struct cli_state *cli, TALLOC_CTX *mem_ctx,
875 POLICY_HND *pol, uint32 *count, LUID_ATTR **set)
877 prs_struct qbuf, rbuf;
878 LSA_Q_ENUMPRIVSACCOUNT q;
879 LSA_R_ENUMPRIVSACCOUNT r;
886 /* Initialise parse structures */
888 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
889 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
891 /* Initialise input parameters */
893 init_lsa_q_enum_privsaccount(&q, pol);
895 /* Marshall data and send request */
897 if (!lsa_io_q_enum_privsaccount("", &q, &qbuf, 0) ||
898 !rpc_api_pipe_req(cli, LSA_ENUMPRIVSACCOUNT, &qbuf, &rbuf)) {
899 result = NT_STATUS_UNSUCCESSFUL;
903 /* Unmarshall response */
905 if (!lsa_io_r_enum_privsaccount("", &r, &rbuf, 0)) {
906 result = NT_STATUS_UNSUCCESSFUL;
910 /* Return output parameters */
912 if (!NT_STATUS_IS_OK(result = r.status)) {
919 if (!((*set = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR) * r.count)))) {
920 DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
921 result = NT_STATUS_UNSUCCESSFUL;
925 for (i=0; i<r.count; i++) {
926 (*set)[i].luid.low = r.set.set[i].luid.low;
927 (*set)[i].luid.high = r.set.set[i].luid.high;
928 (*set)[i].attr = r.set.set[i].attr;
939 /** Get a privilege value given its name */
941 NTSTATUS cli_lsa_lookupprivvalue(struct cli_state *cli, TALLOC_CTX *mem_ctx,
942 POLICY_HND *pol, char *name, LUID *luid)
944 prs_struct qbuf, rbuf;
945 LSA_Q_LOOKUPPRIVVALUE q;
946 LSA_R_LOOKUPPRIVVALUE r;
952 /* Initialise parse structures */
954 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
955 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
957 /* Marshall data and send request */
959 init_lsa_q_lookupprivvalue(&q, pol, name);
961 if (!lsa_io_q_lookupprivvalue("", &q, &qbuf, 0) ||
962 !rpc_api_pipe_req(cli, LSA_LOOKUPPRIVVALUE, &qbuf, &rbuf)) {
963 result = NT_STATUS_UNSUCCESSFUL;
967 /* Unmarshall response */
969 if (!lsa_io_r_lookupprivvalue("", &r, &rbuf, 0)) {
970 result = NT_STATUS_UNSUCCESSFUL;
974 if (!NT_STATUS_IS_OK(result = r.status)) {
978 /* Return output parameters */
980 (*luid).low=r.luid.low;
981 (*luid).high=r.luid.high;
990 /** Query LSA security object */
992 NTSTATUS cli_lsa_query_secobj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
993 POLICY_HND *pol, uint32 sec_info,
996 prs_struct qbuf, rbuf;
997 LSA_Q_QUERY_SEC_OBJ q;
998 LSA_R_QUERY_SEC_OBJ r;
1004 /* Initialise parse structures */
1006 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1007 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1009 /* Marshall data and send request */
1011 init_q_query_sec_obj(&q, pol, sec_info);
1013 if (!lsa_io_q_query_sec_obj("", &q, &qbuf, 0) ||
1014 !rpc_api_pipe_req(cli, LSA_QUERYSECOBJ, &qbuf, &rbuf)) {
1015 result = NT_STATUS_UNSUCCESSFUL;
1019 /* Unmarshall response */
1021 if (!lsa_io_r_query_sec_obj("", &r, &rbuf, 0)) {
1022 result = NT_STATUS_UNSUCCESSFUL;
1026 if (!NT_STATUS_IS_OK(result = r.status)) {
1030 /* Return output parameters */
1036 prs_mem_free(&qbuf);
1037 prs_mem_free(&rbuf);
1042 /** Fetch a DOMAIN sid. Does complete cli setup / teardown anonymously. */
1044 BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid)
1046 extern pstring global_myname;
1047 struct cli_state cli;
1053 if(cli_initialise(&cli) == False) {
1054 DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
1058 if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
1059 DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
1063 if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
1064 DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
1065 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1069 if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
1070 DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS \
1071 session request. Error was %s\n", remote_machine, cli_errstr(&cli) ));
1075 cli.protocol = PROTOCOL_NT1;
1077 if (!cli_negprot(&cli)) {
1078 DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \
1079 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1083 if (cli.protocol != PROTOCOL_NT1) {
1084 DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
1090 * Do an anonymous session setup.
1093 if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
1094 DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \
1095 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1099 if (!(cli.sec_mode & 1)) {
1100 DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n",
1105 if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
1106 DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \
1107 Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1111 /* Fetch domain sid */
1113 if (!cli_nt_session_open(&cli, PIPE_LSARPC)) {
1114 DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n"));
1118 result = cli_lsa_open_policy(&cli, cli.mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
1119 if (!NT_STATUS_IS_OK(result)) {
1120 DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n",
1121 get_nt_error_msg(result) ));
1125 result = cli_lsa_query_info_policy(&cli, cli.mem_ctx, &lsa_pol, 5, domain, psid);
1126 if (!NT_STATUS_IS_OK(result)) {
1127 DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n",
1128 get_nt_error_msg(result) ));