Database access function obtaining apps of a certain user 81/28381/9
authorJan Cybulski <j.cybulski@samsung.com>
Mon, 24 Nov 2014 14:44:18 +0000 (15:44 +0100)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 1 Dec 2014 16:04:33 +0000 (08:04 -0800)
This will be used during user removal in security-manager.

Change-Id: I524c9bf2da936054b7c1b597d7e4eaf879872912
Signed-off-by: Jan Cybulski <j.cybulski@samsung.com>
src/common/include/privilege_db.h
src/common/privilege_db.cpp

index 34a4ed1..a95ade8 100644 (file)
@@ -52,6 +52,7 @@ enum class QueryType {
     EPkgIdExists,
     EGetPkgId,
     EGetPrivilegeGroups,
+    EGetUserApps,
 };
 
 class PrivilegeDb {
@@ -77,6 +78,7 @@ private:
         { QueryType::EPkgIdExists, "SELECT * FROM pkg WHERE name=?" },
         { QueryType::EGetPkgId, " SELECT pkg_name FROM app_pkg_view WHERE app_name = ?" },
         { QueryType::EGetPrivilegeGroups, " SELECT name FROM privilege_group_view WHERE privilege_name = ?" },
+        { QueryType::EGetUserApps, "SELECT name FROM app WHERE uid=?" },
     };
 
     /**
@@ -197,6 +199,16 @@ public:
     void GetPrivilegeGroups(const std::string &privilege,
         std::vector<std::string> &grp_names);
 
+    /**
+     * Retrieve list of apps assigned to user
+     *
+     * @param uid - user identifier
+     * @param[out] apps - list of apps assigned to user,
+     *                    this parameter do not need to be empty, but
+     *                    it is being overwritten during function call.
+     * @exception DB::SqlConnection::Exception::InternalError on internal error
+     */
+    void GetUserApps(uid_t uid, std::vector<std::string> &apps);
 };
 
 } //namespace SecurityManager
index e1c4b14..ac83ce6 100644 (file)
@@ -262,5 +262,21 @@ void PrivilegeDb::GetPrivilegeGroups(const std::string &privilege,
     });
 }
 
+void PrivilegeDb::GetUserApps(uid_t uid, std::vector<std::string> &apps)
+{
+   try_catch<void>([&] {
+        DB::SqlConnection::DataCommandAutoPtr command =
+                mSqlConnection->PrepareDataCommand(
+                        Queries.at(QueryType::EGetUserApps));
+        command->BindInteger(1, static_cast<unsigned int>(uid));
+        apps.clear();
+        while (command->Step()) {
+            std::string app = command->GetColumnString(0);
+            LogDebug("User " << uid << " has app " << app << " installed");
+            apps.push_back(app);
+        };
+    });
+}
+
 
 } //namespace SecurityManager