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 // This file implements a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 HostState state_; | 288 HostState state_; |
289 | 289 |
290 scoped_ptr<ConfigWatcher> config_watcher_; | 290 scoped_ptr<ConfigWatcher> config_watcher_; |
291 | 291 |
292 std::string host_id_; | 292 std::string host_id_; |
293 protocol::SharedSecretHash host_secret_hash_; | 293 protocol::SharedSecretHash host_secret_hash_; |
294 scoped_refptr<RsaKeyPair> key_pair_; | 294 scoped_refptr<RsaKeyPair> key_pair_; |
295 std::string oauth_refresh_token_; | 295 std::string oauth_refresh_token_; |
296 std::string serialized_config_; | 296 std::string serialized_config_; |
297 std::string host_owner_; | 297 std::string host_owner_; |
| 298 std::string host_owner_email_; |
298 bool use_service_account_; | 299 bool use_service_account_; |
299 bool enable_vp9_; | 300 bool enable_vp9_; |
300 int64_t frame_recorder_buffer_size_; | 301 int64_t frame_recorder_buffer_size_; |
301 | 302 |
302 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 303 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
303 std::string host_domain_; | 304 std::string host_domain_; |
304 bool host_username_match_required_; | 305 bool host_username_match_required_; |
305 bool allow_nat_traversal_; | 306 bool allow_nat_traversal_; |
306 bool allow_relay_; | 307 bool allow_relay_; |
307 int min_udp_port_; | 308 int min_udp_port_; |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 | 863 |
863 if (config->GetString(kHostOwnerConfigPath, &host_owner_)) { | 864 if (config->GetString(kHostOwnerConfigPath, &host_owner_)) { |
864 // Service account configs have a host_owner, different from the xmpp_login. | 865 // Service account configs have a host_owner, different from the xmpp_login. |
865 use_service_account_ = true; | 866 use_service_account_ = true; |
866 } else { | 867 } else { |
867 // User credential configs only have an xmpp_login, which is also the owner. | 868 // User credential configs only have an xmpp_login, which is also the owner. |
868 host_owner_ = xmpp_server_config_.username; | 869 host_owner_ = xmpp_server_config_.username; |
869 use_service_account_ = false; | 870 use_service_account_ = false; |
870 } | 871 } |
871 | 872 |
| 873 // For non-Gmail Google accounts, the owner base JID differs from the email. |
| 874 // host_owner_ contains the base JID (used for authenticating clients), while |
| 875 // host_owner_email contains the account's email (used for UI and logs). |
| 876 if (!config->GetString(kHostOwnerEmailConfigPath, &host_owner_email_)) { |
| 877 host_owner_email_ = host_owner_; |
| 878 } |
| 879 |
872 // Allow offering of VP9 encoding to be overridden by the command-line. | 880 // Allow offering of VP9 encoding to be overridden by the command-line. |
873 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableVp9SwitchName)) { | 881 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableVp9SwitchName)) { |
874 enable_vp9_ = true; | 882 enable_vp9_ = true; |
875 } else { | 883 } else { |
876 config->GetBoolean(kEnableVp9ConfigPath, &enable_vp9_); | 884 config->GetBoolean(kEnableVp9ConfigPath, &enable_vp9_); |
877 } | 885 } |
878 | 886 |
879 // Allow the command-line to override the size of the frame recorder buffer. | 887 // Allow the command-line to override the size of the frame recorder buffer. |
880 std::string frame_recorder_buffer_kb; | 888 std::string frame_recorder_buffer_kb; |
881 if (CommandLine::ForCurrentProcess()->HasSwitch( | 889 if (CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 | 927 |
920 if (state_ == HOST_INITIALIZING) { | 928 if (state_ == HOST_INITIALIZING) { |
921 StartHost(); | 929 StartHost(); |
922 } else if (state_ == HOST_STARTED && restart_required) { | 930 } else if (state_ == HOST_STARTED && restart_required) { |
923 RestartHost(); | 931 RestartHost(); |
924 } | 932 } |
925 } | 933 } |
926 | 934 |
927 void HostProcess::ApplyHostDomainPolicy() { | 935 void HostProcess::ApplyHostDomainPolicy() { |
928 HOST_LOG << "Policy sets host domain: " << host_domain_; | 936 HOST_LOG << "Policy sets host domain: " << host_domain_; |
| 937 |
| 938 // If the user does not have a Google email, their client JID will not be |
| 939 // based on their email. In that case, the username/host domain policies would |
| 940 // be meaningless, since there is no way to check that the JID attempting to |
| 941 // connect actually corresponds to the owner email in question. |
| 942 if (host_owner_ != host_owner_email_) { |
| 943 LOG(ERROR) << "The username and host domain policies cannot be enabled for " |
| 944 << "accounts with a non-Google email."; |
| 945 ShutdownHost(kInvalidHostDomainExitCode); |
| 946 } |
| 947 |
929 if (!host_domain_.empty() && | 948 if (!host_domain_.empty() && |
930 !EndsWith(host_owner_, std::string("@") + host_domain_, false)) { | 949 !EndsWith(host_owner_, std::string("@") + host_domain_, false)) { |
931 LOG(ERROR) << "The host domain does not match the policy."; | 950 LOG(ERROR) << "The host domain does not match the policy."; |
932 ShutdownHost(kInvalidHostDomainExitCode); | 951 ShutdownHost(kInvalidHostDomainExitCode); |
933 } | 952 } |
934 } | 953 } |
935 | 954 |
936 bool HostProcess::OnHostDomainPolicyUpdate(base::DictionaryValue* policies) { | 955 bool HostProcess::OnHostDomainPolicyUpdate(base::DictionaryValue* policies) { |
937 // Returns true if the host has to be restarted after this policy update. | 956 // Returns true if the host has to be restarted after this policy update. |
938 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 957 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
939 | 958 |
940 if (!policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, | 959 if (!policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, |
941 &host_domain_)) { | 960 &host_domain_)) { |
942 return false; | 961 return false; |
943 } | 962 } |
944 | 963 |
945 ApplyHostDomainPolicy(); | 964 ApplyHostDomainPolicy(); |
946 return false; | 965 return false; |
947 } | 966 } |
948 | 967 |
949 void HostProcess::ApplyUsernamePolicy() { | 968 void HostProcess::ApplyUsernamePolicy() { |
| 969 // See comment in ApplyHostDomainPolicy. |
| 970 if (host_owner_ != host_owner_email_) { |
| 971 LOG(ERROR) << "The username and host domain policies cannot be enabled for " |
| 972 << "accounts with a non-Google email."; |
| 973 ShutdownHost(kUsernameMismatchExitCode); |
| 974 } |
| 975 |
950 if (host_username_match_required_) { | 976 if (host_username_match_required_) { |
951 HOST_LOG << "Policy requires host username match."; | 977 HOST_LOG << "Policy requires host username match."; |
952 std::string username = GetUsername(); | 978 std::string username = GetUsername(); |
953 bool shutdown = username.empty() || | 979 bool shutdown = username.empty() || |
954 !StartsWithASCII(host_owner_, username + std::string("@"), | 980 !StartsWithASCII(host_owner_, username + std::string("@"), |
955 false); | 981 false); |
956 | 982 |
957 #if defined(OS_MACOSX) | 983 #if defined(OS_MACOSX) |
958 // On Mac, we run as root at the login screen, so the username won't match. | 984 // On Mac, we run as root at the login screen, so the username won't match. |
959 // However, there's no need to enforce the policy at the login screen, as | 985 // However, there's no need to enforce the policy at the login screen, as |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 // Set up reporting the host status notifications. | 1329 // Set up reporting the host status notifications. |
1304 #if defined(REMOTING_MULTI_PROCESS) | 1330 #if defined(REMOTING_MULTI_PROCESS) |
1305 host_event_logger_.reset( | 1331 host_event_logger_.reset( |
1306 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); | 1332 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); |
1307 #else // !defined(REMOTING_MULTI_PROCESS) | 1333 #else // !defined(REMOTING_MULTI_PROCESS) |
1308 host_event_logger_ = | 1334 host_event_logger_ = |
1309 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 1335 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
1310 #endif // !defined(REMOTING_MULTI_PROCESS) | 1336 #endif // !defined(REMOTING_MULTI_PROCESS) |
1311 | 1337 |
1312 host_->SetEnableCurtaining(curtain_required_); | 1338 host_->SetEnableCurtaining(curtain_required_); |
1313 host_->Start(host_owner_); | 1339 host_->Start(host_owner_email_); |
1314 | 1340 |
1315 CreateAuthenticatorFactory(); | 1341 CreateAuthenticatorFactory(); |
1316 } | 1342 } |
1317 | 1343 |
1318 void HostProcess::OnAuthFailed() { | 1344 void HostProcess::OnAuthFailed() { |
1319 ShutdownHost(kInvalidOauthCredentialsExitCode); | 1345 ShutdownHost(kInvalidOauthCredentialsExitCode); |
1320 } | 1346 } |
1321 | 1347 |
1322 void HostProcess::RestartHost() { | 1348 void HostProcess::RestartHost() { |
1323 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1349 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 int exit_code = kSuccessExitCode; | 1474 int exit_code = kSuccessExitCode; |
1449 new HostProcess(context.Pass(), &exit_code); | 1475 new HostProcess(context.Pass(), &exit_code); |
1450 | 1476 |
1451 // Run the main (also UI) message loop until the host no longer needs it. | 1477 // Run the main (also UI) message loop until the host no longer needs it. |
1452 message_loop.Run(); | 1478 message_loop.Run(); |
1453 | 1479 |
1454 return exit_code; | 1480 return exit_code; |
1455 } | 1481 } |
1456 | 1482 |
1457 } // namespace remoting | 1483 } // namespace remoting |
OLD | NEW |