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

Side by Side Diff: ipc/attachment_broker_privileged_win.cc

Issue 1281083004: ipc: Add the class HandleWin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add logging. Created 5 years, 4 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"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 sender->Send(new AttachmentBrokerMsg_WinHandleHasBeenDuplicated(wire_format)); 88 sender->Send(new AttachmentBrokerMsg_WinHandleHasBeenDuplicated(wire_format));
89 } 89 }
90 90
91 AttachmentBrokerPrivilegedWin::HandleWireFormat 91 AttachmentBrokerPrivilegedWin::HandleWireFormat
92 AttachmentBrokerPrivilegedWin::DuplicateWinHandle( 92 AttachmentBrokerPrivilegedWin::DuplicateWinHandle(
93 const HandleWireFormat& wire_format, 93 const HandleWireFormat& wire_format,
94 base::ProcessId source_pid) { 94 base::ProcessId source_pid) {
95 HandleWireFormat new_wire_format; 95 HandleWireFormat new_wire_format;
96 new_wire_format.destination_process = wire_format.destination_process; 96 new_wire_format.destination_process = wire_format.destination_process;
97 new_wire_format.attachment_id = wire_format.attachment_id; 97 new_wire_format.attachment_id = wire_format.attachment_id;
98 new_wire_format.permissions = wire_format.permissions;
99 new_wire_format.handle = 0;
98 100
99 HANDLE original_handle = LongToHandle(wire_format.handle); 101 HANDLE original_handle = LongToHandle(wire_format.handle);
100 102
101 base::Process source_process = 103 base::Process source_process =
102 base::Process::OpenWithExtraPrivileges(source_pid); 104 base::Process::OpenWithExtraPrivileges(source_pid);
103 base::Process dest_process = 105 base::Process dest_process =
104 base::Process::OpenWithExtraPrivileges(wire_format.destination_process); 106 base::Process::OpenWithExtraPrivileges(wire_format.destination_process);
105 if (source_process.Handle() && dest_process.Handle()) { 107 if (source_process.Handle() && dest_process.Handle()) {
108 DWORD desired_access = 0;
109 DWORD options = 0;
110 switch (wire_format.permissions) {
111 case HandleWin::INVALID:
112 LOG(ERROR) << "Received invalid permissions for duplication.";
113 return new_wire_format;
114 case HandleWin::DUPLICATE:
115 options = DUPLICATE_SAME_ACCESS;
116 break;
117 case HandleWin::FILE_READ_WRITE:
118 desired_access = FILE_GENERIC_READ | FILE_GENERIC_WRITE;
119 break;
120 }
121
106 HANDLE new_handle; 122 HANDLE new_handle;
107 DWORD result = ::DuplicateHandle(source_process.Handle(), original_handle, 123 DWORD result = ::DuplicateHandle(source_process.Handle(), original_handle,
108 dest_process.Handle(), &new_handle, 0, 124 dest_process.Handle(), &new_handle,
109 FALSE, DUPLICATE_SAME_ACCESS); 125 desired_access, FALSE, options);
110 126
111 new_wire_format.handle = (result != 0) ? HandleToLong(new_handle) : 0; 127 new_wire_format.handle = (result != 0) ? HandleToLong(new_handle) : 0;
112 } else {
113 new_wire_format.handle = 0;
114 } 128 }
129
115 return new_wire_format; 130 return new_wire_format;
116 } 131 }
117 132
118 } // namespace IPC 133 } // 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