From: seolheui kim Date: Wed, 27 Jun 2018 07:01:20 +0000 (+0900) Subject: Add getDecodedPath for decoding unit name X-Git-Tag: submit/tizen_4.0/20180828.100016~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9191e76bc30441617f84d15e135d2476ee11c3b1;p=platform%2Fcore%2Fsecurity%2Fode.git Add getDecodedPath for decoding unit name Change-Id: I7a1d4afe615e4369d33c0f64755d7e80e23891cf Signed-off-by: seolheui kim --- diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index f0df17f..3fc0cd7 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -184,6 +184,28 @@ void stopKnownSystemdUnits() } } +std::string getDecodedPath(const std::string &path, const std::string &prefix) +{ + std::string ret = path; + size_t pos = 0; + + pos = ret.find(prefix); + if (pos != std::string::npos) + ret = ret.substr(prefix.size(), ret.size()); + + pos = 0; + while ((pos = ret.find("_", pos)) != std::string::npos) { + int a = std::stoi(std::string(1, ret.at(pos+1)), nullptr, 16); + int b = std::stoi(std::string(1, ret.at(pos+2)), nullptr, 16); + if (a < 0 || b < 0) + ret.replace(pos, 3, "_"); + else + ret.replace(pos, 3, std::string(1, ((a << 4) | b))); + pos += 1; + } + return ret; +} + void stopDependedSystemdUnits() { dbus::Connection& systemDBus = dbus::Connection::getSystem(); @@ -192,7 +214,7 @@ void stopDependedSystemdUnits() for (pid_t pid : runtime::FileUser::getList(INTERNAL_PATH, true)) { try { - char *unit; + char *unit = nullptr; systemDBus.methodcall("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", @@ -200,11 +222,11 @@ void stopDependedSystemdUnits() -1, "(o)", "(u)", (unsigned int)pid) .get("(o)", &unit); - if (std::string(unit) == - "/org/freedesktop/systemd1/unit/samsung_2dlog_2dmgr_2eservice") + auto unescapedName = getDecodedPath(unit, "/org/freedesktop/systemd1/unit/"); + if (unescapedName == "samsung-log-mgr.service") p = pid; else - unitsToStop.insert(unit); + unitsToStop.insert(unescapedName); } catch (runtime::Exception &e) { INFO(SINK, "Killing process: " + std::to_string(pid)); ::kill(pid, SIGKILL); @@ -217,10 +239,10 @@ void stopDependedSystemdUnits() INFO(SINK, "Stopping unit: " + unit); const char* job = NULL; systemDBus.methodcall("org.freedesktop.systemd1", - unit, - "org.freedesktop.systemd1.Unit", - "Stop", - -1, "(o)", "(s)", "flush").get("(o)", &job); + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "StopUnit", + -1, "(o)", "(ss)", unit.c_str(), "flush").get("(o)", &job); INFO(SINK, "Waiting for job: " + std::string(job)); if (!watch.waitForJob(job)) throw runtime::Exception("Stopping unit: " + unit + " failed");