3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8 * Copyright (C) Paul Ashton 1997.
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.
32 extern int DEBUGLEVEL;
35 /****************************************************************************
37 ****************************************************************************/
38 BOOL do_lsa_open_policy(struct cli_state *cli,
39 char *server_name, POLICY_HND *hnd,
46 BOOL valid_pol = False;
48 if (hnd == NULL) return False;
50 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
51 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
53 /* create and send a MSRPC command with api LSA_OPENPOLICY */
55 DEBUG(4,("LSA Open Policy\n"));
57 /* store the parameters */
60 make_lsa_sec_qos(&qos, 2, 1, 0, 0x20000000);
61 make_q_open_pol(&q_o, 0x5c, 0, 0, &qos);
65 make_q_open_pol(&q_o, 0x5c, 0, 0x1, NULL);
68 /* turn parameters into data stream */
69 lsa_io_q_open_pol("", &q_o, &buf, 0);
71 /* send the data on \PIPE\ */
72 if (rpc_api_pipe_req(cli, LSA_OPENPOLICY, &buf, &rbuf))
77 lsa_io_r_open_pol("", &r_o, &rbuf, 0);
80 if (p && r_o.status != 0)
82 /* report error code */
83 DEBUG(0,("LSA_OPENPOLICY: %s\n", get_nt_error_msg(r_o.status)));
89 /* ok, at last: we're happy. return the policy handle */
90 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
101 /****************************************************************************
103 ****************************************************************************/
104 BOOL do_lsa_lookup_sids(struct cli_state *cli,
113 LSA_Q_LOOKUP_SIDS q_l;
114 BOOL valid_response = False;
116 if (hnd == NULL || num_sids == 0 || sids == NULL) return False;
118 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
119 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
121 /* create and send a MSRPC command with api LSA_LOOKUP_SIDS */
123 DEBUG(4,("LSA Lookup SIDs\n"));
125 /* store the parameters */
126 make_q_lookup_sids(&q_l, hnd, num_sids, sids, 1);
128 /* turn parameters into data stream */
129 lsa_io_q_lookup_sids("", &q_l, &buf, 0);
131 /* send the data on \PIPE\ */
132 if (rpc_api_pipe_req(cli, LSA_LOOKUPSIDS, &buf, &rbuf))
134 LSA_R_LOOKUP_SIDS r_l;
136 LSA_TRANS_NAME_ENUM t_names;
140 r_l.names = &t_names;
142 lsa_io_r_lookup_sids("", &r_l, &rbuf, 0);
143 p = rbuf.offset != 0;
145 if (p && r_l.status != 0)
147 /* report error code */
148 DEBUG(0,("LSA_LOOKUP_SIDS: %s\n", get_nt_error_msg(r_l.status)));
154 if (t_names.ptr_trans_names != 0 && ref.undoc_buffer != 0)
156 valid_response = True;
160 if (num_names != NULL && valid_response)
162 (*num_names) = t_names.num_entries;
167 for (i = 0; i < t_names.num_entries; i++)
169 if (t_names.name[i].domain_idx >= ref.num_ref_doms_1)
171 DEBUG(0,("LSA_LOOKUP_SIDS: domain index out of bounds\n"));
172 valid_response = False;
178 if (names != NULL && valid_response && t_names.num_entries != 0)
180 (*names) = (char**)malloc((*num_names) * sizeof(char*));
183 if (names != NULL && (*names) != NULL)
186 /* take each name, construct a \DOMAIN\name string */
187 for (i = 0; i < (*num_names); i++)
192 uint32 dom_idx = t_names.name[i].domain_idx;
193 fstrcpy(dom_name, unistr2(ref.ref_dom[dom_idx].uni_dom_name.buffer));
194 fstrcpy(name , unistr2(t_names.uni_name[i].buffer));
196 slprintf(full_name, sizeof(full_name)-1, "\\%s\\%s",
199 (*names)[i] = strdup(full_name);
207 return valid_response;
210 /****************************************************************************
211 do a LSA Query Info Policy
212 ****************************************************************************/
213 BOOL do_lsa_query_info_pol(struct cli_state *cli,
214 POLICY_HND *hnd, uint16 info_class,
215 fstring domain_name, DOM_SID *domain_sid)
219 LSA_Q_QUERY_INFO q_q;
220 BOOL valid_response = False;
222 ZERO_STRUCTP(domain_sid);
225 if (hnd == NULL || domain_name == NULL || domain_sid == NULL) return False;
227 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
228 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
230 /* create and send a MSRPC command with api LSA_QUERYINFOPOLICY */
232 DEBUG(4,("LSA Query Info Policy\n"));
234 /* store the parameters */
235 make_q_query(&q_q, hnd, info_class);
237 /* turn parameters into data stream */
238 lsa_io_q_query("", &q_q, &buf, 0);
240 /* send the data on \PIPE\ */
241 if (rpc_api_pipe_req(cli, LSA_QUERYINFOPOLICY, &buf, &rbuf))
243 LSA_R_QUERY_INFO r_q;
246 lsa_io_r_query("", &r_q, &rbuf, 0);
247 p = rbuf.offset != 0;
249 if (p && r_q.status != 0)
251 /* report error code */
252 DEBUG(0,("LSA_QUERYINFOPOLICY: %s\n", get_nt_error_msg(r_q.status)));
256 if (p && r_q.info_class != q_q.info_class)
258 /* report different info classes */
259 DEBUG(0,("LSA_QUERYINFOPOLICY: error info_class (q,r) differ - (%x,%x)\n",
260 q_q.info_class, r_q.info_class));
267 /* ok, at last: we're happy. */
268 switch (r_q.info_class)
272 if (r_q.dom.id3.buffer_dom_name != 0)
274 char *dom_name = unistrn2(r_q.dom.id3.uni_domain_name.buffer,
275 r_q.dom.id3.uni_domain_name.uni_str_len);
276 fstrcpy(domain_name, dom_name);
278 if (r_q.dom.id3.buffer_dom_sid != 0)
280 *domain_sid = r_q.dom.id3.dom_sid.sid;
283 valid_response = True;
288 if (r_q.dom.id5.buffer_dom_name != 0)
290 char *dom_name = unistrn2(r_q.dom.id5.uni_domain_name.buffer,
291 r_q.dom.id5.uni_domain_name.uni_str_len);
292 fstrcpy(domain_name, dom_name);
294 if (r_q.dom.id5.buffer_dom_sid != 0)
296 *domain_sid = r_q.dom.id5.dom_sid.sid;
299 valid_response = True;
304 DEBUG(3,("LSA_QUERYINFOPOLICY: unknown info class\n"));
311 sid_to_string(sid_str, domain_sid);
312 DEBUG(3,("LSA_QUERYINFOPOLICY (level %x): domain:%s domain sid:%s\n",
313 r_q.info_class, domain_name, sid_str));
320 return valid_response;
323 /****************************************************************************
325 ****************************************************************************/
326 BOOL do_lsa_close(struct cli_state *cli, POLICY_HND *hnd)
331 BOOL valid_close = False;
333 if (hnd == NULL) return False;
335 /* create and send a MSRPC command with api LSA_OPENPOLICY */
337 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
338 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
340 DEBUG(4,("LSA Close\n"));
342 /* store the parameters */
343 make_lsa_q_close(&q_c, hnd);
345 /* turn parameters into data stream */
346 lsa_io_q_close("", &q_c, &buf, 0);
348 /* send the data on \PIPE\ */
349 if (rpc_api_pipe_req(cli, LSA_CLOSE, &buf, &rbuf))
354 lsa_io_r_close("", &r_c, &rbuf, 0);
355 p = rbuf.offset != 0;
357 if (p && r_c.status != 0)
359 /* report error code */
360 DEBUG(0,("LSA_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
366 /* check that the returned policy handle is all zeros */
370 for (i = 0; i < sizeof(r_c.pol.data); i++)
372 if (r_c.pol.data[i] != 0)
380 DEBUG(0,("LSA_CLOSE: non-zero handle returned\n"));