Stop listening for storaged dbus signals 92/207592/12 accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/20191031.022222 accepted/tizen/5.5/unified/mobile/hotfix/20201027.090104 accepted/tizen/unified/20190808.113653 submit/tizen/20190807.075701 submit/tizen_5.5/20191031.000004 submit/tizen_5.5_mobile_hotfix/20201026.185104 tizen_5.5.m2_release
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 7 Jun 2019 16:17:18 +0000 (18:17 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 2 Aug 2019 11:47:14 +0000 (11:47 +0000)
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

index ab2dcd6..2cbc4d6 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License
  */
-#include <fstream>
-#include <sstream>
-#include <cstring>
-
 #include <unistd.h>
 #include <sys/mount.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <climits>
+#include <cstdlib>
+
+#include <fstream>
+#include <sstream>
 
 #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 "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,