From: Jan Cybulski Date: Mon, 24 Nov 2014 14:44:18 +0000 (+0100) Subject: Database access function obtaining apps of a certain user X-Git-Tag: accepted/tizen/tv/20150217.004257~47 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git;a=commitdiff_plain;h=c24b51ec1f9a164a16d3bcfb02ada68411abd723 Database access function obtaining apps of a certain user This will be used during user removal in security-manager. Change-Id: I524c9bf2da936054b7c1b597d7e4eaf879872912 Signed-off-by: Jan Cybulski --- diff --git a/src/common/include/privilege_db.h b/src/common/include/privilege_db.h index 34a4ed1..a95ade8 100644 --- a/src/common/include/privilege_db.h +++ b/src/common/include/privilege_db.h @@ -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 &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 &apps); }; } //namespace SecurityManager diff --git a/src/common/privilege_db.cpp b/src/common/privilege_db.cpp index e1c4b14..ac83ce6 100644 --- a/src/common/privilege_db.cpp +++ b/src/common/privilege_db.cpp @@ -262,5 +262,21 @@ void PrivilegeDb::GetPrivilegeGroups(const std::string &privilege, }); } +void PrivilegeDb::GetUserApps(uid_t uid, std::vector &apps) +{ + try_catch([&] { + DB::SqlConnection::DataCommandAutoPtr command = + mSqlConnection->PrepareDataCommand( + Queries.at(QueryType::EGetUserApps)); + command->BindInteger(1, static_cast(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