OLD | NEW |
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 "ipc/ipc_channel_win.h" | 5 #include "ipc/ipc_channel_win.h" |
6 | 6 |
| 7 #include <stdint.h> |
7 #include <windows.h> | 8 #include <windows.h> |
8 | 9 |
9 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/pickle.h" | 14 #include "base/pickle.h" |
14 #include "base/process/process_handle.h" | 15 #include "base/process/process_handle.h" |
15 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 216 } |
216 | 217 |
217 bool ChannelWin::GetNonBrokeredAttachments(Message* msg) { | 218 bool ChannelWin::GetNonBrokeredAttachments(Message* msg) { |
218 return true; | 219 return true; |
219 } | 220 } |
220 | 221 |
221 void ChannelWin::HandleInternalMessage(const Message& msg) { | 222 void ChannelWin::HandleInternalMessage(const Message& msg) { |
222 DCHECK_EQ(msg.type(), static_cast<unsigned>(Channel::HELLO_MESSAGE_TYPE)); | 223 DCHECK_EQ(msg.type(), static_cast<unsigned>(Channel::HELLO_MESSAGE_TYPE)); |
223 // The hello message contains one parameter containing the PID. | 224 // The hello message contains one parameter containing the PID. |
224 base::PickleIterator it(msg); | 225 base::PickleIterator it(msg); |
225 int32 claimed_pid; | 226 int32_t claimed_pid; |
226 bool failed = !it.ReadInt(&claimed_pid); | 227 bool failed = !it.ReadInt(&claimed_pid); |
227 | 228 |
228 if (!failed && validate_client_) { | 229 if (!failed && validate_client_) { |
229 int32 secret; | 230 int32_t secret; |
230 failed = it.ReadInt(&secret) ? (secret != client_secret_) : true; | 231 failed = it.ReadInt(&secret) ? (secret != client_secret_) : true; |
231 } | 232 } |
232 | 233 |
233 if (failed) { | 234 if (failed) { |
234 NOTREACHED(); | 235 NOTREACHED(); |
235 Close(); | 236 Close(); |
236 listener()->OnChannelError(); | 237 listener()->OnChannelError(); |
237 return; | 238 return; |
238 } | 239 } |
239 | 240 |
(...skipping 13 matching lines...) Expand all Loading... |
253 bool ChannelWin::IsAttachmentBrokerEndpoint() { | 254 bool ChannelWin::IsAttachmentBrokerEndpoint() { |
254 return is_attachment_broker_endpoint(); | 255 return is_attachment_broker_endpoint(); |
255 } | 256 } |
256 | 257 |
257 bool ChannelWin::DidEmptyInputBuffers() { | 258 bool ChannelWin::DidEmptyInputBuffers() { |
258 // We don't need to do anything here. | 259 // We don't need to do anything here. |
259 return true; | 260 return true; |
260 } | 261 } |
261 | 262 |
262 // static | 263 // static |
263 const base::string16 ChannelWin::PipeName( | 264 const base::string16 ChannelWin::PipeName(const std::string& channel_id, |
264 const std::string& channel_id, int32* secret) { | 265 int32_t* secret) { |
265 std::string name("\\\\.\\pipe\\chrome."); | 266 std::string name("\\\\.\\pipe\\chrome."); |
266 | 267 |
267 // Prevent the shared secret from ending up in the pipe name. | 268 // Prevent the shared secret from ending up in the pipe name. |
268 size_t index = channel_id.find_first_of('\\'); | 269 size_t index = channel_id.find_first_of('\\'); |
269 if (index != std::string::npos) { | 270 if (index != std::string::npos) { |
270 if (secret) // Retrieve the secret if asked for. | 271 if (secret) // Retrieve the secret if asked for. |
271 base::StringToInt(channel_id.substr(index + 1), secret); | 272 base::StringToInt(channel_id.substr(index + 1), secret); |
272 return base::ASCIIToUTF16(name.append(channel_id.substr(0, index - 1))); | 273 return base::ASCIIToUTF16(name.append(channel_id.substr(0, index - 1))); |
273 } | 274 } |
274 | 275 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 return false; | 350 return false; |
350 } | 351 } |
351 | 352 |
352 // Create the Hello message to be sent when Connect is called | 353 // Create the Hello message to be sent when Connect is called |
353 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE, | 354 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE, |
354 HELLO_MESSAGE_TYPE, | 355 HELLO_MESSAGE_TYPE, |
355 IPC::Message::PRIORITY_NORMAL)); | 356 IPC::Message::PRIORITY_NORMAL)); |
356 | 357 |
357 // Don't send the secret to the untrusted process, and don't send a secret | 358 // Don't send the secret to the untrusted process, and don't send a secret |
358 // if the value is zero (for IPC backwards compatability). | 359 // if the value is zero (for IPC backwards compatability). |
359 int32 secret = validate_client_ ? 0 : client_secret_; | 360 int32_t secret = validate_client_ ? 0 : client_secret_; |
360 if (!m->WriteInt(GetCurrentProcessId()) || | 361 if (!m->WriteInt(GetCurrentProcessId()) || |
361 (secret && !m->WriteUInt32(secret))) { | 362 (secret && !m->WriteUInt32(secret))) { |
362 pipe_.Close(); | 363 pipe_.Close(); |
363 return false; | 364 return false; |
364 } | 365 } |
365 | 366 |
366 output_queue_.push(m.release()); | 367 output_queue_.push(m.release()); |
367 return true; | 368 return true; |
368 } | 369 } |
369 | 370 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 return true; | 463 return true; |
463 | 464 |
464 if (!pipe_.IsValid()) | 465 if (!pipe_.IsValid()) |
465 return false; | 466 return false; |
466 | 467 |
467 // Write to pipe... | 468 // Write to pipe... |
468 Message* m = output_queue_.front(); | 469 Message* m = output_queue_.front(); |
469 DCHECK(m->size() <= INT_MAX); | 470 DCHECK(m->size() <= INT_MAX); |
470 BOOL ok = WriteFile(pipe_.Get(), | 471 BOOL ok = WriteFile(pipe_.Get(), |
471 m->data(), | 472 m->data(), |
472 static_cast<uint32>(m->size()), | 473 static_cast<uint32_t>(m->size()), |
473 NULL, | 474 NULL, |
474 &output_state_.context.overlapped); | 475 &output_state_.context.overlapped); |
475 if (!ok) { | 476 if (!ok) { |
476 DWORD write_error = GetLastError(); | 477 DWORD write_error = GetLastError(); |
477 if (write_error == ERROR_IO_PENDING) { | 478 if (write_error == ERROR_IO_PENDING) { |
478 output_state_.is_pending = true; | 479 output_state_.is_pending = true; |
479 | 480 |
480 DVLOG(2) << "sent pending message @" << m << " on channel @" << this | 481 DVLOG(2) << "sent pending message @" << m << " on channel @" << this |
481 << " with type " << m->type(); | 482 << " with type " << m->type(); |
482 | 483 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 int secret; | 576 int secret; |
576 do { // Guarantee we get a non-zero value. | 577 do { // Guarantee we get a non-zero value. |
577 secret = base::RandInt(0, std::numeric_limits<int>::max()); | 578 secret = base::RandInt(0, std::numeric_limits<int>::max()); |
578 } while (secret == 0); | 579 } while (secret == 0); |
579 | 580 |
580 id.append(GenerateUniqueRandomChannelID()); | 581 id.append(GenerateUniqueRandomChannelID()); |
581 return id.append(base::StringPrintf("\\%d", secret)); | 582 return id.append(base::StringPrintf("\\%d", secret)); |
582 } | 583 } |
583 | 584 |
584 } // namespace IPC | 585 } // namespace IPC |
OLD | NEW |