#include <condition_variable>
#include <list>
+#include <fstream>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
const char *PRIVILEGE_PLATFORM = "http://tizen.org/privilege/internal/default/platform";
-// TODO: see recovery()
-const std::string PROG_FACTORY_RESET = "/usr/bin/dbus-send";
-const std::vector<std::string> wipeCommand = {
- PROG_FACTORY_RESET,
- "--system",
- "--type=signal",
- "--print-reply",
- "--dest=com.samsung.factoryreset",
- "/com/samsung/factoryreset",
- "com.samsung.factoryreset.start.setting"
-};
-
-
// watches systemd jobs
class JobWatch {
public:
server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::encrypt)(std::string, unsigned int));
server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::decrypt)(std::string));
server.expose(this, "", (int)(InternalEncryptionServer::isPasswordInitialized)());
+ server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::recovery)());
server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::initPassword)(std::string));
server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::cleanPassword)(std::string));
server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::changePassword)(std::string, std::string));
int InternalEncryptionServer::recovery()
{
- if (getState() == State::Unencrypted) {
+ int state = getState();
+
+ if (state == State::Unencrypted)
return error::NoSuchDevice;
- }
- //TODO
- runtime::Process proc(PROG_FACTORY_RESET, wipeCommand);
- if (proc.execute() == -1) {
- ERROR(SINK, "Failed to launch factory-reset");
- return error::WrongPassword;
+ if (state == State::Corrupted) {
+ const char *mkfsPath = "/sbin/mkfs.ext4";
+ std::vector<std::string> formatArg = {
+ mkfsPath, "-F", engine->getSource()};
+ runtime::Process proc(mkfsPath, formatArg);
+
+ int ret = proc.execute();
+ if (ret < 0)
+ throw runtime::Exception("Failed to execute mkfs.ext4");
+
+ ret = proc.waitForFinished();
+ if (ret < 0 || !WIFEXITED(ret) || WEXITSTATUS(ret) != 0)
+ throw runtime::Exception("Failed to wait for finish of format");
}
+ std::fstream fs;
+ fs.open("/opt/.factoryreset", std::ios::out);
+ fs.close();
+
+ ::sync();
+ try {
+ dbus::Connection& systemDBus = dbus::Connection::getSystem();
+ systemDBus.methodcall("org.tizen.deviced",
+ "/Org/Tizen/DeviceD/Power",
+ "org.tizen.deviced.power",
+ "reboot",
+ -1, "()", "(si)");
+ } catch (runtime::Exception &e) {
+ ::reboot(RB_AUTOBOOT);
+ }
return error::None;
}
<< " -s, --state=internal|external get state" << std::endl
<< " -w, --waitmnt=internal|external wait for mount"<< std::endl
<< " -c, --clean=DIRECTORY secure-clean" << std::endl
+ << " -r, --recovery recovery" << std::endl
<< " -h, --help show this" << std::endl
<< std::endl;
return ret;
}
+static inline int recovery()
+{
+ int ret = 0;
+
+ ret = ode_internal_encryption_recovery();
+ if (ret != 0)
+ std::cerr << "Error : " << ret << std::endl;
+
+ return ret;
+}
+
int main(int argc, char* argv[])
{
int opt = 0, luks_opt = 0, index, ret = 0;
{"state", required_argument, 0, 's'},
{"waitmnt", required_argument, 0, 'w'},
{"clean", required_argument, 0, 'c'},
+ {"recovery", no_argument, 0, 'r'},
{0, 0, 0, 0}
};
std::string mapping, device, op;
bool sync = true;
- while ((opt = getopt_long(argc, argv, "m:u:e:d:l:L:p:k:s:w:c:h", options, &index)) != -1) {
+ while ((opt = getopt_long(argc, argv, "m:u:e:d:l:L:p:k:s:w:c:rh", options, &index)) != -1) {
switch (opt) {
case 'm':
ret = mount(optarg);
case 'c':
ret = clean(optarg);
break;
+ case 'r':
+ ret = recovery();
+ break;
case 'D':
device = optarg;
break;