OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/setup/me2me_native_messaging_host.h" | 5 #include "remoting/host/setup/me2me_native_messaging_host.h" |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 return; | 534 return; |
535 } | 535 } |
536 | 536 |
537 // Create a security descriptor that gives full access to the caller and | 537 // Create a security descriptor that gives full access to the caller and |
538 // denies access by anyone else. | 538 // denies access by anyone else. |
539 std::string security_descriptor = base::StringPrintf( | 539 std::string security_descriptor = base::StringPrintf( |
540 "O:%1$sG:%1$sD:(A;;GA;;;%1$s)", base::UTF16ToASCII(user_sid).c_str()); | 540 "O:%1$sG:%1$sD:(A;;GA;;;%1$s)", base::UTF16ToASCII(user_sid).c_str()); |
541 | 541 |
542 ScopedSd sd = ConvertSddlToSd(security_descriptor); | 542 ScopedSd sd = ConvertSddlToSd(security_descriptor); |
543 if (!sd) { | 543 if (!sd) { |
544 LOG_GETLASTERROR(ERROR) << "Failed to create a security descriptor for the" | 544 PLOG(ERROR) << "Failed to create a security descriptor for the" |
545 << "Chromoting Me2Me native messaging host."; | 545 << "Chromoting Me2Me native messaging host."; |
546 OnError(); | 546 OnError(); |
547 return; | 547 return; |
548 } | 548 } |
549 | 549 |
550 SECURITY_ATTRIBUTES security_attributes = {0}; | 550 SECURITY_ATTRIBUTES security_attributes = {0}; |
551 security_attributes.nLength = sizeof(security_attributes); | 551 security_attributes.nLength = sizeof(security_attributes); |
552 security_attributes.lpSecurityDescriptor = sd.get(); | 552 security_attributes.lpSecurityDescriptor = sd.get(); |
553 security_attributes.bInheritHandle = FALSE; | 553 security_attributes.bInheritHandle = FALSE; |
554 | 554 |
555 // Generate a unique name for the input channel. | 555 // Generate a unique name for the input channel. |
556 std::string input_pipe_name(kChromePipeNamePrefix); | 556 std::string input_pipe_name(kChromePipeNamePrefix); |
557 input_pipe_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); | 557 input_pipe_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); |
558 | 558 |
559 base::win::ScopedHandle delegate_write_handle(::CreateNamedPipe( | 559 base::win::ScopedHandle delegate_write_handle(::CreateNamedPipe( |
560 base::ASCIIToUTF16(input_pipe_name).c_str(), | 560 base::ASCIIToUTF16(input_pipe_name).c_str(), |
561 PIPE_ACCESS_OUTBOUND, | 561 PIPE_ACCESS_OUTBOUND, |
562 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS, | 562 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS, |
563 1, | 563 1, |
564 kBufferSize, | 564 kBufferSize, |
565 kBufferSize, | 565 kBufferSize, |
566 kTimeOutMilliseconds, | 566 kTimeOutMilliseconds, |
567 &security_attributes)); | 567 &security_attributes)); |
568 | 568 |
569 if (!delegate_write_handle.IsValid()) { | 569 if (!delegate_write_handle.IsValid()) { |
570 LOG_GETLASTERROR(ERROR) << | 570 PLOG(ERROR) << "Failed to create named pipe '" << input_pipe_name << "'"; |
571 "Failed to create named pipe '" << input_pipe_name << "'"; | |
572 OnError(); | 571 OnError(); |
573 return; | 572 return; |
574 } | 573 } |
575 | 574 |
576 // Generate a unique name for the input channel. | 575 // Generate a unique name for the input channel. |
577 std::string output_pipe_name(kChromePipeNamePrefix); | 576 std::string output_pipe_name(kChromePipeNamePrefix); |
578 output_pipe_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); | 577 output_pipe_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); |
579 | 578 |
580 base::win::ScopedHandle delegate_read_handle(::CreateNamedPipe( | 579 base::win::ScopedHandle delegate_read_handle(::CreateNamedPipe( |
581 base::ASCIIToUTF16(output_pipe_name).c_str(), | 580 base::ASCIIToUTF16(output_pipe_name).c_str(), |
582 PIPE_ACCESS_INBOUND, | 581 PIPE_ACCESS_INBOUND, |
583 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS, | 582 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS, |
584 1, | 583 1, |
585 kBufferSize, | 584 kBufferSize, |
586 kBufferSize, | 585 kBufferSize, |
587 kTimeOutMilliseconds, | 586 kTimeOutMilliseconds, |
588 &security_attributes)); | 587 &security_attributes)); |
589 | 588 |
590 if (!delegate_read_handle.IsValid()) { | 589 if (!delegate_read_handle.IsValid()) { |
591 LOG_GETLASTERROR(ERROR) << | 590 PLOG(ERROR) << "Failed to create named pipe '" << output_pipe_name << "'"; |
592 "Failed to create named pipe '" << output_pipe_name << "'"; | |
593 OnError(); | 591 OnError(); |
594 return; | 592 return; |
595 } | 593 } |
596 | 594 |
597 const CommandLine* current_command_line = CommandLine::ForCurrentProcess(); | 595 const CommandLine* current_command_line = CommandLine::ForCurrentProcess(); |
598 const CommandLine::SwitchMap& switches = current_command_line->GetSwitches(); | 596 const CommandLine::SwitchMap& switches = current_command_line->GetSwitches(); |
599 CommandLine::StringVector args = current_command_line->GetArgs(); | 597 CommandLine::StringVector args = current_command_line->GetArgs(); |
600 | 598 |
601 // Create the child process command line by copying switches from the current | 599 // Create the child process command line by copying switches from the current |
602 // command line. | 600 // command line. |
(...skipping 21 matching lines...) Expand all Loading... |
624 memset(&info, 0, sizeof(info)); | 622 memset(&info, 0, sizeof(info)); |
625 info.cbSize = sizeof(info); | 623 info.cbSize = sizeof(info); |
626 info.hwnd = reinterpret_cast<HWND>(parent_window_handle_); | 624 info.hwnd = reinterpret_cast<HWND>(parent_window_handle_); |
627 info.lpVerb = L"runas"; | 625 info.lpVerb = L"runas"; |
628 info.lpFile = binary.value().c_str(); | 626 info.lpFile = binary.value().c_str(); |
629 info.lpParameters = parameters.c_str(); | 627 info.lpParameters = parameters.c_str(); |
630 info.nShow = SW_HIDE; | 628 info.nShow = SW_HIDE; |
631 | 629 |
632 if (!ShellExecuteEx(&info)) { | 630 if (!ShellExecuteEx(&info)) { |
633 DWORD error = ::GetLastError(); | 631 DWORD error = ::GetLastError(); |
634 LOG_GETLASTERROR(ERROR) << "Unable to launch '" << binary.value() << "'"; | 632 PLOG(ERROR) << "Unable to launch '" << binary.value() << "'"; |
635 if (error != ERROR_CANCELLED) { | 633 if (error != ERROR_CANCELLED) { |
636 OnError(); | 634 OnError(); |
637 } | 635 } |
638 return; | 636 return; |
639 } | 637 } |
640 | 638 |
641 if (!::ConnectNamedPipe(delegate_write_handle.Get(), NULL)) { | 639 if (!::ConnectNamedPipe(delegate_write_handle.Get(), NULL)) { |
642 DWORD error = ::GetLastError(); | 640 DWORD error = ::GetLastError(); |
643 if (error != ERROR_PIPE_CONNECTED) { | 641 if (error != ERROR_PIPE_CONNECTED) { |
644 LOG_GETLASTERROR(ERROR) << "Unable to connect '" | 642 PLOG(ERROR) << "Unable to connect '" << input_pipe_name << "'"; |
645 << input_pipe_name << "'"; | |
646 OnError(); | 643 OnError(); |
647 return; | 644 return; |
648 } | 645 } |
649 } | 646 } |
650 | 647 |
651 if (!::ConnectNamedPipe(delegate_read_handle.Get(), NULL)) { | 648 if (!::ConnectNamedPipe(delegate_read_handle.Get(), NULL)) { |
652 DWORD error = ::GetLastError(); | 649 DWORD error = ::GetLastError(); |
653 if (error != ERROR_PIPE_CONNECTED) { | 650 if (error != ERROR_PIPE_CONNECTED) { |
654 LOG_GETLASTERROR(ERROR) << "Unable to connect '" | 651 PLOG(ERROR) << "Unable to connect '" << output_pipe_name << "'"; |
655 << output_pipe_name << "'"; | |
656 OnError(); | 652 OnError(); |
657 return; | 653 return; |
658 } | 654 } |
659 } | 655 } |
660 | 656 |
661 // Set up the native messaging channel to talk to the elevated host. | 657 // Set up the native messaging channel to talk to the elevated host. |
662 // Note that input for the elevate channel is output forthe elevated host. | 658 // Note that input for the elevate channel is output forthe elevated host. |
663 elevated_channel_.reset(new NativeMessagingChannel( | 659 elevated_channel_.reset(new NativeMessagingChannel( |
664 base::File(delegate_read_handle.Take()), | 660 base::File(delegate_read_handle.Take()), |
665 base::File(delegate_write_handle.Take()))); | 661 base::File(delegate_write_handle.Take()))); |
(...skipping 26 matching lines...) Expand all Loading... |
692 | 688 |
693 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 689 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
694 scoped_ptr<base::DictionaryValue> message) { | 690 scoped_ptr<base::DictionaryValue> message) { |
695 NOTREACHED(); | 691 NOTREACHED(); |
696 return false; | 692 return false; |
697 } | 693 } |
698 | 694 |
699 #endif // !defined(OS_WIN) | 695 #endif // !defined(OS_WIN) |
700 | 696 |
701 } // namespace remoting | 697 } // namespace remoting |
OLD | NEW |