| 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 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 | 10 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 &CreateValidCredConduit, local_auth_fd.get(), remote_auth_fd.get()); | 146 &CreateValidCredConduit, local_auth_fd.get(), remote_auth_fd.get()); |
| 147 | 147 |
| 148 base::WorkerPool::PostTaskAndReply( | 148 base::WorkerPool::PostTaskAndReply( |
| 149 FROM_HERE, create_credentials_conduit_closure, | 149 FROM_HERE, create_credentials_conduit_closure, |
| 150 base::Bind(&SessionManagerClientImpl::CallRestartJobWithValidFd, | 150 base::Bind(&SessionManagerClientImpl::CallRestartJobWithValidFd, |
| 151 weak_ptr_factory_.GetWeakPtr(), base::Passed(&local_auth_fd), | 151 weak_ptr_factory_.GetWeakPtr(), base::Passed(&local_auth_fd), |
| 152 base::Passed(&remote_auth_fd), argv), | 152 base::Passed(&remote_auth_fd), argv), |
| 153 false); | 153 false); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void StartSession(const std::string& user_email) override { | 156 void StartSession(const std::string& user_id) override { |
| 157 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 157 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 158 login_manager::kSessionManagerStartSession); | 158 login_manager::kSessionManagerStartSession); |
| 159 dbus::MessageWriter writer(&method_call); | 159 dbus::MessageWriter writer(&method_call); |
| 160 writer.AppendString(user_email); | 160 writer.AppendString(user_id); |
| 161 writer.AppendString(""); // Unique ID is deprecated | 161 writer.AppendString(""); // Unique ID is deprecated |
| 162 session_manager_proxy_->CallMethod( | 162 session_manager_proxy_->CallMethod( |
| 163 &method_call, | 163 &method_call, |
| 164 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 164 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 165 base::Bind(&SessionManagerClientImpl::OnStartSession, | 165 base::Bind(&SessionManagerClientImpl::OnStartSession, |
| 166 weak_ptr_factory_.GetWeakPtr())); | 166 weak_ptr_factory_.GetWeakPtr())); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void StopSession() override { | 169 void StopSession() override { |
| 170 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 170 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 login_manager::kSessionManagerRetrievePolicy); | 231 login_manager::kSessionManagerRetrievePolicy); |
| 232 session_manager_proxy_->CallMethod( | 232 session_manager_proxy_->CallMethod( |
| 233 &method_call, | 233 &method_call, |
| 234 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 234 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 235 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, | 235 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, |
| 236 weak_ptr_factory_.GetWeakPtr(), | 236 weak_ptr_factory_.GetWeakPtr(), |
| 237 login_manager::kSessionManagerRetrievePolicy, | 237 login_manager::kSessionManagerRetrievePolicy, |
| 238 callback)); | 238 callback)); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void RetrievePolicyForUser(const std::string& username, | 241 void RetrievePolicyForUser(const std::string& user_id, |
| 242 const RetrievePolicyCallback& callback) override { | 242 const RetrievePolicyCallback& callback) override { |
| 243 CallRetrievePolicyByUsername( | 243 CallRetrievePolicyByUsername( |
| 244 login_manager::kSessionManagerRetrievePolicyForUser, | 244 login_manager::kSessionManagerRetrievePolicyForUser, user_id, callback); |
| 245 username, | |
| 246 callback); | |
| 247 } | 245 } |
| 248 | 246 |
| 249 std::string BlockingRetrievePolicyForUser( | 247 std::string BlockingRetrievePolicyForUser( |
| 250 const std::string& username) override { | 248 const std::string& user_id) override { |
| 251 dbus::MethodCall method_call( | 249 dbus::MethodCall method_call( |
| 252 login_manager::kSessionManagerInterface, | 250 login_manager::kSessionManagerInterface, |
| 253 login_manager::kSessionManagerRetrievePolicyForUser); | 251 login_manager::kSessionManagerRetrievePolicyForUser); |
| 254 dbus::MessageWriter writer(&method_call); | 252 dbus::MessageWriter writer(&method_call); |
| 255 writer.AppendString(username); | 253 writer.AppendString(user_id); |
| 256 scoped_ptr<dbus::Response> response = | 254 scoped_ptr<dbus::Response> response = |
| 257 blocking_method_caller_->CallMethodAndBlock(&method_call); | 255 blocking_method_caller_->CallMethodAndBlock(&method_call); |
| 258 std::string policy; | 256 std::string policy; |
| 259 ExtractString(login_manager::kSessionManagerRetrievePolicyForUser, | 257 ExtractString(login_manager::kSessionManagerRetrievePolicyForUser, |
| 260 response.get(), | 258 response.get(), |
| 261 &policy); | 259 &policy); |
| 262 return policy; | 260 return policy; |
| 263 } | 261 } |
| 264 | 262 |
| 265 void RetrieveDeviceLocalAccountPolicy( | 263 void RetrieveDeviceLocalAccountPolicy( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 282 policy_blob.size()); | 280 policy_blob.size()); |
| 283 session_manager_proxy_->CallMethod( | 281 session_manager_proxy_->CallMethod( |
| 284 &method_call, | 282 &method_call, |
| 285 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 283 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 286 base::Bind(&SessionManagerClientImpl::OnStorePolicy, | 284 base::Bind(&SessionManagerClientImpl::OnStorePolicy, |
| 287 weak_ptr_factory_.GetWeakPtr(), | 285 weak_ptr_factory_.GetWeakPtr(), |
| 288 login_manager::kSessionManagerStorePolicy, | 286 login_manager::kSessionManagerStorePolicy, |
| 289 callback)); | 287 callback)); |
| 290 } | 288 } |
| 291 | 289 |
| 292 void StorePolicyForUser(const std::string& username, | 290 void StorePolicyForUser(const std::string& user_id, |
| 293 const std::string& policy_blob, | 291 const std::string& policy_blob, |
| 294 const StorePolicyCallback& callback) override { | 292 const StorePolicyCallback& callback) override { |
| 295 CallStorePolicyByUsername(login_manager::kSessionManagerStorePolicyForUser, | 293 CallStorePolicyByUsername(login_manager::kSessionManagerStorePolicyForUser, |
| 296 username, | 294 user_id, policy_blob, callback); |
| 297 policy_blob, | |
| 298 callback); | |
| 299 } | 295 } |
| 300 | 296 |
| 301 void StoreDeviceLocalAccountPolicy( | 297 void StoreDeviceLocalAccountPolicy( |
| 302 const std::string& account_name, | 298 const std::string& account_name, |
| 303 const std::string& policy_blob, | 299 const std::string& policy_blob, |
| 304 const StorePolicyCallback& callback) override { | 300 const StorePolicyCallback& callback) override { |
| 305 CallStorePolicyByUsername( | 301 CallStorePolicyByUsername( |
| 306 login_manager::kSessionManagerStoreDeviceLocalAccountPolicy, | 302 login_manager::kSessionManagerStoreDeviceLocalAccountPolicy, |
| 307 account_name, | 303 account_name, |
| 308 policy_blob, | 304 policy_blob, |
| 309 callback); | 305 callback); |
| 310 } | 306 } |
| 311 | 307 |
| 312 void SetFlagsForUser(const std::string& username, | 308 void SetFlagsForUser(const std::string& user_id, |
| 313 const std::vector<std::string>& flags) override { | 309 const std::vector<std::string>& flags) override { |
| 314 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 310 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 315 login_manager::kSessionManagerSetFlagsForUser); | 311 login_manager::kSessionManagerSetFlagsForUser); |
| 316 dbus::MessageWriter writer(&method_call); | 312 dbus::MessageWriter writer(&method_call); |
| 317 writer.AppendString(username); | 313 writer.AppendString(user_id); |
| 318 writer.AppendArrayOfStrings(flags); | 314 writer.AppendArrayOfStrings(flags); |
| 319 session_manager_proxy_->CallMethod( | 315 session_manager_proxy_->CallMethod( |
| 320 &method_call, | 316 &method_call, |
| 321 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 317 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 322 dbus::ObjectProxy::EmptyResponseCallback()); | 318 dbus::ObjectProxy::EmptyResponseCallback()); |
| 323 } | 319 } |
| 324 | 320 |
| 325 void GetServerBackedStateKeys(const StateKeysCallback& callback) override { | 321 void GetServerBackedStateKeys(const StateKeysCallback& callback) override { |
| 326 dbus::MethodCall method_call( | 322 dbus::MethodCall method_call( |
| 327 login_manager::kSessionManagerInterface, | 323 login_manager::kSessionManagerInterface, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 412 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 417 method_name); | 413 method_name); |
| 418 session_manager_proxy_->CallMethod( | 414 session_manager_proxy_->CallMethod( |
| 419 &method_call, | 415 &method_call, |
| 420 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 416 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 421 dbus::ObjectProxy::EmptyResponseCallback()); | 417 dbus::ObjectProxy::EmptyResponseCallback()); |
| 422 } | 418 } |
| 423 | 419 |
| 424 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. | 420 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. |
| 425 void CallRetrievePolicyByUsername(const std::string& method_name, | 421 void CallRetrievePolicyByUsername(const std::string& method_name, |
| 426 const std::string& username, | 422 const std::string& user_id, |
| 427 const RetrievePolicyCallback& callback) { | 423 const RetrievePolicyCallback& callback) { |
| 428 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 424 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 429 method_name); | 425 method_name); |
| 430 dbus::MessageWriter writer(&method_call); | 426 dbus::MessageWriter writer(&method_call); |
| 431 writer.AppendString(username); | 427 writer.AppendString(user_id); |
| 432 session_manager_proxy_->CallMethod( | 428 session_manager_proxy_->CallMethod( |
| 433 &method_call, | 429 &method_call, |
| 434 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 430 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 435 base::Bind( | 431 base::Bind( |
| 436 &SessionManagerClientImpl::OnRetrievePolicy, | 432 &SessionManagerClientImpl::OnRetrievePolicy, |
| 437 weak_ptr_factory_.GetWeakPtr(), | 433 weak_ptr_factory_.GetWeakPtr(), |
| 438 method_name, | 434 method_name, |
| 439 callback)); | 435 callback)); |
| 440 } | 436 } |
| 441 | 437 |
| 442 void CallStorePolicyByUsername(const std::string& method_name, | 438 void CallStorePolicyByUsername(const std::string& method_name, |
| 443 const std::string& username, | 439 const std::string& user_id, |
| 444 const std::string& policy_blob, | 440 const std::string& policy_blob, |
| 445 const StorePolicyCallback& callback) { | 441 const StorePolicyCallback& callback) { |
| 446 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 442 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 447 method_name); | 443 method_name); |
| 448 dbus::MessageWriter writer(&method_call); | 444 dbus::MessageWriter writer(&method_call); |
| 449 writer.AppendString(username); | 445 writer.AppendString(user_id); |
| 450 // static_cast does not work due to signedness. | 446 // static_cast does not work due to signedness. |
| 451 writer.AppendArrayOfBytes( | 447 writer.AppendArrayOfBytes( |
| 452 reinterpret_cast<const uint8_t*>(policy_blob.data()), | 448 reinterpret_cast<const uint8_t*>(policy_blob.data()), |
| 453 policy_blob.size()); | 449 policy_blob.size()); |
| 454 session_manager_proxy_->CallMethod( | 450 session_manager_proxy_->CallMethod( |
| 455 &method_call, | 451 &method_call, |
| 456 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 452 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 457 base::Bind( | 453 base::Bind( |
| 458 &SessionManagerClientImpl::OnStorePolicy, | 454 &SessionManagerClientImpl::OnStorePolicy, |
| 459 weak_ptr_factory_.GetWeakPtr(), | 455 weak_ptr_factory_.GetWeakPtr(), |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 return; | 763 return; |
| 768 } | 764 } |
| 769 base::FilePath device_policy_path = | 765 base::FilePath device_policy_path = |
| 770 owner_key_path.DirName().AppendASCII("stub_device_policy"); | 766 owner_key_path.DirName().AppendASCII("stub_device_policy"); |
| 771 base::PostTaskAndReplyWithResult( | 767 base::PostTaskAndReplyWithResult( |
| 772 base::WorkerPool::GetTaskRunner(false).get(), | 768 base::WorkerPool::GetTaskRunner(false).get(), |
| 773 FROM_HERE, | 769 FROM_HERE, |
| 774 base::Bind(&GetFileContent, device_policy_path), | 770 base::Bind(&GetFileContent, device_policy_path), |
| 775 callback); | 771 callback); |
| 776 } | 772 } |
| 777 void RetrievePolicyForUser(const std::string& username, | 773 void RetrievePolicyForUser(const std::string& user_id, |
| 778 const RetrievePolicyCallback& callback) override { | 774 const RetrievePolicyCallback& callback) override { |
| 779 base::PostTaskAndReplyWithResult( | 775 base::PostTaskAndReplyWithResult( |
| 780 base::WorkerPool::GetTaskRunner(false).get(), | 776 base::WorkerPool::GetTaskRunner(false).get(), FROM_HERE, |
| 781 FROM_HERE, | 777 base::Bind(&GetFileContent, GetUserFilePath(user_id, "stub_policy")), |
| 782 base::Bind(&GetFileContent, GetUserFilePath(username, "stub_policy")), | |
| 783 callback); | 778 callback); |
| 784 } | 779 } |
| 785 std::string BlockingRetrievePolicyForUser( | 780 std::string BlockingRetrievePolicyForUser( |
| 786 const std::string& username) override { | 781 const std::string& user_id) override { |
| 787 return GetFileContent(GetUserFilePath(username, "stub_policy")); | 782 return GetFileContent(GetUserFilePath(user_id, "stub_policy")); |
| 788 } | 783 } |
| 789 void RetrieveDeviceLocalAccountPolicy( | 784 void RetrieveDeviceLocalAccountPolicy( |
| 790 const std::string& account_name, | 785 const std::string& account_name, |
| 791 const RetrievePolicyCallback& callback) override { | 786 const RetrievePolicyCallback& callback) override { |
| 792 RetrievePolicyForUser(account_name, callback); | 787 RetrievePolicyForUser(account_name, callback); |
| 793 } | 788 } |
| 794 void StoreDevicePolicy(const std::string& policy_blob, | 789 void StoreDevicePolicy(const std::string& policy_blob, |
| 795 const StorePolicyCallback& callback) override { | 790 const StorePolicyCallback& callback) override { |
| 796 enterprise_management::PolicyFetchResponse response; | 791 enterprise_management::PolicyFetchResponse response; |
| 797 base::FilePath owner_key_path; | 792 base::FilePath owner_key_path; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 814 // Note also that the owner key will be written before the device policy, | 809 // Note also that the owner key will be written before the device policy, |
| 815 // if it was present in the blob. | 810 // if it was present in the blob. |
| 816 base::FilePath device_policy_path = | 811 base::FilePath device_policy_path = |
| 817 owner_key_path.DirName().AppendASCII("stub_device_policy"); | 812 owner_key_path.DirName().AppendASCII("stub_device_policy"); |
| 818 base::WorkerPool::PostTaskAndReply( | 813 base::WorkerPool::PostTaskAndReply( |
| 819 FROM_HERE, | 814 FROM_HERE, |
| 820 base::Bind(&StoreFile, device_policy_path, policy_blob), | 815 base::Bind(&StoreFile, device_policy_path, policy_blob), |
| 821 base::Bind(callback, true), | 816 base::Bind(callback, true), |
| 822 false); | 817 false); |
| 823 } | 818 } |
| 824 void StorePolicyForUser(const std::string& username, | 819 void StorePolicyForUser(const std::string& user_id, |
| 825 const std::string& policy_blob, | 820 const std::string& policy_blob, |
| 826 const StorePolicyCallback& callback) override { | 821 const StorePolicyCallback& callback) override { |
| 827 // The session manager writes the user policy key to a well-known | 822 // The session manager writes the user policy key to a well-known |
| 828 // location. Do the same with the stub impl, so that user policy works and | 823 // location. Do the same with the stub impl, so that user policy works and |
| 829 // can be tested on desktop builds. | 824 // can be tested on desktop builds. |
| 830 enterprise_management::PolicyFetchResponse response; | 825 enterprise_management::PolicyFetchResponse response; |
| 831 if (!response.ParseFromString(policy_blob)) { | 826 if (!response.ParseFromString(policy_blob)) { |
| 832 callback.Run(false); | 827 callback.Run(false); |
| 833 return; | 828 return; |
| 834 } | 829 } |
| 835 | 830 |
| 836 if (response.has_new_public_key()) { | 831 if (response.has_new_public_key()) { |
| 837 base::FilePath key_path = GetUserFilePath(username, "policy.pub"); | 832 base::FilePath key_path = GetUserFilePath(user_id, "policy.pub"); |
| 838 base::WorkerPool::PostTask( | 833 base::WorkerPool::PostTask( |
| 839 FROM_HERE, | 834 FROM_HERE, |
| 840 base::Bind(&StoreFile, key_path, response.new_public_key()), | 835 base::Bind(&StoreFile, key_path, response.new_public_key()), |
| 841 false); | 836 false); |
| 842 } | 837 } |
| 843 | 838 |
| 844 // This file isn't read directly by Chrome, but is used by this class to | 839 // This file isn't read directly by Chrome, but is used by this class to |
| 845 // reload the user policy across restarts. | 840 // reload the user policy across restarts. |
| 846 base::FilePath stub_policy_path = GetUserFilePath(username, "stub_policy"); | 841 base::FilePath stub_policy_path = GetUserFilePath(user_id, "stub_policy"); |
| 847 base::WorkerPool::PostTaskAndReply( | 842 base::WorkerPool::PostTaskAndReply( |
| 848 FROM_HERE, | 843 FROM_HERE, |
| 849 base::Bind(&StoreFile, stub_policy_path, policy_blob), | 844 base::Bind(&StoreFile, stub_policy_path, policy_blob), |
| 850 base::Bind(callback, true), | 845 base::Bind(callback, true), |
| 851 false); | 846 false); |
| 852 } | 847 } |
| 853 void StoreDeviceLocalAccountPolicy( | 848 void StoreDeviceLocalAccountPolicy( |
| 854 const std::string& account_name, | 849 const std::string& account_name, |
| 855 const std::string& policy_blob, | 850 const std::string& policy_blob, |
| 856 const StorePolicyCallback& callback) override { | 851 const StorePolicyCallback& callback) override { |
| 857 StorePolicyForUser(account_name, policy_blob, callback); | 852 StorePolicyForUser(account_name, policy_blob, callback); |
| 858 } | 853 } |
| 859 void SetFlagsForUser(const std::string& username, | 854 void SetFlagsForUser(const std::string& user_id, |
| 860 const std::vector<std::string>& flags) override {} | 855 const std::vector<std::string>& flags) override {} |
| 861 | 856 |
| 862 void GetServerBackedStateKeys(const StateKeysCallback& callback) override { | 857 void GetServerBackedStateKeys(const StateKeysCallback& callback) override { |
| 863 std::vector<std::string> state_keys; | 858 std::vector<std::string> state_keys; |
| 864 for (int i = 0; i < 5; ++i) | 859 for (int i = 0; i < 5; ++i) |
| 865 state_keys.push_back(crypto::SHA256HashString(base::IntToString(i))); | 860 state_keys.push_back(crypto::SHA256HashString(base::IntToString(i))); |
| 866 | 861 |
| 867 if (!callback.is_null()) | 862 if (!callback.is_null()) |
| 868 callback.Run(state_keys); | 863 callback.Run(state_keys); |
| 869 } | 864 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 898 | 893 |
| 899 SessionManagerClient* SessionManagerClient::Create( | 894 SessionManagerClient* SessionManagerClient::Create( |
| 900 DBusClientImplementationType type) { | 895 DBusClientImplementationType type) { |
| 901 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 896 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 902 return new SessionManagerClientImpl(); | 897 return new SessionManagerClientImpl(); |
| 903 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 898 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 904 return new SessionManagerClientStubImpl(); | 899 return new SessionManagerClientStubImpl(); |
| 905 } | 900 } |
| 906 | 901 |
| 907 } // namespace chromeos | 902 } // namespace chromeos |
| OLD | NEW |