Small cleanups 09/149609/4
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Tue, 12 Sep 2017 11:18:04 +0000 (13:18 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 15 Sep 2017 13:52:42 +0000 (15:52 +0200)
- headers
- formatting
- ordering
- change defines to const char* in anonymous namespace
- remove unneeded VCONF redefines

Change-Id: I07fadbe6f11c30214f1bd6839ef046e2c84b6e3c

server/extension-encryption.cpp
server/external-encryption.cpp
server/internal-encryption.cpp

index c03b13ada06643b386c3ecc78a2c85160f2e9204..7b79ba6b3b05a48c2952c71d9b05e70512cdf94d 100644 (file)
 
 #include "rmi/extension-encryption.h"
 
-#define EXTENSION_ENGINE       CryptsetupEngine
 #define EXTENSION_NAME_DEF     "extension"
 
 namespace ode {
 
 namespace {
 
+typedef CryptsetupEngine EXTENSION_ENGINE;
+
 const size_t DEFAULT_KEY_SIZE = 64;
 
 const char *EXTENSION_DEV_PATH = "/dev/mmcblk1p1";
index c6319b2b03996b04d00ed23f3866058cc23c2c47..f448325a9e6f39a7d38465d6b5f2a82eddaf5685 100644 (file)
 
 #include <vconf.h>
 #include <tzplatform_config.h>
-
 #include <klay/file-user.h>
 #include <klay/filesystem.h>
 #include <klay/dbus/variant.h>
 #include <klay/dbus/connection.h>
 
-#include "vconf.h"
 #include "logger.h"
 #include "launchpad.h"
 #include "app-bundle.h"
@@ -38,7 +36,6 @@
 
 #include "rmi/external-encryption.h"
 
-#define EXTERNAL_ENGINE        EcryptfsEngine
 #define EXTERNAL_PATH  "/opt/media/SDCardA1"
 #define EXTERNAL_STATE_VCONF_KEY VCONFKEY_SDE_CRYPTO_STATE
 #define EXTERNAL_OPTION_ONLY_NEW_FILE_VCONF_KEY VCONFKEY_SDE_ENCRYPT_NEWFILE
@@ -50,6 +47,8 @@ namespace ode {
 
 namespace {
 
+typedef EcryptfsEngine EXTERNAL_ENGINE;
+
 std::unique_ptr<EXTERNAL_ENGINE> engine;
 KeyManager::data mountKey;
 bool isBootCompleted = false;
index d6a284eb9f5bc8a430079372dc2442ec2023e84e..5f0d15cc84daa9f982d59800c8e3e5a884f438e5 100644 (file)
@@ -15,6 +15,7 @@
  */
 #include <set>
 #include <algorithm>
+#include <memory>
 
 #include <fcntl.h>
 #include <signal.h>
@@ -34,7 +35,6 @@
 #include <klay/filesystem.h>
 #include <klay/dbus/connection.h>
 
-#include "vconf.h"
 #include "logger.h"
 #include "progress-bar.h"
 #include "engine/encryption/dmcrypt-engine.h"
 
 #include "rmi/internal-encryption.h"
 
-#define INTERNAL_ENGINE        DMCryptEngine
-#define INTERNAL_DEV_PATH      "/dev/disk/by-partlabel"
-#define INTERNAL_DEV_NAME      "USER"
-#define INTERNAL_PATH          "/opt/usr"
-#define INTERNAL_STATE_VCONF_KEY                                       VCONFKEY_ODE_CRYPTO_STATE
-#define INTERNAL_OPTION_ONLY_USED_REGION_VCONF_KEY     VCONFKEY_ODE_FAST_ENCRYPTION
+namespace ode {
+
+namespace {
+
+typedef DMCryptEngine INTERNAL_ENGINE;
 
-#define PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
+const char *INTERNAL_DEV_PATH  = "/dev/disk/by-partlabel";
+const char *INTERNAL_DEV_NAME  = "USER";
+const char *INTERNAL_PATH              = "/opt/usr";
 
+const char *PRIVILEGE_PLATFORM = "http://tizen.org/privilege/internal/default/platform";
+
+// TODO: see recovery()
 const std::string PROG_FACTORY_RESET = "/usr/bin/dbus-send";
 const std::vector<std::string> wipeCommand = {
     PROG_FACTORY_RESET,
@@ -62,13 +66,12 @@ const std::vector<std::string> wipeCommand = {
     "com.samsung.factoryreset.start.setting"
 };
 
-namespace ode {
-
-namespace {
+std::unique_ptr<INTERNAL_ENGINE> engine;
+KeyManager::data mountKey;
 
 std::string findDevPath()
 {
-       std::string source = INTERNAL_DEV_PATH "/" INTERNAL_DEV_NAME;
+       std::string source = INTERNAL_DEV_PATH + std::string("/") + INTERNAL_DEV_NAME;
        try {
                runtime::DirectoryIterator iter(INTERNAL_DEV_PATH), end;
 
@@ -116,9 +119,6 @@ std::string findMntPath(const std::string &devPath)
        return ret;
 }
 
-std::unique_ptr<INTERNAL_ENGINE> engine;
-KeyManager::data mountKey;
-
 void stopKnownSystemdServices() {
        std::vector<std::string> knownSystemdServices;
        dbus::Connection& systemDBus = dbus::Connection::getSystem();
@@ -230,7 +230,7 @@ unsigned int getOptions()
        int value;
 
        value = 0;
-       ::vconf_get_bool(INTERNAL_OPTION_ONLY_USED_REGION_VCONF_KEY, &value);
+       ::vconf_get_bool(VCONFKEY_ODE_FAST_ENCRYPTION, &value);
        if (value) {
                result |= InternalEncryption::Option::IncludeUnusedRegion;
        }
@@ -247,7 +247,7 @@ void setOptions(unsigned int options)
        } else {
                value = false;
        }
-       ::vconf_set_bool(INTERNAL_OPTION_ONLY_USED_REGION_VCONF_KEY, value);
+       ::vconf_set_bool(VCONFKEY_ODE_FAST_ENCRYPTION, value);
 }
 
 }
@@ -394,14 +394,14 @@ int InternalEncryption::encrypt(const std::string& password, unsigned int option
                        setOptions(options & getSupportedOptions());
 
                        INFO(SINK, "Encryption completed");
-                       ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "encrypted");
+                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "encrypted");
                        context.notify("InternalEncryption::mount");
 
                        INFO(SINK, "Syncing disk and rebooting...");
                        ::sync();
                        ::reboot(RB_AUTOBOOT);
                } catch (runtime::Exception &e) {
-                       ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
+                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted");
                        ERROR(SINK, "Encryption failed - " + std::string(e.what()));
                }
        };
@@ -451,13 +451,13 @@ int InternalEncryption::decrypt(const std::string& password)
                        engine->decrypt(MasterKey, getOptions());
 
                        INFO(SINK, "Decryption completed");
-                       ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "unencrypted");
+                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "unencrypted");
 
                        INFO(SINK, "Syncing disk and rebooting...");
                        ::sync();
                        ::reboot(RB_AUTOBOOT);
                } catch (runtime::Exception &e) {
-                       ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
+                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted");
                        ERROR(SINK, "Decryption failed - " + std::string(e.what()));
                }
        };
@@ -545,7 +545,7 @@ int InternalEncryption::verifyPassword(const std::string& password)
 
 int InternalEncryption::getState()
 {
-       char *value = ::vconf_get_str(INTERNAL_STATE_VCONF_KEY);
+       char *value = ::vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
        if (value == NULL) {
                throw runtime::Exception("Failed to get vconf value");
        }