tiny simplification
[Samba/gebeck_regimport.git] / source3 / rpc_server / srv_svcctl.c
blobce81a242027d1a2df05fa952c019d9be3ea3337b
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Gerald Carter 2005 - 2007
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
22 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_RPC_SRV
25 static bool proxy_svcctl_call(pipes_struct *p, uint8 opnum)
27 struct api_struct *fns;
28 int n_fns;
30 svcctl_get_pipe_fns(&fns, &n_fns);
32 if (opnum >= n_fns)
33 return False;
35 if (fns[opnum].opnum != opnum) {
36 smb_panic("SVCCTL function table not sorted\n");
39 return fns[opnum].fn(p);
43 /*******************************************************************
44 ********************************************************************/
46 static bool api_svcctl_close_service(pipes_struct *p)
48 return proxy_svcctl_call( p, NDR_SVCCTL_CLOSESERVICEHANDLE );
51 /*******************************************************************
52 ********************************************************************/
54 static bool api_svcctl_open_scmanager(pipes_struct *p)
56 SVCCTL_Q_OPEN_SCMANAGER q_u;
57 SVCCTL_R_OPEN_SCMANAGER r_u;
58 prs_struct *data = &p->in_data.data;
59 prs_struct *rdata = &p->out_data.rdata;
61 ZERO_STRUCT(q_u);
62 ZERO_STRUCT(r_u);
64 if(!svcctl_io_q_open_scmanager("", &q_u, data, 0))
65 return False;
67 r_u.status = _svcctl_open_scmanager(p, &q_u, &r_u);
69 if(!svcctl_io_r_open_scmanager("", &r_u, rdata, 0))
70 return False;
72 return True;
75 /*******************************************************************
76 ********************************************************************/
78 static bool api_svcctl_open_service(pipes_struct *p)
80 SVCCTL_Q_OPEN_SERVICE q_u;
81 SVCCTL_R_OPEN_SERVICE r_u;
82 prs_struct *data = &p->in_data.data;
83 prs_struct *rdata = &p->out_data.rdata;
85 ZERO_STRUCT(q_u);
86 ZERO_STRUCT(r_u);
88 if(!svcctl_io_q_open_service("", &q_u, data, 0))
89 return False;
91 r_u.status = _svcctl_open_service(p, &q_u, &r_u);
93 if(!svcctl_io_r_open_service("", &r_u, rdata, 0))
94 return False;
96 return True;
99 /*******************************************************************
100 ********************************************************************/
102 static bool api_svcctl_get_display_name(pipes_struct *p)
104 SVCCTL_Q_GET_DISPLAY_NAME q_u;
105 SVCCTL_R_GET_DISPLAY_NAME r_u;
106 prs_struct *data = &p->in_data.data;
107 prs_struct *rdata = &p->out_data.rdata;
109 ZERO_STRUCT(q_u);
110 ZERO_STRUCT(r_u);
112 if(!svcctl_io_q_get_display_name("", &q_u, data, 0))
113 return False;
115 r_u.status = _svcctl_get_display_name(p, &q_u, &r_u);
117 if(!svcctl_io_r_get_display_name("", &r_u, rdata, 0))
118 return False;
120 return True;
123 /*******************************************************************
124 ********************************************************************/
126 static bool api_svcctl_query_status(pipes_struct *p)
128 SVCCTL_Q_QUERY_STATUS q_u;
129 SVCCTL_R_QUERY_STATUS r_u;
130 prs_struct *data = &p->in_data.data;
131 prs_struct *rdata = &p->out_data.rdata;
133 ZERO_STRUCT(q_u);
134 ZERO_STRUCT(r_u);
136 if(!svcctl_io_q_query_status("", &q_u, data, 0))
137 return False;
139 r_u.status = _svcctl_query_status(p, &q_u, &r_u);
141 if(!svcctl_io_r_query_status("", &r_u, rdata, 0))
142 return False;
144 return True;
147 /*******************************************************************
148 ********************************************************************/
150 static bool api_svcctl_enum_services_status(pipes_struct *p)
152 SVCCTL_Q_ENUM_SERVICES_STATUS q_u;
153 SVCCTL_R_ENUM_SERVICES_STATUS r_u;
154 prs_struct *data = &p->in_data.data;
155 prs_struct *rdata = &p->out_data.rdata;
157 ZERO_STRUCT(q_u);
158 ZERO_STRUCT(r_u);
160 if(!svcctl_io_q_enum_services_status("", &q_u, data, 0))
161 return False;
163 r_u.status = _svcctl_enum_services_status(p, &q_u, &r_u);
165 if(!svcctl_io_r_enum_services_status("", &r_u, rdata, 0))
166 return False;
168 return True;
170 /*******************************************************************
171 ********************************************************************/
173 static bool api_svcctl_query_service_status_ex(pipes_struct *p)
175 SVCCTL_Q_QUERY_SERVICE_STATUSEX q_u;
176 SVCCTL_R_QUERY_SERVICE_STATUSEX r_u;
177 prs_struct *data = &p->in_data.data;
178 prs_struct *rdata = &p->out_data.rdata;
180 ZERO_STRUCT(q_u);
181 ZERO_STRUCT(r_u);
183 if(!svcctl_io_q_query_service_status_ex("", &q_u, data, 0))
184 return False;
186 r_u.status = _svcctl_query_service_status_ex(p, &q_u, &r_u);
188 if(!svcctl_io_r_query_service_status_ex("", &r_u, rdata, 0))
189 return False;
191 return True;
193 /*******************************************************************
194 ********************************************************************/
196 static bool api_svcctl_enum_dependent_services(pipes_struct *p)
198 SVCCTL_Q_ENUM_DEPENDENT_SERVICES q_u;
199 SVCCTL_R_ENUM_DEPENDENT_SERVICES r_u;
200 prs_struct *data = &p->in_data.data;
201 prs_struct *rdata = &p->out_data.rdata;
203 ZERO_STRUCT(q_u);
204 ZERO_STRUCT(r_u);
206 if(!svcctl_io_q_enum_dependent_services("", &q_u, data, 0))
207 return False;
209 r_u.status = _svcctl_enum_dependent_services(p, &q_u, &r_u);
211 if(!svcctl_io_r_enum_dependent_services("", &r_u, rdata, 0))
212 return False;
214 return True;
217 /*******************************************************************
218 ********************************************************************/
220 static bool api_svcctl_start_service(pipes_struct *p)
222 SVCCTL_Q_START_SERVICE q_u;
223 SVCCTL_R_START_SERVICE r_u;
224 prs_struct *data = &p->in_data.data;
225 prs_struct *rdata = &p->out_data.rdata;
227 ZERO_STRUCT(q_u);
228 ZERO_STRUCT(r_u);
230 if(!svcctl_io_q_start_service("", &q_u, data, 0))
231 return False;
233 r_u.status = _svcctl_start_service(p, &q_u, &r_u);
235 if(!svcctl_io_r_start_service("", &r_u, rdata, 0))
236 return False;
238 return True;
241 /*******************************************************************
242 ********************************************************************/
244 static bool api_svcctl_control_service(pipes_struct *p)
246 SVCCTL_Q_CONTROL_SERVICE q_u;
247 SVCCTL_R_CONTROL_SERVICE r_u;
248 prs_struct *data = &p->in_data.data;
249 prs_struct *rdata = &p->out_data.rdata;
251 ZERO_STRUCT(q_u);
252 ZERO_STRUCT(r_u);
254 if(!svcctl_io_q_control_service("", &q_u, data, 0))
255 return False;
257 r_u.status = _svcctl_control_service(p, &q_u, &r_u);
259 if(!svcctl_io_r_control_service("", &r_u, rdata, 0))
260 return False;
262 return True;
265 /*******************************************************************
266 ********************************************************************/
268 static bool api_svcctl_query_service_config(pipes_struct *p)
270 SVCCTL_Q_QUERY_SERVICE_CONFIG q_u;
271 SVCCTL_R_QUERY_SERVICE_CONFIG r_u;
272 prs_struct *data = &p->in_data.data;
273 prs_struct *rdata = &p->out_data.rdata;
275 ZERO_STRUCT(q_u);
276 ZERO_STRUCT(r_u);
278 if(!svcctl_io_q_query_service_config("", &q_u, data, 0))
279 return False;
281 r_u.status = _svcctl_query_service_config(p, &q_u, &r_u);
283 if(!svcctl_io_r_query_service_config("", &r_u, rdata, 0))
284 return False;
286 return True;
289 /*******************************************************************
290 ********************************************************************/
292 static bool api_svcctl_query_service_config2(pipes_struct *p)
294 SVCCTL_Q_QUERY_SERVICE_CONFIG2 q_u;
295 SVCCTL_R_QUERY_SERVICE_CONFIG2 r_u;
296 prs_struct *data = &p->in_data.data;
297 prs_struct *rdata = &p->out_data.rdata;
299 ZERO_STRUCT(q_u);
300 ZERO_STRUCT(r_u);
302 if(!svcctl_io_q_query_service_config2("", &q_u, data, 0))
303 return False;
305 r_u.status = _svcctl_query_service_config2(p, &q_u, &r_u);
307 if(!svcctl_io_r_query_service_config2("", &r_u, rdata, 0))
308 return False;
310 return True;
313 /*******************************************************************
314 ********************************************************************/
316 static bool api_svcctl_lock_service_db(pipes_struct *p)
318 SVCCTL_Q_LOCK_SERVICE_DB q_u;
319 SVCCTL_R_LOCK_SERVICE_DB r_u;
320 prs_struct *data = &p->in_data.data;
321 prs_struct *rdata = &p->out_data.rdata;
323 ZERO_STRUCT(q_u);
324 ZERO_STRUCT(r_u);
326 if(!svcctl_io_q_lock_service_db("", &q_u, data, 0))
327 return False;
329 r_u.status = _svcctl_lock_service_db(p, &q_u, &r_u);
331 if(!svcctl_io_r_lock_service_db("", &r_u, rdata, 0))
332 return False;
334 return True;
338 /*******************************************************************
339 ********************************************************************/
341 static bool api_svcctl_unlock_service_db(pipes_struct *p)
343 SVCCTL_Q_UNLOCK_SERVICE_DB q_u;
344 SVCCTL_R_UNLOCK_SERVICE_DB r_u;
345 prs_struct *data = &p->in_data.data;
346 prs_struct *rdata = &p->out_data.rdata;
348 ZERO_STRUCT(q_u);
349 ZERO_STRUCT(r_u);
351 if(!svcctl_io_q_unlock_service_db("", &q_u, data, 0))
352 return False;
354 r_u.status = _svcctl_unlock_service_db(p, &q_u, &r_u);
356 if(!svcctl_io_r_unlock_service_db("", &r_u, rdata, 0))
357 return False;
359 return True;
362 /*******************************************************************
363 ********************************************************************/
365 static bool api_svcctl_query_security_sec(pipes_struct *p)
367 SVCCTL_Q_QUERY_SERVICE_SEC q_u;
368 SVCCTL_R_QUERY_SERVICE_SEC r_u;
369 prs_struct *data = &p->in_data.data;
370 prs_struct *rdata = &p->out_data.rdata;
372 ZERO_STRUCT(q_u);
373 ZERO_STRUCT(r_u);
375 if(!svcctl_io_q_query_service_sec("", &q_u, data, 0))
376 return False;
378 r_u.status = _svcctl_query_service_sec(p, &q_u, &r_u);
380 if(!svcctl_io_r_query_service_sec("", &r_u, rdata, 0))
381 return False;
383 return True;
386 /*******************************************************************
387 ********************************************************************/
389 static bool api_svcctl_set_security_sec(pipes_struct *p)
391 SVCCTL_Q_SET_SERVICE_SEC q_u;
392 SVCCTL_R_SET_SERVICE_SEC r_u;
393 prs_struct *data = &p->in_data.data;
394 prs_struct *rdata = &p->out_data.rdata;
396 ZERO_STRUCT(q_u);
397 ZERO_STRUCT(r_u);
399 if(!svcctl_io_q_set_service_sec("", &q_u, data, 0))
400 return False;
402 r_u.status = _svcctl_set_service_sec(p, &q_u, &r_u);
404 if(!svcctl_io_r_set_service_sec("", &r_u, rdata, 0))
405 return False;
407 return True;
411 /*******************************************************************
412 \PIPE\svcctl commands
413 ********************************************************************/
415 static struct api_struct api_svcctl_cmds[] =
417 { "SVCCTL_CLOSE_SERVICE" , SVCCTL_CLOSE_SERVICE , api_svcctl_close_service },
418 { "SVCCTL_OPEN_SCMANAGER_W" , SVCCTL_OPEN_SCMANAGER_W , api_svcctl_open_scmanager },
419 { "SVCCTL_OPEN_SERVICE_W" , SVCCTL_OPEN_SERVICE_W , api_svcctl_open_service },
420 { "SVCCTL_GET_DISPLAY_NAME" , SVCCTL_GET_DISPLAY_NAME , api_svcctl_get_display_name },
421 { "SVCCTL_QUERY_STATUS" , SVCCTL_QUERY_STATUS , api_svcctl_query_status },
422 { "SVCCTL_QUERY_SERVICE_CONFIG_W" , SVCCTL_QUERY_SERVICE_CONFIG_W , api_svcctl_query_service_config },
423 { "SVCCTL_QUERY_SERVICE_CONFIG2_W" , SVCCTL_QUERY_SERVICE_CONFIG2_W , api_svcctl_query_service_config2 },
424 { "SVCCTL_ENUM_SERVICES_STATUS_W" , SVCCTL_ENUM_SERVICES_STATUS_W , api_svcctl_enum_services_status },
425 { "SVCCTL_ENUM_DEPENDENT_SERVICES_W" , SVCCTL_ENUM_DEPENDENT_SERVICES_W , api_svcctl_enum_dependent_services },
426 { "SVCCTL_START_SERVICE_W" , SVCCTL_START_SERVICE_W , api_svcctl_start_service },
427 { "SVCCTL_CONTROL_SERVICE" , SVCCTL_CONTROL_SERVICE , api_svcctl_control_service },
428 { "SVCCTL_QUERY_SERVICE_STATUSEX_W" , SVCCTL_QUERY_SERVICE_STATUSEX_W , api_svcctl_query_service_status_ex },
429 { "SVCCTL_LOCK_SERVICE_DB" , SVCCTL_LOCK_SERVICE_DB , api_svcctl_lock_service_db },
430 { "SVCCTL_UNLOCK_SERVICE_DB" , SVCCTL_UNLOCK_SERVICE_DB , api_svcctl_unlock_service_db },
431 { "SVCCTL_QUERY_SERVICE_SEC" , SVCCTL_QUERY_SERVICE_SEC , api_svcctl_query_security_sec },
432 { "SVCCTL_SET_SERVICE_SEC" , SVCCTL_SET_SERVICE_SEC , api_svcctl_set_security_sec }
436 void svcctl2_get_pipe_fns( struct api_struct **fns, int *n_fns )
438 *fns = api_svcctl_cmds;
439 *n_fns = sizeof(api_svcctl_cmds) / sizeof(struct api_struct);
442 NTSTATUS rpc_svcctl2_init(void)
444 return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION,
445 "svcctl", "ntsvcs", api_svcctl_cmds,
446 sizeof(api_svcctl_cmds) / sizeof(struct api_struct));