OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/login/supervised_user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/supervised_user_manager_impl.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 "SupervisedUserPasswordSchema"; | 67 "SupervisedUserPasswordSchema"; |
68 | 68 |
69 // A map from user id to password salt. | 69 // A map from user id to password salt. |
70 const char kSupervisedUserPasswordSalt[] = | 70 const char kSupervisedUserPasswordSalt[] = |
71 "SupervisedUserPasswordSalt"; | 71 "SupervisedUserPasswordSalt"; |
72 | 72 |
73 // A map from user id to password revision. | 73 // A map from user id to password revision. |
74 const char kSupervisedUserPasswordRevision[] = | 74 const char kSupervisedUserPasswordRevision[] = |
75 "SupervisedUserPasswordRevision"; | 75 "SupervisedUserPasswordRevision"; |
76 | 76 |
| 77 // A map from user id to flag indicating if password should be updated upon |
| 78 // signin. |
| 79 const char kSupervisedUserNeedPasswordUpdate[] = |
| 80 "SupervisedUserNeedPasswordUpdate"; |
| 81 |
| 82 // A map from user id to flag indicating if cryptohome does not have signature |
| 83 // key. |
| 84 const char kSupervisedUserIncompleteKey[] = "SupervisedUserHasIncompleteKey"; |
| 85 |
77 std::string LoadSyncToken(base::FilePath profile_dir) { | 86 std::string LoadSyncToken(base::FilePath profile_dir) { |
78 std::string token; | 87 std::string token; |
79 base::FilePath token_file = | 88 base::FilePath token_file = |
80 profile_dir.Append(chromeos::kManagedUserTokenFilename); | 89 profile_dir.Append(chromeos::kManagedUserTokenFilename); |
81 VLOG(1) << "Loading" << token_file.value(); | 90 VLOG(1) << "Loading" << token_file.value(); |
82 if (!base::ReadFileToString(token_file, &token)) | 91 if (!base::ReadFileToString(token_file, &token)) |
83 return std::string(); | 92 return std::string(); |
84 return token; | 93 return token; |
85 } | 94 } |
86 | 95 |
(...skipping 23 matching lines...) Expand all Loading... |
110 registry->RegisterStringPref( | 119 registry->RegisterStringPref( |
111 kLocallyManagedUserCreationTransactionUserId, ""); | 120 kLocallyManagedUserCreationTransactionUserId, ""); |
112 registry->RegisterDictionaryPref(kManagedUserSyncId); | 121 registry->RegisterDictionaryPref(kManagedUserSyncId); |
113 registry->RegisterDictionaryPref(kManagedUserManagers); | 122 registry->RegisterDictionaryPref(kManagedUserManagers); |
114 registry->RegisterDictionaryPref(kManagedUserManagerNames); | 123 registry->RegisterDictionaryPref(kManagedUserManagerNames); |
115 registry->RegisterDictionaryPref(kManagedUserManagerDisplayEmails); | 124 registry->RegisterDictionaryPref(kManagedUserManagerDisplayEmails); |
116 | 125 |
117 registry->RegisterDictionaryPref(kSupervisedUserPasswordSchema); | 126 registry->RegisterDictionaryPref(kSupervisedUserPasswordSchema); |
118 registry->RegisterDictionaryPref(kSupervisedUserPasswordSalt); | 127 registry->RegisterDictionaryPref(kSupervisedUserPasswordSalt); |
119 registry->RegisterDictionaryPref(kSupervisedUserPasswordRevision); | 128 registry->RegisterDictionaryPref(kSupervisedUserPasswordRevision); |
| 129 |
| 130 registry->RegisterDictionaryPref(kSupervisedUserNeedPasswordUpdate); |
| 131 registry->RegisterDictionaryPref(kSupervisedUserIncompleteKey); |
120 } | 132 } |
121 | 133 |
122 SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner) | 134 SupervisedUserManagerImpl::SupervisedUserManagerImpl(UserManagerImpl* owner) |
123 : owner_(owner), | 135 : owner_(owner), |
124 cros_settings_(CrosSettings::Get()) { | 136 cros_settings_(CrosSettings::Get()) { |
125 // SupervisedUserManager instance should be used only on UI thread. | 137 // SupervisedUserManager instance should be used only on UI thread. |
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
127 authentication_.reset(new SupervisedUserAuthentication(this)); | 139 authentication_.reset(new SupervisedUserAuthentication(this)); |
128 } | 140 } |
129 | 141 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 258 |
247 void SupervisedUserManagerImpl::GetPasswordInformation( | 259 void SupervisedUserManagerImpl::GetPasswordInformation( |
248 const std::string& user_id, | 260 const std::string& user_id, |
249 base::DictionaryValue* result) { | 261 base::DictionaryValue* result) { |
250 int value; | 262 int value; |
251 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, &value)) | 263 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, &value)) |
252 result->SetIntegerWithoutPathExpansion(kSchemaVersion, value); | 264 result->SetIntegerWithoutPathExpansion(kSchemaVersion, value); |
253 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, &value)) | 265 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, &value)) |
254 result->SetIntegerWithoutPathExpansion(kPasswordRevision, value); | 266 result->SetIntegerWithoutPathExpansion(kPasswordRevision, value); |
255 | 267 |
| 268 bool flag; |
| 269 if (GetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate, &flag)) |
| 270 result->SetBooleanWithoutPathExpansion(kRequirePasswordUpdate, flag); |
| 271 if (GetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, &flag)) |
| 272 result->SetBooleanWithoutPathExpansion(kHasIncompleteKey, flag); |
| 273 |
256 std::string salt; | 274 std::string salt; |
257 if (GetUserStringValue(user_id, kSupervisedUserPasswordSalt, &salt)) | 275 if (GetUserStringValue(user_id, kSupervisedUserPasswordSalt, &salt)) |
258 result->SetStringWithoutPathExpansion(kSalt, salt); | 276 result->SetStringWithoutPathExpansion(kSalt, salt); |
259 } | 277 } |
260 | 278 |
261 void SupervisedUserManagerImpl::SetPasswordInformation( | 279 void SupervisedUserManagerImpl::SetPasswordInformation( |
262 const std::string& user_id, | 280 const std::string& user_id, |
263 const base::DictionaryValue* password_info) { | 281 const base::DictionaryValue* password_info) { |
264 int value; | 282 int value; |
265 if (password_info->GetIntegerWithoutPathExpansion(kSchemaVersion, &value)) | 283 if (password_info->GetIntegerWithoutPathExpansion(kSchemaVersion, &value)) |
266 SetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, value); | 284 SetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, value); |
267 if (password_info->GetIntegerWithoutPathExpansion(kPasswordRevision, &value)) | 285 if (password_info->GetIntegerWithoutPathExpansion(kPasswordRevision, &value)) |
268 SetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, value); | 286 SetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, value); |
269 | 287 |
| 288 bool flag; |
| 289 if (password_info->GetBooleanWithoutPathExpansion(kRequirePasswordUpdate, |
| 290 &flag)) { |
| 291 SetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate, flag); |
| 292 } |
| 293 if (password_info->GetBooleanWithoutPathExpansion(kHasIncompleteKey, &flag)) |
| 294 SetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, flag); |
| 295 |
270 std::string salt; | 296 std::string salt; |
271 if (password_info->GetStringWithoutPathExpansion(kSalt, &salt)) | 297 if (password_info->GetStringWithoutPathExpansion(kSalt, &salt)) |
272 SetUserStringValue(user_id, kSupervisedUserPasswordSalt, salt); | 298 SetUserStringValue(user_id, kSupervisedUserPasswordSalt, salt); |
273 g_browser_process->local_state()->CommitPendingWrite(); | 299 g_browser_process->local_state()->CommitPendingWrite(); |
274 } | 300 } |
275 | 301 |
276 bool SupervisedUserManagerImpl::GetUserStringValue( | 302 bool SupervisedUserManagerImpl::GetUserStringValue( |
277 const std::string& user_id, | 303 const std::string& user_id, |
278 const char* key, | 304 const char* key, |
279 std::string* out_value) const { | 305 std::string* out_value) const { |
280 PrefService* local_state = g_browser_process->local_state(); | 306 PrefService* local_state = g_browser_process->local_state(); |
281 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); | 307 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); |
282 return dictionary->GetStringWithoutPathExpansion(user_id, out_value); | 308 return dictionary->GetStringWithoutPathExpansion(user_id, out_value); |
283 } | 309 } |
284 | 310 |
285 bool SupervisedUserManagerImpl::GetUserIntegerValue( | 311 bool SupervisedUserManagerImpl::GetUserIntegerValue( |
286 const std::string& user_id, | 312 const std::string& user_id, |
287 const char* key, | 313 const char* key, |
288 int* out_value) const { | 314 int* out_value) const { |
289 PrefService* local_state = g_browser_process->local_state(); | 315 PrefService* local_state = g_browser_process->local_state(); |
290 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); | 316 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); |
291 return dictionary->GetIntegerWithoutPathExpansion(user_id, out_value); | 317 return dictionary->GetIntegerWithoutPathExpansion(user_id, out_value); |
292 } | 318 } |
293 | 319 |
| 320 bool SupervisedUserManagerImpl::GetUserBooleanValue(const std::string& user_id, |
| 321 const char* key, |
| 322 bool* out_value) const { |
| 323 PrefService* local_state = g_browser_process->local_state(); |
| 324 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); |
| 325 return dictionary->GetBooleanWithoutPathExpansion(user_id, out_value); |
| 326 } |
| 327 |
294 void SupervisedUserManagerImpl::SetUserStringValue( | 328 void SupervisedUserManagerImpl::SetUserStringValue( |
295 const std::string& user_id, | 329 const std::string& user_id, |
296 const char* key, | 330 const char* key, |
297 const std::string& value) { | 331 const std::string& value) { |
298 PrefService* local_state = g_browser_process->local_state(); | 332 PrefService* local_state = g_browser_process->local_state(); |
299 DictionaryPrefUpdate update(local_state, key); | 333 DictionaryPrefUpdate update(local_state, key); |
300 update->SetStringWithoutPathExpansion(user_id, value); | 334 update->SetStringWithoutPathExpansion(user_id, value); |
301 } | 335 } |
302 | 336 |
303 void SupervisedUserManagerImpl::SetUserIntegerValue( | 337 void SupervisedUserManagerImpl::SetUserIntegerValue( |
304 const std::string& user_id, | 338 const std::string& user_id, |
305 const char* key, | 339 const char* key, |
306 const int value) { | 340 const int value) { |
307 PrefService* local_state = g_browser_process->local_state(); | 341 PrefService* local_state = g_browser_process->local_state(); |
308 DictionaryPrefUpdate update(local_state, key); | 342 DictionaryPrefUpdate update(local_state, key); |
309 update->SetIntegerWithoutPathExpansion(user_id, value); | 343 update->SetIntegerWithoutPathExpansion(user_id, value); |
310 } | 344 } |
311 | 345 |
| 346 void SupervisedUserManagerImpl::SetUserBooleanValue(const std::string& user_id, |
| 347 const char* key, |
| 348 const bool value) { |
| 349 PrefService* local_state = g_browser_process->local_state(); |
| 350 DictionaryPrefUpdate update(local_state, key); |
| 351 update->SetBooleanWithoutPathExpansion(user_id, value); |
| 352 } |
| 353 |
312 const User* SupervisedUserManagerImpl::FindByDisplayName( | 354 const User* SupervisedUserManagerImpl::FindByDisplayName( |
313 const base::string16& display_name) const { | 355 const base::string16& display_name) const { |
314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
315 const UserList& users = owner_->GetUsers(); | 357 const UserList& users = owner_->GetUsers(); |
316 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 358 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
317 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && | 359 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && |
318 ((*it)->display_name() == display_name)) { | 360 ((*it)->display_name() == display_name)) { |
319 return *it; | 361 return *it; |
320 } | 362 } |
321 } | 363 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 ListPrefUpdate prefs_new_users_update(prefs, kLocallyManagedUsersFirstRun); | 447 ListPrefUpdate prefs_new_users_update(prefs, kLocallyManagedUsersFirstRun); |
406 prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 448 prefs_new_users_update->Remove(base::StringValue(user_id), NULL); |
407 | 449 |
408 CleanPref(user_id, kManagedUserSyncId); | 450 CleanPref(user_id, kManagedUserSyncId); |
409 CleanPref(user_id, kManagedUserManagers); | 451 CleanPref(user_id, kManagedUserManagers); |
410 CleanPref(user_id, kManagedUserManagerNames); | 452 CleanPref(user_id, kManagedUserManagerNames); |
411 CleanPref(user_id, kManagedUserManagerDisplayEmails); | 453 CleanPref(user_id, kManagedUserManagerDisplayEmails); |
412 CleanPref(user_id, kSupervisedUserPasswordSalt); | 454 CleanPref(user_id, kSupervisedUserPasswordSalt); |
413 CleanPref(user_id, kSupervisedUserPasswordSchema); | 455 CleanPref(user_id, kSupervisedUserPasswordSchema); |
414 CleanPref(user_id, kSupervisedUserPasswordRevision); | 456 CleanPref(user_id, kSupervisedUserPasswordRevision); |
| 457 CleanPref(user_id, kSupervisedUserNeedPasswordUpdate); |
| 458 CleanPref(user_id, kSupervisedUserIncompleteKey); |
415 } | 459 } |
416 | 460 |
417 void SupervisedUserManagerImpl::CleanPref(const std::string& user_id, | 461 void SupervisedUserManagerImpl::CleanPref(const std::string& user_id, |
418 const char* key) { | 462 const char* key) { |
419 PrefService* prefs = g_browser_process->local_state(); | 463 PrefService* prefs = g_browser_process->local_state(); |
420 DictionaryPrefUpdate dict_update(prefs, key); | 464 DictionaryPrefUpdate dict_update(prefs, key); |
421 dict_update->RemoveWithoutPathExpansion(user_id, NULL); | 465 dict_update->RemoveWithoutPathExpansion(user_id, NULL); |
422 } | 466 } |
423 | 467 |
424 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { | 468 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 } | 511 } |
468 | 512 |
469 void SupervisedUserManagerImpl::ConfigureSyncWithToken( | 513 void SupervisedUserManagerImpl::ConfigureSyncWithToken( |
470 Profile* profile, | 514 Profile* profile, |
471 const std::string& token) { | 515 const std::string& token) { |
472 if (!token.empty()) | 516 if (!token.empty()) |
473 ManagedUserServiceFactory::GetForProfile(profile)->InitSync(token); | 517 ManagedUserServiceFactory::GetForProfile(profile)->InitSync(token); |
474 } | 518 } |
475 | 519 |
476 } // namespace chromeos | 520 } // namespace chromeos |
OLD | NEW |