#include "ecryptfs-engine.h"
+#include "misc.h"
+
#define OPTION_ONLY_NEW_FILE (1 << 0)
#define OPTION_EXCEPT_FOR_MEDIA_FILE (1 << 1)
bool EcryptfsEngine::isMounted()
{
- std::ifstream file("/proc/mounts");
- std::string line;
-
- while (std::getline(file, line)) {
- std::stringstream info(line);
- std::string src, dest, type;
-
- info >> src >> dest >> type;
- if (type == "ecryptfs" && src == source && dest == destination) {
+ Mtab mtab;
+ struct ::mntent* entry;
+ while ((entry = mtab.next()) != NULL) {
+ if (std::string("ecryptfs") == entry->mnt_type &&
+ source == entry->mnt_fsname &&
+ destination == entry->mnt_dir)
return true;
- }
}
return false;
auto encryptWorker = [MasterKey, options, this]() {
try {
std::string source = engine->getSource();
- std::string mntPath = findMntPath(source);
+ std::string mntPath = findMountPointByDevice(source);
if (!mntPath.empty()) {
INFO(SINK, "Closing all known systemd services that might be using internal storage.");
}
stopDependedSystemdServices();
}
- mntPath = findMntPath(source);
+ mntPath = findMountPointByDevice(source);
}
showProgressUI("Encrypting");
*/
#include <signal.h>
#include <sys/types.h>
-#include <stdio.h>
-#include <mntent.h>
#include <klay/file-user.h>
+#include <klay/filesystem.h>
+#include <klay/exception.h>
#include "logger.h"
#include "misc.h"
namespace ode {
-std::string findMntPath(const std::string &devPath)
+Mtab::Mtab() {
+ mtab = ::setmntent("/proc/self/mounts", "r");
+ if (mtab == NULL)
+ throw runtime::Exception("Opening mtab failed");
+}
+
+Mtab::~Mtab() {
+ ::endmntent(mtab);
+}
+
+struct ::mntent* Mtab::next() {
+ return ::getmntent(mtab);
+}
+
+
+std::string findMountPointByDevice(const std::string &devPath)
{
std::string ret;
- FILE* mtab = ::setmntent("/etc/mtab", "r");
+ Mtab mtab;
struct ::mntent* entry = NULL;
- while ((entry = ::getmntent(mtab)) != NULL) {
+ while ((entry = mtab.next()) != NULL) {
if (devPath == entry->mnt_fsname) {
ret = entry->mnt_dir;
break;
}
}
- ::endmntent(mtab);
return ret;
}
#define __MISC_H__
#include <string>
+#include <stdio.h>
+#include <mntent.h>
namespace ode {
-std::string findMntPath(const std::string &devPath);
+class Mtab {
+public:
+ Mtab();
+ ~Mtab();
+
+ struct ::mntent* next();
+
+private:
+ FILE* mtab;
+};
+
+std::string findMountPointByDevice(const std::string &devPath);
void killDependentApplications(const std::string &mntPath);
} // namespace ode
#include <fstream>
#include <vconf.h>
#include <unistd.h>
-#include <mntent.h>
+#include "misc.h"
#include "secure-erase.h"
namespace ode {
typedef std::unordered_map<std::string, std::string> DeviceList;
const char *PRIVILEGE_PLATFORM = "http://tizen.org/privilege/internal/default/platform";
-std::string findDevPath(const std::string &mntPath)
+std::string findDeviceByMountPoint(const std::string &mntPath)
{
std::string ret;
- FILE* mtab = ::setmntent("/etc/mtab", "r");
+ Mtab mtab;
struct ::mntent* entry = NULL;
- while ((entry = ::getmntent(mtab)) != NULL) {
- if (strcmp(entry->mnt_type, "ext2") && strcmp(entry->mnt_type, "ext3") && strcmp(entry->mnt_type, "ext4"))
+ while ((entry = mtab.next()) != NULL) {
+ if (strcmp(entry->mnt_type, "ext2") &&
+ strcmp(entry->mnt_type, "ext3") &&
+ strcmp(entry->mnt_type, "ext4"))
continue;
+
if (mntPath == entry->mnt_dir) {
ret = entry->mnt_fsname;
break;
}
}
- ::endmntent(mtab);
return ret;
}
+
} /* namespace */
SecureEraseServer::SecureEraseServer(ServerContext &srv) :
{
auto cleanWorker = [name, this]() {
try {
- std::string target = findDevPath(name);
+ std::string target = findDeviceByMountPoint(name);
engine->cleanDevice(target);
} catch (runtime::Exception &e) {}
};
../server/key-manager/anti-forensics.cpp
../server/ext4-tool.cpp
../server/progress-bar.cpp
+ ../server/misc.cpp
)
ADD_EXECUTABLE(${PROJECT_NAME} ${TEST_SRC})