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.
|
---|
10 | *
|
---|
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.
|
---|
15 | *
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 |
|
---|
22 | #undef DBGC_CLASS
|
---|
23 | #define DBGC_CLASS DBGC_RPC_SRV
|
---|
24 |
|
---|
25 | static bool proxy_svcctl_call(pipes_struct *p, uint8 opnum)
|
---|
26 | {
|
---|
27 | struct api_struct *fns;
|
---|
28 | int n_fns;
|
---|
29 |
|
---|
30 | svcctl_get_pipe_fns(&fns, &n_fns);
|
---|
31 |
|
---|
32 | if (opnum >= n_fns)
|
---|
33 | return False;
|
---|
34 |
|
---|
35 | if (fns[opnum].opnum != opnum) {
|
---|
36 | smb_panic("SVCCTL function table not sorted\n");
|
---|
37 | }
|
---|
38 |
|
---|
39 | return fns[opnum].fn(p);
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | /*******************************************************************
|
---|
44 | ********************************************************************/
|
---|
45 |
|
---|
46 | static bool api_svcctl_close_service(pipes_struct *p)
|
---|
47 | {
|
---|
48 | return proxy_svcctl_call( p, NDR_SVCCTL_CLOSESERVICEHANDLE );
|
---|
49 | }
|
---|
50 |
|
---|
51 | /*******************************************************************
|
---|
52 | ********************************************************************/
|
---|
53 |
|
---|
54 | static bool api_svcctl_open_scmanager(pipes_struct *p)
|
---|
55 | {
|
---|
56 | return proxy_svcctl_call(p, NDR_SVCCTL_OPENSCMANAGERW);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /*******************************************************************
|
---|
60 | ********************************************************************/
|
---|
61 |
|
---|
62 | static bool api_svcctl_open_service(pipes_struct *p)
|
---|
63 | {
|
---|
64 | return proxy_svcctl_call(p, NDR_SVCCTL_OPENSERVICEW);
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*******************************************************************
|
---|
68 | ********************************************************************/
|
---|
69 |
|
---|
70 | static bool api_svcctl_get_display_name(pipes_struct *p)
|
---|
71 | {
|
---|
72 | return proxy_svcctl_call(p, NDR_SVCCTL_GETSERVICEDISPLAYNAMEW);
|
---|
73 | }
|
---|
74 |
|
---|
75 | /*******************************************************************
|
---|
76 | ********************************************************************/
|
---|
77 |
|
---|
78 | static bool api_svcctl_query_status(pipes_struct *p)
|
---|
79 | {
|
---|
80 | return proxy_svcctl_call(p, NDR_SVCCTL_QUERYSERVICESTATUS);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*******************************************************************
|
---|
84 | ********************************************************************/
|
---|
85 |
|
---|
86 | static bool api_svcctl_enum_services_status(pipes_struct *p)
|
---|
87 | {
|
---|
88 | SVCCTL_Q_ENUM_SERVICES_STATUS q_u;
|
---|
89 | SVCCTL_R_ENUM_SERVICES_STATUS r_u;
|
---|
90 | prs_struct *data = &p->in_data.data;
|
---|
91 | prs_struct *rdata = &p->out_data.rdata;
|
---|
92 |
|
---|
93 | ZERO_STRUCT(q_u);
|
---|
94 | ZERO_STRUCT(r_u);
|
---|
95 |
|
---|
96 | if(!svcctl_io_q_enum_services_status("", &q_u, data, 0))
|
---|
97 | return False;
|
---|
98 |
|
---|
99 | r_u.status = _svcctl_enum_services_status(p, &q_u, &r_u);
|
---|
100 |
|
---|
101 | if(!svcctl_io_r_enum_services_status("", &r_u, rdata, 0))
|
---|
102 | return False;
|
---|
103 |
|
---|
104 | return True;
|
---|
105 | }
|
---|
106 | /*******************************************************************
|
---|
107 | ********************************************************************/
|
---|
108 |
|
---|
109 | static bool api_svcctl_query_service_status_ex(pipes_struct *p)
|
---|
110 | {
|
---|
111 | SVCCTL_Q_QUERY_SERVICE_STATUSEX q_u;
|
---|
112 | SVCCTL_R_QUERY_SERVICE_STATUSEX r_u;
|
---|
113 | prs_struct *data = &p->in_data.data;
|
---|
114 | prs_struct *rdata = &p->out_data.rdata;
|
---|
115 |
|
---|
116 | ZERO_STRUCT(q_u);
|
---|
117 | ZERO_STRUCT(r_u);
|
---|
118 |
|
---|
119 | if(!svcctl_io_q_query_service_status_ex("", &q_u, data, 0))
|
---|
120 | return False;
|
---|
121 |
|
---|
122 | r_u.status = _svcctl_query_service_status_ex(p, &q_u, &r_u);
|
---|
123 |
|
---|
124 | if(!svcctl_io_r_query_service_status_ex("", &r_u, rdata, 0))
|
---|
125 | return False;
|
---|
126 |
|
---|
127 | return True;
|
---|
128 | }
|
---|
129 | /*******************************************************************
|
---|
130 | ********************************************************************/
|
---|
131 |
|
---|
132 | static bool api_svcctl_enum_dependent_services(pipes_struct *p)
|
---|
133 | {
|
---|
134 | SVCCTL_Q_ENUM_DEPENDENT_SERVICES q_u;
|
---|
135 | SVCCTL_R_ENUM_DEPENDENT_SERVICES r_u;
|
---|
136 | prs_struct *data = &p->in_data.data;
|
---|
137 | prs_struct *rdata = &p->out_data.rdata;
|
---|
138 |
|
---|
139 | ZERO_STRUCT(q_u);
|
---|
140 | ZERO_STRUCT(r_u);
|
---|
141 |
|
---|
142 | if(!svcctl_io_q_enum_dependent_services("", &q_u, data, 0))
|
---|
143 | return False;
|
---|
144 |
|
---|
145 | r_u.status = _svcctl_enum_dependent_services(p, &q_u, &r_u);
|
---|
146 |
|
---|
147 | if(!svcctl_io_r_enum_dependent_services("", &r_u, rdata, 0))
|
---|
148 | return False;
|
---|
149 |
|
---|
150 | return True;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /*******************************************************************
|
---|
154 | ********************************************************************/
|
---|
155 |
|
---|
156 | static bool api_svcctl_start_service(pipes_struct *p)
|
---|
157 | {
|
---|
158 | return proxy_svcctl_call(p, NDR_SVCCTL_STARTSERVICEW);
|
---|
159 | }
|
---|
160 |
|
---|
161 | /*******************************************************************
|
---|
162 | ********************************************************************/
|
---|
163 |
|
---|
164 | static bool api_svcctl_control_service(pipes_struct *p)
|
---|
165 | {
|
---|
166 | return proxy_svcctl_call(p, NDR_SVCCTL_CONTROLSERVICE);
|
---|
167 | }
|
---|
168 |
|
---|
169 | /*******************************************************************
|
---|
170 | ********************************************************************/
|
---|
171 |
|
---|
172 | static bool api_svcctl_query_service_config(pipes_struct *p)
|
---|
173 | {
|
---|
174 | SVCCTL_Q_QUERY_SERVICE_CONFIG q_u;
|
---|
175 | SVCCTL_R_QUERY_SERVICE_CONFIG r_u;
|
---|
176 | prs_struct *data = &p->in_data.data;
|
---|
177 | prs_struct *rdata = &p->out_data.rdata;
|
---|
178 |
|
---|
179 | ZERO_STRUCT(q_u);
|
---|
180 | ZERO_STRUCT(r_u);
|
---|
181 |
|
---|
182 | if(!svcctl_io_q_query_service_config("", &q_u, data, 0))
|
---|
183 | return False;
|
---|
184 |
|
---|
185 | r_u.status = _svcctl_query_service_config(p, &q_u, &r_u);
|
---|
186 |
|
---|
187 | if(!svcctl_io_r_query_service_config("", &r_u, rdata, 0))
|
---|
188 | return False;
|
---|
189 |
|
---|
190 | return True;
|
---|
191 | }
|
---|
192 |
|
---|
193 | /*******************************************************************
|
---|
194 | ********************************************************************/
|
---|
195 |
|
---|
196 | static bool api_svcctl_query_service_config2(pipes_struct *p)
|
---|
197 | {
|
---|
198 | SVCCTL_Q_QUERY_SERVICE_CONFIG2 q_u;
|
---|
199 | SVCCTL_R_QUERY_SERVICE_CONFIG2 r_u;
|
---|
200 | prs_struct *data = &p->in_data.data;
|
---|
201 | prs_struct *rdata = &p->out_data.rdata;
|
---|
202 |
|
---|
203 | ZERO_STRUCT(q_u);
|
---|
204 | ZERO_STRUCT(r_u);
|
---|
205 |
|
---|
206 | if(!svcctl_io_q_query_service_config2("", &q_u, data, 0))
|
---|
207 | return False;
|
---|
208 |
|
---|
209 | r_u.status = _svcctl_query_service_config2(p, &q_u, &r_u);
|
---|
210 |
|
---|
211 | if(!svcctl_io_r_query_service_config2("", &r_u, rdata, 0))
|
---|
212 | return False;
|
---|
213 |
|
---|
214 | return True;
|
---|
215 | }
|
---|
216 |
|
---|
217 | /*******************************************************************
|
---|
218 | ********************************************************************/
|
---|
219 |
|
---|
220 | static bool api_svcctl_lock_service_db(pipes_struct *p)
|
---|
221 | {
|
---|
222 | return proxy_svcctl_call(p, NDR_SVCCTL_LOCKSERVICEDATABASE);
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | /*******************************************************************
|
---|
227 | ********************************************************************/
|
---|
228 |
|
---|
229 | static bool api_svcctl_unlock_service_db(pipes_struct *p)
|
---|
230 | {
|
---|
231 | return proxy_svcctl_call(p, NDR_SVCCTL_UNLOCKSERVICEDATABASE);
|
---|
232 | }
|
---|
233 |
|
---|
234 | /*******************************************************************
|
---|
235 | ********************************************************************/
|
---|
236 |
|
---|
237 | static bool api_svcctl_query_security_sec(pipes_struct *p)
|
---|
238 | {
|
---|
239 | return proxy_svcctl_call(p, NDR_SVCCTL_QUERYSERVICEOBJECTSECURITY);
|
---|
240 | }
|
---|
241 |
|
---|
242 | /*******************************************************************
|
---|
243 | ********************************************************************/
|
---|
244 |
|
---|
245 | static bool api_svcctl_set_security_sec(pipes_struct *p)
|
---|
246 | {
|
---|
247 | return proxy_svcctl_call(p, NDR_SVCCTL_SETSERVICEOBJECTSECURITY);
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | /*******************************************************************
|
---|
252 | \PIPE\svcctl commands
|
---|
253 | ********************************************************************/
|
---|
254 |
|
---|
255 | static struct api_struct api_svcctl_cmds[] =
|
---|
256 | {
|
---|
257 | { "SVCCTL_CLOSE_SERVICE" , SVCCTL_CLOSE_SERVICE , api_svcctl_close_service },
|
---|
258 | { "SVCCTL_OPEN_SCMANAGER_W" , SVCCTL_OPEN_SCMANAGER_W , api_svcctl_open_scmanager },
|
---|
259 | { "SVCCTL_OPEN_SERVICE_W" , SVCCTL_OPEN_SERVICE_W , api_svcctl_open_service },
|
---|
260 | { "SVCCTL_GET_DISPLAY_NAME" , SVCCTL_GET_DISPLAY_NAME , api_svcctl_get_display_name },
|
---|
261 | { "SVCCTL_QUERY_STATUS" , SVCCTL_QUERY_STATUS , api_svcctl_query_status },
|
---|
262 | { "SVCCTL_QUERY_SERVICE_CONFIG_W" , SVCCTL_QUERY_SERVICE_CONFIG_W , api_svcctl_query_service_config },
|
---|
263 | { "SVCCTL_QUERY_SERVICE_CONFIG2_W" , SVCCTL_QUERY_SERVICE_CONFIG2_W , api_svcctl_query_service_config2 },
|
---|
264 | { "SVCCTL_ENUM_SERVICES_STATUS_W" , SVCCTL_ENUM_SERVICES_STATUS_W , api_svcctl_enum_services_status },
|
---|
265 | { "SVCCTL_ENUM_DEPENDENT_SERVICES_W" , SVCCTL_ENUM_DEPENDENT_SERVICES_W , api_svcctl_enum_dependent_services },
|
---|
266 | { "SVCCTL_START_SERVICE_W" , SVCCTL_START_SERVICE_W , api_svcctl_start_service },
|
---|
267 | { "SVCCTL_CONTROL_SERVICE" , SVCCTL_CONTROL_SERVICE , api_svcctl_control_service },
|
---|
268 | { "SVCCTL_QUERY_SERVICE_STATUSEX_W" , SVCCTL_QUERY_SERVICE_STATUSEX_W , api_svcctl_query_service_status_ex },
|
---|
269 | { "SVCCTL_LOCK_SERVICE_DB" , SVCCTL_LOCK_SERVICE_DB , api_svcctl_lock_service_db },
|
---|
270 | { "SVCCTL_UNLOCK_SERVICE_DB" , SVCCTL_UNLOCK_SERVICE_DB , api_svcctl_unlock_service_db },
|
---|
271 | { "SVCCTL_QUERY_SERVICE_SEC" , SVCCTL_QUERY_SERVICE_SEC , api_svcctl_query_security_sec },
|
---|
272 | { "SVCCTL_SET_SERVICE_SEC" , SVCCTL_SET_SERVICE_SEC , api_svcctl_set_security_sec }
|
---|
273 | };
|
---|
274 |
|
---|
275 |
|
---|
276 | void svcctl2_get_pipe_fns( struct api_struct **fns, int *n_fns )
|
---|
277 | {
|
---|
278 | *fns = api_svcctl_cmds;
|
---|
279 | *n_fns = sizeof(api_svcctl_cmds) / sizeof(struct api_struct);
|
---|
280 | }
|
---|
281 |
|
---|
282 | NTSTATUS rpc_svcctl2_init(void)
|
---|
283 | {
|
---|
284 | return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION,
|
---|
285 | "svcctl", "ntsvcs", api_svcctl_cmds,
|
---|
286 | sizeof(api_svcctl_cmds) / sizeof(struct api_struct));
|
---|
287 | }
|
---|