* 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"
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());
}
}
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
*
server.createNotification("ExternalEncryptionServer::mount");
- externalAddEventReceiver();
}
ExternalEncryptionServer::~ExternalEncryptionServer()
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,