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

Unified Diff: service.cc

Issue 2645008: Update on feedback, update dbus API, add unit tests. TEST=manual,unit,BVT BUG=3628 323 (Closed) Base URL: ssh://git@chromiumos-git/cryptohome.git
Patch Set: Address second round of feedback. Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service.h ('k') | service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service.cc
diff --git a/service.cc b/service.cc
index bbe5c35c536e045e911278c642b77bb9904c1034..fc4771267a50260b585bc56d1510fe3f7a759371 100644
--- a/service.cc
+++ b/service.cc
@@ -1,17 +1,19 @@
// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cryptohome/service.h"
-#include <base/logging.h>
-#include <chromeos/dbus/dbus.h>
+#include "service.h"
+
#include <stdio.h>
#include <stdlib.h>
-#include "cryptohome/interface.h"
-#include "cryptohome/mount.h"
-#include "cryptohome/secure_blob.h"
-#include "cryptohome/username_passkey.h"
+#include <base/logging.h>
+#include <chromeos/dbus/dbus.h>
+
+#include "interface.h"
+#include "mount.h"
+#include "secure_blob.h"
+#include "username_passkey.h"
// Forcibly namespace the dbus-bindings generated server bindings instead of
// modifying the files afterward.
@@ -26,22 +28,19 @@ namespace cryptohome {
Service::Service() : loop_(NULL),
cryptohome_(NULL),
system_salt_(),
- mount_(NULL) { }
+ default_mount_(new cryptohome::Mount()),
+ mount_(default_mount_.get()) { }
Service::~Service() {
if (loop_)
g_main_loop_unref(loop_);
if (cryptohome_)
g_object_unref(cryptohome_);
- if (mount_)
- delete mount_;
}
bool Service::Initialize() {
- if(mount_ == NULL) {
- mount_ = new cryptohome::Mount();
- mount_->Init();
- }
+ mount_->Init();
+
// Install the type-info for the service with dbus.
dbus_g_object_type_install_info(gobject::cryptohome_get_type(),
&gobject::dbus_glib_cryptohome_object_info);
@@ -71,8 +70,7 @@ gboolean Service::CheckKey(gchar *userid,
gchar *key,
gboolean *OUT_success,
GError **error) {
- UsernamePasskey credentials(userid, strlen(userid),
- chromeos::Blob(key, key + strlen(key)));
+ UsernamePasskey credentials(userid, SecureBlob(key, strlen(key)));
// TODO(fes): Handle CHROMEOS_PAM_LOCALACCOUNT
*OUT_success = mount_->TestCredentials(credentials);
@@ -84,8 +82,7 @@ gboolean Service::MigrateKey(gchar *userid,
gchar *to_key,
gboolean *OUT_success,
GError **error) {
- UsernamePasskey credentials(userid, strlen(userid),
- chromeos::Blob(to_key, to_key + strlen(to_key)));
+ UsernamePasskey credentials(userid, SecureBlob(to_key, strlen(to_key)));
*OUT_success = mount_->MigratePasskey(credentials, from_key);
return TRUE;
@@ -94,16 +91,15 @@ gboolean Service::MigrateKey(gchar *userid,
gboolean Service::Remove(gchar *userid,
gboolean *OUT_success,
GError **error) {
- UsernamePasskey credentials(userid, strlen(userid),
- chromeos::Blob());
+ UsernamePasskey credentials(userid, chromeos::Blob());
*OUT_success = mount_->RemoveCryptohome(credentials);
return TRUE;
}
gboolean Service::GetSystemSalt(GArray **OUT_salt, GError **error) {
- if(system_salt_.size() == 0) {
- system_salt_ = mount_->GetSystemSalt();
+ if (system_salt_.size() == 0) {
+ mount_->GetSystemSalt(&system_salt_);
}
*OUT_salt = g_array_new(false, false, 1);
g_array_append_vals(*OUT_salt, &system_salt_.front(), system_salt_.size());
@@ -118,42 +114,54 @@ gboolean Service::IsMounted(gboolean *OUT_is_mounted, GError **error) {
gboolean Service::Mount(gchar *userid,
gchar *key,
+ gint *OUT_error,
gboolean *OUT_done,
GError **error) {
- UsernamePasskey credentials(userid, strlen(userid),
- chromeos::Blob(key, key + strlen(key)));
+ UsernamePasskey credentials(userid, SecureBlob(key, strlen(key)));
- if(mount_->IsCryptohomeMounted()) {
- if(mount_->IsCryptohomeMountedForUser(credentials)) {
+ if (mount_->IsCryptohomeMounted()) {
+ if (mount_->IsCryptohomeMountedForUser(credentials)) {
LOG(INFO) << "Cryptohome already mounted for this user";
+ *OUT_error = Mount::MOUNT_ERROR_NONE;
*OUT_done = TRUE;
return TRUE;
} else {
- if(!mount_->UnmountCryptohome()) {
+ if (!mount_->UnmountCryptohome()) {
LOG(ERROR) << "Could not unmount cryptohome from previous user";
+ *OUT_error = Mount::MOUNT_ERROR_MOUNT_POINT_BUSY;
*OUT_done = FALSE;
return TRUE;
}
}
}
- // TODO(fes): Iterate keys if we change how cryptohome keeps track of key
- // indexes. Right now, 0 is always the current, and 0+n should only be used
- // temporarily during password migration.
- Mount::MountError mount_error = Mount::MOUNT_ERROR_NONE;
- *OUT_done = mount_->MountCryptohome(credentials, 0, &mount_error);
- if(!(*OUT_done) && (mount_error == Mount::MOUNT_ERROR_KEY_FAILURE)) {
- // If there is a key failure, create cryptohome from scratch.
- // TODO(fes): remove this when Chrome is no longer expecting this behavior.
- if(mount_->RemoveCryptohome(credentials)) {
- *OUT_done = mount_->MountCryptohome(credentials, 0, &mount_error);
+ // We only check key 0 because it is the only key that we use. Other indexes
+ // are only used in password migration.
+ Mount::MountError local_error = Mount::MOUNT_ERROR_NONE;
+ *OUT_done = mount_->MountCryptohome(credentials, 0, &local_error);
+ *OUT_error = local_error;
+ return TRUE;
+}
+
+gboolean Service::MountGuest(gint *OUT_error,
+ gboolean *OUT_done,
+ GError **error) {
+ if (mount_->IsCryptohomeMounted()) {
+ if (!mount_->UnmountCryptohome()) {
+ LOG(ERROR) << "Could not unmount cryptohome from previous user";
+ *OUT_error = Mount::MOUNT_ERROR_MOUNT_POINT_BUSY;
+ *OUT_done = FALSE;
+ return TRUE;
}
}
+
+ *OUT_error = Mount::MOUNT_ERROR_NONE;
+ *OUT_done = mount_->MountGuestCryptohome();
return TRUE;
}
gboolean Service::Unmount(gboolean *OUT_done, GError **error) {
- if(mount_->IsCryptohomeMounted()) {
+ if (mount_->IsCryptohomeMounted()) {
*OUT_done = mount_->UnmountCryptohome();
} else {
*OUT_done = true;
« no previous file with comments | « service.h ('k') | service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698