Index: remoting/host/elevated_controller_win.cc |
diff --git a/remoting/host/elevated_controller_win.cc b/remoting/host/elevated_controller_win.cc |
index e5b655e6439a262484ce1fee3f2527a01293b040..e86612414bb6eb0de1cef6134559f453093ecc18 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* kNonUpdateableKeys[] = { kHostId, kXmppLogin }; |
alexeypa (please no reviews)
2012/04/16 23:28:36
nit: kReadonlyKeys maybe?
simonmorris
2012/04/16 23:38:46
Done.
|
+ |
// 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(kNonUpdateableKeys); ++i) { |
+ if (config_dict->HasKey(kNonUpdateableKeys[i])) { |
+ return E_FAIL; |
alexeypa (please no reviews)
2012/04/16 23:28:36
nit: I think returning HRESULT_FROM_WIN32(ERROR_AC
simonmorris
2012/04/16 23:38:46
Done.
|
+ } |
+ } |
+ // 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) { |