Add to search storage-dependent services and apps with file-user 27/100427/8
authorSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 28 Nov 2016 06:10:29 +0000 (15:10 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 1 Dec 2016 02:50:55 +0000 (11:50 +0900)
Change-Id: I9155e95f38dc673a44f8bb590f0cc224357fff36
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
server/external-encryption.cpp
server/internal-encryption.cpp

index e52bf2c..870ca38 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License
  */
+#include <signal.h>
 #include <unistd.h>
 #include <sys/mount.h>
 
+#include <tzplatform_config.h>
+#include <klay/file-user.h>
 #include <klay/filesystem.h>
 #include <klay/audit/logger.h>
 
@@ -25,6 +28,7 @@
 #include "rmi/external-encryption.h"
 
 #define EXTERNAL_STORAGE_PATH  "/opt/media/SDCardA1"
+#define DEFAULT_USER "owner"
 
 namespace ode {
 
@@ -35,6 +39,10 @@ EcryptfsEngine engine(EXTERNAL_STORAGE_PATH, EXTERNAL_STORAGE_PATH);
 
 void killDependedApplications()
 {
+       for (pid_t pid : runtime::FileUser::getList(EXTERNAL_STORAGE_PATH, true)) {
+               INFO("Close process - " + std::to_string(pid));
+               ::kill(pid, SIGKILL);
+       }
 }
 
 }
@@ -137,6 +145,7 @@ int ExternalEncryption::decrypt(const std::string& password)
                try {
                        engine.umount();
                } catch (runtime::Exception& e) {}
+
                INFO("Decryption started...");
                engine.decrypt(DEK);
                INFO("Sync disk...");
index 59a9186..3a217fc 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License
  */
+#include <set>
+
+#include <signal.h>
 #include <unistd.h>
 #include <sys/mount.h>
 #include <sys/reboot.h>
 
+#include <klay/file-user.h>
 #include <klay/filesystem.h>
 #include <klay/dbus/connection.h>
 #include <klay/audit/logger.h>
@@ -35,55 +39,34 @@ namespace {
 KeyManager keyManager(INTERNAL_STORAGE_PATH);
 DMCryptEngine engine("/dev/mmcblk0p25", INTERNAL_STORAGE_PATH);
 
-std::vector<std::string> dependedSystemdServices = {
-       "resourced.service",
-       "msg-server.service",
-       "mtp-responder.service",
-};
-
 void stopDependedSystemdServices()
 {
-       std::vector<std::string> servicesToStop(dependedSystemdServices);
        dbus::Connection& systemDBus = dbus::Connection::getSystem();
-       dbus::VariantIterator iter;
-
-       systemDBus.methodcall("org.freedesktop.systemd1",
-                                                       "/org/freedesktop/systemd1",
-                                                       "org.freedesktop.systemd1.Manager",
-                                                       "ListUnits",
-                                                       -1, "(a(ssssssouso))", "")
-                                                               .get("(a(ssssssouso))", &iter);
-
-       while(1) {
-               unsigned int dataUint;
-               char *dataStr[9];
-               int ret;
-
-               ret = iter.get("(ssssssouso)", dataStr, dataStr + 1, dataStr + 2,
-                                                                               dataStr + 3, dataStr + 4, dataStr + 5,
-                                                                               dataStr + 6, &dataUint, dataStr + 7,
-                                                                               dataStr + 8);
-
-               if (!ret) {
-                       break;
-               }
+       std::set<std::string> servicesToStop;
 
-               std::string service(dataStr[0]);
-               if (service.compare(0, 5, "user@") == 0) {
-                       servicesToStop.push_back(service);
+       for (pid_t pid : runtime::FileUser::getList(INTERNAL_STORAGE_PATH, true)) {
+               try {
+                       char *service;
+                       systemDBus.methodcall("org.freedesktop.systemd1",
+                                                                       "/org/freedesktop/systemd1",
+                                                                       "org.freedesktop.systemd1.Manager",
+                                                                       "GetUnitByPID",
+                                                                       -1, "(o)", "(u)", (unsigned int)pid)
+                                                                               .get("(o)", &service);
+                       servicesToStop.insert(service);
+               } catch (runtime::Exception &e) {
+                       INFO("Close process - " + std::to_string(pid));
+                       ::kill(pid, SIGKILL);
                }
        }
 
-
-       //TODO : get other services that are using INTERNAL_STORAGE_PATH
-
        for (const std::string& service : servicesToStop) {
-               INFO("Stop service - " + service);
+               INFO("Close service - " + service);
                systemDBus.methodcall("org.freedesktop.systemd1",
-                                                               "/org/freedesktop/systemd1",
-                                                               "org.freedesktop.systemd1.Manager",
-                                                               "StopUnit",
-                                                               -1, "", "(ss)", service.c_str(), "flush");
+                                                               service,
+                                                               "org.freedesktop.systemd1.Unit",
+                                                               "Stop",
+                                                               -1, "", "(s)", "flush");
        }
 }