From d898ffdd582eec8d80a6f101f83d15e145e81571 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 7 Jun 2019 18:17:18 +0200 Subject: [PATCH] Stop listening for storaged dbus signals Oded is now socket & dbus activated and won't listen for dbus signals. Additionally the default sd card mountpoint will be removed. From now on oded will expect passing mountpoint via dbus call. Launch the sd card UI with file activation instead of dbus call as the sd card UI is now a user service. To be merged after storaged starts using the dbus service. Change-Id: Ic5fb3f4ec4a74d0a8a0a3ec61876498b7a3527f6 --- server/external-encryption.cpp | 132 +++++++-------------------------- 1 file changed, 27 insertions(+), 105 deletions(-) diff --git a/server/external-encryption.cpp b/server/external-encryption.cpp index ab2dcd6..2cbc4d6 100644 --- a/server/external-encryption.cpp +++ b/server/external-encryption.cpp @@ -13,19 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License */ -#include -#include -#include - #include #include +#include +#include + +#include +#include + +#include +#include #include #include #include #include -#include -#include #include "misc.h" #include "logger.h" @@ -40,24 +42,19 @@ namespace ode { namespace { -bool isBootCompleted = false; - -constexpr const char *DEFAULT_EXTERNAL_PATH = "/media/SDCardA1"; const char *PRIVILEGE_PLATFORM = "http://tizen.org/privilege/internal/default/platform"; +const char *SDCARD_UI_ACTIVATOR_PATH = "/run/ode-booting-with-encrypted-sdcard"; void spawnUI() { INFO(SINK, "Launching SD card password popup."); - try { - dbus::Connection &systemDBus = dbus::Connection::getSystem(); - systemDBus.methodcall("org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "StartUnit", - -1, "", "(ss)", "ode-external-lock.service", "replace"); - } catch (runtime::Exception &e) { - ERROR(SINK, "Failed to launch SD card password popup: " + std::string(e.what())); + runtime::File act(SDCARD_UI_ACTIVATOR_PATH); + try { + act.create(O_WRONLY|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // 644 + } catch (const runtime::Exception& e) { + ERROR(SINK, "Opening sdcard UI activator (" << SDCARD_UI_ACTIVATOR_PATH << ") failed: " << + e.what()); } } @@ -73,88 +70,6 @@ bool isEncrypted() return encrypted; } -void externalCallback(dbus::Variant parameters) -{ - int intparams[6]; - char* strparams[7]; - - parameters.get("(issssssisibii)", - &intparams[0], // block type: 0 - scsi, 1 : mmc - &strparams[0], // devnode - &strparams[1], // syspath - &strparams[2], // usage - &strparams[3], // fs type - &strparams[4], // fs version - &strparams[5], // fs uuid enc - &intparams[1], // readonly: 0 - rw, 1 - ro - &strparams[6], // mount point - &intparams[2], // state: 0 - unmount, 1 - mount - &intparams[3], // primary: 0 - flase, 1 - true - &intparams[4], // flags: 1 - unmounted 2 - broken filesystem 4 - no filesystem 8 - not supported 16 - readonly - &intparams[5]); // storage id - - if (intparams[0] != 1 || (std::string(strparams[3]) != "vfat" && - std::string(strparams[3]) != "ext4")) { - DEBUG(SINK, "Storaged says it's not a regular SD card. Ignoring."); - return; - } - - if(intparams[2] == 0) { - INFO(SINK, "SD card not mounted, ignoring."); - int ret = ::vconf_unset(VCONFKEY_SDE_MOUNT_POINT); - if (ret != 0) - ERROR(SINK, "vconf_unset() failed with " << ret); - } else { - INFO(SINK, "SD card mounted."); - int ret; - ret = ::vconf_set_str(VCONFKEY_SDE_MOUNT_POINT, DEFAULT_EXTERNAL_PATH); - if (ret != 0) { - ERROR(SINK, "vconf_set() failed with " << ret); - return; - } - - if (isEncrypted() && isBootCompleted) - spawnUI(); - } -} - -void bootCompletionCallback(dbus::Variant parameters) -{ - auto waitForHomescreen = []() { - //For a delay until homescreen is totally loaded - sleep(8); - - INFO(SINK, "Boot completed."); - int ret = ::vconf_set_str(VCONFKEY_SDE_MOUNT_POINT, DEFAULT_EXTERNAL_PATH); - if (ret != 0) { - ERROR(SINK, "vconf_set() failed with " << ret); - } else if (isEncrypted()) { - spawnUI(); - } - isBootCompleted = true; - }; - - std::thread asyncWork(waitForHomescreen); - asyncWork.detach(); -} - -void externalAddEventReceiver() -{ - dbus::Connection &systemDBus = dbus::Connection::getSystem(); - - systemDBus.subscribeSignal("", - "/Org/Tizen/System/Storage/Block/Manager", - "org.tizen.system.storage.BlockManager", - "DeviceChanged", - externalCallback); - - systemDBus.subscribeSignal("", - "/Org/Tizen/System/DeviceD/Core", - "org.tizen.system.deviced.core", - "BootingDone", - bootCompletionCallback); -} - /* * Introspection data for the exported object * @@ -250,7 +165,6 @@ ExternalEncryptionServer::ExternalEncryptionServer(ServerContext &srv, server.createNotification("ExternalEncryptionServer::mount"); - externalAddEventReceiver(); } ExternalEncryptionServer::~ExternalEncryptionServer() @@ -593,13 +507,21 @@ EXTERNAL_ENGINE& ExternalEncryptionServer::getEngine() const if (!engine) { char *tmp = ::vconf_get_str(VCONFKEY_SDE_MOUNT_POINT); - static_assert(DEFAULT_EXTERNAL_PATH); + if (tmp == NULL) { + ERROR(SINK, "Sd card not mounted"); + throw runtime::Exception("Sd card not mounted"); + } - std::string mountPoint(tmp ? tmp : DEFAULT_EXTERNAL_PATH); + std::string mountPoint(tmp); free(tmp); - runtime::File f(mountPoint); - mountPoint = f.readlink(); + char *realMountPoint = ::realpath(mountPoint.c_str(), NULL); + if (realMountPoint == NULL) { + ERROR(SINK, "Failed to resolve mountpoint."); + throw runtime::Exception("Failed to resolve mountpoint."); + } + mountPoint.assign(realMountPoint); + free(realMountPoint); engine.reset(new EXTERNAL_ENGINE(mountPoint, mountPoint, -- 2.34.1