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

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

Issue 9403010: Add support for kiosk mode on the client. Make sure the settings are written in the lockbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 8 years, 10 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) 2011 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 9
10 namespace em = enterprise_management;
11
10 namespace { 12 namespace {
11 13
12 const char kAttrEnterpriseOwned[] = "enterprise.owned"; 14 const char kAttrEnterpriseOwned[] = "enterprise.owned";
13 const char kAttrEnterpriseUser[] = "enterprise.user"; 15 const char kAttrEnterpriseUser[] = "enterprise.user";
16 const char kAttrEnterpriseDomain[] = "enterprise.domain";
17 const char kAttrEnterpriseMode[] = "enterprise.mode";
18 const char kAttrEnterpriseDeviceId[] = "enterprise.device_id";
19
20 // Extract the domain from a given email.
21 std::string ExtractDomainName(const std::string& email) {
22 size_t separator_pos = email.find('@');
23 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.
24 return email.substr(separator_pos + 1);
25 else
26 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.
27 return std::string();
28 }
14 29
15 } // namespace 30 } // namespace
16 31
17 namespace policy { 32 namespace policy {
18 33
34 const char kEnterpiseDeviceMode[] = "enterprise";
35 const char kKioskDeviceMode[] = "kiosk";
36
19 EnterpriseInstallAttributes::EnterpriseInstallAttributes( 37 EnterpriseInstallAttributes::EnterpriseInstallAttributes(
20 chromeos::CryptohomeLibrary* cryptohome) 38 chromeos::CryptohomeLibrary* cryptohome)
21 : cryptohome_(cryptohome), 39 : cryptohome_(cryptohome),
22 device_locked_(false) {} 40 device_locked_(false),
41 registration_mode_(em::DeviceRegisterResponse::ENTERPRISE) {}
23 42
24 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice( 43 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice(
25 const std::string& user) { 44 const std::string& user,
45 em::DeviceRegisterResponse_DeviceMode device_mode,
46 const std::string& device_id) {
26 // Check for existing lock first. 47 // Check for existing lock first.
27 if (device_locked_) { 48 if (device_locked_) {
28 return !registration_user_.empty() && user == registration_user_ ? 49 return !registration_user_.empty() && user == registration_user_ ?
29 LOCK_SUCCESS : LOCK_WRONG_USER; 50 LOCK_SUCCESS : LOCK_WRONG_USER;
30 } 51 }
31 52
32 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady()) 53 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady())
33 return LOCK_NOT_READY; 54 return LOCK_NOT_READY;
34 55
35 // Clearing the TPM password seems to be always a good deal. 56 // Clearing the TPM password seems to be always a good deal.
36 if (cryptohome_->TpmIsEnabled() && 57 if (cryptohome_->TpmIsEnabled() &&
37 !cryptohome_->TpmIsBeingOwned() && 58 !cryptohome_->TpmIsBeingOwned() &&
38 cryptohome_->TpmIsOwned()) { 59 cryptohome_->TpmIsOwned()) {
39 cryptohome_->TpmClearStoredPassword(); 60 cryptohome_->TpmClearStoredPassword();
40 } 61 }
41 62
42 // Make sure we really have a working InstallAttrs. 63 // Make sure we really have a working InstallAttrs.
43 if (cryptohome_->InstallAttributesIsInvalid()) { 64 if (cryptohome_->InstallAttributesIsInvalid()) {
44 LOG(ERROR) << "Install attributes invalid."; 65 LOG(ERROR) << "Install attributes invalid.";
45 return LOCK_BACKEND_ERROR; 66 return LOCK_BACKEND_ERROR;
46 } 67 }
47 68
48 if (!cryptohome_->InstallAttributesIsFirstInstall()) 69 if (!cryptohome_->InstallAttributesIsFirstInstall())
49 return LOCK_WRONG_USER; 70 return LOCK_WRONG_USER;
50 71
72 std::string domain = ExtractDomainName(user);
73 std::string mode;
74 switch (device_mode) {
75 case em::DeviceRegisterResponse::ENTERPRISE:
76 mode = kEnterpiseDeviceMode;
77 break;
78 case em::DeviceRegisterResponse::KIOSK:
79 mode = kKioskDeviceMode;
80 break;
81 default:
82 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.
83 }
84
51 // Set values in the InstallAttrs and lock it. 85 // Set values in the InstallAttrs and lock it.
52 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") || 86 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") ||
53 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user)) { 87 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user) ||
88 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) ||
89 !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) ||
90 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId, device_id)) {
54 LOG(ERROR) << "Failed writing attributes"; 91 LOG(ERROR) << "Failed writing attributes";
55 return LOCK_BACKEND_ERROR; 92 return LOCK_BACKEND_ERROR;
56 } 93 }
57 94
58 if (!cryptohome_->InstallAttributesFinalize() || 95 if (!cryptohome_->InstallAttributesFinalize() ||
59 cryptohome_->InstallAttributesIsFirstInstall() || 96 cryptohome_->InstallAttributesIsFirstInstall() ||
60 GetRegistrationUser() != user) { 97 GetRegistrationUser() != user) {
61 LOG(ERROR) << "Failed locking."; 98 LOG(ERROR) << "Failed locking.";
62 return LOCK_BACKEND_ERROR; 99 return LOCK_BACKEND_ERROR;
63 } 100 }
(...skipping 12 matching lines...) Expand all
76 if (!device_locked_) 113 if (!device_locked_)
77 return std::string(); 114 return std::string();
78 115
79 return registration_user_; 116 return registration_user_;
80 } 117 }
81 118
82 std::string EnterpriseInstallAttributes::GetDomain() { 119 std::string EnterpriseInstallAttributes::GetDomain() {
83 if (!IsEnterpriseDevice()) 120 if (!IsEnterpriseDevice())
84 return std::string(); 121 return std::string();
85 122
86 std::string domain; 123 return registration_domain_;
87 size_t pos = registration_user_.find('@'); 124 }
88 if (pos != std::string::npos)
89 domain = registration_user_.substr(pos + 1);
90 125
91 return domain; 126 std::string EnterpriseInstallAttributes::GetDeviceId() {
127 if (!IsEnterpriseDevice())
128 return std::string();
129
130 return registration_device_id_;
131 }
132
133 em::DeviceRegisterResponse_DeviceMode EnterpriseInstallAttributes::GetMode() {
134 if (!IsEnterpriseDevice())
135 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.
136
137 return registration_mode_;
92 } 138 }
93 139
94 void EnterpriseInstallAttributes::ReadImmutableAttributes() { 140 void EnterpriseInstallAttributes::ReadImmutableAttributes() {
95 if (device_locked_) 141 if (device_locked_)
96 return; 142 return;
97 143
98 if (cryptohome_ && 144 if (cryptohome_ &&
99 cryptohome_->InstallAttributesIsReady() && 145 cryptohome_->InstallAttributesIsReady() &&
100 !cryptohome_->InstallAttributesIsInvalid() && 146 !cryptohome_->InstallAttributesIsInvalid() &&
101 !cryptohome_->InstallAttributesIsFirstInstall()) { 147 !cryptohome_->InstallAttributesIsFirstInstall()) {
102 device_locked_ = true; 148 device_locked_ = true;
103 std::string enterprise_owned; 149 std::string enterprise_owned;
104 std::string enterprise_user; 150 std::string enterprise_user;
105 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseOwned, 151 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseOwned,
106 &enterprise_owned) && 152 &enterprise_owned) &&
107 cryptohome_->InstallAttributesGet(kAttrEnterpriseUser, 153 cryptohome_->InstallAttributesGet(kAttrEnterpriseUser,
108 &enterprise_user) && 154 &enterprise_user) &&
109 enterprise_owned == "true" && 155 enterprise_owned == "true" &&
110 !enterprise_user.empty()) { 156 !enterprise_user.empty()) {
111 registration_user_ = enterprise_user; 157 registration_user_ = enterprise_user;
158 // If we could extract basic setting we should try to extract the extended
159 // ones too. We try to set those to defaults as good as possible if not
160 // present.
161 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDomain,
162 &registration_domain_)) {
163 registration_domain_ = ExtractDomainName(registration_user_);
164 }
165 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDeviceId,
166 &registration_device_id_)) {
167 registration_device_id_.clear();
168 }
169 std::string enterprise_mode;
170 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseMode,
171 &enterprise_mode)) {
172 if (enterprise_mode == kEnterpiseDeviceMode)
173 registration_mode_ = em::DeviceRegisterResponse::ENTERPRISE;
174 else if (enterprise_mode == kKioskDeviceMode)
175 registration_mode_ = em::DeviceRegisterResponse::KIOSK;
176 else
177 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.
178 }
112 } 179 }
113 } 180 }
114 } 181 }
115 182
116 } // namespace policy 183 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698