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

Side by Side Diff: mount.cc

Issue 6598074: DoAutomaticFreeDiskSpaceControl() introduced (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cryptohome.git@master
Patch Set: Created 9 years, 9 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
« no previous file with comments | « mount.h ('k') | mount_task.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009-2010 The Chromium OS 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 // Contains the implementation of class Mount 5 // Contains the implementation of class Mount
6 6
7 #include "mount.h" 7 #include "mount.h"
8 8
9 #include <errno.h> 9 #include <errno.h>
10 10
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 471 }
472 file_util::Delete(tmp_migrated_dir, true); 472 file_util::Delete(tmp_migrated_dir, true);
473 } 473 }
474 } 474 }
475 475
476 // Restore the umask 476 // Restore the umask
477 platform_->SetMask(original_mask); 477 platform_->SetMask(original_mask);
478 return result; 478 return result;
479 } 479 }
480 480
481 void Mount::CleanUnmountedTrackedSubdirectories() const { 481 void Mount::DoForEveryUnmountedCryptohome(CryptohomeCallback callback) const {
482 FilePath shadow_root(shadow_root_); 482 FilePath shadow_root(shadow_root_);
483 file_util::FileEnumerator dir_enumerator(shadow_root, false, 483 file_util::FileEnumerator dir_enumerator(shadow_root, false,
484 file_util::FileEnumerator::DIRECTORIES); 484 file_util::FileEnumerator::DIRECTORIES);
485 for (FilePath next_path = dir_enumerator.Next(); !next_path.empty(); 485 for (FilePath next_path = dir_enumerator.Next(); !next_path.empty();
486 next_path = dir_enumerator.Next()) { 486 next_path = dir_enumerator.Next()) {
487 FilePath dir_name = next_path.BaseName(); 487 FilePath dir_name = next_path.BaseName();
488 string str_dir_name = dir_name.value(); 488 string str_dir_name = dir_name.value();
489 if (str_dir_name.length() != kUserDirNameLength) { 489 if (str_dir_name.length() != kUserDirNameLength) {
490 continue; 490 continue;
491 } 491 }
492 bool valid_name = true; 492 bool valid_name = true;
493 for (string::const_iterator itr = str_dir_name.begin(); 493 for (string::const_iterator itr = str_dir_name.begin();
494 itr < str_dir_name.end(); ++itr) { 494 itr < str_dir_name.end(); ++itr) {
495 if (!isxdigit(*itr)) { 495 if (!isxdigit(*itr)) {
496 valid_name = false; 496 valid_name = false;
497 break; 497 break;
498 } 498 }
499 } 499 }
500 if (!valid_name) { 500 if (!valid_name) {
501 continue; 501 continue;
502 } 502 }
503 FilePath vault_path = next_path.Append("vault"); 503 FilePath vault_path = next_path.Append("vault");
504 if (!file_util::DirectoryExists(vault_path)) { 504 if (!file_util::DirectoryExists(vault_path)) {
505 continue; 505 continue;
506 } 506 }
507 if (platform_->IsDirectoryMountedWith(home_dir_, vault_path.value())) { 507 if (platform_->IsDirectoryMountedWith(home_dir_, vault_path.value())) {
508 continue; 508 continue;
509 } 509 }
510 file_util::FileEnumerator subdir_enumerator( 510 callback(vault_path);
511 vault_path, 511 }
512 false, 512 }
513 file_util::FileEnumerator::DIRECTORIES); 513
514 for (FilePath subdir_path = subdir_enumerator.Next(); !subdir_path.empty(); 514 // Deletes all tracking subdirectories of the given vault.
515 subdir_path = subdir_enumerator.Next()) { 515 static void DeleteTrackedDirsCallback(const FilePath& vault) {
516 FilePath subdir_name = subdir_path.BaseName(); 516 file_util::FileEnumerator subdir_enumerator(
517 if (subdir_name.value().find(kEncryptedFilePrefix) == 0) { 517 vault, false, file_util::FileEnumerator::DIRECTORIES);
518 continue; 518 for (FilePath subdir_path = subdir_enumerator.Next(); !subdir_path.empty();
519 } 519 subdir_path = subdir_enumerator.Next()) {
520 if (subdir_name.value().compare(".") == 0 || 520 FilePath subdir_name = subdir_path.BaseName();
521 subdir_name.value().compare("..") == 0) { 521 if (subdir_name.value().find(kEncryptedFilePrefix) == 0) {
522 continue; 522 continue;
523 }
524 file_util::Delete(subdir_path, true);
525 } 523 }
524 if (subdir_name.value().compare(".") == 0 ||
525 subdir_name.value().compare("..") == 0) {
526 continue;
527 }
528 file_util::Delete(subdir_path, true);
526 } 529 }
527 } 530 }
528 531
532 void Mount::CleanUnmountedTrackedSubdirectories() const {
533 DoForEveryUnmountedCryptohome(&DeleteTrackedDirsCallback);
534 }
535
536 // Deletes Cache tracking directory of the given vault.
537 static void DeleteCacheCallback(const FilePath& vault) {
538 LOG(WARNING) << "Deleting Cache for user " << vault.value();
539 file_util::Delete(vault.Append(kCacheDir), true);
540 }
541
542 void Mount::DoAutomaticFreeDiskSpaceControl() const {
543 if (platform_->AmountOfFreeDiskSpace(home_dir_) > kMinFreeSpace)
544 return;
545
546 // Clean Cache directories for every user (except current one).
547 DoForEveryUnmountedCryptohome(&DeleteCacheCallback);
548
549 // TODO(glotov): do further cleanup.
550 }
551
529 bool Mount::TestCredentials(const Credentials& credentials) const { 552 bool Mount::TestCredentials(const Credentials& credentials) const {
530 // If the current logged in user matches, use the UserSession to verify the 553 // If the current logged in user matches, use the UserSession to verify the
531 // credentials. This is less costly than a trip to the TPM, and only verifies 554 // credentials. This is less costly than a trip to the TPM, and only verifies
532 // a user during their logged in session. 555 // a user during their logged in session.
533 if (current_user_->CheckUser(credentials)) { 556 if (current_user_->CheckUser(credentials)) {
534 return current_user_->Verify(credentials); 557 return current_user_->Verify(credentials);
535 } 558 }
536 MountError mount_error; 559 MountError mount_error;
537 VaultKeyset vault_keyset; 560 VaultKeyset vault_keyset;
538 SerializedVaultKeyset serialized; 561 SerializedVaultKeyset serialized;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 if (error) { 1072 if (error) {
1050 *error = Mount::MOUNT_ERROR_KEY_FAILURE; 1073 *error = Mount::MOUNT_ERROR_KEY_FAILURE;
1051 } 1074 }
1052 return false; 1075 return false;
1053 } 1076 }
1054 1077
1055 return true; 1078 return true;
1056 } 1079 }
1057 1080
1058 } // namespace cryptohome 1081 } // namespace cryptohome
OLDNEW
« no previous file with comments | « mount.h ('k') | mount_task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698