Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Side by Side Diff: remoting/host/elevated_controller_win.cc

Issue 10048003: The Chromoting service should not start automatically unless it was configured from the webapp to d… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/elevated_controller_win.h" 5 #include "remoting/host/elevated_controller_win.h"
6 6
7 #include <sddl.h> 7 #include <sddl.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 file_content.size()); 220 file_content.size());
221 } 221 }
222 222
223 STDMETHODIMP ElevatedControllerWin::StartDaemon() { 223 STDMETHODIMP ElevatedControllerWin::StartDaemon() {
224 ScopedScHandle service; 224 ScopedScHandle service;
225 HRESULT hr = OpenService(&service); 225 HRESULT hr = OpenService(&service);
226 if (FAILED(hr)) { 226 if (FAILED(hr)) {
227 return hr; 227 return hr;
228 } 228 }
229 229
230 // Change the service start type to 'auto'.
231 if (!::ChangeServiceConfigW(service,
232 SERVICE_NO_CHANGE,
233 SERVICE_AUTO_START,
234 SERVICE_NO_CHANGE,
235 NULL,
236 NULL,
237 NULL,
238 NULL,
239 NULL,
240 NULL,
241 NULL)) {
242 DWORD error = GetLastError();
243 LOG_GETLASTERROR(ERROR)
244 << "Failed to change the '" << kWindowsServiceName
245 << "'service start type to 'auto'";
246 return HRESULT_FROM_WIN32(error);
247 }
248
249 // Start the service.
230 if (!StartService(service, 0, NULL)) { 250 if (!StartService(service, 0, NULL)) {
231 DWORD error = GetLastError(); 251 DWORD error = GetLastError();
232 if (error != ERROR_SERVICE_ALREADY_RUNNING) { 252 if (error != ERROR_SERVICE_ALREADY_RUNNING) {
233 LOG_GETLASTERROR(ERROR) 253 LOG_GETLASTERROR(ERROR)
234 << "Failed to start the '" << kWindowsServiceName << "'service"; 254 << "Failed to start the '" << kWindowsServiceName << "'service";
235 255
236 return HRESULT_FROM_WIN32(error); 256 return HRESULT_FROM_WIN32(error);
237 } 257 }
238 } 258 }
239 259
240 return S_OK; 260 return S_OK;
241 } 261 }
242 262
243 STDMETHODIMP ElevatedControllerWin::StopDaemon() { 263 STDMETHODIMP ElevatedControllerWin::StopDaemon() {
244 ScopedScHandle service; 264 ScopedScHandle service;
245 HRESULT hr = OpenService(&service); 265 HRESULT hr = OpenService(&service);
246 if (FAILED(hr)) { 266 if (FAILED(hr)) {
247 return hr; 267 return hr;
248 } 268 }
249 269
270 // Change the service start type to 'manual'.
271 if (!::ChangeServiceConfigW(service,
272 SERVICE_NO_CHANGE,
273 SERVICE_DEMAND_START,
274 SERVICE_NO_CHANGE,
275 NULL,
276 NULL,
277 NULL,
278 NULL,
279 NULL,
280 NULL,
281 NULL)) {
282 DWORD error = GetLastError();
283 LOG_GETLASTERROR(ERROR)
284 << "Failed to change the '" << kWindowsServiceName
285 << "'service start type to 'manual'";
286 return HRESULT_FROM_WIN32(error);
287 }
288
289 // Stop the service.
250 SERVICE_STATUS status; 290 SERVICE_STATUS status;
251 if (!ControlService(service, SERVICE_CONTROL_STOP, &status)) { 291 if (!ControlService(service, SERVICE_CONTROL_STOP, &status)) {
252 DWORD error = GetLastError(); 292 DWORD error = GetLastError();
253 if (error != ERROR_SERVICE_NOT_ACTIVE) { 293 if (error != ERROR_SERVICE_NOT_ACTIVE) {
254 LOG_GETLASTERROR(ERROR) 294 LOG_GETLASTERROR(ERROR)
255 << "Failed to stop the '" << kWindowsServiceName << "'service"; 295 << "Failed to stop the '" << kWindowsServiceName << "'service";
256 return HRESULT_FROM_WIN32(error); 296 return HRESULT_FROM_WIN32(error);
257 } 297 }
258 } 298 }
259 299
(...skipping 11 matching lines...) Expand all
271 ::OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASE, 311 ::OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASE,
272 SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE)); 312 SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE));
273 if (!scmanager.IsValid()) { 313 if (!scmanager.IsValid()) {
274 error = GetLastError(); 314 error = GetLastError();
275 LOG_GETLASTERROR(ERROR) 315 LOG_GETLASTERROR(ERROR)
276 << "Failed to connect to the service control manager"; 316 << "Failed to connect to the service control manager";
277 317
278 return HRESULT_FROM_WIN32(error); 318 return HRESULT_FROM_WIN32(error);
279 } 319 }
280 320
321 DWORD desired_access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS |
322 SERVICE_START | SERVICE_STOP;
281 ScopedScHandle service( 323 ScopedScHandle service(
282 ::OpenServiceW(scmanager, UTF8ToUTF16(kWindowsServiceName).c_str(), 324 ::OpenServiceW(scmanager, UTF8ToUTF16(kWindowsServiceName).c_str(),
283 SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP)); 325 desired_access));
284 if (!service.IsValid()) { 326 if (!service.IsValid()) {
285 error = GetLastError(); 327 error = GetLastError();
286 LOG_GETLASTERROR(ERROR) 328 LOG_GETLASTERROR(ERROR)
287 << "Failed to open to the '" << kWindowsServiceName << "' service"; 329 << "Failed to open to the '" << kWindowsServiceName << "' service";
288 330
289 return HRESULT_FROM_WIN32(error); 331 return HRESULT_FROM_WIN32(error);
290 } 332 }
291 333
292 service_out->Set(service.Take()); 334 service_out->Set(service.Take());
293 return S_OK; 335 return S_OK;
294 } 336 }
295 337
296 } // namespace remoting 338 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/host/host_service_win.h » ('j') | remoting/host/wts_console_monitor_win.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698