3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1998,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
8 * Copyright (C) Paul Ashton 1997-1998.
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;
34 /****************************************************************************
36 ****************************************************************************/
37 BOOL svc_open_sc_man(struct cli_state *cli, uint16 fnum,
38 char *srv_name, char *db_name,
44 SVC_Q_OPEN_SC_MAN q_o;
45 BOOL valid_pol = False;
47 if (hnd == NULL) return False;
49 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
50 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
52 /* create and send a MSRPC command with api SVC_OPEN_SC_MAN */
54 DEBUG(4,("SVC Open SC_MAN\n"));
56 make_svc_q_open_sc_man(&q_o, srv_name, db_name, des_access);
58 /* turn parameters into data stream */
59 svc_io_q_open_sc_man("", &q_o, &buf, 0);
61 /* send the data on \PIPE\ */
62 if (rpc_api_pipe_req(cli, fnum, SVC_OPEN_SC_MAN, &buf, &rbuf))
64 SVC_R_OPEN_SC_MAN r_o;
69 svc_io_r_open_sc_man("", &r_o, &rbuf, 0);
72 if (p && r_o.status != 0)
74 /* report error code */
75 DEBUG(1,("SVC_OPEN_SC_MAN: %s\n", get_nt_error_msg(r_o.status)));
81 /* ok, at last: we're happy. return the policy handle */
82 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
94 /****************************************************************************
96 ****************************************************************************/
97 BOOL svc_open_service(struct cli_state *cli, uint16 fnum,
105 SVC_Q_OPEN_SERVICE q_o;
106 BOOL valid_pol = False;
108 if (hnd == NULL || scm_hnd == NULL) return False;
110 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
111 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
113 /* create and send a MSRPC command with api SVC_OPEN_SERVICE */
115 DEBUG(4,("SVC Open Service\n"));
117 make_svc_q_open_service(&q_o, scm_hnd, srv_name, des_access);
119 /* turn parameters into data stream */
120 svc_io_q_open_service("", &q_o, &buf, 0);
122 /* send the data on \PIPE\ */
123 if (rpc_api_pipe_req(cli, fnum, SVC_OPEN_SERVICE, &buf, &rbuf))
125 SVC_R_OPEN_SERVICE r_o;
130 svc_io_r_open_service("", &r_o, &rbuf, 0);
131 p = rbuf.offset != 0;
133 if (p && r_o.status != 0)
135 /* report error code */
136 DEBUG(1,("SVC_OPEN_SC_MAN: %s\n", get_nt_error_msg(r_o.status)));
142 /* ok, at last: we're happy. return the policy handle */
143 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
155 /****************************************************************************
156 do a SVC Enumerate Services
157 ****************************************************************************/
158 BOOL svc_enum_svcs(struct cli_state *cli, uint16 fnum,
160 uint32 services_type, uint32 services_state,
161 uint32 *buf_size, uint32 *resume_hnd,
163 ENUM_SRVC_STATUS **svcs, uint32 *num_svcs)
167 SVC_Q_ENUM_SVCS_STATUS q_o;
168 BOOL valid_pol = False;
170 if (hnd == NULL || buf_size == NULL || dos_error == NULL || num_svcs == NULL)
175 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
176 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
178 /* create and send a MSRPC command with api SVC_ENUM_SVCS_STATUS */
180 DEBUG(4,("SVC Enum Services Status\n"));
182 make_svc_q_enum_svcs_status(&q_o, hnd,
183 services_type, services_state,
184 *buf_size, *resume_hnd);
186 /* turn parameters into data stream */
187 svc_io_q_enum_svcs_status("", &q_o, &buf, 0);
189 /* send the data on \PIPE\ */
190 if (rpc_api_pipe_req(cli, fnum, SVC_ENUM_SVCS_STATUS, &buf, &rbuf))
192 SVC_R_ENUM_SVCS_STATUS r_o;
197 svc_io_r_enum_svcs_status("", &r_o, &rbuf, 0);
198 p = rbuf.offset != 0;
200 if (p && r_o.dos_status != 0)
204 if (r_o.dos_status != ERRmoredata)
206 smb_safe_err_msg(ERRDOS, r_o.dos_status,
207 errmsg, sizeof(errmsg));
208 /* report error code */
209 DEBUG(1,("SVC_ENUM_SVCS_STATUS: %s\n", errmsg));
211 p = r_o.dos_status == ERRmoredata;
217 (*num_svcs) = r_o.num_svcs;
218 (*resume_hnd) = get_enum_hnd(&r_o.resume_hnd);
219 (*buf_size) = r_o.more_buf_size;
220 (*dos_error) = r_o.dos_status;
232 /****************************************************************************
233 do a SVC Query Service Config
234 ****************************************************************************/
235 BOOL svc_query_svc_cfg(struct cli_state *cli, uint16 fnum,
237 QUERY_SERVICE_CONFIG *cfg,
242 SVC_Q_QUERY_SVC_CONFIG q_c;
243 BOOL valid_cfg = False;
245 if (hnd == NULL || buf_size == NULL) return False;
247 /* create and send a MSRPC command with api SVC_QUERY_SVC_CONFIG */
249 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
250 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
252 DEBUG(4,("SVC Query Service Config\n"));
254 /* store the parameters */
255 make_svc_q_query_svc_config(&q_c, hnd, *buf_size);
257 /* turn parameters into data stream */
258 svc_io_q_query_svc_config("", &q_c, &buf, 0);
260 /* send the data on \PIPE\ */
261 if (rpc_api_pipe_req(cli, fnum, SVC_QUERY_SVC_CONFIG, &buf, &rbuf))
263 SVC_R_QUERY_SVC_CONFIG r_c;
271 svc_io_r_query_svc_config("", &r_c, &rbuf, 0);
272 p = rbuf.offset != 0;
274 if (p && r_c.status != 0)
276 /* report error code */
277 DEBUG(1,("SVC_QUERY_SVC_CONFIG: %s\n", get_nt_error_msg(r_c.status)));
283 valid_cfg = r_c.buf_size != 0;
294 /****************************************************************************
296 ****************************************************************************/
297 BOOL svc_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
302 BOOL valid_close = False;
304 if (hnd == NULL) return False;
306 /* create and send a MSRPC command with api SVC_CLOSE */
308 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
309 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
311 DEBUG(4,("SVC Close\n"));
313 /* store the parameters */
314 make_svc_q_close(&q_c, hnd);
316 /* turn parameters into data stream */
317 svc_io_q_close("", &q_c, &buf, 0);
319 /* send the data on \PIPE\ */
320 if (rpc_api_pipe_req(cli, fnum, SVC_CLOSE, &buf, &rbuf))
327 svc_io_r_close("", &r_c, &rbuf, 0);
328 p = rbuf.offset != 0;
330 if (p && r_c.status != 0)
332 /* report error code */
333 DEBUG(1,("SVC_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
339 /* check that the returned policy handle is all zeros */
343 for (i = 0; i < sizeof(r_c.pol.data); i++)
345 if (r_c.pol.data[i] != 0)
353 DEBUG(1,("SVC_CLOSE: non-zero handle returned\n"));