diff options
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/elevated_controller_resource.h | 6 | ||||
-rw-r--r-- | remoting/host/elevated_controller_win.cc | 36 | ||||
-rw-r--r-- | remoting/host/plugin/daemon_controller_win.cc | 37 | ||||
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 42 |
4 files changed, 111 insertions, 10 deletions
diff --git a/remoting/host/elevated_controller_resource.h b/remoting/host/elevated_controller_resource.h index ce55048..0376ed2 100644 --- a/remoting/host/elevated_controller_resource.h +++ b/remoting/host/elevated_controller_resource.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef REMOTING_HOST_ELEVATED_CONTROLLER_RESOURCE_H -#define REMOTING_HOST_ELEVATED_CONTROLLER_RESOURCE_H 1 +#ifndef REMOTING_HOST_ELEVATED_CONTROLLER_RESOURCE_H_ +#define REMOTING_HOST_ELEVATED_CONTROLLER_RESOURCE_H_ #define IDS_CONTROLLER 100 #define IDD_VERIFY_CONFIG_DIALOG 101 @@ -11,4 +11,4 @@ #define IDC_EMAIL 103 #define IDC_PIN 104 -#endif REMOTING_HOST_ELEVATED_CONTROLLER_RESOURCE_H 1 +#endif // REMOTING_HOST_ELEVATED_CONTROLLER_RESOURCE_H_ diff --git a/remoting/host/elevated_controller_win.cc b/remoting/host/elevated_controller_win.cc index e5b655e..ac47f84 100644 --- a/remoting/host/elevated_controller_win.cc +++ b/remoting/host/elevated_controller_win.cc @@ -44,6 +44,9 @@ const size_t kMaxConfigFileSize = 1024 * 1024; const char kHostId[] = "host_id"; const char kXmppLogin[] = "xmpp_login"; +// The configuration keys that cannot be specified in UpdateConfig(). +const char* const kReadonlyKeys[] = { kHostId, kXmppLogin }; + // Reads and parses the configuration file up to |kMaxConfigFileSize| in // size. HRESULT ReadConfig(const FilePath& filename, @@ -327,7 +330,38 @@ STDMETHODIMP ElevatedControllerWin::StopDaemon() { } STDMETHODIMP ElevatedControllerWin::UpdateConfig(BSTR config) { - return E_NOTIMPL; + // Parse the config. + std::string config_str = UTF16ToUTF8( + string16(static_cast<char16*>(config), ::SysStringLen(config))); + scoped_ptr<base::Value> config_value(base::JSONReader::Read(config_str)); + if (!config_value.get()) { + return E_FAIL; + } + base::DictionaryValue* config_dict = NULL; + if (!config_value->GetAsDictionary(&config_dict)) { + return E_FAIL; + } + // Check for bad keys. + for (int i = 0; i < arraysize(kReadonlyKeys); ++i) { + if (config_dict->HasKey(kReadonlyKeys[i])) { + return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); + } + } + // Get the old config. + FilePath config_dir = remoting::GetConfigDir(); + scoped_ptr<base::DictionaryValue> config_old; + HRESULT hr = ReadConfig(config_dir.Append(kConfigFileName), &config_old); + if (FAILED(hr)) { + return hr; + } + // Merge items from the given config into the old config. + config_old->MergeDictionary(config_dict); + // Write the updated config. + std::string config_updated_str; + base::JSONWriter::Write(config_old.get(), &config_updated_str); + return WriteConfig(config_dir.Append(kConfigFileName), + config_updated_str.c_str(), + config_updated_str.size()); } HRESULT ElevatedControllerWin::OpenService(ScopedScHandle* service_out) { diff --git a/remoting/host/plugin/daemon_controller_win.cc b/remoting/host/plugin/daemon_controller_win.cc index 13f3725..cb9bebf 100644 --- a/remoting/host/plugin/daemon_controller_win.cc +++ b/remoting/host/plugin/daemon_controller_win.cc @@ -102,6 +102,8 @@ class DaemonControllerWin : public remoting::DaemonController { const CompletionCallback& done_callback); void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, const CompletionCallback& done_callback); + void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, + const CompletionCallback& done_callback); void DoStop(const CompletionCallback& done_callback); // The worker thread used for servicing long running operations. @@ -202,7 +204,6 @@ void DaemonControllerWin::GetConfig(const GetConfigCallback& callback) { void DaemonControllerWin::SetConfigAndStart( scoped_ptr<base::DictionaryValue> config, const CompletionCallback& done_callback) { - worker_thread_.message_loop_proxy()->PostTask( FROM_HERE, base::Bind( &DaemonControllerWin::DoInstallAsNeededAndStart, @@ -212,8 +213,10 @@ void DaemonControllerWin::SetConfigAndStart( void DaemonControllerWin::UpdateConfig( scoped_ptr<base::DictionaryValue> config, const CompletionCallback& done_callback) { - NOTIMPLEMENTED(); - done_callback.Run(RESULT_FAILED); + worker_thread_.message_loop_proxy()->PostTask( + FROM_HERE, base::Bind( + &DaemonControllerWin::DoUpdateConfig, + base::Unretained(this), base::Passed(&config), done_callback)); } void DaemonControllerWin::Stop(const CompletionCallback& done_callback) { @@ -405,6 +408,34 @@ void DaemonControllerWin::DoSetConfigAndStart( done_callback.Run(HResultToAsyncResult(hr)); } +void DaemonControllerWin::DoUpdateConfig( + scoped_ptr<base::DictionaryValue> config, + const CompletionCallback& done_callback) { + // TODO(simonmorris): Much of this code was copied from DoSetConfigAndStart(). + // Refactor. + DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); + + IDaemonControl* control = NULL; + HRESULT hr = worker_thread_.ActivateElevatedController(&control); + if (FAILED(hr)) { + done_callback.Run(HResultToAsyncResult(hr)); + return; + } + + // Store the configuration. + std::string file_content; + base::JSONWriter::Write(config.get(), &file_content); + + ScopedBstr host_config(UTF8ToUTF16(file_content).c_str()); + if (host_config == NULL) { + done_callback.Run(HResultToAsyncResult(E_OUTOFMEMORY)); + return; + } + + hr = control->UpdateConfig(host_config); + done_callback.Run(HResultToAsyncResult(hr)); +} + void DaemonControllerWin::DoStop(const CompletionCallback& done_callback) { DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index cb81bf8..ad8c175 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -16,6 +16,7 @@ #include "base/command_line.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/files/file_path_watcher.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" @@ -83,6 +84,9 @@ class HostProcess : public OAuthClient::Delegate { new ChromotingHostContext(message_loop_.message_loop_proxy())); context_->Start(); network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); + config_updated_timer_.reset(new base::DelayTimer<HostProcess>( + FROM_HERE, base::TimeDelta::FromSeconds(2), this, + &HostProcess::ConfigUpdated)); } void InitWithCommandLine(const CommandLine* cmd_line) { @@ -118,12 +122,42 @@ class HostProcess : public OAuthClient::Delegate { } } -#if defined(OS_MACOSX) +#if defined(OS_WIN) + class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { + public: + ConfigChangedDelegate(HostProcess* host_process) : + host_process_(host_process) { + } + void OnFilePathChanged(const FilePath& path) OVERRIDE { + // Call ConfigUpdated after a short delay, so that this object won't + // try to read the updated configuration file before it has been + // completely written. + // If the writer moves the new configuration file into place atomically, + // this delay may not be necessary. + host_process_->config_updated_timer_->Reset(); + } + void OnFilePathError(const FilePath& path) OVERRIDE { + } + private: + HostProcess* host_process_; + + DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); + }; +#endif // defined(OS_WIN) + void ListenForConfigChanges() { +#if defined(OS_MACOSX) remoting::RegisterHupSignalHandler( base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))); - } +#elif defined(OS_WIN) + scoped_refptr<base::files::FilePathWatcher::Delegate> delegate( + new ConfigChangedDelegate(this)); + config_watcher_.reset(new base::files::FilePathWatcher()); + if (!config_watcher_->Watch(host_config_path_, delegate)) { + LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); + } #endif + } void CreateAuthenticatorFactory() { scoped_ptr<protocol::AuthenticatorFactory> factory( @@ -151,7 +185,7 @@ class HostProcess : public OAuthClient::Delegate { StartWatchingNatPolicy(); } -#if defined(OS_MACOSX) +#if defined(OS_MACOSX) || defined(OS_WIN) context_->file_message_loop()->PostTask( FROM_HERE, base::Bind(&HostProcess::ListenForConfigChanges, @@ -356,6 +390,8 @@ class HostProcess : public OAuthClient::Delegate { scoped_ptr<policy_hack::NatPolicy> nat_policy_; bool allow_nat_traversal_; + scoped_ptr<base::files::FilePathWatcher> config_watcher_; + scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; bool restarting_; |