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)
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, 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,
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, 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 fstrcpy(domain_name, dom_name);
152 sid_to_string(domain_sid, &(r_q.dom.id3.dom_sid.sid));
154 valid_response = True;
159 char *dom_name = unistrn2(r_q.dom.id5.uni_domain_name.buffer,
160 r_q.dom.id5.uni_domain_name.uni_str_len);
161 fstrcpy(domain_name, dom_name);
162 sid_to_string(domain_sid, &(r_q.dom.id5.dom_sid.sid));
164 valid_response = True;
169 DEBUG(3,("LSA_QUERYINFOPOLICY: unknown info class\n"));
176 DEBUG(3,("LSA_QUERYINFOPOLICY (level %x): domain:%s domain sid:%s\n",
177 r_q.info_class, domain_name, domain_sid));
184 return valid_response;
187 /****************************************************************************
189 ****************************************************************************/
190 BOOL do_lsa_close(struct cli_state *cli, POLICY_HND *hnd)
195 BOOL valid_close = False;
197 if (hnd == NULL) return False;
199 /* create and send a MSRPC command with api LSA_OPENPOLICY */
201 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
202 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
204 DEBUG(4,("LSA Close\n"));
206 /* store the parameters */
207 make_lsa_q_close(&q_c, hnd);
209 /* turn parameters into data stream */
210 lsa_io_q_close("", &q_c, &buf, 0);
212 /* send the data on \PIPE\ */
213 if (rpc_api_pipe_req(cli, LSA_CLOSE, &buf, &rbuf))
218 lsa_io_r_close("", &r_c, &rbuf, 0);
219 p = rbuf.offset != 0;
221 if (p && r_c.status != 0)
223 /* report error code */
224 DEBUG(0,("LSA_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
230 /* check that the returned policy handle is all zeros */
234 for (i = 0; i < sizeof(r_c.pol.data); i++)
236 if (r_c.pol.data[i] != 0)
244 DEBUG(0,("LSA_CLOSE: non-zero handle returned\n"));