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

Side by Side Diff: ipc/attachment_broker_privileged_win.cc

Issue 1493413004: ipc: Allow attachment brokering for shared memory handles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp1
Patch Set: Fix more tests. Created 4 years, 11 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ipc/attachment_broker_privileged_win.h" 5 #include "ipc/attachment_broker_privileged_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/process/process.h" 9 #include "base/process/process.h"
10 #include "ipc/attachment_broker_messages.h" 10 #include "ipc/attachment_broker_messages.h"
11 #include "ipc/brokerable_attachment.h" 11 #include "ipc/brokerable_attachment.h"
12 #include "ipc/handle_attachment_win.h" 12 #include "ipc/handle_attachment_win.h"
13 #include "ipc/ipc_channel.h" 13 #include "ipc/ipc_channel.h"
14 14
15 namespace IPC { 15 namespace IPC {
16 16
17 AttachmentBrokerPrivilegedWin::AttachmentBrokerPrivilegedWin() {} 17 AttachmentBrokerPrivilegedWin::AttachmentBrokerPrivilegedWin() {}
18 18
19 AttachmentBrokerPrivilegedWin::~AttachmentBrokerPrivilegedWin() {} 19 AttachmentBrokerPrivilegedWin::~AttachmentBrokerPrivilegedWin() {}
20 20
21 bool AttachmentBrokerPrivilegedWin::SendAttachmentToProcess( 21 bool AttachmentBrokerPrivilegedWin::SendAttachmentToProcess(
22 const scoped_refptr<IPC::BrokerableAttachment>& attachment, 22 const scoped_refptr<IPC::BrokerableAttachment>& attachment,
23 base::ProcessId destination_process) { 23 base::ProcessId destination_process) {
24 switch (attachment->GetBrokerableType()) { 24 switch (attachment->GetBrokerableType()) {
25 case BrokerableAttachment::WIN_HANDLE: { 25 case BrokerableAttachment::WIN_HANDLE: {
26 const internal::HandleAttachmentWin* handle_attachment = 26 internal::HandleAttachmentWin* handle_attachment =
27 static_cast<const internal::HandleAttachmentWin*>(attachment.get()); 27 static_cast<internal::HandleAttachmentWin*>(attachment.get());
28 HandleWireFormat wire_format = 28 HandleWireFormat wire_format =
29 handle_attachment->GetWireFormat(destination_process); 29 handle_attachment->GetWireFormat(destination_process);
30 HandleWireFormat new_wire_format = 30 HandleWireFormat new_wire_format =
31 DuplicateWinHandle(wire_format, base::Process::Current().Pid()); 31 DuplicateWinHandle(wire_format, base::Process::Current().Pid());
32 handle_attachment->reset_handle_ownership();
32 if (new_wire_format.handle == 0) 33 if (new_wire_format.handle == 0)
33 return false; 34 return false;
34 RouteDuplicatedHandle(new_wire_format); 35 RouteDuplicatedHandle(new_wire_format);
35 return true; 36 return true;
36 } 37 }
37 case BrokerableAttachment::MACH_PORT: 38 case BrokerableAttachment::MACH_PORT:
38 case BrokerableAttachment::PLACEHOLDER: 39 case BrokerableAttachment::PLACEHOLDER:
39 NOTREACHED(); 40 NOTREACHED();
40 return false; 41 return false;
41 } 42 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 101
101 AttachmentBrokerPrivilegedWin::HandleWireFormat 102 AttachmentBrokerPrivilegedWin::HandleWireFormat
102 AttachmentBrokerPrivilegedWin::DuplicateWinHandle( 103 AttachmentBrokerPrivilegedWin::DuplicateWinHandle(
103 const HandleWireFormat& wire_format, 104 const HandleWireFormat& wire_format,
104 base::ProcessId source_pid) { 105 base::ProcessId source_pid) {
105 // If the source process is the destination process, then no additional work 106 // If the source process is the destination process, then no additional work
106 // is required. 107 // is required.
107 if (source_pid == wire_format.destination_process) 108 if (source_pid == wire_format.destination_process)
108 return wire_format; 109 return wire_format;
109 110
111 // If the handle is not valid, no additional work is required.
112 if (wire_format.handle == 0)
113 return wire_format;
114
110 base::Process source_process = 115 base::Process source_process =
111 base::Process::OpenWithExtraPrivileges(source_pid); 116 base::Process::OpenWithExtraPrivileges(source_pid);
112 base::Process dest_process = 117 base::Process dest_process =
113 base::Process::OpenWithExtraPrivileges(wire_format.destination_process); 118 base::Process::OpenWithExtraPrivileges(wire_format.destination_process);
114 if (!source_process.Handle() || !dest_process.Handle()) { 119 if (!source_process.Handle() || !dest_process.Handle()) {
115 LogError(ERROR_COULD_NOT_OPEN_SOURCE_OR_DEST); 120 LogError(ERROR_COULD_NOT_OPEN_SOURCE_OR_DEST);
116 return wire_format; 121 return wire_format;
117 } 122 }
118 123
119 DWORD desired_access = 0; 124 DWORD desired_access = 0;
(...skipping 22 matching lines...) Expand all
142 147
143 AttachmentBrokerPrivilegedWin::HandleWireFormat 148 AttachmentBrokerPrivilegedWin::HandleWireFormat
144 AttachmentBrokerPrivilegedWin::CopyWireFormat( 149 AttachmentBrokerPrivilegedWin::CopyWireFormat(
145 const HandleWireFormat& wire_format, 150 const HandleWireFormat& wire_format,
146 int handle) { 151 int handle) {
147 return HandleWireFormat(handle, wire_format.destination_process, 152 return HandleWireFormat(handle, wire_format.destination_process,
148 wire_format.permissions, wire_format.attachment_id); 153 wire_format.permissions, wire_format.attachment_id);
149 } 154 }
150 155
151 } // namespace IPC 156 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/attachment_broker_privileged_win.h ('k') | ipc/attachment_broker_privileged_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698