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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 // Called on the network thread to set the host's Authenticator factory. | 217 // Called on the network thread to set the host's Authenticator factory. |
218 void CreateAuthenticatorFactory(); | 218 void CreateAuthenticatorFactory(); |
219 | 219 |
220 // Tear down resources that run on the UI thread. | 220 // Tear down resources that run on the UI thread. |
221 void ShutdownOnUiThread(); | 221 void ShutdownOnUiThread(); |
222 | 222 |
223 // Applies the host config, returning true if successful. | 223 // Applies the host config, returning true if successful. |
224 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); | 224 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); |
225 | 225 |
| 226 // Handles policy updates, by calling On*PolicyUpdate methods. |
226 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 227 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); |
227 bool OnHostDomainPolicyUpdate(const std::string& host_domain); | 228 void ApplyHostDomainPolicy(); |
228 bool OnUsernamePolicyUpdate(bool curtain_required, | 229 void ApplyUsernamePolicy(); |
229 bool username_match_required); | 230 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); |
230 bool OnNatPolicyUpdate(bool nat_traversal_enabled); | 231 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
231 bool OnRelayPolicyUpdate(bool allow_relay); | 232 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
232 bool OnUdpPortPolicyUpdate(const std::string& udp_port_range); | 233 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
233 void OnCurtainPolicyUpdate(bool curtain_required); | 234 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
234 bool OnHostTalkGadgetPrefixPolicyUpdate(const std::string& talkgadget_prefix); | 235 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
235 bool OnHostTokenUrlPolicyUpdate( | 236 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
236 const GURL& token_url, | 237 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
237 const GURL& token_validation_url, | 238 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
238 const std::string& token_validation_cert_issuer); | 239 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
239 bool OnPairingPolicyUpdate(bool pairing_enabled); | |
240 bool OnGnubbyAuthPolicyUpdate(bool enable_gnubby_auth); | |
241 | 240 |
242 void StartHost(); | 241 void StartHost(); |
243 | 242 |
244 void OnAuthFailed(); | 243 void OnAuthFailed(); |
245 | 244 |
246 void RestartHost(); | 245 void RestartHost(); |
247 | 246 |
248 // Stops the host and shuts down the process with the specified |exit_code|. | 247 // Stops the host and shuts down the process with the specified |exit_code|. |
249 void ShutdownHost(HostExitCodes exit_code); | 248 void ShutdownHost(HostExitCodes exit_code); |
250 | 249 |
(...skipping 30 matching lines...) Expand all Loading... |
281 | 280 |
282 scoped_ptr<ConfigWatcher> config_watcher_; | 281 scoped_ptr<ConfigWatcher> config_watcher_; |
283 | 282 |
284 std::string host_id_; | 283 std::string host_id_; |
285 protocol::SharedSecretHash host_secret_hash_; | 284 protocol::SharedSecretHash host_secret_hash_; |
286 scoped_refptr<RsaKeyPair> key_pair_; | 285 scoped_refptr<RsaKeyPair> key_pair_; |
287 std::string oauth_refresh_token_; | 286 std::string oauth_refresh_token_; |
288 std::string serialized_config_; | 287 std::string serialized_config_; |
289 std::string host_owner_; | 288 std::string host_owner_; |
290 bool use_service_account_; | 289 bool use_service_account_; |
| 290 |
291 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 291 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 292 std::string host_domain_; |
| 293 bool host_username_match_required_; |
292 bool allow_nat_traversal_; | 294 bool allow_nat_traversal_; |
293 bool allow_relay_; | 295 bool allow_relay_; |
294 int min_udp_port_; | 296 int min_udp_port_; |
295 int max_udp_port_; | 297 int max_udp_port_; |
296 std::string talkgadget_prefix_; | 298 std::string talkgadget_prefix_; |
297 bool allow_pairing_; | 299 bool allow_pairing_; |
298 | 300 |
299 bool curtain_required_; | 301 bool curtain_required_; |
300 ThirdPartyAuthConfig third_party_auth_config_; | 302 ThirdPartyAuthConfig third_party_auth_config_; |
301 bool enable_gnubby_auth_; | 303 bool enable_gnubby_auth_; |
(...skipping 20 matching lines...) Expand all Loading... |
322 bool signal_parent_; | 324 bool signal_parent_; |
323 | 325 |
324 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; | 326 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; |
325 }; | 327 }; |
326 | 328 |
327 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 329 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
328 int* exit_code_out) | 330 int* exit_code_out) |
329 : context_(context.Pass()), | 331 : context_(context.Pass()), |
330 state_(HOST_INITIALIZING), | 332 state_(HOST_INITIALIZING), |
331 use_service_account_(false), | 333 use_service_account_(false), |
| 334 host_username_match_required_(false), |
332 allow_nat_traversal_(true), | 335 allow_nat_traversal_(true), |
333 allow_relay_(true), | 336 allow_relay_(true), |
334 min_udp_port_(0), | 337 min_udp_port_(0), |
335 max_udp_port_(0), | 338 max_udp_port_(0), |
336 allow_pairing_(true), | 339 allow_pairing_(true), |
337 curtain_required_(false), | 340 curtain_required_(false), |
338 enable_gnubby_auth_(false), | 341 enable_gnubby_auth_(false), |
339 #if defined(REMOTING_MULTI_PROCESS) | 342 #if defined(REMOTING_MULTI_PROCESS) |
340 desktop_session_connector_(NULL), | 343 desktop_session_connector_(NULL), |
341 #endif // defined(REMOTING_MULTI_PROCESS) | 344 #endif // defined(REMOTING_MULTI_PROCESS) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 478 |
476 if (state_ == HOST_INITIALIZING) { | 479 if (state_ == HOST_INITIALIZING) { |
477 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is | 480 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is |
478 // already loaded so PolicyWatcher has to be started here. Separate policy | 481 // already loaded so PolicyWatcher has to be started here. Separate policy |
479 // loading from policy verifications and move |policy_watcher_| | 482 // loading from policy verifications and move |policy_watcher_| |
480 // initialization to StartOnNetworkThread(). | 483 // initialization to StartOnNetworkThread(). |
481 policy_watcher_.reset( | 484 policy_watcher_.reset( |
482 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); | 485 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); |
483 policy_watcher_->StartWatching( | 486 policy_watcher_->StartWatching( |
484 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); | 487 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); |
485 } else if (state_ == HOST_STARTED) { | 488 } else { |
486 // TODO(sergeyu): Here we assume that PIN is the only part of the config | 489 // Reapply policies that could be affected by a new config. |
487 // that may change while the service is running. Change ApplyConfig() to | 490 ApplyHostDomainPolicy(); |
488 // detect other changes in the config and restart host if necessary here. | 491 ApplyUsernamePolicy(); |
489 CreateAuthenticatorFactory(); | 492 |
| 493 if (state_ == HOST_STARTED) { |
| 494 // TODO(sergeyu): Here we assume that PIN is the only part of the config |
| 495 // that may change while the service is running. Change ApplyConfig() to |
| 496 // detect other changes in the config and restart host if necessary here. |
| 497 CreateAuthenticatorFactory(); |
| 498 } |
490 } | 499 } |
491 } | 500 } |
492 | 501 |
493 void HostProcess::OnConfigWatcherError() { | 502 void HostProcess::OnConfigWatcherError() { |
494 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 503 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
495 ShutdownHost(kInvalidHostConfigurationExitCode); | 504 ShutdownHost(kInvalidHostConfigurationExitCode); |
496 } | 505 } |
497 | 506 |
498 void HostProcess::StartOnNetworkThread() { | 507 void HostProcess::StartOnNetworkThread() { |
499 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 508 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 use_service_account_ = true; | 813 use_service_account_ = true; |
805 } else { | 814 } else { |
806 // User credential configs only have an xmpp_login, which is also the owner. | 815 // User credential configs only have an xmpp_login, which is also the owner. |
807 host_owner_ = xmpp_server_config_.username; | 816 host_owner_ = xmpp_server_config_.username; |
808 use_service_account_ = false; | 817 use_service_account_ = false; |
809 } | 818 } |
810 return true; | 819 return true; |
811 } | 820 } |
812 | 821 |
813 void HostProcess::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 822 void HostProcess::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { |
814 // TODO(rmsousa): Consolidate all On*PolicyUpdate methods into this one. | |
815 // TODO(sergeyu): Currently polices are verified only when they are loaded. | |
816 // Separate policy loading from policy verifications - this will allow to | |
817 // check policies again later, e.g. when host config changes. | |
818 | |
819 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 823 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
820 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 824 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
821 &HostProcess::OnPolicyUpdate, this, base::Passed(&policies))); | 825 &HostProcess::OnPolicyUpdate, this, base::Passed(&policies))); |
822 return; | 826 return; |
823 } | 827 } |
824 | 828 |
825 bool restart_required = false; | 829 bool restart_required = false; |
826 bool bool_value; | 830 restart_required |= OnHostDomainPolicyUpdate(policies.get()); |
827 std::string string_value; | 831 restart_required |= OnCurtainPolicyUpdate(policies.get()); |
828 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, | 832 // Note: UsernamePolicyUpdate must run after OnCurtainPolicyUpdate. |
829 &string_value)) { | 833 restart_required |= OnUsernamePolicyUpdate(policies.get()); |
830 restart_required |= OnHostDomainPolicyUpdate(string_value); | 834 restart_required |= OnNatPolicyUpdate(policies.get()); |
831 } | 835 restart_required |= OnRelayPolicyUpdate(policies.get()); |
832 bool curtain_required = false; | 836 restart_required |= OnUdpPortPolicyUpdate(policies.get()); |
833 if (policies->GetBoolean( | 837 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(policies.get()); |
834 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, | 838 restart_required |= OnHostTokenUrlPolicyUpdate(policies.get()); |
835 &curtain_required)) { | 839 restart_required |= OnPairingPolicyUpdate(policies.get()); |
836 OnCurtainPolicyUpdate(curtain_required); | 840 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); |
837 } | |
838 if (policies->GetBoolean( | |
839 policy_hack::PolicyWatcher::kHostMatchUsernamePolicyName, | |
840 &bool_value)) { | |
841 restart_required |= OnUsernamePolicyUpdate(curtain_required, bool_value); | |
842 } | |
843 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | |
844 &bool_value)) { | |
845 restart_required |= OnNatPolicyUpdate(bool_value); | |
846 } | |
847 if (policies->GetBoolean(policy_hack::PolicyWatcher::kRelayPolicyName, | |
848 &bool_value)) { | |
849 restart_required |= OnRelayPolicyUpdate(bool_value); | |
850 } | |
851 std::string udp_port_range; | |
852 if (policies->GetString(policy_hack::PolicyWatcher::kUdpPortRangePolicyName, | |
853 &udp_port_range)) { | |
854 restart_required |= OnUdpPortPolicyUpdate(udp_port_range); | |
855 } | |
856 | |
857 if (policies->GetString( | |
858 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, | |
859 &string_value)) { | |
860 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(string_value); | |
861 } | |
862 std::string token_url_string, token_validation_url_string; | |
863 std::string token_validation_cert_issuer; | |
864 if (policies->GetString( | |
865 policy_hack::PolicyWatcher::kHostTokenUrlPolicyName, | |
866 &token_url_string) && | |
867 policies->GetString( | |
868 policy_hack::PolicyWatcher::kHostTokenValidationUrlPolicyName, | |
869 &token_validation_url_string) && | |
870 policies->GetString( | |
871 policy_hack::PolicyWatcher::kHostTokenValidationCertIssuerPolicyName, | |
872 &token_validation_cert_issuer)) { | |
873 restart_required |= OnHostTokenUrlPolicyUpdate( | |
874 GURL(token_url_string), GURL(token_validation_url_string), | |
875 token_validation_cert_issuer); | |
876 } | |
877 if (policies->GetBoolean( | |
878 policy_hack::PolicyWatcher::kHostAllowClientPairing, | |
879 &bool_value)) { | |
880 restart_required |= OnPairingPolicyUpdate(bool_value); | |
881 } | |
882 if (policies->GetBoolean( | |
883 policy_hack::PolicyWatcher::kHostAllowGnubbyAuthPolicyName, | |
884 &bool_value)) | |
885 restart_required |= OnGnubbyAuthPolicyUpdate(bool_value); | |
886 | 841 |
887 if (state_ == HOST_INITIALIZING) { | 842 if (state_ == HOST_INITIALIZING) { |
888 StartHost(); | 843 StartHost(); |
889 } else if (state_ == HOST_STARTED && restart_required) { | 844 } else if (state_ == HOST_STARTED && restart_required) { |
890 RestartHost(); | 845 RestartHost(); |
891 } | 846 } |
892 } | 847 } |
893 | 848 |
894 bool HostProcess::OnHostDomainPolicyUpdate(const std::string& host_domain) { | 849 void HostProcess::ApplyHostDomainPolicy() { |
| 850 HOST_LOG << "Policy sets host domain: " << host_domain_; |
| 851 if (!host_domain_.empty() && |
| 852 !EndsWith(host_owner_, std::string("@") + host_domain_, false)) { |
| 853 LOG(ERROR) << "The host domain does not match the policy."; |
| 854 ShutdownHost(kInvalidHostDomainExitCode); |
| 855 } |
| 856 } |
| 857 |
| 858 bool HostProcess::OnHostDomainPolicyUpdate(base::DictionaryValue* policies) { |
895 // Returns true if the host has to be restarted after this policy update. | 859 // Returns true if the host has to be restarted after this policy update. |
896 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 860 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
897 | 861 |
898 HOST_LOG << "Policy sets host domain: " << host_domain; | 862 if (!policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, |
| 863 &host_domain_)) { |
| 864 return false; |
| 865 } |
899 | 866 |
900 if (!host_domain.empty() && | 867 ApplyHostDomainPolicy(); |
901 !EndsWith(host_owner_, std::string("@") + host_domain, false)) { | |
902 ShutdownHost(kInvalidHostDomainExitCode); | |
903 } | |
904 return false; | 868 return false; |
905 } | 869 } |
906 | 870 |
907 bool HostProcess::OnUsernamePolicyUpdate(bool curtain_required, | 871 void HostProcess::ApplyUsernamePolicy() { |
908 bool host_username_match_required) { | 872 if (host_username_match_required_) { |
909 // Returns false: never restart the host after this policy update. | |
910 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
911 | |
912 if (host_username_match_required) { | |
913 HOST_LOG << "Policy requires host username match."; | 873 HOST_LOG << "Policy requires host username match."; |
914 std::string username = GetUsername(); | 874 std::string username = GetUsername(); |
915 bool shutdown = username.empty() || | 875 bool shutdown = username.empty() || |
916 !StartsWithASCII(host_owner_, username + std::string("@"), | 876 !StartsWithASCII(host_owner_, username + std::string("@"), |
917 false); | 877 false); |
918 | 878 |
919 #if defined(OS_MACOSX) | 879 #if defined(OS_MACOSX) |
920 // On Mac, we run as root at the login screen, so the username won't match. | 880 // On Mac, we run as root at the login screen, so the username won't match. |
921 // However, there's no need to enforce the policy at the login screen, as | 881 // However, there's no need to enforce the policy at the login screen, as |
922 // the client will have to reconnect if a login occurs. | 882 // the client will have to reconnect if a login occurs. |
923 if (shutdown && getuid() == 0) { | 883 if (shutdown && getuid() == 0) { |
924 shutdown = false; | 884 shutdown = false; |
925 } | 885 } |
926 #endif | 886 #endif |
927 | 887 |
928 // Curtain-mode on Windows presents the standard OS login prompt to the user | 888 // Curtain-mode on Windows presents the standard OS login prompt to the user |
929 // for each connection, removing the need for an explicit user-name matching | 889 // for each connection, removing the need for an explicit user-name matching |
930 // check. | 890 // check. |
931 #if defined(OS_WIN) && defined(REMOTING_RDP_SESSION) | 891 #if defined(OS_WIN) && defined(REMOTING_RDP_SESSION) |
932 if (curtain_required) | 892 if (curtain_required_) |
933 return false; | 893 return; |
934 #endif // defined(OS_WIN) && defined(REMOTING_RDP_SESSION) | 894 #endif // defined(OS_WIN) && defined(REMOTING_RDP_SESSION) |
935 | 895 |
936 // Shutdown the host if the username does not match. | 896 // Shutdown the host if the username does not match. |
937 if (shutdown) { | 897 if (shutdown) { |
938 LOG(ERROR) << "The host username does not match."; | 898 LOG(ERROR) << "The host username does not match."; |
939 ShutdownHost(kUsernameMismatchExitCode); | 899 ShutdownHost(kUsernameMismatchExitCode); |
940 } | 900 } |
941 } else { | 901 } else { |
942 HOST_LOG << "Policy does not require host username match."; | 902 HOST_LOG << "Policy does not require host username match."; |
943 } | 903 } |
| 904 } |
944 | 905 |
| 906 bool HostProcess::OnUsernamePolicyUpdate(base::DictionaryValue* policies) { |
| 907 // Returns false: never restart the host after this policy update. |
| 908 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 909 |
| 910 if (!policies->GetBoolean( |
| 911 policy_hack::PolicyWatcher::kHostMatchUsernamePolicyName, |
| 912 &host_username_match_required_)) { |
| 913 return false; |
| 914 } |
| 915 |
| 916 ApplyUsernamePolicy(); |
945 return false; | 917 return false; |
946 } | 918 } |
947 | 919 |
948 bool HostProcess::OnNatPolicyUpdate(bool nat_traversal_enabled) { | 920 bool HostProcess::OnNatPolicyUpdate(base::DictionaryValue* policies) { |
949 // Returns true if the host has to be restarted after this policy update. | 921 // Returns true if the host has to be restarted after this policy update. |
950 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 922 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
951 | 923 |
952 if (allow_nat_traversal_ != nat_traversal_enabled) { | 924 if (!policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
953 if (nat_traversal_enabled) | 925 &allow_nat_traversal_)) { |
954 HOST_LOG << "Policy enables NAT traversal."; | 926 return false; |
955 else | |
956 HOST_LOG << "Policy disables NAT traversal."; | |
957 allow_nat_traversal_ = nat_traversal_enabled; | |
958 return true; | |
959 } | 927 } |
960 return false; | 928 |
| 929 if (allow_nat_traversal_) { |
| 930 HOST_LOG << "Policy enables NAT traversal."; |
| 931 } else { |
| 932 HOST_LOG << "Policy disables NAT traversal."; |
| 933 } |
| 934 return true; |
961 } | 935 } |
962 | 936 |
963 bool HostProcess::OnRelayPolicyUpdate(bool allow_relay) { | 937 bool HostProcess::OnRelayPolicyUpdate(base::DictionaryValue* policies) { |
964 // Returns true if the host has to be restarted after this policy update. | 938 // Returns true if the host has to be restarted after this policy update. |
965 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 939 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
966 | 940 |
967 if (allow_relay_ != allow_relay) { | 941 if (!policies->GetBoolean(policy_hack::PolicyWatcher::kRelayPolicyName, |
968 if (allow_relay) | 942 &allow_relay_)) { |
969 HOST_LOG << "Policy enables use of relay server."; | 943 return false; |
970 else | |
971 HOST_LOG << "Policy disables use of relay server."; | |
972 allow_relay_ = allow_relay; | |
973 return true; | |
974 } | 944 } |
975 return false; | 945 |
| 946 if (allow_relay_) { |
| 947 HOST_LOG << "Policy enables use of relay server."; |
| 948 } else { |
| 949 HOST_LOG << "Policy disables use of relay server."; |
| 950 } |
| 951 return true; |
976 } | 952 } |
977 | 953 |
978 bool HostProcess::OnUdpPortPolicyUpdate(const std::string& udp_port_range) { | 954 bool HostProcess::OnUdpPortPolicyUpdate(base::DictionaryValue* policies) { |
979 // Returns true if the host has to be restarted after this policy update. | 955 // Returns true if the host has to be restarted after this policy update. |
980 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 956 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
981 | 957 |
| 958 std::string udp_port_range; |
| 959 if (!policies->GetString(policy_hack::PolicyWatcher::kUdpPortRangePolicyName, |
| 960 &udp_port_range)) { |
| 961 return false; |
| 962 } |
| 963 |
982 // Use default values if policy setting is empty or invalid. | 964 // Use default values if policy setting is empty or invalid. |
983 int min_udp_port = 0; | 965 int min_udp_port = 0; |
984 int max_udp_port = 0; | 966 int max_udp_port = 0; |
985 if (!udp_port_range.empty() && | 967 if (!udp_port_range.empty() && |
986 !NetworkSettings::ParsePortRange(udp_port_range, &min_udp_port, | 968 !NetworkSettings::ParsePortRange(udp_port_range, &min_udp_port, |
987 &max_udp_port)) { | 969 &max_udp_port)) { |
988 LOG(WARNING) << "Invalid port range policy: \"" << udp_port_range | 970 LOG(WARNING) << "Invalid port range policy: \"" << udp_port_range |
989 << "\". Using default values."; | 971 << "\". Using default values."; |
990 } | 972 } |
991 | 973 |
992 if (min_udp_port_ != min_udp_port || max_udp_port_ != max_udp_port) { | 974 if (min_udp_port_ != min_udp_port || max_udp_port_ != max_udp_port) { |
993 if (min_udp_port != 0 && max_udp_port != 0) { | 975 if (min_udp_port != 0 && max_udp_port != 0) { |
994 HOST_LOG << "Policy restricts UDP port range to [" << min_udp_port | 976 HOST_LOG << "Policy restricts UDP port range to [" << min_udp_port |
995 << ", " << max_udp_port << "]"; | 977 << ", " << max_udp_port << "]"; |
996 } else { | 978 } else { |
997 HOST_LOG << "Policy does not restrict UDP port range."; | 979 HOST_LOG << "Policy does not restrict UDP port range."; |
998 } | 980 } |
999 min_udp_port_ = min_udp_port; | 981 min_udp_port_ = min_udp_port; |
1000 max_udp_port_ = max_udp_port; | 982 max_udp_port_ = max_udp_port; |
1001 return true; | 983 return true; |
1002 } | 984 } |
1003 return false; | 985 return false; |
1004 } | 986 } |
1005 | 987 |
1006 void HostProcess::OnCurtainPolicyUpdate(bool curtain_required) { | 988 bool HostProcess::OnCurtainPolicyUpdate(base::DictionaryValue* policies) { |
1007 // Returns true if the host has to be restarted after this policy update. | 989 // Returns true if the host has to be restarted after this policy update. |
1008 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 990 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1009 | 991 |
| 992 if (!policies->GetBoolean( |
| 993 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, |
| 994 &curtain_required_)) { |
| 995 return false; |
| 996 } |
| 997 |
1010 #if defined(OS_MACOSX) | 998 #if defined(OS_MACOSX) |
1011 if (curtain_required) { | 999 if (curtain_required_) { |
1012 // When curtain mode is in effect on Mac, the host process runs in the | 1000 // When curtain mode is in effect on Mac, the host process runs in the |
1013 // user's switched-out session, but launchd will also run an instance at | 1001 // user's switched-out session, but launchd will also run an instance at |
1014 // the console login screen. Even if no user is currently logged-on, we | 1002 // the console login screen. Even if no user is currently logged-on, we |
1015 // can't support remote-access to the login screen because the current host | 1003 // can't support remote-access to the login screen because the current host |
1016 // process model disconnects the client during login, which would leave | 1004 // process model disconnects the client during login, which would leave |
1017 // the logged in session un-curtained on the console until they reconnect. | 1005 // the logged in session un-curtained on the console until they reconnect. |
1018 // | 1006 // |
1019 // TODO(jamiewalch): Fix this once we have implemented the multi-process | 1007 // TODO(jamiewalch): Fix this once we have implemented the multi-process |
1020 // daemon architecture (crbug.com/134894) | 1008 // daemon architecture (crbug.com/134894) |
1021 if (getuid() == 0) { | 1009 if (getuid() == 0) { |
1022 LOG(ERROR) << "Running the host in the console login session is yet not " | 1010 LOG(ERROR) << "Running the host in the console login session is yet not " |
1023 "supported."; | 1011 "supported."; |
1024 ShutdownHost(kLoginScreenNotSupportedExitCode); | 1012 ShutdownHost(kLoginScreenNotSupportedExitCode); |
1025 return; | 1013 return false; |
1026 } | 1014 } |
1027 } | 1015 } |
1028 #endif | 1016 #endif |
1029 | 1017 |
1030 if (curtain_required_ != curtain_required) { | 1018 if (curtain_required_) { |
1031 if (curtain_required) | 1019 HOST_LOG << "Policy requires curtain-mode."; |
1032 HOST_LOG << "Policy requires curtain-mode."; | 1020 } else { |
1033 else | 1021 HOST_LOG << "Policy does not require curtain-mode."; |
1034 HOST_LOG << "Policy does not require curtain-mode."; | |
1035 curtain_required_ = curtain_required; | |
1036 if (host_) | |
1037 host_->SetEnableCurtaining(curtain_required_); | |
1038 } | 1022 } |
| 1023 |
| 1024 if (host_) |
| 1025 host_->SetEnableCurtaining(curtain_required_); |
| 1026 return false; |
1039 } | 1027 } |
1040 | 1028 |
1041 bool HostProcess::OnHostTalkGadgetPrefixPolicyUpdate( | 1029 bool HostProcess::OnHostTalkGadgetPrefixPolicyUpdate( |
1042 const std::string& talkgadget_prefix) { | 1030 base::DictionaryValue* policies) { |
1043 // Returns true if the host has to be restarted after this policy update. | 1031 // Returns true if the host has to be restarted after this policy update. |
1044 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1032 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1045 | 1033 |
1046 if (talkgadget_prefix != talkgadget_prefix_) { | 1034 if (!policies->GetString( |
1047 HOST_LOG << "Policy sets talkgadget prefix: " << talkgadget_prefix; | 1035 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, |
1048 talkgadget_prefix_ = talkgadget_prefix; | 1036 &talkgadget_prefix_)) { |
1049 return true; | 1037 return false; |
1050 } | 1038 } |
1051 return false; | 1039 |
| 1040 HOST_LOG << "Policy sets talkgadget prefix: " << talkgadget_prefix_; |
| 1041 return true; |
1052 } | 1042 } |
1053 | 1043 |
1054 bool HostProcess::OnHostTokenUrlPolicyUpdate( | 1044 bool HostProcess::OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies) { |
1055 const GURL& token_url, | |
1056 const GURL& token_validation_url, | |
1057 const std::string& token_validation_cert_issuer) { | |
1058 // Returns true if the host has to be restarted after this policy update. | 1045 // Returns true if the host has to be restarted after this policy update. |
1059 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1046 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1060 | 1047 |
1061 if (third_party_auth_config_.token_url != token_url || | 1048 bool token_policy_changed = false; |
1062 third_party_auth_config_.token_validation_url != token_validation_url || | 1049 std::string token_url_string; |
1063 third_party_auth_config_.token_validation_cert_issuer != | 1050 if (policies->GetString( |
1064 token_validation_cert_issuer) { | 1051 policy_hack::PolicyWatcher::kHostTokenUrlPolicyName, |
1065 HOST_LOG << "Policy sets third-party token URLs: " | 1052 &token_url_string)) { |
1066 << "TokenUrl: " << token_url << ", " | 1053 token_policy_changed = true; |
1067 << "TokenValidationUrl: " << token_validation_url | 1054 third_party_auth_config_.token_url = GURL(token_url_string); |
1068 << "TokenValidationCertificateIssuer: " | 1055 } |
1069 << token_validation_cert_issuer; | 1056 std::string token_validation_url_string; |
1070 third_party_auth_config_.token_url = token_url; | 1057 if (policies->GetString( |
1071 third_party_auth_config_.token_validation_url = token_validation_url; | 1058 policy_hack::PolicyWatcher::kHostTokenValidationUrlPolicyName, |
1072 third_party_auth_config_.token_validation_cert_issuer = | 1059 &token_validation_url_string)) { |
1073 token_validation_cert_issuer; | 1060 token_policy_changed = true; |
1074 return true; | 1061 third_party_auth_config_.token_validation_url = |
| 1062 GURL(token_validation_url_string); |
| 1063 } |
| 1064 if (policies->GetString( |
| 1065 policy_hack::PolicyWatcher::kHostTokenValidationCertIssuerPolicyName, |
| 1066 &third_party_auth_config_.token_validation_cert_issuer)) { |
| 1067 token_policy_changed = true; |
1075 } | 1068 } |
1076 | 1069 |
1077 return false; | 1070 if (token_policy_changed) { |
| 1071 HOST_LOG << "Policy sets third-party token URLs: " |
| 1072 << "TokenUrl: " |
| 1073 << third_party_auth_config_.token_url << ", " |
| 1074 << "TokenValidationUrl: " |
| 1075 << third_party_auth_config_.token_validation_url << ", " |
| 1076 << "TokenValidationCertificateIssuer: " |
| 1077 << third_party_auth_config_.token_validation_cert_issuer; |
| 1078 } |
| 1079 return token_policy_changed; |
1078 } | 1080 } |
1079 | 1081 |
1080 bool HostProcess::OnPairingPolicyUpdate(bool allow_pairing) { | 1082 bool HostProcess::OnPairingPolicyUpdate(base::DictionaryValue* policies) { |
1081 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1083 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1082 | 1084 |
1083 if (allow_pairing_ == allow_pairing) | 1085 if (!policies->GetBoolean( |
| 1086 policy_hack::PolicyWatcher::kHostAllowClientPairing, |
| 1087 &allow_pairing_)) { |
1084 return false; | 1088 return false; |
| 1089 } |
1085 | 1090 |
1086 if (allow_pairing) | 1091 if (allow_pairing_) { |
1087 HOST_LOG << "Policy enables client pairing."; | 1092 HOST_LOG << "Policy enables client pairing."; |
1088 else | 1093 } else { |
1089 HOST_LOG << "Policy disables client pairing."; | 1094 HOST_LOG << "Policy disables client pairing."; |
1090 allow_pairing_ = allow_pairing; | 1095 } |
1091 return true; | 1096 return true; |
1092 } | 1097 } |
1093 | 1098 |
1094 bool HostProcess::OnGnubbyAuthPolicyUpdate(bool enable_gnubby_auth) { | 1099 bool HostProcess::OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies) { |
1095 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1100 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1096 | 1101 |
1097 if (enable_gnubby_auth_ == enable_gnubby_auth) | 1102 if (!policies->GetBoolean( |
| 1103 policy_hack::PolicyWatcher::kHostAllowGnubbyAuthPolicyName, |
| 1104 &enable_gnubby_auth_)) { |
1098 return false; | 1105 return false; |
| 1106 } |
1099 | 1107 |
1100 if (enable_gnubby_auth) { | 1108 if (enable_gnubby_auth_) { |
1101 HOST_LOG << "Policy enables gnubby auth."; | 1109 HOST_LOG << "Policy enables gnubby auth."; |
1102 } else { | 1110 } else { |
1103 HOST_LOG << "Policy disables gnubby auth."; | 1111 HOST_LOG << "Policy disables gnubby auth."; |
1104 } | 1112 } |
1105 enable_gnubby_auth_ = enable_gnubby_auth; | |
1106 | 1113 |
1107 if (desktop_environment_factory_) | 1114 if (desktop_environment_factory_) |
1108 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth); | 1115 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); |
1109 | 1116 |
1110 return true; | 1117 return true; |
1111 } | 1118 } |
1112 | 1119 |
1113 void HostProcess::StartHost() { | 1120 void HostProcess::StartHost() { |
1114 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1121 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1115 DCHECK(!host_); | 1122 DCHECK(!host_); |
1116 DCHECK(!signal_strategy_.get()); | 1123 DCHECK(!signal_strategy_.get()); |
1117 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1124 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
1118 state_ == HOST_STOPPED) << state_; | 1125 state_ == HOST_STOPPED) << state_; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 return exit_code; | 1360 return exit_code; |
1354 } | 1361 } |
1355 | 1362 |
1356 } // namespace remoting | 1363 } // namespace remoting |
1357 | 1364 |
1358 #if !defined(OS_WIN) | 1365 #if !defined(OS_WIN) |
1359 int main(int argc, char** argv) { | 1366 int main(int argc, char** argv) { |
1360 return remoting::HostMain(argc, argv); | 1367 return remoting::HostMain(argc, argv); |
1361 } | 1368 } |
1362 #endif // !defined(OS_WIN) | 1369 #endif // !defined(OS_WIN) |
OLD | NEW |