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

Side by Side Diff: content/common/sandbox_policy.cc

Issue 10082018: Move BrokerDuplicateHandle() to be declared in content/public (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 "content/common/sandbox_policy.h" 5 #include "content/common/sandbox_policy.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/debugger.h" 10 #include "base/debug/debugger.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/process_util.h" 15 #include "base/process_util.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/win/scoped_handle.h" 18 #include "base/win/scoped_handle.h"
19 #include "base/win/scoped_process_information.h" 19 #include "base/win/scoped_process_information.h"
20 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
21 #include "content/common/debug_flags.h" 21 #include "content/common/debug_flags.h"
22 #include "content/public/common/content_client.h" 22 #include "content/public/common/content_client.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/process_type.h" 24 #include "content/public/common/process_type.h"
25 #include "content/public/common/sandbox_init.h"
25 #include "sandbox/src/sandbox.h" 26 #include "sandbox/src/sandbox.h"
26 #include "ui/gfx/gl/gl_switches.h" 27 #include "ui/gfx/gl/gl_switches.h"
27 28
28 static sandbox::BrokerServices* g_broker_services = NULL; 29 static sandbox::BrokerServices* g_broker_services = NULL;
29 static sandbox::TargetServices* g_target_services = NULL; 30 static sandbox::TargetServices* g_target_services = NULL;
30 31
31 namespace { 32 namespace {
32 33
33 // The DLLs listed here are known (or under strong suspicion) of causing crashes 34 // The DLLs listed here are known (or under strong suspicion) of causing crashes
34 // when they are loaded in the renderer. Note: at runtime we generate short 35 // when they are loaded in the renderer. Note: at runtime we generate short
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 452 }
452 453
453 bool InitTargetServices(sandbox::TargetServices* target_services) { 454 bool InitTargetServices(sandbox::TargetServices* target_services) {
454 DCHECK(target_services); 455 DCHECK(target_services);
455 DCHECK(!g_target_services); 456 DCHECK(!g_target_services);
456 sandbox::ResultCode result = target_services->Init(); 457 sandbox::ResultCode result = target_services->Init();
457 g_target_services = target_services; 458 g_target_services = target_services;
458 return SBOX_ALL_OK == result; 459 return SBOX_ALL_OK == result;
459 } 460 }
460 461
461 bool BrokerDuplicateHandle(HANDLE source_handle,
462 DWORD target_process_id,
463 HANDLE* target_handle,
464 DWORD desired_access,
465 DWORD options) {
466 // If our process is the target just duplicate the handle.
467 if (::GetCurrentProcessId() == target_process_id) {
468 return !!::DuplicateHandle(::GetCurrentProcess(), source_handle,
469 ::GetCurrentProcess(), target_handle,
470 desired_access, FALSE, options);
471
472 }
473
474 // Try the broker next
475 if (g_target_services &&
476 g_target_services->DuplicateHandle(source_handle, target_process_id,
477 target_handle, desired_access,
478 options) == SBOX_ALL_OK) {
479 return true;
480 }
481
482 // Finally, see if we already have access to the process.
483 base::win::ScopedHandle target_process;
484 target_process.Set(::OpenProcess(PROCESS_DUP_HANDLE, FALSE,
485 target_process_id));
486 if (target_process.IsValid()) {
487 return !!::DuplicateHandle(::GetCurrentProcess(), source_handle,
488 target_process, target_handle,
489 desired_access, FALSE, options);
490 }
491
492 return false;
493 }
494
495
496 base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line, 462 base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line,
497 const FilePath& exposed_dir) { 463 const FilePath& exposed_dir) {
498 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 464 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
499 content::ProcessType type; 465 content::ProcessType type;
500 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); 466 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType);
501 if (type_str == switches::kRendererProcess) { 467 if (type_str == switches::kRendererProcess) {
502 type = content::PROCESS_TYPE_RENDERER; 468 type = content::PROCESS_TYPE_RENDERER;
503 } else if (type_str == switches::kPluginProcess) { 469 } else if (type_str == switches::kPluginProcess) {
504 type = content::PROCESS_TYPE_PLUGIN; 470 type = content::PROCESS_TYPE_PLUGIN;
505 } else if (type_str == switches::kWorkerProcess) { 471 } else if (type_str == switches::kWorkerProcess) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 647
682 // Help the process a little. It can't start the debugger by itself if 648 // Help the process a little. It can't start the debugger by itself if
683 // the process is in a sandbox. 649 // the process is in a sandbox.
684 if (child_needs_help) 650 if (child_needs_help)
685 base::debug::SpawnDebuggerOnProcess(target.process_id()); 651 base::debug::SpawnDebuggerOnProcess(target.process_id());
686 652
687 return target.TakeProcessHandle(); 653 return target.TakeProcessHandle();
688 } 654 }
689 655
690 } // namespace sandbox 656 } // namespace sandbox
657
658 namespace content {
jschuh 2012/04/14 19:59:53 You're going to have to fix this up manually now t
659
660 bool BrokerDuplicateHandle(HANDLE source_handle,
661 DWORD target_process_id,
662 HANDLE* target_handle,
663 DWORD desired_access,
664 DWORD options) {
665 // If our process is the target just duplicate the handle.
666 if (::GetCurrentProcessId() == target_process_id) {
667 return !!::DuplicateHandle(::GetCurrentProcess(), source_handle,
668 ::GetCurrentProcess(), target_handle,
669 desired_access, FALSE, options);
670
671 }
672
673 // Try the broker next
674 if (g_target_services &&
675 g_target_services->DuplicateHandle(source_handle, target_process_id,
676 target_handle, desired_access,
677 options) == sandbox::SBOX_ALL_OK) {
678 return true;
679 }
680
681 // Finally, see if we already have access to the process.
682 base::win::ScopedHandle target_process;
683 target_process.Set(::OpenProcess(PROCESS_DUP_HANDLE, FALSE,
684 target_process_id));
685 if (target_process.IsValid()) {
686 return !!::DuplicateHandle(::GetCurrentProcess(), source_handle,
687 target_process, target_handle,
688 desired_access, FALSE, options);
689 }
690
691 return false;
692 }
693
694 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698