libbrillo: Add GetDaemonPathForTemporaryUserHome to cryptohome utilities
Similar to GetDaemonPath, GetDaemonPathForTemporaryUserHome returns
the directory where the passed daemon should store its data for a
temporary user home mount.
BUG=chromium:722371
TEST=Tests still pass, actual functionality tested by CL
https://chromium-review.googlesource.com/c/562158/
Change-Id: I06efeed13bc611bab9baa542de47d9f7112e792e
Reviewed-on: https://chromium-review.googlesource.com/562277
Commit-Ready: Pavol Marko <pmarko@chromium.org>
Tested-by: Pavol Marko <pmarko@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
diff --git a/brillo/cryptohome.cc b/brillo/cryptohome.cc
index 49a4a88..88e4739 100644
--- a/brillo/cryptohome.cc
+++ b/brillo/cryptohome.cc
@@ -24,6 +24,17 @@
const char kGuestUserName[] = "$guest";
+// Path to user homes mounted with the mount_hidden option. The user home mount
+// will be located at:
+// kHiddenUserHomeBaseDir/<sanitized_user_name>/kHiddenUserHomeMountSubdir
+const char kHiddenUserHomeBaseDir[] = "/home/.shadow";
+const char kHiddenUserHomeMountSubdir[] = "mount";
+
+// Subdirectory of a user home mount where daemon-specific data is stored.
+// This is used to assemble daemon data storage paths for hidden user home
+// mounts.
+const char kHiddenUserHomeRootSubdir[] = "root";
+
static char g_user_home_prefix[PATH_MAX] = "/home/user/";
static char g_root_home_prefix[PATH_MAX] = "/home/root/";
static char g_system_salt_path[PATH_MAX] = "/home/.shadow/salt";
@@ -92,23 +103,35 @@
FilePath GetUserPath(const std::string& username) {
if (!EnsureSystemSaltIsLoaded())
- return FilePath("");
+ return FilePath();
return GetHashedUserPath(SanitizeUserName(username));
}
FilePath GetRootPath(const std::string& username) {
if (!EnsureSystemSaltIsLoaded())
- return FilePath("");
+ return FilePath();
return FilePath(base::StringPrintf(
"%s%s", g_root_home_prefix, SanitizeUserName(username).c_str()));
}
FilePath GetDaemonPath(const std::string& username, const std::string& daemon) {
if (!EnsureSystemSaltIsLoaded())
- return FilePath("");
+ return FilePath();
return GetRootPath(username).Append(daemon);
}
+FilePath GetDaemonPathForHiddenUserHome(const std::string& username,
+ const std::string& daemon) {
+ if (!EnsureSystemSaltIsLoaded())
+ return FilePath();
+
+ return FilePath(kHiddenUserHomeBaseDir)
+ .Append(SanitizeUserName(username))
+ .Append(kHiddenUserHomeMountSubdir)
+ .Append(kHiddenUserHomeRootSubdir)
+ .Append(daemon);
+}
+
bool IsSanitizedUserName(const std::string& sanitized) {
std::vector<uint8_t> bytes;
return (sanitized.length() == 2 * SHA_DIGEST_LENGTH) &&
diff --git a/brillo/cryptohome.h b/brillo/cryptohome.h
index caca31b..798d3a0 100644
--- a/brillo/cryptohome.h
+++ b/brillo/cryptohome.h
@@ -42,6 +42,12 @@
BRILLO_EXPORT base::FilePath GetDaemonPath(const std::string& username,
const std::string& daemon);
+// Returns the path at which the daemon |daemon| should store per-user data
+// when the user's home was mounted with mount_hidden.
+BRILLO_EXPORT base::FilePath GetDaemonPathForHiddenUserHome(
+ const std::string& username,
+ const std::string& daemon);
+
// Checks whether |sanitized| has the format of a sanitized username.
BRILLO_EXPORT bool IsSanitizedUserName(const std::string& sanitized);