From: Sungbae Yoo Date: Wed, 22 Mar 2017 05:06:08 +0000 (+0900) Subject: Change to allow duplicated mount/umount API calls for lockscreen X-Git-Tag: submit/tizen/20170322.105714 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Ftags%2Fsubmit%2Ftizen%2F20170322.105714;p=platform%2Fcore%2Fsecurity%2Fode.git Change to allow duplicated mount/umount API calls for lockscreen Signed-off-by: Sungbae Yoo Change-Id: Ieab8aea8507a9138645ec2a991a08e3981be4a22 --- diff --git a/server/engine/encryption/dmcrypt-engine.cpp b/server/engine/encryption/dmcrypt-engine.cpp index 7baf6e5..30b88fc 100644 --- a/server/engine/encryption/dmcrypt-engine.cpp +++ b/server/engine/encryption/dmcrypt-engine.cpp @@ -246,6 +246,8 @@ void DMCryptEngine::mount(const DMCryptEngine::data &key, unsigned int options) if (::mount(cryptoBlkDev.c_str(), destination.c_str(), "ext4", 0, 0) < 0) throw runtime::Exception(runtime::GetSystemErrorMessage()); + + mounted = true; } void DMCryptEngine::umount() @@ -254,6 +256,13 @@ void DMCryptEngine::umount() throw runtime::Exception(runtime::GetSystemErrorMessage()); destroyCryptoBlkDev(DM_DEFAULT_LABEL_NAME); + + mounted = false; +} + +bool DMCryptEngine::isMounted() +{ + return mounted; } void DMCryptEngine::encrypt(const DMCryptEngine::data &key, unsigned int options) diff --git a/server/engine/encryption/dmcrypt-engine.h b/server/engine/encryption/dmcrypt-engine.h index 45efeee..3c8d5f3 100644 --- a/server/engine/encryption/dmcrypt-engine.h +++ b/server/engine/encryption/dmcrypt-engine.h @@ -19,6 +19,7 @@ #include #include +#include #include "progress-bar.h" @@ -48,6 +49,7 @@ public: void mount(const data &key, unsigned int options); void umount(); + bool isMounted(); void encrypt(const data &key, unsigned int options); void decrypt(const data &key, unsigned int options); @@ -62,6 +64,7 @@ public: private: std::string source, destination; ProgressBar progress; + std::atomic mounted; }; } // namespace ode diff --git a/server/engine/encryption/ecryptfs-engine.cpp b/server/engine/encryption/ecryptfs-engine.cpp index b7d2161..b4a1c03 100644 --- a/server/engine/encryption/ecryptfs-engine.cpp +++ b/server/engine/encryption/ecryptfs-engine.cpp @@ -325,11 +325,20 @@ EcryptfsEngine::~EcryptfsEngine() void EcryptfsEngine::mount(const data &key, unsigned int options) { ecryptfsMount(source, destination, key, options); + + mounted = true; } void EcryptfsEngine::umount() { ecryptfsUmount(destination); + + mounted = false; +} + +bool EcryptfsEngine::isMounted() +{ + return mounted; } void EcryptfsEngine::encrypt(const data &key, unsigned int options) diff --git a/server/engine/encryption/ecryptfs-engine.h b/server/engine/encryption/ecryptfs-engine.h index 983ed6d..1adeec7 100644 --- a/server/engine/encryption/ecryptfs-engine.h +++ b/server/engine/encryption/ecryptfs-engine.h @@ -19,6 +19,7 @@ #include #include +#include #include "progress-bar.h" @@ -48,6 +49,7 @@ public: void mount(const data& key, unsigned int); void umount(); + bool isMounted(); void encrypt(const data& key, unsigned int); void decrypt(const data& key, unsigned int); @@ -62,6 +64,7 @@ public: private: std::string source, destination; ProgressBar progress; + std::atomic mounted; }; } // namespace ode diff --git a/server/engine/encryption/ext4-engine.cpp b/server/engine/encryption/ext4-engine.cpp index 4e47551..351266a 100644 --- a/server/engine/encryption/ext4-engine.cpp +++ b/server/engine/encryption/ext4-engine.cpp @@ -310,6 +310,8 @@ void Ext4Engine::mount(const Ext4Engine::data& key, unsigned int options) if (::mount(encryptedPath.c_str(), destination.c_str(), NULL, MS_BIND, 0) < 0) { throw runtime::Exception("Mount error - " + runtime::GetSystemErrorMessage()); } + + mounted = true; } void Ext4Engine::umount() @@ -319,6 +321,13 @@ void Ext4Engine::umount() if (::umount(destination.c_str())) { throw runtime::Exception(runtime::GetSystemErrorMessage()); } + + mounted = false; +} + +bool Ext4Engine::isMounted() +{ + return mounted; } void Ext4Engine::encrypt(const Ext4Engine::data& key, unsigned int options) diff --git a/server/engine/encryption/ext4-engine.h b/server/engine/encryption/ext4-engine.h index dd69b70..f1aecec 100644 --- a/server/engine/encryption/ext4-engine.h +++ b/server/engine/encryption/ext4-engine.h @@ -19,6 +19,7 @@ #include #include +#include #include "progress-bar.h" @@ -48,6 +49,7 @@ public: void mount(const data &key, unsigned int options); void umount(); + bool isMounted(); void encrypt(const data &key, unsigned int options); void decrypt(const data &key, unsigned int options); @@ -62,6 +64,7 @@ public: private: std::string source, destination; ProgressBar progress; + std::atomic mounted; }; } // namespace ode diff --git a/server/external-encryption.cpp b/server/external-encryption.cpp index 82d2690..0033904 100644 --- a/server/external-encryption.cpp +++ b/server/external-encryption.cpp @@ -201,6 +201,11 @@ int ExternalEncryption::mount(const std::string &password) return -2; } + if (engine->isMounted()) { + INFO("Already mounted"); + return 0; + } + engine->mount(keyManager.getMasterKey(data), getOptions()); context.notify("ExternalEncryption::mount"); @@ -213,6 +218,11 @@ int ExternalEncryption::umount() return -1; } + if (!engine->isMounted()) { + INFO("Already umounted"); + return 0; + } + INFO("Close all applications using external storage..."); killDependedApplications(); INFO("Umount external storage..."); diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index f1a1a0d..63c0f24 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -234,6 +234,11 @@ int InternalEncryption::mount(const std::string& password) return -2; } + if (engine->isMounted()) { + INFO("Already mounted"); + return 0; + } + engine->mount(keyManager.getMasterKey(pwData), getOptions()); context.notify("InternalEncryption::mount"); @@ -246,6 +251,11 @@ int InternalEncryption::umount() return -1; } + if (!engine->isMounted()) { + INFO("Already umounted"); + return 0; + } + INFO("Close all processes using internal storage..."); stopDependedSystemdServices(); INFO("Umount internal storage...");