Fix logger usage according to KLAY API changed 34/139934/1 submit/tizen/20170724.061427
authorsangwan.kwon <sangwan.kwon@samsung.com>
Thu, 20 Jul 2017 08:03:44 +0000 (17:03 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Fri, 21 Jul 2017 05:58:03 +0000 (14:58 +0900)
Change-Id: I1eca335cfeff003a5dcdd1ecd900d0225e33f68c
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
16 files changed:
server/engine/encryption/cryptsetup-engine.cpp
server/engine/encryption/dmcrypt-engine.cpp
server/engine/encryption/ecryptfs-engine.cpp
server/engine/encryption/ext4-engine.cpp
server/engine/erase/mmc-engine.cpp
server/ext4-tool.cpp
server/extension-encryption.cpp
server/external-encryption.cpp
server/file-footer.cpp
server/internal-encryption.cpp
server/key-manager/key-generator.cpp
server/key-manager/key-store.cpp
server/launchpad.cpp
server/logger.h [new file with mode: 0644]
server/server.cpp
tests/main.cpp

index d013d2f..9c35f48 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "cryptsetup-engine.h"
 #include "../../file-footer.h"
+#include "../../logger.h"
 
 #include <cctype>
 #include <algorithm>
@@ -23,7 +24,6 @@
 #include <libcryptsetup.h>
 
 #include <klay/exception.h>
-#include <klay/audit/logger.h>
 
 namespace ode {
 
@@ -52,17 +52,17 @@ void log(int level, const char *msg, void*)
        switch (level)
        {
        case CRYPT_LOG_ERROR:
-               ERROR("[libcryptsetup] " + msgStr);
+               ERROR(SINK, "[libcryptsetup] " + msgStr);
                break;
        case CRYPT_LOG_VERBOSE:
-               INFO("[libcryptsetup] " + msgStr);
+               INFO(SINK, "[libcryptsetup] " + msgStr);
                break;
        case CRYPT_LOG_DEBUG:
        case CRYPT_LOG_NORMAL:
-               DEBUG("[libcryptsetup] " + msgStr);
+               DEBUG(SINK, "[libcryptsetup] " + msgStr);
                break;
        default:
-               ERROR("[libcryptsetup] Unsupported log level. Msg: " + msgStr);
+               ERROR(SINK, "[libcryptsetup] Unsupported log level. Msg: " + msgStr);
        }
 }
 #endif
@@ -120,7 +120,7 @@ public:
        ~Device()
        {
                if (0 != crypt_memory_lock(device, 0))
-               ERROR("Failed to unlock memory");
+               ERROR(SINK, "Failed to unlock memory");
 
                crypt_free(device);
        }
index 0820e49..c4cccfb 100644 (file)
 #include <fcntl.h>
 #include <errno.h>
 
-#include <klay/audit/logger.h>
 
 #include <klay/error.h>
 #include <klay/exception.h>
 #include <klay/filesystem.h>
 
+#include "../../logger.h"
 #include "../../file-footer.h"
 #include "../../ext4-tool.h"
 
@@ -279,10 +279,10 @@ void DMCryptEngine::encrypt(const DMCryptEngine::data &key, unsigned int options
 
        std::function<bool(blkcnt_t)> isTarget;
        if (!(options & OPTION_INCLUDE_UNUSED_REGION)) {
-               INFO("FastEncryption: Disabled");
+               INFO(SINK, "FastEncryption: Disabled");
                isTarget = std::bind(&Ext4Tool::isUsedBlock, &ext4Source, _1);
        } else {
-               INFO("FastEncryption: Enabled");
+               INFO(SINK, "FastEncryption: Enabled");
                isTarget = [](unsigned int n) {
                        return true;
                };
@@ -312,10 +312,10 @@ void DMCryptEngine::decrypt(const DMCryptEngine::data &key, unsigned int options
 
        std::function<bool(blkcnt_t)> isTarget;
        if (!(options & OPTION_INCLUDE_UNUSED_REGION)) {
-               INFO("FastEncryption: Disabled");
+               INFO(SINK, "FastEncryption: Disabled");
                isTarget = std::bind(&Ext4Tool::isUsedBlock, &ext4CryptoBlkDev, _1);
        } else {
-               INFO("FastEncryption: Enabled");
+               INFO(SINK, "FastEncryption: Enabled");
                isTarget = [](unsigned int n) {
                        return true;
                };
index 5c087cf..682bbdd 100644 (file)
 #include <klay/error.h>
 #include <klay/exception.h>
 #include <klay/filesystem.h>
-#include <klay/audit/logger.h>
 
 #include "../../kernel-keyring.h"
 #include "../../file-footer.h"
+#include "../../logger.h"
 
 #include "ecryptfs-engine.h"
 
@@ -311,9 +311,9 @@ void ecryptfsMount(const std::string &source, const std::string &destination, co
                mountOption += ",ecryptfs_enable_filtering=" MEDIA_EXCLUSION_LIST;
        }
 
-       INFO("option = " + mountOption);
-       INFO("source = " + source);
-       INFO("dest = " + destination);
+       INFO(SINK, "option = " + mountOption);
+       INFO(SINK, "source = " + source);
+       INFO(SINK, "dest = " + destination);
 
        if (::mount(source.c_str(), destination.c_str(), "ecryptfs", MS_NODEV,
                                mountOption.c_str()) != 0) {
index a48cb2f..908d841 100755 (executable)
@@ -30,8 +30,8 @@
 #include <klay/error.h>
 #include <klay/exception.h>
 #include <klay/filesystem.h>
-#include <klay/audit/logger.h>
 
+#include "../../logger.h"
 #include "../../kernel-keyring.h"
 #include "../../file-footer.h"
 #include "../../key-manager/key-generator.h"
@@ -113,7 +113,7 @@ void addKeyToKeyring(const Ext4Engine::data& key)
        keyDescriptor = "ext4:" + convertToHex(generateKeyDescriptor(key));
        if (KernelKeyRing::search(keyringId, EXT4_KEYRING_TYPE,
                                                                keyDescriptor, 0) >= 0) {
-               INFO("Key with descriptor already exist");
+               INFO(SINK, "Key with descriptor already exist");
                return;
        }
 
index 470f18f..44cbbf1 100644 (file)
@@ -24,8 +24,8 @@
 #include <vconf.h>
 #include <klay/filesystem.h>
 #include <klay/exception.h>
-#include <klay/audit/logger.h>
 
+#include "logger.h"
 #include "ext4-tool.h"
 #include "block-device.h"
 #include "mmc-engine.h"
index 27770a0..1564dc6 100644 (file)
@@ -21,8 +21,8 @@
 #include <klay/filesystem.h>
 #include <klay/process.h>
 #include <klay/exception.h>
-#include <klay/audit/logger.h>
 
+#include "logger.h"
 #include "ext4-tool.h"
 
 namespace ode {
@@ -170,7 +170,7 @@ void Ext4Tool::readInfo()
 
                        memcpy(bitmap.data() + (blkItr >> 3), block_bitmap.data(), (cnt + 7) >> 3);
                } catch (runtime::Exception &e) {
-                       WARN("Block " + std::to_string(blk) + " is missing");
+                       WARN(SINK, "Block " + std::to_string(blk) + " is missing");
                        memset(bitmap.data() + (blkItr >> 3), 0, (cnt + 7) >> 3);
                }
                blkItr += cnt;
index 06f8b17..f23698f 100644 (file)
 
 #include <klay/file-user.h>
 #include <klay/filesystem.h>
-#include <klay/audit/logger.h>
 #include <klay/dbus/variant.h>
 #include <klay/dbus/connection.h>
 
+#include "logger.h"
 #include "ext4-tool.h"
 #include "engine/encryption/cryptsetup-engine.h"
 #include "key-manager/key-manager.h"
@@ -79,7 +79,7 @@ std::string findMntPath(const std::string &devPath)
 void killDependedApplications(const std::string &mntPath)
 {
        for (pid_t pid : runtime::FileUser::getList(mntPath, true)) {
-               INFO("Close process - " + std::to_string(pid));
+               INFO(SINK, "Close process - " + std::to_string(pid));
                ::kill(pid, SIGKILL);
        }
 }
@@ -88,12 +88,12 @@ bool findKillAndUmount(const std::string &devPath)
 {
        std::string realMntPath = findMntPath(devPath);
        if (!realMntPath.empty()) {
-               INFO("Closing all applications using an SD card...");
+               INFO(SINK, "Closing all applications using an SD card...");
                killDependedApplications(realMntPath);
 
                int ret = ::umount(realMntPath.c_str());
                if (ret != 0) {
-                       ERROR("The card is still mounted, umount failed with: "
+                       ERROR(SINK, "The card is still mounted, umount failed with: "
                                  + std::to_string(ret));
                        return false;
                }
@@ -139,7 +139,7 @@ int ExtensionEncryption::mount(const std::string& password)
        std::unique_lock<std::mutex> stateLock(stateGuard);
 
        if (getStatePriv() != State::Encrypted) {
-               ERROR("Cannot mount, card not inserted or corrupted");
+               ERROR(SINK, "Cannot mount, card not inserted or corrupted");
                return -1;
        }
 
@@ -147,40 +147,40 @@ int ExtensionEncryption::mount(const std::string& password)
        KeyManager keyManager(engine->getKeyMeta());
 
        if (!keyManager.verifyPassword(pwData)) {
-               ERROR("Wrong password passed.");
+               ERROR(SINK, "Wrong password passed.");
                return -2;
        }
 
        if (isMounted()) {
-               INFO("Already mounted");
+               INFO(SINK, "Already mounted");
                return 0;
        }
 
        KeyManager::data mountKey = keyManager.getMasterKey(pwData);
 
-       INFO("Mount extension storage...");
+       INFO(SINK, "Mount extension storage...");
 
        if (!isOpened()) {
                // Storaged will mount MAP automatically when it appears, let's prepare
                currentReq = Request::MOUNT;
 
                try {
-                       INFO("Open the MAP of an extension storage...");
+                       INFO(SINK, "Open the MAP of an extension storage...");
                        engine->open(CryptsetupEngine::DeviceType::LUKS, EXTENSION_NAME, mountKey);
                } catch (runtime::Exception &e) {
-                       ERROR("Open failed: " + std::string(e.what()));
+                       ERROR(SINK, "Open failed: " + std::string(e.what()));
                        return -3;
                }
 
-               INFO("Wait for the storaged to mount the MAP automatically...");
+               INFO(SINK, "Wait for the storaged to mount the MAP automatically...");
                if (!storagedCv.wait_for(stateLock, std::chrono::seconds(1), [this] {
                                        return currentReq == Request::NONE;
                                })) {
-                       ERROR("Storaged timed out mounting the MAP.");
+                       ERROR(SINK, "Storaged timed out mounting the MAP.");
                        return -3;
                }
        } else {
-               INFO("Ask storaged to mount extension storage...");
+               INFO(SINK, "Ask storaged to mount extension storage...");
                if (!storagedMount(stateLock)) {
                        return -3;
                }
@@ -196,33 +196,33 @@ int ExtensionEncryption::umount()
        std::unique_lock<std::mutex> stateLock(stateGuard);
 
        if (getStatePriv() != State::Encrypted) {
-               ERROR("Cannot umount, card not inserted or corrupted.");
+               ERROR(SINK, "Cannot umount, card not inserted or corrupted.");
                return -1;
        }
 
        if (!isMounted() && !isOpened()) {
-               INFO("Already umounted.");
+               INFO(SINK, "Already umounted.");
                return 0;
        }
 
-       INFO("Umount extension storage...");
+       INFO(SINK, "Umount extension storage...");
 
        if (isMounted()) {
-               INFO("Close all applications using extension storage...");
+               INFO(SINK, "Close all applications using extension storage...");
                killDependedApplications(info[Device::MAP].mntPath);
 
-               INFO("Ask storaged to umount extension storage...");
+               INFO(SINK, "Ask storaged to umount extension storage...");
                if (!storagedUnmount(stateLock)) {
                        return -3;
                }
        }
 
        if (isOpened()) {
-               INFO("Close the MAP of an extension storage...");
+               INFO(SINK, "Close the MAP of an extension storage...");
                try {
                        CryptsetupEngine::close(EXTENSION_NAME);
                } catch (runtime::Exception &e) {
-                       ERROR("Close failed: " + std::string(e.what()));
+                       ERROR(SINK, "Close failed: " + std::string(e.what()));
                        return -3;
                }
        }
@@ -241,7 +241,7 @@ int ExtensionEncryption::format(const std::string &password)
                        std::unique_lock<std::mutex> stateLock(stateGuard);
 
                        if (!isInserted()) {
-                               ERROR("There is no card inserted.");
+                               ERROR(SINK, "There is no card inserted.");
                                status = -1;
                                stateLock.unlock();
                                workerCv.notify_one();
@@ -249,7 +249,7 @@ int ExtensionEncryption::format(const std::string &password)
                        }
 
                        if (isMounted() || isOpened()) {
-                               ERROR("The card is still mounted and/or opened, umount and close first.");
+                               ERROR(SINK, "The card is still mounted and/or opened, umount and close first.");
                                status = -1;
                                stateLock.unlock();
                                workerCv.notify_one();
@@ -260,7 +260,7 @@ int ExtensionEncryption::format(const std::string &password)
                        KeyManager keyManager(engine->getKeyMeta());
 
                        if (!keyManager.verifyPassword(pwData)) {
-                               ERROR("Wrong password passed.");
+                               ERROR(SINK, "Wrong password passed.");
                                status = -2;
                                stateLock.unlock();
                                workerCv.notify_one();
@@ -281,24 +281,24 @@ int ExtensionEncryption::format(const std::string &password)
                        if (!findKillAndUmount(EXTENSION_DEV_PATH))
                                return;
 
-                       INFO("Creating LUKS...");
+                       INFO(SINK, "Creating LUKS...");
                        engine->format(CryptsetupEngine::DeviceType::LUKS, masterKey);
 
-                       INFO("Opening LUKS...");
+                       INFO(SINK, "Opening LUKS...");
                        std::string mappingPath = engine->open(CryptsetupEngine::DeviceType::LUKS,
                                                                                                   EXTENSION_NAME,
                                                                                                   masterKey);
 
-                       INFO("Creating EXT4...");
+                       INFO(SINK, "Creating EXT4...");
                        Ext4Tool::mkfs(mappingPath);
 
-                       INFO("Closing up the operation...");
+                       INFO(SINK, "Closing up the operation...");
                        CryptsetupEngine::close(EXTENSION_NAME);
                        sync();
 
-                       INFO("Formatting completed");
+                       INFO(SINK, "Formatting completed");
                } catch (runtime::Exception &e) {
-                       ERROR("Formatting thread failed: " + std::string(e.what()));
+                       ERROR(SINK, "Formatting thread failed: " + std::string(e.what()));
                }
        };
 
@@ -309,7 +309,7 @@ int ExtensionEncryption::format(const std::string &password)
        if(!workerCv.wait_for(stateLock, std::chrono::seconds(1), [&status] {
                                return status != 0;
                        })) {
-               ERROR("Timed out waiting for format status.");
+               ERROR(SINK, "Timed out waiting for format status.");
                return -4;
        }
 
@@ -350,7 +350,7 @@ int ExtensionEncryption::cleanPassword(const std::string& password)
        KeyManager keyManager(engine->getKeyMeta());
 
        if (!keyManager.verifyPassword(pwData)) {
-               ERROR("Wrong password passed.");
+               ERROR(SINK, "Wrong password passed.");
                return -2;
        }
 
@@ -368,7 +368,7 @@ int ExtensionEncryption::changePassword(const std::string &oldPassword,
        KeyManager keyManager(engine->getKeyMeta());
 
        if (!keyManager.verifyPassword(oldPwData)) {
-               ERROR("Wrong password passed.");
+               ERROR(SINK, "Wrong password passed.");
                return -2;
        }
 
@@ -402,17 +402,17 @@ int ExtensionEncryption::getState()
 
 void ExtensionEncryption::logStoragedEvent(Operation op, Device d)
 {
-       DEBUG("Storaged event:");
+       DEBUG(SINK, "Storaged event:");
 
        switch(op) {
        case Operation::ADDED:
-               DEBUG("   Operation: ADDED");
+               DEBUG(SINK, "   Operation: ADDED");
                break;
        case Operation::CHANGED:
-               DEBUG("   Operation: CHANGED");
+               DEBUG(SINK, "   Operation: CHANGED");
                break;
        case Operation::REMOVED:
-               DEBUG("   Operation: REMOVED");
+               DEBUG(SINK, "   Operation: REMOVED");
                break;
        default:
                break;
@@ -420,20 +420,20 @@ void ExtensionEncryption::logStoragedEvent(Operation op, Device d)
 
        switch(d) {
        case Device::MMC:
-               DEBUG("   Device: MMC");
+               DEBUG(SINK, "   Device: MMC");
                break;
        case Device::MAP:
-               DEBUG("   Device: MAP");
+               DEBUG(SINK, "   Device: MAP");
                break;
        default:
                break;
        }
 
-       DEBUG("   Mnt Path: " + info[d].mntPath);
-       DEBUG("   Fs Type: " + info[d].fsType);
-       DEBUG("   Sys path: " + info[d].sysPath);
-       DEBUG("   Mounted: " + std::to_string(info[d].mounted));
-       DEBUG("   ID: " + std::to_string(info[d].storagedId));
+       DEBUG(SINK, "   Mnt Path: " + info[d].mntPath);
+       DEBUG(SINK, "   Fs Type: " + info[d].fsType);
+       DEBUG(SINK, "   Sys path: " + info[d].sysPath);
+       DEBUG(SINK, "   Mounted: " + std::to_string(info[d].mounted));
+       DEBUG(SINK, "   ID: " + std::to_string(info[d].storagedId));
 }
 
 void ExtensionEncryption::handleDevice(Operation op,
@@ -447,7 +447,7 @@ void ExtensionEncryption::handleDevice(Operation op,
        } else if (std::string(strparams[0]) == EXTENSION_MAP_PATH && intparams[0] == 2) {
                d = Device::MAP;
        } else {
-               DEBUG("Storaged event: neither extension MMC nor extension mapping, ignoring");
+               DEBUG(SINK, "Storaged event: neither extension MMC nor extension mapping, ignoring");
                return;
        }
 
@@ -470,18 +470,18 @@ void ExtensionEncryption::handleDevice(Operation op,
                                                         (op == Operation::CHANGED &&
                                                          info[d].fsType != EXTENSION_FS_TYPE))) {
                if (isMounted()) {
-                       INFO("MMC card removed while still mounted, umounting.");
+                       INFO(SINK, "MMC card removed while still mounted, umounting.");
                        if (!findKillAndUmount(EXTENSION_MAP_PATH)) {
                                return;
                        }
                }
 
                if (isOpened()) {
-                       INFO("MMC card removed while LUKS is still opened, closing.");
+                       INFO(SINK, "MMC card removed while LUKS is still opened, closing.");
                        try {
                                CryptsetupEngine::close(EXTENSION_NAME);
                        } catch (runtime::Exception &e) {
-                               ERROR("Closing failed: " + std::string(e.what()));
+                               ERROR(SINK, "Closing failed: " + std::string(e.what()));
                                return;
                        }
                }
@@ -534,7 +534,7 @@ void ExtensionEncryption::parseVariant(Operation op, dbus::Variant parameters)
 
 void ExtensionEncryption::queryStoraged()
 {
-       INFO("Querying the storaged for devices...");
+       INFO(SINK, "Querying the storaged for devices...");
 
        dbus::VariantIterator vi;
 
@@ -548,7 +548,7 @@ void ExtensionEncryption::queryStoraged()
                                                                                                 "(s)",
                                                                                                 "all").get("(a(issssssisibii))", &vi);
        } catch (runtime::Exception &e) {
-               ERROR("Failed to query storaged: " + std::string(e.what()));
+               ERROR(SINK, "Failed to query storaged: " + std::string(e.what()));
        }
 
        std::vector<int> intparams(6);
@@ -621,13 +621,13 @@ bool ExtensionEncryption::storagedMount(std::unique_lock<std::mutex> &lock)
                                                                                                 info[Device::MAP].storagedId,
                                                                                                 info[Device::MAP].mntPath.c_str()).get("(i)", &ret);
        } catch (runtime::Exception &e) {
-               ERROR("Failed to call mount in storaged: " + std::string(e.what()));
+               ERROR(SINK, "Failed to call mount in storaged: " + std::string(e.what()));
                currentReq = Request::NONE;
                return false;
        }
 
        if (ret != 0) {
-               ERROR("Storaged failed to mount: " + std::to_string(ret));
+               ERROR(SINK, "Storaged failed to mount: " + std::to_string(ret));
                currentReq = Request::NONE;
                return false;
        }
@@ -635,7 +635,7 @@ bool ExtensionEncryption::storagedMount(std::unique_lock<std::mutex> &lock)
        if (!storagedCv.wait_for(lock, std::chrono::seconds(1), [this] {
                                return currentReq == Request::NONE;
                        })) {
-               ERROR("Storaged timed out mounting the MAP.");
+               ERROR(SINK, "Storaged timed out mounting the MAP.");
                currentReq = Request::NONE;
                return false;
        }
@@ -659,13 +659,13 @@ bool ExtensionEncryption::storagedUnmount(std::unique_lock<std::mutex> &lock)
                                                                                                 info[Device::MAP].storagedId,
                                                                                                 0).get("(i)", &ret);
        } catch (runtime::Exception &e) {
-               ERROR("Failed to call unmount in storaged: " + std::string(e.what()));
+               ERROR(SINK, "Failed to call unmount in storaged: " + std::string(e.what()));
                currentReq = Request::NONE;
                return false;
        }
 
        if (ret != 0) {
-               ERROR("Storaged failed to unmount: " + std::to_string(ret));
+               ERROR(SINK, "Storaged failed to unmount: " + std::to_string(ret));
                currentReq = Request::NONE;
                return false;
        }
@@ -673,7 +673,7 @@ bool ExtensionEncryption::storagedUnmount(std::unique_lock<std::mutex> &lock)
        if (!storagedCv.wait_for(lock, std::chrono::seconds(1), [this] {
                                return currentReq == Request::NONE;
                        })) {
-               ERROR("Storaged timed out unmounting the MAP.");
+               ERROR(SINK, "Storaged timed out unmounting the MAP.");
                currentReq = Request::NONE;
                return false;
        }
@@ -684,7 +684,7 @@ bool ExtensionEncryption::storagedUnmount(std::unique_lock<std::mutex> &lock)
 int ExtensionEncryption::getStatePriv() const
 {
        if (!isInserted()) {
-               ERROR("Cannot check state, card not inserted");
+               ERROR(SINK, "Cannot check state, card not inserted");
                return -1;
        }
 
index 70a4aa5..c8b96bd 100644 (file)
 
 #include <klay/file-user.h>
 #include <klay/filesystem.h>
-#include <klay/audit/logger.h>
 #include <klay/dbus/variant.h>
 #include <klay/dbus/connection.h>
 
 #include "vconf.h"
+#include "logger.h"
 #include "launchpad.h"
 #include "app-bundle.h"
 #include "progress-bar.h"
@@ -56,7 +56,7 @@ KeyManager::data mountKey;
 void killDependedApplications()
 {
        for (pid_t pid : runtime::FileUser::getList(EXTERNAL_PATH, true)) {
-               INFO("Close process - " + std::to_string(pid));
+               INFO(SINK, "Close process - " + std::to_string(pid));
                ::kill(pid, SIGKILL);
        }
 }
@@ -85,28 +85,28 @@ void externalCallback(dbus::Variant parameters)
        // ExtensionEncryption in terms of how it detects and reacts to card events
        if (intparams[0] != 1 || (std::string(strparams[3]) != "vfat" &&
                                                          std::string(strparams[3]) != "ext4")) {
-               DEBUG("Storaged says it's not a regular SD card. Ignoring.");
+               DEBUG(SINK, "Storaged says it's not a regular SD card. Ignoring.");
                return;
        }
 
        if(intparams[2] == 0) {
-               INFO("Unmounted");
+               INFO(SINK, "Unmounted");
        } else {
-               INFO("Mounted");
+               INFO(SINK, "Mounted");
                char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY);
                if (value != NULL) {
                        std::string valueStr(value);
                        free(value);
                        if (valueStr == "encrypted") {
                                try {
-                                       INFO("Launch SD card password popup");
+                                       INFO(SINK, "Launch SD card password popup");
                                        AppBundle bundle;
                                        bundle.add("viewtype", "SD_CARD_PASSWORD");
 
                                        Launchpad launchpad(::tzplatform_getuid(TZ_SYS_DEFAULT_USER));
                                        launchpad.launch("org.tizen.ode", bundle);
                                } catch (runtime::Exception &e) {
-                                       ERROR("Failed to launch SD card password popup");
+                                       ERROR(SINK, "Failed to launch SD card password popup");
                                }
                        }
                }
@@ -219,7 +219,7 @@ int ExternalEncryption::mount()
        }
 
        if (engine->isMounted()) {
-               INFO("Already mounted");
+               INFO(SINK, "Already mounted");
                return 0;
        }
 
@@ -238,13 +238,13 @@ int ExternalEncryption::umount()
        }
 
        if (!engine->isMounted()) {
-               INFO("Already umounted");
+               INFO(SINK, "Already umounted");
                return 0;
        }
 
-       INFO("Close all applications using external storage...");
+       INFO(SINK, "Close all applications using external storage...");
        killDependedApplications();
-       INFO("Umount external storage...");
+       INFO(SINK, "Umount external storage...");
        engine->umount();
 
        return 0;
@@ -266,19 +266,19 @@ int ExternalEncryption::encrypt(const std::string &password, unsigned int option
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto encryptWorker = [MasterKey, options, this]() {
                try {
-                       INFO("Close all applications using external storage...");
+                       INFO(SINK, "Close all applications using external storage...");
                        killDependedApplications();
-                       INFO("Encryption started...");
+                       INFO(SINK, "Encryption started...");
                        engine->encrypt(MasterKey, options);
                        setOptions(options & getSupportedOptions());
-                       INFO("Sync disk...");
+                       INFO(SINK, "Sync disk...");
                        sync();
-                       INFO("Encryption completed");
+                       INFO(SINK, "Encryption completed");
                        ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "encrypted");
                        context.notify("ExternalEncryption::mount");
                } catch (runtime::Exception &e) {
                        ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
-                       ERROR("Encryption failed - " + std::string(e.what()));
+                       ERROR(SINK, "Encryption failed - " + std::string(e.what()));
                }
        };
 
@@ -304,9 +304,9 @@ int ExternalEncryption::decrypt(const std::string &password)
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto decryptWorker = [MasterKey, this]() {
                try {
-                       INFO("Close all applications using external storage...");
+                       INFO(SINK, "Close all applications using external storage...");
                        killDependedApplications();
-                       INFO("Umount external storage...");
+                       INFO(SINK, "Umount external storage...");
                        while (1) {
                                try {
                                        engine->umount();
@@ -316,15 +316,15 @@ int ExternalEncryption::decrypt(const std::string &password)
                                }
                        }
 
-                       INFO("Decryption started...");
+                       INFO(SINK, "Decryption started...");
                        ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
                        engine->decrypt(MasterKey, getOptions());
-                       INFO("Sync disk...");
+                       INFO(SINK, "Sync disk...");
                        sync();
-                       INFO("Decryption completed");
+                       INFO(SINK, "Decryption completed");
                        ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "unencrypted");
                } catch (runtime::Exception &e) {
-                       ERROR("Decryption failed - " + std::string(e.what()));
+                       ERROR(SINK, "Decryption failed - " + std::string(e.what()));
                }
        };
 
index 9ea0f6b..c1bc23b 100644 (file)
@@ -20,8 +20,8 @@
 
 #include <klay/exception.h>
 #include <klay/filesystem.h>
-#include <klay/audit/logger.h>
 
+#include "logger.h"
 #include "file-footer.h"
 #include "key-manager/key-generator.h"
 
@@ -49,7 +49,7 @@ bool FileFooter::exist(const std::string &key)
 {
        std::string fileName(getFileName(key));
 
-       INFO("Footer file : " + fileName);
+       INFO(SINK, "Footer file : " + fileName);
 
        runtime::File file(fileName);
 
@@ -60,7 +60,7 @@ const FileFooter::data FileFooter::read(const std::string &key)
 {
        std::string fileName(getFileName(key));
 
-       INFO("Footer file : " + fileName);
+       INFO(SINK, "Footer file : " + fileName);
 
        runtime::File file(fileName);
        data value(file.size());
@@ -75,7 +75,7 @@ void FileFooter::write(const std::string &key, const data &value)
 {
        std::string fileName(getFileName(key));
 
-       INFO("Footer file : " + fileName);
+       INFO(SINK, "Footer file : " + fileName);
 
        runtime::File file(fileName);
 
@@ -87,7 +87,7 @@ void FileFooter::clear(const std::string &key)
 {
        std::string fileName(getFileName(key));
 
-       INFO("Footer file : " + fileName);
+       INFO(SINK, "Footer file : " + fileName);
 
        runtime::File file(fileName);
 
index deeb064..897a6fd 100644 (file)
@@ -28,9 +28,9 @@
 #include <klay/file-user.h>
 #include <klay/filesystem.h>
 #include <klay/dbus/connection.h>
-#include <klay/audit/logger.h>
 
 #include "vconf.h"
+#include "logger.h"
 #include "progress-bar.h"
 #include "engine/encryption/dmcrypt-engine.h"
 #include "key-manager/key-manager.h"
@@ -97,7 +97,7 @@ void stopSystemdUserSessions() {
        }
 
        for (const std::string& service : userSessionServices) {
-               INFO("Stop service - " + service);
+               INFO(SINK, "Stop service - " + service);
                systemDBus.methodcall("org.freedesktop.systemd1",
                                                                "/org/freedesktop/systemd1",
                                                                "org.freedesktop.systemd1.Manager",
@@ -124,13 +124,13 @@ void stopDependedSystemdServices()
                                                                                .get("(o)", &service);
                        servicesToStop.insert(service);
                } catch (runtime::Exception &e) {
-                       INFO("Close process - " + std::to_string(pid));
+                       INFO(SINK, "Close process - " + std::to_string(pid));
                        ::kill(pid, SIGKILL);
                }
        }
 
        for (const std::string& service : servicesToStop) {
-               INFO("Close service - " + service);
+               INFO(SINK, "Close service - " + service);
                systemDBus.methodcall("org.freedesktop.systemd1",
                                                                service,
                                                                "org.freedesktop.systemd1.Unit",
@@ -156,7 +156,7 @@ void showProgressUI(const std::string type) {
                        defaultElmConfigDir.copyTo(shareDirectory.getPath());
                }
        } catch (runtime::Exception &e) {
-               ERROR("Failed to set up elm configuration");
+               ERROR(SINK, "Failed to set up elm configuration");
        }
 
        std::vector<std::string> args = {
@@ -266,7 +266,7 @@ int InternalEncryption::mount()
        }
 
     if (engine->isMounted()) {
-               INFO("Already mounted");
+               INFO(SINK, "Already mounted");
                return 0;
        }
 
@@ -288,13 +288,13 @@ int InternalEncryption::umount()
        }
 
        if (!engine->isMounted()) {
-               INFO("Already umounted");
+               INFO(SINK, "Already umounted");
                return 0;
        }
 
-       INFO("Close all processes using internal storage...");
+       INFO(SINK, "Close all processes using internal storage...");
        stopDependedSystemdServices();
-       INFO("Umount internal storage...");
+       INFO(SINK, "Umount internal storage...");
        engine->umount();
 
        return 0;
@@ -316,11 +316,11 @@ int InternalEncryption::encrypt(const std::string& password, unsigned int option
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto encryptWorker = [MasterKey, options, this]() {
                try {
-                       INFO("Close all user sessions...");
+                       INFO(SINK, "Close all user sessions...");
                        stopSystemdUserSessions();
-                       INFO("Close all processes using internal storage...");
+                       INFO(SINK, "Close all processes using internal storage...");
                        stopDependedSystemdServices();
-                       INFO("Umount internal storage...");
+                       INFO(SINK, "Umount internal storage...");
                        while (::umount(INTERNAL_PATH) == -1) {
                                if (errno != EBUSY) {
                                        throw runtime::Exception("Umount error - " + std::to_string(errno));
@@ -330,19 +330,19 @@ int InternalEncryption::encrypt(const std::string& password, unsigned int option
 
                        showProgressUI("Encrypting");
 
-                       INFO("Encryption started...");
+                       INFO(SINK, "Encryption started...");
                        engine->encrypt(MasterKey, options);
                        setOptions(options & getSupportedOptions());
-                       INFO("Sync disk...");
+                       INFO(SINK, "Sync disk...");
                        sync();
-                       INFO("Encryption completed");
+                       INFO(SINK, "Encryption completed");
 
                        ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "encrypted");
                        context.notify("InternalEncryption::mount");
                        ::reboot(RB_AUTOBOOT);
                } catch (runtime::Exception &e) {
                        ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
-                       ERROR("Encryption failed - " + std::string(e.what()));
+                       ERROR(SINK, "Encryption failed - " + std::string(e.what()));
                }
        };
 
@@ -368,11 +368,11 @@ int InternalEncryption::decrypt(const std::string& password)
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto decryptWorker = [MasterKey, this]() {
                try {
-                       INFO("Close all user sessions...");
+                       INFO(SINK, "Close all user sessions...");
                        stopSystemdUserSessions();
-                       INFO("Close all processes using internal storage...");
+                       INFO(SINK, "Close all processes using internal storage...");
                        stopDependedSystemdServices();
-                       INFO("Umount internal storage...");
+                       INFO(SINK, "Umount internal storage...");
                        while (1) {
                                try {
                                        engine->umount();
@@ -384,17 +384,17 @@ int InternalEncryption::decrypt(const std::string& password)
 
                        showProgressUI("Decrypting");
 
-                       INFO("Decryption started...");
+                       INFO(SINK, "Decryption started...");
                        engine->decrypt(MasterKey, getOptions());
-                       INFO("Sync disk...");
+                       INFO(SINK, "Sync disk...");
                        sync();
-                       INFO("Decryption completed");
+                       INFO(SINK, "Decryption completed");
 
                        ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "unencrypted");
                        ::reboot(RB_AUTOBOOT);
                } catch (runtime::Exception &e) {
                        ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
-                       ERROR("Decryption failed - " + std::string(e.what()));
+                       ERROR(SINK, "Decryption failed - " + std::string(e.what()));
                }
        };
 
@@ -413,7 +413,7 @@ int InternalEncryption::recovery()
        //TODO
        runtime::Process proc(PROG_FACTORY_RESET, wipeCommand);
        if (proc.execute() == -1) {
-               ERROR("Failed to launch factory-reset");
+               ERROR(SINK, "Failed to launch factory-reset");
                return -2;
        }
 
index 44a1a0e..6f089e3 100644 (file)
@@ -22,8 +22,8 @@
 #include <openssl/sha.h>
 
 #include <klay/filesystem.h>
-#include <klay/audit/logger.h>
 
+#include "../logger.h"
 #include "key-generator.h"
 
 #define PBKDF_DEFAULT_ITERATION 1000
index e1aec0d..53b7524 100644 (file)
@@ -20,9 +20,9 @@
 #include <algorithm>
 
 #include <klay/filesystem.h>
-#include <klay/audit/logger.h>
 #include <klay/exception.h>
 
+#include "../logger.h"
 #include "key-store.h"
 #include "key-generator.h"
 
index 27d47e2..a41ea29 100644 (file)
@@ -19,8 +19,8 @@
 
 #include <aul.h>
 #include <klay/exception.h>
-#include <klay/audit/logger.h>
 
+#include "logger.h"
 #include "launchpad.h"
 
 Launchpad::Launchpad(const uid_t uid) :
@@ -60,7 +60,7 @@ void Launchpad::terminate(const std::string& appid)
        int pid = ::aul_app_get_pid_for_uid(appid.c_str(), user);
        if (pid > 0) {
                if (::aul_terminate_pid_for_uid(pid, user) < 0) {
-                       WARN("Failed to terminate app PID=" + std::to_string(pid));
+                       WARN(SINK, "Failed to terminate app PID=" + std::to_string(pid));
                        ::kill(pid, SIGKILL);
                }
        }
diff --git a/server/logger.h b/server/logger.h
new file mode 100644 (file)
index 0000000..f25c533
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __ODE_LOGGER_H__
+#define __ODE_LOGGER_H__
+
+#include <klay/audit/logger.h>
+
+extern audit::LogSink *SINK;
+
+#endif //__ODE_SERVER_H__
index 5d6ab6b..dc4b51c 100644 (file)
@@ -16,9 +16,9 @@
 #include <cynara-client.h>
 #include <cynara-session.h>
 
-#include <klay/audit/logger.h>
 #include <klay/audit/dlog-sink.h>
 
+#include "logger.h"
 #include "rmi/secure-erase.h"
 #include "rmi/internal-encryption.h"
 #include "rmi/external-encryption.h"
@@ -37,15 +37,18 @@ std::unique_ptr<ode::SecureErase> secureErase;
 std::unique_ptr<ode::InternalEncryption> internalEncryption;
 std::unique_ptr<ode::ExternalEncryption> externalEncryption;
 std::unique_ptr<ode::ExtensionEncryption> extensionEncryption;
+std::unique_ptr<audit::DlogLogSink> _sink = nullptr;
 
 } // namespace
 
+audit::LogSink *SINK = nullptr;
+
 Server::Server()
 {
-       audit::Logger::setBackend(new audit::DlogLogSink());
-       audit::Logger::setTag("ODE");
+       _sink.reset(new audit::DlogLogSink("ODE"));
+       SINK = dynamic_cast<audit::LogSink*>((_sink).get());
 
-       INFO("ODE server starting.");
+       INFO(SINK, "ODE server starting.");
 
        service.reset(new rmi::Service(ODE_MANAGER_ADDRESS));
 
@@ -87,7 +90,7 @@ bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string&
        }
 
        if (::cynara_initialize(&p_cynara, NULL) != CYNARA_API_SUCCESS) {
-               ERROR("Failure in cynara API");
+               ERROR(SINK, "Failure in cynara API");
                return false;
        }
 
@@ -95,7 +98,7 @@ bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string&
                                           std::to_string(cred.uid).c_str(),
                                           privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) {
                ::cynara_finish(p_cynara);
-               ERROR("Access denied: " + cred.security + " : " + privilege);
+               ERROR(SINK, "Access denied: " + cred.security + " : " + privilege);
                return false;
        }
 
@@ -106,8 +109,8 @@ bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string&
 
 runtime::FileDescriptor Server::registerNotificationSubscriber(const std::string& name)
 {
-       INFO("registerNotificationSubscriber");
-       INFO(name);
+       INFO(SINK, "registerNotificationSubscriber");
+       INFO(SINK, name);
        return runtime::FileDescriptor(service->subscribeNotification(name), true);
 }
 
index c578255..1b4c721 100644 (file)
  *  limitations under the License
  */
 #include <klay/testbench.h>
-#include <klay/audit/logger.h>
+#include <klay/audit/dlog-sink.h>
+
+#include "../server/logger.h"
+
+namespace {
+
+std::unique_ptr<audit::DlogLogSink> _sink = nullptr;
+
+} // namespace
+
+audit::LogSink *SINK = nullptr;
 
 int main(int argc, char** argv)
 {
-       audit::Logger::setLogLevel(audit::LogLevel::Trace);
+       _sink.reset(new audit::DlogLogSink("ODE"));
+       SINK = dynamic_cast<audit::LogSink*>((_sink).get());
+
        testbench::Testbench::runAllTestSuites();
 
        return 0;