Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: chrome/browser/policy/enterprise_install_attributes.cc

Issue 10443125: Allow re-enrollment to the same domain in case of policy data loss. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/policy/enterprise_install_attributes.h" 5 #include "chrome/browser/policy/enterprise_install_attributes.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 8 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
9 #include "chrome/browser/chromeos/login/authenticator.h"
9 10
10 namespace policy { 11 namespace policy {
11 12
12 namespace { 13 namespace {
13 // Constants for the possible device modes that can be stored in the lockbox. 14 // Constants for the possible device modes that can be stored in the lockbox.
14 const char kConsumerDeviceMode[] = "consumer"; 15 const char kConsumerDeviceMode[] = "consumer";
15 const char kEnterpiseDeviceMode[] = "enterprise"; 16 const char kEnterpiseDeviceMode[] = "enterprise";
16 const char kKioskDeviceMode[] = "kiosk"; 17 const char kKioskDeviceMode[] = "kiosk";
17 const char kUnknownDeviceMode[] = "unknown"; 18 const char kUnknownDeviceMode[] = "unknown";
18 19
19 // Field names in the lockbox. 20 // Field names in the lockbox.
20 const char kAttrEnterpriseDeviceId[] = "enterprise.device_id"; 21 const char kAttrEnterpriseDeviceId[] = "enterprise.device_id";
21 const char kAttrEnterpriseDomain[] = "enterprise.domain"; 22 const char kAttrEnterpriseDomain[] = "enterprise.domain";
22 const char kAttrEnterpriseMode[] = "enterprise.mode"; 23 const char kAttrEnterpriseMode[] = "enterprise.mode";
23 const char kAttrEnterpriseOwned[] = "enterprise.owned"; 24 const char kAttrEnterpriseOwned[] = "enterprise.owned";
24 const char kAttrEnterpriseUser[] = "enterprise.user"; 25 const char kAttrEnterpriseUser[] = "enterprise.user";
25 26
26 // Extract the domain from a given email.
27 std::string ExtractDomainName(const std::string& email) {
28 size_t separator_pos = email.find('@');
29 if (separator_pos != email.npos && separator_pos < email.length() - 1)
30 return email.substr(separator_pos + 1);
31 else
32 NOTREACHED() << "Not a proper email address: " << email;
33 return std::string();
34 }
35
36 // Translates DeviceMode constants to strings used in the lockbox. 27 // Translates DeviceMode constants to strings used in the lockbox.
37 std::string GetDeviceModeString(DeviceMode mode) { 28 std::string GetDeviceModeString(DeviceMode mode) {
38 switch (mode) { 29 switch (mode) {
39 case DEVICE_MODE_CONSUMER: 30 case DEVICE_MODE_CONSUMER:
40 return kConsumerDeviceMode; 31 return kConsumerDeviceMode;
41 case DEVICE_MODE_ENTERPRISE: 32 case DEVICE_MODE_ENTERPRISE:
42 return kEnterpiseDeviceMode; 33 return kEnterpiseDeviceMode;
43 case DEVICE_MODE_KIOSK: 34 case DEVICE_MODE_KIOSK:
44 return kKioskDeviceMode; 35 return kKioskDeviceMode;
45 case DEVICE_MODE_PENDING: 36 case DEVICE_MODE_PENDING:
(...skipping 25 matching lines...) Expand all
71 device_locked_(false), 62 device_locked_(false),
72 registration_mode_(DEVICE_MODE_PENDING) {} 63 registration_mode_(DEVICE_MODE_PENDING) {}
73 64
74 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice( 65 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice(
75 const std::string& user, 66 const std::string& user,
76 DeviceMode device_mode, 67 DeviceMode device_mode,
77 const std::string& device_id) { 68 const std::string& device_id) {
78 CHECK_NE(device_mode, DEVICE_MODE_PENDING); 69 CHECK_NE(device_mode, DEVICE_MODE_PENDING);
79 CHECK_NE(device_mode, DEVICE_MODE_NOT_SET); 70 CHECK_NE(device_mode, DEVICE_MODE_NOT_SET);
80 71
72 std::string domain = chromeos::Authenticator::ExtractDomainName(user);
73
81 // Check for existing lock first. 74 // Check for existing lock first.
82 if (device_locked_) { 75 if (device_locked_) {
83 return !registration_user_.empty() && user == registration_user_ ? 76 return !registration_domain_.empty() && domain == registration_domain_ ?
84 LOCK_SUCCESS : LOCK_WRONG_USER; 77 LOCK_SUCCESS : LOCK_WRONG_USER;
85 } 78 }
86 79
87 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady()) 80 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady())
88 return LOCK_NOT_READY; 81 return LOCK_NOT_READY;
89 82
90 // Clearing the TPM password seems to be always a good deal. 83 // Clearing the TPM password seems to be always a good deal.
91 if (cryptohome_->TpmIsEnabled() && 84 if (cryptohome_->TpmIsEnabled() &&
92 !cryptohome_->TpmIsBeingOwned() && 85 !cryptohome_->TpmIsBeingOwned() &&
93 cryptohome_->TpmIsOwned()) { 86 cryptohome_->TpmIsOwned()) {
94 cryptohome_->TpmClearStoredPassword(); 87 cryptohome_->TpmClearStoredPassword();
95 } 88 }
96 89
97 // Make sure we really have a working InstallAttrs. 90 // Make sure we really have a working InstallAttrs.
98 if (cryptohome_->InstallAttributesIsInvalid()) { 91 if (cryptohome_->InstallAttributesIsInvalid()) {
99 LOG(ERROR) << "Install attributes invalid."; 92 LOG(ERROR) << "Install attributes invalid.";
100 return LOCK_BACKEND_ERROR; 93 return LOCK_BACKEND_ERROR;
101 } 94 }
102 95
103 if (!cryptohome_->InstallAttributesIsFirstInstall()) 96 if (!cryptohome_->InstallAttributesIsFirstInstall())
104 return LOCK_WRONG_USER; 97 return LOCK_WRONG_USER;
105 98
106 std::string domain = ExtractDomainName(user);
107 std::string mode = GetDeviceModeString(device_mode); 99 std::string mode = GetDeviceModeString(device_mode);
108 100
109 // Set values in the InstallAttrs and lock it. 101 // Set values in the InstallAttrs and lock it.
110 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") || 102 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") ||
111 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user) || 103 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user) ||
112 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) || 104 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) ||
113 !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) || 105 !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) ||
114 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId, device_id)) { 106 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId, device_id)) {
115 LOG(ERROR) << "Failed writing attributes"; 107 LOG(ERROR) << "Failed writing attributes";
116 return LOCK_BACKEND_ERROR; 108 return LOCK_BACKEND_ERROR;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 !cryptohome_->InstallAttributesIsFirstInstall()) { 161 !cryptohome_->InstallAttributesIsFirstInstall()) {
170 device_locked_ = true; 162 device_locked_ = true;
171 std::string enterprise_owned; 163 std::string enterprise_owned;
172 std::string enterprise_user; 164 std::string enterprise_user;
173 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseOwned, 165 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseOwned,
174 &enterprise_owned) && 166 &enterprise_owned) &&
175 cryptohome_->InstallAttributesGet(kAttrEnterpriseUser, 167 cryptohome_->InstallAttributesGet(kAttrEnterpriseUser,
176 &enterprise_user) && 168 &enterprise_user) &&
177 enterprise_owned == "true" && 169 enterprise_owned == "true" &&
178 !enterprise_user.empty()) { 170 !enterprise_user.empty()) {
179 registration_user_ = enterprise_user; 171 registration_user_ =
172 chromeos::Authenticator::Canonicalize(enterprise_user);
180 173
181 // Initialize the mode to the legacy enterprise mode here and update 174 // Initialize the mode to the legacy enterprise mode here and update
182 // below if more information is present. 175 // below if more information is present.
183 registration_mode_ = DEVICE_MODE_ENTERPRISE; 176 registration_mode_ = DEVICE_MODE_ENTERPRISE;
184 177
185 // If we could extract basic setting we should try to extract the 178 // If we could extract basic setting we should try to extract the
186 // extended ones too. We try to set these to defaults as good as 179 // extended ones too. We try to set these to defaults as good as
187 // as possible if present, which could happen for device enrolled in 180 // as possible if present, which could happen for device enrolled in
188 // pre 19 revisions of the code, before these new attributes were added. 181 // pre 19 revisions of the code, before these new attributes were added.
189 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDomain, 182 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDomain,
Mattias Nissler (ping if slow) 2012/06/18 16:45:17 nit: Invert the logic so this is easier to follow.
pastarmovj 2012/06/18 17:12:58 Done.
190 &registration_domain_)) { 183 &registration_domain_)) {
191 registration_domain_ = ExtractDomainName(registration_user_); 184 registration_domain_ =
185 chromeos::Authenticator::ExtractDomainName(registration_user_);
186 } else {
187 registration_domain_ =
188 chromeos::Authenticator::CanonicalizeDomain(registration_domain_);
192 } 189 }
193 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDeviceId, 190 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDeviceId,
194 &registration_device_id_)) { 191 &registration_device_id_)) {
195 registration_device_id_.clear(); 192 registration_device_id_.clear();
196 } 193 }
197 std::string mode; 194 std::string mode;
198 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseMode, &mode)) 195 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseMode, &mode))
199 registration_mode_ = GetDeviceModeFromString(mode); 196 registration_mode_ = GetDeviceModeFromString(mode);
200 } else if (enterprise_user.empty() && enterprise_owned != "true") { 197 } else if (enterprise_user.empty() && enterprise_owned != "true") {
201 // |registration_user_| is empty on consumer devices. 198 // |registration_user_| is empty on consumer devices.
202 registration_mode_ = DEVICE_MODE_CONSUMER; 199 registration_mode_ = DEVICE_MODE_CONSUMER;
203 } 200 }
204 } 201 }
205 } 202 }
206 } 203 }
207 204
208 } // namespace policy 205 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698