| 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 "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 5 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // Translates DeviceMode constants to strings used in the lockbox. | 25 // Translates DeviceMode constants to strings used in the lockbox. |
| 26 std::string GetDeviceModeString(DeviceMode mode) { | 26 std::string GetDeviceModeString(DeviceMode mode) { |
| 27 switch (mode) { | 27 switch (mode) { |
| 28 case DEVICE_MODE_CONSUMER: | 28 case DEVICE_MODE_CONSUMER: |
| 29 return EnterpriseInstallAttributes::kConsumerDeviceMode; | 29 return EnterpriseInstallAttributes::kConsumerDeviceMode; |
| 30 case DEVICE_MODE_ENTERPRISE: | 30 case DEVICE_MODE_ENTERPRISE: |
| 31 return EnterpriseInstallAttributes::kEnterpiseDeviceMode; | 31 return EnterpriseInstallAttributes::kEnterpiseDeviceMode; |
| 32 case DEVICE_MODE_RETAIL_KIOSK: | 32 case DEVICE_MODE_RETAIL_KIOSK: |
| 33 return EnterpriseInstallAttributes::kRetailKioskDeviceMode; | 33 return EnterpriseInstallAttributes::kRetailKioskDeviceMode; |
| 34 case DEVICE_MODE_CONSUMER_KIOSK: | 34 case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH: |
| 35 return EnterpriseInstallAttributes::kConsumerKioskDeviceMode; | 35 return EnterpriseInstallAttributes::kConsumerKioskDeviceMode; |
| 36 case DEVICE_MODE_PENDING: | 36 case DEVICE_MODE_PENDING: |
| 37 case DEVICE_MODE_NOT_SET: | 37 case DEVICE_MODE_NOT_SET: |
| 38 break; | 38 break; |
| 39 } | 39 } |
| 40 NOTREACHED() << "Invalid device mode: " << mode; | 40 NOTREACHED() << "Invalid device mode: " << mode; |
| 41 return EnterpriseInstallAttributes::kUnknownDeviceMode; | 41 return EnterpriseInstallAttributes::kUnknownDeviceMode; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Translates strings used in the lockbox to DeviceMode values. | 44 // Translates strings used in the lockbox to DeviceMode values. |
| 45 DeviceMode GetDeviceModeFromString( | 45 DeviceMode GetDeviceModeFromString( |
| 46 const std::string& mode) { | 46 const std::string& mode) { |
| 47 if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode) | 47 if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode) |
| 48 return DEVICE_MODE_CONSUMER; | 48 return DEVICE_MODE_CONSUMER; |
| 49 else if (mode == EnterpriseInstallAttributes::kEnterpiseDeviceMode) | 49 else if (mode == EnterpriseInstallAttributes::kEnterpiseDeviceMode) |
| 50 return DEVICE_MODE_ENTERPRISE; | 50 return DEVICE_MODE_ENTERPRISE; |
| 51 else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode) | 51 else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode) |
| 52 return DEVICE_MODE_RETAIL_KIOSK; | 52 return DEVICE_MODE_RETAIL_KIOSK; |
| 53 else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode) | 53 else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode) |
| 54 return DEVICE_MODE_CONSUMER_KIOSK; | 54 return DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH; |
| 55 NOTREACHED() << "Unknown device mode string: " << mode; | 55 NOTREACHED() << "Unknown device mode string: " << mode; |
| 56 return DEVICE_MODE_NOT_SET; | 56 return DEVICE_MODE_NOT_SET; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool ReadMapKey(const std::map<std::string, std::string>& map, | 59 bool ReadMapKey(const std::map<std::string, std::string>& map, |
| 60 const std::string& key, | 60 const std::string& key, |
| 61 std::string* value) { | 61 std::string* value) { |
| 62 std::map<std::string, std::string>::const_iterator entry = map.find(key); | 62 std::map<std::string, std::string>::const_iterator entry = map.find(key); |
| 63 if (entry == map.end()) | 63 if (entry == map.end()) |
| 64 return false; | 64 return false; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const std::string& user, | 183 const std::string& user, |
| 184 DeviceMode device_mode, | 184 DeviceMode device_mode, |
| 185 const std::string& device_id, | 185 const std::string& device_id, |
| 186 const LockResultCallback& callback) { | 186 const LockResultCallback& callback) { |
| 187 DCHECK(!callback.is_null()); | 187 DCHECK(!callback.is_null()); |
| 188 CHECK_NE(device_mode, DEVICE_MODE_PENDING); | 188 CHECK_NE(device_mode, DEVICE_MODE_PENDING); |
| 189 CHECK_NE(device_mode, DEVICE_MODE_NOT_SET); | 189 CHECK_NE(device_mode, DEVICE_MODE_NOT_SET); |
| 190 | 190 |
| 191 // Check for existing lock first. | 191 // Check for existing lock first. |
| 192 if (device_locked_) { | 192 if (device_locked_) { |
| 193 if (device_mode == DEVICE_MODE_CONSUMER_KIOSK) { | 193 if (device_mode == DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH) { |
| 194 callback.Run((registration_mode_ == device_mode) ? LOCK_SUCCESS : | 194 callback.Run((registration_mode_ == device_mode) ? LOCK_SUCCESS : |
| 195 LOCK_NOT_READY); | 195 LOCK_NOT_READY); |
| 196 } else { | 196 } else { |
| 197 std::string domain = gaia::ExtractDomainName(user); | 197 std::string domain = gaia::ExtractDomainName(user); |
| 198 callback.Run( | 198 callback.Run( |
| 199 (!registration_domain_.empty() && domain == registration_domain_) ? | 199 (!registration_domain_.empty() && domain == registration_domain_) ? |
| 200 LOCK_SUCCESS : LOCK_WRONG_USER); | 200 LOCK_SUCCESS : LOCK_WRONG_USER); |
| 201 } | 201 } |
| 202 return; | 202 return; |
| 203 } | 203 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (!cryptohome_util::InstallAttributesIsFirstInstall()) { | 240 if (!cryptohome_util::InstallAttributesIsFirstInstall()) { |
| 241 callback.Run(LOCK_WRONG_USER); | 241 callback.Run(LOCK_WRONG_USER); |
| 242 return; | 242 return; |
| 243 } | 243 } |
| 244 | 244 |
| 245 std::string mode = GetDeviceModeString(device_mode); | 245 std::string mode = GetDeviceModeString(device_mode); |
| 246 std::string registration_user; | 246 std::string registration_user; |
| 247 if (!user.empty()) | 247 if (!user.empty()) |
| 248 registration_user = gaia::CanonicalizeEmail(user); | 248 registration_user = gaia::CanonicalizeEmail(user); |
| 249 | 249 |
| 250 if (device_mode == DEVICE_MODE_CONSUMER_KIOSK) { | 250 if (device_mode == DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH) { |
| 251 // Set values in the InstallAttrs and lock it. | 251 // Set values in the InstallAttrs and lock it. |
| 252 if (!cryptohome_util::InstallAttributesSet(kAttrConsumerKioskEnabled, | 252 if (!cryptohome_util::InstallAttributesSet(kAttrConsumerKioskEnabled, |
| 253 "true")) { | 253 "true")) { |
| 254 LOG(ERROR) << "Failed writing attributes"; | 254 LOG(ERROR) << "Failed writing attributes"; |
| 255 callback.Run(LOCK_BACKEND_ERROR); | 255 callback.Run(LOCK_BACKEND_ERROR); |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 } else { | 258 } else { |
| 259 std::string domain = gaia::ExtractDomainName(registration_user); | 259 std::string domain = gaia::ExtractDomainName(registration_user); |
| 260 // Set values in the InstallAttrs and lock it. | 260 // Set values in the InstallAttrs and lock it. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| 299 callback.Run(LOCK_SUCCESS); | 299 callback.Run(LOCK_SUCCESS); |
| 300 } | 300 } |
| 301 | 301 |
| 302 bool EnterpriseInstallAttributes::IsEnterpriseDevice() { | 302 bool EnterpriseInstallAttributes::IsEnterpriseDevice() { |
| 303 return device_locked_ && !registration_user_.empty(); | 303 return device_locked_ && !registration_user_.empty(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool EnterpriseInstallAttributes::IsConsumerKioskDevice() { | 306 bool EnterpriseInstallAttributes::IsConsumerKioskDeviceWithAutoLaunch() { |
| 307 return device_locked_ && registration_mode_ == DEVICE_MODE_CONSUMER_KIOSK; | 307 return device_locked_ && |
| 308 registration_mode_ == DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH; |
| 308 } | 309 } |
| 309 | 310 |
| 310 std::string EnterpriseInstallAttributes::GetRegistrationUser() { | 311 std::string EnterpriseInstallAttributes::GetRegistrationUser() { |
| 311 if (!device_locked_) | 312 if (!device_locked_) |
| 312 return std::string(); | 313 return std::string(); |
| 313 | 314 |
| 314 return registration_user_; | 315 return registration_user_; |
| 315 } | 316 } |
| 316 | 317 |
| 317 std::string EnterpriseInstallAttributes::GetDomain() { | 318 std::string EnterpriseInstallAttributes::GetDomain() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 359 |
| 359 ReadMapKey(attr_map, kAttrEnterpriseDeviceId, ®istration_device_id_); | 360 ReadMapKey(attr_map, kAttrEnterpriseDeviceId, ®istration_device_id_); |
| 360 | 361 |
| 361 std::string mode; | 362 std::string mode; |
| 362 if (ReadMapKey(attr_map, kAttrEnterpriseMode, &mode)) | 363 if (ReadMapKey(attr_map, kAttrEnterpriseMode, &mode)) |
| 363 registration_mode_ = GetDeviceModeFromString(mode); | 364 registration_mode_ = GetDeviceModeFromString(mode); |
| 364 } else if (ReadMapKey(attr_map, | 365 } else if (ReadMapKey(attr_map, |
| 365 kAttrConsumerKioskEnabled, | 366 kAttrConsumerKioskEnabled, |
| 366 &consumer_kiosk_enabled) && | 367 &consumer_kiosk_enabled) && |
| 367 consumer_kiosk_enabled == "true") { | 368 consumer_kiosk_enabled == "true") { |
| 368 registration_mode_ = DEVICE_MODE_CONSUMER_KIOSK; | 369 registration_mode_ = DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH; |
| 369 } else if (enterprise_user.empty() && enterprise_owned != "true") { | 370 } else if (enterprise_user.empty() && enterprise_owned != "true") { |
| 370 // |registration_user_| is empty on consumer devices. | 371 // |registration_user_| is empty on consumer devices. |
| 371 registration_mode_ = DEVICE_MODE_CONSUMER; | 372 registration_mode_ = DEVICE_MODE_CONSUMER; |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| 375 } // namespace policy | 376 } // namespace policy |
| OLD | NEW |