Add path name based admin indentifier for session daemons 67/102067/1
authorJaemin Ryu <jm77.ryu@samsung.com>
Thu, 24 Nov 2016 06:58:24 +0000 (15:58 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Mon, 5 Dec 2016 00:17:48 +0000 (09:17 +0900)
Change-Id: Ifa24fbe0336c7cbcdb273416ba6ed2e4213cdc18
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
server/client-manager.cpp
server/server.cpp

index 6ff7652..46f2813 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <string>
 #include <climits>
-#include <klay/exception.h>
 
 #include <klay/exception.h>
 
@@ -32,7 +31,7 @@ DeviceAdministrator::~DeviceAdministrator()
 }
 
 DeviceAdministratorManager::DeviceAdministratorManager(const std::string& path) :
-       repository(path + "/.client.db")
+       repository(path + "/.dpm.db")
 {
        prepareRepository();
 }
@@ -41,7 +40,7 @@ DeviceAdministrator DeviceAdministratorManager::enroll(const std::string& name,
 {
        database::Connection connection(repository, database::Connection::ReadWrite);
 
-       std::string selectQuery = "SELECT * FROM CLIENT WHERE PKG = ? AND UID = ?";
+       std::string selectQuery = "SELECT * FROM ADMIN WHERE PKG = ? AND UID = ?";
        database::Statement stmt0(connection, selectQuery);
        stmt0.bind(1, name);
        stmt0.bind(2, static_cast<int>(uid));
@@ -51,7 +50,7 @@ DeviceAdministrator DeviceAdministratorManager::enroll(const std::string& name,
 
        std::string key = generateKey();
 
-       std::string insertQuery = "INSERT INTO CLIENT (PKG, UID, KEY, VALID) VALUES (?, ?, ?, ?)";
+       std::string insertQuery = "INSERT INTO ADMIN (PKG, UID, KEY, REMOVABLE) VALUES (?, ?, ?, ?)";
        database::Statement stmt(connection, insertQuery);
        stmt.bind(1, name);
        stmt.bind(2, static_cast<int>(uid));
@@ -68,7 +67,7 @@ void DeviceAdministratorManager::disenroll(const std::string& name, uid_t uid)
 {
        database::Connection connection(repository, database::Connection::ReadWrite);
 
-       std::string query = "DELETE FROM CLIENT WHERE PKG = ? AND UID = ?";
+       std::string query = "DELETE FROM ADMIN WHERE PKG = ? AND UID = ?";
        database::Statement stmt(connection, query);
        stmt.bind(1, name);
        stmt.bind(2, static_cast<int>(uid));
@@ -88,16 +87,16 @@ void DeviceAdministratorManager::prepareRepository()
        database::Connection connection(repository, database::Connection::ReadWrite |
                                                                                                database::Connection::Create);
 
-       std::string query = "CREATE TABLE IF NOT EXISTS CLIENT ("    \
+       std::string query = "CREATE TABLE IF NOT EXISTS ADMIN ("    \
                                                "ID INTEGER PRIMARY KEY AUTOINCREMENT, " \
                                                "PKG TEXT, "                             \
                                                "UID INTEGER, "                          \
                                                "KEY TEXT, "                             \
-                                               "VALID INTEGER)";
+                                               "REMOVABLE INTEGER)";
 
        connection.exec(query);
 
-       database::Statement stmt(connection, "SELECT * FROM CLIENT");
+       database::Statement stmt(connection, "SELECT * FROM ADMIN");
        while (stmt.step()) {
                std::string name = stmt.getColumn(1).getText();
                uid_t uid = static_cast<uid_t>(stmt.getColumn(2).getInt());
index 16dee15..eb42a98 100644 (file)
  *  limitations under the License
  */
 
-#include <fcntl.h>
-#include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include <functional>
 
@@ -47,7 +47,24 @@ std::string GetPackageId(uid_t uid, pid_t pid)
        char pkgid[PATH_MAX];
 
        if (aul_app_get_pkgid_bypid_for_uid(pid, pkgid, PATH_MAX, uid) != 0) {
-               throw runtime::Exception("Unknown PID");
+               int fd = ::open(std::string("/proc/" + std::to_string(pid) + "/cmdline").c_str(), O_RDONLY);
+               if (fd == -1) {
+                       throw runtime::Exception("Unknown PID");
+               }
+
+               ssize_t ret, bytes = 0;
+               do {
+                       ret = ::read(fd, &pkgid[bytes], PATH_MAX);
+                       if (ret != -1) {
+                               bytes += ret;
+                       }
+               } while ((ret == -1) && (errno == EINTR));
+
+               if (ret == -1) {
+                       throw runtime::Exception("Failed to get admin info");
+               }
+
+               pkgid[bytes] = '\0';
        }
 
        return pkgid;