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, int t_idx, uint16 fnum,
39 char *server_name, POLICY_HND *hnd)
44 BOOL valid_pol = False;
46 if (hnd == NULL) return False;
48 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
49 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
51 /* create and send a MSRPC command with api LSA_OPENPOLICY */
53 DEBUG(4,("LSA Open Policy\n"));
55 /* store the parameters */
56 make_q_open_pol(&q_o, server_name, 0, 0, 0x1);
58 /* turn parameters into data stream */
59 lsa_io_q_open_pol("", &q_o, &buf, 0);
61 /* send the data on \PIPE\ */
62 if (rpc_api_pipe_req(cli, t_idx, fnum, LSA_OPENPOLICY, &buf, &rbuf))
67 lsa_io_r_open_pol("", &r_o, &rbuf, 0);
70 if (p && r_o.status != 0)
72 /* report error code */
73 DEBUG(0,("LSA_OPENPOLICY: %s\n", get_nt_error_msg(r_o.status)));
79 /* ok, at last: we're happy. return the policy handle */
80 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
91 /****************************************************************************
92 do a LSA Query Info Policy
93 ****************************************************************************/
94 BOOL do_lsa_query_info_pol(struct cli_state *cli, int t_idx, uint16 fnum,
95 POLICY_HND *hnd, uint16 info_class,
96 fstring domain_name, fstring domain_sid)
100 LSA_Q_QUERY_INFO q_q;
101 BOOL valid_response = False;
103 if (hnd == NULL || domain_name == NULL || domain_sid == NULL) return False;
105 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
106 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
108 /* create and send a MSRPC command with api LSA_QUERYINFOPOLICY */
110 DEBUG(4,("LSA Query Info Policy\n"));
112 /* store the parameters */
113 make_q_query(&q_q, hnd, info_class);
115 /* turn parameters into data stream */
116 lsa_io_q_query("", &q_q, &buf, 0);
118 /* send the data on \PIPE\ */
119 if (rpc_api_pipe_req(cli, t_idx, fnum, LSA_QUERYINFOPOLICY, &buf, &rbuf))
121 LSA_R_QUERY_INFO r_q;
124 lsa_io_r_query("", &r_q, &rbuf, 0);
125 p = rbuf.offset != 0;
127 if (p && r_q.status != 0)
129 /* report error code */
130 DEBUG(0,("LSA_QUERYINFOPOLICY: %s\n", get_nt_error_msg(r_q.status)));
134 if (p && r_q.info_class != q_q.info_class)
136 /* report different info classes */
137 DEBUG(0,("LSA_QUERYINFOPOLICY: error info_class (q,r) differ - (%x,%x)\n",
138 q_q.info_class, r_q.info_class));
144 /* ok, at last: we're happy. */
145 switch (r_q.info_class)
149 char *dom_name = unistrn2(r_q.dom.id3.uni_domain_name.buffer,
150 r_q.dom.id3.uni_domain_name.uni_str_len);
151 char *dom_sid = dom_sid_to_string(&(r_q.dom.id3.dom_sid.sid));
152 fstrcpy(domain_name, dom_name);
153 pstrcpy(domain_sid , dom_sid);
155 valid_response = True;
160 char *dom_name = unistrn2(r_q.dom.id5.uni_domain_name.buffer,
161 r_q.dom.id5.uni_domain_name.uni_str_len);
162 char *dom_sid = dom_sid_to_string(&(r_q.dom.id5.dom_sid.sid));
163 fstrcpy(domain_name, dom_name);
164 pstrcpy(domain_sid , dom_sid);
166 valid_response = True;
171 DEBUG(3,("LSA_QUERYINFOPOLICY: unknown info class\n"));
178 DEBUG(3,("LSA_QUERYINFOPOLICY (level %x): domain:%s domain sid:%s\n",
179 r_q.info_class, domain_name, domain_sid));
186 return valid_response;
189 /****************************************************************************
191 ****************************************************************************/
192 BOOL do_lsa_close(struct cli_state *cli, int t_idx, uint16 fnum, POLICY_HND *hnd)
197 BOOL valid_close = False;
199 if (hnd == NULL) return False;
201 /* create and send a MSRPC command with api LSA_OPENPOLICY */
203 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
204 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
206 DEBUG(4,("LSA Close\n"));
208 /* store the parameters */
209 make_lsa_q_close(&q_c, hnd);
211 /* turn parameters into data stream */
212 lsa_io_q_close("", &q_c, &buf, 0);
214 /* send the data on \PIPE\ */
215 if (rpc_api_pipe_req(cli, t_idx, fnum, LSA_CLOSE, &buf, &rbuf))
220 lsa_io_r_close("", &r_c, &rbuf, 0);
221 p = rbuf.offset != 0;
223 if (p && r_c.status != 0)
225 /* report error code */
226 DEBUG(0,("LSA_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
232 /* check that the returned policy handle is all zeros */
236 for (i = 0; i < sizeof(r_c.pol.data); i++)
238 if (r_c.pol.data[i] != 0)
246 DEBUG(0,("LSA_CLOSE: non-zero handle returned\n"));