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 #include "chromeos/dbus/session_manager_client.h" | 5 #include "chromeos/dbus/session_manager_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "third_party/cros_system_api/dbus/service_constants.h" | 33 #include "third_party/cros_system_api/dbus/service_constants.h" |
34 | 34 |
35 namespace chromeos { | 35 namespace chromeos { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // TODO(hidehiko): Share the constant between Chrome and ChromeOS. | 39 // TODO(hidehiko): Share the constant between Chrome and ChromeOS. |
40 constexpr char kArcLowDiskError[] = | 40 constexpr char kArcLowDiskError[] = |
41 "org.chromium.SessionManagerInterface.LowFreeDisk"; | 41 "org.chromium.SessionManagerInterface.LowFreeDisk"; |
42 | 42 |
| 43 constexpr char kStubPolicyFile[] = "stub_policy"; |
| 44 constexpr char kStubDevicePolicyFile[] = "stub_device_policy"; |
| 45 |
43 // Returns a location for |file| that is specific to the given |cryptohome_id|. | 46 // Returns a location for |file| that is specific to the given |cryptohome_id|. |
44 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only | 47 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only |
45 // to store stub files. | 48 // to store stub files. |
46 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id, | 49 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id, |
47 const char* file) { | 50 const char* file) { |
48 base::FilePath keys_path; | 51 base::FilePath keys_path; |
49 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &keys_path)) | 52 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &keys_path)) |
50 return base::FilePath(); | 53 return base::FilePath(); |
51 const std::string sanitized = | 54 const std::string sanitized = |
52 CryptohomeClient::GetStubSanitizedUsername(cryptohome_id); | 55 CryptohomeClient::GetStubSanitizedUsername(cryptohome_id); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 login_manager::kSessionManagerRetrievePolicy); | 204 login_manager::kSessionManagerRetrievePolicy); |
202 session_manager_proxy_->CallMethod( | 205 session_manager_proxy_->CallMethod( |
203 &method_call, | 206 &method_call, |
204 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 207 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
205 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, | 208 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, |
206 weak_ptr_factory_.GetWeakPtr(), | 209 weak_ptr_factory_.GetWeakPtr(), |
207 login_manager::kSessionManagerRetrievePolicy, | 210 login_manager::kSessionManagerRetrievePolicy, |
208 callback)); | 211 callback)); |
209 } | 212 } |
210 | 213 |
| 214 std::string BlockingRetrieveDevicePolicy() override { |
| 215 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 216 login_manager::kSessionManagerRetrievePolicy); |
| 217 std::unique_ptr<dbus::Response> response = |
| 218 blocking_method_caller_->CallMethodAndBlock(&method_call); |
| 219 std::string policy; |
| 220 ExtractString(login_manager::kSessionManagerRetrievePolicy, response.get(), |
| 221 &policy); |
| 222 return policy; |
| 223 } |
| 224 |
211 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, | 225 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, |
212 const RetrievePolicyCallback& callback) override { | 226 const RetrievePolicyCallback& callback) override { |
213 CallRetrievePolicyByUsername( | 227 CallRetrievePolicyByUsername( |
214 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), | 228 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), |
215 callback); | 229 callback); |
216 } | 230 } |
217 | 231 |
218 std::string BlockingRetrievePolicyForUser( | 232 std::string BlockingRetrievePolicyForUser( |
219 const cryptohome::Identification& cryptohome_id) override { | 233 const cryptohome::Identification& cryptohome_id) override { |
220 dbus::MethodCall method_call( | 234 dbus::MethodCall method_call( |
(...skipping 12 matching lines...) Expand all Loading... |
233 | 247 |
234 void RetrieveDeviceLocalAccountPolicy( | 248 void RetrieveDeviceLocalAccountPolicy( |
235 const std::string& account_name, | 249 const std::string& account_name, |
236 const RetrievePolicyCallback& callback) override { | 250 const RetrievePolicyCallback& callback) override { |
237 CallRetrievePolicyByUsername( | 251 CallRetrievePolicyByUsername( |
238 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, | 252 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, |
239 account_name, | 253 account_name, |
240 callback); | 254 callback); |
241 } | 255 } |
242 | 256 |
| 257 std::string BlockingRetrieveDeviceLocalAccountPolicy( |
| 258 const std::string& account_name) override { |
| 259 dbus::MethodCall method_call( |
| 260 login_manager::kSessionManagerInterface, |
| 261 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy); |
| 262 dbus::MessageWriter writer(&method_call); |
| 263 writer.AppendString(account_name); |
| 264 std::unique_ptr<dbus::Response> response = |
| 265 blocking_method_caller_->CallMethodAndBlock(&method_call); |
| 266 std::string policy; |
| 267 ExtractString( |
| 268 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, |
| 269 response.get(), &policy); |
| 270 return policy; |
| 271 } |
| 272 |
243 void StoreDevicePolicy(const std::string& policy_blob, | 273 void StoreDevicePolicy(const std::string& policy_blob, |
244 const StorePolicyCallback& callback) override { | 274 const StorePolicyCallback& callback) override { |
245 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 275 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
246 login_manager::kSessionManagerStorePolicy); | 276 login_manager::kSessionManagerStorePolicy); |
247 dbus::MessageWriter writer(&method_call); | 277 dbus::MessageWriter writer(&method_call); |
248 // static_cast does not work due to signedness. | 278 // static_cast does not work due to signedness. |
249 writer.AppendArrayOfBytes( | 279 writer.AppendArrayOfBytes( |
250 reinterpret_cast<const uint8_t*>(policy_blob.data()), | 280 reinterpret_cast<const uint8_t*>(policy_blob.data()), |
251 policy_blob.size()); | 281 policy_blob.size()); |
252 session_manager_proxy_->CallMethod( | 282 session_manager_proxy_->CallMethod( |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 } | 858 } |
829 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { | 859 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { |
830 } | 860 } |
831 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { | 861 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { |
832 base::FilePath owner_key_path; | 862 base::FilePath owner_key_path; |
833 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 863 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
834 callback.Run(""); | 864 callback.Run(""); |
835 return; | 865 return; |
836 } | 866 } |
837 base::FilePath device_policy_path = | 867 base::FilePath device_policy_path = |
838 owner_key_path.DirName().AppendASCII("stub_device_policy"); | 868 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); |
839 base::PostTaskWithTraitsAndReplyWithResult( | 869 base::PostTaskWithTraitsAndReplyWithResult( |
840 FROM_HERE, base::TaskTraits() | 870 FROM_HERE, base::TaskTraits() |
841 .WithShutdownBehavior( | 871 .WithShutdownBehavior( |
842 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 872 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
843 .MayBlock(), | 873 .MayBlock(), |
844 base::Bind(&GetFileContent, device_policy_path), callback); | 874 base::Bind(&GetFileContent, device_policy_path), callback); |
845 } | 875 } |
| 876 std::string BlockingRetrieveDevicePolicy() override { |
| 877 base::FilePath owner_key_path; |
| 878 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
| 879 return ""; |
| 880 } |
| 881 base::FilePath device_policy_path = |
| 882 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); |
| 883 return GetFileContent(device_policy_path); |
| 884 } |
846 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, | 885 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, |
847 const RetrievePolicyCallback& callback) override { | 886 const RetrievePolicyCallback& callback) override { |
848 base::PostTaskWithTraitsAndReplyWithResult( | 887 base::PostTaskWithTraitsAndReplyWithResult( |
849 FROM_HERE, base::TaskTraits() | 888 FROM_HERE, |
850 .WithShutdownBehavior( | 889 base::TaskTraits() |
851 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 890 .WithShutdownBehavior( |
852 .MayBlock(), | 891 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 892 .MayBlock(), |
853 base::Bind(&GetFileContent, | 893 base::Bind(&GetFileContent, |
854 GetUserFilePath(cryptohome_id, "stub_policy")), | 894 GetUserFilePath(cryptohome_id, kStubPolicyFile)), |
855 callback); | 895 callback); |
856 } | 896 } |
857 std::string BlockingRetrievePolicyForUser( | 897 std::string BlockingRetrievePolicyForUser( |
858 const cryptohome::Identification& cryptohome_id) override { | 898 const cryptohome::Identification& cryptohome_id) override { |
859 return GetFileContent(GetUserFilePath(cryptohome_id, "stub_policy")); | 899 return GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile)); |
860 } | 900 } |
861 void RetrieveDeviceLocalAccountPolicy( | 901 void RetrieveDeviceLocalAccountPolicy( |
862 const std::string& account_id, | 902 const std::string& account_id, |
863 const RetrievePolicyCallback& callback) override { | 903 const RetrievePolicyCallback& callback) override { |
864 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), | 904 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), |
865 callback); | 905 callback); |
866 } | 906 } |
| 907 std::string BlockingRetrieveDeviceLocalAccountPolicy( |
| 908 const std::string& account_id) override { |
| 909 return BlockingRetrievePolicyForUser( |
| 910 cryptohome::Identification::FromString(account_id)); |
| 911 } |
867 void StoreDevicePolicy(const std::string& policy_blob, | 912 void StoreDevicePolicy(const std::string& policy_blob, |
868 const StorePolicyCallback& callback) override { | 913 const StorePolicyCallback& callback) override { |
869 enterprise_management::PolicyFetchResponse response; | 914 enterprise_management::PolicyFetchResponse response; |
870 base::FilePath owner_key_path; | 915 base::FilePath owner_key_path; |
871 if (!response.ParseFromString(policy_blob) || | 916 if (!response.ParseFromString(policy_blob) || |
872 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 917 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
873 callback.Run(false); | 918 callback.Run(false); |
874 return; | 919 return; |
875 } | 920 } |
876 | 921 |
877 if (response.has_new_public_key()) { | 922 if (response.has_new_public_key()) { |
878 base::PostTaskWithTraits( | 923 base::PostTaskWithTraits( |
879 FROM_HERE, base::TaskTraits() | 924 FROM_HERE, base::TaskTraits() |
880 .WithShutdownBehavior( | 925 .WithShutdownBehavior( |
881 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 926 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
882 .MayBlock(), | 927 .MayBlock(), |
883 base::Bind(&StoreFile, owner_key_path, response.new_public_key())); | 928 base::Bind(&StoreFile, owner_key_path, response.new_public_key())); |
884 } | 929 } |
885 | 930 |
886 // Chrome will attempt to retrieve the device policy right after storing | 931 // Chrome will attempt to retrieve the device policy right after storing |
887 // during enrollment, so make sure it's written before signaling | 932 // during enrollment, so make sure it's written before signaling |
888 // completion. | 933 // completion. |
889 // Note also that the owner key will be written before the device policy, | 934 // Note also that the owner key will be written before the device policy, |
890 // if it was present in the blob. | 935 // if it was present in the blob. |
891 base::FilePath device_policy_path = | 936 base::FilePath device_policy_path = |
892 owner_key_path.DirName().AppendASCII("stub_device_policy"); | 937 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); |
893 base::PostTaskWithTraitsAndReply( | 938 base::PostTaskWithTraitsAndReply( |
894 FROM_HERE, base::TaskTraits() | 939 FROM_HERE, base::TaskTraits() |
895 .WithShutdownBehavior( | 940 .WithShutdownBehavior( |
896 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 941 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
897 .MayBlock(), | 942 .MayBlock(), |
898 base::Bind(&StoreFile, device_policy_path, policy_blob), | 943 base::Bind(&StoreFile, device_policy_path, policy_blob), |
899 base::Bind(callback, true)); | 944 base::Bind(callback, true)); |
900 } | 945 } |
901 void StorePolicyForUser(const cryptohome::Identification& cryptohome_id, | 946 void StorePolicyForUser(const cryptohome::Identification& cryptohome_id, |
902 const std::string& policy_blob, | 947 const std::string& policy_blob, |
(...skipping 13 matching lines...) Expand all Loading... |
916 FROM_HERE, base::TaskTraits() | 961 FROM_HERE, base::TaskTraits() |
917 .WithShutdownBehavior( | 962 .WithShutdownBehavior( |
918 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 963 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
919 .MayBlock(), | 964 .MayBlock(), |
920 base::Bind(&StoreFile, key_path, response.new_public_key())); | 965 base::Bind(&StoreFile, key_path, response.new_public_key())); |
921 } | 966 } |
922 | 967 |
923 // This file isn't read directly by Chrome, but is used by this class to | 968 // This file isn't read directly by Chrome, but is used by this class to |
924 // reload the user policy across restarts. | 969 // reload the user policy across restarts. |
925 base::FilePath stub_policy_path = | 970 base::FilePath stub_policy_path = |
926 GetUserFilePath(cryptohome_id, "stub_policy"); | 971 GetUserFilePath(cryptohome_id, kStubPolicyFile); |
927 base::PostTaskWithTraitsAndReply( | 972 base::PostTaskWithTraitsAndReply( |
928 FROM_HERE, base::TaskTraits() | 973 FROM_HERE, base::TaskTraits() |
929 .WithShutdownBehavior( | 974 .WithShutdownBehavior( |
930 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 975 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
931 .MayBlock(), | 976 .MayBlock(), |
932 base::Bind(&StoreFile, stub_policy_path, policy_blob), | 977 base::Bind(&StoreFile, stub_policy_path, policy_blob), |
933 base::Bind(callback, true)); | 978 base::Bind(callback, true)); |
934 } | 979 } |
935 void StoreDeviceLocalAccountPolicy( | 980 void StoreDeviceLocalAccountPolicy( |
936 const std::string& account_id, | 981 const std::string& account_id, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 | 1053 |
1009 SessionManagerClient* SessionManagerClient::Create( | 1054 SessionManagerClient* SessionManagerClient::Create( |
1010 DBusClientImplementationType type) { | 1055 DBusClientImplementationType type) { |
1011 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 1056 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
1012 return new SessionManagerClientImpl(); | 1057 return new SessionManagerClientImpl(); |
1013 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 1058 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
1014 return new SessionManagerClientStubImpl(); | 1059 return new SessionManagerClientStubImpl(); |
1015 } | 1060 } |
1016 | 1061 |
1017 } // namespace chromeos | 1062 } // namespace chromeos |
OLD | NEW |