Chromium Code Reviews| Index: chrome/browser/policy/enterprise_install_attributes.cc |
| diff --git a/chrome/browser/policy/enterprise_install_attributes.cc b/chrome/browser/policy/enterprise_install_attributes.cc |
| index 6d897228622f529fd412a8a5ebf7dea2a9477eaa..984d0957011ed1f8551eb5b2110ef1859a8fdad2 100644 |
| --- a/chrome/browser/policy/enterprise_install_attributes.cc |
| +++ b/chrome/browser/policy/enterprise_install_attributes.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -7,22 +7,43 @@ |
| #include "base/logging.h" |
| #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| +namespace em = enterprise_management; |
| + |
| namespace { |
| const char kAttrEnterpriseOwned[] = "enterprise.owned"; |
| const char kAttrEnterpriseUser[] = "enterprise.user"; |
| +const char kAttrEnterpriseDomain[] = "enterprise.domain"; |
| +const char kAttrEnterpriseMode[] = "enterprise.mode"; |
| +const char kAttrEnterpriseDeviceId[] = "enterprise.device_id"; |
| + |
| +// Extract the domain from a given email. |
| +std::string ExtractDomainName(const std::string& email) { |
| + size_t separator_pos = email.find('@'); |
| + if (separator_pos != email.npos && separator_pos < email.length()-1) |
|
Mattias Nissler (ping if slow)
2012/02/15 15:32:03
spaces around -
pastarmovj
2012/02/15 17:40:14
Done.
|
| + return email.substr(separator_pos + 1); |
| + else |
| + NOTREACHED() << "|user| is not a proper email address."; |
|
Mattias Nissler (ping if slow)
2012/02/15 15:32:03
Change this to "Not a proper email: " << email;
pastarmovj
2012/02/15 17:40:14
Done.
|
| + return std::string(); |
| +} |
| } // namespace |
| namespace policy { |
| +const char kEnterpiseDeviceMode[] = "enterprise"; |
| +const char kKioskDeviceMode[] = "kiosk"; |
| + |
| EnterpriseInstallAttributes::EnterpriseInstallAttributes( |
| chromeos::CryptohomeLibrary* cryptohome) |
| : cryptohome_(cryptohome), |
| - device_locked_(false) {} |
| + device_locked_(false), |
| + registration_mode_(em::DeviceRegisterResponse::ENTERPRISE) {} |
| EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice( |
| - const std::string& user) { |
| + const std::string& user, |
| + em::DeviceRegisterResponse_DeviceMode device_mode, |
| + const std::string& device_id) { |
| // Check for existing lock first. |
| if (device_locked_) { |
| return !registration_user_.empty() && user == registration_user_ ? |
| @@ -48,9 +69,25 @@ EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice( |
| if (!cryptohome_->InstallAttributesIsFirstInstall()) |
| return LOCK_WRONG_USER; |
| + std::string domain = ExtractDomainName(user); |
| + std::string mode; |
| + switch (device_mode) { |
| + case em::DeviceRegisterResponse::ENTERPRISE: |
| + mode = kEnterpiseDeviceMode; |
| + break; |
| + case em::DeviceRegisterResponse::KIOSK: |
| + mode = kKioskDeviceMode; |
| + break; |
| + default: |
| + NOTREACHED() << "Unknown device mode: " << device_mode; |
|
Mattias Nissler (ping if slow)
2012/02/15 15:32:03
a function for translating to the string would be
pastarmovj
2012/02/15 17:40:14
Done.
|
| + } |
| + |
| // Set values in the InstallAttrs and lock it. |
| if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") || |
| - !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user)) { |
| + !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user) || |
| + !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) || |
| + !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) || |
| + !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId, device_id)) { |
| LOG(ERROR) << "Failed writing attributes"; |
| return LOCK_BACKEND_ERROR; |
| } |
| @@ -83,12 +120,21 @@ std::string EnterpriseInstallAttributes::GetDomain() { |
| if (!IsEnterpriseDevice()) |
| return std::string(); |
| - std::string domain; |
| - size_t pos = registration_user_.find('@'); |
| - if (pos != std::string::npos) |
| - domain = registration_user_.substr(pos + 1); |
| + return registration_domain_; |
| +} |
| + |
| +std::string EnterpriseInstallAttributes::GetDeviceId() { |
| + if (!IsEnterpriseDevice()) |
| + return std::string(); |
| + |
| + return registration_device_id_; |
| +} |
| + |
| +em::DeviceRegisterResponse_DeviceMode EnterpriseInstallAttributes::GetMode() { |
| + if (!IsEnterpriseDevice()) |
| + VLOG(1) << "Calling GetMode on non-enrolled device"; |
|
Mattias Nissler (ping if slow)
2012/02/15 15:32:03
VLOG_IF
pastarmovj
2012/02/15 17:40:14
Not needed.
|
| - return domain; |
| + return registration_mode_; |
| } |
| void EnterpriseInstallAttributes::ReadImmutableAttributes() { |
| @@ -109,6 +155,27 @@ void EnterpriseInstallAttributes::ReadImmutableAttributes() { |
| enterprise_owned == "true" && |
| !enterprise_user.empty()) { |
| registration_user_ = enterprise_user; |
| + // If we could extract basic setting we should try to extract the extended |
| + // ones too. We try to set those to defaults as good as possible if not |
| + // present. |
| + if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDomain, |
| + ®istration_domain_)) { |
| + registration_domain_ = ExtractDomainName(registration_user_); |
| + } |
| + if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDeviceId, |
| + ®istration_device_id_)) { |
| + registration_device_id_.clear(); |
| + } |
| + std::string enterprise_mode; |
| + if (cryptohome_->InstallAttributesGet(kAttrEnterpriseMode, |
| + &enterprise_mode)) { |
| + if (enterprise_mode == kEnterpiseDeviceMode) |
| + registration_mode_ = em::DeviceRegisterResponse::ENTERPRISE; |
| + else if (enterprise_mode == kKioskDeviceMode) |
| + registration_mode_ = em::DeviceRegisterResponse::KIOSK; |
| + else |
| + NOTREACHED() << "Unknown enterprise mode : " << enterprise_mode; |
|
Mattias Nissler (ping if slow)
2012/02/15 15:32:03
same here, use a function for translating.
pastarmovj
2012/02/15 17:40:14
Done.
|
| + } |
| } |
| } |
| } |